From f9ccdc1663bc98b1e068ab47c58887e3b482bc6d Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期三, 11 十一月 2026 20:07:28 +0800
Subject: [PATCH] feat(H202): 新增货运车辆拥有情况导入与查看

---
 traffic-audit-server/src/main/java/com/trafficaudit/reportexport/calc/FreightCalc.java |   70 +++++++++++++++++++++++++----------
 1 files changed, 50 insertions(+), 20 deletions(-)

diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/calc/FreightCalc.java b/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/calc/FreightCalc.java
index 267ccf6..fb3cd2d 100644
--- a/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/calc/FreightCalc.java
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/calc/FreightCalc.java
@@ -24,8 +24,9 @@
  * 1. 瑙勪笂璐ц繍閲� = h2032_enterprise_monthly.freight_total锛堝惃锛夋寜 17 甯傚窞姹囨�� 梅10000锛堜竾鍚級銆�
  * 2. 鍚堣璐ц繍閲� = freight_turnover_import.freight_mMM锛堝綋鏈堬級/ freight_m01..mMM锛堢疮璁★級銆�
  * 3. 瑙勪笅璐ц繍閲� = 鍚堣 鈭� 瑙勪笂锛堟媶鍒嗚〃涓嶅瓨璐ц繍閲忓垪锛屼笉鑳界洿鎺ュ彇瑙勪笅锛夈��
- * 4. 瑙勪笂/鍚堣鍛ㄨ浆閲� = scale_split_transport MONTH|CUMULATIVE 鐨� above_scale_turnover / total_turnover
- *    锛堝悎璁′笌 freight_turnover_import.turnover_mMM 鍚屾簮锛屽凡鏍稿涓�鑷达級锛涜涓嬪懆杞� = 鍚堣 鈭� 瑙勪笂銆�
+ * 4. 瑙勪笂鍛ㄨ浆閲忓缁堝彇 鈶� H203-2 鐨� turnover_total锛堝惃鍏噷 梅10000 = 涓囧惃鍏噷锛夛紱
+ *    鈶� scale_split_transport 鍙彁渚涘悎璁″懆杞噺 total_turnover锛堢己 鈶� 鏃跺彇 freight_turnover_import锛夛紝
+ *    瑙勪笅鍛ㄨ浆 = 鍚堣 鈭� 瑙勪笂銆傝涓婂彛寰勪笉渚濊禆 鈶€��
  * 5. 鍚屾瘮锛堝幓骞村悓鍙e緞锛変笉鍦ㄦ湰鏈嶅姟璁$畻锛氭寜 Q1 浠ユ瘝鐗堢紦瀛� 2025 鍙傜収缁勪负鍩哄噯锛岀敱鍐欏洖灞傚~琛ㄦ椂璁$畻銆�
  *
  * 杈撳嚭 key = RegionUtil 瑙勮寖甯傚窞鍚嶏紙姝︽眽甯傗�︾鍐滄灦鏋楀尯锛�+ PROVINCE锛堟箹鍖楃渷锛屽叏鐪佽 = 17 甯傚窞涔嬪拰锛�
@@ -92,8 +93,9 @@
         int year = Integer.parseInt(period.substring(0, 4));
         int month = Integer.parseInt(period.substring(5, 7));
 
-        // H2032 瑙勪笂璐ц繍閲忥紙鍚級锛氬競宸� -> 鏈堟《
+        // H2032 瑙勪笂璐ц繍閲�/鍛ㄨ浆閲忥紙鍚ㄣ�佸惃鍏噷锛夛細甯傚窞 -> 鏈堟《
         Map<String, Map<Integer, Double>> h2032TonByCityMonth = new HashMap<>();
