<?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.report.statistics.order.basic.mapper.ReportOrderInfoMapper">
    <!--namespace根据路径填写-->
<!--    <resultMap id="ReportBasicOrderVOMap" type="net.xnzn.core.report.statistics.order.basic.vo.ReportBasicOrderVO">-->
<!--        <result property="orderId" column="order_id"/>-->
<!--        <result property="canteenStallName" column="canteen_stall_name"/>-->
<!--        <result property="mealtimeType" column="mealtime_type"/>-->
<!--        <result property="consumeSource" column="consume_source"/>-->
<!--        <result property="sourceType" column="source_type"/>-->
<!--        <result property="custNum" column="cust_num"/>-->
<!--        <result property="custName" column="cust_name"/>-->
<!--        <result property="orgName" column="org_name"/>-->
<!--        <result property="orgFullName" column="org_full_name"/>-->
<!--        <result property="psnTypeName" column="psn_type_name"/>-->
<!--        <result property="payTime" column="pay_time"/>-->
<!--        <result property="orderTime" column="order_time"/>-->
<!--        <result property="orderDate" column="order_date"/>-->
<!--        <result property="payableAmount" column="payable_amount"/>-->
<!--        <result property="realAmount" column="real_amount"/>-->
<!--        <result property="discountsAmount" column="discounts_amount"/>-->
<!--        <result property="deliveryAmount" column="delivery_amount"/>-->
<!--        <result property="packingAmount" column="packing_amount"/>-->
<!--        <result property="refundAmount" column="refund_amount"/>-->
<!--        <result property="tradeType" column="trade_type"/>-->
<!--        <result property="remark" column="remark"/>-->
<!--        <result property="payTypeStr" column="pay_type_str"/>-->
<!--        <result property="discountStr" column="discount_str"/>-->
<!--    </resultMap>-->

<!--    <resultMap id="ReportBasicOrderExportVOMap" type="net.xnzn.core.report.statistics.order.basic.vo.ReportBasicOrderVO">-->
<!--        <result property="orderId" column="order_id"/>-->
<!--        <result property="canteenStallName" column="canteen_stall_name"/>-->
<!--        <result property="mealtimeType" column="mealtime_type"/>-->
<!--        <result property="consumeSource" column="consume_source"/>-->
<!--        <result property="sourceType" column="source_type"/>-->
<!--        <result property="custNum" column="cust_num"/>-->
<!--        <result property="custName" column="cust_name"/>-->
<!--        <result property="orgName" column="org_name"/>-->
<!--        <result property="orgFullName" column="org_full_name"/>-->
<!--        <result property="psnTypeName" column="psn_type_name"/>-->
<!--        <result property="payTime" column="pay_time"/>-->
<!--        <result property="orderTime" column="order_time"/>-->
<!--        <result property="orderDate" column="order_date"/>-->
<!--        <result property="payableAmount" column="payable_amount"/>-->
<!--        <result property="realAmount" column="real_amount"/>-->
<!--        <result property="discountsAmount" column="discounts_amount"/>-->
<!--        <result property="deliveryAmount" column="delivery_amount"/>-->
<!--        <result property="packingAmount" column="packing_amount"/>-->
<!--        <result property="refundAmount" column="refund_amount"/>-->
<!--        <result property="tradeType" column="trade_type"/>-->
<!--        <result property="remark" column="remark"/>-->
<!--        <result property="payTypeStr" column="pay_type_str"/>-->
<!--    </resultMap>-->

<!--    <sql id="queryParam">-->
<!--        <if test="param.ifAcrossTime != null and param.ifAcrossTime == 1">-->
<!--            AND a.order_time NOT BETWEEN #{param.startTime} and #{param.endTime}-->
<!--        </if>-->
<!--        <if test="param.ageTypes != null and param.ageTypes.size() > 0">-->
<!--            AND a.age_type IN-->
<!--            <foreach collection="param.ageTypes" item="ageType" separator="," open="(" close=")">-->
<!--                #{ageType}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.canteenId != null">-->
<!--            AND a.canteen_id = #{param.canteenId}-->
<!--        </if>-->
<!--        <if test="param.stallId != null">-->
<!--            AND a.stall_id = #{param.stallId}-->
<!--        </if>-->
<!--        <if test="param.canteenStallIds != null and param.canteenStallIds.size() > 0">-->
<!--            AND (a.canteen_id IN-->
<!--            <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                #{canteenStallId}-->
<!--            </foreach>-->
<!--            OR a.stall_id IN-->
<!--            <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                #{canteenStallId}-->
<!--            </foreach>-->
<!--            )-->
<!--        </if>-->
<!--        <if test="param.orgId != null">-->
<!--            AND a.org_id = #{param.orgId}-->
<!--        </if>-->
<!--        <if test="param.orgIds != null and param.orgIds.size() > 0">-->
<!--            and a.org_id in-->
<!--            <foreach collection="param.orgIds" item="orgId" separator="," open="("-->
<!--                     close=")">-->
<!--                #{orgId}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.mealtimeTypes != null and param.mealtimeTypes.size() > 0">-->
<!--            AND a.mealtime_type IN-->
<!--            <foreach collection="param.mealtimeTypes" item="mealtimeType" separator="," open="(" close=")">-->
<!--                #{mealtimeType}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.payChannels != null and param.payChannels.size() > 0">-->
<!--            AND p.pay_channel in-->
<!--            <foreach collection="param.payChannels" item="payChannel" separator="," open="(" close=")">-->
<!--                #{payChannel}-->
<!--            </foreach>-->
<!--        </if>-->

<!--        <if test="param.payTypes != null and param.payTypes.size() > 0">-->
<!--            AND p.pay_type in-->
<!--            <foreach collection="param.payTypes" item="payType" separator="," open="(" close=")">-->
<!--                #{payType}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.psnTypes != null and param.psnTypes.size() > 0">-->
<!--            AND EXISTS (-->
<!--            SELECT 1 FROM report_order_info_snapshot ros where ros.order_id = a.order_id-->
<!--            AND ros.psn_type IN-->
<!--            <foreach collection="param.psnTypes" item="psnType" separator="," open="(" close=")">-->
<!--                #{psnType}-->
<!--            </foreach>-->
<!--            )-->
<!--        </if>-->
<!--        <if test="param.holidayTypeList != null and param.holidayTypeList.size() > 0">-->
<!--            <if test="param.timeType != null and param.timeType == 1">-->
<!--                AND EXISTS (-->
<!--                SELECT 1 FROM mkt_holiday mh WHERE mh.hol_date = DATE_FORMAT(a.order_time,'%Y-%m-%d')-->
<!--                AND mh.hol_type in-->
<!--                <foreach collection="param.holidayTypeList" item="holidayType" separator="," open="(" close=")">-->
<!--                    #{holidayType}-->
<!--                </foreach>-->
<!--                )-->
<!--            </if>-->
<!--            <if test="param.timeType != null and param.timeType == 2">-->
<!--                AND EXISTS (-->
<!--                SELECT 1 FROM mkt_holiday mh WHERE mh.hol_date = DATE_FORMAT(a.pay_time,'%Y-%m-%d')-->
<!--                AND mh.hol_type in-->
<!--                <foreach collection="param.holidayTypeList" item="holidayType" separator="," open="(" close=")">-->
<!--                    #{holidayType}-->
<!--                </foreach>-->
<!--                )-->
<!--            </if>-->
<!--        </if>-->
<!--        <if test="param.sourceType != null">-->
<!--            and a.source_type = #{param.sourceType}-->
<!--        </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 a.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 (a.canteen_id = it1.data_id)-->
<!--            )-->
<!--            OR 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 (a.stall_id = it1.data_id)-->
<!--            )-->
<!--            )-->
<!--        </if>-->
<!--    </sql>-->

<!--    <sql id="areaParameter">-->
<!--        <if test="param.areaIdList != null and param.areaIdList.size() > 0">-->
<!--            AND ar.area_id in-->
<!--            <foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--            and EXISTS (-->
<!--            SELECT null-->
<!--            FROM mgr_role_area 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 ar.area_id = it1.data_id-->
<!--            )-->
<!--        </if>-->
<!--    </sql>-->

