<?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.workContract.mapper.WorkContractBorrowMapper">

	<update id="updateStatusById">
		UPDATE work_contract_borrow SET borrow_type = #{borrowType} WHERE del_flag = 0 AND id = #{id}
	</update>

	<update id="updateStatusByContractInfoId">
		UPDATE work_contract_borrow SET borrow_type = #{borrowType} WHERE del_flag = 0 AND contract_info_id = #{id}
	</update>

	<select id="selectFileByContractInfoId" resultType="com.jeeplus.test.workContract.domain.WorkContractBorrow">
		SELECT * FROM `work_contract_borrow` WHERE del_flag = 0 AND contract_info_id = #{id}
	</select>

	<update id="updateMessageByBorrowId">
		UPDATE 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 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="findMessageList" resultType="com.jeeplus.test.workContract.domain.WorkContractBorrowMessage">
		SELECT
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			del_flag,
			contract_borrow_id,
			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 work_contract_borrow_message WHERE del_flag = 0 AND contract_borrow_id = #{id}
		 order by create_date desc
	</select>
</mapper>
