<?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="org.jeecg.modules.hotelorder.mapper.HotelOrderMapper">

    <resultMap id="orderReq" type="org.jeecg.modules.hotelorder.entity.HotelOrder">
        <id property="id" column="id"/>
        <result property="title" column="title"></result>
        <result property="userName" column="user_name"></result>
        <result property="userPhone" column="user_phone"></result>
        <result property="userAddress" column="user_address"></result>
        <result property="userId" column="user_id"></result>
        <result property="shopId" column="shop_id"></result>
        <result property="leaseTime" column="lease_time"></result>
        <result property="payFee" column="pay_fee"></result>
        <result property="deposit" column="deposit"></result>
        <result property="washPay" column="wash_pay"></result>
        <result property="rentPay" column="rent_pay"></result>
        <result property="orderPay" column="order_pay"></result>
        <collection property="orderDetails"
                    ofType="org.jeecg.modules.hotelorderdetail.entity.HotelOrderDetail"
                    column="id"
                    select="org.jeecg.modules.hotelorderdetail.mapper.HotelOrderDetailMapper.getOrderDetailList">
        </collection>
    </resultMap>

    <resultMap id="orderOneReq" type="org.jeecg.modules.hotelorder.entity.HotelOrder">
        <id property="id" column="id"/>
        <result property="title" column="title"></result>
        <result property="userName" column="user_name"></result>
        <result property="userPhone" column="user_phone"></result>
        <result property="userAddress" column="user_address"></result>
        <result property="userId" column="user_id"></result>
        <result property="shopId" column="shop_id"></result>
        <result property="leaseTime" column="lease_time"></result>
        <result property="payFee" column="pay_fee"></result>
        <result property="deposit" column="deposit"></result>
        <result property="washPay" column="wash_pay"></result>
        <result property="rentPay" column="rent_pay"></result>
        <result property="orderPay" column="order_pay"></result>
        <collection property="orderDetails"
                    ofType="org.jeecg.modules.hotelorderdetail.entity.HotelOrderDetail"
                    column="id"
                    select="org.jeecg.modules.hotelorderdetail.mapper.HotelOrderDetailMapper.getOrderDetailList">
        </collection>
        <collection property="hotelOrderFlows" ofType="org.jeecg.modules.hotelorderflow.entity.HotelOrderFlow"
                    column="type"
                    select="org.jeecg.modules.hotelorderflow.mapper.HotelOrderFlowMapper.getOrderFlowList">
        </collection>
    </resultMap>

    <select id="getOrderOne" resultType="org.jeecg.modules.hotelorder.entity.HotelOrder">
        SELECT a.*,
               (SELECT item_text from sys_dict_item where dict_id = (select id from sys_dict where dict_code = 'order_status') and item_value = a.status) status_dictText,
               (SELECT item_text from sys_dict_item where dict_id = (select id from sys_dict where dict_code = 'hotel_order_type') and item_value = a.type) type_dictText
        FROM hotel_order a WHERE a.del_flag = 0 AND (a.shop_id = #{userId} OR a.user_id = #{userId}) AND a.id = #{id}
    </select>

    <select id="getOrderOne3" resultType="org.jeecg.modules.hotelorder.entity.HotelOrder">
        SELECT a.*,
               (SELECT item_text from sys_dict_item where dict_id = (select id from sys_dict where dict_code = 'order_status') and item_value = a.status) status_dictText,
               (SELECT item_text from sys_dict_item where dict_id = (select id from sys_dict where dict_code = 'hotel_order_type') and item_value = a.type) type_dictText
        FROM hotel_order a WHERE a.del_flag = 0  AND a.id = #{id}
    </select>

    <select id="getOrderOne2" resultType="org.jeecg.modules.hotelorder.entity.HotelOrder">
        SELECT a.*,
               (SELECT item_text from sys_dict_item where dict_id = (select id from sys_dict where dict_code = 'order_status') and item_value = a.status) status_dictText,
               (SELECT item_text from sys_dict_item where dict_id = (select id from sys_dict where dict_code = 'hotel_order_type') and item_value = a.type) type_dictText
        FROM hotel_order a WHERE a.del_flag = 0 AND a.user_id = #{userId} AND a.id = #{id}
    </select>

    <select id="getOrderPage" resultType="org.jeecg.modules.hotelorder.entity.HotelOrder">
        SELECT * FROM hotel_order WHERE order_log_id = #{id}
    </select>


    <select id="getOrderLogPage" resultMap="orderReq">
        SELECT a.* FROM hotel_order a WHERE a.del_flag = 0
        <if test="type != null">
            AND a.type = #{type}
        </if>
        <if test="uid == null">
            AND (a.user_id = #{userId} or a.shop_id = #{userId})
        </if>
        <if test="uid != null">
            AND a.user_id = #{uid}
        </if>
        order by a.create_time desc
    </select>

    <select id="getOrderByUserIdById" resultMap="orderOneReq">
        SELECT * FROM hotel_order WHERE del_flag = 0
        <if test="userId != null">
            AND user_id = #{userId}
        </if>
        <if test="id != null">
            AND id = #{id}
        </if>
    </select>

</mapper>