<?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.CmcContractInvoiceMapper">
    
    <resultMap type="CmcContractInvoice" id="CmcContractInvoiceResult">
        <result property="invoiceId"    column="invoice_id"    />
        <result property="contractId"    column="contract_id"    />
        <result property="invoicePercentage"    column="invoice_percentage"    />
        <result property="invoiceAmount"    column="invoice_amount"    />
        <result property="invoiceTime"    column="invoice_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCmcContractInvoiceVo">
        select invoice_id, contract_id, invoice_percentage, invoice_amount, invoice_time, remark from cmc_contract_invoice
    </sql>

    <select id="selectCmcContractInvoiceList" parameterType="CmcContractInvoice" resultMap="CmcContractInvoiceResult">
        <include refid="selectCmcContractInvoiceVo"/>
        <where>  
            <if test="contractId != null  and contractId != ''"> and contract_id = #{contractId}</if>
            <if test="invoicePercentage != null  and invoicePercentage != ''"> and invoice_percentage = #{invoicePercentage}</if>
            <if test="invoiceAmount != null "> and invoice_amount = #{invoiceAmount}</if>
            <if test="invoiceTime != null "> and invoice_time = #{invoiceTime}</if>
        </where>
    </select>
    
    <select id="selectCmcContractInvoiceByInvoiceId" parameterType="Integer" resultMap="CmcContractInvoiceResult">
        <include refid="selectCmcContractInvoiceVo"/>
        where invoice_id = #{invoiceId}
    </select>
        
    <insert id="insertCmcContractInvoice" parameterType="CmcContractInvoice" useGeneratedKeys="true" keyProperty="invoiceId">
        insert into cmc_contract_invoice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="contractId != null">contract_id,</if>
            <if test="invoicePercentage != null">invoice_percentage,</if>
            <if test="invoiceAmount != null">invoice_amount,</if>
            <if test="invoiceTime != null">invoice_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="contractId != null">#{contractId},</if>
            <if test="invoicePercentage != null">#{invoicePercentage},</if>
            <if test="invoiceAmount != null">#{invoiceAmount},</if>
            <if test="invoiceTime != null">#{invoiceTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCmcContractInvoice" parameterType="CmcContractInvoice">
        update cmc_contract_invoice
        <trim prefix="SET" suffixOverrides=",">
            <if test="contractId != null">contract_id = #{contractId},</if>
            <if test="invoicePercentage != null">invoice_percentage = #{invoicePercentage},</if>
            <if test="invoiceAmount != null">invoice_amount = #{invoiceAmount},</if>
            <if test="invoiceTime != null">invoice_time = #{invoiceTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where invoice_id = #{invoiceId}
    </update>

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

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