<?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.CmcContractSubContractMapper">
    
    <resultMap type="CmcContractSubContract" id="CmcContractSubContractResult">
        <result property="contractId"    column="contract_id"    />
        <result property="subContractId"    column="sub_contract_id"    />
    </resultMap>

    <sql id="selectCmcContractSubContractVo">
        select contract_id, sub_contract_id from cmc_contract_sub_contract
    </sql>

    <select id="selectCmcContractSubContractList" parameterType="CmcContractSubContract" resultMap="CmcContractSubContractResult">
        <include refid="selectCmcContractSubContractVo"/>
        <where>
            <if test="contractId != null  and contractId != ''"> and contract_id = #{contractId}</if>
            <if test="subContractId != null  and subContractId != ''"> and sub_contract_id = #{subContractId}</if>
        </where>
    </select>
    
    <select id="selectCmcContractSubContractByContractId" parameterType="String" resultMap="CmcContractSubContractResult">
        <include refid="selectCmcContractSubContractVo"/>
        where contract_id = #{contractId}
    </select>
        
    <insert id="insertCmcContractSubContract" parameterType="CmcContractSubContract">
        insert into cmc_contract_sub_contract
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="contractId != null">contract_id,</if>
            <if test="subContractId != null">sub_contract_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="contractId != null">#{contractId},</if>
            <if test="subContractId != null">#{subContractId},</if>
         </trim>
    </insert>

    <update id="updateCmcContractSubContract" parameterType="CmcContractSubContract">
        update cmc_contract_sub_contract
        <trim prefix="SET" suffixOverrides=",">
            <if test="subContractId != null">sub_contract_id = #{subContractId},</if>
        </trim>
        where contract_id = #{contractId}
    </update>

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

    <delete id="deleteCmcContractSubContractBySubContractIds" parameterType="String">
        delete from cmc_contract_sub_contract where sub_contract_id in
        <foreach item="subContractId" collection="array" open="(" separator="," close=")">
            #{subContractId}
        </foreach>
    </delete>
</mapper>