<?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.oa.mapper.CmcContractWorkMapper">
    
    <resultMap type="CmcContractWork" id="CmcContractWorkResult">
        <result property="workId"    column="work_id"    />
        <result property="contractId"    column="contract_id"    />
        <result property="content"    column="content"    />
        <result property="scale"    column="scale"    />
        <result property="unit"    column="unit"    />
        <result property="workload"    column="workload"    />
        <result property="deadline"    column="deadline"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCmcContractWorkVo">
        select work_id, contract_id, content, scale, unit, workload, deadline, remark from cmc_contract_work
    </sql>

    <select id="selectCmcContractWorkList" parameterType="CmcContractWork" resultMap="CmcContractWorkResult">
        <include refid="selectCmcContractWorkVo"/>
        <where>  
            <if test="contractId != null  and contractId != ''"> and contract_id = #{contractId}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="scale != null  and scale != ''"> and scale = #{scale}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="workload != null  and workload != ''"> and workload = #{workload}</if>
            <if test="deadline != null "> and deadline = #{deadline}</if>
        </where>
    </select>
    
    <select id="selectCmcContractWorkByContractId" parameterType="String" resultMap="CmcContractWorkResult">
        <include refid="selectCmcContractWorkVo"/>
        where contract_id = #{contractId}
    </select>
        
    <insert id="insertCmcContractWork" parameterType="CmcContractWork">
        insert into cmc_contract_work
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workId != null">work_id,</if>
            <if test="contractId != null">contract_id,</if>
            <if test="content != null">content,</if>
            <if test="scale != null">scale,</if>
            <if test="unit != null">unit,</if>
            <if test="workload != null">workload,</if>
            <if test="deadline != null">deadline,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="workId != null">#{workId},</if>
            <if test="contractId != null">#{contractId},</if>
            <if test="content != null">#{content},</if>
            <if test="scale != null">#{scale},</if>
            <if test="unit != null">#{unit},</if>
            <if test="workload != null">#{workload},</if>
            <if test="deadline != null">#{deadline},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCmcContractWork" parameterType="CmcContractWork">
        update cmc_contract_work
        <trim prefix="SET" suffixOverrides=",">
            <if test="contractId != null">contract_id = #{contractId},</if>
            <if test="content != null">content = #{content},</if>
            <if test="scale != null">scale = #{scale},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="workload != null">workload = #{workload},</if>
            <if test="deadline != null">deadline = #{deadline},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where work_id = #{workId}
    </update>

    <delete id="deleteCmcContractWorkByContractId" parameterType="String">
        delete from cmc_contract_work where contract_id = #{contractId}
    </delete>

    <delete id="deleteCmcContractWorkByContractIds" parameterType="String">
        delete from cmc_contract_work where contract_id in 
        <foreach item="contractId" collection="array" open="(" separator="," close=")">
            #{contractId}
        </foreach>
    </delete>
</mapper>