<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.qunzhixinxi.hnqz.admin.mapper.WmDeptBudgetMapper">

	<resultMap id="wmDeptBudgetMap" type="com.qunzhixinxi.hnqz.admin.entity.WmDeptBudget">
		<id property="id" column="id"/>
		<result property="deptId" column="dept_id"/>
		<result property="belongDate" column="belong_date"/>
		<result property="declareDept" column="declare_dept"/>
		<result property="budgetType" column="budget_type"/>
		<result property="budget" column="budget"/>
		<result property="createTime" column="create_time"/>
	</resultMap>

	<select id="getBudgetViewPage" resultType="com.qunzhixinxi.hnqz.admin.entity.output.BudgetViewOutput">
		SELECT t.dept_id, t.declare_dept, t.belong_date,
			SUM( IF ( t.budget_type = '0', t.budget, 0 ) ) scoreBudget,
			SUM( IF ( t.budget_type = '1', t.budget, 0 ) ) taskBudget
		FROM wm_dept_budget t
		<where>
			t.dept_id = #{query.deptId,jdbcType=INTEGER}
			<if test="query.belongDate != null and query.belongDate != ''">
				AND t.belong_date = #{query.belongDate,jdbcType=VARCHAR}
			</if>
			<if test="query.declareDept != null ">
				AND t.declare_dept = #{query.declareDept,jdbcType=INTEGER}
			</if>
		</where>
		GROUP BY t.dept_id, t.declare_dept, t.belong_date
	</select>

	<select id="getBudgetEntViewPage" resultType="com.qunzhixinxi.hnqz.admin.entity.output.BudgetViewOutput">
		SELECT t.dept_id, t.declare_dept, t.belong_date,
		SUM( IF ( t.budget_type = '0', t.budget, 0 ) ) scoreBudget,
		SUM( IF ( t.budget_type = '1', t.budget, 0 ) ) taskBudget
		FROM wm_dept_budget t
		<where>
			t.declare_dept = #{query.declareDept,jdbcType=INTEGER}
			<if test="query.belongDate != null and query.belongDate != ''">
				AND t.belong_date = #{query.belongDate,jdbcType=VARCHAR}
			</if>
			<if test="query.deptId != null ">
				AND t.dept_id = #{query.deptId,jdbcType=INTEGER}
			</if>
		</where>
		GROUP BY t.dept_id, t.declare_dept, t.belong_date
	</select>
</mapper>
