<?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">
<!-- 命名，每一个映射对象不一样
	namespace:必须与对应的接口全类名一致
 -->
<mapper namespace="com.iamberry.rent.service.order.mapper.RentExchangeMapper">
	<insert id="insertRentExchange" parameterType="RentExchangeInfo"
			keyProperty="exchangeId" useGeneratedKeys="true">
		INSERT INTO tb_iamberry_rent_exchange
			(
				EXCHANGE_ITEM_ID,
				EXCHANGE_STATUS,
				EXCHANGE_SEND_DATE,
				EXCHANGE_POST_NUM,
				EXCHANGE_POST_FIRM,
				EXCHANGE_ADDRESS_INFO,
				EXCHANGE_ADDRESS_TEL,
				EXCHANGE_ADDRESS_NAME,
				EXCHANGE_CREATE_DATE,
				EXCHANGE_CHECK_DATE,
				EXCHANGE_REMARK
			)
		VALUES
			(
				#{exchangeItemId},#{exchangeStatus},#{exchangeSendDate},#{exchangePostNum},
				#{exchangePostFirm},#{exchangeAddressInfo},#{exchangeAddressTel},
				#{exchangeAddressName},NOW(),#{exchangeCheckDate},#{exchangeRemark}
			)
	</insert>

	<select id="getExchangeInfoByItemId" parameterType="int" resultType="RentExchangeInfo">
		SELECT
			EXCHANGE_ID exchangeId,
			EXCHANGE_ITEM_ID exchangeItemId,
			EXCHANGE_STATUS exchangeStatus,
			EXCHANGE_SEND_DATE exchangeSendDate,
			EXCHANGE_POST_NUM exchangePostNum,
			EXCHANGE_POST_FIRM exchangePostFirm,
			EXCHANGE_ADDRESS_INFO exchangeAddressInfo,
			EXCHANGE_ADDRESS_TEL exchangeAddressTel,
			EXCHANGE_ADDRESS_NAME exchangeAddressName,
			EXCHANGE_CREATE_DATE exchangeCreateDate,
			EXCHANGE_CHECK_DATE exchangeCheckDate,
			EXCHANGE_REMARK exchangeRemark
		FROM tb_iamberry_rent_exchange
		WHERE EXCHANGE_ITEM_id = #{exchangeItemId}
		<if test="exchangeStatus != null">
			AND EXCHANGE_STATUS = #{exchangeStatus}
		</if>
		ORDER BY EXCHANGE_ID DESC
	</select>

	<update id="updateExchangeById" parameterType="RentExchangeInfo">
		UPDATE tb_iamberry_rent_exchange
		<set>
			<if test="exchangeStatus != null">
				EXCHANGE_STATUS = #{exchangeStatus},
			</if>
			<if test="exchangeSendDate != null and exchangeSendDate != ''">
				EXCHANGE_SEND_DATE = NOW(),
			</if>
			<if test="exchangePostNum != null and exchangePostNum != ''">
				EXCHANGE_POST_NUM = #{exchangePostNum},
			</if>
			<if test="exchangePostFirm != null and exchangePostFirm != ''">
				EXCHANGE_POST_FIRM = #{exchangePostFirm},
			</if>
			<if test="exchangeCheckDate != null and exchangeCheckDate != ''">
				EXCHANGE_CHECK_DATE = #{exchangeCheckDate},
			</if>
			<if test="exchangeRemark != null and exchangeRemark != ''">
				EXCHANGE_REMARK = #{exchangeRemark}
			</if>
		</set>
		WHERE EXCHANGE_ID = #{exchangeId}
	</update>
</mapper>