<?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.bonus.core.order.common.mapper.OrderInfoMapper">

    <!-- 抽取权限 -->
    <sql id="if-permission">
        <if test="permission != null and permission.codes != null and permission.codes.size() > 0">
            AND oi.permission_code in
            <foreach collection="permission.codes" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="permission != null and permission.orgIds != null and permission.orgIds.size() > 0">
            AND oi.org_id in
            <foreach collection="permission.orgIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </sql>

<!--    <select id="existOrder" resultType="java.lang.Integer">-->
<!--        SELECT EXISTS(-->
<!--        SELECT 1 FROM order_info oi-->
<!--            WHERE oi.order_date BETWEEN #{startDate} AND #{endDate}-->
<!--            <if test="orderId != null">-->
<!--                AND oi.order_id = #{orderId}-->
<!--            </if>-->
<!--            <if test="macOrderId != null and macOrderId != ''">-->
<!--                AND oi.mac_order_id = #{macOrderId}-->
<!--            </if>-->
<!--            <if test="payStateList != null and payStateList.size() > 0">-->
<!--                AND oi.pay_state in-->
<!--                <foreach collection="payStateList" item="item" open="(" close=")" separator=",">-->
<!--                    #{item}-->
<!--                </foreach>-->
<!--            </if>-->
<!--        )-->
<!--    </select>-->

