<?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.project.plant.mapper.TTargetmeasuresMapper">
    
    <resultMap type="TTargetmeasures" id="TTargetmeasuresResult">
        <result property="id"    column="id"    />
        <result property="targetlistId"    column="targetlist_id"    />
        <result property="measures"    column="measures"    />
        <result property="responsible"    column="responsible"    />
        <result property="expectedDate"    column="expected_date"    />
        <result property="firstquarter"    column="firstquarter"    />
        <result property="halfyear"    column="halfyear"    />
        <result property="threequarter"    column="threequarter"    />
        <result property="annual"    column="annual"    />
        <result property="firstquarterStatus"    column="firstquarter_status"    />
        <result property="halfyearStatus"    column="halfyear_status"    />
        <result property="threequarterStatus"    column="threequarter_status"    />
        <result property="annualStatus"    column="annual_status"    />
        <result property="firstChecker"    column="first_checker"    />
        <result property="secondChecker"    column="second_checker"    />
        <result property="threeChecker"    column="three_checker"    />
        <result property="annualChecker"    column="annual_checker"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTTargetmeasuresVo">
        select d.id, d.targetlist_id, d.measures, d.responsible, d.expected_date, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks, d.firstquarter, d.halfyear, d.threequarter, d.annual, d.firstquarter_status, d.halfyear_status, d.threequarter_status, d.annual_status, d.first_checker, d.second_checker, d.three_checker, d.annual_checker ,s.dept_name from t_targetmeasures d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTTargetmeasuresList" parameterType="TTargetmeasures" resultMap="TTargetmeasuresResult">
        <include refid="selectTTargetmeasuresVo"/>
        <where>  
            <if test="targetlistId != null "> and targetlist_id = #{targetlistId}</if>
            <if test="measures != null  and measures != ''"> and measures = #{measures}</if>
            <if test="responsible != null  and responsible != ''"> and responsible = #{responsible}</if>
            <if test="expectedDate != null "> and expected_date = #{expectedDate}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by targetlist_id asc, d.id asc
    </select>
    
    <select id="selectTTargetmeasuresById" parameterType="Long" resultMap="TTargetmeasuresResult">
        <include refid="selectTTargetmeasuresVo"/>
        where d.id = #{id}
    </select>

    <select id="selectTTargetmeasuresByListId" parameterType="Long" resultMap="TTargetmeasuresResult">
        <include refid="selectTTargetmeasuresVo"/>
        where d.targetlist_id = #{targetlistId}
    </select>

    <insert id="insertTTargetmeasures" parameterType="TTargetmeasures">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_targetmeasures.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_targetmeasures
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="targetlistId != null">targetlist_id,</if>
            <if test="measures != null">measures,</if>
            <if test="responsible != null">responsible,</if>
            <if test="expectedDate != null">expected_date,</if>
            <if test="firstquarter != null">firstquarter,</if>
            <if test="halfyear != null">halfyear,</if>
            <if test="threequarter != null">threequarter,</if>
            <if test="annual != null">annual,</if>
            <if test="firstquarterStatus != null">firstquarter_status,</if>
            <if test="halfyearStatus != null">halfyear_status,</if>
            <if test="threequarterStatus != null">threequarter_status,</if>
            <if test="annualStatus != null">annual_status,</if>
            <if test="firstChecker != null">first_checker,</if>
            <if test="secondChecker != null">second_checker,</if>
            <if test="threeChecker != null">three_checker,</if>
            <if test="annualChecker != null">annual_checker,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="targetlistId != null">#{targetlistId},</if>
            <if test="measures != null">#{measures},</if>
            <if test="responsible != null">#{responsible},</if>
            <if test="expectedDate != null">#{expectedDate},</if>
            <if test="firstquarter != null">#{firstquarter},</if>
            <if test="halfyear != null">#{halfyear},</if>
            <if test="threequarter != null">#{threequarter},</if>
            <if test="annual != null">#{annual},</if>
            <if test="firstquarterStatus != null">#{firstquarterStatus},</if>
            <if test="halfyearStatus != null">#{halfyearStatus},</if>
            <if test="threequarterStatus != null">#{threequarterStatus},</if>
            <if test="annualStatus != null">#{annualStatus},</if>
            <if test="firstChecker != null">#{firstChecker},</if>
            <if test="secondChecker != null">#{secondChecker},</if>
            <if test="threeChecker != null">#{threeChecker},</if>
            <if test="annualChecker != null">#{annualChecker},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
        </trim>
    </insert>

    <update id="updateTTargetmeasures" parameterType="TTargetmeasures">
        update t_targetmeasures
        <trim prefix="SET" suffixOverrides=",">
            <if test="targetlistId != null">targetlist_id = #{targetlistId},</if>
            <if test="measures != null">measures = #{measures},</if>
            <if test="responsible != null">responsible = #{responsible},</if>
            <if test="expectedDate != null">expected_date = #{expectedDate},</if>
            <if test="firstquarter != null">firstquarter = #{firstquarter},</if>
            <if test="halfyear != null">halfyear = #{halfyear},</if>
            <if test="threequarter != null">threequarter = #{threequarter},</if>
            <if test="annual != null">annual = #{annual},</if>
            <if test="firstquarterStatus != null">firstquarter_status = #{firstquarterStatus},</if>
            <if test="halfyearStatus != null">halfyear_status = #{halfyearStatus},</if>
            <if test="threequarterStatus != null">threequarter_status = #{threequarterStatus},</if>
            <if test="annualStatus != null">annual_status = #{annualStatus},</if>
            <if test="firstquarterStatus == null">firstquarter_status = NULL,</if>
            <if test="halfyearStatus == null">halfyear_status = NULL,</if>
            <if test="threequarterStatus == null">threequarter_status = NULL,</if>
            <if test="annualStatus == null">annual_status = NULL,</if>
            <if test="firstChecker != null">first_checker = #{firstChecker},</if>
            <if test="secondChecker != null">second_checker = #{secondChecker},</if>
            <if test="threeChecker != null">three_checker = #{threeChecker},</if>
            <if test="annualChecker != null">annual_checker = #{annualChecker},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTTargetmeasuresById" parameterType="Long">
        update t_targetmeasures set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTTargetmeasuresByIds" parameterType="String">
        update t_targetmeasures set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>