<?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.RentOrderMapper">
	<sql id="rentOrderField">
		RENT_ORDERID rentOrderId,
		RENT_OPENID rentOpenid,
		RENT_AMOUNT rentAmount,
		RENT_PAY_MONEY rentPayMoney,
		RENT_SERVICE_ID rentServiceId,
		RENT_SERVICE_MONEY rentServiceMoney,
		RENT_TYPE_ID rentTypeId,
		RENT_STATUS rentStatus,
		RENT_SEND_DATE rentSendDate,
		RENT_POST_NUM rentPostNum,
		RENT_POST_FIRM rentPostFirm,
		RENT_ADDRESS_INFO rentAddressInfo,
		RENT_ADDRESS_TEL rentAddressTel,
		RENT_ADDRESS_NAME rentAddressName,
		RENT_TRANSACTION_ID rentTransactionId,
		RENT_TRANSACTION_DATE rentTransactionDate,
		RENT_CREATE_DATE rentCreateDate,
		RENT_ADMIN_REMARK rentAdminRemark,
		RENT_USER_REMARK rentUserRemark
	</sql>
	
	<sql id="orderItemInfo">
		ITEM_ID itemId,
		ITEM_ORDER_ID itemOrderId,
		ITEM_PRODUCT_ID itemProductId,
		ITEM_COLOR_ID itemColorId,
		ITEM_STATUS itemStatus,
		RENT_DEPOSIT rentDeposit,
		RENT_IS_OUT rentIsOut,
		RENT_REMAIN_DEPOSIT rentRemainDeposit,
		RENT_PLEDGE_ID rentPledgeId,
		ITEM_RETURN_DATE itemReturnDate,
		ITEM_INIT_CODE itemInitCode,
		ITEM_CODE_STATE itemCodeState,
		ITEM_MACHINE_NUM ItemMachineNum,
		ITEM_USE_YEARS itemUseYears,
		ITEM_PRODUCT_NAME itemProductName,
		ITEM_PRODUCT_PIC itemProductPic,
		ITEM_PRODUCT_TYPE itemProductType,
		ITEM_PRODUCT_COLOR_NAME itemProductColorName,
		ITEM_CREATE_DATE itemCreateDate 
	</sql>

	<!-- 订单详情接口展示 前台-->	
	<select id="listRentOrder" parameterType="com.iamberry.wechat.core.entity.rent.RentOrderDTO" resultMap="rentOrderResult">
		SELECT 
			RENT_ORDERID,
			RENT_AMOUNT ,
			RENT_PAY_MONEY ,
			RENT_SERVICE_ID ,
			RENT_SERVICE_MONEY ,
			RENT_TYPE_ID,
			RENT_STATUS ,
			RENT_SEND_DATE ,
			RENT_POST_NUM ,
			RENT_POST_FIRM ,
			RENT_ADDRESS_INFO ,
			RENT_ADDRESS_TEL ,
			RENT_ADDRESS_NAME ,
			RENT_CREATE_DATE,
			RENT_TRANSACTION_DATE,
			T.TYPE_NAME typeName,
			U.USER_NICKNAME rentUserNickName
		FROM TB_IAMBERRY_RENT_ORDER O 
		LEFT JOIN TB_IAMBERRY_RENT_TYPE T ON O.RENT_TYPE_ID = T.TYPE_ID
		LEFT JOIN TB_IAMBERRY_USER_USERINFO U ON O.RENT_OPENID = U.USER_OPENID
		<where>
			<if test="rentOpenid != null and rentOpenid != ''">
				RENT_OPENID = #{rentOpenid}
			</if>
			<if test="rentOrderId != null and rentOrderId != ''">
				AND RENT_ORDERID LIKE CONCAT('%',#{rentOrderId},'%')
			</if>
			<if test="rentAddressName != null and rentAddressName != ''">
				AND RENT_ADDRESS_NAME LIKE CONCAT('%',#{rentAddressName},'%')
			</if>
			<if test="rentAddressTel != null and rentAddressTel != ''">
				AND RENT_ADDRESS_TEL LIKE CONCAT('%',#{rentAddressTel},'%')
			</if>
			<if test="rentAddressInfo != null and rentAddressInfo != ''">
				AND RENT_ADDRESS_INFO LIKE CONCAT('%',#{rentAddressInfo},'%')
			</if>
			<if test="rentStatus != null and rentStatus != -1">
				AND RENT_STATUS = #{rentStatus}
			</if>
		</where>
		ORDER BY RENT_CREATE_DATE DESC
		<if test="page!=null and page.recordBegin>0 and page.pageSize>0 ">
	     LIMIT ${page.recordBegin},${page.pageSize}
	    </if>
	     <if test="page!=null and page.recordBegin==0 and page.pageSize>0 ">
	     LIMIT ${page.pageSize} 
	    </if>
	</select>
	<resultMap type="com.iamberry.wechat.core.entity.rent.RentOrderDTO" id="rentOrderResult">
		<id property="rentOrderId" column="RENT_ORDERID"/>
		<result property="rentAmount" column="RENT_AMOUNT" />
		<result property="rentPayMoney" column="RENT_PAY_MONEY" />
		<result property="rentServiceId" column="RENT_SERVICE_ID" />
		<result property="rentServiceMoney" column="RENT_SERVICE_MONEY" />
		<result property="rentTypeId" column="RENT_TYPE_ID" />
		
		<result property="rentStatus" column="RENT_STATUS" />
		<result property="rentSendDate" column="RENT_SEND_DATE" />
		<result property="rentPostNum" column="RENT_POST_NUM" />
		<result property="rentPostFirm" column="RENT_POST_FIRM" />
		
		<result property="rentAddressInfo" column="RENT_ADDRESS_INFO" />
		<result property="rentAddressTel" column="RENT_ADDRESS_TEL" />
		<result property="rentAddressName" column="RENT_ADDRESS_NAME" />
		<result property="rentCreateDate" column="RENT_CREATE_DATE" />
		<result property="rentTransactionDate" column="RENT_TRANSACTION_DATE" />
		<collection property="orderItemList" column="RENT_ORDERID" ofType="com.iamberry.wechat.core.entity.rent.RentOrderItemDTO" select="listItemOrder"/>
	</resultMap>
	<select id="listItemOrder" resultType="com.iamberry.wechat.core.entity.rent.RentOrderItemDTO">
		SELECT 
			I.ITEM_ID itemId,
			I.ITEM_PRODUCT_ID itemProductId,
			I.ITEM_COLOR_ID itemColorId,
			I.RENT_DEPOSIT rentDeposit,
			I.ITEM_PRODUCT_NAME itemProductName,
			I.ITEM_PRODUCT_COLOR_NAME itemProductColorName,
			I.ITEM_PRODUCT_TYPE itemProductType,
			I.ITEM_CODE_STATE itemCodeState,
			c.COLOR_69CODE color69Code, 
			c.COLOR_DISCOUNT colorDiscount,
			c.COLOR_PRICE colorPrice 
		FROM TB_IAMBERRY_RENT_ORDER O 
		LEFT JOIN TB_IAMBERRY_RENT_TYPE T ON O.RENT_TYPE_ID = T.TYPE_ID
		LEFT JOIN TB_IAMBERRY_RENT_ORDER_ITEM I ON O.RENT_ORDERID = I.ITEM_ORDER_ID
		LEFT JOIN TB_IAMBERRY_PRODUCT_COLOR c ON c.COLOR_ID = I.ITEM_COLOR_ID 
		WHERE RENT_ORDERID = #{rentOrderid}
	</select>
	<select id="countRentOrder" parameterType="com.iamberry.wechat.core.entity.rent.RentOrderDTO" resultType="Integer">
		SELECT 
			COUNT(RENT_ORDERID)
		FROM TB_IAMBERRY_RENT_ORDER O 
		<where>
			<if test="rentOpenid != null and rentOpenid != ''">
				RENT_OPENID = #{rentOpenid}
			</if>
			<if test="rentOrderId != null and rentOrderId != ''">
				AND RENT_ORDERID LIKE #{rentOrderId}
			</if>
			<if test="rentAddressName != null and rentAddressName != ''">
				AND RENT_ADDRESS_NAME LIKE #{rentAddressName}
			</if>
			<if test="rentAddressTel != null and rentAddressTel != ''">
				AND RENT_ADDRESS_TEL LIKE #{rentAddressTel}
			</if>
			<if test="rentAddressInfo != null and rentAddressInfo != ''">
				AND RENT_ADDRESS_INFO LIKE #{rentAddressInfo}
			</if>
			<if test="rentStatus != null and rentStatus != -1 and rentStatus != 20">
				AND RENT_STATUS = #{rentStatus}
			</if>
			<if test="rentStatus != null and rentStatus == 20">
				AND RENT_STATUS in (2,5)
			</if>
		</where>
	</select>
		
	<!-- list code -->
	<select id="listInitCode" parameterType="String" resultType="RentOrderItem">
		SELECT
			I.ITEM_ID itemId, I.ITEM_INIT_CODE itemInitCode, O.RENT_ORDERID itemOrderId,
			I.ITEM_USE_YEARS itemUseYears, I.ITEM_MACHINE_NUM itemMachineNum, O.RENT_OPENID itemOpenId
		FROM
			TB_IAMBERRY_RENT_ORDER O
		LEFT JOIN
			TB_IAMBERRY_RENT_ORDER_ITEM I
		<!-- 查询没有使用的激活 -->
		ON
			O.RENT_ORDERID = I.ITEM_ORDER_ID
		<!-- 查询用户已支付的订单 -->
		WHERE
			RENT_OPENID = #{openId} AND O.RENT_STATUS = 5 AND I.ITEM_CODE_STATE = 1
	</select>
	
	<!-- 修改订单项信息 -->
	<update id="update" parameterType="RentOrderItem">
		UPDATE
			TB_IAMBERRY_RENT_ORDER_ITEM 
		<set>
			<if test="itemStatus != null">
				ITEM_STATUS = #{itemStatus}, 
			</if>
			<if test="rentDeposit != null">
				RENT_DEPOSIT = #{rentDeposit}, 
			</if>
			<if test="rentIsOut != null">
				RENT_IS_OUT = #{rentIsOut}, 
			</if>
			<if test="rentRemainDeposit != null">
				RENT_REMAIN_DEPOSIT = #{rentRemainDeposit}, 
			</if>
			<if test="itemReturnDate != null">
				ITEM_RETURN_DATE = #{itemReturnDate},
			</if>
			<if test="itemInitCode != null">
				ITEM_INIT_CODE = #{itemInitCode}, 
			</if>
			<if test="itemCodeState != null">
				ITEM_CODE_STATE = #{itemCodeState}, 
			</if>
			<if test="ItemMachineNum != null">
				ITEM_MACHINE_NUM = #{ItemMachineNum}
			</if>
		</set>
		<where>
			<if test="itemId != null and itemId != 0">
				ITEM_ID = #{itemId}
			</if>
			<if test="itemInitCode != null">
				AND ITEM_INIT_CODE = #{itemInitCode}
			</if>
			<if test="itemInitCodeOldState != null">
				AND ITEM_CODE_STATE = #{itemInitCodeOldState}
			</if>
		</where>
	</update>
	
	<!-- 获取最近的激活记录 -->
	<select id="getWaitInit" parameterType="String" resultType="RentOrderItem">
		SELECT
			I.ITEM_ID itemId, I.ITEM_INIT_CODE itemInitCode, i.ITEM_ORDER_ID itemOrderId,
			I.ITEM_USE_YEARS itemUseYears, I.ITEM_MACHINE_NUM itemMachineNum, O.RENT_OPENID itemOpenId
		FROM
			TB_IAMBERRY_RENT_MACHINE_WAIT_INIT w
		LEFT JOIN
			TB_IAMBERRY_RENT_ORDER_ITEM i
		ON
			w.INIT_CODE = i.ITEM_INIT_CODE
		LEFT JOIN
			TB_IAMBERRY_RENT_ORDER O
		ON
			i.ITEM_ORDER_ID = O.RENT_ORDERID
		WHERE 
			INIT_OPENID = #{openId} AND INIT_STATE = 1
		ORDER BY
			INIT_ID DESC
		LIMIT
			0, 1
	</select>
	
	<!-- 添加租赁订单信息 -->
	<insert id="insertRentOrderInfo" parameterType="RentOrder">
		INSERT INTO 
		 	TB_IAMBERRY_RENT_ORDER 
		 		(
			 		RENT_ORDERID, RENT_OPENID, RENT_AMOUNT, RENT_PAY_MONEY, RENT_SERVICE_ID,RENT_SERVICE_MONEY,
			 		RENT_TYPE_ID, RENT_STATUS, RENT_ADDRESS_INFO, RENT_ADDRESS_TEL,
			 		RENT_ADDRESS_NAME,RENT_TRANSACTION_ID,RENT_TRANSACTION_DATE,
			 		RENT_CREATE_DATE,RENT_ADMIN_REMARK,RENT_USER_REMARK 
				)
		 VALUES 
		 		(
		 			#{rentOrderId},#{rentOpenid},#{rentAmount},#{rentPayMoney},#{rentServiceId},#{rentServiceMoney},
					#{rentTypeId},#{rentStatus},#{rentAddressInfo},#{rentAddressTel},
		 			#{rentAddressName},#{rentTransactionId},NOW(),
		 			NOW(),#{rentAdminRemark},#{rentUserRemark}
		 		)
	</insert>
	
	<!-- 插入租赁订单条目信息 -->
	<insert id="insertRentOrderItemList" parameterType="java.util.List">
		INSERT INTO 
		 	TB_IAMBERRY_RENT_ORDER_ITEM 
		 		(
			 		ITEM_ORDER_ID, ITEM_PRODUCT_ID, ITEM_COLOR_ID, ITEM_STATUS, RENT_DEPOSIT,RENT_IS_OUT,
			 		RENT_REMAIN_DEPOSIT, RENT_PLEDGE_ID, ITEM_INIT_CODE, ITEM_CODE_STATE,
			 		ITEM_MACHINE_NUM,ITEM_USE_YEARS,ITEM_PRODUCT_NAME,ITEM_PRODUCT_PIC,
			 		ITEM_PRODUCT_COLOR_NAME,ITEM_CREATE_DATE,ITEM_PRODUCT_TYPE  
				)
		 VALUES 
		  	<foreach collection="list" item="item" separator=",">
				(
					#{item.itemOrderId}, #{item.itemProductId}, #{item.itemColorId}, #{item.itemStatus}, 
					#{item.rentDeposit}, #{item.rentIsOut}, #{item.rentRemainDeposit}, #{item.rentPledgeId},
					#{item.itemInitCode}, #{item.itemCodeState}, #{item.ItemMachineNum}, #{item.itemUseYears}, 
					#{item.itemProductName}, #{item.itemProductPic}, #{item.itemProductColorName}, NOW(),
					#{item.itemProductType} 
				)
	        </foreach>
	</insert>
	
	<!-- 跟据条件查询一条订单项数据 -->
	<select id="getOrderItemByInitCode" parameterType="RentOrderItem" resultType="RentOrderItem">
		SELECT 
			<include refid="orderItemInfo" /> 
		FROM 
			TB_IAMBERRY_RENT_ORDER_ITEM
		<where>
			<if test="itemInitCode != null and itemInitCode != ''">
				ITEM_INIT_CODE = #{itemInitCode}
			</if>
			<if test="itemId != null">
				ITEM_ID = #{itemId}
			</if>
		</where> 
	</select>
	
	<!-- 根据激活码查询订单id -->
	<select id="getOrderIdByInitCode" parameterType="String" resultType="RentOrder">
		SELECT
			O.RENT_OPENID rentOpenid, O.RENT_ORDERID rentOrderId
		FROM
			TB_IAMBERRY_RENT_ORDER_ITEM i
		LEFT JOIN
			TB_IAMBERRY_RENT_ORDER O
		ON
			i.ITEM_ORDER_ID = O.RENT_ORDERID
		WHERE 
			i.ITEM_INIT_CODE = #{itemInitCode}
	</select>
	
	<select id="getRentOrderByOrderId" parameterType="RentOrder" resultMap="rentOrderResultOne">
		SELECT 
			<include refid="rentOrderField" />,
			item_id,
			item_order_id,
			item_product_id,
			item_color_id,
			item_product_type,
			item_status,
			rent_deposit,
			rent_is_out,
			rent_remain_deposit,
			rent_pledge_id,
			item_return_date,
			item_init_code,
			item_code_state,
			item_machine_num,
			item_use_years,
			item_product_name,
			item_product_pic,
			item_product_color_name,
			item_create_date
		FROM
			TB_IAMBERRY_RENT_ORDER
		LEFT JOIN TB_IAMBERRY_RENT_ORDER_ITEM ON RENT_ORDERID = ITEM_ORDER_ID
		WHERE  RENT_ORDERID = #{rentOrderId}
		ORDER BY ITEM_PRODUCT_TYPE ASC
	</select>

	<resultMap type="RentOrder" id="rentOrderResultOne" autoMapping="true">
		<id property="rentOrderId" column="RENT_ORDERID"/>
		<collection property="list" ofType="com.iamberry.wechat.core.entity.rent.RentOrderItem">
			<id property="itemId" column="ITEM_ID"/>
			<result property="itemOrderId" column="ITEM_ORDER_ID"/>
			<result property="itemProductId" column="ITEM_PRODUCT_ID"/>
			<result property="itemColorId" column="ITEM_COLOR_ID"/>
			<result property="itemProductType" column="item_product_type"/>
			<result property="itemStatus" column="item_status"/>
			<result property="rentDeposit" column="rent_deposit"/>
			<result property="rentIsOut" column="rent_is_out"/>
			<result property="rentRemainDeposit" column="rent_remain_deposit"/>
			<result property="rentPledgeId" column="rent_pledge_id"/>
			<result property="itemReturnDate" column="item_return_date"/>
			<result property="itemInitCode" column="item_init_code"/>
			<result property="itemCodeState" column="item_code_state"/>
			<result property="ItemMachineNum" column="item_machine_num"/>
			<result property="itemUseYears" column="item_use_years"/>
			<result property="itemProductName" column="item_product_name"/>
			<result property="itemProductPic" column="item_product_pic"/>
			<result property="itemProductColorName" column="item_product_color_name"/>
			<result property="itemCreateDate" column="item_create_date"/>
		</collection>
	</resultMap>
	
	<select id="listOrderItem" parameterType="RentOrderItem" resultType="RentOrderItem">
		SELECT 
			<include refid="orderItemInfo" /> 
		FROM 
			TB_IAMBERRY_RENT_ORDER_ITEM 
		<where>
			<if test="itemOrderId != null and itemOrderId != ''">
				ITEM_ORDER_ID = #{itemOrderId}
			</if>
		</where> 
	</select>
	
	<!-- 修改订单状态 -->
	<update id="updateRentOrder" parameterType="RentOrder">
		UPDATE 
			TB_IAMBERRY_RENT_ORDER 
		<set>
			<if test="rentStatus != null and rentStatus != ''">
				RENT_STATUS = #{rentStatus}, 
			</if>
			<if test="rentTransactionId != null and rentTransactionId != ''">
				RENT_TRANSACTION_ID = #{rentTransactionId}, 
			</if>
			<if test="rentTransactionDate != null and rentTransactionDate != ''">
				RENT_TRANSACTION_DATE = #{rentTransactionDate}
			</if>
		</set> 
		<where>
				RENT_ORDERID = #{rentOrderId} 
			<if test="rentOldStatus != null and rentOldStatus != ''">
				AND RENT_STATUS = #{rentOldStatus} 
			</if>
		</where>
	</update>
	
	<!-- 修改订单项状态 -->
	<update id="updateOrderItem" parameterType="RentOrderItem">
		UPDATE 
			TB_IAMBERRY_RENT_ORDER_ITEM 
		<set>
			<if test="itemStatus != null and itemStatus != ''">
				ITEM_STATUS = #{itemStatus},
			</if>
			<if test="itemReturnDate != null and itemReturnDate != ''">
				ITEM_RETURN_DATE = #{itemReturnDate}
			</if>
		</set>
		<where>
				ITEM_ORDER_ID = #{itemOrderId}
			<if test="itemId != null and itemId != ''">
				AND item_id = #{itemId}
			</if>
			<if test="itemInitCodeOldState != null and itemInitCodeOldState != ''">
				AND ITEM_STATUS = #{itemInitCodeOldState} 
			</if>
		</where>
	</update>
	<!-- 根据openid查询订单返回订单项 -->
	<select id="getRentOrderByOpenId" parameterType="String" resultType="RentOrderItem">
		SELECT 
		<include refid="orderItemInfo" /> 
		FROM 
			TB_IAMBERRY_RENT_ORDER o left JOIN tb_iamberry_rent_order_item i on o.rent_orderid = i.item_order_id
		where
		
				o.rent_openid = #{rentOpenid}
				and item_product_type = 1
	</select>
	<select id="listRentOrderAdmin" >
		SELECT * FROM TB_IAMBERRY_RENT_ORDER 
		ORDER BY RENT_CREATE_DATE DESC
		<if test="page!=null and page.recordBegin>0 and page.pageSize>0 ">
	     LIMIT ${page.recordBegin},${page.pageSize}
	    </if>
	     <if test="page!=null and page.recordBegin==0 and page.pageSize>0 ">
	     LIMIT ${page.pageSize} 
	    </if>
	</select>

	<update id="updateRentOrderByOrderId"  parameterType="RentOrder">
		UPDATE 
			TB_IAMBERRY_RENT_ORDER 
		<set>
			<if test="rentTypeId != null">
				RENT_TYPE_ID = #{rentTypeId}, 
			</if>
			<if test="rentStatus != null and rentStatus != ''">
				RENT_STATUS = #{rentStatus}, 
			</if>
			<if test="rentSendDate != null and rentSendDate != ''">
				RENT_SEND_DATE = #{rentSendDate}, 
			</if>
			<if test="rentPostNum != null and rentPostNum != ''">
				RENT_POST_NUM = #{rentPostNum}, 
			</if>
			<if test="rentPostFirm != null and rentPostFirm != ''">
				RENT_POST_FIRM = #{rentPostFirm}, 
			</if>
			<if test="rentAddressInfo != null and rentAddressInfo != ''">
				RENT_ADDRESS_INFO = #{rentAddressInfo}, 
			</if>
			<if test="rentAddressTel != null and rentAddressTel != ''">
				RENT_ADDRESS_TEL = #{rentAddressTel},
			</if>
			<if test="rentAddressName != null and rentAddressName != ''">
				RENT_ADDRESS_NAME = #{rentAddressName},
			</if>
			<if test="rentAdminRemark != null and rentAdminRemark != ''">
				RENT_ADMIN_REMARK = #{rentAdminRemark},
			</if>
			<if test="rentUserRemark != null and rentUserRemark != ''">
				RENT_USER_REMARK = #{rentUserRemark}
			</if>
		</set> 
		<where>
			RENT_ORDERID = #{rentOrderId} 
			<if test="rentOldStatus != null and rentOldStatus != ''">
				AND RENT_STATUS = #{rentOldStatus} 
			</if>
		</where>
	</update>
	
	<!-- 根据订单创建时间和状态查询订单信息 -->
	<select id="listOrderByDeadline" parameterType="RentOrder" resultType="RentOrder">
		SELECT 
			* 
		FROM 
			TB_IAMBERRY_RENT_ORDER 
		<where>
			<if test="deadline != null and deadline != ''">
				<![CDATA[ TIMESTAMPDIFF(SECOND,RENT_CREATE_DATE,NOW()) >= #{deadline} ]]> 
			</if>
			<if test="rentStatus != null and rentStatus != ''">
				AND RENT_STATUS = #{rentStatus} 
			</if>
		</where>
	</select>
	
	<!-- 批量修改订单状态 -->
	<update id="updateOrderList" parameterType="java.util.List">
		UPDATE 
			TB_IAMBERRY_RENT_ORDER 
		SET 
			RENT_STATUS = 0 
		WHERE 
			RENT_ORDERID  IN (
				<foreach collection="list" item="item" separator=",">
					#{item} 
		        </foreach>) 
		 AND 
		 	RENT_STATUS = 1 
	</update>
	
	<!-- 批量修改订单项状态 -->
	<update id="updateOrderItemList" parameterType="java.util.List">
		UPDATE 
			TB_IAMBERRY_RENT_ORDER_ITEM 
		SET 
			ITEM_STATUS = 0 
		WHERE 
			ITEM_ORDER_ID  IN (
				<foreach collection="list" item="item" separator=",">
					#{item} 
		        </foreach>) 
		 AND 
		    ITEM_STATUS = 1  
	</update>

	<!-- 根据openid查询订单返回订单项(押金抵扣卷使用) -->
	<select id="selectRentOrderByOpenId" parameterType="String" resultType="RentOrderItem">
		SELECT
		<include refid="orderItemInfo" />
		FROM
		TB_IAMBERRY_RENT_ORDER o left JOIN tb_iamberry_rent_order_item i on o.rent_orderid = i.item_order_id
		where
		o.rent_openid = #{rentOpenid}
		and o.rent_status in (2,5)
		and item_product_type = 1
	</select>
	
	<insert id="addTransferRecord" parameterType="AccountLogsInfo" >
		INSERT INTO
		 	tb_iamberry_rent_account_logs
		 		(
			 		account_order_id,account_open_Id,account_money,account_type,account_remark,account_create_time,transfer_order_no
				)
		 VALUES
		 		(
		 			#{accountOrderId},#{accountOpenId},#{accountMoney},#{accountType},#{accountRemark},
					,NOW(),#{transferOrderNo}
		 		)
	</insert>
</mapper>