<?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.ruoyi.ss.order.mapper.OrderMapper">

    <resultMap type="OrderVO" id="RlOrderResult" autoMapping="true"/>

    <sql id="selectRlOrderVo">
        select order_id, order_no, user_id, user_name, real_name, phone, rule_id, gate_mac, gate_mac2, gate_sn, gate_id, room_mac, room_mac2, room_sn, picture, pay_time, pay_type,
               paid, pay_id, type, re_type, total_fee, pay_fee, deposit, deposit_refund, refund, refund_time, is_refund, platform_service_fee, mark, duration, status, create_time,
               change_reason, pay_channel, channel_name, channel_cost, store_name, lng,lat, store_id, merchant_id, original_order_no, price, `explain`, auto_cancel_time,
               is_send_msg, room_id,equipment_id, equipment_type,equipment_name, room_name, room_type, room_type2, mode, hours, reserve_start_time, reserve_end_time,
               wifi, wifi_password, manager_phone, deposit_refund_desc, product_id, product_name from ss_order
    </sql>

    <sql id="selectRlOrderDetail">
        SELECT
            o.order_id,
            o.order_no,
            o.user_id,
            o.user_name,
            o.real_name,
            o.phone,
            o.rule_id,
            o.gate_mac,
            o.gate_mac2,
            o.gate_sn,
            o.gate_id,
            o.room_mac,
            o.room_mac2,
            o.room_sn,
            o.picture,
            o.pay_time,
            o.pay_type,
            o.paid,
            o.pay_id,
            o.type,
            o.re_type,
            o.total_fee,
            o.pay_fee,
            o.deposit,
            o.deposit_refund,
            o.refund,
            o.refund_time,
            o.is_refund,
            o.platform_service_fee,
            o.mark,
            o.duration,
            o.status,
            o.create_time,
            o.change_reason,
            o.pay_channel,
            o.channel_name,
            o.channel_cost,
            o.store_name,
            o.lng,
            o.lat,
            o.store_id,
            o.merchant_id,
            m.user_name AS merchantName,
            m.phonenumber AS merchantPhone,
            o.original_order_no,
            o.price,
            o.`explain`,
            o.auto_cancel_time,
            o.is_send_msg,
            o.room_id,
            o.room_name,
            o.room_type,
            o.room_type2,
            o.equipment_id,
            o.equipment_type,
            o.equipment_name,
            o.mode,
            o.hours,
            ro.picture,
            ROUND(o.price / o.hours, 1) AS hourPrice,
            o.reserve_start_time,
            o.reserve_end_time,
            o.wifi,
            o.wifi_password,
            o.manager_phone,
            o.product_name,
            o.product_id,
            o.deposit_refund_desc
        FROM
            ss_order o
                left join ss_user u on o.user_id = u.user_id
                left join ss_user m on o.merchant_id = m.user_id
                left join ss_fee_rule r on o.rule_id = r.rule_id
                left join ss_room ro on o.room_id = ro.room_id
    </sql>

    <sql id="selectInProgressOrder">
        select
            o.order_no,
            o.room_id,
            o.room_name,
            o.store_id,
            o.gate_id,
            o.gate_mac,
            o.gate_mac2,
            o.gate_sn,
            o.store_name,
            o.reserve_start_time,
            o.reserve_end_time,
            o.re_type,
            r.picture,
            o.room_type2,
            s.unlock_mode gateUnlockMode,
            s.unlock_time gateUnlockTime
        from ss_order o
        left join ss_room r on r.room_id = o.room_id
        left join ss_store s on s.store_id = o.store_id
    </sql>

    <sql id="isUsing">
        (
            !(
                o.reserve_start_time is null or o.reserve_start_time > now()
            ) and !(<include refid="isFinished"/>)
        )
    </sql>

    <sql id="isFinished">
        (
            o.reserve_end_time is not null and o.reserve_end_time &lt;= now()
        )
    </sql>
    <sql id="searchCondition">
        <if test="orderNo != null and orderNo != ''"> and o.order_no like concat('%', #{orderNo}, '%')</if>
        <if test="userId != null"> and o.user_id = #{userId}</if>
        <if test="userName != null and userName != ''"> and u.user_name like concat('%', #{userName}, '%')</if>
        <if test="realName != null and realName != ''"> and o.real_name like concat('%', #{realName}, '%')</if>
        <if test="phone != null and phone != ''"> and o.phone like concat('%', #{phone}, '%')</if>
        <if test="ruleId != null"> and o.rule_id = #{ruleId}</if>
        <if test="payTime != null"> and o.pay_time = #{payTime}</if>
        <if test="payType != null and payType != ''"> and o.pay_type = #{payType}</if>
        <if test="paid != null and paid != ''"> and o.paid = #{paid}</if>
        <if test="type != null and type != ''"> and o.type = #{type}</if>
        <if test="totalFee != null"> and o.total_fee = #{totalFee}</if>
        <if test="payFee != null"> and o.pay_fee = #{payFee}</if>
        <if test="deposit != null"> and o.deposit = #{deposit}</if>
        <if test="depositRefund != null"> and o.deposit_refund = #{depositRefund}</if>
        <if test="refund != null"> and o.refund = #{refund}</if>
        <if test="refundTime != null"> and o.refund_time = #{refundTime}</if>
        <if test="isRefund != null"> and o.is_refund = #{isRefund}</if>
        <if test="mark != null and mark != ''"> and o.mark = #{mark}</if>
        <if test="duration != null"> and o.duration = #{duration}</if>
        <if test="status != null and status != ''"> and o.status = #{status}</if>
        <if test="payChannel != null"> and o.pay_channel = #{payChannel}</if>
        <if test="storeId != null"> and o.store_id = #{storeId}</if>
        <if test="roomId != null"> and o.room_id = #{roomId}</if>
        <if test="equipmentId != null"> and o.equipment_id = #{equipmentId}</if>
        <if test="storeName != null and storeName != ''"> and o.store_name = #{storeName}</if>
        <if test="merchantId != null"> and o.merchant_id = #{merchantId}</if>
        <if test="originalOrderNo != null and originalOrderNo != ''"> and o.original_order_no = #{originalOrderNo}</if>
        <if test="startTime != null and startTime != ''"><!-- 开始时间检索 -->
            and date_format(o.create_time,'%Y%m%d') &gt;= date_format(#{startTime},'%Y%m%d')
        </if>
        <if test="endTime != null and endTime != ''">
            and date_format(o.create_time,'%Y%m%d') &lt;= date_format(#{endTime},'%Y%m%d')
        </if>
        <if test="payStartTime != null "> and date(o.pay_time) >= #{payStartTime}</if>
        <if test="payEndTime != null "> and date(o.pay_time) &lt;= #{payEndTime}</if>
        <if test="keywords != null and keywords != ''">
            AND (o.phone LIKE CONCAT('%', #{keywords}, '%') OR o.order_no LIKE CONCAT('%', #{keywords}, '%'))
        </if>
        <if test="statusList != null and  statusList !=''">
            AND o.status IN
            <foreach item="item" index="index" collection="statusList" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="isUsing != null">
            <if test="isUsing">
                and <include refid="isUsing"/>
            </if>
            <if test="!isUsing">
                and !<include refid="isUsing"/>
            </if>
        </if>
        <if test="isFinished != null">
            <if test="isFinished">
                and <include refid="isFinished"/>
            </if>
            <if test="!isFinished">
                and !<include refid="isFinished"/>
            </if>
        </if>
    </sql>

    <select id="selectRlOrderList" parameterType="OrderQuery" resultMap="RlOrderResult">
        <include refid="selectRlOrderDetail"/>
        <where>
            <include refid="searchCondition"/>
        </where>
        ${params.dataScope}
        order by o.create_time desc
    </select>

    <select id="selectAllRlOrderList" parameterType="OrderQuery" resultMap="RlOrderResult">
        <include refid="selectRlOrderVo"/>
        <where>
            <if test="orderNo != null and orderNo != ''"> and order_no = #{orderNo}</if>
            <if test="userId != null"> and user_id = #{userId}</if>
            <if test="userName != null and userName != ''"> and u.user_name like concat('%', #{userName}, '%')</if>
            <if test="realName != null and realName != ''"> and o.real_name like concat('%', #{realName}, '%')</if>
            <if test="phone != null and phone != ''"> and u.phone like concat('%', #{phone}, '%')</if>
            <if test="status != null and status != ''"> and status = #{status}</if>
            <if test="paid != null and paid != ''"> and paid = #{paid}</if>
        </where>
    </select>

    <select id="selectRlOrderByOrderId" parameterType="Long" resultMap="RlOrderResult">
        <include refid="selectRlOrderDetail"/>
        where o.order_id = #{orderId}
    </select>

    <select id="selectRlOrderByOrderNo" parameterType="String" resultMap="RlOrderResult">
        <include refid="selectRlOrderDetail"/>
        where o.order_no = #{orderNo}
    </select>

    <select id="getInProgressOrder" resultType="integer">
        select count(1) from ss_order o
        where o.room_id = #{roomId} and o.status = 3
        order by create_time desc
    </select>

    <select id="getInProgressOrderByIds" resultType="integer" parameterType="List">
        select count(1) from ss_order o
        where o.room_id in
        <foreach collection="list" item="roomId" open="(" separator="," close=")">
            #{roomId}
        </foreach>
        and o.status = 3
        order by create_time desc
    </select>

    <select id="getInProgressOrderList" resultMap="RlOrderResult">
        <include refid="selectInProgressOrder"/>
        where o.room_id = #{roomId} and o.status = 3
        order by o.create_time desc
    </select>

    <select id="getInProgressOrderListByUserId" resultMap="RlOrderResult">
        <include refid="selectInProgressOrder"/>
        where o.user_id = #{userId} and o.status in (1,2,3)
        order by o.create_time desc
    </select>

    <select id="getHistoricalOrderListByUserId" resultType="com.ruoyi.ss.order.domain.OrderVO">
        select
            o.order_no
        from ss_order o
        where o.user_id = #{userId}
    </select>

<!--    <select id="getOrderFee" resultType="java.math.BigDecimal">-->
<!--        select COALESCE(SUM(pay_fee), 0) payFee from ss_order where status = 8-->
<!--        <if test="startDateStr != null  and startDateStr != ''">-->
<!--            AND date_format(pay_time,'%Y%m%d%H%i%s') &gt;= date_format(#{startDateStr},'%Y%m%d%H%i%s')-->
<!--        </if>-->
<!--        <if test="endDateStr != null  and endDateStr != ''">-->
<!--            AND date_format(pay_time,'%Y%m%d%H%i%s') &lt;= date_format(#{endDateStr},'%Y%m%d%H%i%s')-->
<!--        </if>-->
<!--        <if test="merchantId != null">and merchant_id = #{merchantId}</if>-->
<!--    </select>-->

    <select id="getOrderNum" resultType="java.lang.Integer">
        select count(DISTINCT order_id) from ss_order where status not in('5', '6') and paid = 1
        <if test="startTime != null">
            AND pay_time >= #{startTime}
        </if>
        <if test="endTime != null">
            AND pay_time &lt; #{endTime}
        </if>
        <if test="merchantId != null">and merchant_id = #{merchantId}</if>
    </select>

    <select id="selectSoldNum" resultType="java.lang.Integer">
        select count(1) from ss_order where status in (1,2,3,4,7,8,9) and room_id = #{roomId}
    </select>

    <select id="selectReservedTimes" resultType="ReservedTimePeriod">
        select
            o.reserve_start_time startTime,
            o.reserve_end_time endTime
        from ss_order o
        where room_id = #{roomId}
        and o.status in('2','3')
        and o.reserve_start_time &lt; #{endTime}
        and o.reserve_end_time  &gt; #{startTime}
        ORDER BY o.reserve_start_time
    </select>

    <select id="isReserved" resultType="java.lang.Integer">
        select
            count(1)
        from ss_order o
        where room_id = #{roomId}
          and o.status in('2','3')
          and o.reserve_start_time &lt; #{startTime}
          and o.reserve_end_time  &gt; #{endTime}
        ORDER BY o.reserve_start_time
    </select>

    <select id="selectEndOrderList" resultMap="RlOrderResult">
        SELECT o.order_no,
               o.store_id,
               o.merchant_id,
               o.room_id,
               o.room_name,
               o.is_send_msg,
               u.phonenumber merchantPhone
        FROM ss_order o
                 left join ss_user u on u.user_id = o.merchant_id
        WHERE o.status IN (2, 3)
        AND o.reserve_end_time &lt;= now()
    </select>

    <select id="selectToeUsedOrderList" resultMap="RlOrderResult">
        SELECT o.order_no,
               o.store_id,
               o.merchant_id,
               o.room_id,
               o.room_name,
               u.phonenumber merchantPhone,
               o.reserve_start_time reserveStartTime,
               o.reserve_end_time reserveEndTime
        FROM ss_order o
                 left join ss_user u on u.user_id = o.merchant_id
        WHERE o.status = 2 AND o.reserve_start_time &lt;= now()
        AND o.reserve_end_time > now() AND o.paid = 3 AND pay_id is not null
    </select>

    <select id="selectNotRefundedOrderList" resultMap="RlOrderResult">
        SELECT
            o.order_no,
            o.deposit_refund,
            o.pay_fee,
            p.pay_no
        FROM
            ss_order o
        left join ss_pay_bill p on p.pay_id = o.pay_id
        WHERE
            o.is_refund = '0'
          AND o.mode = '1'
          AND o.refund_time IS NOT NULL
          AND p.status = '3'
    </select>

    <select id="getCount" parameterType="OrderQuery" resultType="java.lang.Integer">
        select count(1) from ss_order o
        <where>
            <include refid="searchCondition"/>
        </where>
    </select>

    <select id="getOrderFee" parameterType="OrderQuery" resultType="java.math.BigDecimal">
        select COALESCE(SUM(pay_fee), 0) payFee from ss_order o
        <where>
            <include refid="searchCondition"/>
        </where>
    </select>

    <select id="getReconciliation" parameterType="IndexChartQuery" resultType="IndexInCome">
        SELECT
            DATE(o.pay_time) AS day,
            COALESCE(SUM(CASE WHEN o.pay_fee > 0 THEN o.pay_fee ELSE 0 END), 0) AS orderIncome,
            COALESCE(SUM(o.refund), 0) AS refund,
            COALESCE(SUM(
            CASE
            WHEN o.pay_fee > COALESCE(o.refund, 0) THEN o.pay_fee - COALESCE(o.refund, 0)
            ELSE 0
            END
            ), 0) AS actualPayment
        FROM ss_order o
        WHERE DATE(o.pay_time) = #{startTime}
        GROUP BY DATE(o.pay_time);
    </select>

    <select id="getInComeList" parameterType="OrderQuery" resultType="com.ruoyi.system.domain.vo.InCome">
        SELECT
            DATE_FORMAT(o.pay_time, '%Y-%m-%d') as day,
            COALESCE(SUM(pay_fee), 0) as orderIncome,
            COALESCE(COUNT(DISTINCT o.order_no), 0) as orderNum
        FROM
            ss_order o
        <where>
            <include refid="searchCondition"/>
        </where>
        GROUP BY
            DATE_FORMAT(o.pay_time, '%Y-%m-%d')
        ORDER BY
            day ASC
    </select>

    <insert id="insertRlOrder" parameterType="Order" useGeneratedKeys="true" keyProperty="orderId">
        insert into ss_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">order_no,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null and userName != ''">user_name,</if>
            <if test="realName != null and realName != ''">real_name,</if>
            <if test="phone != null and phone != ''">phone,</if>
            <if test="ruleId != null">rule_id,</if>
            <if test="gateMac != null">gate_mac,</if>
            <if test="gateSn != null">gate_sn,</if>
            <if test="gateId != null">gate_id,</if>
            <if test="roomMac != null">room_mac,</if>
            <if test="roomSn != null">room_sn,</if>
            <if test="picture != null">picture,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="payType != null">pay_type,</if>
            <if test="paid != null and paid != ''">paid,</if>
            <if test="payId != null and payId != ''">pay_id,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="reType != null and reType != ''">re_type,</if>
            <if test="totalFee != null">total_fee,</if>
            <if test="payFee != null">pay_fee,</if>
            <if test="deposit != null">deposit,</if>
            <if test="depositRefund != null">deposit_refund,</if>
            <if test="refund != null">refund,</if>
            <if test="refundTime != null">refund_time,</if>
            <if test="isRefund != null">is_refund,</if>
            <if test="platformServiceFee != null">platform_service_fee,</if>
            <if test="mark != null">mark,</if>
            <if test="duration != null">duration,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="changeReason != null">change_reason,</if>
            <if test="payChannel != null">pay_channel,</if>
            <if test="channelCost != null">channel_cost,</if>
            <if test="storeId != null">store_id,</if>
            <if test="storeName != null">store_name,</if>
            <if test="lng != null">lng,</if>
            <if test="lat != null">lat,</if>
            <if test="merchantId != null">merchant_id,</if>
            <if test="originalOrderNo != null">original_order_no,</if>
            <if test="price != null">price,</if>
            <if test="explain != null">`explain`,</if>
            <if test="autoCancelTime != null">auto_cancel_time,</if>
            <if test="isSendMsg != null">is_send_msg,</if>
            <if test="roomId != null">room_id,</if>
            <if test="roomName != null">room_name,</if>
            <if test="roomType != null">room_type,</if>
            <if test="roomType2 != null">room_type2,</if>
            <if test="equipmentId != null">equipment_id,</if>
            <if test="equipmentType != null">equipment_type,</if>
            <if test="equipmentName != null">equipment_name,</if>
            <if test="mode != null">mode,</if>
            <if test="hours != null">hours,</if>
            <if test="reserveStartTime != null">reserve_start_time,</if>
            <if test="reserveEndTime != null">reserve_end_time,</if>
            <if test="wifi != null">wifi,</if>
            <if test="wifiPassword != null">wifi_password,</if>
            <if test="managerPhone != null">manager_phone,</if>
            <if test="productId != null">product_id,</if>
            <if test="productName != null">product_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">#{orderNo},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null and userName != ''">#{userName},</if>
            <if test="realName != null and realName != ''">#{realName},</if>
            <if test="phone != null and phone != ''">#{phone},</if>
            <if test="ruleId != null">#{ruleId},</if>
            <if test="gateMac != null">#{gateMac},</if>
            <if test="gateSn != null">#{gateSn},</if>
            <if test="gateId != null">#{gateId},</if>
            <if test="roomMac != null">#{roomMac},</if>
            <if test="roomSn != null">#{roomSn},</if>
            <if test="picture != null">#{picture},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="payType != null">#{payType},</if>
            <if test="paid != null and paid != ''">#{paid},</if>
            <if test="payId != null and payId != ''">#{payId},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="reType != null and reType != ''">#{reType},</if>
            <if test="totalFee != null">#{totalFee},</if>
            <if test="payFee != null">#{payFee},</if>
            <if test="deposit != null">#{deposit},</if>
            <if test="depositRefund != null">#{depositRefund},</if>
            <if test="refund != null">#{refund},</if>
            <if test="refundTime != null">#{refundTime},</if>
            <if test="isRefund != null">#{isRefund},</if>
            <if test="platformServiceFee != null">#{platformServiceFee},</if>
            <if test="mark != null">#{mark},</if>
            <if test="duration != null">#{duration},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="changeReason != null">#{changeReason},</if>
            <if test="payChannel != null">#{payChannel},</if>
            <if test="channelCost != null">#{channelCost},</if>
            <if test="storeId != null">#{storeId},</if>
            <if test="storeName != null">#{storeName},</if>
            <if test="lng != null">#{lng},</if>
            <if test="lat != null">#{lat},</if>
            <if test="merchantId != null">#{merchantId},</if>
            <if test="originalOrderNo != null">#{originalOrderNo},</if>
            <if test="price != null">#{price},</if>
            <if test="explain != null">#{explain},</if>
            <if test="autoCancelTime != null">#{autoCancelTime},</if>
            <if test="isSendMsg != null">#{isSendMsg},</if>
            <if test="roomId != null">#{roomId},</if>
            <if test="roomName != null">#{roomName},</if>
            <if test="roomType != null">#{roomType},</if>
            <if test="roomType2 != null">#{roomType2},</if>
            <if test="equipmentId != null">#{equipmentId},</if>
            <if test="equipmentType != null">#{equipmentType},</if>
            <if test="equipmentName != null">#{equipmentName},</if>
            <if test="mode != null">#{mode},</if>
            <if test="hours != null">#{hours},</if>
            <if test="reserveStartTime != null">#{reserveStartTime},</if>
            <if test="reserveEndTime != null">#{reserveEndTime},</if>
            <if test="wifi != null">#{wifi},</if>
            <if test="wifiPassword != null">#{wifiPassword},</if>
            <if test="managerPhone != null">#{managerPhone},</if>
            <if test="productId != null">#{productId},</if>
            <if test="productName != null">#{productName},</if>
         </trim>
    </insert>

    <update id="addRefundAmountByOrderNo">
            update ss_order
            set refund = refund + #{refundAmount}
            where order_no = #{orderNo} and refund <![CDATA[<]]> pay_fee
    </update>

    <update id="updateRlOrder" parameterType="Order">
        update ss_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">order_no = #{orderNo},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null and userName != ''">user_name = #{userName},</if>
            <if test="realName != null and realName != ''">real_name = #{realName},</if>
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="ruleId != null">rule_id = #{ruleId},</if>
            <if test="gateMac != null">gate_mac = #{gateMac},</if>
            <if test="gateSn != null">gate_sn = #{gateSn},</if>
            <if test="gateId != null">gate_id = #{gateId},</if>
            <if test="roomMac != null">room_mac = #{roomMac},</if>
            <if test="roomSn != null">room_sn = #{roomSn},</if>
            <if test="picture != null">picture = #{picture},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="payType != null">pay_type = #{payType},</if>
            <if test="paid != null and paid != ''">paid = #{paid},</if>
            <if test="payId != null and payId != ''">pay_id = #{payId},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="reType != null and reType != ''">re_type = #{reType},</if>
            <if test="totalFee != null">total_fee = #{totalFee},</if>
            <if test="payFee != null">pay_fee = #{payFee},</if>
            <if test="deposit != null">deposit = #{deposit},</if>
            <if test="depositRefund != null">deposit_refund = #{depositRefund},</if>
            <if test="refund != null">refund = #{refund},</if>
            <if test="refundTime != null">refund_time = #{refundTime},</if>
            <if test="isRefund != null">is_refund = #{isRefund},</if>
            <if test="platformServiceFee != null">platform_service_fee = #{platformServiceFee},</if>
            <if test="mark != null">mark = #{mark},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="changeReason != null">change_reason = #{changeReason},</if>
            <if test="payChannel != null">pay_channel = #{payChannel},</if>
            <if test="channelName != null">channel_name = #{channelName},</if>
            <if test="channelCost != null">channel_cost = #{channelCost},</if>
            <if test="storeId != null">store_id = #{storeId},</if>
            <if test="storeName != null">store_name = #{storeName},</if>
            <if test="lng != null">lng = #{lng},</if>
            <if test="lat != null">lat = #{lat},</if>
            <if test="merchantId != null">merchant_id = #{merchantId},</if>
            <if test="originalOrderNo != null">original_order_no = #{originalOrderNo},</if>
            <if test="price != null">price = #{price},</if>
            <if test="explain != null">`explain` = #{explain},</if>
            <if test="autoCancelTime != null">auto_cancel_time = #{autoCancelTime},</if>
            <if test="isSendMsg != null">is_send_msg = #{isSendMsg},</if>
            <if test="roomId != null">room_id = #{roomId},</if>
            <if test="roomName != null">room_name = #{roomName},</if>
            <if test="roomType != null">room_type = #{roomType}</if>
            <if test="roomType2 != null">room_type2 = #{roomType2}</if>
            <if test="equipmentId != null">equipment_id = #{equipmentId},</if>
            <if test="equipmentType != null">equipment_type = #{equipmentType},</if>
            <if test="equipmentName != null">equipment_name = #{equipmentName},</if>
            <if test="mode != null">mode = #{mode}</if>
            <if test="hours != null">hours = #{hours}</if>
            <if test="reserveStartTime != null">reserve_start_time = #{reserveStartTime},</if>
            <if test="reserveEndTime != null">reserve_end_time = #{reserveEndTime},</if>
            <if test="wifi != null">wifi = #{wifi},</if>
            <if test="wifiPassword != null">wifi_password = #{wifiPassword},</if>
            <if test="managerPhone != null">manager_phone = #{managerPhone},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="productName != null">product_name = #{productName},</if>
            <if test="depositRefundDesc != null">deposit_refund_desc = #{depositRefundDesc},</if>
        </trim>
        where order_id = #{orderId}
    </update>

    <update id="updateRlOrderByOrderNo" parameterType="Order">
        update ss_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">order_no = #{orderNo},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null and userName != ''">user_name = #{userName},</if>
            <if test="realName != null and realName != ''">real_name = #{realName},</if>
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="ruleId != null">rule_id = #{ruleId},</if>
            <if test="gateMac != null">gate_mac = #{gateMac},</if>
            <if test="gateSn != null">gate_sn = #{gateSn},</if>
            <if test="gateId != null">gate_id = #{gateId},</if>
            <if test="roomMac != null">room_mac = #{roomMac},</if>
            <if test="roomSn != null">room_sn = #{roomSn},</if>
            <if test="picture != null">picture = #{picture},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="payType != null">pay_type = #{payType},</if>
            <if test="paid != null and paid != ''">paid = #{paid},</if>
            <if test="payId != null and payId != ''">pay_id = #{payId},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="reType != null and reType != ''">re_type = #{reType},</if>
            <if test="totalFee != null">total_fee = #{totalFee},</if>
            <if test="payFee != null">pay_fee = #{payFee},</if>
            <if test="deposit != null">deposit = #{deposit},</if>
            <if test="depositRefund != null">deposit_refund = #{depositRefund},</if>
            <if test="refund != null">refund = #{refund},</if>
            <if test="refundTime != null">refund_time = #{refundTime},</if>
            <if test="isRefund != null">is_refund = #{isRefund},</if>
            <if test="platformServiceFee != null">platform_service_fee = #{platformServiceFee},</if>
            <if test="mark != null">mark = #{mark},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="changeReason != null">change_reason = #{changeReason},</if>
            <if test="payChannel != null">pay_channel = #{payChannel},</if>
            <if test="channelName != null">channel_name = #{channelName},</if>
            <if test="channelCost != null">channel_cost = #{channelCost},</if>
            <if test="storeId != null">store_id = #{storeId},</if>
            <if test="storeName != null">store_name = #{storeName},</if>
            <if test="lng != null">lng = #{lng},</if>
            <if test="lat != null">lat = #{lat},</if>
            <if test="merchantId != null">merchant_id = #{merchantId},</if>
            <if test="originalOrderNo != null">original_order_no = #{originalOrderNo},</if>
            <if test="price != null">price = #{price},</if>
            <if test="explain != null">`explain` = #{explain},</if>
            <if test="autoCancelTime != null">auto_cancel_time = #{autoCancelTime},</if>
            <if test="isSendMsg != null">is_send_msg = #{isSendMsg},</if>
            <if test="roomId != null">room_id = #{roomId},</if>
            <if test="roomName != null">room_name = #{roomName},</if>
            <if test="roomType != null">room_type = #{roomType}</if>
            <if test="roomType2 != null">room_type2 = #{roomType2}</if>
            <if test="equipmentId != null">equipment_id = #{equipmentId},</if>
            <if test="equipmentType != null">equipment_type = #{equipmentType},</if>
            <if test="equipmentName != null">equipment_name = #{equipmentName},</if>
            <if test="mode != null">mode = #{mode}</if>
            <if test="hours != null">hours = #{hours}</if>
            <if test="reserveStartTime != null">reserve_start_time = #{reserveStartTime},</if>
            <if test="reserveEndTime != null">reserve_end_time = #{reserveEndTime},</if>
            <if test="wifi != null">wifi = #{wifi},</if>
            <if test="wifiPassword != null">wifi_password = #{wifiPassword},</if>
            <if test="managerPhone != null">manager_phone = #{managerPhone},</if>
            <if test="productId != null">product_id = #{productId},</if>
            <if test="productName != null">product_name = #{productName},</if>
            <if test="depositRefundDesc != null">deposit_refund_desc = #{depositRefundDesc},</if>
        </trim>
        where order_no = #{orderNo}
    </update>

    <update id="changeRoom">
        update ss_order
        room_id = #{roomId}
        where order_no = #{orderNo}
    </update>

    <delete id="deleteRlOrderByOrderId" parameterType="Long">
        delete from ss_order where order_id = #{orderId}
    </delete>

    <delete id="deleteRlOrderByOrderIds" parameterType="String">
        delete from ss_order where order_id in
        <foreach item="orderId" collection="array" open="(" separator="," close=")">
            #{orderId}
        </foreach>
    </delete>
</mapper>