+        Map<String, Map<Integer, Double>> h2032TurnoverByCityMonth = new HashMap<>();
         List<H2032EnterpriseMonthly> h2032List = h2032Mapper.selectList(
             new LambdaQueryWrapper<H2032EnterpriseMonthly>().likeRight(H2032EnterpriseMonthly::getReportPeriod, year));
         for (H2032EnterpriseMonthly rec : h2032List) {
@@ -101,9 +103,13 @@
             if (rp == null || rp.compareTo(period) > 0) continue;
             String city = RegionUtil.cityByCode(rec.getRegionCode());
             if (city == null) continue;
+            int hMonth = Integer.parseInt(rp.substring(5, 7));
             double freight = rec.getFreightTotal() == null ? 0.0 : rec.getFreightTotal();
-            h2032TonByCityMonth.computeIfAbsent(city, k -> new HashMap<>())
-                .merge(Integer.parseInt(rp.substring(5, 7)), freight, Double::sum);
+            h2032TonByCityMonth.computeIfAbsent(city, k -> new HashMap<>()).merge(hMonth, freight, Double::sum);
+            if (rec.getTurnoverTotal() != null) {
+                h2032TurnoverByCityMonth.computeIfAbsent(city, k -> new HashMap<>())
+                    .merge(hMonth, rec.getTurnoverTotal(), Double::sum);
+            }
         }
 
         // freight_turnover_import锛氬悎璁¤揣杩愰噺/鍛ㄨ浆閲忥紙浠呭瓨鍩庡競琛岋紱婀栧寳鐪佽鐢辨眰鍜屽緱鍑猴級
@@ -130,8 +136,10 @@
         Map<String, FreightMetrics> monthMap = new LinkedHashMap<>();
         Map<String, FreightMetrics> cumulativeMap = new LinkedHashMap<>();
         for (String city : RegionUtil.cityList()) {
-            monthMap.put(city, buildMetrics(city, month, h2032TonByCityMonth, ftMap, splitMonth, false));
-            cumulativeMap.put(city, buildMetrics(city, month, h2032TonByCityMonth, ftMap, splitCumulative, true));
+            monthMap.put(city, buildMetrics(city, month, h2032TonByCityMonth, h2032TurnoverByCityMonth,
+                ftMap, splitMonth, false));
+            cumulativeMap.put(city, buildMetrics(city, month, h2032TonByCityMonth, h2032TurnoverByCityMonth,
+                ftMap, splitCumulative, true));
         }
         monthMap.put(PROVINCE, sumOf(monthMap));
         cumulativeMap.put(PROVINCE, sumOf(cumulativeMap));
@@ -141,20 +149,36 @@
     /** 鍗曞煄甯傛寚鏍囥�俢umulative=true 鏃� H2032 鍙� 1..month 鍏ㄦ《銆佸悎璁″彇 m01..mMM 涔嬪拰锛沠alse 鏃跺彧鍙栧綋鏈堛�� */
     private FreightMetrics buildMetrics(String city, int month,
                                         Map<String, Map<Integer, Double>> h2032TonByCityMonth,
+                                        Map<String, Map<Integer, Double>> h2032TurnoverByCityMonth,
                                         Map<String, FreightTurnoverImport> ftMap,
                                         Map<String, ScaleSplitTransport> splitMap,
                                         boolean cumulative) {
         Double aboveFreight = null;
         Map<Integer, Double> h2032Buckets = h2032TonByCityMonth.get(city);
         if (h2032Buckets != null) {
-            double ton;
             if (cumulative) {
-                ton = 0.0;
+                double ton = 0.0;
                 for (int m = 1; m <= month; m++) ton += h2032Buckets.getOrDefault(m, 0.0);
+                aboveFreight = ton / 10000.0;
             } else {
-                ton = h2032Buckets.getOrDefault(month, 0.0);
+                // 褰撴湀鏃犺涓婅褰� -> 鐣欑┖锛堜笉鍐嶅啓 0锛夛紱鏈夎褰曪紙鍚湡瀹� 0 鍊硷級鎵嶅啓鏁�
+                Double ton = h2032Buckets.get(month);
+                aboveFreight = ton == null ? null : ton / 10000.0;
             }
-            aboveFreight = ton / 10000.0;
+        }
+
+        // 鈶� H203-2 瑙勪笂鍛ㄨ浆閲忥紙鍚ㄥ叕閲� -> 涓囧惃鍏噷锛夛紝鏄涓婃寚鏍囩殑姝e紡鍙栨暟鏉ユ簮
+        Double aboveTurnoverH2032 = null;
+        Map<Integer, Double> turnoverBuckets = h2032TurnoverByCityMonth.get(city);
+        if (turnoverBuckets != null) {
+            if (cumulative) {
+                double tonKm = 0.0;
+                for (int m = 1; m <= month; m++) tonKm += turnoverBuckets.getOrDefault(m, 0.0);
+                aboveTurnoverH2032 = tonKm / 10000.0;
+            } else {
+                Double tonKm = turnoverBuckets.get(month);
+                aboveTurnoverH2032 = tonKm == null ? null : tonKm / 10000.0;
+            }
         }
 
         FreightTurnoverImport ft = ftMap.get(city);
@@ -176,7 +200,8 @@
         }
 
         ScaleSplitTransport split = splitMap.get(city);
