|
|
@@ -89,33 +89,128 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
|
|
|
|
|
|
|
|
- <!-- 按照省份查询订单量-->
|
|
|
+ <!-- 按照省份查询订单量和金额(整合版)-->
|
|
|
<select id="queryProvinceOrdersReport" parameterType="java.util.Map" resultType="java.util.HashMap" >
|
|
|
SELECT
|
|
|
- a.province_name,
|
|
|
- a.merger_name,
|
|
|
- ifnull( b.num, 0 ) num
|
|
|
- FROM
|
|
|
- ( SELECT NAME province_name, merger_name FROM sys_city WHERE `level` = 0 ) a
|
|
|
- LEFT JOIN ( SELECT sender_province, count( 1 ) num FROM biz_waybill_order d WHERE d.order_status != 6
|
|
|
-
|
|
|
- <if test="orderType != null and orderType != ''">
|
|
|
- and d.order_type = #{orderType}
|
|
|
- </if>
|
|
|
- <if test="startTime != null and startTime != ''">
|
|
|
- and DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
|
|
|
- </if>
|
|
|
- <if test="endTime != null and endTime != ''">
|
|
|
- and DATE_FORMAT(d.create_time, '%Y-%m-%d')<![CDATA[<=]]> #{endTime}
|
|
|
- </if>
|
|
|
- <if test="deptId != null and deptId != ''">
|
|
|
- and d.dept_id = #{deptId}
|
|
|
- </if>
|
|
|
- <!-- 数据范围过滤 -->
|
|
|
- ${params.dataScope}
|
|
|
-
|
|
|
- GROUP BY sender_province ) b ON a.province_name = b.sender_province
|
|
|
- order by num desc
|
|
|
+ province_name,
|
|
|
+ merger_name,
|
|
|
+ IFNULL(outflow_num, 0) AS outflowNum,
|
|
|
+ IFNULL(inflow_num, 0) AS inflowNum,
|
|
|
+ IFNULL(outflow_amount, 0) AS outflowAmount,
|
|
|
+ IFNULL(inflow_amount, 0) AS inflowAmount
|
|
|
+ FROM (
|
|
|
+ SELECT
|
|
|
+ a.NAME AS province_name,
|
|
|
+ a.merger_name,
|
|
|
+ -- 流出订单数(该省作为发货地)
|
|
|
+ IFNULL(outflow_order.num, 0) AS outflow_num,
|
|
|
+ -- 流入订单数(该省作为收货地)
|
|
|
+ IFNULL(inflow_order.num, 0) AS inflow_num,
|
|
|
+ -- 流出金额(该省作为发货地)
|
|
|
+ IFNULL(outflow_cost.amt, 0) AS outflow_amount,
|
|
|
+ -- 流入金额(该省作为收货地)
|
|
|
+ IFNULL(inflow_cost.amt, 0) AS inflow_amount
|
|
|
+ FROM
|
|
|
+ (SELECT NAME, merger_name FROM sys_city WHERE `level` = 0) a
|
|
|
+ LEFT JOIN (
|
|
|
+ -- 流出订单统计
|
|
|
+ SELECT
|
|
|
+ sender_province,
|
|
|
+ COUNT(1) AS num
|
|
|
+ FROM biz_waybill_order d
|
|
|
+ WHERE d.order_status != 6
|
|
|
+ <if test="orderType != null and orderType != ''">
|
|
|
+ AND d.order_type = #{orderType}
|
|
|
+ </if>
|
|
|
+ <if test="startTime != null and startTime != ''">
|
|
|
+ AND DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
|
|
|
+ </if>
|
|
|
+ <if test="endTime != null and endTime != ''">
|
|
|
+ AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
|
|
|
+ </if>
|
|
|
+ <if test="deptId != null and deptId != ''">
|
|
|
+ AND d.dept_id = #{deptId}
|
|
|
+ </if>
|
|
|
+ ${params.dataScope}
|
|
|
+ GROUP BY sender_province
|
|
|
+ ) outflow_order ON a.NAME = outflow_order.sender_province
|
|
|
+ LEFT JOIN (
|
|
|
+ -- 流入订单统计
|
|
|
+ SELECT
|
|
|
+ receiver_province,
|
|
|
+ COUNT(1) AS num
|
|
|
+ FROM biz_waybill_order d
|
|
|
+ WHERE d.order_status != 6
|
|
|
+ <if test="orderType != null and orderType != ''">
|
|
|
+ AND d.order_type = #{orderType}
|
|
|
+ </if>
|
|
|
+ <if test="startTime != null and startTime != ''">
|
|
|
+ AND DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
|
|
|
+ </if>
|
|
|
+ <if test="endTime != null and endTime != ''">
|
|
|
+ AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
|
|
|
+ </if>
|
|
|
+ <if test="deptId != null and deptId != ''">
|
|
|
+ AND d.dept_id = #{deptId}
|
|
|
+ </if>
|
|
|
+ ${params.dataScope}
|
|
|
+ GROUP BY receiver_province
|
|
|
+ ) inflow_order ON a.NAME = inflow_order.receiver_province
|
|
|
+ LEFT JOIN (
|
|
|
+ -- 流出金额统计
|
|
|
+ SELECT
|
|
|
+ d.sender_province,
|
|
|
+ IFNULL(SUM(IFNULL(c.adjust_amount, c.rate_amount)), 0) AS amt
|
|
|
+ FROM biz_waybill_order d
|
|
|
+ LEFT JOIN biz_waybill_cost_details c ON d.waybill_id = c.waybill_id
|
|
|
+ WHERE d.order_status != 6
|
|
|
+ <if test="orderType != null and orderType != ''">
|
|
|
+ AND d.order_type = #{orderType}
|
|
|
+ </if>
|
|
|
+ <if test="startTime != null and startTime != ''">
|
|
|
+ AND DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
|
|
|
+ </if>
|
|
|
+ <if test="endTime != null and endTime != ''">
|
|
|
+ AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
|
|
|
+ </if>
|
|
|
+ <if test="deptId != null and deptId != ''">
|
|
|
+ AND d.dept_id = #{deptId}
|
|
|
+ </if>
|
|
|
+ ${params.dataScope}
|
|
|
+ GROUP BY d.sender_province
|
|
|
+ ) outflow_cost ON a.NAME = outflow_cost.sender_province
|
|
|
+ LEFT JOIN (
|
|
|
+ -- 流入金额统计
|
|
|
+ SELECT
|
|
|
+ d.receiver_province,
|
|
|
+ IFNULL(SUM(IFNULL(c.adjust_amount, c.rate_amount)), 0) AS amt
|
|
|
+ FROM biz_waybill_order d
|
|
|
+ LEFT JOIN biz_waybill_cost_details c ON d.waybill_id = c.waybill_id
|
|
|
+ WHERE d.order_status != 6
|
|
|
+ <if test="orderType != null and orderType != ''">
|
|
|
+ AND d.order_type = #{orderType}
|
|
|
+ </if>
|
|
|
+ <if test="startTime != null and startTime != ''">
|
|
|
+ AND DATE_FORMAT(d.create_time, '%Y-%m-%d') >= #{startTime}
|
|
|
+ </if>
|
|
|
+ <if test="endTime != null and endTime != ''">
|
|
|
+ AND DATE_FORMAT(d.create_time, '%Y-%m-%d') <![CDATA[<=]]> #{endTime}
|
|
|
+ </if>
|
|
|
+ <if test="deptId != null and deptId != ''">
|
|
|
+ AND d.dept_id = #{deptId}
|
|
|
+ </if>
|
|
|
+ ${params.dataScope}
|
|
|
+ GROUP BY d.receiver_province
|
|
|
+ ) inflow_cost ON a.NAME = inflow_cost.receiver_province
|
|
|
+ ) t
|
|
|
+ <where>
|
|
|
+ <if test="rankType != null and rankType != '' and rankType == '1'">
|
|
|
+ ORDER BY outflow_amount DESC
|
|
|
+ </if>
|
|
|
+ <if test="rankType != null and rankType != '' and rankType == '2'">
|
|
|
+ ORDER BY outflow_num DESC
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
</select>
|
|
|
|
|
|
<!-- 供应商列表-->
|