<?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.canteen.core.order.deprecated.mapper.OrdAppInfoMapper">

    <!--查询订单并获取对应的菜品明细-->
    <resultMap id="ordInfoDetailMap" type="com.bonus.canteen.core.order.deprecated.vo.OrdInfoVO">
        <id property="id" column="id"/>
        <result property="ordId" column="ord_id"/>
        <result property="leOrdId" column="le_ord_id"/>
        <result property="totalOrdId" column="total_ord_id"/>
        <result property="leTotalOrdId" column="le_total_ord_id"/>
        <result property="custId" column="cust_id"/>
        <result property="refundOrdId" column="refund_ord_id"/>
        <result property="thirdPayOrdId" column="third_pay_ord_id"/>
        <result property="openid" column="openid"/>
        <result property="sourceType" column="source_type"/>
        <result property="shopstallName" column="shopstall_name"/>
        <result property="shopstallId" column="shopstall_id"/>
        <result property="shopstallCallNum" column="shopstall_call_num"/>
        <result property="mchNum" column="mch_num"/>
        <result property="mchName" column="mch_name"/>
        <result property="macOrdId" column="mac_ord_id"/>
        <result property="nuClearMode" column="nu_clear_mode"/>
        <result property="ifOnline" column="if_online"/>
        <result property="consumMode" column="consum_mode"/>
        <result property="machineSn" column="machine_sn"/>
        <result property="ordGoodsDate" column="ord_goods_date"/>
        <result property="ordTime" column="ord_time"/>
        <result property="repairDeductDate" column="repair_deduct_date"/>
        <result property="placeOrdName" column="place_ord_name"/>
        <result property="placeOrdMobile" column="place_ord_mobile"/>
        <result property="canteenId" column="canteen_id"/>
        <result property="canteenName" column="canteen_name"/>
        <result property="intervalId" column="interval_id"/>
        <result property="intervalName" column="interval_name"/>
        <result property="tableId" column="table_id"/>
        <result property="couponId" column="coupon_id"/>
        <result property="payType" column="pay_type"/>
        <result property="payState" column="pay_state"/>
        <result property="amount" column="amount"/>
        <result property="couponReduce" column="coupon_reduce"/>
        <result property="voucherReduce" column="voucher_reduce"/>
        <result property="discountReduce" column="discount_reduce"/>
        <result property="redEnvelopeReduce" column="red_envelope_reduce"/>
        <result property="subsidyReduce" column="subsidy_reduce"/>
        <result property="personalPay" column="personal_pay"/>
        <result property="thirdAmount" column="third_amount"/>
        <result property="thirdPayType" column="third_pay_type"/>
        <result property="deliveryFee" column="delivery_fee"/>
        <result property="realAmount" column="real_amount"/>
        <result property="accBal" column="acc_bal"/>
        <result property="payTime" column="pay_time"/>
        <result property="refundTime" column="refund_time"/>
        <result property="takeOutFlag" column="take_out_flag"/>
        <result property="ifPrint" column="if_print"/>
        <result property="ifWriteOff" column="if_write_off"/>
        <result property="counterId" column="counter_id"/>
        <result property="deliverId" column="deliver_id"/>
        <result property="deliveryType" column="delivery_type"/>
        <result property="deliveryAddr" column="delivery_addr"/>
        <result property="ordState" column="ord_state"/>
        <result property="relateOrdId" column="relate_ord_id"/>
        <result property="ifReverse" column="if_reverse"/>
        <result property="remark" column="remark"/>
        <result property="checkState" column="check_state"/>
        <result property="reason" column="reason"/>
        <result property="resressPicurl" column="resress_picurl"/>
        <result property="revision" column="revision"/>
        <result property="crby" column="crby"/>
        <result property="crtime" column="crtime"/>
        <result property="upby" column="upby"/>
        <result property="uptime" column="uptime"/>
        <result property="custNum" column="custNum"/>
        <result property="custName" column="custName"/>
        <result property="orgFullName" column="orgFullName"/>
        <result property="psnType" column="psnType"/>
        <result property="psnTypeName" column="psnTypeName"/>
        <collection property="ordDetailList" ofType="com.bonus.canteen.core.order.deprecated.vo.OrdDetailMachineVO">
            <result property="detailId" column="detailId"/>
            <result property="goodsName" column="goodsName"/>
            <result property="price" column="price"/>
            <result property="quantity" column="quantity"/>
            <result property="ordState" column="ordState"/>
            <result property="realAmount" column="realAmount"/>
            <result property="unit" column="unit"/>
        </collection>
    </resultMap>

    <!-- 分页查询订单信息 订单中心-订单明细-->
    <select id="queryPageOrdInfoDetail" resultMap="ordInfoDetailMap"
            parameterType="com.bonus.canteen.core.order.deprecated.param.OrdParam">
        select
        oai.*,ci.cust_num custNum,ci.cust_name custName,
        ci.org_full_name orgFullName,ci.psn_type psnType, cp.psn_type_name psnTypeName

        from order_info oai
        left join cust_info ci on ci.cust_id = oai.cust_id
        left join acc_card ac on ac.cust_id = oai.cust_id and  ac.card_status in (1,4)
        left join cust_psn_type cp on cp.psn_type = ci.psn_type
        <where>
            <if test="ordParam.ordId != null">
                and oai.order_id = #{ordParam.ordId}
            </if>
            <if test="ordParam.macOrdId != null">
                and oai.mac_order_id like concat('%',#{ordParam.macOrdId})
            </if>
            <!--查询超市类型的订单 12,13-->
            <if test="ordParam.ordTypeList != null and ordParam.ordTypeList.size() > 0">
                and oai.order_type in
                <foreach collection="ordParam.ordTypeList" item="ordType" separator="," open="(" close=")">
                    #{ordType}
                </foreach>
            </if>
            <if test="ordParam.orgIdList != null and ordParam.orgIdList.size() > 0">
                and ci.org_id in
                <foreach collection="ordParam.orgIdList" item="orgId" separator="," open="(" close=")">
                    #{orgId}
                </foreach>
            </if>
            <if test="ordParam.custId != null">
                and ci.cust_id = #{ordParam.custId}
            </if>

            <if test="ordParam.custNum != null">
                and ci.cust_num = #{ordParam.custNum}
            </if>
            <if test="ordParam.custName != null and ordParam.custName != ''">
                and ci.cust_name like #{ordParam.custName}
            </if>
            <if test="ordParam.mobile != null">
                and ci.cust_name = #{ordParam.mobile,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
            </if>
            <if test="ordParam.keywords != null and ordParam.keywords != ''">
                and (
                    ci.cust_name = #{ordParam.keywords,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                    OR ci.cust_num = #{ordParam.keywords,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                    OR ci.mobile = #{ordParam.keywords,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                    OR ci.mobile_suffix = #{ordParam.keywords,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
                )
            </if>
            <if test="ordParam.psnTypeList != null and ordParam.psnTypeList.size() > 0">
                and ci.psn_type in
                <foreach collection="ordParam.psnTypeList" item="psnType" separator="," open="(" close=")">
                    #{psnType}
                </foreach>
            </if>
            <if test="ordParam.canteenId != null">
                and oai.canteen_id = #{ordParam.canteenId}
            </if>
            <if test="ordParam.shopstallId != null">
                and oai.stall_id = #{ordParam.shopstallId}
            </if>
            <if test="ordParam.sourceTypeList != null and ordParam.sourceTypeList.size() > 0">
                and oai.source_type in
                <foreach collection="ordParam.sourceTypeList" item="sourceType" separator="," open="(" close=")">
                    #{sourceType}
                </foreach>
            </if>
            <if test="ordParam.ordStateList != null and ordParam.ordStateList.size() > 0">
                and oai.order_state in
                <foreach collection="ordParam.ordStateList" item="ordState" separator="," open="(" close=")">
                    #{ordState}
                </foreach>
            </if>
            <if test="ordParam.payTypeList != null and ordParam.payTypeList.size() > 0">
                and oai.pay_type in
                <foreach collection="ordParam.payTypeList" item="payType" separator="," open="(" close=")">
                    #{payType}
                </foreach>
            </if>
            <if test="ordParam.payStateList != null and ordParam.payStateList.size() > 0">
                and oai.pay_state in
                <foreach collection="ordParam.payStateList" item="payState" separator="," open="(" close=")">
                    #{payState}
                </foreach>
            </if>
            <if test="ordParam.deliveryTypeList != null and ordParam.deliveryTypeList.size() > 0">
                and oai.delivery_type in
                <foreach collection="ordParam.deliveryTypeList" item="deliveryType" separator="," open="(" close=")">
                    #{deliveryType}
                </foreach>
            </if>
            <if test="ordParam.ordDateMin != null and ordParam.ordDateMax != null">
                <![CDATA[and oai.order_date >= #{ordParam.ordDateMin}]]>
                <![CDATA[and oai.order_date <= #{ordParam.ordDateMax}]]>
            </if>
            <if test="ordParam.ordTimeMin != null and ordParam.ordTimeMax != null">
                <![CDATA[and oai.order_time >= #{ordParam.ordTimeMin}]]>
                <![CDATA[and oai.order_time <= #{ordParam.ordTimeMax}]]>
            </if>
            <if test="ordParam.payTimeMin != null and ordParam.payTimeMax != null">
                <![CDATA[and oai.pay_time >= #{ordParam.payTimeMin}]]>
                <![CDATA[and oai.pay_time <= #{ordParam.payTimeMax}]]>
            </if>
            <if test="ordParam.realAmountMin != null and ordParam.realAmountMax != null">
                <![CDATA[and oai.real_amount >= #{ordParam.realAmountMin}]]>
                <![CDATA[and oai.real_amount <= #{ordParam.realAmountMax}]]>
            </if>
            <if test="ordParam.intervalIdList != null and ordParam.intervalIdList.size() > 0">
                and oai.mealtime_type in
                <foreach collection="ordParam.intervalIdList" item="intervalId" separator="," open="(" close=")">
                    #{intervalId}
                </foreach>
            </if>
            <if test="ordParam.mchNum != null and ordParam.mchNum != ''">
                and oai.machine_num = #{ordParam.mchNum}
            </if>
            <if test="ordParam.nuClearModeList != null and ordParam.nuClearModeList.size() > 0">
                and oai.nu_clear_mode in
                <foreach collection="ordParam.nuClearModeList" item="nuClearMode" separator="," open="(" close=")">
                    #{nuClearMode}
                </foreach>
            </if>
            <if test="ordParam.ifOnline != null and ordParam.ifOnline != ''">
                and oai.if_online = #{ordParam.ifOnline}
            </if>
            <if test="ordParam.consumModeList != null and ordParam.consumModeList.size() > 0">
                and oai.consum_mode in
                <foreach collection="ordParam.consumModeList" item="consumMode" separator="," open="(" close=")">
                    #{consumMode}
                </foreach>
            </if>
<!--            <if test="ordParam.checkStateList != null and ordParam.checkStateList.size() > 0">-->
<!--                and oai.check_state in-->
<!--                <foreach collection="ordParam.checkStateList" item="checkState" separator="," open="(" close=")">-->
<!--                    #{checkState}-->
<!--                </foreach>-->
<!--            </if>-->
            <if test="ordParam.machineSn != null and ordParam.machineSn != ''">
                and oai.machine_sn = #{ordParam.machineSn}
            </if>
<!--            <if test="ordParam.ifReverse != null">-->
<!--                and oai.if_reverse = #{ordParam.ifReverse}-->
<!--            </if>-->
<!--            <if test="ordParam.relateOrdId != null">-->
<!--                and oai.relate_ord_id = #{ordParam.relateOrdId}-->
<!--            </if>-->
            <if test="ordParam.serialNum != null">
                and ac.serial_num = #{ordParam.serialNum}
            </if>
            /**登录人权限*/
            <if test="'2'.toString() == authPO.roleType.toString()">
                and EXISTS (
                SELECT null
                FROM mgr_role_org it1
                LEFT JOIN mgr_role it2 ON it2.role_id = it1.role_id
                LEFT JOIN mgr_user_role it3 ON it1.role_id = it3.role_id
                WHERE it2.del_flag = 2
                AND it2.role_code = #{authPO.roleCode}
                AND it1.half_select = 1
                AND it3.user_id = #{authPO.userId}
                AND ci.org_id = it1.org_id
                )
            </if>
            <if test="'3'.toString() == authPO.roleType.toString()">
                AND EXISTS(
                SELECT NULL
                FROM mgr_role_canteen it1
                LEFT JOIN mgr_role it2 ON it2.role_id = it1.role_id
                LEFT JOIN mgr_user_role it3 ON it1.role_id = it3.role_id
                WHERE it2.del_flag = 2
                AND it2.role_code = #{authPO.roleCode}
                AND it1.half_select = 1
                AND it3.user_id = #{authPO.userId}
                AND (oai.stall_id = it1.data_id or oai.canteen_id = it1.data_id)
                )
            </if>
        </where>
        order by oai.order_date desc,oai.order_time desc
    </select>

    <select id="macOrdInfoDetailByConditon" resultType="com.bonus.canteen.core.order.deprecated.vo.MacMarketOrdInfoVO">
        SELECT
        t1.order_id  as ordId,
        t1.order_date as ordGoodsDate,
        t1.order_time as ordTime,
        t1.payable_amount as amount,
        t1.real_amount as realAmount,
        t1.order_state as ordState,
        t1.order_refund_state as ordRefundState,
        t1.dishes_state,
        t2.cust_name ,
        t2.cust_num  ,
        t2.mobile  ,
        t2.org_full_name
        FROM  order_info t1
        LEFT JOIN cust_info t2 ON t1.cust_id = t2.cust_id
        <where>
            t1.order_type in(4, 5)
            <if test="marketOrdDTO.ordId != null">
                AND t1.order_id LIKE concat('%', #{marketOrdDTO.ordId},'%')
            </if>
            <if test="marketOrdDTO.machineSn != null">
                and t1.machine_sn = #{marketOrdDTO.machineSn}
            </if>
            <if test="marketOrdDTO.startDate != null and marketOrdDTO.endDate != null">
                AND t1.order_date BETWEEN #{marketOrdDTO.startDate} AND #{marketOrdDTO.endDate}
            </if>
            <if test="marketOrdDTO.mixCondition != null and marketOrdDTO.mixCondition != '' ">
                AND concat(t2.cust_num,t2.cust_name,t2.mobile) LIKE concat('%', #{marketOrdDTO.mixCondition},'%')
            </if>
        </where>
        order by t1.order_date desc,t1.order_time desc
    </select>

    <select id="pageMacOrdInfoNotWriteOff" resultType="com.bonus.canteen.core.order.deprecated.vo.MacMarketOrdInfoVO">
        SELECT
        t1.order_id  as ordId,
        t1.order_date as ordGoodsDate,
        t1.order_time as ordTime,
        t1.payable_amount as amount,
        t1.real_amount as realAmount,
        t1.order_state as ordState,
        t1.order_refund_state as ordRefundState,
        t1.dishes_state,
        t1.order_time as ordTime,
        t1.order_date as ordGoodsDate,
        2 as ifWriteOff,

        t2.cust_name,
        t2.cust_num,
        t2.mobile,
        t2.org_full_name
        FROM order_info t1
        LEFT JOIN cust_info t2 ON t1.cust_id = t2.cust_id
        WHERE
            t1.order_type in (4 ,5)
            AND t1.dishes_state = 3
            AND t1.pay_state = 3
            AND t1.order_refund_state IN (1,3)
            <if test="marketOrdDTO.ordId != null and marketOrdDTO.ordId != ''">
                AND t1.order_id = #{marketOrdDTO.ordId}
            </if>
            <if test="marketOrdDTO.canteenId != null">
                AND t1.canteen_id = #{marketOrdDTO.canteenId}
            </if>
            <if test="marketOrdDTO.custId != null">
                AND t1.cust_id = #{marketOrdDTO.custId}
            </if>
            <if test="marketOrdDTO.localdate != null">
                <![CDATA[and t1.order_date <= #{marketOrdDTO.localdate}]]>
            </if>
        order by t1.order_date desc,t1.order_time desc
    </select>

    <!--获取订单列表（设备端  无商城订单）-->
    <select id="getOrderListForAndroid" resultType="com.bonus.canteen.core.order.deprecated.vo.OrdAssignSrcMacVO">
        SELECT oi.order_id AS ordId,
        oi.mac_order_id AS macOrdId,
        oi.order_date AS ordGoodsDate,
        oi.source_type AS sourceType,
        oi.pay_state AS payState,
        oi.order_state,
        oi.order_refund_state AS orderRefundState,
        ci.cust_name AS custName,
        oi.stall_id AS shopstallId,
        oi.stall_name AS shopstallName,
        oi.meal_code AS shopstallCallNum,
        oi.mealtime_name AS intervalName,
        oi.pay_time AS payTime,
        oi.order_date AS ordGoodsDate,
        oi.dishes_state
        FROM order_info oi
        LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id
        WHERE
        oi.order_date = #{localdate}
        AND oi.order_refund_state IN (1, 3)
        <if test="custId != null">
            AND oi.cust_id = #{custId}
        </if>
        <if test="canteenId != null">
            AND oi.canteen_id = #{canteenId}
        </if>
        <if test="shopstallId != null">
            AND oi.stall_id = #{shopstallId}
        </if>
        <if test="payState != null">
            AND oi.pay_state = #{payState}
        </if>
        <if test="ordState != null">
            AND oi.order_state = #{ordState}
        </if>
        <if test="mealtimeType != null ">
            AND oi.mealtime_type = #{mealtimeType}
        </if>
        <if test="deliveryType != null">
            AND oi.delivery_type = #{deliveryType}
        </if>
        ORDER BY oi.order_date DESC, oi.order_id DESC
    </select>

    <!--获取商城订单列表（设备端）-->
    <select id="getOrderShopListForAndroid" resultType="com.bonus.canteen.core.order.deprecated.vo.OrdAssignSrcMacVO">
        SELECT oi.order_id AS ordId,
        oi.mac_order_id AS macOrdId,
        oi.source_type AS sourceType,
        oi.order_date AS ordGoodsDate,
        oi.pay_state AS payState,
        oi.order_state,
        oi.order_refund_state AS orderRefundState,
        ci.cust_name AS custName,
        oi.stall_id AS shopstallId,
        oi.stall_name AS shopstallName,
        oi.meal_code AS shopstallCallNum,
        oi.mealtime_name AS intervalName,
        oi.pay_time AS payTime,
        oi.order_date AS ordGoodsDate,
        oi.dishes_state
        FROM order_info oi
        LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id
        WHERE
        oi.order_date >= #{localdate}
        AND oi.order_refund_state IN (1, 3)
        <if test="custId != null">
            and oi.cust_id = #{custId}
        </if>
        <if test="payState != null">
            and oi.pay_state = #{payState}
        </if>
        <if test="ordState != null">
            and oi.order_state = #{ordState}
        </if>
        <if test="deliveryType != null">
            and oi.delivery_type = #{deliveryType}
        </if>
        <if test="canteenId != null">
            AND oi.canteen_id = #{canteenId}
        </if>
        and oi.order_type = 4
        order by oi.order_date DESC, oi.order_id desc
    </select>

    <!--获取当餐预订的订单-->
    <select id="getReserveOrderListForAndroid" resultType="com.bonus.canteen.core.order.deprecated.vo.OrdCurrentReserveMacVO">
        SELECT order_id AS ordId,
        source_type AS sourceType
        FROM order_info oi
        WHERE order_date = #{localdate}
        <if test="custId != null">
            AND cust_id = #{custId}
        </if>
        <if test="canteenId != null">
            AND canteen_id = #{canteenId}
        </if>
        <if test="shopstallId != null">
            AND stall_id = #{shopstallId}
        </if>
        <if test="payState != null">
            AND pay_state = #{payState}
        </if>
        <if test="ordState != null">
            AND order_state = #{ordState}
        </if>
        <if test="intervalId != null ">
            AND mealtime_type = #{intervalId}
        </if>
        ORDER BY order_id DESC LIMIT 1
    </select>

    <select id="queryOrdListBySn" resultType="com.bonus.canteen.core.order.deprecated.vo.OrdAssignSrcMacOldVO">
        SELECT oi.order_id AS ordId,
        oi.mac_order_id AS macOrdId,
        oi.source_type AS sourceType,
        oi.pay_state AS payState,
        oi.order_state,
        oi.order_refund_state AS orderRefundState,
        ci.cust_name AS custName,
        oi.stall_id AS shopstallId,
        oi.stall_name AS shopstallName,
        oi.meal_code AS shopstallCallNum,
        oi.mealtime_name AS intervalName,
        oi.pay_time AS payTime,
        oi.order_date AS ordGoodsDate,
        oi.real_amount AS realAmount
        FROM order_info oi
        LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id
        WHERE
        oi.order_date = #{orderDate}
        <if test="ordRefundQueryDTO.custId != null">
            AND oi.cust_id = #{ordRefundQueryDTO.custId}
        </if>
        <if test="ordRefundQueryDTO.machineSn != null and ordRefundQueryDTO.machineSn != ''">
            AND oi.machine_sn = #{ordRefundQueryDTO.machineSn}
        </if>
        <if test="payState != null">
            AND oi.pay_state = #{payState}
        </if>
        ORDER BY oi.uptime DESC, oi.order_id DESC limit 3
    </select>

    <select id="queryPageOrdInfoMachine" resultType="com.bonus.canteen.core.order.deprecated.vo.OrdInfoVO"
            parameterType="com.bonus.canteen.core.order.deprecated.param.OrdMachineParam">
        SELECT oi.order_id AS ordId,
        oi.mac_order_id AS macOrdId,
        oi.machine_sn AS machineSn,
        oi.machine_num AS mchNum,
        oi.cust_id AS custId,
        oi.nu_clear_mode AS nuClearMode,
        oi.consum_mode AS consumMode,
        oi.source_type AS sourceType,
        oi.if_online AS ifOnline,
        oi.canteen_id AS canteenId,
        oi.canteen_name AS canteenName,
        oi.stall_id AS shopstallId,
        oi.stall_name AS shopstallName,
        oi.mealtime_type AS intervalId,
        oi.mealtime_name AS intervalName,
        oi.meal_code AS shopstallCallNum,
        oi.order_date AS ordGoodsDate,
        oi.coupon_id AS couponId,
        oi.payable_amount AS amount,
        oi.discounts_amount AS discountReduce,
        oi.coupon_amount AS couponReduce,
        oi.delivery_amount AS deliveryFee,
        oi.real_amount AS realAmount,
        oi.acc_pay_amount AS personalPay,
        oi.out_pay_amount AS thirdAmount,
        oi.order_time AS ordTime,
        oi.order_type AS takeOutFlag,
        oi.order_state AS ordState,
        oi.order_refund_state AS ordRefundState,
        oi.pay_time AS payTime,
        oi.pay_type AS payType,
        oi.pay_state AS payState,
        oi.delivery_type AS deliveryType,
        oi.dishes_state AS dishesState,
        oi.remark,
        ci.cust_num AS custNum,
        ci.cust_name AS custName,
        ci.org_full_name AS orgFullName,
        ci.psn_type AS psnType,
        ci.psn_type_name AS psnTypeName
        FROM order_info oi
        LEFT JOIN cust_info ci ON ci.cust_id = oi.cust_id
        <if test="ordMachineParam.serialNum != null and ordMachineParam.serialNum != ''">
            LEFT JOIN acc_card ac ON ci.cust_id = ac.cust_id and  ac.card_status in (1,4)
        </if>
        <where>
            <if test="ordMachineParam.custId != null">
                AND oi.cust_id = #{ordMachineParam.custId}
            </if>
            <if test="ordMachineParam.machineSn != null">
                AND oi.machine_sn = #{ordMachineParam.machineSn}
            </if>
            <if test="ordMachineParam.mchNum != null">
                AND oi.machine_num = #{ordMachineParam.mchNum}
            </if>
            <if test="ordMachineParam.localdate != null ">
                AND oi.order_date = #{ordMachineParam.localdate}
            </if>
            <if test="ordMachineParam.mealtimeType != null ">
                AND oi.mealtime_type = #{ordMachineParam.mealtimeType}
            </if>
            <if test="ordMachineParam.ifWriteOff == 1">
                AND oi.order_state = 2
            </if>
            <if test="ordMachineParam.ifWriteOff == 2">
                AND oi.order_state = 1
            </if>
            <if test="ordMachineParam.serialNum != null and ordMachineParam.serialNum != ''">
                AND ac.serial_num = #{ordMachineParam.serialNum}
            </if>
        </where>
        ORDER BY oi.order_date DESC, oi.order_id DESC
    </select>

<!--    &lt;!&ndash;手持机&ndash;&gt;-->

<!--    <select id="pageOrdInfoDetailByOperatorId" resultType="net.xnzn.core.order.deprecated.vo.MacOrdInfoDetailVO">-->
<!--        SELECT-->
<!--        A.order_id as ord_id ,-->
<!--        o.consignee_name as custName,-->
<!--        o.consignee_mobile as mobile,-->
<!--        A.order_date as ord_goods_date ,-->
<!--        A.order_time as ord_time ,-->
<!--        A.canteen_name ,-->
<!--        A.stall_name as shopstall_name ,-->
<!--        A.mealtime_name as interval_name ,-->
<!--        A.payable_amount as amount ,-->
<!--        A.real_amount ,-->
<!--        1 as if_print,-->
<!--        o.delivery_related_id as place_id,-->
<!--        o.consignee_address as deliveryAddr,-->

<!--        A.order_type,-->
<!--        A.order_state,-->
<!--        A.pay_state,-->
<!--        A.order_refund_state,-->
<!--        A.dishes_state-->

<!--        FROM order_info A-->
<!--        left join order_delivery o on o.order_id = A.order_id AND o.order_date = A.order_date-->
<!--        JOIN  cust_place B ON o.delivery_related_id = B.place_id-->
<!--        WHERE-->
<!--        B.user_id =#{macTradeDTO.operatorId}-->
<!--        <if test="macTradeDTO.ordType == 2">-->
<!--            AND A.order_refund_state = 2-->
<!--        </if>-->
<!--        <if test="macTradeDTO.ordType == 3">-->
<!--            AND A.order_state = 2 and A.order_refund_state != 2 and A.dishes_state = 4-->
<!--        </if>-->
<!--        <if test="macTradeDTO.startDate != null and macTradeDTO.endDate != null">-->
<!--            AND A.order_date BETWEEN #{macTradeDTO.startDate} AND #{macTradeDTO.endDate}-->
<!--        </if>-->
<!--        order by A.order_id desc-->
<!--    </select>-->

<!--    <select id="countTodayTotalOrd" resultType="java.lang.Long">-->
<!--        SELECT COUNT(A.order_id)-->
<!--        FROM order_info A-->
<!--                 left join order_delivery o on o.order_id = A.order_id AND A.order_date = o.order_date-->
<!--                 LEFT JOIN cust_place B ON o.delivery_related_id = B.place_id-->
<!--        WHERE B.user_id = #{userId}-->
<!--          AND A.order_date = #{today}-->
<!--          AND A.pay_state = 3 AND A.order_refund_state != 2-->
<!--    </select>-->

<!--    <select id="countTodayDeliveryOrd" resultType="java.lang.Long">-->
<!--        SELECT COUNT(*)-->
<!--        FROM order_info A-->
<!--                 left join order_delivery o on o.order_id = A.order_id AND o.order_date = A.order_date-->
<!--                 LEFT JOIN cust_place B ON o.delivery_related_id = B.place_id-->
<!--        WHERE B.user_id = #{userId}-->
<!--          AND A.order_state = #{state}-->
<!--          AND A.order_date = #{today}-->
<!--          AND A.pay_state = 3 AND A.order_refund_state != 2-->
<!--          AND A.dishes_state = 4-->
<!--    </select>-->

<!--    <select id="queryTakeMeal" resultType="net.xnzn.core.order.deprecated.vo.AppletListTakeMealVO">-->
<!--        SELECT A.order_date as ord_goods_date,-->
<!--        A.mealtime_type as interval_id,-->
<!--        A.mealtime_name as interval_name,-->
<!--        A.canteen_id,-->
<!--        A.canteen_name,-->
<!--        A.stall_id as shopstall_id,-->
<!--        A.stall_name as shopstall_name-->
<!--        FROM order_info A-->
<!--        left join order_delivery o on o.order_id = A.order_id AND o.order_date = A.order_date-->
<!--        LEFT JOIN cust_place B ON o.delivery_related_id = B.place_id-->
<!--        WHERE B.user_id = #{operatorId}-->
<!--        AND A.pay_state = 3 AND A.order_refund_state != 2-->
<!--        <if test="param.date != null">-->
<!--            AND A.order_date = #{param.date}-->
<!--        </if>-->
<!--        <if test="param.intervalId != null and param.intervalId != 0L">-->
<!--            AND A.mealtime_type = #{param.intervalId}-->
<!--        </if>-->
<!--        <if test="param.canteenId != null and param.canteenId != 0L">-->
<!--            AND A.canteen_id = #{param.canteenId}-->
<!--        </if>-->
<!--        <if test="param.shopstallId != null and param.shopstallId != 0L">-->
<!--            AND A.stall_id = #{param.shopstallId}-->
<!--        </if>-->
<!--        GROUP BY A.order_date, A.mealtime_type, A.mealtime_name,-->
<!--        A.canteen_id, A.canteen_name, A.stall_id, A.stall_name-->
<!--    </select>-->

<!--    <select id="queryTakeMealDetail" resultType="net.xnzn.core.order.deprecated.vo.AppletListTakeMealDetailVO">-->
<!--        SELECT B.goods_dishes_name as goods_name,-->
<!--               COUNT(B.quantity - B.goods_refund_num) AS quantity-->
<!--        FROM order_info A-->
<!--                 left join order_delivery o on o.order_id = A.order_id AND o.order_date = A.order_date-->
<!--                 INNER JOIN order_detail B ON A.order_id = B.order_id AND A.order_date = B.order_date-->
<!--                 LEFT JOIN cust_place C ON C.place_id = o.delivery_related_id-->
<!--        WHERE C.user_id = #{operatorId}-->
<!--          AND A.canteen_id = #{param.canteenId}-->
<!--          AND A.stall_id = #{param.shopstallId}-->
<!--          AND A.mealtime_type = #{param.intervalId}-->
<!--          AND A.order_date = #{param.ordGoodsDate}-->
<!--          AND A.pay_state = 3 AND A.order_refund_state != 2-->
<!--        GROUP BY B.goods_dishes_name-->
<!--    </select>-->

<!--    <select id="queryTakeMealSum" resultType="net.xnzn.core.order.deprecated.vo.AppletListTakeMealSumVO">-->
<!--        SELECT-->
<!--        sum(B.quantity) AS quantity,-->
<!--        sum(B.real_amount) AS real_amount-->
<!--        FROM order_info A-->
<!--        left join order_delivery o on o.order_id = A.order_id AND o.order_date = A.order_date-->
<!--        INNER JOIN order_detail B ON A.order_id = B.order_id AND A.order_date = B.order_date-->
<!--        LEFT JOIN cust_place C ON C.place_id = o.delivery_related_id-->
<!--        WHERE C.user_id = #{operatorId} AND A.pay_state = 3 AND A.order_refund_state != 2-->
<!--        <if test="param.date != null">-->
<!--            AND A.order_date = #{param.date}-->
<!--        </if>-->
<!--        <if test="param.intervalId != null and param.intervalId != 0L">-->
<!--            AND A.mealtime_type = #{param.intervalId}-->
<!--        </if>-->
<!--        <if test="param.canteenId != null and param.canteenId != 0L">-->
<!--            AND A.canteen_id = #{param.canteenId}-->
<!--        </if>-->
<!--        <if test="param.shopstallId != null and param.shopstallId != 0L">-->
<!--            AND A.stall_id = #{param.shopstallId}-->
<!--        </if>-->
<!--        <if test="param.takeOutFlag != null">-->
<!--            AND A.order_type = #{param.takeOutFlag}-->
<!--        </if>-->
<!--    </select>-->

<!--    <select id="countNotSendNum" resultType="net.xnzn.core.order.common.vo.OrderUnDeliveredCountVO">-->
<!--        SELECT o.delivery_related_id AS placeId, COUNT(A.order_id) AS unDeliveredCount-->
<!--        FROM order_info A-->
<!--        left join order_delivery o on o.order_id = A.order_id AND o.order_date = A.order_date-->
<!--        LEFT JOIN cust_info B ON A.cust_id = B.cust_id-->
<!--        LEFT JOIN cust_place C ON o.delivery_related_id = C.place_id-->
<!--        WHERE C.user_id = #{param.userId} AND A.order_date = #{param.date}-->
<!--        AND A.pay_state = 3 AND A.order_refund_state != 2 AND A.dishes_state != 4-->
<!--        <if test="placeIds != null and placeIds.size > 0">-->
<!--            AND o.delivery_related_id IN-->
<!--            <foreach collection="placeIds" separator="," open="(" close=")" item="placeId">-->
<!--                #{placeId}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.date != null">-->
<!--            AND A.order_date = #{param.date}-->
<!--        </if>-->
<!--        <if test="param.intervalId != null and param.intervalId != 0L">-->
<!--            AND A.mealtime_type = #{param.intervalId}-->
<!--        </if>-->
<!--        <if test="param.custName != null and param.custName != ''">-->
<!--            AND B.cust_name = #{param.custName}-->
<!--        </if>-->
<!--        <if test="param.mobile != null and param.mobile != ''">-->
<!--            AND B.mobile = #{param.mobile}-->
<!--        </if>-->
<!--        GROUP BY o.delivery_related_id-->
<!--    </select>-->

<!--    <select id="queryDeliveryOrdDetail" resultType="net.xnzn.core.order.deprecated.vo.AppletListDeliveryMealOrdVO">-->
<!--        SELECT-->
<!--        A.order_id as ord_id ,-->
<!--        o.consignee_address as delivery_addr ,-->
<!--        case A.dishes_state when 4 then 11 else 1 end as ord_state ,-->
<!--        B.cust_name ,-->
<!--        B.mobile ,-->
<!--        A.order_date as ord_goods_date-->
<!--        FROM order_info A-->
<!--        left join order_delivery o on o.order_id = A.order_id AND o.order_date = A.order_date-->
<!--        LEFT JOIN cust_info B ON A.cust_id = B.cust_id-->
<!--        LEFT JOIN cust_place C ON C.place_id = o.delivery_related_id-->
<!--        WHERE C.user_id = #{param.userId} AND A.pay_state = 3  AND A.order_refund_state != 2 AND-->
<!--        A.order_date = #{param.date} AND o.order_date = #{param.date}-->
<!--        <if test="placeIds != null and placeIds.size > 0">-->
<!--            AND o.delivery_related_id IN-->
<!--            <foreach collection="placeIds" item="placeId" open="(" close=")" separator=",">-->
<!--                #{placeId}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.date != null">-->
<!--            AND A.order_date = #{param.date}-->
<!--        </if>-->
<!--        <if test="param.intervalId != null and param.intervalId != 0L">-->
<!--            AND A.mealtime_type = #{param.intervalId}-->
<!--        </if>-->
<!--        <if test="param.custName != null and param.custName != ''">-->
<!--            AND B.cust_name = #{param.custName}-->
<!--        </if>-->
<!--        <if test="param.mobile != null and param.mobile != ''">-->
<!--            AND B.mobile = #{param.mobile}-->
<!--        </if>-->
<!--    </select>-->

<!--    <select id="queryCustPlaceDutyAreaByDTO" resultType="java.lang.Long">-->
<!--        SELECT DISTINCT B.place_id-->
<!--        FROM order_info A-->
<!--        left join order_delivery o on o.order_id = A.order_id AND o.order_date = A.order_date-->
<!--        LEFT JOIN cust_place B ON o.delivery_related_id = B.place_id-->
<!--        LEFT JOIN cust_info C ON A.cust_id = C.cust_id-->
<!--        WHERE B.user_id = #{param.userId}-->
<!--        AND A.order_date = #{param.date}-->
<!--        AND A.pay_state = 3 AND A.order_refund_state != 2-->
<!--        <if test="param.placeId != null and param.placeId != 0L">-->
<!--            AND o.delivery_related_id = #{param.placeId}-->
<!--        </if>-->
<!--        <if test="param.intervalId != null and param.intervalId != 0L">-->
<!--            AND A.mealtime_type = #{param.intervalId}-->
<!--        </if>-->
<!--        <if test="param.custName != null and param.custName != 0L">-->
<!--            AND C.cust_name = #{param.custName}-->
<!--        </if>-->
<!--        <if test="param.mobile != null and param.mobile != 0L">-->
<!--            AND C.mobile = #{param.mobile}-->
<!--        </if>-->
<!--    </select>-->

</mapper>