<!--    <select id="queryMinMaxPayTime" resultType="map">-->
<!--        SELECT min(pay_time) AS minPayTime,-->
<!--               max(pay_time) AS maxPayTime-->
<!--        FROM-->
<!--        <if test="param.timeType != null and param.timeType == 1">-->
<!--            report_order_info_order_time a-->
<!--        </if>-->
<!--        <if test="param.timeType != null and param.timeType == 3">-->
<!--            report_order_info_order_date a-->
<!--        </if>-->
<!--        WHERE 1=1-->
<!--            <if test="param.timeType != null and param.timeType == 1">-->
<!--               <![CDATA[ and a.order_time >= #{param.startTime}]]>-->

<!--               <![CDATA[AND a.order_time <= #{param.endTime}]]>-->
<!--            </if>-->
<!--            <if test="param.timeType != null and param.timeType == 3">-->
<!--               <![CDATA[and a.order_date >= #{param.startTime}]]>-->

<!--               <![CDATA[AND a.order_date <= #{param.endTime}]]>-->
<!--            </if>-->
<!--    </select>-->


<!--    <select id="listSummaryId" resultType="java.lang.Long">-->
<!--        SELECT t.order_id-->
<!--        FROM (-->
<!--        select a.order_id,a.pay_time-->
<!--        from-->
<!--        report_order_info a-->
<!--        <if test="(param.payChannels != null and param.payChannels.size() > 0) || (param.payTypes != null and param.payTypes.size() > 0)">-->
<!--            inner join report_order_pay p on p.order_id = a.order_id-->
<!--        </if>-->

<!--        where 1=1-->
<!--        <choose>-->
<!--            <when test="param.timeType != null and param.timeType == 1">-->
<!--                <if test="param.startTime != null">-->
<!--                    <![CDATA[AND a.order_time >= #{param.startTime}]]>-->
<!--                </if>-->
<!--                <if test="param.endTime != null">-->
<!--                    <![CDATA[AND a.order_time <= #{param.endTime}]]>-->
<!--                </if>-->
<!--            </when>-->
<!--            <when test="param.timeType != null and param.timeType == 2">-->
<!--                <if test="param.startTime != null">-->
<!--                    <![CDATA[AND a.pay_time >= #{param.startTime}]]>-->
<!--                </if>-->
<!--                <if test="param.endTime != null">-->
<!--                    <![CDATA[AND a.pay_time <= #{param.endTime}]]>-->
<!--                </if>-->
<!--            </when>-->
<!--            <otherwise>-->
<!--                <if test="param.startDate !=null and param.endDate!=null ">-->
<!--                    AND a.order_date BETWEEN #{param.startDate} AND #{param.endDate}-->
<!--                </if>-->
<!--            </otherwise>-->
<!--        </choose>-->
<!--        <if test="param.orderId != null">-->
<!--            AND a.order_id = #{param.orderId}-->
<!--        </if>-->
<!--        <if test="param.minAmount != null">-->
<!--            <![CDATA[AND a.real_amount >= #{param.minAmount}]]>-->
<!--        </if>-->
<!--        <if test="param.maxAmount != null">-->
<!--            <![CDATA[AND a.real_amount <= #{param.maxAmount}]]>-->
<!--        </if>-->
<!--        <if test="param.machineName != null and param.machineName != ''">-->
<!--            AND EXISTS(-->
<!--            SELECT 1 FROM device_info m-->
<!--            WHERE m.device_sn = a.machine_sn-->
<!--            AND m.device_name LIKE concat('%', #{param.machineName},'%')-->
<!--            )-->
<!--        </if>-->
<!--        <if test="param.areaIdList != null and param.areaIdList.size() > 0">-->
<!--            AND EXISTS(-->
<!--            SELECT 1 FROM alloc_canteen ac-->
<!--            WHERE a.canteen_id = ac.canteen_id-->
<!--            AND ac.area_id in-->
<!--            <foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--            )-->
<!--        </if>-->
<!--        <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--            AND EXISTS(-->
<!--            SELECT 1 FROM alloc_canteen ac-->
<!--            WHERE a.canteen_id = ac.canteen_id-->
<!--            and EXISTS (-->
<!--            SELECT null-->
<!--            FROM mgr_role_area 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 ac.area_id = it1.data_id-->
<!--            )-->
<!--            )-->
<!--        </if>-->
<!--        <if test="param.keyword != null and param.keyword != ''">-->
<!--            AND EXISTS(-->
<!--            SELECT 1 FROM cust_info ci-->
<!--            WHERE a.cust_id = ci.cust_id-->
<!--            AND (-->
<!--            ci.cust_name = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--            OR ci.cust_name_like LIKE CONCAT('%',#{param.keyword,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')-->
<!--            OR ci.cust_num = #{param.keyword}-->
<!--            OR ci.mobile = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--            OR ci.mobile_suffix = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--            )-->
<!--            )-->
<!--        </if>-->
<!--        <if test="param.tradeTypeList != null and param.tradeTypeList.size() > 0">-->
<!--            AND IF( a.order_type = 21, 3, 1 ) IN-->
<!--            <foreach collection="param.tradeTypeList" item="tradeType" separator="," open="(" close=")">-->
<!--                #{tradeType}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <include refid="queryParam"></include>-->

<!--        <if test="param.tradeTypeList.size() == 0 or param.tradeTypeList.contains(2)">-->
<!--        UNION ALL-->

<!--        select a.order_id,a.pay_time-->
<!--        FROM report_refund r-->
<!--            inner join report_order_info a on a.order_id = r.order_id-->
<!--        <if test="(param.payChannels != null and param.payChannels.size() > 0) || (param.payTypes != null and param.payTypes.size() > 0)">-->
<!--            inner join report_order_pay p on p.order_id = a.order_id-->
<!--        </if>-->
<!--        where 1=1-->
<!--        <choose>-->
<!--            <when test="param.timeType != null and param.timeType == 1">-->
<!--                <if test="param.startTime != null">-->
<!--                    <![CDATA[AND a.order_time >= #{param.startTime}]]>-->
<!--                </if>-->
<!--                <if test="param.endTime != null">-->
<!--                    <![CDATA[AND a.order_time <= #{param.endTime}]]>-->
<!--                </if>-->
<!--            </when>-->
<!--            <when test="param.timeType != null and param.timeType == 2">-->
<!--                <if test="param.startTime != null">-->
<!--                    <![CDATA[AND r.check_time >= #{param.startTime}]]>-->
<!--                </if>-->
<!--                <if test="param.endTime != null">-->
<!--                    <![CDATA[AND r.check_time <= #{param.endTime}]]>-->
<!--                </if>-->
<!--            </when>-->
<!--            <otherwise>-->
<!--                <if test="param.startDate !=null and param.endDate!=null ">-->
<!--                    AND a.order_date BETWEEN #{param.startDate} AND #{param.endDate}-->
<!--                </if>-->
<!--            </otherwise>-->
<!--        </choose>-->
<!--        <if test="param.orderId != null">-->
<!--            AND a.order_id = #{param.orderId}-->
<!--        </if>-->
<!--        <if test="param.minAmount != null">-->
<!--            <![CDATA[AND a.real_amount >= #{param.minAmount}]]>-->
<!--        </if>-->
<!--        <if test="param.maxAmount != null">-->
<!--            <![CDATA[AND a.real_amount <= #{param.maxAmount}]]>-->
<!--        </if>-->

<!--        <if test="param.machineName != null and param.machineName != ''">-->
<!--            AND EXISTS(-->
<!--            SELECT 1 FROM device_info m-->
<!--            WHERE m.device_sn = a.machine_sn-->
<!--            AND m.device_name LIKE concat('%', #{param.machineName},'%')-->
<!--            )-->
<!--        </if>-->
<!--        <if test="param.areaIdList != null and param.areaIdList.size() > 0">-->
<!--            AND EXISTS(-->
<!--            SELECT 1 FROM alloc_canteen ac-->
<!--            WHERE a.canteen_id = ac.canteen_id-->
<!--            AND ac.area_id in-->
<!--            <foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--            )-->
<!--        </if>-->
<!--        <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--            AND EXISTS(-->
<!--            SELECT 1 FROM alloc_canteen ac-->
<!--            WHERE a.canteen_id = ac.canteen_id-->
<!--            and EXISTS (-->
<!--            SELECT null-->
<!--            FROM mgr_role_area 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 ac.area_id = it1.data_id-->
<!--            )-->
<!--            )-->
<!--        </if>-->
<!--        <if test="param.keyword != null and param.keyword != ''">-->
<!--            AND EXISTS(-->
<!--            SELECT 1 FROM cust_info ci-->
<!--            WHERE a.cust_id = ci.cust_id-->
<!--            AND (-->
<!--            ci.cust_name = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--            OR ci.cust_name_like LIKE CONCAT('%',#{param.keyword,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')-->
<!--            OR ci.cust_num = #{param.keyword}-->
<!--            OR ci.mobile = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--            OR ci.mobile_suffix = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--            )-->
<!--            )-->
<!--        </if>-->

<!--        <include refid="queryParam"></include>-->
<!--        </if>-->
<!--        ) t ORDER BY t.pay_time DESC-->
<!--    </select>-->

<!--    <select id="listSummary" resultMap="ReportBasicOrderVOMap">-->
<!--        select t.order_id,-->
<!--                CONCAT_WS( '/', IFNULL( c.canteen_name, si.supermarket_name), s.stall_name ) AS canteen_stall_name,-->
<!--               ar.area_name,-->
<!--                CONCAT_WS('-',m.device_name,t.machine_sn) consume_source,-->
<!--               t.source_type,-->
<!--               t.mealtime_type,-->
<!--               ci.cust_num,-->
<!--               ci.cust_name,-->
<!--               co.org_name,-->
<!--               co.org_full_name,-->
<!--               cp.psn_type_name,-->
<!--               t.pay_time,-->
<!--               t.order_time,-->
<!--               t.order_date,-->
<!--               t.payable_amount,-->
<!--               t.real_amount,-->
<!--               t.discounts_amount AS discounts_amount,-->
<!--               t.delivery_amount,-->
<!--               t.packing_amount,-->
<!--               t.refund_amount,-->
<!--               t.trade_type,-->
<!--               t.pay_channel,-->
<!--               t.pay_type,-->
<!--               t.out_trade_no,-->
<!--               t.remark,-->
<!--               p.pay_type_str,-->
<!--               ch.discount_str-->
<!--        from (-->
<!--                 select DISTINCT a.order_id,-->
<!--                        a.canteen_id,-->
<!--                        a.stall_id,-->
<!--                        a.machine_sn,-->
<!--                        a.source_type,-->
<!--                        a.mealtime_type,-->
<!--                        a.cust_id,-->
<!--                        a.pay_time,-->
<!--                        a.order_time,-->
<!--                        a.order_date,-->
<!--                        a.payable_amount,-->
<!--                        a.real_amount,-->
<!--                        a.discounts_amount,-->
<!--                        a.delivery_amount,-->
<!--                        a.packing_amount,-->
<!--                        0 AS refund_amount,-->
<!--                        IF(a.order_type = 21, 3, 1) as trade_type,-->
<!--                        a.pay_channel,-->
<!--                        a.pay_type,-->
<!--                        a.out_trade_no,-->
<!--                        a.remark-->
<!--                 from-->
<!--                    report_order_info a-->
<!--                WHERE a.order_id IN-->
<!--                <foreach collection="orderIdList" item="orderId" open="(" close=")" separator=",">-->
<!--                    #{orderId}-->
<!--                </foreach>-->
<!--                <choose>-->
<!--                    <when test="param.timeType != null and param.timeType == 1">-->
<!--                        <if test="param.startTime != null">-->
<!--                            <![CDATA[AND a.order_time >= #{param.startTime}]]>-->
<!--                        </if>-->
<!--                        <if test="param.endTime != null">-->
<!--                            <![CDATA[AND a.order_time <= #{param.endTime}]]>-->
<!--                        </if>-->
<!--                    </when>-->
<!--                    <when test="param.timeType != null and param.timeType == 2">-->
<!--                        <if test="param.startTime != null">-->
<!--                            <![CDATA[AND a.pay_time >= #{param.startTime}]]>-->
<!--                        </if>-->
<!--                        <if test="param.endTime != null">-->
<!--                            <![CDATA[AND a.pay_time <= #{param.endTime}]]>-->
<!--                        </if>-->
<!--                    </when>-->
<!--                    <otherwise>-->
<!--                        <if test="param.startDate !=null and param.endDate!=null ">-->
<!--                            AND a.order_date BETWEEN #{param.startDate} AND #{param.endDate}-->
<!--                        </if>-->
<!--                    </otherwise>-->
<!--                </choose>-->

<!--                 union all-->

<!--                 select a.order_id,-->
<!--                        a.canteen_id,-->
<!--                        a.stall_id,-->
<!--                        '消费退款' as machine_sn,-->
<!--                        -1                        as source_type,-->
<!--                        a.mealtime_type,-->
<!--                        a.cust_id,-->
<!--                        r.check_time              as pay_time,-->
<!--                        a.order_time,-->
<!--                        a.order_date,-->
<!--                        0                         as payable_amount,-->
<!--                        0                         as real_amount,-->
<!--                        0                         as discounts_amount,-->
<!--                        0                         as delivery_amount,-->
<!--                        0                         as packing_amount,-->
<!--                        r.real_refund_amount * - 1 AS refund_amount,-->
<!--                        2                         as trade_type,-->
<!--                        a.pay_channel,-->
<!--                        a.pay_type,-->
<!--                        a.out_trade_no,-->
<!--                        a.remark-->
<!--                 from report_refund r-->
<!--                        inner join report_order_info a on a.order_id = r.order_id-->
<!--                WHERE a.order_id IN-->
<!--                <foreach collection="orderIdList" item="orderId" open="(" close=")" separator=",">-->
<!--                    #{orderId}-->
<!--                </foreach>-->
<!--                <choose>-->
<!--                     <when test="param.timeType != null and param.timeType == 1">-->
<!--                        <if test="param.startTime != null">-->
<!--                            <![CDATA[AND a.order_time >= #{param.startTime}]]>-->
<!--                        </if>-->
<!--                        <if test="param.endTime != null">-->
<!--                            <![CDATA[AND a.order_time <= #{param.endTime}]]>-->
<!--                        </if>-->
<!--                    </when>-->
<!--                    <when test="param.timeType != null and param.timeType == 2">-->
<!--                        <if test="param.startTime != null">-->
<!--                            <![CDATA[AND r.check_time >= #{param.startTime}]]>-->
<!--                        </if>-->
<!--                        <if test="param.endTime != null">-->
<!--                            <![CDATA[AND r.check_time <= #{param.endTime}]]>-->
<!--                        </if>-->
<!--                    </when>-->
<!--                    <otherwise>-->
<!--                        <if test="param.startDate !=null and param.endDate!=null ">-->
<!--                            AND a.order_date BETWEEN #{param.startDate} AND #{param.endDate}-->
<!--                        </if>-->
<!--                    </otherwise>-->
<!--                </choose>-->
<!--             ) t-->
<!--                 left join alloc_stall s on s.stall_id = t.stall_id-->
<!--                 LEFT JOIN alloc_canteen c ON c.canteen_id = t.canteen_id-->
<!--                 LEFT JOIN supermarket_info si ON si.supermarket_id = t.canteen_id-->

<!--                 left join device_info m on m.device_sn = t.machine_sn-->
<!--                 left join cust_info ci on ci.cust_id = t.cust_id-->

<!--                 left join report_order_info_snapshot ros on ros.order_id = t.order_id and ros.order_id in-->
<!--                    <foreach collection="orderIdList" item="orderId" open="(" close=")" separator=",">-->
<!--                        #{orderId}-->
<!--                    </foreach>-->
<!--                 left join cust_org co on co.org_id = ros.org_id-->
<!--                 left join cust_psn_type cp on cp.psn_type = ros.psn_type-->
<!--                 LEFT JOIN alloc_area ar ON c.area_id = ar.area_id-->
<!--                LEFT JOIN (-->
<!--                SELECT-->
<!--                t.order_id,-->
<!--                GROUP_CONCAT( t.pay_str SEPARATOR ';' ) AS pay_type_str-->
<!--                FROM-->
<!--                ( SELECT p.order_id, CONCAT( p.pay_type, '-', p.pay_channel,'-',p.pay_amount,'-',p.refund_amount ) pay_str FROM report_order_pay p-->
<!--                WHERE p.order_id IN-->
<!--                    <foreach collection="orderIdList" item="orderId" open="(" close=")" separator=",">-->
<!--                        #{orderId}-->
<!--                    </foreach>-->
<!--                ) t-->
<!--                GROUP BY-->
<!--                t.order_id-->
<!--                ) p ON p.order_id = t.order_id-->
<!--                LEFT JOIN (-->
<!--                SELECT-->
<!--                t.order_id, GROUP_CONCAT( t.change_str SEPARATOR ';' ) AS discount_str-->
<!--                FROM-->
<!--                ( SELECT order_id, CONCAT( change_type, ',', change_detail_type,',',change_amount*-1 ) change_str-->
<!--                FROM report_order_discount a-->
<!--                WHERE a.order_id IN-->
<!--                    <foreach collection="orderIdList" item="orderId" open="(" close=")" separator=",">-->
<!--                        #{orderId}-->
<!--                    </foreach>-->
<!--                ) t-->
<!--                GROUP BY-->
<!--                t.order_id-->
<!--                ) ch on ch.order_id = t.order_id-->
<!--                order by t.pay_time desc-->

<!--    </select>-->

<!--    <select id="getSummaryTotal" resultMap="ReportBasicOrderVOMap">-->
<!--        select-->
<!--            sum(t.payable_amount) AS payable_amount,-->
<!--            sum(t.real_amount) AS real_amount,-->
<!--            sum(t.discounts_amount) AS discounts_amount,-->
<!--            sum(t.delivery_amount) AS delivery_amount,-->
<!--            sum(t.packing_amount) AS packing_amount,-->
<!--            sum( t.refund_amount ) AS refund_amount-->
<!--        from (-->
<!--            select-->
<!--                a.cust_id,-->
<!--                a.canteen_id,-->
<!--                a.payable_amount,-->
<!--                a.real_amount,-->
<!--                a.discounts_amount AS discounts_amount,-->
<!--                a.delivery_amount,-->
<!--                a.packing_amount,-->
<!--                0 AS refund_amount,-->
<!--                IF(a.order_type = 21, 3, 1) as trade_type-->
<!--            from-->
<!--                report_order_info a-->
<!--                <if test="(param.payChannels != null and param.payChannels.size() > 0) || (param.payTypes != null and param.payTypes.size() > 0)">-->
<!--                    inner join report_order_pay p on p.order_id = a.order_id-->
<!--                </if>-->
<!--            left join device_info m on m.device_sn = a.machine_sn-->
<!--            <choose>-->
<!--                <when test="param.timeType != null and param.timeType == 1">-->
<!--                    LEFT JOIN mkt_holiday mh on mh.hol_date = DATE_FORMAT(a.order_time,'%Y-%m-%d')-->
<!--                </when>-->
<!--                <otherwise>-->
<!--                    LEFT JOIN mkt_holiday mh on mh.hol_date = DATE_FORMAT(a.pay_time,'%Y-%m-%d')-->
<!--                </otherwise>-->
<!--            </choose>-->
<!--                <where>-->
<!--                    <choose>-->
<!--                        <when test="param.timeType != null and param.timeType == 1">-->
<!--                            <if test="param.startTime != null">-->
<!--                                <![CDATA[AND a.order_time >= #{param.startTime}]]>-->
<!--                            </if>-->
<!--                            <if test="param.endTime != null">-->
<!--                                <![CDATA[AND a.order_time <= #{param.endTime}]]>-->
<!--                            </if>-->
<!--                        </when>-->
<!--                        <when test="param.timeType != null and param.timeType == 2">-->
<!--                            <if test="param.startTime != null">-->
<!--                                <![CDATA[AND a.pay_time >= #{param.startTime}]]>-->
<!--                            </if>-->
<!--                            <if test="param.endTime != null">-->
<!--                                <![CDATA[AND a.pay_time <= #{param.endTime}]]>-->
<!--                            </if>-->
<!--                        </when>-->
<!--                        <otherwise>-->
<!--                            <if test="param.startDate !=null and param.endDate!=null ">-->
<!--                                AND a.order_date BETWEEN #{param.startDate} AND #{param.endDate}-->
<!--                            </if>-->
<!--                        </otherwise>-->
<!--                    </choose>-->
<!--                    <if test="param.machineName != null and param.machineName != ''">-->
<!--                        AND m.device_name LIKE concat('%', #{param.machineName},'%')-->
<!--                    </if>-->
<!--                    <if test="param.orderId != null">-->
<!--                        AND a.order_id = #{param.orderId}-->
<!--                    </if>-->
<!--                    <include refid="queryParam"></include>-->
<!--                </where>-->
<!--            union all-->

<!--            select-->
<!--                a.cust_id,-->
<!--                a.canteen_id,-->
<!--                0                         as payable_amount,-->
<!--                0                         as real_amount,-->
<!--                0                         as discounts_amount,-->
<!--                0                         as delivery_amount,-->
<!--                0                         as packing_amount,-->
<!--                r.real_refund_amount * - 1 AS refund_amount,-->
<!--                2                         as trade_type-->
<!--            from report_refund r-->
<!--                inner join report_order_info a on a.order_id = r.order_id-->
<!--            <if test="(param.payChannels != null and param.payChannels.size() > 0) || (param.payTypes != null and param.payTypes.size() > 0)">-->
<!--                inner join report_order_pay p on p.order_id = a.order_id-->
<!--            </if>-->
<!--            left join device_info m on m.device_sn = a.machine_sn-->
<!--            <choose>-->
<!--                <when test="param.timeType != null and param.timeType == 1">-->
<!--                    LEFT JOIN mkt_holiday mh on mh.hol_date = DATE_FORMAT(a.order_time,'%Y-%m-%d')-->
<!--                </when>-->
<!--                <otherwise>-->
<!--                    LEFT JOIN mkt_holiday mh on mh.hol_date = DATE_FORMAT(r.check_time,'%Y-%m-%d')-->
<!--                </otherwise>-->
<!--            </choose>-->
<!--                <where>-->
<!--                    <choose>-->
<!--                        <when test="param.timeType != null and param.timeType == 1">-->
<!--                            <if test="param.startTime != null">-->
<!--                                <![CDATA[AND a.order_time >= #{param.startTime}]]>-->
<!--                            </if>-->
<!--                            <if test="param.endTime != null">-->
<!--                                <![CDATA[AND a.order_time <= #{param.endTime}]]>-->
<!--                            </if>-->
<!--                        </when>-->
<!--                        <when test="param.timeType != null and param.timeType == 2">-->
<!--                            <if test="param.startTime != null">-->
<!--                                <![CDATA[AND r.check_time >= #{param.startTime}]]>-->
<!--                            </if>-->
<!--                            <if test="param.endTime != null">-->
<!--                                <![CDATA[AND r.check_time <= #{param.endTime}]]>-->
<!--                            </if>-->
<!--                        </when>-->
<!--                        <otherwise>-->
<!--                            <if test="param.startDate !=null and param.endDate!=null ">-->
<!--                                AND a.order_date BETWEEN #{param.startDate} AND #{param.endDate}-->
<!--                            </if>-->
<!--                        </otherwise>-->
<!--                    </choose>-->
<!--                    <if test="param.machineName != null and param.machineName != ''">-->
<!--                        AND m.device_name LIKE concat('%', #{param.machineName},'%')-->
<!--                    </if>-->
<!--                    <if test="param.orderId != null">-->
<!--                        AND a.order_id = #{param.orderId}-->
<!--                    </if>-->
<!--                    <include refid="queryParam"></include>-->
<!--                </where>-->
<!--            ) t-->
<!--            left join cust_info ci on ci.cust_id = t.cust_id-->
<!--            LEFT JOIN alloc_canteen c ON c.canteen_id = t.canteen_id-->
<!--            LEFT JOIN alloc_area ar ON c.area_id = ar.area_id-->
<!--                <where>-->
<!--                    <if test="param.keyword != null and param.keyword != ''">-->
<!--                        AND (-->
<!--                        ci.cust_name = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                        OR ci.cust_name_like LIKE CONCAT('%',#{param.keyword,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')-->
<!--                        OR ci.cust_num = #{param.keyword}-->
<!--                        OR ci.mobile = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                        OR ci.mobile_suffix = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                        )-->
<!--                    </if>-->
<!--                    <if test="param.tradeTypeList != null and param.tradeTypeList.size() > 0">-->
<!--                        AND t.trade_type IN-->
<!--                        <foreach collection="param.tradeTypeList" item="tradeType" separator="," open="(" close=")">-->
<!--                            #{tradeType}-->
<!--                        </foreach>-->
<!--                    </if>-->
<!--                    <if test="param.minAmount != null">-->
<!--                        <![CDATA[AND t.real_amount >= #{param.minAmount}]]>-->
<!--                    </if>-->
<!--                    <if test="param.maxAmount != null">-->
<!--                        <![CDATA[AND t.real_amount <= #{param.maxAmount}]]>-->
<!--                    </if>-->
<!--                    <include refid="areaParameter"></include>-->
<!--                </where>-->
<!--    </select>-->


<!--    <select id="getOrdPayList" resultType="net.xnzn.core.report.statistics.order.basic.model.ReportOrderPay">-->
<!--        SELECT order_id, pay_type, pay_channel, out_trade_no, pay_amount, refund_amount-->
<!--        FROM report_order_pay WHERE order_id = #{order_id}-->
<!--    </select>-->

<!--    <select id="getOrdDiscountList" resultType="net.xnzn.core.report.statistics.order.basic.model.ReportOrderDiscount">-->
<!--        SELECT order_id, abs(change_amount) change_amount, change_type, change_detail_type-->
<!--        FROM report_order_discount WHERE order_id = #{order_id}-->
<!--    </select>-->

    <delete id="deleteByPayTime">
        DELETE FROM
            report_order_info
        WHERE
            pay_time BETWEEN #{startTime} AND #{endTime}
    </delete>

<!--    <select id="listCustSummary_COUNT" resultType="long">-->
<!--        select count(*)-->
<!--        from-->
<!--            (-->
<!--        SELECT-->
<!--                <if test="param.sumType == 2">-->
<!--                    t.statistic_date,-->
<!--                </if>-->
<!--                t.cust_id,-->
<!--                co.org_full_name-->
<!--        FROM (-->
<!--            SELECT-->
<!--                    <if test="param.sumType == 2">-->
<!--                        t.statistic_date,-->
<!--                    </if>-->
<!--                    t.cust_id,-->
<!--                    t.org_id-->
<!--            FROM-->

<!--            (-->
<!--            SELECT-->
<!--                <if test="param.sumType == 2">-->
<!--                    DATE_FORMAT(o.pay_time,'%Y-%m-%d') statistic_date,-->
<!--                </if>-->
<!--                o.cust_id,-->
<!--                o.org_id-->
<!--            FROM-->
<!--                report_order_info o-->
<!--                LEFT JOIN mkt_holiday mh ON mh.hol_date = DATE_FORMAT( o.pay_time, '%Y-%m-%d' )-->
<!--                LEFT JOIN alloc_canteen c ON c.canteen_id = o.canteen_id-->
<!--                LEFT JOIN alloc_area ar ON c.area_id = ar.area_id-->
<!--            <where>-->
<!--                 <if test="param.startDate != null">-->
<!--                         <![CDATA[AND o.pay_time >= concat(#{param.startDate},' 00:00:00')]]>-->
<!--                 </if>-->
<!--                 <if test="param.endDate != null">-->
<!--                         <![CDATA[AND o.pay_time <= concat(#{param.endDate},' 23:59:59')]]>-->
<!--                 </if>-->
<!--                 <if test="param.ageTypes != null and param.ageTypes.size() > 0">-->
<!--                         AND o.age_type IN-->
<!--                         <foreach collection="param.ageTypes" item="ageType" separator="," open="(" close=")">-->
<!--                                 #{ageType}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                 <if test="param.orgIds != null and param.orgIds.size() > 0">-->
<!--                         and o.org_id in-->
<!--                         <foreach collection="param.orgIds" item="orgId" separator="," open="("-->
<!--                                            close=")">-->
<!--                                 #{orgId}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                 <if test="param.holidayTypeList != null and param.holidayTypeList.size() > 0">-->
<!--                         AND mh.hol_type in-->
<!--                         <foreach collection="param.holidayTypeList" item="holidayType" separator="," open="(" close=")">-->
<!--                                 #{holidayType}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                <if test="param.canteenStallIds != null and param.canteenStallIds.size() > 0">-->
<!--                    AND (o.canteen_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    OR o.stall_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    )-->
<!--                </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 o.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 (o.canteen_id = it1.data_id)-->
<!--                         )-->
<!--                         OR 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 (o.stall_id = it1.data_id)-->
<!--                         )-->
<!--                         )-->
<!--                 </if>-->
<!--                <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--                    and EXISTS (-->
<!--                    SELECT null-->
<!--                    FROM mgr_role_area 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 ar.area_id = it1.data_id-->
<!--                    )-->
<!--                </if>-->
<!--            </where>-->

<!--            UNION ALL-->

<!--            SELECT-->
<!--                <if test="param.sumType == 2">-->
<!--                    DATE_FORMAT(r.check_time,'%Y-%m-%d') statistic_date,-->
<!--                </if>-->
<!--                o.cust_id,-->
<!--                o.org_id-->
<!--            from report_refund r-->
<!--              left join report_order_info o on o.order_id = r.order_id-->
<!--                LEFT JOIN mkt_holiday mh ON mh.hol_date = DATE_FORMAT( r.check_time, '%Y-%m-%d' )-->
<!--                LEFT JOIN alloc_canteen c ON c.canteen_id = o.canteen_id-->
<!--                LEFT JOIN alloc_area ar ON c.area_id = ar.area_id-->
<!--            <where>-->
<!--                 <if test="param.startDate != null">-->
<!--                         <![CDATA[AND r.check_time >= concat(#{param.startDate},' 00:00:00')]]>-->
<!--                 </if>-->
<!--                 <if test="param.endDate != null">-->
<!--                         <![CDATA[AND r.check_time <= concat(#{param.endDate},' 23:59:59')]]>-->
<!--                 </if>-->
<!--                 <if test="param.ageTypes != null and param.ageTypes.size() > 0">-->
<!--                         AND o.age_type IN-->
<!--                         <foreach collection="param.ageTypes" item="ageType" separator="," open="(" close=")">-->
<!--                                 #{ageType}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                 <if test="param.orgIds != null and param.orgIds.size() > 0">-->
<!--                         and o.org_id in-->
<!--                         <foreach collection="param.orgIds" item="orgId" separator="," open="(" close=")">-->
<!--                                 #{orgId}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                 <if test="param.holidayTypeList != null and param.holidayTypeList.size() > 0">-->
<!--                         AND mh.hol_type in-->
<!--                         <foreach collection="param.holidayTypeList" item="holidayType" separator="," open="(" close=")">-->
<!--                                 #{holidayType}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                <if test="param.canteenStallIds != null and param.canteenStallIds.size() > 0">-->
<!--                    AND (o.canteen_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    OR o.stall_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    )-->
<!--                </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 ros.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 (o.canteen_id = it1.data_id)-->
<!--                         )-->
<!--                         OR 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 (o.stall_id = it1.data_id)-->
<!--                         )-->
<!--                         )-->
<!--                 </if>-->
<!--                <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--                    and EXISTS (-->
<!--                    SELECT null-->
<!--                    FROM mgr_role_area 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 ar.area_id = it1.data_id-->
<!--                    )-->
<!--                </if>-->
<!--            </where>-->

<!--                ) t-->
<!--                GROUP BY-->
<!--                        <if test="param.sumType == 2">-->
<!--                            statistic_date,-->
<!--                        </if>-->
<!--                        cust_id,-->
<!--                        org_id-->

<!--        ) t-->
<!--            left join cust_info ci on ci.cust_id = t.cust_id-->
<!--            left join cust_org co on co.org_id = t.org_id-->
<!--            <where>-->
<!--                <if test="param.keyword != null and param.keyword != ''">-->
<!--                    AND (-->
<!--                    ci.cust_name = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                    OR ci.cust_name_like LIKE CONCAT('%',#{param.keyword,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')-->
<!--                    OR ci.cust_num = #{param.keyword}-->
<!--                    OR ci.mobile = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                    OR ci.mobile_suffix = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                    )-->
<!--                </if>-->
<!--            </where>-->
<!--            GROUP BY-->
<!--                    <if test="param.sumType == 2">-->
<!--                        t.statistic_date,-->
<!--                    </if>-->
<!--                    t.cust_id,-->
<!--                    co.org_full_name-->

<!--            ) t-->
<!--            <if test="param.sumType == 2">-->
<!--            RIGHT JOIN (-->
<!--            SELECT-->
<!--            date_add( date_sub( #{param.startDate}, INTERVAL 1 DAY ), INTERVAL (CAST(custom_id AS signed INTEGER)) DAY) statistic_date-->
<!--            FROM-->
<!--            menu_custom_dict-->
<!--            WHERE-->
<!--            custom_id <![CDATA[ <= ]]> DATEDIFF(-->
<!--            #{param.endDate},-->
<!--            date_sub( #{param.startDate}, INTERVAL 1 DAY ))-->
<!--            ) daydate ON daydate.statistic_date = t.statistic_date-->
<!--        </if>-->
<!--    </select>-->


<!--    <select id="listCustSummary_COUNT" resultType="long" databaseId="kb">-->
<!--        select count(*)-->
<!--        from-->
<!--            (-->
<!--        SELECT-->
<!--                <if test="param.sumType == 2">-->
<!--                    t.statistic_date,-->
<!--                </if>-->
<!--                t.cust_id,-->
<!--                co.org_full_name-->
<!--        FROM (-->
<!--            SELECT-->
<!--                    <if test="param.sumType == 2">-->
<!--                        t.statistic_date,-->
<!--                    </if>-->
<!--                    t.cust_id,-->
<!--                    t.org_id-->
<!--            FROM-->

<!--            (-->
<!--            SELECT-->
<!--                <if test="param.sumType == 2">-->
<!--                    DATE_FORMAT(o.pay_time,'%Y-%m-%d') statistic_date,-->
<!--                </if>-->
<!--                o.cust_id,-->
<!--                o.org_id-->
<!--            FROM-->
<!--                report_order_info o-->
<!--                LEFT JOIN mkt_holiday mh ON mh.hol_date = DATE_FORMAT( o.pay_time, '%Y-%m-%d' )-->
<!--                LEFT JOIN alloc_canteen c ON c.canteen_id = o.canteen_id-->
<!--                LEFT JOIN alloc_area ar ON c.area_id = ar.area_id-->
<!--            <where>-->
<!--                 <if test="param.startDate != null">-->
<!--                         <![CDATA[AND o.pay_time >= concat(#{param.startDate},' 00:00:00')]]>-->
<!--                 </if>-->
<!--                 <if test="param.endDate != null">-->
<!--                         <![CDATA[AND o.pay_time <= concat(#{param.endDate},' 23:59:59')]]>-->
<!--                 </if>-->
<!--                 <if test="param.ageTypes != null and param.ageTypes.size() > 0">-->
<!--                         AND o.age_type IN-->
<!--                         <foreach collection="param.ageTypes" item="ageType" separator="," open="(" close=")">-->
<!--                                 #{ageType}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                 <if test="param.orgIds != null and param.orgIds.size() > 0">-->
<!--                         and o.org_id in-->
<!--                         <foreach collection="param.orgIds" item="orgId" separator="," open="("-->
<!--                                            close=")">-->
<!--                                 #{orgId}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                 <if test="param.holidayTypeList != null and param.holidayTypeList.size() > 0">-->
<!--                         AND mh.hol_type in-->
<!--                         <foreach collection="param.holidayTypeList" item="holidayType" separator="," open="(" close=")">-->
<!--                                 #{holidayType}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                <if test="param.canteenStallIds != null and param.canteenStallIds.size() > 0">-->
<!--                    AND (o.canteen_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    OR o.stall_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    )-->
<!--                </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 o.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 (o.canteen_id = it1.data_id)-->
<!--                         )-->
<!--                         OR 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 (o.stall_id = it1.data_id)-->
<!--                         )-->
<!--                         )-->
<!--                 </if>-->
<!--                <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--                    and EXISTS (-->
<!--                    SELECT null-->
<!--                    FROM mgr_role_area 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 ar.area_id = it1.data_id-->
<!--                    )-->
<!--                </if>-->
<!--            </where>-->

<!--            UNION ALL-->

<!--            SELECT-->
<!--                <if test="param.sumType == 2">-->
<!--                    DATE_FORMAT(r.check_time,'%Y-%m-%d') statistic_date,-->
<!--                </if>-->
<!--                o.cust_id,-->
<!--                o.org_id-->
<!--            from report_refund r-->
<!--              left join report_order_info o on o.order_id = r.order_id-->
<!--                LEFT JOIN mkt_holiday mh ON mh.hol_date = DATE_FORMAT( r.check_time, '%Y-%m-%d' )-->
<!--                LEFT JOIN alloc_canteen c ON c.canteen_id = o.canteen_id-->
<!--                LEFT JOIN alloc_area ar ON c.area_id = ar.area_id-->
<!--            <where>-->
<!--                 <if test="param.startDate != null">-->
<!--                         <![CDATA[AND r.check_time >= concat(#{param.startDate},' 00:00:00')]]>-->
<!--                 </if>-->
<!--                 <if test="param.endDate != null">-->
<!--                         <![CDATA[AND r.check_time <= concat(#{param.endDate},' 23:59:59')]]>-->
<!--                 </if>-->
<!--                 <if test="param.ageTypes != null and param.ageTypes.size() > 0">-->
<!--                         AND o.age_type IN-->
<!--                         <foreach collection="param.ageTypes" item="ageType" separator="," open="(" close=")">-->
<!--                                 #{ageType}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                 <if test="param.orgIds != null and param.orgIds.size() > 0">-->
<!--                         and o.org_id in-->
<!--                         <foreach collection="param.orgIds" item="orgId" separator="," open="(" close=")">-->
<!--                                 #{orgId}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                 <if test="param.holidayTypeList != null and param.holidayTypeList.size() > 0">-->
<!--                         AND mh.hol_type in-->
<!--                         <foreach collection="param.holidayTypeList" item="holidayType" separator="," open="(" close=")">-->
<!--                                 #{holidayType}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                <if test="param.canteenStallIds != null and param.canteenStallIds.size() > 0">-->
<!--                    AND (o.canteen_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    OR o.stall_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    )-->
<!--                </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 ros.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 (o.canteen_id = it1.data_id)-->
<!--                         )-->
<!--                         OR 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 (o.stall_id = it1.data_id)-->
<!--                         )-->
<!--                         )-->
<!--                 </if>-->
<!--                <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--                    and EXISTS (-->
<!--                    SELECT null-->
<!--                    FROM mgr_role_area 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 ar.area_id = it1.data_id-->
<!--                    )-->
<!--                </if>-->
<!--            </where>-->

<!--                ) t-->
<!--                GROUP BY-->
<!--                        <if test="param.sumType == 2">-->
<!--                            statistic_date,-->
<!--                        </if>-->
<!--                        cust_id,-->
<!--                        org_id-->

<!--        ) t-->
<!--            left join cust_info ci on ci.cust_id = t.cust_id-->
<!--            left join cust_org co on co.org_id = t.org_id-->
<!--            <where>-->
<!--                <if test="param.keyword != null and param.keyword != ''">-->
<!--                    AND (-->
<!--                    ci.cust_name = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                    OR ci.cust_name_like LIKE CONCAT('%',#{param.keyword,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')-->
<!--                    OR ci.cust_num = #{param.keyword}-->
<!--                    OR ci.mobile = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                    OR ci.mobile_suffix = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                    )-->
<!--                </if>-->
<!--            </where>-->
<!--            GROUP BY-->
<!--                    <if test="param.sumType == 2">-->
<!--                        t.statistic_date,-->
<!--                    </if>-->
<!--                    t.cust_id,-->
<!--                    co.org_full_name-->

<!--            ) t-->
<!--            <if test="param.sumType == 2">-->
<!--            RIGHT JOIN (-->
<!--            SELECT-->
<!--            (TO_DATE(#{param.startDate}, 'YYYY-MM-DD') + ROWNUM - 1) as statistic_date-->
<!--            FROM-->
<!--            DUAL-->
<!--            CONNECT BY-->
<!--            ROWNUM <![CDATA[<=]]> TO_DATE(#{param.endDate}, 'YYYY-MM-DD') - TO_DATE(#{param.startDate}, 'YYYY-MM-DD') + 1-->
<!--            ) daydate ON daydate.statistic_date = t.statistic_date-->
<!--        </if>-->
<!--    </select>-->

<!--    <select id="listCustSummary" resultType="net.xnzn.core.report.statistics.order.basic.vo.ReportCustSummaryVO">-->
<!--        <if test="param.sumType == 2">-->
<!--        SELECT-->
<!--            daydate.statistic_date AS statistic_date,-->
<!--            A.cust_id,-->
<!--            A.cust_num,-->
<!--            A.cust_name,-->
<!--            A.mobile,-->
<!--            A.org_full_name,-->
<!--            IF(A.cust_id is NULL,0,1) AS total_consume_day_num,-->

<!--            IFNULL( A.breakfast_consume_num, 0 ) AS breakfast_consume_num,-->
<!--            IFNULL( A.breakfast_real_amount, 0 ) AS breakfast_real_amount,-->
<!--            IFNULL( A.breakfast_payable_amount, 0 ) AS breakfast_payable_amount,-->
<!--            IFNULL( A.breakfast_discount_amount, 0 ) AS breakfast_discount_amount,-->
<!--            IFNULL( A.breakfast_refund_amount, 0 ) AS breakfast_refund_amount,-->

<!--            IFNULL( A.lunch_consume_num, 0 ) AS lunch_consume_num,-->
<!--            IFNULL( A.lunch_real_amount, 0 ) AS lunch_real_amount,-->
<!--            IFNULL( A.lunch_payable_amount, 0 ) AS lunch_payable_amount,-->
<!--            IFNULL( A.lunch_discount_amount, 0 ) AS lunch_discount_amount,-->
<!--            IFNULL( A.lunch_refund_amount, 0 ) AS lunch_refund_amount,-->

<!--            IFNULL( A.afternoon_consume_num, 0 ) AS afternoon_consume_num,-->
<!--            IFNULL( A.afternoon_real_amount, 0 ) AS afternoon_real_amount,-->
<!--            IFNULL( A.afternoon_payable_amount, 0 ) AS afternoon_payable_amount,-->
<!--            IFNULL( A.afternoon_discount_amount, 0 ) AS afternoon_discount_amount,-->
<!--            IFNULL( A.afternoon_refund_amount, 0 ) AS afternoon_refund_amount,-->

<!--            IFNULL( A.dinner_consume_num, 0 ) AS dinner_consume_num,-->
<!--            IFNULL( A.dinner_real_amount, 0 ) AS dinner_real_amount,-->
<!--            IFNULL( A.dinner_payable_amount, 0 ) AS dinner_payable_amount,-->
<!--            IFNULL( A.dinner_discount_amount, 0 ) AS dinner_discount_amount,-->
<!--            IFNULL( A.dinner_refund_amount, 0 ) AS dinner_refund_amount,-->

<!--            IFNULL( A.supper_consume_num, 0 ) AS supper_consume_num,-->
<!--            IFNULL( A.supper_real_amount, 0 ) AS supper_real_amount,-->
<!--            IFNULL( A.supper_payable_amount, 0 ) AS supper_payable_amount,-->
<!--            IFNULL( A.supper_discount_amount, 0 ) AS supper_discount_amount,-->
<!--            IFNULL( A.supper_refund_amount, 0 ) AS supper_refund_amount,-->

<!--            IFNULL( A.other_consume_num, 0 ) AS other_consume_num,-->
<!--            IFNULL( A.other_real_amount, 0 ) AS other_real_amount,-->
<!--            IFNULL( A.other_payable_amount, 0 ) AS other_payable_amount,-->
<!--            IFNULL( A.other_discount_amount, 0 ) AS other_discount_amount,-->
<!--            IFNULL( A.other_refund_amount, 0 ) AS other_refund_amount,-->

<!--            IFNULL( A.total_consume_num, 0 ) AS total_consume_num,-->
<!--            IFNULL( A.total_real_amount, 0 ) AS total_real_amount,-->
<!--            IFNULL( A.total_payable_amount, 0 ) AS total_payable_amount,-->
<!--            IFNULL( A.total_discount_amount, 0 ) AS total_discount_amount,-->
<!--            IFNULL( A.total_refund_amount, 0 ) AS total_refund_amount-->
<!--        FROM-->
<!--            (-->
<!--        </if>-->

<!--        <include refid="querySummary"></include>-->

<!--        <if test="param.sumType == 2">-->
<!--            ) A-->
<!--            RIGHT JOIN (-->
<!--            SELECT-->
<!--            date_add( date_sub( #{param.startDate}, INTERVAL 1 DAY ), INTERVAL (CAST(custom_id AS signed INTEGER)) DAY) statistic_date-->
<!--            FROM-->
<!--            menu_custom_dict-->
<!--            WHERE-->
<!--            custom_id <![CDATA[ <= ]]> DATEDIFF(-->
<!--            #{param.endDate},-->
<!--            date_sub( #{param.startDate}, INTERVAL 1 DAY ))-->
<!--            ) daydate ON daydate.statistic_date = A.statistic_date-->
<!--        </if>-->
<!--    </select>-->

<!--    <select id="listCustSummary" resultType="net.xnzn.core.report.statistics.order.basic.vo.ReportCustSummaryVO" databaseId="kb">-->
<!--        <if test="param.sumType == 2">-->
<!--            SELECT-->
<!--            daydate.statistic_date AS statistic_date,-->
<!--            A.cust_id,-->
<!--            A.cust_num,-->
<!--            A.cust_name,-->
<!--            A.mobile,-->
<!--            A.org_full_name,-->
<!--            IF(A.cust_id is NULL,0,1) AS total_consume_day_num,-->

<!--            IFNULL( A.breakfast_consume_num, 0 ) AS breakfast_consume_num,-->
<!--            IFNULL( A.breakfast_real_amount, 0 ) AS breakfast_real_amount,-->
<!--            IFNULL( A.breakfast_payable_amount, 0 ) AS breakfast_payable_amount,-->
<!--            IFNULL( A.breakfast_discount_amount, 0 ) AS breakfast_discount_amount,-->
<!--            IFNULL( A.breakfast_refund_amount, 0 ) AS breakfast_refund_amount,-->

<!--            IFNULL( A.lunch_consume_num, 0 ) AS lunch_consume_num,-->
<!--            IFNULL( A.lunch_real_amount, 0 ) AS lunch_real_amount,-->
<!--            IFNULL( A.lunch_payable_amount, 0 ) AS lunch_payable_amount,-->
<!--            IFNULL( A.lunch_discount_amount, 0 ) AS lunch_discount_amount,-->
<!--            IFNULL( A.lunch_refund_amount, 0 ) AS lunch_refund_amount,-->

<!--            IFNULL( A.afternoon_consume_num, 0 ) AS afternoon_consume_num,-->
<!--            IFNULL( A.afternoon_real_amount, 0 ) AS afternoon_real_amount,-->
<!--            IFNULL( A.afternoon_payable_amount, 0 ) AS afternoon_payable_amount,-->
<!--            IFNULL( A.afternoon_discount_amount, 0 ) AS afternoon_discount_amount,-->
<!--            IFNULL( A.afternoon_refund_amount, 0 ) AS afternoon_refund_amount,-->

<!--            IFNULL( A.dinner_consume_num, 0 ) AS dinner_consume_num,-->
<!--            IFNULL( A.dinner_real_amount, 0 ) AS dinner_real_amount,-->
<!--            IFNULL( A.dinner_payable_amount, 0 ) AS dinner_payable_amount,-->
<!--            IFNULL( A.dinner_discount_amount, 0 ) AS dinner_discount_amount,-->
<!--            IFNULL( A.dinner_refund_amount, 0 ) AS dinner_refund_amount,-->

<!--            IFNULL( A.supper_consume_num, 0 ) AS supper_consume_num,-->
<!--            IFNULL( A.supper_real_amount, 0 ) AS supper_real_amount,-->
<!--            IFNULL( A.supper_payable_amount, 0 ) AS supper_payable_amount,-->
<!--            IFNULL( A.supper_discount_amount, 0 ) AS supper_discount_amount,-->
<!--            IFNULL( A.supper_refund_amount, 0 ) AS supper_refund_amount,-->

<!--            IFNULL( A.other_consume_num, 0 ) AS other_consume_num,-->
<!--            IFNULL( A.other_real_amount, 0 ) AS other_real_amount,-->
<!--            IFNULL( A.other_payable_amount, 0 ) AS other_payable_amount,-->
<!--            IFNULL( A.other_discount_amount, 0 ) AS other_discount_amount,-->
<!--            IFNULL( A.other_refund_amount, 0 ) AS other_refund_amount,-->

<!--            IFNULL( A.total_consume_num, 0 ) AS total_consume_num,-->
<!--            IFNULL( A.total_real_amount, 0 ) AS total_real_amount,-->
<!--            IFNULL( A.total_payable_amount, 0 ) AS total_payable_amount,-->
<!--            IFNULL( A.total_discount_amount, 0 ) AS total_discount_amount,-->
<!--            IFNULL( A.total_refund_amount, 0 ) AS total_refund_amount-->
<!--            FROM-->
<!--            (-->
<!--        </if>-->

<!--        <include refid="querySummary"></include>-->

<!--        <if test="param.sumType == 2">-->
<!--            ) A-->
<!--            RIGHT JOIN (-->
<!--            SELECT-->
<!--            (TO_DATE(#{param.startDate}, 'YYYY-MM-DD') + ROWNUM - 1) as statistic_date-->
<!--            FROM-->
<!--            DUAL-->
<!--            CONNECT BY-->
<!--            ROWNUM <![CDATA[<=]]> TO_DATE(#{param.endDate}, 'YYYY-MM-DD') - TO_DATE(#{param.startDate}, 'YYYY-MM-DD') + 1-->
<!--            ) daydate ON daydate.statistic_date = A.statistic_date-->
<!--        </if>-->
<!--    </select>-->

<!--    <select id="getCustSummaryTotal" resultType="net.xnzn.core.report.statistics.order.basic.vo.ReportCustSummaryVO">-->
<!--        SELECT sum(breakfast_consume_num)                  AS breakfast_consume_num-->
<!--             , sum(breakfast_payable_amount)               AS breakfast_payable_amount-->
<!--             , sum(breakfast_discount_amount)              AS breakfast_discount_amount-->
<!--             , sum(breakfast_refund_amount)                AS breakfast_refund_amount-->
<!--             , sum(breakfast_real_amount)                  AS breakfast_real_amount-->


<!--             , sum(lunch_consume_num)                   AS lunch_consume_num-->
<!--             , sum(lunch_payable_amount)                AS lunch_payable_amount-->
<!--             , sum(lunch_discount_amount)               AS lunch_discount_amount-->
<!--             , sum(lunch_refund_amount)                 AS lunch_refund_amount-->
<!--             , sum(lunch_real_amount)                   AS lunch_real_amount-->


<!--             , sum(afternoon_consume_num)                   AS afternoon_consume_num-->
<!--             , sum(afternoon_payable_amount)                AS afternoon_payable_amount-->
<!--             , sum(afternoon_discount_amount)               AS afternoon_discount_amount-->
<!--             , sum(afternoon_refund_amount)                 AS afternoon_refund_amount-->
<!--             , sum(afternoon_real_amount)                   AS afternoon_real_amount-->


<!--             , sum(dinner_consume_num)                      AS dinner_consume_num-->
<!--             , sum(dinner_payable_amount)                   AS dinner_payable_amount-->
<!--             , sum(dinner_discount_amount)                  AS dinner_discount_amount-->
<!--             , sum(dinner_refund_amount)                    AS dinner_refund_amount-->
<!--             , sum(dinner_real_amount)                      AS dinner_real_amount-->


<!--             , sum(supper_consume_num)                      AS supper_consume_num-->
<!--             , sum(supper_payable_amount)                   AS supper_payable_amount-->
<!--             , sum(supper_discount_amount)                  AS supper_discount_amount-->
<!--             , sum(supper_refund_amount)                    AS supper_refund_amount-->
<!--             , sum(supper_real_amount)                      AS supper_real_amount-->


<!--             , sum(other_consume_num)                   AS other_consume_num-->
<!--             , sum(other_payable_amount)                AS other_payable_amount-->
<!--             , sum(other_discount_amount)               AS other_discount_amount-->
<!--             , sum(other_refund_amount)                 AS other_refund_amount-->
<!--             , sum(other_real_amount)                   AS other_real_amount-->
<!--             , sum(total_consume_num)                   AS total_consume_num-->
<!--             , sum(total_payable_amount)                AS total_payable_amount-->
<!--             , sum(total_discount_amount)               AS total_discount_amount-->
<!--             , sum(total_refund_amount)                 AS total_refund_amount-->
<!--             , sum(total_real_amount)                   AS total_real_amount-->
<!--            <if test="param.sumType == 2">-->
<!--                , COUNT(IF(t.cust_id is NULL,0,1)) AS total_consume_day_num-->
<!--            </if>-->

<!--        FROM (-->
<!--             <include refid="querySummary"></include>-->
<!--         ) t-->
<!--    </select>-->

<!--    <sql id="querySummary">-->
<!--        <if test="param.sumType == 1">-->
<!--            SELECT t.*-->

<!--            FROM-->
<!--            (-->
<!--        </if>-->
<!--        SELECT-->
<!--                <if test="param.sumType == 2">-->
<!--                    t.statistic_date,-->
<!--                </if>-->
<!--                t.cust_id,-->
<!--                ci.cust_num,-->
<!--                ci.cust_name,-->
<!--                ci.mobile,-->
<!--                co.org_full_name-->

<!--                , sum(if(t.mealtime_type = 1, t.consume_num, 0)) AS breakfast_consume_num-->
<!--                , sum(if(t.mealtime_type = 1, t.total_amount, 0)) AS breakfast_real_amount-->
<!--                , sum(if(t.mealtime_type = 1, t.payable_amount, 0)) AS breakfast_payable_amount-->
<!--                , sum(if(t.mealtime_type = 1, t.discount_amount, 0)) AS breakfast_discount_amount-->
<!--                , sum(if(t.mealtime_type = 1, t.refund_amount, 0)) AS breakfast_refund_amount-->


<!--                , sum(if(t.mealtime_type = 2, t.consume_num, 0)) AS lunch_consume_num-->
<!--                , sum(if(t.mealtime_type = 2, t.total_amount, 0)) AS lunch_real_amount-->
<!--                , sum(if(t.mealtime_type = 2, t.payable_amount, 0)) AS lunch_payable_amount-->
<!--                , sum(if(t.mealtime_type = 2, t.discount_amount, 0)) AS lunch_discount_amount-->
<!--                , sum(if(t.mealtime_type = 2, t.refund_amount, 0)) AS lunch_refund_amount-->


<!--                , sum(if(t.mealtime_type = 3, t.consume_num, 0)) AS afternoon_consume_num-->
<!--                , sum(if(t.mealtime_type = 3, t.total_amount, 0)) AS afternoon_real_amount-->
<!--                , sum(if(t.mealtime_type = 3, t.payable_amount, 0)) AS afternoon_payable_amount-->
<!--                , sum(if(t.mealtime_type = 3, t.discount_amount, 0)) AS afternoon_discount_amount-->
<!--                , sum(if(t.mealtime_type = 3, t.refund_amount, 0)) AS afternoon_refund_amount-->


<!--                , sum(if(t.mealtime_type = 4, t.consume_num, 0)) AS dinner_consume_num-->
<!--                , sum(if(t.mealtime_type = 4, t.total_amount, 0)) AS dinner_real_amount-->
<!--                , sum(if(t.mealtime_type = 4, t.payable_amount, 0)) AS dinner_payable_amount-->
<!--                , sum(if(t.mealtime_type = 4, t.discount_amount, 0)) AS dinner_discount_amount-->
<!--                , sum(if(t.mealtime_type = 4, t.refund_amount, 0)) AS dinner_refund_amount-->


<!--                , sum(if(t.mealtime_type = 5, t.consume_num, 0)) AS supper_consume_num-->
<!--                , sum(if(t.mealtime_type = 5, t.total_amount, 0)) AS supper_real_amount-->
<!--                , sum(if(t.mealtime_type = 5, t.payable_amount, 0)) AS supper_payable_amount-->
<!--                , sum(if(t.mealtime_type = 5, t.discount_amount, 0)) AS supper_discount_amount-->
<!--                , sum(if(t.mealtime_type = 5, t.refund_amount, 0)) AS supper_refund_amount-->


<!--                , sum(if(t.mealtime_type = -1, t.consume_num, 0)) AS other_consume_num-->
<!--                , sum(if(t.mealtime_type = -1, t.total_amount, 0)) AS other_real_amount-->
<!--                , sum(if(t.mealtime_type = -1, t.payable_amount, 0)) AS other_payable_amount-->
<!--                , sum(if(t.mealtime_type = -1, t.discount_amount, 0)) AS other_discount_amount-->
<!--                , sum(if(t.mealtime_type = -1, t.refund_amount, 0)) AS other_refund_amount-->


<!--                , sum(t.consume_num) AS total_consume_num-->
<!--                , sum(t.total_amount) AS total_real_amount-->
<!--                , sum(t.payable_amount) AS total_payable_amount-->
<!--                , sum(t.discount_amount) AS total_discount_amount-->
<!--                , sum(t.refund_amount) AS total_refund_amount-->
<!--        FROM (-->
<!--            SELECT-->
<!--                    <if test="param.sumType == 2">-->
<!--                        t.statistic_date,-->
<!--                    </if>-->
<!--                    t.cust_id,-->
<!--                    t.org_id,-->
<!--                    t.mealtime_type,-->
<!--                    COUNT( DISTINCT t.order_id ) consume_num,-->
<!--                    SUM( t.real_amount ) + SUM( t.refund_amount ) total_amount,-->
<!--                    SUM( t.payable_amount ) payable_amount,-->
<!--                    SUM( t.discount_amount ) discount_amount,-->
<!--                    SUM( t.refund_amount ) refund_amount-->
<!--            FROM-->

<!--            (-->
<!--            SELECT-->
<!--                <if test="param.sumType == 2">-->
<!--                    DATE_FORMAT(o.pay_time,'%Y-%m-%d') statistic_date,-->
<!--                </if>-->
<!--                o.cust_id,-->
<!--                o.org_id,-->
<!--                o.mealtime_type,-->
<!--                o.order_id,-->
<!--                o.real_amount,-->
<!--                o.payable_amount,-->
<!--                o.discounts_amount AS discount_amount,-->
<!--                0 as refund_amount-->
<!--            FROM-->
<!--                report_order_info o-->
<!--                LEFT JOIN mkt_holiday mh ON mh.hol_date = DATE_FORMAT( o.pay_time, '%Y-%m-%d' )-->
<!--                LEFT JOIN alloc_canteen c ON c.canteen_id = o.canteen_id-->
<!--                LEFT JOIN alloc_area ar ON c.area_id = ar.area_id-->
<!--            <where>-->
<!--                 <if test="param.startDate != null">-->
<!--                         <![CDATA[AND o.pay_time >= concat(#{param.startDate},' 00:00:00')]]>-->
<!--                 </if>-->
<!--                 <if test="param.endDate != null">-->
<!--                         <![CDATA[AND o.pay_time <= concat(#{param.endDate},' 23:59:59')]]>-->
<!--                 </if>-->
<!--                 <if test="param.ageTypes != null and param.ageTypes.size() > 0">-->
<!--                         AND o.age_type IN-->
<!--                         <foreach collection="param.ageTypes" item="ageType" separator="," open="(" close=")">-->
<!--                                 #{ageType}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                 <if test="param.orgIds != null and param.orgIds.size() > 0">-->
<!--                         and o.org_id in-->
<!--                         <foreach collection="param.orgIds" item="orgId" separator="," open="("-->
<!--                                            close=")">-->
<!--                                 #{orgId}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                 <if test="param.holidayTypeList != null and param.holidayTypeList.size() > 0">-->
<!--                         AND mh.hol_type in-->
<!--                         <foreach collection="param.holidayTypeList" item="holidayType" separator="," open="(" close=")">-->
<!--                                 #{holidayType}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                <if test="param.canteenStallIds != null and param.canteenStallIds.size() > 0">-->
<!--                    AND (o.canteen_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    OR o.stall_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    )-->
<!--                </if>-->
<!--                <if test="param.areaIdList != null and param.areaIdList.size() > 0">-->
<!--                    AND c.area_id in-->
<!--                    <foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">-->
<!--                        #{item}-->
<!--                    </foreach>-->
<!--                </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 o.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 (o.canteen_id = it1.data_id)-->
<!--                         )-->
<!--                         OR 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 (o.stall_id = it1.data_id)-->
<!--                         )-->
<!--                         )-->
<!--                 </if>-->
<!--                <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--                    and EXISTS (-->
<!--                    SELECT null-->
<!--                    FROM mgr_role_area 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 ar.area_id = it1.data_id-->
<!--                    )-->
<!--                </if>-->
<!--            </where>-->

<!--            UNION ALL-->

<!--            SELECT-->
<!--                <if test="param.sumType == 2">-->
<!--                    DATE_FORMAT(r.check_time,'%Y-%m-%d') statistic_date,-->
<!--                </if>-->
<!--                o.cust_id,-->
<!--                o.org_id,-->
<!--                o.mealtime_type,-->
<!--                o.order_id,-->
<!--                0 AS total_amount,-->
<!--                0 AS payable_amount,-->
<!--                0 AS discount_amount,-->
<!--                r.real_refund_amount * - 1 as refund_amount-->
<!--            from report_refund r-->
<!--              left join report_order_info o on o.order_id = r.order_id-->
<!--                LEFT JOIN mkt_holiday mh ON mh.hol_date = DATE_FORMAT( r.check_time, '%Y-%m-%d' )-->
<!--                LEFT JOIN alloc_canteen c ON c.canteen_id = o.canteen_id-->
<!--                LEFT JOIN alloc_area ar ON c.area_id = ar.area_id-->
<!--            <where>-->
<!--                 <if test="param.startDate != null">-->
<!--                         <![CDATA[AND r.check_time >= concat(#{param.startDate},' 00:00:00')]]>-->
<!--                 </if>-->
<!--                 <if test="param.endDate != null">-->
<!--                         <![CDATA[AND r.check_time <= concat(#{param.endDate},' 23:59:59')]]>-->
<!--                 </if>-->
<!--                 <if test="param.ageTypes != null and param.ageTypes.size() > 0">-->
<!--                         AND o.age_type IN-->
<!--                         <foreach collection="param.ageTypes" item="ageType" separator="," open="(" close=")">-->
<!--                                 #{ageType}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                 <if test="param.orgIds != null and param.orgIds.size() > 0">-->
<!--                         and o.org_id in-->
<!--                         <foreach collection="param.orgIds" item="orgId" separator="," open="(" close=")">-->
<!--                                 #{orgId}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                 <if test="param.holidayTypeList != null and param.holidayTypeList.size() > 0">-->
<!--                         AND mh.hol_type in-->
<!--                         <foreach collection="param.holidayTypeList" item="holidayType" separator="," open="(" close=")">-->
<!--                                 #{holidayType}-->
<!--                         </foreach>-->
<!--                 </if>-->
<!--                <if test="param.canteenStallIds != null and param.canteenStallIds.size() > 0">-->
<!--                    AND (o.canteen_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    OR o.stall_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    )-->
<!--                </if>-->

<!--                <if test="param.areaIdList != null and param.areaIdList.size() > 0">-->
<!--                    AND c.area_id in-->
<!--                    <foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">-->
<!--                        #{item}-->
<!--                    </foreach>-->
<!--                </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 o.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 (o.canteen_id = it1.data_id)-->
<!--                         )-->
<!--                         OR 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 (o.stall_id = it1.data_id)-->
<!--                         )-->
<!--                         )-->
<!--                 </if>-->
<!--                <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--                    and EXISTS (-->
<!--                    SELECT null-->
<!--                    FROM mgr_role_area 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 ar.area_id = it1.data_id-->
<!--                    )-->
<!--                </if>-->
<!--            </where>-->

<!--                ) t-->
<!--                GROUP BY-->
<!--                        <if test="param.sumType == 2">-->
<!--                            statistic_date,-->
<!--                        </if>-->
<!--                        cust_id,-->
<!--                        org_id,-->
<!--                        mealtime_type-->

<!--        ) t-->
<!--            left join cust_info ci on ci.cust_id = t.cust_id-->
<!--            left join cust_org co on co.org_id = t.org_id-->
<!--            <where>-->
<!--                <if test="param.keyword != null and param.keyword != ''">-->
<!--                    AND (-->
<!--                    ci.cust_name = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                    OR ci.cust_name_like LIKE CONCAT('%',#{param.keyword,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')-->
<!--                    OR ci.cust_num = #{param.keyword}-->
<!--                    OR ci.mobile = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                    OR ci.mobile_suffix = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--                    )-->
<!--                </if>-->
<!--            </where>-->
<!--            GROUP BY-->
<!--                    <if test="param.sumType == 2">-->
<!--                        t.statistic_date,-->
<!--                    </if>-->
<!--                    t.cust_id,-->
<!--                    ci.cust_num,-->
<!--                    ci.cust_name,-->
<!--                    ci.mobile,-->
<!--                    co.org_full_name-->

<!--        <if test="param.sumType == 1">-->
<!--            ) t-->
<!--        </if>-->
<!--    </sql>-->

    <insert id="initByPayTime">
        INSERT INTO report_order_info (order_id, canteen_id, stall_id, org_id, mealtime_type, cust_id,
                                       machine_sn, nu_clear_mode, psn_type, age_type, source_type, payable_amount,
                                       discounts_amount, delivery_amount, packing_amount, real_amount, acc_pay_amount,
                                       out_pay_amount, order_time, order_date, order_type, order_refund_state, pay_time,
                                       pay_type, pay_channel, remark, consume_flag, holiday_type, if_online, refund_amount, status)
            SELECT
                d.order_id,
                d.canteen_id,
                d.stall_id,
                ifnull(ci.org_id, 99999) AS org_id,
                d.mealtime_type,
                d.cust_id,
                d.machine_sn,
                ifnull(d.nu_clear_mode, -1) AS nu_clear_mode,
                ifnull(ci.psn_type, -1) AS psn_type,
                (case
                when TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE())>=0 and TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE()) <![CDATA[ < ]]> 10 then 0
                when TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE())>=10 and TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE()) <![CDATA[ < ]]> 20 then 1
                when TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE())>=20 and TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE()) <![CDATA[ < ]]> 30 then 2
                when TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE())>=30 and TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE()) <![CDATA[ < ]]> 40 then 3
                when TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE())>=40 and TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE()) <![CDATA[ < ]]> 50 then 4
                when TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE())>=50 and TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE()) <![CDATA[ < ]]> 60 then 5
                when TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE())>=60 and TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE()) <![CDATA[ < ]]> 70 then 6
                when TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE())>=70 and TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE()) <![CDATA[ < ]]> 80 then 7
                when TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE())>=80 and TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE()) <![CDATA[ < ]]> 90 then 8
                when TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE())>=90 and TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE()) <![CDATA[ < ]]> 100 then 9
                when TIMESTAMPDIFF(YEAR, ci.birthday, CURDATE())>=100 then 10
                else 11 end) as age_type,
                d.source_type,
                d.payable_amount,
                d.discounts_amount * - 1,
                d.delivery_amount,
                d.packing_amount,
                d.real_amount,
                d.acc_pay_amount,
                d.out_pay_amount,
                d.order_time,
                d.order_date,
                d.order_type,
                d.order_refund_state,
                d.pay_time,
                d.pay_type,
                d.pay_channel,
                d.remark,
                2 AS consume_flag,
                ifnull(a.hol_type, -1) AS holiday_type,
                d.if_online,
                d.refund_amount,
                1
            FROM
                order_info d
            LEFT JOIN cust_info ci ON d.cust_id = ci.cust_id
            LEFT JOIN (
                    SELECT hol_date,MIN(hol_type) AS hol_type FROM mkt_holiday GROUP BY hol_date
                ) a ON DATE_FORMAT(d.pay_time,'%Y-%m-%d') = DATE_FORMAT(a.hol_date,'%Y-%m-%d')
            WHERE
                d.pay_state = 3
                AND d.pay_time BETWEEN #{startTime} AND #{endTime}
    </insert>


<!--    <insert id="initByPayTime" databaseId="kb">-->
<!--        INSERT INTO report_order_info (order_id, canteen_id, stall_id, org_id, mealtime_type, cust_id,-->
<!--                                       machine_sn, nu_clear_mode, psn_type, age_type, source_type, payable_amount,-->
<!--                                       discounts_amount, delivery_amount, packing_amount, real_amount, acc_pay_amount,-->
<!--                                       out_pay_amount, order_time, order_date, order_type, order_refund_state, pay_time,-->
<!--                                       pay_type, pay_channel, remark, consume_flag, holiday_type, if_online, refund_amount, status)-->
<!--        SELECT-->
<!--            d.order_id,-->
<!--            d.canteen_id,-->
<!--            d.stall_id,-->
<!--            ifnull(ci.org_id, 99999) AS org_id,-->
<!--            d.mealtime_type,-->
<!--            d.cust_id,-->
<!--            d.machine_sn,-->
<!--            ifnull(d.nu_clear_mode, -1) AS nu_clear_mode,-->
<!--            ifnull(ci.psn_type, -1) AS psn_type,-->
<!--            (case-->
<!--                 when EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) >=0-->
<!--                          and EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) <![CDATA[ < ]]> 10 then 0-->
<!--                 when EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) >=10-->
<!--                     and EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) <![CDATA[ < ]]> 20 then 1-->
<!--                 when EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) >=20-->
<!--                     and EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) <![CDATA[ < ]]> 30 then 2-->
<!--                 when EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) >=30-->
<!--                     and EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) <![CDATA[ < ]]> 40 then 3-->
<!--                 when EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) >=40-->
<!--                     and EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) <![CDATA[ < ]]> 50 then 4-->
<!--                 when EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) >=50-->
<!--                     and EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) <![CDATA[ < ]]> 60 then 5-->
<!--                 when EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) >=60-->
<!--                     and EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) <![CDATA[ < ]]> 70 then 6-->
<!--                 when EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) >=70-->
<!--                     and EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) <![CDATA[ < ]]> 80 then 7-->
<!--                 when EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) >=80-->
<!--                     and EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) <![CDATA[ < ]]> 90 then 8-->
<!--                 when EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) >=90-->
<!--                     and EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) <![CDATA[ < ]]> 100 then 9-->
<!--                 when EXTRACT(YEAR FROM to_date(ci.birthday, 'YYYY-MM-DD')) - EXTRACT(YEAR FROM to_date(CURRENT_DATE, 'YYYY-MM-DD')) >=100 then 10-->
<!--                 else 11 end) as age_type,-->
<!--            d.source_type,-->
<!--            d.payable_amount,-->
<!--            d.discounts_amount * - 1,-->
<!--            d.delivery_amount,-->
<!--            d.packing_amount,-->
<!--            d.real_amount,-->
<!--            d.acc_pay_amount,-->
<!--            d.out_pay_amount,-->
<!--            d.order_time,-->
<!--            d.order_date,-->
<!--            d.order_type,-->
<!--            d.order_refund_state,-->
<!--            d.pay_time,-->
<!--            d.pay_type,-->
<!--            d.pay_channel,-->
<!--            d.remark,-->
<!--            2 AS consume_flag,-->
<!--            ifnull(a.hol_type, -1) AS holiday_type,-->
<!--            d.if_online,-->
<!--            d.refund_amount,-->
<!--            1-->
<!--        FROM-->
<!--            order_info d-->
<!--                LEFT JOIN cust_info ci ON d.cust_id = ci.cust_id-->
<!--                LEFT JOIN (-->
<!--                SELECT hol_date,MIN(hol_type) AS hol_type FROM mkt_holiday GROUP BY hol_date-->
<!--            ) a ON DATE_FORMAT(d.pay_time,'%Y-%m-%d') = DATE_FORMAT(a.hol_date,'%Y-%m-%d')-->
<!--        WHERE-->
<!--            d.pay_state = 3-->
<!--          AND d.pay_time BETWEEN #{startTime} AND #{endTime}-->
<!--    </insert>-->

<!--    <select id="queryNotConsumeData" resultType="net.xnzn.core.report.statistics.config.mq.dto.ReportNotConsumeDTO">-->
<!--        select if(t1.order_refund_state = 1, DATE_FORMAT(t1.pay_time, '%Y-%m-%d'),-->
<!--                  date_format(t2.check_time, '%Y-%m-%d')) statistic_date,-->
<!--               t1.order_date,-->
<!--               t1.order_id                                relationId-->
<!--        from report_order_info t1-->
<!--                 left join-->
<!--             report_refund t2 on t1.order_id = t2.order_id-->
<!--        where t1.status = 0-->
<!--    </select>-->

<!--    <update id="updateOrderMsg">-->
<!--        update report_order_info set status = 1 where order_id in-->
<!--        <foreach collection="list" item="item" separator="," open="("-->
<!--                 close=")">-->
<!--            #{item.relationId}-->
<!--        </foreach>-->
<!--    </update>-->


<!--    <select id="getOrderDishesSumForDevice" resultType="net.xnzn.core.report.api.vo.DeviceOrderDishesSumVO">-->
<!--        SELECT od.goods_dishes_id,-->
<!--               od.goods_dishes_name,-->
<!--               od.unit_name,-->
<!--               od.sales_mode,-->
<!--               SUM( od.quantity - od.goods_refund_num ) AS quantity,-->
<!--               SUM(-->
<!--                   <if test="param.IfContainsUnPay">od.calc_total_amount</if>-->
<!--                   <if test="!param.IfContainsUnPay">od.real_amount - od.refund_amount</if>-->
<!--                   ) AS totalRealAmount-->
<!--        FROM order_info oi-->
<!--        LEFT JOIN order_detail od ON oi.order_id = od.order_id-->
<!--        WHERE 1=1-->
<!--        <if test="param.machineSn != null and param.machineSn.trim() != ''">-->
<!--            AND oi.machine_sn = #{param.machineSn}-->
<!--        </if>-->
<!--        <if test="param.startDate != null and param.endDate != null">-->
<!--            AND oi.order_date BETWEEN #{param.startDate} AND #{param.endDate}-->
<!--        </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.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.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.orderStateList != null and param.orderStateList.size() > 0">-->
<!--            AND oi.order_state in-->
<!--            <foreach collection="param.orderStateList" item="item" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.detailMachineSn != null and param.detailMachineSn.trim() != ''">-->
<!--            AND EXISTS(-->
<!--            SELECT 1 FROM order_detail od-->
<!--            WHERE od.order_id = oi.order_id-->
<!--            AND od.machine_sn = #{param.detailMachineSn}-->
<!--            )-->
<!--        </if>-->
<!--        GROUP BY od.goods_dishes_id,-->
<!--                 od.goods_dishes_name,-->
<!--                 od.unit_name,-->
<!--                 od.sales_mode-->
<!--        ORDER BY od.goods_dishes_id DESC-->
<!--    </select>-->


    <select id="getCustConsumeSum"
            resultType="com.bonus.canteen.core.report.statistics.order.basic.model.ReportOrderInfo">
        SELECT
            o.canteen_id,
            o.stall_id,
            o.machine_sn,
            o.order_refund_state,
            o.order_type,
            o.real_amount - o.refund_amount AS real_amount
        FROM
            report_order_info o
        <where>
            <if test="param.custId != null">
                and o.cust_id = #{param.custId}
            </if>
            <if test="param.mealtimeTypeList != null and param.mealtimeTypeList.size() >0 ">
                AND o.mealtime_type IN
                <foreach collection="param.mealtimeTypeList" item="mealtimeType" open="(" separator="," close=")">
                    #{mealtimeType}
                </foreach>
            </if>
            <if test="param.orderTypeList != null and param.orderTypeList.size() > 0">
                AND o.order_type IN
                <foreach collection="param.orderTypeList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="param.startTime !=null and param.endTime !=null">
                AND o.pay_time between #{param.startTime} AND #{param.endTime}
            </if>
        </where>

    </select>

<!--    <select id="drpDishesSum" resultType="net.xnzn.core.report.api.vo.ReportOrderDetaiVO">-->
<!--        SELECT-->
<!--            oi.order_type,-->
<!--            oi.order_date,-->
<!--            oi.mealtime_type,-->
<!--            od.goods_dishes_id AS goods_dishes_id,-->
<!--            od.goods_dishes_name AS goods_dishes_name,-->
<!--            d.unit_name,-->
<!--            od.sales_mode,-->
<!--            SUM( od.quantity - od.goods_refund_num ) AS quantity-->
<!--        FROM-->
<!--            report_order_detail od-->
<!--            JOIN report_order_info oi ON od.order_id = oi.order_id-->
<!--            LEFT JOIN menu_material mma ON od.goods_dishes_id = mma.material_id-->
<!--            LEFT JOIN drp_unit d ON d.unit_id = mma.unit_id-->
<!--        WHERE-->
<!--            oi.order_refund_state IN (1, 3)-->
<!--        <if test="param.startDate !=null and param.endDate!=null ">-->
<!--            AND oi.order_date BETWEEN #{param.startDate} AND #{param.endDate}-->
<!--        </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>-->
<!--        GROUP BY-->
<!--            oi.order_type,-->
<!--            oi.order_date,-->
<!--            oi.mealtime_type,-->
<!--            od.goods_dishes_id,-->
<!--            od.goods_dishes_name,-->
<!--            d.unit_name,-->
<!--            od.sales_mode-->
<!--        ORDER BY-->
<!--            od.goods_dishes_id-->
<!--    </select>-->

<!--    <select id="listOrderStatForBus" resultType="net.xnzn.core.order.api.vo.OrderBusStatVO">-->
<!--        SELECT-->
<!--            oi.canteen_id,-->
<!--            ac.canteen_name,-->
<!--            oi.machine_sn,-->
<!--            mm.device_num AS machineNum,-->
<!--            oi.source_type,-->
<!--            mm.device_name AS machineName,-->
<!--            COUNT(1) AS orderTotalNum,-->
<!--            SUM(IF((oi.order_refund_state = 2 OR oi.order_refund_state = 3), 1, 0)) AS orderRefundTotalNum,-->
<!--            SUM(IF((oi.order_refund_state = 1 OR oi.order_refund_state = 3), 1, 0)) AS orderValidTotalNum,-->
<!--            SUM(IF((oi.order_refund_state = 1 OR oi.order_refund_state = 3), oi.real_amount - oi.refund_amount, 0)) AS orderValidTotalAmount-->
<!--        FROM-->
<!--            report_order_info oi-->
<!--            LEFT JOIN device_info mm ON oi.machine_sn = mm.device_sn-->
<!--            LEFT JOIN cust_info ci ON oi.cust_id = ci.cust_id-->
<!--            LEFT JOIN alloc_canteen ac ON ac.canteen_id = oi.canteen_id-->
<!--            LEFT JOIN alloc_area ar ON ac.area_id = ar.area_id-->
<!--            WHERE oi.order_type = 8-->
<!--        <if test="param.startDate != null and param.endDate != null">-->
<!--            AND oi.order_date BETWEEN #{param.startDate} AND #{param.endDate}-->
<!--        </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.machineSnList != null and param.machineSnList.size() > 0">-->
<!--            AND oi.machine_sn in-->
<!--            <foreach collection="param.machineSnList" item="item" open="(" close=")" separator=",">-->
<!--                    #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.psnTypeList != null and param.psnTypeList.size() > 0">-->
<!--            AND ci.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 ci.org_id in-->
<!--            <foreach collection="param.orgIdList" item="item" open="(" close=")" separator=",">-->
<!--                    #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--        <if test="param.searchText != null and param.searchText != ''">-->
<!--            AND (ci.cust_name like #{param.searchText}-->
<!--            OR ci.cust_num like #{param.searchText}-->
<!--            OR ci.mobile like #{param.searchText})-->
<!--        </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 oi.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 (oi.canteen_id = it1.data_id)-->
<!--            )-->
<!--            OR 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 (oi.stall_id = it1.data_id)-->
<!--            )-->
<!--            )-->
<!--        </if>-->
<!--        <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--            and EXISTS (-->
<!--            SELECT null-->
<!--            FROM mgr_role_area 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 ar.area_id = it1.data_id-->
<!--            )-->
<!--        </if>-->

<!--        GROUP BY-->
<!--            oi.canteen_id,-->
<!--            ac.canteen_name,-->
<!--            oi.machine_sn,-->
<!--            mm.device_num,-->
<!--            oi.source_type,-->
<!--            mm.device_name-->
<!--    </select>-->

<!--    <select id="getBookStat" resultType="net.xnzn.core.order.mobile.vo.OrderBookStatMobileVO">-->
<!--        SELECT-->
<!--            COUNT(DISTINCT mac_order_id) AS bookTotalTimes,-->
<!--            COUNT(DISTINCT IF(o.order_type = 9, oi.mac_order_id, NULL)) AS book3DayTimes,-->
<!--            COUNT(DISTINCT IF(o.order_type = 10, oi.mac_order_id, NULL)) AS book7DayTimes,-->
<!--            COUNT(DISTINCT IF(o.order_type = 3, oi.mac_order_id, NULL)) AS bookFreeTimes-->
<!--        FROM report_order_info o-->
<!--                 LEFT JOIN order_info oi ON o.order_id = oi.order_id-->
<!--        WHERE-->
<!--            o.cust_id = #{custId}-->
<!--          AND o.order_type IN (3,9,10)-->
<!--          and o.pay_time between #{startTime} and #{endTime}-->
<!--    </select>-->

<!--    <select id="getBookRefundStat" resultType="net.xnzn.core.order.mobile.vo.OrderBookRefundStatMobileVO">-->
<!--        SELECT-->
<!--            COUNT(DISTINCT orf.order_refund_id) AS refundTotalNum,-->
<!--            SUM(IF(orf.check_state = 1, 1, 0)) AS refundWaitNum,-->
<!--            SUM(IF(orf.check_state = 2, 1, 0)) AS refundPassNum,-->
<!--            SUM(IF(orf.check_state = 3, 1, 0)) AS refundRefuseNum-->
<!--        FROM report_order_info oi-->
<!--                 JOIN order_refund orf ON oi.order_id = orf.order_id-->
<!--        WHERE-->
<!--            oi.cust_id = #{custId}-->
<!--          AND oi.order_type IN (3,9,10)-->
<!--            and oi.pay_time between #{startTime} and #{endTime}-->
<!--    </select>-->

<!--    <select id="getOrderTime" resultType="map">-->
<!--        SELECT-->
<!--            MIN(order_time) AS minOrdTime,-->
<!--            MAX(order_time) AS maxOrdTime,-->
<!--            MIN(order_date) as minOrderDate,-->
<!--            MAX(order_date) as maxOrderDate-->
<!--        FROM-->
<!--            report_order_info-->
<!--        where pay_time between #{startTime} and #{endTime}-->
<!--    </select>-->


<!--    <select id="getTotalConsumeDayNum" resultType="net.xnzn.core.report.statistics.order.summary.param.ReportMealtimeTypeCustNumDTO">-->
<!--        <if test="param.ifTotal == 1">-->
<!--            select ifnull(sum(t.cust_num), 0) cust_num-->
<!--            from-->
<!--            (-->
<!--        </if>-->
<!--        SELECT-->
<!--            o.cust_id,-->
<!--            co.org_full_name,-->
<!--            count(DISTINCT DATE_FORMAT(o.pay_time,'%Y-%m-%d')) cust_num-->
<!--            FROM-->
<!--            report_order_info o-->
<!--            left join cust_org co on co.org_id = o.org_id-->
<!--            <if test="(param.areaIdList != null and param.areaIdList.size() > 0) or-->
<!--                    ('2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString())">-->
<!--               LEFT JOIN alloc_canteen c ON c.canteen_id = o.canteen_id-->
<!--            </if>-->
<!--            <where>-->
<!--                <if test="param.custIdList != null and param.custIdList.size() > 0">-->
<!--                    and o.cust_id in-->
<!--                    <foreach collection="param.custIdList" item="custId" separator="," open="(" close=")">-->
<!--                        #{custId}-->
<!--                    </foreach>-->
<!--                </if>-->
<!--                <if test="param.orgFullNameList != null and param.orgFullNameList.size() > 0">-->
<!--                    and co.org_full_name in-->
<!--                    <foreach collection="param.orgFullNameList" item="orgFullName" separator="," open="(" close=")">-->
<!--                        #{orgFullName}-->
<!--                    </foreach>-->
<!--                </if>-->
<!--                <if test="param.startDate != null">-->
<!--                    <![CDATA[AND o.pay_time >= concat(#{param.startDate},' 00:00:00')]]>-->
<!--                </if>-->
<!--                <if test="param.endDate != null">-->
<!--                    <![CDATA[AND o.pay_time <= concat(#{param.endDate},' 23:59:59.999999999')]]>-->
<!--                </if>-->
<!--                <if test="param.canteenStallIds != null and param.canteenStallIds.size() > 0">-->
<!--                    AND (o.canteen_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    OR o.stall_id IN-->
<!--                    <foreach collection="param.canteenStallIds" item="canteenStallId" separator="," open="(" close=")">-->
<!--                        #{canteenStallId}-->
<!--                    </foreach>-->
<!--                    )-->
<!--                </if>-->
<!--                <if test="param.areaIdList != null and param.areaIdList.size() > 0">-->
<!--                    AND c.area_id in-->
<!--                    <foreach collection="param.areaIdList" item="item" open="(" close=")" separator=",">-->
<!--                        #{item}-->
<!--                    </foreach>-->
<!--                </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 o.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 (o.canteen_id = it1.data_id)-->
<!--                    )-->
<!--                    OR 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 (o.stall_id = it1.data_id)-->
<!--                    )-->
<!--                    )-->
<!--                </if>-->
<!--                <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--                    and EXISTS (-->
<!--                    SELECT null-->
<!--                    FROM mgr_role_area 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 c.area_id = it1.data_id-->
<!--                    )-->
<!--                </if>-->
<!--            </where>-->
<!--                GROUP BY-->
<!--                o.cust_id,-->
<!--                co.org_full_name-->
<!--        <if test="param.ifTotal == 1">-->
<!--            ) t-->
<!--        </if>-->
<!--    </select>-->

<!--    <select id="listRemoteDetailSummary"-->
<!--            resultType="net.xnzn.core.report.statistics.order.basic.vo.ReportRemoteDetailVO">-->
<!--        SELECT-->
<!--            a.order_id,-->
<!--            a.cust_id,-->
<!--            ci.cust_num,-->
<!--            ci.cust_name,-->
<!--            ci.mobile,-->
<!--            co.org_name,-->
<!--            co.org_full_name,-->
<!--            a.payable_amount,-->
<!--            a.real_amount,-->
<!--            a.pay_time,-->
<!--            ac.area_id,-->
<!--            ar.area_name,-->
<!--            p.dining_place_id,-->
<!--            ap.area_name AS work_area_name-->
<!--        FROM-->
<!--            report_order_info a-->
<!--                LEFT JOIN report_order_info_snapshot ros ON ros.order_id = a.order_id-->
<!--                LEFT JOIN alloc_canteen ac ON ac.canteen_id = a.canteen_id-->
<!--                LEFT JOIN cust_info ci ON ci.cust_id = a.cust_id-->
<!--                LEFT JOIN cust_org co ON co.org_id = ros.org_id-->
<!--                JOIN cust_dining_place p ON p.cust_id = ci.cust_id-->
<!--                AND p.type = 'area'-->
<!--                LEFT JOIN alloc_area ar ON ar.area_id = ac.area_id-->
<!--                LEFT JOIN alloc_area ap ON ap.area_id = p.dining_place_id-->
<!--        WHERE-->
<!--            ac.area_id != p.dining_place_id-->
<!--        <if test="param.startDate != null">-->
<!--            <![CDATA[AND a.pay_time >= concat(#{param.startDate},' 00:00:00')]]>-->
<!--        </if>-->
<!--        <if test="param.endDate != null">-->
<!--            <![CDATA[AND a.pay_time <= concat(#{param.endDate},' 23:59:59.999999999')]]>-->
<!--        </if>-->
<!--        <if test="param.workAreaId != null">-->
<!--            and p.dining_place_id = #{param.workAreaId}-->
<!--        </if>-->
<!--        <if test="param.eatAreaId != null">-->
<!--            and ac.area_id = #{param.eatAreaId}-->
<!--        </if>-->
<!--        <if test="param.keyword != null and param.keyword != ''">-->
<!--            AND (-->
<!--            ci.cust_name = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--            OR ci.cust_name_like LIKE CONCAT('%',#{param.keyword,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')-->
<!--            OR ci.cust_num = #{param.keyword}-->
<!--            OR ci.mobile = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--            OR ci.mobile_suffix = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--            )-->
<!--        </if>-->
<!--        <if test="param.orgIds != null and param.orgIds.size() > 0">-->
<!--            and a.org_id in-->
<!--            <foreach collection="param.orgIds" item="orgId" separator="," open="("-->
<!--                     close=")">-->
<!--                #{orgId}-->
<!--            </foreach>-->
<!--        </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 a.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 (a.canteen_id = it1.data_id)-->
<!--            )-->
<!--            OR 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 (a.stall_id = it1.data_id)-->
<!--            )-->
<!--            )-->
<!--        </if>-->
<!--        <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--            and EXISTS (-->
<!--            SELECT null-->
<!--            FROM mgr_role_area 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 ar.area_id = it1.data_id-->
<!--            )-->
<!--        </if>-->
<!--    </select>-->

<!--    <select id="getRemoteDetailTotal"-->
<!--            resultType="net.xnzn.core.report.statistics.order.basic.vo.ReportRemoteDetailVO">-->
<!--        SELECT-->
<!--            sum(a.payable_amount) payable_amount,-->
<!--            sum(a.real_amount) real_amount-->
<!--        FROM-->
<!--        report_order_info a-->
<!--        LEFT JOIN report_order_info_snapshot ros ON ros.order_id = a.order_id-->
<!--        LEFT JOIN alloc_canteen ac ON ac.canteen_id = a.canteen_id-->
<!--        LEFT JOIN cust_info ci ON ci.cust_id = a.cust_id-->
<!--        LEFT JOIN cust_org co ON co.org_id = ros.org_id-->
<!--        JOIN cust_dining_place p ON p.cust_id = ci.cust_id-->
<!--        AND p.type = 'area'-->
<!--        LEFT JOIN alloc_area ar ON ar.area_id = ac.area_id-->
<!--        LEFT JOIN alloc_area ap ON ap.area_id = p.dining_place_id-->
<!--        WHERE-->
<!--        ac.area_id != p.dining_place_id-->
<!--        <if test="param.startDate != null">-->
<!--            <![CDATA[AND a.pay_time >= concat(#{param.startDate},' 00:00:00')]]>-->
<!--        </if>-->
<!--        <if test="param.endDate != null">-->
<!--            <![CDATA[AND a.pay_time <= concat(#{param.endDate},' 23:59:59.999999999')]]>-->
<!--        </if>-->
<!--        <if test="param.workAreaId != null">-->
<!--            and p.dining_place_id = #{param.workAreaId}-->
<!--        </if>-->
<!--        <if test="param.eatAreaId != null">-->
<!--            and ac.area_id = #{param.eatAreaId}-->
<!--        </if>-->
<!--        <if test="param.keyword != null and param.keyword != ''">-->
<!--            AND (-->
<!--            ci.cust_name = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--            OR ci.cust_name_like LIKE CONCAT('%',#{param.keyword,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')-->
<!--            OR ci.cust_num = #{param.keyword}-->
<!--            OR ci.mobile = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--            OR ci.mobile_suffix = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}-->
<!--            )-->
<!--        </if>-->
<!--        <if test="param.orgIds != null and param.orgIds.size() > 0">-->
<!--            and a.org_id in-->
<!--            <foreach collection="param.orgIds" item="orgId" separator="," open="("-->
<!--                     close=")">-->
<!--                #{orgId}-->
<!--            </foreach>-->
<!--        </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 a.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 (a.canteen_id = it1.data_id)-->
<!--            )-->
<!--            OR 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 (a.stall_id = it1.data_id)-->
<!--            )-->
<!--            )-->
<!--        </if>-->
<!--        <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--            and EXISTS (-->
<!--            SELECT null-->
<!--            FROM mgr_role_area 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 ar.area_id = it1.data_id-->
<!--            )-->
<!--        </if>-->
<!--    </select>-->

<!--    <select id="listRemoteSummary"-->
<!--            resultType="net.xnzn.core.report.statistics.order.basic.vo.ReportRemoteSumVO">-->
<!--        SELECT-->
<!--               co.org_full_name,-->
<!--               sum(a.real_amount) orderAmount,-->
<!--               ar.area_name,-->
<!--               ap.area_name AS work_area_name,-->
<!--            count(distinct a.cust_id) as cust_num-->
<!--        FROM report_order_info a-->
<!--                 LEFT JOIN report_order_info_snapshot ros ON ros.order_id = a.order_id-->
<!--                 LEFT JOIN alloc_canteen ac ON ac.canteen_id = a.canteen_id-->
<!--                 LEFT JOIN cust_info ci ON ci.cust_id = a.cust_id-->
<!--                 LEFT JOIN cust_org co ON co.org_id = ros.org_id-->
<!--                 JOIN cust_dining_place p ON p.cust_id = ci.cust_id-->
<!--            AND p.type = 'area'-->
<!--                 LEFT JOIN alloc_area ar ON ar.area_id = ac.area_id-->
<!--                 LEFT JOIN alloc_area ap ON ap.area_id = p.dining_place_id-->
<!--        WHERE ac.area_id != p.dining_place_id-->
<!--        <if test="param.startDate != null">-->
<!--            <![CDATA[-->
<!--            AND a.pay_time >= concat(#{param.startDate}, ' 00:00:00')-->
<!--            ]]>-->
<!--        </if>-->
<!--        <if test="param.endDate != null">-->
<!--            <![CDATA[-->
<!--            AND a.pay_time <= concat(#{param.endDate}, ' 23:59:59.999999999')-->
<!--            ]]>-->
<!--        </if>-->
<!--        <if test="param.workAreaId != null">-->
<!--            and p.dining_place_id = #{param.workAreaId}-->
<!--        </if>-->
<!--        <if test="param.eatAreaId != null">-->
<!--            and ac.area_id = #{param.eatAreaId}-->
<!--        </if>-->

<!--        <if test="param.orgIds != null and param.orgIds.size() > 0">-->
<!--            and a.org_id in-->
<!--            <foreach collection="param.orgIds" item="orgId" separator="," open="("-->
<!--                     close=")">-->
<!--                #{orgId}-->
<!--            </foreach>-->
<!--        </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 a.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 (a.canteen_id = it1.data_id))-->
<!--                    OR 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 (a.stall_id = it1.data_id))-->
<!--                )-->
<!--        </if>-->
<!--        <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--            and EXISTS (-->
<!--            SELECT null-->
<!--            FROM mgr_role_area 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 ar.area_id = it1.data_id-->
<!--            )-->
<!--        </if>-->
<!--        group by ar.area_name,co.org_full_name,ap.area_name-->
<!--    </select>-->

<!--    <select id="listRemoteSummaryTotal"-->
<!--            resultType="net.xnzn.core.report.statistics.order.basic.vo.ReportRemoteSumVO">-->
<!--        SELECT-->
<!--               sum(a.real_amount)           orderAmount,-->
<!--               count(distinct a.cust_id) as cust_num-->
<!--        FROM report_order_info a-->
<!--                 LEFT JOIN report_order_info_snapshot ros ON ros.order_id = a.order_id-->
<!--                 LEFT JOIN alloc_canteen ac ON ac.canteen_id = a.canteen_id-->
<!--                 LEFT JOIN cust_info ci ON ci.cust_id = a.cust_id-->
<!--                 LEFT JOIN cust_org co ON co.org_id = ros.org_id-->
<!--                 JOIN cust_dining_place p ON p.cust_id = ci.cust_id-->
<!--            AND p.type = 'area'-->
<!--                 LEFT JOIN alloc_area ar ON ar.area_id = ac.area_id-->
<!--                 LEFT JOIN alloc_area ap ON ap.area_id = p.dining_place_id-->
<!--        WHERE ac.area_id != p.dining_place_id-->
<!--        <if test="param.startDate != null">-->
<!--            <![CDATA[-->
<!--            AND a.pay_time >= concat(#{param.startDate}, ' 00:00:00')-->
<!--            ]]>-->
<!--        </if>-->
<!--        <if test="param.endDate != null">-->
<!--            <![CDATA[-->
<!--            AND a.pay_time <= concat(#{param.endDate}, ' 23:59:59.999999999')-->
<!--            ]]>-->
<!--        </if>-->
<!--        <if test="param.workAreaId != null">-->
<!--            and p.dining_place_id = #{param.workAreaId}-->
<!--        </if>-->
<!--        <if test="param.eatAreaId != null">-->
<!--            and ac.area_id = #{param.eatAreaId}-->
<!--        </if>-->

<!--        <if test="param.orgIds != null and param.orgIds.size() > 0">-->
<!--            and a.org_id in-->
<!--            <foreach collection="param.orgIds" item="orgId" separator="," open="("-->
<!--                     close=")">-->
<!--                #{orgId}-->
<!--            </foreach>-->
<!--        </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 a.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 (a.canteen_id = it1.data_id))-->
<!--                    OR 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 (a.stall_id = it1.data_id))-->
<!--                )-->
<!--        </if>-->
<!--        <if test="'2'.toString() == authPO.roleType.toString() or '1'.toString() == authPO.roleType.toString()">-->
<!--            and EXISTS (SELECT null-->
<!--                        FROM mgr_role_area 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 ar.area_id = it1.data_id)-->
<!--        </if>-->

<!--    </select>-->
</mapper>
