<?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.TTargetactionMapper">
    
    <resultMap type="TTargetaction" id="TTargetactionResult">
        <result property="id"    column="id"    />
        <result property="targetreviewId"    column="targetreview_id"    />
        <result property="actionItem"    column="action_item"    />
        <result property="principal"    column="principal"    />
        <result property="principalName"    column="name"    />
        <result property="expectedDate"    column="expected_date"    />
        <result property="completionDate"    column="completion_date"    />
        <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"    />
    </resultMap>

    <sql id="selectTTargetactionVo">
        select d.id, d.targetreview_id, d.action_item, d.expected_date, d.completion_date, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.principal, t.name from t_targetaction d
    left join t_staffmgr t on t.staffid = d.principal
    </sql>

    <select id="selectTTargetactionList" parameterType="TTargetaction" resultMap="TTargetactionResult">
        <include refid="selectTTargetactionVo"/>
        <where>  
            <if test="targetreviewId != null "> and targetreview_id = #{targetreviewId}</if>
            and d.del_flag = 0
        </where>
    </select>
    
    <select id="selectTTargetactionById" parameterType="Long" resultMap="TTargetactionResult">
        <include refid="selectTTargetactionVo"/>
        where d.id = #{id}
    </select>
        
    <insert id="insertTTargetaction" parameterType="TTargetaction">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_targetaction.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_targetaction
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="targetreviewId != null">targetreview_id,</if>
            <if test="actionItem != null and actionItem != ''">action_item,</if>
            <if test="principal != null">principal,</if>
            <if test="expectedDate != null">expected_date,</if>
            <if test="completionDate != null">completion_date,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="targetreviewId != null">#{targetreviewId},</if>
            <if test="actionItem != null and actionItem != ''">#{actionItem},</if>
            <if test="principal != null">#{principal},</if>
            <if test="expectedDate != null">#{expectedDate},</if>
            <if test="completionDate != null">#{completionDate},</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>
         </trim>
    </insert>

    <update id="updateTTargetaction" parameterType="TTargetaction">
        update t_targetaction
        <trim prefix="SET" suffixOverrides=",">
            <if test="targetreviewId != null">targetreview_id = #{targetreviewId},</if>
            <if test="actionItem != null and actionItem != ''">action_item = #{actionItem},</if>
            <if test="principal != null">principal = #{principal},</if>
            <if test="expectedDate != null">expected_date = #{expectedDate},</if>
            <if test="completionDate != null">completion_date = #{completionDate},</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>
        </trim>
        where id = #{id}
    </update>

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

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