<?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.CmcDepositMapper">
    
    <resultMap type="CmcDeposit" id="CmcDepositResult">
        <result property="depositId"    column="deposit_id"    />
        <result property="depositType"    column="deposit_type"    />
        <result property="tenderId"    column="tender_id"    />
        <result property="contractId"    column="contract_id"    />
        <result property="returnTime"    column="return_time"    />
        <result property="accountName"    column="account_name"    />
        <result property="accountBank"    column="account_bank"    />
        <result property="cardNumber"    column="card_number"    />
        <result property="depositWay"    column="deposit_way"    />
        <result property="applier"    column="applier"    />
        <result property="applyTime"    column="apply_time"    />
        <result property="applyReason"    column="apply_reason"    />
        <result property="applyDocument"    column="apply_document"    />
        <result property="managerComment"    column="manager_comment"    />
        <result property="managerTime"    column="manager_time"    />
        <result property="managerUserId"    column="manager_user_id"    />
        <result property="remitTime"    column="remit_time"    />
        <result property="cwTime"    column="cw_time"    />
        <result property="backTime"    column="back_time"    />
        <result property="cwComment"    column="cw_comment"    />
        <result property="remitDocument"    column="remit_document"    />
        <result property="cwUserId"    column="cw_user_id"    />
        <association property="applierUser"    javaType="SysUser"         resultMap="ApplierUserResult" />
        <association property="managerUser"    javaType="SysUser"         resultMap="ManagerUserResult" />
        <association property="cwUser"    javaType="SysUser"         resultMap="CwUserResult" />
        <association property="tender"    javaType="CmcTender"         resultMap="CmcTenderResult" />
        <association property="contract"    javaType="CmcContract"         resultMap="CmcContractResult" />
    </resultMap>

    <resultMap type="CmcContract" id="CmcContractResult">
        <result property="contractId"    column="contract_id"    />
        <result property="contractName"    column="contract_name"    />
    </resultMap>

    <resultMap type="CmcTender" id="CmcTenderResult">
        <result property="tenderId"    column="tender_id"    />
        <result property="projectName"    column="project_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ApplierUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="applier_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ManagerUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="manager_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="CwUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="cw_nick_name"    />
    </resultMap>

    <sql id="selectCmcDepositVo">
        select d.deposit_id, d.deposit_type, d.tender_id, t.project_name, d.contract_id, c.contract_name, d.return_time, d.account_name, d.account_bank, d.card_number, d.deposit_way, d.applier, u.nick_name as applier_nick_name,
               d.apply_time, d.apply_reason, d.apply_document, d.manager_time, d.manager_comment, d.manager_user_id, u1.nick_name as manager_nick_name, d.remit_time, d.cw_time, d.back_time, d.cw_comment,
               d.cw_user_id, u2.nick_name as cw_nick_name, d.remit_document from cmc_deposit as d
         left join sys_user as u on u.user_id = d.applier
         left join sys_user as u1 on u1.user_id = d.manager_user_id
         left join sys_user as u2 on u2.user_id = d.cw_user_id
         left join cmc_tender as t on t.tender_id = d.tender_id
         left join cmc_contract as c on c.contract_id = d.contract_id
    </sql>

    <select id="selectCmcDepositList" parameterType="CmcDeposit" resultMap="CmcDepositResult">
        <include refid="selectCmcDepositVo"/>
        <where>  
            <if test="depositType != null  and depositType != ''"> and d.deposit_type = #{depositType}</if>
            <if test="tenderId != null  and tenderId != ''"> and d.tender_id = #{tenderId}</if>
            <if test="contractId != null  and contractId != ''"> and d.contract_id = #{contractId}</if>
            <if test="returnTime != null "> and d.return_time = #{returnTime}</if>
            <if test="accountName != null  and accountName != ''"> and d.account_name like concat('%', #{accountName}, '%')</if>
            <if test="accountBank != null  and accountBank != ''"> and d.account_bank = #{accountBank}</if>
            <if test="cardNumber != null  and cardNumber != ''"> and d.card_number = #{cardNumber}</if>
            <if test="depositWay != null  and depositWay != ''"> and d.deposit_way = #{depositWay}</if>
            <if test="applier != null "> and d.applier = #{applier}</if>
            <if test="applyTime != null "> and d.apply_time = #{applyTime}</if>
            <if test="applyReason != null  and applyReason != ''"> and d.apply_reason = #{applyReason}</if>
            <if test="applyDocument != null  and applyDocument != ''"> and d.apply_document = #{applyDocument}</if>
            <if test="managerTime != null "> and d.manager_time = #{managerTime}</if>
            <if test="managerUserId != null "> and d.manager_user_id = #{managerUserId}</if>
            <if test="remitTime != null "> and d.remit_time = #{remitTime}</if>
            <if test="cwTime != null "> and d.cw_time = #{cwTime}</if>
            <if test="backTime != null "> and d.back_time = #{backTime}</if>
            <if test="cwComment != null  and cwComment != ''"> and d.cw_comment = #{cwComment}</if>
            <if test="cwUserId != null "> and d.cw_user_id = #{cwUserId}</if>
        </where>
        order by d.apply_time desc
    </select>
    
    <select id="selectCmcDepositByDepositId" parameterType="String" resultMap="CmcDepositResult">
        <include refid="selectCmcDepositVo"/>
        where d.deposit_id = #{depositId}
    </select>
        
    <insert id="insertCmcDeposit" parameterType="CmcDeposit">
        insert into cmc_deposit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="depositId != null">deposit_id,</if>
            <if test="depositType != null">deposit_type,</if>
            <if test="tenderId != null">tender_id,</if>
            <if test="contractId != null">contract_id,</if>
            <if test="returnTime != null">return_time,</if>
            <if test="accountName != null">account_name,</if>
            <if test="accountBank != null">account_bank,</if>
            <if test="cardNumber != null">card_number,</if>
            <if test="depositWay != null">deposit_way,</if>
            <if test="applier != null">applier,</if>
            <if test="applyTime != null">apply_time,</if>
            <if test="applyReason != null">apply_reason,</if>
            <if test="applyDocument != null">apply_document,</if>
            <if test="managerComment != null">manager_comment,</if>
            <if test="managerTime != null">manager_time,</if>
            <if test="managerUserId != null">manager_user_id,</if>
            <if test="remitTime != null">remit_time,</if>
            <if test="cwTime != null">cw_time,</if>
            <if test="backTime != null">back_time,</if>
            <if test="cwComment != null">cw_comment,</if>
            <if test="cwUserId != null">cw_user_id,</if>
            <if test="remitDocument != null">remit_document,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="depositId != null">#{depositId},</if>
            <if test="depositType != null">#{depositType},</if>
            <if test="tenderId != null">#{tenderId},</if>
            <if test="contractId != null">#{contractId},</if>
            <if test="returnTime != null">#{returnTime},</if>
            <if test="accountName != null">#{accountName},</if>
            <if test="accountBank != null">#{accountBank},</if>
            <if test="cardNumber != null">#{cardNumber},</if>
            <if test="depositWay != null">#{depositWay},</if>
            <if test="applier != null">#{applier},</if>
            <if test="applyTime != null">#{applyTime},</if>
            <if test="applyReason != null">#{applyReason},</if>
            <if test="applyDocument != null">#{applyDocument},</if>
            <if test="managerComment != null">#{managerComment},</if>
            <if test="managerTime != null">#{managerTime},</if>
            <if test="managerUserId != null">#{managerUserId},</if>
            <if test="remitTime != null">#{remitTime},</if>
            <if test="cwTime != null">#{cwTime},</if>
            <if test="backTime != null">#{backTime},</if>
            <if test="cwComment != null">#{cwComment},</if>
            <if test="cwUserId != null">#{cwUserId},</if>
            <if test="remitDocument != null">#{remitDocument},</if>
         </trim>
    </insert>

    <update id="updateCmcDeposit" parameterType="CmcDeposit">
        update cmc_deposit
        <trim prefix="SET" suffixOverrides=",">
            <if test="depositType != null">deposit_type = #{depositType},</if>
            <if test="tenderId != null">tender_id = #{tenderId},</if>
            <if test="contractId != null">contract_id = #{contractId},</if>
            <if test="returnTime != null">return_time = #{returnTime},</if>
            <if test="accountName != null">account_name = #{accountName},</if>
            <if test="accountBank != null">account_bank = #{accountBank},</if>
            <if test="cardNumber != null">card_number = #{cardNumber},</if>
            <if test="depositWay != null">deposit_way = #{depositWay},</if>
            <if test="applier != null">applier = #{applier},</if>
            <if test="applyTime != null">apply_time = #{applyTime},</if>
            <if test="applyReason != null">apply_reason = #{applyReason},</if>
            <if test="applyDocument != null">apply_document = #{applyDocument},</if>
            <if test="managerComment != null">manager_comment = #{managerComment},</if>
            <if test="managerTime != null">manager_time = #{managerTime},</if>
            <if test="managerUserId != null">manager_user_id = #{managerUserId},</if>
            <if test="remitTime != null">remit_time = #{remitTime},</if>
            <if test="cwTime != null">cw_time = #{cwTime},</if>
            <if test="backTime != null">back_time = #{backTime},</if>
            <if test="cwComment != null">cw_comment = #{cwComment},</if>
            <if test="cwUserId != null">cw_user_id = #{cwUserId},</if>
            <if test="remitDocument != null">remit_document = #{remitDocument},</if>
        </trim>
        where deposit_id = #{depositId}
    </update>

    <delete id="deleteCmcDepositByDepositId" parameterType="String">
        delete from cmc_deposit where deposit_id = #{depositId}
    </delete>

    <delete id="deleteCmcDepositByDepositIds" parameterType="String">
        delete from cmc_deposit where deposit_id in 
        <foreach item="depositId" collection="array" open="(" separator="," close=")">
            #{depositId}
        </foreach>
    </delete>
</mapper>