<!--    <select id="listVoByIds" resultType="net.xnzn.core.order.common.vo.OrderInfoVO">-->
<!--        SELECT oi.cust_id,-->
<!--        ci.cust_name,-->
<!--        ci.cust_num,-->
<!--        ci.mobile,-->
<!--        oi.org_full_name,-->
<!--        ci.cust_photo_url,-->
<!--        oi.psn_type,-->
<!--        oi.psn_type_name,-->
<!--        oi.order_type,-->
<!--        oi.source_type,-->
<!--        oi.machine_sn,-->
<!--        oi.order_id,-->
<!--        oi.order_date,-->
<!--        oi.order_time,-->
<!--        oi.pay_time,-->
<!--        oi.canteen_id,-->
<!--        oi.canteen_name,-->
<!--        oi.stall_id,-->
<!--        oi.stall_name,-->
<!--        oi.room_id,-->
<!--        oi.room_name,-->
<!--        oi.mealtime_type,-->
<!--        oi.mealtime_name,-->
<!--        oi.payable_amount,-->
<!--        oi.real_amount,-->
<!--        oi.delivery_amount,-->
<!--        oi.packing_amount,-->
<!--        oi.pay_type,-->
<!--        oi.deduction_type,-->
<!--        oi.delivery_type,-->
<!--        oi.order_state,-->
<!--        oi.pay_state,-->
<!--        oi.order_refund_state,-->
<!--        oi.dishes_state,-->
<!--        oi.remark,-->
<!--        oi.mac_order_id,-->
<!--        oi.coupon_amount,-->
<!--        oi.machine_num,-->
<!--        oi.pay_channel,-->
<!--        oi.nu_clear_mode,-->
<!--        oi.operator_id,-->
<!--        oi.operator_name,-->
<!--        oi.cashier_id,-->
<!--        oi.cashier_name,-->
<!--        oi.meal_code,-->
<!--        odr.delivery_related_id,-->
<!--        odr.consignee_name,-->
<!--        odr.consignee_mobile,-->
<!--        odr.consignee_address,-->
<!--        odr.delivery_name,-->
<!--        odr.delivery_mobile-->
<!--        FROM order_info oi-->
<!--        LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id-->
<!--        LEFT JOIN order_delivery odr ON oi.order_id = odr.order_id AND oi.order_date = odr.order_date-->
<!--        WHERE oi.order_id IN-->
<!--        <foreach collection="orderIds" item="item" open="(" close=")" separator=",">-->
<!--            #{item}-->
<!--        </foreach>-->
<!--        <if test="startDate != null">-->
<!--            AND oi.order_date <![CDATA[ >= ]]> #{startDate}-->
<!--        </if>-->
<!--        <if test="endDate != null">-->
<!--            AND oi.order_date <![CDATA[ <= ]]> #{endDate}-->
<!--        </if>-->
<!--        ORDER BY oi.order_id desc-->
<!--    </select>-->

    <!-- 查询订单id -->
    <select id="queryOrderId" resultType="com.bonus.core.order.common.vo.OrderIdDateVO">
        SELECT oi.order_id AS id, oi.order_date
        FROM order_info oi
        where 1=1
            <if test="param.custId != null">
                AND oi.cust_id = #{param.custId}
            </if>
            <if test="param.macOrderId != null and param.macOrderId.trim() != ''">
                AND oi.mac_order_id = #{param.macOrderId}
            </if>
            <if test="param.orderDate != null">
                AND oi.order_date = #{param.orderDate}
            </if>
            <if test="param.startDate != null and param.endDate != null">
                AND oi.order_date BETWEEN #{param.startDate} AND #{param.endDate}
            </if>
            <if test="param.nuClearMode != null">
                AND oi.nu_clear_mode = #{param.nuClearMode}
            </if>
            <if test="param.mealCode != null and param.mealCode.trim() != ''">
                AND oi.meal_code = #{param.mealCode}
            </if>
            <if test="param.ifCoupon != null and param.ifCoupon == 1">
                AND oi.coupon_id <![CDATA[ <> ]]> ''
            </if>
            <if test="param.ifCoupon != null and param.ifCoupon == 2">
                AND (oi.coupon_id IS NULL OR oi.coupon_id = '')
            </if>
            <if test="param.ifOnline != null">
                AND oi.if_online = #{param.ifOnline}
            </if>
            <if test="param.commentState != null">
                AND oi.comment_state = #{param.commentState}
            </if>
            <if test="param.serialNum != null and param.serialNum.trim() != ''">
                AND oi.pay_param = #{param.serialNum}
            </if>
            <if test="param.orderIdList != null and param.orderIdList.size() > 0">
                AND oi.order_id IN
                <foreach collection="param.orderIdList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.mealtimeTypeList != null and param.mealtimeTypeList.size() > 0">
                AND oi.mealtime_type in
                <foreach collection="param.mealtimeTypeList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.payStateList != null and param.payStateList.size() > 0">
                AND oi.pay_state in
                <foreach collection="param.payStateList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.orderRefundStateList != null and param.orderRefundStateList.size() > 0">
                AND oi.order_refund_state in
                <foreach collection="param.orderRefundStateList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.deliveryTypeList != null and param.deliveryTypeList.size() > 0">
                AND oi.delivery_type in
                <foreach collection="param.deliveryTypeList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.sourceTypeList != null and param.sourceTypeList.size() > 0">
                AND oi.source_type in
                <foreach collection="param.sourceTypeList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.canteenIdList != null and param.canteenIdList.size() > 0">
                AND oi.canteen_id in
                <foreach collection="param.canteenIdList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.stallIdList != null and param.stallIdList.size() > 0">
                AND oi.stall_id in
                <foreach collection="param.stallIdList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.roomIdList != null and param.roomIdList.size() > 0">
                AND oi.room_id in
                <foreach collection="param.roomIdList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.operatorIdList != null and param.operatorIdList.size() > 0">
                AND oi.operator_id in
                <foreach collection="param.operatorIdList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.cashierIdList != null and param.cashierIdList.size() > 0">
                AND oi.cashier_id in
                <foreach collection="param.cashierIdList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.orderTypeList != null and param.orderTypeList.size() > 0">
                AND oi.order_type IN
                <foreach collection="param.orderTypeList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.dishesStateList != null and param.dishesStateList.size() > 0">
                AND oi.dishes_state IN
                <foreach collection="param.dishesStateList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.orderStateList != null and param.orderStateList.size() > 0">
                AND oi.order_state in
                <foreach collection="param.orderStateList" item="orderState" separator="," open="(" close=")">
                    #{orderState}
                </foreach>
            </if>
            <if test="param.machineSnList != null and param.machineSnList.size() > 0">
                AND oi.machine_sn in
                <foreach collection="param.machineSnList" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="param.psnTypeList != null and param.psnTypeList.size() > 0">
                AND oi.psn_type in
                <foreach collection="param.psnTypeList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.orgIdList != null and param.orgIdList.size() > 0">
                AND oi.org_id in
                <foreach collection="param.orgIdList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.custSearchInfo != null and param.custSearchInfo != ''">
                AND EXISTS(
                    SELECT 1 FROM cust_info ci
                    WHERE oi.cust_id = ci.cust_id
                    AND (
                        ci.cust_name = #{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                        OR ci.cust_name_like LIKE CONCAT('%',#{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')
                        OR ci.cust_num = #{param.custSearchInfo}
                        OR ci.mobile = #{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                        OR ci.mobile_suffix = #{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                        )
                )
            </if>
            <if test="param.goodsSearchInfo != null and param.goodsSearchInfo.trim() != ''">
                AND EXISTS(
                    SELECT 1 FROM order_detail od
                    WHERE od.order_id = oi.order_id and od.order_date = oi.order_date
                    AND od.goods_dishes_name like concat('%', #{param.goodsSearchInfo}, '%')
                )
            </if>
            <if test="param.buffetSearchInfo != null and param.buffetSearchInfo.trim() != ''">
                AND (
                    EXISTS(
                        SELECT 1 FROM cust_info ci
                        WHERE oi.cust_id = ci.cust_id
                        AND (
                            ci.cust_name = #{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                            OR ci.cust_name_like LIKE CONCAT('%',#{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')
                            OR ci.cust_num = #{param.buffetSearchInfo}
                            OR ci.mobile = #{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                            OR ci.mobile_suffix = #{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                        )
                    ) OR EXISTS(
                        SELECT 1 FROM mac_plateid_bind_serial mpbs
                        WHERE oi.plate_serial_num = mpbs.plate_serial_num
                        AND mpbs.plate_id like concat('%', #{param.buffetSearchInfo}, '%')
                    )
                )
            </if>
            <if test="param.deviceSearchInfo != null and param.deviceSearchInfo.trim() != ''">
                AND EXISTS(
                    SELECT 1 FROM device_info di
                    WHERE oi.machine_sn = di.device_sn
                    AND di.device_name like concat('%', #{param.deviceSearchInfo}, '%')
                )
            </if>
            <if test="param.canteenSearchInfo != null and param.canteenSearchInfo.trim() != ''">
                AND (
                oi.canteen_name like concat('%', #{param.canteenSearchInfo}, '%')
                OR oi.stall_name like concat('%', #{param.canteenSearchInfo}, '%')
                OR EXISTS (
                    SELECT 1 FROM order_detail od
                    WHERE od.order_id = oi.order_id AND od.order_date = oi.order_date
                    AND od.goods_dishes_name LIKE concat('%', #{param.canteenSearchInfo}, '%')
                    )
                )
            </if>
            <if test="param.orderIdSearchInfo != null and param.orderIdSearchInfo != ''">
                AND oi.order_id like concat('%', #{param.orderIdSearchInfo}, '%')
            </if>
            <if test="param.orderSearchInfo != null and param.orderSearchInfo != ''">
                AND (
                    EXISTS(
                    SELECT 1 FROM cust_info ci
                    WHERE oi.cust_id = ci.cust_id
                    AND (
                        ci.cust_name = #{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                        OR ci.cust_name_like LIKE CONCAT('%',#{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')
                        OR ci.cust_num = #{param.buffetSearchInfo}
                        OR ci.mobile = #{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                        OR ci.mobile_suffix = #{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                        )
                    ) OR oi.order_id like concat('%', #{param.orderSearchInfo}, '%')
                )
            </if>
            <if test="param.roomSearchInfo != null and param.roomSearchInfo != ''">
                AND (
                    EXISTS(
                        SELECT 1 FROM cust_info ci
                        WHERE oi.cust_id = ci.cust_id
                        AND (
                            ci.cust_name = #{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                            OR ci.cust_name_like LIKE CONCAT('%',#{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')
                            OR ci.cust_num = #{param.buffetSearchInfo}
                            OR ci.mobile = #{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                            OR ci.mobile_suffix = #{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                        )
                    ) OR oi.room_name like concat('%', #{param.roomSearchInfo}, '%')
                )
            </if>
            <if test="param.areaIdList != null and param.areaIdList.size() > 0">
                AND EXISTS(
                    SELECT 1 FROM alloc_canteen ac
                    WHERE oi.canteen_id = ac.canteen_id
                    AND ac.area_id in
                    <foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">
                        #{item}
                    </foreach>
                )
            </if>
            <if test="param.payTypeList != null and param.payTypeList.size() > 0">
                AND EXISTS(
                    SELECT 1 FROM order_amount_detail oad
                    WHERE oad.order_id = oi.order_id and oad.order_date = oi.order_date
                    AND oad.pay_type in
                    <foreach collection="param.payTypeList" item="payType" open="(" close=")" separator=",">
                        #{payType}
                    </foreach>
                )
            </if>
            <if test="param.tradeNo != null and param.tradeNo.trim() != ''">
                AND EXISTS(
                    SELECT 1 FROM trade_order_recharge tor
                    LEFT JOIN trade_record tr ON tor.trade_id = tr.id AND tor.create_time = tr.create_time
                    WHERE tor.order_recharge_id = oi.order_id
                        AND (tr.out_trade_no = #{param.tradeNo} OR tor.trade_id = #{param.tradeNo})
                    <if test="param.startDateTime != null and param.endDateTime != null">
                        AND tor.create_time BETWEEN #{param.startDateTime} AND #{param.endDateTime}
                        AND tr.create_time BETWEEN #{param.startDateTime} AND #{param.endDateTime}
                    </if>
                )
            </if>
            <if test="param.accExceptionRecordStateList != null and param.accExceptionRecordStateList.size() > 0">
                AND EXISTS(
                    SELECT 1 FROM trade_order_recharge tor
                    LEFT JOIN acc_exception_record acr ON tor.trade_id = acr.relation_id
                    WHERE tor.order_recharge_id = oi.order_id
                    AND acr.record_status IN
                    <foreach collection="param.accExceptionRecordStateList" item="item" open="(" close=")" separator=",">
                        #{item}
                    </foreach>
                    <if test="param.startDateTime != null and param.endDateTime != null">
                        AND tor.create_time BETWEEN #{param.startDateTime} AND #{param.endDateTime}
                    </if>
                )
            </if>
            <if test="param.existsRefund != null and param.existsRefund == 1">
                AND EXISTS (
                    SELECT 1 FROM order_refund orf
                    WHERE orf.order_id = oi.order_id
                    <if test="param.checkState != null">
                        AND orf.check_state = #{param.checkState}
                    </if>
                )
            </if>
            <if test="param.deliveryRelatedIdList != null and param.deliveryRelatedIdList.size() > 0">
                AND EXISTS(
                    SELECT 1 FROM order_delivery od
                    WHERE od.order_id = oi.order_id and od.order_date = oi.order_date
                    AND od.delivery_related_id IN
                    <foreach collection="param.deliveryRelatedIdList" item="item" open="(" close=")" separator=",">
                        #{item}
                    </foreach>
                )
            </if>
            <if test="param.detailMachineSnList != null and param.detailMachineSnList.size() > 0">
                AND EXISTS(
                    SELECT 1 FROM order_detail od
                    WHERE od.order_id = oi.order_id and od.order_date = oi.order_date
                    AND od.machine_sn IN
                    <foreach collection="param.detailMachineSnList" item="item" open="(" close=")" separator=",">
                        #{item}
                    </foreach>
                )
            </if>
        <include refid="if-permission"/>
        ORDER BY oi.order_date DESC, oi.order_id DESC
    </select>

<!--    <select id="queryDeliveryId" resultType="net.xnzn.core.order.common.vo.OrderIdDateVO">-->
<!--        SELECT od.delivery_id AS id, od.order_date-->
<!--        FROM order_delivery od-->
<!--        LEFT JOIN order_info oi ON oi.order_id = od.order_id AND oi.order_date = od.order_date-->
<!--        where 1=1-->
<!--        <if test="param.deliveryRelatedIdList != null and param.deliveryRelatedIdList.size() > 0">-->
<!--            AND od.delivery_related_id IN-->
<!--            <foreach collection="param.deliveryRelatedIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.deliveryUserIdList != null and param.deliveryUserIdList.size() > 0">-->
<!--            AND od.delivery_user_id IN-->
<!--            <foreach collection="param.deliveryUserIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.ifExistsPlaceId != null and param.ifExistsPlaceId == 1">-->
<!--            AND EXISTS(-->
<!--            SELECT 1 FROM cust_place cp-->
<!--            WHERE od.delivery_related_id = cp.place_id-->
<!--            )-->
<!--        </if>-->
<!--        <if test="param.custId != null">-->
<!--            AND oi.cust_id = #{param.custId}-->
<!--        </if>-->
<!--        <if test="param.macOrderId != null and param.macOrderId.trim() != ''">-->
<!--            AND oi.mac_order_id = #{param.macOrderId}-->
<!--        </if>-->
<!--        <if test="param.startDate != null and param.endDate != null">-->
<!--            AND oi.order_date BETWEEN #{param.startDate} AND #{param.endDate}-->
<!--        </if>-->
<!--        <if test="param.mealCode != null and param.mealCode.trim() != ''">-->
<!--            AND oi.meal_code = #{param.mealCode}-->
<!--        </if>-->
<!--        <if test="param.ifOnline != null">-->
<!--            AND oi.if_online = #{param.ifOnline}-->
<!--        </if>-->
<!--        <if test="param.orderIdList != null and param.orderIdList.size() > 0">-->
<!--            AND oi.order_id IN-->
<!--            <foreach collection="param.orderIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.mealtimeTypeList != null and param.mealtimeTypeList.size() > 0">-->
<!--            AND oi.mealtime_type in-->
<!--            <foreach collection="param.mealtimeTypeList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.payStateList != null and param.payStateList.size() > 0">-->
<!--            AND oi.pay_state in-->
<!--            <foreach collection="param.payStateList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.orderRefundStateList != null and param.orderRefundStateList.size() > 0">-->
<!--            AND oi.order_refund_state in-->
<!--            <foreach collection="param.orderRefundStateList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.deliveryTypeList != null and param.deliveryTypeList.size() > 0">-->
<!--            AND oi.delivery_type in-->
<!--            <foreach collection="param.deliveryTypeList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.sourceTypeList != null and param.sourceTypeList.size() > 0">-->
<!--            AND oi.source_type in-->
<!--            <foreach collection="param.sourceTypeList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.areaIdList != null and param.areaIdList.size() > 0">-->
<!--            AND EXISTS(-->
<!--            SELECT 1 FROM alloc_canteen ac-->
<!--            WHERE oi.canteen_id = ac.canteen_id-->
<!--            AND ac.area_id in-->
<!--            <foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--            )-->
<!--        </if>-->
<!--        <if test="param.canteenIdList != null and param.canteenIdList.size() > 0">-->
<!--            AND oi.canteen_id in-->
<!--            <foreach collection="param.canteenIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.stallIdList != null and param.stallIdList.size() > 0">-->
<!--            AND oi.stall_id in-->
<!--            <foreach collection="param.stallIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.orderTypeList != null and param.orderTypeList.size() > 0">-->
<!--            AND oi.order_type IN-->
<!--            <foreach collection="param.orderTypeList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.dishesStateList != null and param.dishesStateList.size() > 0">-->
<!--            AND oi.dishes_state IN-->
<!--            <foreach collection="param.dishesStateList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.orderStateList != null and param.orderStateList.size() > 0">-->
<!--            AND oi.order_state in-->
<!--            <foreach collection="param.orderStateList" item="orderState" separator="," open="(" close=")">-->
<!--                #{orderState}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.custSearchInfo != null and param.custSearchInfo != ''">-->
<!--            AND (-->
<!--                od.consignee_name = #{param.custSearchInfo}-->
<!--                OR od.consignee_mobile = #{param.custSearchInfo}-->
<!--                OR EXISTS(-->
<!--                    SELECT 1 FROM cust_info ci-->
<!--                    WHERE oi.cust_id = ci.cust_id-->
<!--                    <if test="param.custSearchInfo != null and param.custSearchInfo != ''">-->
<!--                        AND (-->
<!--                        ci.cust_name = #{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                        OR ci.cust_name_like LIKE CONCAT('%',#{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')-->
<!--                        OR ci.cust_num = #{param.custSearchInfo}-->
<!--                        OR ci.mobile = #{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                        OR ci.mobile_suffix = #{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                        )-->
<!--                    </if>-->
<!--                )-->
<!--            )-->
<!--        </if>-->
<!--        <if test="param.roomIdList != null and param.roomIdList.size() > 0">-->
<!--            AND oi.room_id in-->
<!--            <foreach collection="param.roomIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.operatorIdList != null and param.operatorIdList.size() > 0">-->
<!--            AND oi.operator_id in-->
<!--            <foreach collection="param.operatorIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.cashierIdList != null and param.cashierIdList.size() > 0">-->
<!--            AND oi.cashier_id in-->
<!--            <foreach collection="param.cashierIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.psnTypeList != null and param.psnTypeList.size() > 0">-->
<!--            AND oi.psn_type in-->
<!--            <foreach collection="param.psnTypeList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.orgIdList != null and param.orgIdList.size() > 0">-->
<!--            AND oi.org_id in-->
<!--            <foreach collection="param.orgIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <include refid="if-permission"/>-->
<!--        ORDER BY oi.order_date DESC, oi.order_id DESC-->
<!--    </select>-->

<!--    <select id="queryRefundId" resultType="net.xnzn.core.order.common.vo.OrderIdDateVO">-->
<!--        SELECT t.order_refund_id AS id, oi.order_date-->
<!--        FROM order_refund t-->
<!--        INNER JOIN order_info oi ON t.order_id = oi.order_id-->
<!--        <where>-->
<!--            <if test="param.custId != null">-->
<!--                AND oi.cust_id = #{param.custId}-->
<!--            </if>-->
<!--            <if test="param.orderId != null">-->
<!--                AND oi.order_id = #{param.orderId}-->
<!--            </if>-->
<!--            <if test="param.macOrderId != null and param.macOrderId != ''">-->
<!--                AND oi.mac_order_id = #{param.macOrderId}-->
<!--            </if>-->
<!--            <if test="param.orderRefundId != null">-->
<!--                AND t.order_refund_id = #{param.orderRefundId}-->
<!--            </if>-->
<!--            <if test="param.checkState != null">-->
<!--                AND t.check_state = #{param.checkState}-->
<!--            </if>-->
<!--            <if test="param.applyType != null">-->
<!--                AND t.apply_type = #{param.applyType}-->
<!--            </if>-->
<!--            <if test="param.startDate != null and param.endDate != null">-->
<!--                AND oi.order_date BETWEEN #{param.startDate} AND #{param.endDate}-->
<!--            </if>-->
<!--            <if test="param.custSearchInfo != null and param.custSearchInfo != ''">-->
<!--                AND EXISTS(-->
<!--                SELECT 1 FROM cust_info ci-->
<!--                WHERE oi.cust_id = ci.cust_id-->
<!--                <if test="param.custSearchInfo != null and param.custSearchInfo != ''">-->
<!--                    AND (-->
<!--                        ci.cust_name = #{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                        OR ci.cust_name_like LIKE CONCAT('%',#{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')-->
<!--                        OR ci.cust_num = #{param.custSearchInfo}-->
<!--                        OR ci.mobile = #{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                        OR ci.mobile_suffix = #{param.custSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                    )-->
<!--                </if>-->
<!--                )-->
<!--            </if>-->
<!--            <if test="param.buffetSearchInfo != null and param.buffetSearchInfo.trim() != ''">-->
<!--                AND (-->
<!--                    EXISTS(-->
<!--                        SELECT 1 FROM cust_info ci-->
<!--                        WHERE oi.cust_id = ci.cust_id-->
<!--                        AND (-->
<!--                            ci.cust_name = #{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                            OR ci.cust_name_like LIKE CONCAT('%',#{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')-->
<!--                            OR ci.cust_num = #{param.buffetSearchInfo}-->
<!--                            OR ci.mobile = #{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                            OR ci.mobile_suffix = #{param.buffetSearchInfo,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                            )-->
<!--                    ) OR EXISTS(-->
<!--                        SELECT 1 FROM mac_plateid_bind_serial mpbs-->
<!--                        WHERE oi.plate_serial_num = mpbs.plate_serial_num-->
<!--                        AND mpbs.plate_id like concat('%', #{param.buffetSearchInfo}, '%')-->
<!--                    )-->
<!--                )-->
<!--            </if>-->
<!--            <if test="param.orderTypeList != null and param.orderTypeList.size() > 0">-->
<!--                AND oi.order_type IN-->
<!--                <foreach collection="param.orderTypeList" item="item" open="(" close=")" separator=",">-->
<!--                    #{item}-->
<!--                </foreach>-->
<!--            </if>-->
<!--            <include refid="if-permission"/>-->
<!--        </where>-->
<!--        ORDER BY t.order_refund_id DESC-->
<!--    </select>-->

<!--    <select id="queryOrderInfoWeb" resultType="net.xnzn.core.order.web.vo.OrderListWebVO">-->
<!--        SELECT oi.cust_id,-->
<!--        ci.cust_name,-->
<!--        ci.cust_num,-->
<!--        ci.mobile,-->
<!--        oi.org_full_name,-->
<!--        oi.psn_type,-->
<!--        oi.psn_type_name,-->
<!--        oi.order_type,-->
<!--        oi.if_online,-->
<!--        oi.source_type,-->
<!--        oi.machine_sn,-->
<!--        oi.order_id,-->
<!--        oi.order_date,-->
<!--        oi.order_time,-->
<!--        oi.pay_time,-->
<!--        oi.canteen_id,-->
<!--        oi.canteen_name,-->
<!--        oi.stall_id,-->
<!--        oi.stall_name,-->
<!--        oi.room_id,-->
<!--        oi.room_name,-->
<!--        oi.mealtime_type,-->
<!--        oi.mealtime_name,-->
<!--        oi.payable_amount,-->
<!--        oi.discounts_amount,-->
<!--        oi.real_amount,-->
<!--        oi.refund_amount,-->
<!--        oi.delivery_amount,-->
<!--        oi.packing_amount,-->
<!--        oi.pay_type,-->
<!--        oi.deduction_type,-->
<!--        oi.delivery_type,-->
<!--        oi.order_state,-->
<!--        oi.pay_state,-->
<!--        oi.order_refund_state,-->
<!--        oi.dishes_state,-->
<!--        oi.meal_code,-->
<!--        oi.remark,-->
<!--        oi.mac_order_id,-->
<!--        oi.coupon_amount,-->
<!--        oi.machine_num,-->
<!--        oi.pay_channel,-->
<!--        oi.nu_clear_mode,-->
<!--        oi.operator_id,-->
<!--        oi.operator_name,-->
<!--        oi.cashier_id,-->
<!--        oi.cashier_name,-->
<!--        oi.part_pay_reason,-->
<!--        aa.area_id,-->
<!--        aa.area_name,-->
<!--        mc.coupon_name-->
<!--        FROM order_info oi-->
<!--        LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id-->
<!--        LEFT JOIN mkt_coupon mc ON oi.coupon_id = mc.coupon_num-->
<!--        LEFT JOIN alloc_canteen ac ON oi.canteen_id = ac.canteen_id-->
<!--        LEFT JOIN alloc_area aa ON ac.area_id = aa.area_id-->
<!--        WHERE oi.order_id IN-->
<!--        <foreach collection="orderIds" item="item" open="(" close=")" separator=",">-->
<!--            #{item}-->
<!--        </foreach>-->
<!--        <if test="startDate != null">-->
<!--            AND oi.order_date <![CDATA[ >= ]]> #{startDate}-->
<!--        </if>-->
<!--        <if test="endDate != null">-->
<!--            AND oi.order_date <![CDATA[ <= ]]> #{endDate}-->
<!--        </if>-->
<!--        ORDER BY oi.order_id desc-->
<!--    </select>-->

<!--    <select id="queryOrderDeliveryDetailList" resultType="net.xnzn.core.order.web.vo.OrderDeliveryDetailVO">-->
<!--        SELECT-->
<!--        oi.order_id , oi.order_type,  oi.order_date, oi.mealtime_name , oi.machine_num , oi.delivery_type ,-->
<!--        oi.source_type , oi.order_state , oi.delivery_amount ,oi.payable_amount, oi.packing_amount, oi.real_amount,-->
<!--        oi.operator_id, oi.operator_name, oi.order_refund_state, oi.pay_state,oi.dishes_state, oi.remark, oi.meal_code,-->
<!--        oi.canteen_id, oi.canteen_name, oi.stall_id, oi.stall_name,-->
<!--        aa.area_id, aa.area_name,-->
<!--        oi.real_amount, oi.org_full_name,-->
<!--        od.consignee_address , od.consignee_name , od.consignee_mobile , od.delivery_name , od.delivery_mobile, od.delivery_code,-->
<!--        mu.username AS operatorUserName, mu.real_name AS operatorRealName-->
<!--        FROM order_delivery od-->
<!--        INNER JOIN order_info oi ON od.order_id = oi.order_id AND oi.order_date = od.order_date-->
<!--        LEFT JOIN mgr_user mu       ON oi.operator_id = mu.user_id-->
<!--        LEFT JOIN alloc_canteen ac  ON oi.canteen_id = ac.canteen_id-->
<!--        LEFT JOIN alloc_area aa ON ac.area_id = aa.area_id-->
<!--        WHERE od.delivery_id IN-->
<!--        <foreach collection="deliveryIds" item="item" open="(" close=")" separator=",">-->
<!--            #{item}-->
<!--        </foreach>-->
<!--        <if test="startDate != null">-->
<!--            AND oi.order_date <![CDATA[ >= ]]> #{startDate}-->
<!--        </if>-->
<!--        <if test="endDate != null">-->
<!--            AND oi.order_date <![CDATA[ <= ]]> #{endDate}-->
<!--        </if>-->
<!--        ORDER BY oi.order_date DESC, oi.order_id DESC-->
<!--    </select>-->

    <!--分页获取移动端订单列表-->
    <select id="getOrderMobileList" resultType="com.bonus.core.order.mobile.vo.OrderListMobileVO">
        SELECT order_id,
               mac_order_id,
               machine_sn,
               machine_num,
               plate_serial_num,
               source_type,
               canteen_id,
               canteen_name,
               stall_id,
               stall_name,
               mealtime_type,
               mealtime_name,
               meal_code,
               order_date,
               payable_amount,
               discounts_amount,
               coupon_amount,
               delivery_amount,
               packing_amount,
               real_amount,
               refund_amount,
               order_time,
               order_type,
               order_state,
               dishes_state,
               order_refund_state,
               pay_time,
               pay_type,
               pay_state,
               deduction_type,
               comment_state,
               remark
        FROM order_info oi
        WHERE oi.order_id IN
        <foreach collection="orderIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="startDate != null">
            AND oi.order_date <![CDATA[ >= ]]> #{startDate}
        </if>
        <if test="endDate != null">
            AND oi.order_date <![CDATA[ <= ]]> #{endDate}
        </if>
        ORDER BY oi.order_date DESC, oi.order_id DESC
    </select>

<!--    <select id="getOrderMobileGroup" resultType="net.xnzn.core.order.mobile.vo.OrderGroupMobileVO">-->
<!--        SELECT-->
<!--        mac_order_id,-->
<!--        order_type,-->
<!--        source_type,-->
<!--        GROUP_CONCAT(DISTINCT canteen_name SEPARATOR '，') AS canteen_name,-->
<!--        GROUP_CONCAT(DISTINCT stall_name SEPARATOR '，') AS stall_name,-->
<!--        MIN(order_date) AS order_date_start,-->
<!--        MAX(order_date) AS order_date_end,-->
<!--        MIN(order_time) AS order_time-->
<!--        FROM order_info-->
<!--        WHERE-->
<!--        cust_id = #{queryDTO.custId}-->
<!--        <if test="queryDTO.orderTypeList != null and queryDTO.orderTypeList.size() > 0">-->
<!--            AND order_type IN-->
<!--            <foreach collection="queryDTO.orderTypeList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="queryDTO.startDate != null">-->
<!--            AND order_date <![CDATA[ >= ]]> #{queryDTO.startDate}-->
<!--        </if>-->
<!--        <if test="queryDTO.endDate != null">-->
<!--            AND order_date <![CDATA[ <= ]]> #{queryDTO.endDate}-->
<!--        </if>-->
<!--        GROUP BY mac_order_id, order_type, source_type-->
<!--        ORDER BY order_time DESC-->
<!--    </select>-->

<!--    <select id="getOrderRefundMobileList" resultType="net.xnzn.core.order.mobile.vo.OrderRefundListMobileVO">-->
<!--        SELECT-->
<!--            oi.order_id,-->
<!--            oi.mac_order_id,-->
<!--            oi.source_type,-->
<!--            oi.order_date,-->
<!--            oi.canteen_id,-->
<!--            oi.canteen_name,-->
<!--            oi.stall_id,-->
<!--            oi.stall_name,-->
<!--            oi.mealtime_type,-->
<!--            oi.mealtime_name,-->
<!--            oi.payable_amount,-->
<!--            oi.real_amount,-->
<!--            oi.refund_amount,-->
<!--            oi.order_time,-->
<!--            oi.pay_time,-->
<!--            oi.pay_type,-->
<!--            oi.pay_channel,-->
<!--            oi.order_state,-->
<!--            oi.pay_state,-->
<!--            oi.order_refund_state,-->
<!--            oi.dishes_state,-->
<!--            oi.cust_id,-->
<!--            ci.cust_name,-->
<!--            ci.cust_num,-->
<!--            ci.mobile,-->
<!--            oi.org_full_name,-->
<!--            ci.cust_photo_url,-->
<!--            oi.psn_type,-->
<!--            oi.psn_type_name,-->
<!--            oi.order_type,-->
<!--            oi.remark-->
<!--        FROM order_info oi-->
<!--        LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id-->
<!--        WHERE oi.order_id IN-->
<!--        <foreach collection="orderIds" item="item" open="(" close=")" separator=",">-->
<!--            #{item}-->
<!--        </foreach>-->
<!--        <if test="startDate != null">-->
<!--            AND oi.order_date <![CDATA[ >= ]]> #{startDate}-->
<!--        </if>-->
<!--        <if test="endDate != null">-->
<!--            AND oi.order_date <![CDATA[ <= ]]> #{endDate}-->
<!--        </if>-->
<!--        ORDER BY order_date DESC, oi.order_id desc-->
<!--    </select>-->

<!--    <select id="queryOrderRefundList" resultType="net.xnzn.core.order.web.vo.OrderRefundWebVO">-->
<!--        SELECT t.check_state AS checkState,-->
<!--               t.apply_time AS applyTime,-->
<!--               t.resress_picurl AS resressPicurl,-->
<!--               t.apply_type AS applyType,-->
<!--               t.order_refund_id AS orderRefundId,-->
<!--               t.apply_reason AS applyReason,-->
<!--               t.check_time,-->
<!--               t.refund_amount,-->
<!--               t.real_refund_amount,-->
<!--               t.fee_amount AS refundFeeAmount,-->
<!--               t.order_id,-->
<!--               t.mac_order_id,-->
<!--               t.check_by,-->
<!--               t.order_refund_id,-->
<!--               t.fee_rate,-->
<!--               t.flow_instance_id,-->
<!--               oi.cust_id AS custId,-->
<!--               ci.cust_num AS custNum,-->
<!--               ci.cust_name AS custName,-->
<!--               ci.mobile,-->
<!--               oi.org_full_name AS orgFullName,-->
<!--               oi.order_id AS orderId,-->
<!--               oi.mac_order_id AS macOrderId,-->
<!--               oi.order_type,-->
<!--               oi.plate_serial_num,-->
<!--               oi.pay_type,-->
<!--               oi.nu_clear_mode,-->
<!--               oi.real_amount,-->
<!--               oi.order_date,-->
<!--               oi.order_time,-->
<!--               mpbs.plate_id AS plateNum-->
<!--        FROM order_refund t-->
<!--        INNER JOIN order_info oi ON t.order_id = oi.order_id-->
<!--        LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id-->
<!--        LEFT JOIN mac_plateid_bind_serial mpbs ON oi.plate_serial_num = mpbs.plate_serial_num-->
<!--        WHERE t.order_refund_id IN-->
<!--        <foreach collection="orderRefundIds" item="item" open="(" close=")" separator=",">-->
<!--            #{item}-->
<!--        </foreach>-->
<!--        <if test="startDate != null">-->
<!--            AND oi.order_date <![CDATA[ >= ]]> #{startDate}-->
<!--        </if>-->
<!--        <if test="endDate != null">-->
<!--            AND oi.order_date <![CDATA[ <= ]]> #{endDate}-->
<!--        </if>-->
<!--        ORDER BY t.order_refund_id DESC-->
<!--    </select>-->

<!--    <select id="getOrderCounterNum" resultType="java.lang.Integer">-->
<!--        SELECT COUNT(1) FROM order_info oi-->
<!--        INNER JOIN order_delivery od ON oi.order_id = od.order_id AND oi.order_date = od.order_date-->
<!--        WHERE oi.order_date = #{orderDate}-->
<!--          AND oi.mealtime_type = #{mealtimeType}-->
<!--          AND od.delivery_related_id = #{counterId}-->
<!--          AND oi.order_state = 1-->
<!--    </select>-->

<!--    &lt;!&ndash;查询菜品领取列表&ndash;&gt;-->
<!--    <select id="queryOrderDetailSumGet" resultType="net.xnzn.core.order.deprecated.vo.OrderDetailSumGetVO">-->
<!--        SELECT-->
<!--        oi.order_type,-->
<!--        oi.order_date as ordGoodsDate,-->
<!--        oi.mealtime_type as intervalId,-->
<!--        oi.mealtime_name as intervalName,-->
<!--        od.goods_dishes_id as goodsId,-->
<!--        od.goods_dishes_name as goodsName,-->
<!--        sum(od.quantity - od.goods_refund_num) as quantity,-->
<!--        od.sales_mode,-->
<!--        oi.stall_name as shopstall_name,-->
<!--        oi.canteen_name,-->
<!--        u.username,-->
<!--        cp.user_id,-->
<!--        aa.area_id,-->
<!--        aa.area_name-->
<!--        FROM order_delivery o-->
<!--        INNER join order_info oi on o.order_id = oi.order_id AND oi.order_date = o.order_date-->
<!--        INNER JOIN order_detail od ON oi.order_id = od.order_id AND oi.order_date = od.order_date-->
<!--        LEFT JOIN cust_place cp ON o.delivery_related_id = cp.place_id-->
<!--        left join mgr_user u on u.user_id = cp.user_id-->
<!--        LEFT JOIN alloc_canteen ac ON oi.canteen_id = ac.canteen_id-->
<!--        LEFT JOIN alloc_area aa ON ac.area_id = aa.area_id-->
<!--        WHERE od.detail_state in (1,3)-->
<!--          AND o.delivery_id IN-->
<!--        <foreach collection="deliveryIds" item="item" open="(" close=")" separator=",">-->
<!--            #{item}-->
<!--        </foreach>-->
<!--        <if test="startDate != null">-->
<!--            AND oi.order_date <![CDATA[ >= ]]> #{startDate}-->
<!--        </if>-->
<!--        <if test="endDate != null">-->
<!--            AND oi.order_date <![CDATA[ <= ]]> #{endDate}-->
<!--        </if>-->
<!--        GROUP BY oi.order_type,oi.order_date,oi.mealtime_type,oi.mealtime_name,-->
<!--        od.goods_dishes_id,od.goods_dishes_name,od.sales_mode,oi.stall_name,-->
<!--        oi.canteen_name, u.username,cp.user_id,aa.area_id,aa.area_name-->
<!--        ORDER BY oi.order_date desc, od.goods_dishes_id ASC-->
<!--    </select>-->

<!--    <select id="listOrderForPad" resultType="net.xnzn.core.order.web.vo.OrderListPadVO">-->
<!--        SELECT-->
<!--        oi.order_id,-->
<!--        oi.mac_order_id,-->
<!--        oi.machine_sn,-->
<!--        oi.machine_num,-->
<!--        oi.source_type,-->
<!--        oi.canteen_id,-->
<!--        oi.canteen_name,-->
<!--        oi.stall_id,-->
<!--        oi.stall_name,-->
<!--        oi.room_id,-->
<!--        oi.room_name,-->
<!--        oi.mealtime_name,-->
<!--        oi.meal_code,-->
<!--        oi.order_date,-->
<!--        oi.payable_amount,-->
<!--        oi.discounts_amount,-->
<!--        oi.coupon_amount,-->
<!--        oi.delivery_amount,-->
<!--        oi.packing_amount,-->
<!--        oi.real_amount,-->
<!--        oi.refund_amount,-->
<!--        oi.order_time,-->
<!--        oi.order_type,-->
<!--        oi.order_state,-->
<!--        oi.dishes_state,-->
<!--        oi.order_refund_state,-->
<!--        oi.pay_time,-->
<!--        oi.pay_type,-->
<!--        oi.pay_state,-->
<!--        oi.deduction_type,-->
<!--        oi.comment_state,-->
<!--        oi.remark,-->
<!--        oi.operator_id,-->
<!--        oi.operator_name,-->
<!--        oi.cashier_id,-->
<!--        oi.cashier_name-->
<!--        FROM order_info oi-->
<!--        LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id-->
<!--        WHERE oi.order_id IN-->
<!--        <foreach collection="orderIds" item="orderId" open="(" close=")" separator=",">-->
<!--            #{orderId}-->
<!--        </foreach>-->
<!--        <if test="startDate != null">-->
<!--            AND oi.order_date <![CDATA[ >= ]]> #{startDate}-->
<!--        </if>-->
<!--        <if test="endDate != null">-->
<!--            AND oi.order_date <![CDATA[ <= ]]> #{endDate}-->
<!--        </if>-->
<!--        ORDER BY oi.order_date DESC, oi.order_id desc-->
<!--    </select>-->

<!--    <select id="listOrderForAndroid" resultType="net.xnzn.core.order.android.vo.OrderListAndroidVO">-->
<!--        SELECT-->
<!--        oi.order_id,-->
<!--        oi.mac_order_id,-->
<!--        oi.machine_sn,-->
<!--        oi.machine_num,-->
<!--        oi.plate_serial_num,-->
<!--        oi.source_type,-->
<!--        oi.cust_id,-->
<!--        oi.canteen_id,-->
<!--        oi.canteen_name,-->
<!--        oi.stall_id,-->
<!--        oi.stall_name,-->
<!--        oi.permission_code,-->
<!--        oi.room_id,-->
<!--        oi.room_name,-->
<!--        oi.mealtime_type,-->
<!--        oi.mealtime_name,-->
<!--        oi.meal_code,-->
<!--        oi.order_date,-->
<!--        oi.payable_amount,-->
<!--        oi.discounts_amount,-->
<!--        oi.coupon_amount,-->
<!--        oi.delivery_amount,-->
<!--        oi.packing_amount,-->
<!--        oi.real_amount,-->
<!--        oi.refund_amount,-->
<!--        oi.order_time,-->
<!--        oi.order_type,-->
<!--        oi.order_state,-->
<!--        oi.dishes_state,-->
<!--        oi.order_refund_state,-->
<!--        oi.pay_time,-->
<!--        oi.pay_type,-->
<!--        oi.pay_state,-->
<!--        oi.pay_channel,-->
<!--        oi.deduction_type,-->
<!--        oi.comment_state,-->
<!--        oi.remark,-->
<!--        oi.if_online,-->
<!--        ci.cust_id,-->
<!--        ci.cust_name,-->
<!--        ci.cust_num,-->
<!--        ci.mobile,-->
<!--        oi.org_num,-->
<!--        oi.org_full_name,-->
<!--        mpbs.plate_id AS plateNum-->
<!--        FROM order_info oi-->
<!--        LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id-->
<!--        LEFT JOIN mac_plateid_bind_serial mpbs ON oi.plate_serial_num = mpbs.plate_serial_num-->
<!--        WHERE oi.order_id IN-->
<!--        <foreach collection="orderIds" item="item" open="(" close=")" separator=",">-->
<!--            #{item}-->
<!--        </foreach>-->
<!--        <if test="startDate != null">-->
<!--            AND oi.order_date <![CDATA[ >= ]]> #{startDate}-->
<!--        </if>-->
<!--        <if test="endDate != null">-->
<!--            AND oi.order_date <![CDATA[ <= ]]> #{endDate}-->
<!--        </if>-->
<!--        ORDER BY oi.order_date DESC, oi.order_id DESC-->
<!--    </select>-->
<!--    <select id="queryOrderIdsByGoodsId" resultType="java.lang.Long">-->
<!--        SELECT oi.order_id-->
<!--        FROM order_info oi-->
<!--            JOIN order_detail od ON oi.order_id = od.order_id AND oi.order_date = od.order_date-->
<!--        WHERE-->
<!--            oi.order_state in (1, 2)-->
<!--        AND od.goods_dishes_id = #{goodsDishesId}-->
<!--        AND od.menu_detail_id = #{menuDetailId}-->
<!--        AND oi.order_date BETWEEN #{startDate} AND #{endDate}-->
<!--        GROUP BY oi.order_id-->
<!--        ORDER BY oi.order_id desc-->
<!--    </select>-->
<!--    <select id="listOrderForBackfield" resultType="net.xnzn.core.order.api.vo.OrderInfoBackfieldVO">-->
<!--        SELECT oi.cust_id,-->
<!--        ci.cust_name,-->
<!--        ci.cust_num,-->
<!--        ci.mobile,-->
<!--        oi.org_full_name,-->
<!--        oi.source_type,-->
<!--        oi.machine_sn,-->
<!--        oi.order_id,-->
<!--        oi.order_date,-->
<!--        oi.order_time,-->
<!--        oi.pay_time,-->
<!--        oi.canteen_id,-->
<!--        oi.canteen_name,-->
<!--        oi.stall_id,-->
<!--        oi.stall_name,-->
<!--        oi.room_id,-->
<!--        oi.room_name,-->
<!--        oi.mealtime_type,-->
<!--        oi.mealtime_name,-->
<!--        oi.payable_amount,-->
<!--        oi.real_amount,-->
<!--        oi.delivery_amount,-->
<!--        oi.packing_amount,-->
<!--        oi.pay_type,-->
<!--        oi.deduction_type,-->
<!--        oi.delivery_type,-->
<!--        oi.order_state,-->
<!--        oi.pay_state,-->
<!--        oi.order_refund_state,-->
<!--        oi.dishes_state,-->
<!--        oi.remark,-->
<!--        oi.mac_order_id,-->
<!--        oi.coupon_amount,-->
<!--        oi.machine_num,-->
<!--        oi.pay_channel,-->
<!--        oi.nu_clear_mode,-->
<!--        oi.operator_id,-->
<!--        oi.operator_name,-->
<!--        oi.cashier_id,-->
<!--        oi.cashier_name,-->
<!--        mc.coupon_name,-->
<!--        oi.psn_type_name-->
<!--        FROM order_info oi-->
<!--        LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id-->
<!--        LEFT JOIN mkt_coupon mc ON oi.coupon_id = mc.coupon_num-->
<!--        WHERE oi.order_id IN-->
<!--        <foreach collection="orderIds" item="item" open="(" close=")" separator=",">-->
<!--            #{item}-->
<!--        </foreach>-->
<!--        <if test="startDate != null">-->
<!--            AND oi.order_date <![CDATA[ >= ]]> #{startDate}-->
<!--        </if>-->
<!--        <if test="endDate != null">-->
<!--            AND oi.order_date <![CDATA[ <= ]]> #{endDate}-->
<!--        </if>-->

<!--        ORDER BY oi.order_date DESC, oi.order_id desc-->
<!--    </select>-->

<!--    &lt;!&ndash;app 订单详情&ndash;&gt;-->
<!--    <select id="getAppOrderInfo" resultType="net.xnzn.core.order.web.vo.OrderAppInfoVO">-->
<!--        SELECT-->
<!--            oi.order_id,-->
<!--            oi.mac_order_id,-->
<!--            oi.machine_sn,-->
<!--            oi.machine_num,-->
<!--            oi.source_type,-->
<!--            oi.canteen_id,-->
<!--            oi.canteen_name,-->
<!--            oi.stall_id,-->
<!--            oi.stall_name,-->
<!--            oi.room_id,-->
<!--            oi.room_name,-->
<!--            oi.mealtime_type,-->
<!--            oi.mealtime_name,-->
<!--            oi.meal_code,-->
<!--            oi.order_date,-->
<!--            oi.payable_amount,-->
<!--            oi.discounts_amount,-->
<!--            oi.coupon_amount,-->
<!--            oi.delivery_amount,-->
<!--            oi.packing_amount,-->
<!--            oi.real_amount,-->
<!--            oi.refund_amount,-->
<!--            oi.order_time,-->
<!--            oi.order_type,-->
<!--            oi.order_state,-->
<!--            oi.dishes_state,-->
<!--            oi.order_refund_state,-->
<!--            oi.pay_time,-->
<!--            oi.pay_type,-->
<!--            oi.pay_state,-->
<!--            oi.deduction_type,-->
<!--            oi.comment_state,-->
<!--            oi.remark,-->
<!--            oi.plate_serial_num,-->
<!--            ci.cust_name,-->
<!--            ci.cust_num,-->
<!--            oi.org_num,-->
<!--            oi.org_full_name,-->
<!--            od.delivery_type,-->
<!--            od.delivery_time,-->
<!--            od.delivery_finish_time,-->
<!--            od.consignee_name,-->
<!--            od.consignee_mobile,-->
<!--            od.consignee_address,-->
<!--            mpbs.plate_id AS plateNum-->
<!--        FROM order_info oi-->
<!--                 LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id-->
<!--                 LEFT JOIN order_delivery od on oi.order_id = od.order_id AND oi.order_date = od.order_date-->
<!--                 LEFT JOIN mac_plateid_bind_serial mpbs ON oi.plate_serial_num = mpbs.plate_serial_num-->
<!--        WHERE oi.order_id = #{orderId}-->
<!--          AND oi.order_date BETWEEN #{startDate} AND #{endDate}-->
<!--    </select>-->
<!--    &lt;!&ndash; app分页查询订单列表 &ndash;&gt;-->
<!--    <select id="listAppOrderDetail" resultType="net.xnzn.core.order.web.vo.OrderAppListVO">-->
<!--        SELECT oi.cust_id, ci.cust_name, ci.cust_num, ci.mobile, oi.org_full_name, ci.cust_photo_url, ci.head_portrait_url,-->
<!--        oi.source_type, oi.machine_sn, oi.order_id, oi.order_date, oi.order_time, oi.pay_time, oi.canteen_id, oi.canteen_name, oi.stall_id,-->
<!--        oi.stall_name, oi.mealtime_type, oi.mealtime_name, oi.payable_amount, oi.real_amount, oi.pay_type,-->
<!--        oi.deduction_type, oi.delivery_type, oi.order_state, oi.pay_state, oi.order_refund_state, oi.dishes_state,oi.remark,oi.mac_order_id,-->
<!--        oi.coupon_amount,oi.machine_num, oi.pay_channel,oi.order_type, ci.cust_name ,ci.mobile, oi.plate_serial_num, mpbs.plate_id AS plateNum-->
<!--        FROM order_info oi-->
<!--            LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id-->
<!--            LEFT JOIN mac_plateid_bind_serial mpbs ON oi.plate_serial_num = mpbs.plate_serial_num-->
<!--        WHERE oi.order_id IN-->
<!--        <foreach collection="orderIds" item="orderId" open="(" close=")" separator=",">-->
<!--            #{orderId}-->
<!--        </foreach>-->
<!--        <if test="startDate != null">-->
<!--            AND oi.order_date <![CDATA[ >= ]]> #{startDate}-->
<!--        </if>-->
<!--        <if test="endDate != null">-->
<!--            AND oi.order_date <![CDATA[ <= ]]> #{endDate}-->
<!--        </if>-->
<!--        ORDER BY oi.order_date DESC, oi.order_id desc-->
<!--    </select>-->

<!--    <select id="listOrderAppRefundCheckList" resultType="net.xnzn.core.order.web.vo.OrderAppRefundVO">-->
<!--        SELECT-->
<!--        t.check_state,t.apply_time,t.resress_picurl,t.apply_type,t.order_refund_id,t.apply_reason,-->
<!--        t.fee_rate, t.fee_amount AS refundFeeAmount, t.refund_amount AS applyRefundAmount, t.real_refund_amount AS realRefundAmount,-->
<!--        t.check_by, t.check_result, t.check_time,-->
<!--        ci.cust_num,ci.cust_name,ci.mobile,oi.org_full_name,-->
<!--        oi.cust_id,oi.order_id,oi.mac_order_id,oi.canteen_id, oi.canteen_name,-->
<!--        oi.stall_id,oi.stall_name,oi.order_type,oi.mealtime_type,oi.payable_amount, oi.real_amount,-->
<!--        oi.mealtime_name,oi.plate_serial_num,oi.order_state,oi.order_date,oi.order_time,-->
<!--        IF(t.check_state = 1, 1, 2) AS isWaitCheck-->
<!--        FROM order_refund t-->
<!--        LEFT JOIN order_info oi ON t.order_id = oi.order_id-->
<!--        LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id-->
<!--        WHERE t.order_refund_id IN-->
<!--        <foreach collection="orderRefundIds" item="item" open="(" close=")" separator=",">-->
<!--            #{item}-->
<!--        </foreach>-->
<!--        <if test="startDate != null">-->
<!--            AND oi.order_date <![CDATA[ >= ]]> #{startDate}-->
<!--        </if>-->
<!--        <if test="endDate != null">-->
<!--            AND oi.order_date <![CDATA[ <= ]]> #{endDate}-->
<!--        </if>-->
<!--        ORDER BY isWaitCheck, t.order_refund_id DESC-->
<!--    </select>-->
</mapper>
