<?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.CmcContractPaymentMapper">
    
    <resultMap type="CmcContractPayment" id="CmcContractPaymentResult">
        <result property="paymentId"    column="payment_id"    />
        <result property="contractId"    column="contract_id"    />
        <result property="paymentCondition"    column="payment_condition"    />
        <result property="paymentPercentage"    column="payment_percentage"    />
        <result property="paymentAmount"    column="payment_amount"    />
        <result property="paymentTime"    column="payment_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCmcContractPaymentVo">
        select payment_id, contract_id, payment_condition, payment_percentage, payment_amount, payment_time, remark from cmc_contract_payment
    </sql>

    <select id="selectCmcContractPaymentList" parameterType="CmcContractPayment" resultMap="CmcContractPaymentResult">
        <include refid="selectCmcContractPaymentVo"/>
        <where>  
            <if test="contractId != null  and contractId != ''"> and contract_id like concat('%', #{contractId}, '%')</if>
            <if test="paymentCondition != null  and paymentCondition != ''"> and payment_condition = #{paymentCondition}</if>
            <if test="paymentPercentage != null  and paymentPercentage != ''"> and payment_percentage = #{paymentPercentage}</if>
            <if test="paymentAmount != null  and paymentAmount != ''"> and payment_amount = #{paymentAmount}</if>
            <if test="paymentTime != null "> and payment_time = #{paymentTime}</if>
        </where>
    </select>
    
    <select id="selectCmcContractPaymentByPaymentId" parameterType="String" resultMap="CmcContractPaymentResult">
        <include refid="selectCmcContractPaymentVo"/>
        where payment_id = #{paymentId}
    </select>
        
    <insert id="insertCmcContractPayment" parameterType="CmcContractPayment">
        insert into cmc_contract_payment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="paymentId != null">payment_id,</if>
            <if test="contractId != null">contract_id,</if>
            <if test="paymentCondition != null">payment_condition,</if>
            <if test="paymentPercentage != null">payment_percentage,</if>
            <if test="paymentAmount != null">payment_amount,</if>
            <if test="paymentTime != null">payment_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="paymentId != null">#{paymentId},</if>
            <if test="contractId != null">#{contractId},</if>
            <if test="paymentCondition != null">#{paymentCondition},</if>
            <if test="paymentPercentage != null">#{paymentPercentage},</if>
            <if test="paymentAmount != null">#{paymentAmount},</if>
            <if test="paymentTime != null">#{paymentTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCmcContractPayment" parameterType="CmcContractPayment">
        update cmc_contract_payment
        <trim prefix="SET" suffixOverrides=",">
            <if test="contractId != null">contract_id = #{contractId},</if>
            <if test="paymentCondition != null">payment_condition = #{paymentCondition},</if>
            <if test="paymentPercentage != null">payment_percentage = #{paymentPercentage},</if>
            <if test="paymentAmount != null">payment_amount = #{paymentAmount},</if>
            <if test="paymentTime != null">payment_time = #{paymentTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where payment_id = #{paymentId}
    </update>

    <delete id="deleteCmcContractPaymentByPaymentId" parameterType="String">
        delete from cmc_contract_payment where payment_id = #{paymentId}
    </delete>

    <delete id="deleteCmcContractPaymentByPaymentIds" parameterType="String">
        delete from cmc_contract_payment where payment_id in 
        <foreach item="paymentId" collection="array" open="(" separator="," close=")">
            #{paymentId}
        </foreach>
    </delete>
</mapper>