<?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.TTargetyardstickMapper">
    
    <resultMap type="TTargetyardstick" id="TTargetyardstickResult">
        <result property="id"    column="id"    />
        <result property="agreementId"    column="agreement_id"    />
        <result property="target"    column="target"    />
        <result property="achieveDate"    column="achieve_date"    />
        <result property="yardstick"    column="yardstick"    />
        <result property="partners"    column="partners"    />
        <result property="weighing"    column="weighing"    />
        <result property="assessment"    column="assessment"    />
        <result property="category"    column="category"    />
        <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="selectTTargetyardstickVo">
        select d.id, d.agreement_id, d.target, d.achieve_date, d.yardstick, d.partners, d.weighing, d.assessment, d.category, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate from t_targetyardstick d
    </sql>

    <select id="selectTTargetyardstickList" parameterType="TTargetyardstick" resultMap="TTargetyardstickResult">
        <include refid="selectTTargetyardstickVo"/>
        <where>  
            <if test="agreementId != null "> and agreement_id = #{agreementId}</if>
            and d.del_flag = 0
        </where>
    </select>
    
    <select id="selectTTargetyardstickById" parameterType="Long" resultMap="TTargetyardstickResult">
        <include refid="selectTTargetyardstickVo"/>
        where id = #{id}
    </select>

    <select id="selectTTargetyardstickByAgreementId" parameterType="Long" resultMap="TTargetyardstickResult">
        <include refid="selectTTargetyardstickVo"/>
        where agreement_id = #{agreementId}
        and d.del_flag = 0
    </select>
        
    <insert id="insertTTargetyardstick" parameterType="TTargetyardstick">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_targetyardstick.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_targetyardstick
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="agreementId != null">agreement_id,</if>
            <if test="target != null">target,</if>
            <if test="achieveDate != null">achieve_date,</if>
            <if test="yardstick != null">yardstick,</if>
            <if test="partners != null">partners,</if>
            <if test="weighing != null">weighing,</if>
            <if test="assessment != null">assessment,</if>
            <if test="category != null">category,</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="agreementId != null">#{agreementId},</if>
            <if test="target != null">#{target},</if>
            <if test="achieveDate != null">#{achieveDate},</if>
            <if test="yardstick != null">#{yardstick},</if>
            <if test="partners != null">#{partners},</if>
            <if test="weighing != null">#{weighing},</if>
            <if test="assessment != null">#{assessment},</if>
            <if test="category != null">#{category},</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="updateTTargetyardstick" parameterType="TTargetyardstick">
        update t_targetyardstick
        <trim prefix="SET" suffixOverrides=",">
            <if test="agreementId != null">agreement_id = #{agreementId},</if>
            <if test="target != null">target = #{target},</if>
            <if test="achieveDate != null">achieve_date = #{achieveDate},</if>
            <if test="yardstick != null">yardstick = #{yardstick},</if>
            <if test="partners != null">partners = #{partners},</if>
            <if test="weighing != null">weighing = #{weighing},</if>
            <if test="assessment != null">assessment = #{assessment},</if>
            <if test="category != null">category = #{category},</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="deleteTTargetyardstickById" parameterType="Long">
        update t_targetyardstick set del_flag = 2 where id = #{id}
    </update>

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