<?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.ruoyi.system.mapper.project.BmDeptPlanAreaMapper">
    
    <resultMap type="BmDeptPlanArea" id="BmDeptPlanAreaResult">
        <result property="id"    column="id"    />
        <result property="sysDeptId"    column="sys_dept_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="year"    column="year"    />
        <result property="projectMillionNum"    column="project_million_num"    />
        <result property="projectIndustryNum"    column="project_industry_num"    />
        <result property="projectOneNum"    column="project_one_num"    />
        <result property="projectTwoNum"    column="project_two_num"    />
        <result property="projectThrNum"    column="project_thr_num"    />
        <result property="projectFourNum"    column="project_four_num"    />
        <result property="projectFiveNum"    column="project_five_num"    />
        <result property="projectCityMoney"    column="project_city_money"    />
        <result property="projectProNum"    column="project_pro_num"    />
        <result property="projectRisNum"    column="project_ris_num"    />
        <result property="projectSerNum"    column="project_ser_num"    />
        <result property="projectProFiveNum"    column="project_pro_five_num"    />
        <result property="projectInvestmentNum"    column="project_investment_num"    />
        <result property="projectIntegrationNum"    column="project_integration_num"    />
        <result property="projectSmallNum"    column="project_small_num"    />
        <result property="projectNewNum"    column="project_new_num"    />
        <result property="remark"    column="remark"    />
        <result property="deptName"    column="dept_name"    />
    </resultMap>

    <sql id="selectBmDeptPlanAreaVo">
        select id, sys_dept_id, create_by, create_time, update_by, update_time, is_del, year, project_million_num, project_industry_num, project_one_num, project_two_num, project_thr_num, project_four_num, project_five_num, project_city_money, project_pro_num, project_ris_num, project_ser_num, project_pro_five_num, project_investment_num, project_integration_num, project_small_num, project_new_num, remark from bm_dept_plan_area
    </sql>

    <select id="selectBmDeptPlanAreaList" parameterType="BmDeptPlanArea" resultMap="BmDeptPlanAreaResult">
        select a.id, a.sys_dept_id, a.create_by, a.create_time, a.update_by, a.update_time, a.is_del, a.year, a.project_million_num, a.project_industry_num, a.project_one_num, a.project_two_num, a.project_thr_num, a.project_four_num, a.project_five_num, a.project_city_money, a.project_pro_num, a.project_ris_num, a.project_ser_num, a.project_pro_five_num, a.project_investment_num, a.project_integration_num, a.project_small_num, a.project_new_num, a.remark, d.dept_name
        from bm_dept_plan_area a
        left join sys_dept d on a.sys_dept_id = d.dept_id and a.is_del = '0'
        <where>  
            <if test="sysDeptId != null "> and a.sys_dept_id = #{sysDeptId}</if>
            <if test="year != null  and year != ''"> and a.year = #{year}</if>
            <if test="projectMillionNum != null "> and a.project_million_num = #{projectMillionNum}</if>
            <if test="projectIndustryNum != null "> and a.project_industry_num = #{projectIndustryNum}</if>
            <if test="projectOneNum != null "> and a.project_one_num = #{projectOneNum}</if>
            <if test="projectTwoNum != null "> and a.project_two_num = #{projectTwoNum}</if>
            <if test="projectThrNum != null "> and a.project_thr_num = #{projectThrNum}</if>
            <if test="projectFourNum != null "> and a.project_four_num = #{projectFourNum}</if>
            <if test="projectFiveNum != null "> and a.project_five_num = #{projectFiveNum}</if>
            <if test="projectCityMoney != null "> and a.project_city_money = #{projectCityMoney}</if>
            <if test="projectProNum != null "> and a.project_pro_num = #{projectProNum}</if>
            <if test="projectRisNum != null "> and a.project_ris_num = #{projectRisNum}</if>
            <if test="projectSerNum != null "> and a.project_ser_num = #{projectSerNum}</if>
            <if test="projectProFiveNum != null "> and a.project_pro_five_num = #{projectProFiveNum}</if>
            <if test="projectInvestmentNum != null "> and a.project_investment_num = #{projectInvestmentNum}</if>
            <if test="projectIntegrationNum != null "> and a.project_integration_num = #{projectIntegrationNum}</if>
            <if test="projectSmallNum != null "> and a.project_small_num = #{projectSmallNum}</if>
            <if test="projectNewNum != null "> and a.project_new_num = #{projectNewNum}</if>
        </where>
        order by a.create_time DESC
    </select>
    
    <select id="selectBmDeptPlanAreaById" parameterType="Long" resultMap="BmDeptPlanAreaResult">
        <include refid="selectBmDeptPlanAreaVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBmDeptPlanArea" parameterType="BmDeptPlanArea" useGeneratedKeys="true" keyProperty="id">
        insert into bm_dept_plan_area
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sysDeptId != null">sys_dept_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="year != null">year,</if>
            <if test="projectMillionNum != null">project_million_num,</if>
            <if test="projectIndustryNum != null">project_industry_num,</if>
            <if test="projectOneNum != null">project_one_num,</if>
            <if test="projectTwoNum != null">project_two_num,</if>
            <if test="projectThrNum != null">project_thr_num,</if>
            <if test="projectFourNum != null">project_four_num,</if>
            <if test="projectFiveNum != null">project_five_num,</if>
            <if test="projectCityMoney != null">project_city_money,</if>
            <if test="projectProNum != null">project_pro_num,</if>
            <if test="projectRisNum != null">project_ris_num,</if>
            <if test="projectSerNum != null">project_ser_num,</if>
            <if test="projectProFiveNum != null">project_pro_five_num,</if>
            <if test="projectInvestmentNum != null">project_investment_num,</if>
            <if test="projectIntegrationNum != null">project_integration_num,</if>
            <if test="projectSmallNum != null">project_small_num,</if>
            <if test="projectNewNum != null">project_new_num,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sysDeptId != null">#{sysDeptId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="year != null">#{year},</if>
            <if test="projectMillionNum != null">#{projectMillionNum},</if>
            <if test="projectIndustryNum != null">#{projectIndustryNum},</if>
            <if test="projectOneNum != null">#{projectOneNum},</if>
            <if test="projectTwoNum != null">#{projectTwoNum},</if>
            <if test="projectThrNum != null">#{projectThrNum},</if>
            <if test="projectFourNum != null">#{projectFourNum},</if>
            <if test="projectFiveNum != null">#{projectFiveNum},</if>
            <if test="projectCityMoney != null">#{projectCityMoney},</if>
            <if test="projectProNum != null">#{projectProNum},</if>
            <if test="projectRisNum != null">#{projectRisNum},</if>
            <if test="projectSerNum != null">#{projectSerNum},</if>
            <if test="projectProFiveNum != null">#{projectProFiveNum},</if>
            <if test="projectInvestmentNum != null">#{projectInvestmentNum},</if>
            <if test="projectIntegrationNum != null">#{projectIntegrationNum},</if>
            <if test="projectSmallNum != null">#{projectSmallNum},</if>
            <if test="projectNewNum != null">#{projectNewNum},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateBmDeptPlanArea" parameterType="BmDeptPlanArea">
        update bm_dept_plan_area
        <trim prefix="SET" suffixOverrides=",">
            <if test="sysDeptId != null">sys_dept_id = #{sysDeptId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="year != null">year = #{year},</if>
            <if test="projectMillionNum != null">project_million_num = #{projectMillionNum},</if>
            <if test="projectIndustryNum != null">project_industry_num = #{projectIndustryNum},</if>
            <if test="projectOneNum != null">project_one_num = #{projectOneNum},</if>
            <if test="projectTwoNum != null">project_two_num = #{projectTwoNum},</if>
            <if test="projectThrNum != null">project_thr_num = #{projectThrNum},</if>
            <if test="projectFourNum != null">project_four_num = #{projectFourNum},</if>
            <if test="projectFiveNum != null">project_five_num = #{projectFiveNum},</if>
            <if test="projectCityMoney != null">project_city_money = #{projectCityMoney},</if>
            <if test="projectProNum != null">project_pro_num = #{projectProNum},</if>
            <if test="projectRisNum != null">project_ris_num = #{projectRisNum},</if>
            <if test="projectSerNum != null">project_ser_num = #{projectSerNum},</if>
            <if test="projectProFiveNum != null">project_pro_five_num = #{projectProFiveNum},</if>
            <if test="projectInvestmentNum != null">project_investment_num = #{projectInvestmentNum},</if>
            <if test="projectIntegrationNum != null">project_integration_num = #{projectIntegrationNum},</if>
            <if test="projectSmallNum != null">project_small_num = #{projectSmallNum},</if>
            <if test="projectNewNum != null">project_new_num = #{projectNewNum},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBmDeptPlanAreaById" parameterType="Long">
        delete from bm_dept_plan_area where id = #{id}
    </delete>

    <delete id="deleteBmDeptPlanAreaByIds" parameterType="String">
        delete from bm_dept_plan_area where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectAreaList"  resultMap="BmDeptPlanAreaResult">
		select ifnull(a.project_million_num,0) as project_million_num, ifnull(a.project_city_money,0) as project_city_money, ifnull(a.project_pro_num,0) as project_pro_num,  d.dept_name
		from bm_dept_plan_area a
		right join sys_dept d on a.sys_dept_id = d.dept_id and a.is_del = '0' and a.year = #{year}
		where d.parent_id = 105
    </select>
        </mapper>