<?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.CmcContractPaidMapper">
    
    <resultMap type="CmcContractPaid" id="CmcContractPaidResult">
        <result property="paidId"    column="paid_id"    />
        <result property="contractId"    column="contract_id"    />
        <result property="paidPercentage"    column="paid_percentage"    />
        <result property="paidAmount"    column="paid_amount"    />
        <result property="paidTime"    column="paid_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCmcContractPaidVo">
        select paid_id, contract_id, paid_percentage, paid_amount, paid_time, remark from cmc_contract_paid
    </sql>

    <select id="selectCmcContractPaidList" parameterType="CmcContractPaid" resultMap="CmcContractPaidResult">
        <include refid="selectCmcContractPaidVo"/>
        <where>  
            <if test="contractId != null  and contractId != ''"> and contract_id = #{contractId}</if>
            <if test="paidPercentage != null  and paidPercentage != ''"> and paid_percentage = #{paidPercentage}</if>
            <if test="paidAmount != null"> and paid_amount = #{paidAmount}</if>
            <if test="paidTime != null "> and paid_time = #{paidTime}</if>
        </where>
    </select>
    
    <select id="selectCmcContractPaidByPaidId" parameterType="Long" resultMap="CmcContractPaidResult">
        <include refid="selectCmcContractPaidVo"/>
        where paid_id = #{paidId}
    </select>
        
    <insert id="insertCmcContractPaid" parameterType="CmcContractPaid" useGeneratedKeys="true" keyProperty="paidId">
        insert into cmc_contract_paid
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="contractId != null">contract_id,</if>
            <if test="paidPercentage != null">paid_percentage,</if>
            <if test="paidAmount != null">paid_amount,</if>
            <if test="paidTime != null">paid_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="contractId != null">#{contractId},</if>
            <if test="paidPercentage != null">#{paidPercentage},</if>
            <if test="paidAmount != null">#{paidAmount},</if>
            <if test="paidTime != null">#{paidTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCmcContractPaid" parameterType="CmcContractPaid">
        update cmc_contract_paid
        <trim prefix="SET" suffixOverrides=",">
            <if test="contractId != null">contract_id = #{contractId},</if>
            <if test="paidPercentage != null">paid_percentage = #{paidPercentage},</if>
            <if test="paidAmount != null">paid_amount = #{paidAmount},</if>
            <if test="paidTime != null">paid_time = #{paidTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where paid_id = #{paidId}
    </update>

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

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