| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216 | <?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.zhongzheng.modules.top.goods.mapper.TopOldOrderMapper">    <resultMap type="com.zhongzheng.modules.top.goods.domain.TopOldOrder" id="TopOrderResult">        <result property="orderId" column="order_id"/>        <result property="orderSn" column="order_sn"/>        <result property="userId" column="user_id"/>        <result property="orderPrice" column="order_price"/>        <result property="orderGeneral" column="order_general"/>        <result property="orderStatus" column="order_status"/>        <result property="createTime" column="create_time"/>        <result property="updateTime" column="update_time"/>        <result property="payTime" column="pay_time"/>        <result property="payType" column="pay_type"/>        <result property="transid" column="transid"/>        <result property="cancelTime" column="cancel_time"/>        <result property="finishTime" column="finish_time"/>        <result property="orderType" column="order_type"/>        <result property="payPrice" column="pay_price"/>        <result property="orderFrom" column="order_from"/>        <result property="createUsername" column="create_username"/>        <result property="status" column="status"/>        <result property="createSysUserId" column="create_sys_user_id"/>        <result property="inputOrderSn" column="input_order_sn"/>        <result property="payStatus" column="pay_status"/>        <result property="checkStatus" column="check_status"/>        <result property="refundStatus" column="refund_status"/>        <result property="creditStatus" column="credit_status"/>        <result property="invoiceStatus" column="invoice_status"/>        <result property="orderProfit" column="order_profit"/>        <result property="orderCost" column="order_cost"/>        <result property="orderRefund" column="order_refund"/>        <result property="orderRefunded" column="order_refunded"/>        <result property="orderUncollected" column="order_uncollected"/>        <result property="orderReceived" column="order_received"/>        <result property="remark" column="remark"/>        <result property="costJson" column="cost_json"/>        <result property="buyTime" column="buy_time"/>    </resultMap>    <select id="queryList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"            resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">        SELECT        vto.*        FROM        <if test="businessFullName != null and businessFullName != '' and ((userCard == null or userCard == '') and (userName == null or userName == ''))">            ( SELECT DISTINCT order_sn            FROM `v_top_order_business` where INSTR( business_full_name,#{businessFullName} ) > 0            ) a            LEFT JOIN v_top_order vto ON a.order_sn = vto.order_sn        </if>        <if test="((userCard != null and userCard != '') or (userName != null and userName != '')) and (businessFullName == null or businessFullName == '')">            ( SELECT DISTINCT order_sn            FROM `v_top_order_card` where 1=1            <if test="userCard != null and userCard != ''">                AND user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}            </if>            <if test="userName != null and userName != ''">                AND user_name LIKE CONCAT( '%', #{userName}, '%' )            </if>            ) a            LEFT JOIN v_top_order vto ON a.order_sn = vto.order_sn        </if>        <if test="((userCard != null and userCard != '') or (userName != null and userName != '')) and businessFullName != null and businessFullName != ''">            ( SELECT DISTINCT order_sn            FROM (            SELECT            DISTINCT order_sn            FROM            ( SELECT order_sn FROM v_top_order_business WHERE INSTR( business_full_name,#{businessFullName} ) > 0 UNION            ALL SELECT order_sn FROM v_top_order_card            WHERE 1 = 1            <if test="userCard != null and userCard != ''">                AND user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}            </if>            <if test="userName != null and userName != ''">                AND user_name LIKE CONCAT( '%', #{userName}, '%' )            </if>            ) b            ) m            ) a            LEFT JOIN v_top_order vto ON a.order_sn = vto.order_sn        </if>        <if test="(userCard == null or userCard == '') and (businessFullName == null or businessFullName == '') and (userName == null or userName == '')">            v_top_order vto        </if>        WHERE vto.`status` in (0,1)        <if test="operationType != null">            AND vto.operation_type = #{operationType}        </if>        <if test="checkStatus != null and checkStatus.size()!=0 ">            AND vto.check_status in            <foreach collection="checkStatus" item="item" index="index" open="(" close=")" separator=",">                #{item}            </foreach>        </if>        <if test="refundStatus != null">            AND vto.refund_status = #{refundStatus}        </if>        <if test="refundStatusList != null and refundStatusList.size()!=0 ">            AND vto.refund_status in            <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">                #{item}            </foreach>        </if>        <if test="creditStatus != null and creditStatus == 0">            AND vto.order_received <![CDATA[ < ]]> vto.pay_price        </if>        <if test="creditStatus != null and creditStatus == 1">            AND vto.pay_price = vto.order_received        </if>        <if test="finishStatus != null">            AND vto.finish_status = #{finishStatus}        </if>        <if test="invoiceStatus != null and invoiceStatus != ''">            AND vto.invoice_status = #{invoiceStatus}        </if>        <if test="orderOrg != null and orderOrg != ''">            AND vto.order_org LIKE CONCAT( '%', #{orderOrg}, '%' )        </if>        <if test="startTime != null and startTime != ''">            AND vto.buy_time <![CDATA[ >= ]]> #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND vto.buy_time <![CDATA[ <= ]]> #{endTime}        </if>        <if test="checkStartTime != null and checkStartTime != ''">            AND vto.check_time <![CDATA[ >= ]]> #{checkStartTime}        </if>        <if test="checkEndTime != null and checkEndTime != ''">            AND vto.check_time <![CDATA[ <= ]]> #{checkEndTime}        </if>        <if test="orderSn != null and orderSn != ''">            AND vto.order_sn = #{orderSn}        </if>        <if test="tenantId != null and tenantId != ''">            AND vto.tenant_id = #{tenantId}        </if>        <if test="orderSnList != null and orderSnList.size()!=0 ">            AND vto.order_sn in            <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">                #{item}            </foreach>        </if>        <if test="keyword != null and keyword != ''">            AND (            vto.order_sn LIKE CONCAT( '%', #{keyword}, '%' )            OR vto.create_no LIKE CONCAT( '%', #{keyword}, '%' )            OR vto.purchase_org LIKE CONCAT( '%', #{keyword}, '%' ))        </if>        order by vto.create_time DESC    </select>    <select id="queryList_COUNT" resultType="Long">        SELECT        ((SELECT        COUNT( DISTINCT ot.order_sn ) AS num        FROM        top_old_order ot        LEFT JOIN top_old_order_goods otg ON ot.order_sn = otg.order_sn        WHERE        1 = 1 AND ot.`status` = 1        <if test="businessFullName != null and businessFullName != ''">            AND INSTR( otg.business_full_name , #{businessFullName} ) > 0        </if>        <if test="userCard != null and userCard != ''">            AND otg.user_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}        </if>        <if test="operationType != null">            AND ot.operation_type = #{operationType}        </if>        <if test="userName != null and userName != ''">            AND otg.user_name LIKE CONCAT( '%', #{userName}, '%' )        </if>        <if test="checkStatus != null and checkStatus.size()!=0 ">            AND ot.check_status in            <foreach collection="checkStatus" item="item" index="index" open="(" close=")" separator=",">                #{item}            </foreach>        </if>        <if test="refundStatus != null">            AND ot.refund_status = #{refundStatus}        </if>        <if test="refundStatusList != null and refundStatusList.size()!=0 ">            AND ot.refund_status in            <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">                #{item}            </foreach>        </if>        <if test="orderOrg != null and orderOrg != ''">            AND ot.order_org LIKE CONCAT( '%', #{orderOrg}, '%' )        </if>        <if test="checkStartTime != null and checkStartTime != ''">            AND ot.check_time <![CDATA[ >= ]]> #{checkStartTime}        </if>        <if test="checkEndTime != null and checkEndTime != ''">            AND ot.check_time <![CDATA[ <= ]]> #{checkEndTime}        </if>        <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">            AND ot.order_received <![CDATA[ < ]]> ot.pay_price        </if>        <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">            AND ot.pay_price = ot.order_received        </if>        <if test="invoiceStatus != null and invoiceStatus != ''">            AND ot.invoice_status = #{invoiceStatus}        </if>        <if test="startTime != null and startTime != ''">            AND ot.create_time <![CDATA[ >= ]]> #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND ot.create_time <![CDATA[ <= ]]> #{endTime}        </if>        <if test="orderSn != null and orderSn != ''">            AND ot.order_sn = #{orderSn}        </if>        <if test="finishStatus != null">            AND ot.finish_status = #{finishStatus}        </if>        <if test="tenantId != null and tenantId != ''">            AND ot.tenant_id = #{tenantId}        </if>        <if test="orderSnList != null and orderSnList.size()!=0 ">            AND ot.order_sn in            <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">                #{item}            </foreach>        </if>        <if test="keyword != null and keyword != ''">            AND (            ot.order_sn LIKE CONCAT( '%', #{keyword}, '%' )            OR ot.create_no LIKE CONCAT( '%', #{keyword}, '%' )            OR ot.purchase_org LIKE CONCAT( '%', #{keyword}, '%' ))        </if>        ) + (SELECT        COUNT( DISTINCT o.order_sn ) AS num        FROM        `order` o        LEFT JOIN order_goods og ON o.order_sn = og.order_sn        LEFT JOIN `user` u ON o.user_id = u.user_id        WHERE        1 = 1 AND o.`status` IN (0,1)        AND ( `o`.`order_type` != 4 )        AND (        isnull( `o`.`input_order_sn` )        OR (        NOT (        `o`.`input_order_sn` IN ( SELECT `top_old_order`.`input_order_sn` FROM `top_old_order` ))))        <if test="businessFullName != null and businessFullName != ''">            AND (            SELECT            COUNT(g.goods_id)            FROM            goods g            LEFT JOIN course_education_type cet ON g.education_type_id = cet.id            LEFT JOIN course_project_type cpt ON g.project_id = cpt.id            LEFT JOIN course_business cb ON g.business_id = cb.id            WHERE            og.goods_id = g.goods_id            AND            INSTR( CONCAT('学校业务', cet.education_name, cb.business_name, cpt.project_name),#{businessFullName}) > 0) > 0        </if>        <if test="userCard != null and userCard != ''">            AND u.id_card = #{userCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}        </if>        <if test="userName != null and userName != ''">            AND u.realname LIKE CONCAT( '%', #{userName}, '%' )        </if>        <if test="checkStatus != null and checkStatus.size()!=0 ">            AND o.check_status in            <foreach collection="checkStatus" item="item" index="index" open="(" close=")" separator=",">                #{item}            </foreach>        </if>        <if test="operationType != null">            AND o.operation_type = #{operationType}        </if>        <if test="refundStatus != null">            AND o.order_refund_status = #{refundStatus}        </if>        <if test="refundStatusList != null and refundStatusList.size()!=0 ">            AND o.order_refund_status in            <foreach collection="refundStatusList" item="item" index="index" open="(" close=")" separator=",">                #{item}            </foreach>        </if>        <if test="orderOrg != null and orderOrg != ''">            AND 'C端云学堂' LIKE CONCAT( '%', #{orderOrg}, '%' )        </if>        <if test="checkStartTime != null and checkStartTime != ''">            AND o.pay_time <![CDATA[ >= ]]> #{checkStartTime}        </if>        <if test="checkEndTime != null and checkEndTime != ''">            AND o.pay_time <![CDATA[ <= ]]> #{checkEndTime}        </if>        <if test="creditStatus != null and creditStatus != '' and creditStatus == 0">            AND o.order_received <![CDATA[ < ]]> o.pay_price        </if>        <if test="creditStatus != null and creditStatus != '' and creditStatus == 1">            AND o.pay_price = o.order_received        </if>        <if test="invoiceStatus != null and invoiceStatus != ''">            AND o.invoice_status = #{invoiceStatus}        </if>        <if test="finishStatus != null">            AND o.finish_status = #{finishStatus}        </if>        <if test="tenantId != null and tenantId != ''">            AND o.tenant_id = #{tenantId}        </if>        <if test="startTime != null and startTime != ''">            AND o.create_time <![CDATA[ >= ]]> #{startTime}        </if>        <if test="startTime == null">            AND o.create_time <![CDATA[ > ]]> #{filtrationTime}        </if>        <if test="endTime != null and endTime != ''">            AND o.create_time <![CDATA[ <= ]]> #{endTime}        </if>        <if test="orderSn != null and orderSn != ''">            AND o.order_sn = #{orderSn}        </if>        <if test="orderSnList != null and orderSnList.size()!=0 ">            AND o.order_sn in            <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">                #{item}            </foreach>        </if>        <if test="keyword != null and keyword != ''">            AND o.order_sn LIKE CONCAT( '%', #{keyword}, '%' )        </if>        )) as number    </select>    <select id="queryById" parameterType="java.lang.String"            resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">        SELECT *        FROM v_top_order        WHERE order_sn = #{orderSn}    </select>    <select id="queryBusinessBySn" parameterType="java.lang.String" resultType="java.lang.String">        SELECT DISTINCT business_name        FROM v_top_order_business        WHERE order_sn = #{orderSn}    </select>    <select id="queryBusinessFullNameBySn" parameterType="java.lang.String" resultType="java.lang.String">        SELECT DISTINCT business_full_name        FROM top_old_order_goods        WHERE order_sn = #{orderSn}          AND `status` = 1          AND check_status = 1    </select>    <select id="queryByOrderSns" parameterType="java.lang.String"            resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">        SELECT * FROM v_top_order WHERE 1 =1        <if test="orderSnList != null and orderSnList.size()!=0 ">            AND order_sn in            <foreach collection="orderSnList" item="item" index="index" open="(" close=")" separator=",">                #{item}            </foreach>        </if>    </select>    <select id="queryReceiveUnSum" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"            resultType="long">        SELECT        IFNULL(sum(        too.order_uncollected),0)        FROM        top_old_order too        LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id        LEFT JOIN top_order_rec_note rn ON too.tenant_id = rn.tenant_id and too.order_sn = rn.order_sn        where too.check_status=1 AND too.order_uncollected >0        <if test="tenantId != null and tenantId != ''">            AND too.tenant_id = #{tenantId}        </if>        <if test="startTime != null and startTime != ''">            AND too.buy_time <![CDATA[ >= ]]> #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND too.buy_time <![CDATA[ <= ]]> #{endTime}        </if>        <if test="keyNo != null and keyNo != ''">            AND (st.tenant_name like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))        </if>        <if test="creditStatus != null and creditStatus != ''">            AND too.credit_status = #{creditStatus}        </if>        <if test="orderSn != null and orderSn != ''">            AND too.order_sn = #{orderSn}        </if>        <if test="badBill != null and badBill == 1 and badBillList != null and badBillList.size()!=0 ">            AND            <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">                (too.check_time BETWEEN #{item.startTime} and #{item.endTime})            </foreach>        </if>        <if test="badBill != null and badBill == 2 and badBillList != null and badBillList.size()!=0 ">            AND            <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">                (too.check_time NOT BETWEEN #{item.startTime} and #{item.endTime})            </foreach>        </if>        ORDER BY too.buy_time DESC    </select>    <select id="queryReceiveList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"            resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">        SELECT        too.*,        st.tenant_name,        rn.id as note_id,        rn.note_type,        rn.day_time,        rn.week_time,        rn.month_time,        rn.last_time,        rn.exceed_type        FROM        top_old_order too        LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id        LEFT JOIN top_order_rec_note rn ON too.tenant_id = rn.tenant_id and too.order_sn = rn.order_sn        where too.check_status=1 AND too.order_uncollected >0        <if test="operationType != null and operationType != ''">            AND too.operation_type = #{operationType}        </if>        <if test="tenantId != null and tenantId != ''">            AND too.tenant_id = #{tenantId}        </if>        <if test="startTime != null and startTime != ''">            AND too.buy_time <![CDATA[ >= ]]> #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND too.buy_time <![CDATA[ <= ]]> #{endTime}        </if>        <if test="keyNo != null and keyNo != ''">            AND (st.tenant_name like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))        </if>        <if test="creditStatus != null and creditStatus != ''">            AND too.credit_status = #{creditStatus}        </if>        <if test="orderSn != null and orderSn != ''">            AND too.order_sn = #{orderSn}        </if>        <if test="badBill != null and badBill == 1 and badBillList != null and badBillList.size()!=0 ">            AND            <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">                (too.check_time BETWEEN #{item.startTime} and #{item.endTime})            </foreach>        </if>        <if test="badBill != null and badBill == 2 and badBillList != null and badBillList.size()!=0 ">            AND            <foreach collection="badBillList" item="item" index="index" open="(" close=")" separator="or">                (too.check_time NOT BETWEEN #{item.startTime} and #{item.endTime})            </foreach>        </if>        ORDER BY too.buy_time DESC    </select>    <select id="queryDivSellerList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"            resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">        SELECT        too.*,        st.tenant_name,        r.role_name,        cl.check_status as divide_check_status        FROM        v_top_order too        LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id        LEFT JOIN top_old_order_check_log cl ON too.order_sn = cl.order_sn        AND cl.check_sign = 1        AND ( too.divide_model + 1 ) = cl.check_from        LEFT JOIN top_sys_role r ON cl.role_id = r.role_id        where 1=1 AND too.divide_model = 2        <if test="startTime != null and startTime != ''">            AND too.create_time <![CDATA[ >= ]]> #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND too.create_time <![CDATA[ <= ]]> #{endTime}        </if>        <if test="keyNo != null and keyNo != ''">            AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))        </if>        <if test="divideStatusList != null and divideStatusList.size()!=0 ">            AND too.divide_status in            <foreach collection="divideStatusList" item="item" index="index" open="(" close=")" separator=",">                #{item}            </foreach>        </if>        <if test="divideStatus != null and divideStatus != ''">            AND too.divide_status = #{divideStatus}        </if>        <if test="roleId != null and roleId != ''">            AND cl.role_id = #{roleId}        </if>        ORDER BY too.order_id DESC    </select>    <select id="queryTenantList" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"            resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">        SELECT        too.*,        st.tenant_name,        r.role_name,        cl.check_status as divide_check_status        FROM        top_old_order too        LEFT JOIN sys_tenant st ON too.tenant_id = st.tenant_id        LEFT JOIN top_old_order_check_log cl ON too.order_sn = cl.order_sn        AND cl.check_sign = 1        AND ( too.divide_model + 1 ) = cl.check_from        LEFT JOIN top_sys_role r ON cl.role_id = r.role_id        where 1=1 AND too.divide_model = 1        <if test="startTime != null and startTime != ''">            AND too.create_time <![CDATA[ >= ]]> #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND too.create_time <![CDATA[ <= ]]> #{endTime}        </if>        <if test="keyNo != null and keyNo != ''">            AND (too.tenant_id like concat('%', #{keyNo}, '%') or too.create_no like concat('%', #{keyNo}, '%'))        </if>        <if test="divideStatusList != null and divideStatusList.size()!=0 ">            AND too.divide_status in            <foreach collection="divideStatusList" item="item" index="index" open="(" close=")" separator=",">                #{item}            </foreach>        </if>        <if test="divideStatus != null and divideStatus != ''">            AND too.divide_status = #{divideStatus}        </if>        <if test="tenantId != null and tenantId != ''">            AND too.tenant_id = #{tenantId}        </if>        <if test="roleId != null and roleId != ''">            AND cl.role_id = #{roleId}        </if>        ORDER BY too.order_id DESC    </select>    <select id="tenantMoneyTotal" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"            resultType="BigDecimal">        SELECT IFNULL(SUM(too.divide_company_money), 0)        FROM v_top_order too        WHERE too.divide_model = 1          AND too.divide_status = 5    </select>    <select id="tenantSellerTotal" parameterType="com.zhongzheng.modules.top.goods.bo.TopOldOrderQueryBo"            resultType="BigDecimal">        SELECT IFNULL(SUM(too.divide_seller_money), 0)        FROM v_top_order too        WHERE too.divide_model = 2          AND too.divide_status = 5    </select>    <select id="queryListAll" resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderVo">        SELECT *        FROM v_top_order    </select>    <select id="getOrderBySn" parameterType="java.lang.String"            resultType="com.zhongzheng.modules.top.goods.domain.TopOldOrder">        SELECT *        FROM v_top_order        WHERE order_sn = #{orderSn}    </select>    <select id="logList" parameterType="com.zhongzheng.modules.top.financial.bo.TopOrderLogQueryBo"            resultType="com.zhongzheng.modules.top.financial.vo.TopOrderLogVo">        SELECT *        FROM top_order_log        WHERE order_sn = #{orderSn}    </select>    <select id="getRefundOrder" parameterType="java.lang.String"            resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderRefundVo">        SELECT *        FROM v_top_order_refund        WHERE order_sn = #{orderSn}    </select>    <select id="getRefundOrderByBo" parameterType="com.zhongzheng.modules.top.financial.bo.RefundOrderBo"            resultType="com.zhongzheng.modules.top.goods.vo.TopOldOrderRefundVo">        SELECT * FROM v_top_order_refund WHERE order_sn = #{orderSn} AND status = 1        <if test="periodStatus != null and periodStatus != ''">            AND period_status = #{periodStatus}        </if>    </select>    <select id="getOrderSnByBusiness" parameterType="java.lang.String" resultType="java.lang.String">        SELECT DISTINCT order_sn        FROM v_top_order_business        WHERE INSTR(business_full_name, #{businessName}) > 0    </select>    <select id="getOrderInvoiceList" parameterType="com.zhongzheng.modules.top.goods.vo.TopOldOrderInvoiceVo" resultType="java.lang.String">        SELECT            create_time AS applyUpTime,            `status` AS invoiceStatus,            update_time AS invoiceTime,            oss_pdf_url AS ossPdfUrl,            content        FROM            top_nuo_mplatform_log        WHERE            INSTR(order_no_list,#{orderSn})    </select>    <select id="getMoneyStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"            resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsMoneyVo">        SELECT        *        FROM        (            SELECT                SUM( too.order_received - too.order_refunded ) AS money,                too.old_customer_id AS customer_id,                (                SELECT                tod.purchase_org                FROM                top_old_order tod                WHERE                tod.old_customer_id = too.old_customer_id                AND tod.`status` = 1                AND tod.check_status = 1                LIMIT 1                ) AS customer_name            FROM            top_old_order too            WHERE                too.`status` = 1                AND too.check_status = 1                AND too.old_customer_id IS NOT NULL                <if test="startTime != null and startTime != ''">                    AND too.check_time >= #{startTime}                </if>                <if test="endTime != null and endTime != ''">                    AND too.check_time <= #{endTime}                </if>                <if test="customerId != null and customerId != ''">                    AND too.old_customer_id = #{customerId}                </if>            GROUP BY            too.old_customer_id UNION ALL            SELECT                SUM( o.order_price ) AS money,                o.tenant_id AS customer_id,                ( SELECT tenant_name FROM sys_tenant st WHERE st.tenant_id = o.tenant_id LIMIT 1 ) AS customer_name            FROM            `order` o            WHERE                o.`status` = 1                AND o.order_status = 1                AND (                o.input_order_sn IS NULL                OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0 ) AND o.tenant_id IS NOT NULL                <if test="startTime != null and startTime != ''">                    AND o.create_time >= #{startTime}                </if>                <if test="endTime != null and endTime != ''">                    AND o.create_time <= #{endTime}                </if>                <if test="customerId != null and customerId != ''">                    AND o.tenant_id  = #{customerId}                </if>            GROUP BY            o.tenant_id        ) a        WHERE        1 = 1        ORDER BY        a.money DESC    </select>    <select id="getMoneyStatisticsTotal" parameterType="java.lang.Long"            resultType="java.math.BigDecimal">        SELECT            (            SELECT            SUM( too.order_received - too.order_refunded ) AS money            FROM            top_old_order too            WHERE            too.`status` = 1            AND too.check_status = 1            AND too.old_customer_id IS NOT NULL            <if test="startTime != null and startTime != ''">                AND too.check_time >= #{startTime}            </if>            <if test="endTime != null and endTime != ''">                AND too.check_time <= #{endTime}            </if>            ) + (            SELECT            SUM( o.order_price ) AS money            FROM            `order` o            WHERE            o.`status` = 1            AND o.order_status = 1            AND (            o.input_order_sn IS NULL            OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0 ) AND o.tenant_id IS NOT NULL            <if test="startTime != null and startTime != ''">                AND o.create_time >= #{startTime}            </if>            <if test="endTime != null and endTime != ''">                AND o.create_time <= #{endTime}            </if>            ) money_total    </select>    <select id="getNumStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"            resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsNumVo">        SELECT        *        FROM        (        SELECT        COUNT(too.order_id) AS orderNum,        too.old_customer_id AS customer_id,        (        SELECT        tod.purchase_org        FROM        top_old_order tod        WHERE        tod.old_customer_id = too.old_customer_id        AND tod.`status` = 1        AND tod.check_status = 1        LIMIT 1        ) AS customer_name        FROM        top_old_order too        WHERE        too.`status` = 1        AND too.check_status = 1        AND too.old_customer_id IS NOT NULL        <if test="startTime != null and startTime != ''">            AND too.check_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND too.check_time <= #{endTime}        </if>        <if test="customerId != null and customerId != ''">            AND too.old_customer_id = #{customerId}        </if>        GROUP BY        too.old_customer_id UNION ALL        SELECT        COUNT(o.order_id) AS orderNum,        o.tenant_id AS customer_id,        ( SELECT tenant_name FROM sys_tenant st WHERE st.tenant_id = o.tenant_id LIMIT 1 ) AS customer_name        FROM        `order` o        WHERE        o.`status` = 1        AND o.order_status = 1        AND (        o.input_order_sn IS NULL        OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0 ) AND o.tenant_id IS NOT NULL        <if test="startTime != null and startTime != ''">            AND o.create_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND o.create_time <= #{endTime}        </if>        <if test="customerId != null and customerId != ''">            AND o.tenant_id  = #{customerId}        </if>        GROUP BY        o.tenant_id        ) a        WHERE        1 = 1        ORDER BY        a.orderNum DESC    </select>    <select id="getNumStatisticsTotal" parameterType="java.lang.Long"            resultType="java.lang.Long">        SELECT        (        SELECT        COUNT(too.order_id) AS orderNum        FROM        top_old_order too        WHERE        too.`status` = 1        AND too.check_status = 1        AND too.old_customer_id IS NOT NULL        <if test="startTime != null and startTime != ''">            AND too.check_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND too.check_time <= #{endTime}        </if>        ) + (        SELECT        COUNT(o.order_id) AS orderNum        FROM        `order` o        WHERE        o.`status` = 1        AND o.order_status = 1        AND (        o.input_order_sn IS NULL        OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0 ) AND o.tenant_id IS NOT NULL        <if test="startTime != null and startTime != ''">            AND o.create_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND o.create_time <= #{endTime}        </if>        ) num_total    </select>    <select id="getDetailStatisticsTotal" parameterType="java.lang.Long"            resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailTotalVo">        SELECT        ((        SELECT        SUM( too.order_received - too.order_refunded ) AS money        FROM        top_old_order too        WHERE        too.`status` = 1        AND too.check_status = 1        AND too.old_customer_id IS NOT NULL        <if test="startTime != null and startTime != ''">            AND too.check_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND too.check_time <= #{endTime}        </if>        ) + (        SELECT        SUM( o.order_price ) AS money        FROM        `order` o        WHERE        o.`status` = 1        AND o.order_status = 1        AND (        o.input_order_sn IS NULL        OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0 ) AND o.tenant_id IS NOT NULL        <if test="startTime != null and startTime != ''">            AND o.create_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND o.create_time <= #{endTime}        </if>        )) moneyTotal,        ((        SELECT        COUNT(too.order_id) AS orderNum        FROM        top_old_order too        WHERE        too.`status` = 1        AND too.check_status = 1        AND too.old_customer_id IS NOT NULL        <if test="startTime != null and startTime != ''">            AND too.check_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND too.check_time <= #{endTime}        </if>        ) + (        SELECT        COUNT(o.order_id) AS orderNum        FROM        `order` o        WHERE        o.`status` = 1        AND o.order_status = 1        AND (        o.input_order_sn IS NULL        OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0 ) AND o.tenant_id IS NOT NULL        <if test="startTime != null and startTime != ''">            AND o.create_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND o.create_time <= #{endTime}        </if>        )) orderNumTotal    </select>    <select id="getStatisticsView" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"            resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsTwoVo">        SELECT        COUNT(a.order_id) AS orderNum,        SUM(a.money) AS money,        any_value(a.timeStr) AS orderTime,        <if test="viewSign != null and viewSign == 1">            DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d') AS timeStr        </if>        <if test="viewSign != null and viewSign == 2">            DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U') AS timeStr        </if>        <if test="viewSign != null and viewSign == 3">            DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m') AS timeStr        </if>        FROM (        SELECT        too.order_id as order_id,        too.check_time as timeStr,        too.order_received - too.order_refunded as money        FROM        top_old_order too        WHERE        too.`status` = 1        AND too.check_status = 1        <if test="startTime != null and startTime != ''">            AND too.check_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND too.check_time <= #{endTime}        </if>        <if test="customerId != null and customerId != ''">            AND too.old_customer_id IS NOT NULL            AND too.old_customer_id = #{customerId}        </if>        UNION ALL        SELECT        o.order_id as order_id,        o.create_time as timeStr,        o.order_price as money        FROM        `order` o        WHERE        o.`status` = 1        AND o.order_status = 1        AND (        o.input_order_sn IS NULL        OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0        )        <if test="startTime != null and startTime != ''">            AND o.create_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND o.create_time <= #{endTime}        </if>        <if test="customerId != null and customerId != ''">            AND o.tenant_id = #{customerId}            AND o.tenant_id IS NOT NULL        </if>        ) a WHERE 1=1        <if test="viewSign != null and viewSign == 1">            GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d')        </if>        <if test="viewSign != null and viewSign == 2">            GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U')        </if>        <if test="viewSign != null and viewSign == 3">            GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m')        </if>    </select>    <select  id="getDetailStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"             resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailVo">        SELECT            1 AS orderType,            COUNT(too.order_id) AS orderNum,            SUM( too.order_received - too.order_refunded ) AS money,            too.old_customer_id AS customer_id,            (            SELECT            tod.purchase_org            FROM            top_old_order tod            WHERE            tod.old_customer_id = too.old_customer_id            AND tod.`status` = 1            AND tod.check_status = 1            LIMIT 1            ) AS customer_name        FROM        top_old_order too        WHERE            too.`status` = 1            AND too.check_status = 1            AND too.old_customer_id IS NOT NULL            <if test="startTime != null and startTime != ''">                AND too.check_time >= #{startTime}            </if>            <if test="endTime != null and endTime != ''">                AND too.check_time <= #{endTime}            </if>            <if test="customerId != null and customerId != ''">                AND too.old_customer_id = #{customerId}            </if>            <if test="businessName != null and businessName != ''">                AND (SELECT COUNT(DISTINCT oog.order_sn) FROM top_old_order_goods oog WHERE too.order_sn = oog.order_sn AND INSTR(oog.business_full_name,#{businessName}) ) > 0            </if>            <if test="customerName != null and customerName != ''">                AND too.purchase_org LIKE CONCAT('%',#{customerName},'%')            </if>            GROUP BY            too.old_customer_id UNION ALL        SELECT            2 AS orderType,            COUNT(o.order_id) AS orderNum,            SUM( o.order_price ) AS money,            o.tenant_id AS customer_id,            ( SELECT tenant_name FROM sys_tenant st WHERE st.tenant_id = o.tenant_id LIMIT 1 ) AS customer_name        FROM            `order` o        WHERE            o.`status` = 1            AND o.order_status = 1            AND (            o.input_order_sn IS NULL            OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0 ) AND o.tenant_id IS NOT NULL            <if test="startTime != null and startTime != ''">                AND o.create_time >= #{startTime}            </if>            <if test="endTime != null and endTime != ''">                AND o.create_time <= #{endTime}            </if>            <if test="customerId != null and customerId != ''">                AND o.tenant_id  = #{customerId}            </if>            <if test="businessName != null and businessName != ''">                AND (                SELECT                COUNT(DISTINCT og.order_sn)                FROM order_goods og                LEFT JOIN goods g ON og.goods_id = g.goods_id                LEFT JOIN course_education_type cet ON g.education_type_id = cet.id                LEFT JOIN course_project_type cpt ON g.project_id = cpt.id                LEFT JOIN course_business cb ON g.business_id = cb.id                WHERE o.order_sn = og.order_sn                AND INSTR(CONCAT(cet.education_name,cpt.project_name,cb.business_name),#{businessName}) ) > 0            </if>            <if test="customerName != null and customerName != ''">                AND (SELECT COUNT(s.tenant_id) FROM sys_tenant s WHERE o.tenant_id = s.tenant_id AND s.tenant_name LIKE CONCAT('%',#{customerName},'%')) > 0            </if>            GROUP BY            o.tenant_id    </select>    <select id="getTenantStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"            resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsMoneyVo">        SELECT            vo.*,            st.tenant_name        FROM            (                SELECT                    tenant_id,                    SUM( order_received - order_refunded ) money                    <if test="tenantId != null and tenantId != ''">                        , create_no,any_value(create_username) as create_username                    </if>                FROM                 v_top_order                WHERE                    1 = 1                    AND `status` = 1                    AND check_status = 1                    AND check_time BETWEEN #{startTime}                    AND #{endTime}                <if test="tenantId != null and tenantId != ''">                    AND tenant_id = #{tenantId}                </if>                GROUP BY                    tenant_id                <if test="tenantId != null and tenantId != ''">                    , create_no                </if>                ORDER BY                     money DESC            ) vo                LEFT JOIN sys_tenant st ON vo.tenant_id = st.tenant_id    </select>    <select id="getSingleTenantStatistics" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"            resultType="BigDecimal">        SELECT        IFNULL(SUM( vo.order_received - vo.order_refunded ),0) money        FROM        v_top_order vo        WHERE        1 = 1        AND vo.`status` = 1        AND vo.check_status = 1        AND vo.check_time BETWEEN #{startTime}        AND #{endTime}        <if test="tenantId != null and tenantId != ''">            AND vo.tenant_id = #{tenantId}        </if>        <if test="createNo != null and createNo != ''">            AND vo.create_no = #{createNo}        </if>    </select>    <select id="getTenantStatisticsOrderNum" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"            resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsNumVo">        SELECT        vo.*,        st.tenant_name        FROM        (        SELECT        tenant_id,        COUNT( * ) order_num        <if test="tenantId != null and tenantId != ''">            , create_no,any_value(create_username) as create_username        </if>        FROM        v_top_order        WHERE        1 = 1        AND `status` = 1        AND check_status = 1        <if test="startTime != null and startTime != ''">            AND check_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND check_time <= #{endTime}        </if>        <if test="tenantId != null and tenantId != ''">            AND tenant_id = #{tenantId}        </if>        GROUP BY        tenant_id        <if test="tenantId != null and tenantId != ''">            , create_no        </if>        ORDER BY        order_num DESC        ) vo        LEFT JOIN sys_tenant st ON vo.tenant_id = st.tenant_id    </select>    <select id="getSingleTenantStatisticsOrderNum" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"            resultType="java.lang.Long">        SELECT        IFNULL(COUNT( * ),0)        FROM        v_top_order        WHERE        1 = 1        AND `status` = 1        AND check_status = 1        <if test="startTime != null and startTime != ''">            AND check_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND check_time <= #{endTime}        </if>        <if test="tenantId != null and tenantId != ''">            AND tenant_id = #{tenantId}        </if>        <if test="createNo != null and createNo != ''">            AND create_no = #{createNo}        </if>    </select>    <select id="getNumStatisticsTotalWithBo" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"            resultType="java.lang.Long">        SELECT        IFNULL(COUNT(*),0)        FROM        v_top_order        WHERE        `status` = 1        AND check_status = 1        <if test="startTime != null and startTime != ''">            AND check_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND check_time <= #{endTime}        </if>        <if test="tenantId != null and tenantId != ''">            AND tenant_id = #{tenantId}        </if>    </select>    <select id="getMoneyStatisticsWithBo" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"            resultType="java.math.BigDecimal">        SELECT        IFNULL(SUM( order_received - order_refunded ),0)        FROM        v_top_order        WHERE        `status` = 1        AND check_status = 1        <if test="startTime != null and startTime != ''">            AND check_time >= #{startTime}        </if>        <if test="endTime != null and endTime != ''">            AND check_time <= #{endTime}        </if>        <if test="tenantId != null and tenantId != ''">            AND tenant_id = #{tenantId}        </if>    </select>    <select id="getOrderTenant" parameterType="java.lang.Long" resultType="java.lang.Long">        SELECT tenant_id FROM top_old_order WHERE old_customer_id = #{customerId} LIMIT 1    </select></mapper>
 |