<?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.CmcProjectSubContractMapper">
    
    <resultMap type="CmcProjectSubContract" id="CmcProjectSubContractResult">
        <result property="projectId"    column="project_id"    />
        <result property="subContractId"    column="sub_contract_id"    />
    </resultMap>

    <sql id="selectCmcProjectSubContractVo">
        select project_id, sub_contract_id from cmc_project_sub_contract
    </sql>

    <select id="selectCmcProjectSubContractList" parameterType="CmcProjectSubContract" resultMap="CmcProjectSubContractResult">
        <include refid="selectCmcProjectSubContractVo"/>
        <where>
            <if test="projectId != null  and projectId != ''"> and project_id = #{projectId}</if>
            <if test="subContractId != null  and subContractId != ''"> and sub_contract_id = #{subContractId}</if>
        </where>
    </select>
    
    <select id="selectCmcProjectSubContractByProjectId" parameterType="String" resultMap="CmcProjectSubContractResult">
        <include refid="selectCmcProjectSubContractVo"/>
        where project_id = #{projectId}
    </select>
        
    <insert id="insertCmcProjectSubContract" parameterType="CmcProjectSubContract">
        insert into cmc_project_sub_contract
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="subContractId != null">sub_contract_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectId != null">#{projectId},</if>
            <if test="subContractId != null">#{subContractId},</if>
         </trim>
    </insert>

    <update id="updateCmcProjectSubContract" parameterType="CmcProjectSubContract">
        update cmc_project_sub_contract
        <trim prefix="SET" suffixOverrides=",">
            <if test="subContractId != null">sub_contract_id = #{subContractId},</if>
        </trim>
        where project_id = #{projectId}
    </update>

    <delete id="deleteCmcProjectSubContractByProjectId" parameterType="String">
        delete from cmc_project_sub_contract where project_id = #{projectId}
    </delete>

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