-        Double aboveTurnover = split == null ? null : split.getAboveScaleTurnover();
+        // 瑙勪笂璐ц繍閲�/鍛ㄨ浆閲忓彧鐢� 鈶� H203-2 鍐冲畾锛涒憿鍙弬涓庡悎璁″懆杞噺銆�
+        Double aboveTurnover = aboveTurnoverH2032;
         Double totalTurnover = split != null && split.getTotalTurnover() != null
             ? split.getTotalTurnover() : totalTurnoverFromFt;
 
@@ -187,22 +212,27 @@
                                   aboveTurnover, belowTurnover, totalTurnover);
     }
 
-    /** 婀栧寳鐪佽 = 17 甯傚窞涔嬪拰锛堜笌姣嶇増鍏ㄧ渷琛� 危 鍏紡涓�鑷达紱鍏ㄥ競宸炴棤鏁版嵁鏃惰緭鍑� 0锛� */
+    /** 婀栧寳鐪佽 = 17 甯傚窞涔嬪拰锛堜笌姣嶇増鍏ㄧ渷琛� 危 鍏紡涓�鑷达級锛涘叏閮ㄥ競宸炴棤鏁版嵁鏃朵繚鎸� null锛岃惤瀹炩�滅己鏁扮暀绌衡�� */
     private FreightMetrics sumOf(Map<String, FreightMetrics> byCity) {
-        double af = 0.0, bf = 0.0, tf = 0.0, at = 0.0, bt = 0.0, tt = 0.0;
+        Double af = null, bf = null, tf = null, at = null, bt = null, tt = null;
         for (String city : RegionUtil.cityList()) {
             FreightMetrics m = byCity.get(city);
             if (m == null) continue;
-            af += nz(m.getAboveFreight());
-            bf += nz(m.getBelowFreight());
-            tf += nz(m.getTotalFreight());
-            at += nz(m.getAboveTurnover());
-            bt += nz(m.getBelowTurnover());
-            tt += nz(m.getTotalTurnover());
+            af = add(af, m.getAboveFreight());
+            bf = add(bf, m.getBelowFreight());
+            tf = add(tf, m.getTotalFreight());
+            at = add(at, m.getAboveTurnover());
+            bt = add(bt, m.getBelowTurnover());
+            tt = add(tt, m.getTotalTurnover());
         }
         return new FreightMetrics(af, bf, tf, at, bt, tt);
     }
 
+    private Double add(Double acc, Double v) {
+        if (v == null) return acc;
+        return acc == null ? v : acc + v;
+    }
+
     private double monthField(FreightTurnoverImport e, int m, boolean freight) {
         switch (m) {
             case 1: return freight ? nz(e.getFreightM01()) : nz(e.getTurnoverM01());

--
Gitblit v1.9.1