Kaynağa Gözat

feat: 数据大屏汇总逻辑调整;

hanchaolong 1 hafta önce
ebeveyn
işleme
e58b913ea4

+ 15 - 3
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/impl/LargeScreenReportServiceImpl.java

@@ -68,16 +68,28 @@ public class LargeScreenReportServiceImpl  implements LargeScreenReportService {
         Map<String,Object> result=new HashMap<>();
         List<String> allProvince= new ArrayList<>();
         List<String> allMergerProvince= new ArrayList<>();
-        List<Integer> orderNum= new ArrayList<>();
+        List<Integer> outflowNum= new ArrayList<>();
+        List<Integer> inflowNum= new ArrayList<>();
+        List<BigDecimal> outflowAmounts = new ArrayList<>();
+        List<BigDecimal> inflowAmounts = new ArrayList<>();
+        
+        // 一次查询获取订单数量和金额数据
         List<Map<String,Object>> list= largeScreenReportMapper.queryProvinceOrdersReport(largeRequest);
         for(int i=0;i<list.size();i++){
             allProvince.add(list.get(i).get("province_name").toString()) ;
-            orderNum.add(Integer.parseInt(list.get(i).get("num").toString())) ;
+            outflowNum.add(Integer.parseInt(list.get(i).get("outflowNum").toString())) ;
+            inflowNum.add(Integer.parseInt(list.get(i).get("inflowNum").toString())) ;
             allMergerProvince.add(list.get(i).get("merger_name").toString());
+            outflowAmounts.add(new BigDecimal(list.get(i).get("outflowAmount").toString()));
+            inflowAmounts.add(new BigDecimal(list.get(i).get("inflowAmount").toString()));
         }
         result.put("allProvince",allProvince);
         result.put("allMergerProvince",allMergerProvince);
-        result.put("orderNum",orderNum);
+        result.put("outflowNum",outflowNum);
+        result.put("inflowNum",inflowNum);
+        result.put("outflowAmounts", outflowAmounts);
+        result.put("inflowAmounts", inflowAmounts);
+
         return result;
 
     }

+ 120 - 25
jd-logistics-modules/jd-logistics-system/src/main/resources/mapper/logistics/LargeScreenReportMapper.xml

@@ -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>
 
     <!-- 供应商列表-->