<?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.jeeplus.test.cw.contractRegistration.mapper.CwWorkContractBorrowMapper">

    <update id="updateStatusById">
        UPDATE cw_work_contract_borrow SET borrow_type = #{borrowType} WHERE del_flag = 0 AND id = #{id}
    </update>
    <update id="updateStatusByContractInfoId">
        UPDATE cw_work_contract_borrow SET borrow_type = #{borrowType} WHERE del_flag = 0 AND contract_info_id = #{id}
    </update>
    <update id="updateMessageByBorrowId">
        UPDATE cw_work_contract_borrow_message SET borrow_type = #{borrowType}
        <if test="type != null and type != ''">
            ,ret_data = NOW()
        </if>
        WHERE del_flag = 0 AND contract_borrow_id = #{id} order by create_date desc limit 1
    </update>
    <update id="deleteMessageById">
        UPDATE cw_work_contract_borrow_message SET del_flag = 1
		WHERE del_flag = 0 AND contract_borrow_id = #{id} order by create_date desc limit 1
    </update>
    <select id="selectFileByContractInfoId"
            resultType="com.jeeplus.test.cw.contractRegistration.domain.CwWorkContractBorrow">
        SELECT * FROM `cw_work_contract_borrow` WHERE del_flag = 0 AND contract_info_id = #{id}
    </select>
    <select id="findMessageList"
            resultType="com.jeeplus.test.cw.contractRegistration.domain.CwWorkContractBorrowMessage">
        SELECT
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			del_flag,
			contract_borrow_id,
			contract_name,
			borrow_name,
			DATE_FORMAT(borrow_data,'%Y-%m-%d') as borrow_data,
			DATE_FORMAT(borrow_ret_data,'%Y-%m-%d') as borrow_ret_data,
			borrow_type,
			DATE_FORMAT( ret_data, '%Y-%m-%d' ) AS ret_data
		 FROM cw_work_contract_borrow_message WHERE del_flag = 0 AND contract_borrow_id = #{id}
		 order by create_date desc
    </select>
</mapper>
