<?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.CmcContractMapper">

    <resultMap type="CmcContract" id="CmcContractResult">
        <result property="contractId"    column="contract_id"    />
        <result property="contractNumber"    column="contract_number"    />
        <result property="contractName"    column="contract_name"    />
        <result property="partyA"    column="party_a"    />
        <result property="contactPerson"    column="contact_person"    />
        <result property="telephone"    column="telephone"    />
        <result property="projectType"    column="project_type"    />
        <result property="projectSource"    column="project_source"    />
        <result property="undertakingDept"    column="undertaking_dept"    />
        <result property="amount"    column="amount"    />
        <result property="deposit"    column="deposit"    />
        <result property="contractDocument"    column="contract_document"    />
        <result property="drafter"    column="drafter"    />
        <result property="draftTime"    column="draft_time"    />
        <result property="projectIds"    column="project_ids"    />
        <result property="remark"    column="remark"    />
        <result property="signDate"    column="sign_date"    />
        <result property="signRemark"    column="sign_remark"    />
        <result property="signScan"    column="sign_scan"    />
        <result property="commentType"    column="comment_type"    />
    </resultMap>

    <sql id="selectCmcContractVo">
        select contract_id, contract_number, contract_name, party_a, contact_person, telephone, project_type, project_source, undertaking_dept, amount, deposit, contract_document, drafter, draft_time, project_ids, remark, sign_date, sign_remark, sign_scan, comment_type from cmc_contract
    </sql>

    <select id="selectCmcContractList" parameterType="CmcContract" resultMap="CmcContractResult">
        <include refid="selectCmcContractVo"/>
        <where>
            <if test="contractNumber != null  and contractNumber != ''"> and contract_number like concat('%', #{contractNumber}, '%')</if>
            <if test="contractName != null  and contractName != ''"> and contract_name like concat('%', #{contractName}, '%')</if>
            <if test="partyA != null  and partyA != ''"> and party_a like concat('%', #{partyA}, '%')</if>
            <if test="contactPerson != null  and contactPerson != ''"> and contact_person like concat('%', #{contactPerson}, '%')</if>
            <if test="telephone != null  and telephone != ''"> and telephone like concat('%', #{telephone}, '%')</if>
            <if test="projectType != null  and projectType != ''"> and project_type like concat('%', #{projectType}, '%')</if>
            <if test="projectSource != null  and projectSource != ''"> and project_source = #{projectSource}</if>
            <if test="undertakingDept != null  and undertakingDept != ''"> and undertaking_dept = #{undertakingDept}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="deposit != null "> and deposit = #{deposit}</if>
            <if test="contractDocument != null  and contractDocument != ''"> and contract_document = #{contractDocument}</if>
            <if test="drafter != null "> and drafter = #{drafter}</if>
            <if test="draftTime != null "> and draft_time = #{draftTime}</if>
            <if test="projectIds != null  and projectIds != ''"> and project_ids = #{projectIds}</if>
            <if test="signDate != null "> and sign_date = #{signDate}</if>
            <if test="signRemark != null  and signRemark != ''"> and sign_remark = #{signRemark}</if>
            <if test="signScan != null  and signScan != ''"> and sign_scan = #{signScan}</if>
            <if test="commentType != null  and commentType != ''"> and comment_type = #{commentType}</if>
        </where>
    </select>

    <select id="selectCmcContractByContractId" parameterType="String" resultMap="CmcContractResult">
        <include refid="selectCmcContractVo"/>
        where contract_id = #{contractId}
    </select>

    <insert id="insertCmcContract" parameterType="CmcContract">
        insert into cmc_contract
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="contractId != null">contract_id,</if>
            <if test="contractNumber != null">contract_number,</if>
            <if test="contractName != null">contract_name,</if>
            <if test="partyA != null">party_a,</if>
            <if test="contactPerson != null">contact_person,</if>
            <if test="telephone != null">telephone,</if>
            <if test="projectType != null">project_type,</if>
            <if test="projectSource != null">project_source,</if>
            <if test="undertakingDept != null">undertaking_dept,</if>
            <if test="amount != null">amount,</if>
            <if test="deposit != null">deposit,</if>
            <if test="contractDocument != null">contract_document,</if>
            <if test="drafter != null">drafter,</if>
            <if test="draftTime != null">draft_time,</if>
            <if test="projectIds != null">project_ids,</if>
            <if test="remark != null">remark,</if>
            <if test="signDate != null">sign_date,</if>
            <if test="signRemark != null">sign_remark,</if>
            <if test="signScan != null">sign_scan,</if>
            <if test="commentType != null">comment_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="contractId != null">#{contractId},</if>
            <if test="contractNumber != null">#{contractNumber},</if>
            <if test="contractName != null">#{contractName},</if>
            <if test="partyA != null">#{partyA},</if>
            <if test="contactPerson != null">#{contactPerson},</if>
            <if test="telephone != null">#{telephone},</if>
            <if test="projectType != null">#{projectType},</if>
            <if test="projectSource != null">#{projectSource},</if>
            <if test="undertakingDept != null">#{undertakingDept},</if>
            <if test="amount != null">#{amount},</if>
            <if test="deposit != null">#{deposit},</if>
            <if test="contractDocument != null">#{contractDocument},</if>
            <if test="drafter != null">#{drafter},</if>
            <if test="draftTime != null">#{draftTime},</if>
            <if test="projectIds != null">#{projectIds},</if>
            <if test="remark != null">#{remark},</if>
            <if test="signDate != null">#{signDate},</if>
            <if test="signRemark != null">#{signRemark},</if>
            <if test="signScan != null">#{signScan},</if>
            <if test="commentType != null">#{commentType},</if>
        </trim>
    </insert>

    <update id="updateCmcContract" parameterType="CmcContract">
        update cmc_contract
        <trim prefix="SET" suffixOverrides=",">
            <if test="contractNumber != null">contract_number = #{contractNumber},</if>
            <if test="contractName != null">contract_name = #{contractName},</if>
            <if test="partyA != null">party_a = #{partyA},</if>
            <if test="contactPerson != null">contact_person = #{contactPerson},</if>
            <if test="telephone != null">telephone = #{telephone},</if>
            <if test="projectType != null">project_type = #{projectType},</if>
            <if test="projectSource != null">project_source = #{projectSource},</if>
            <if test="undertakingDept != null">undertaking_dept = #{undertakingDept},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="deposit != null">deposit = #{deposit},</if>
            <if test="contractDocument != null">contract_document = #{contractDocument},</if>
            <if test="drafter != null">drafter = #{drafter},</if>
            <if test="draftTime != null">draft_time = #{draftTime},</if>
            <if test="projectIds != null">project_ids = #{projectIds},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="signDate != null">sign_date = #{signDate},</if>
            <if test="signRemark != null">sign_remark = #{signRemark},</if>
            <if test="signScan != null">sign_scan = #{signScan},</if>
            <if test="commentType != null">comment_type = #{commentType},</if>
        </trim>
        where contract_id = #{contractId}
    </update>

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

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