From 5e9f38f4b1807f862d11a4979efac672724fd5ef Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期三, 11 十一月 2026 20:08:01 +0800
Subject: [PATCH] feat(补贴审核): 新增补贴材料读取与OCR识别组件
---
traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 152 insertions(+), 9 deletions(-)
diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java b/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java
index 8ddc35a..2cbeaf0 100644
--- a/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java
@@ -1003,16 +1003,14 @@
Map<String, ScaleSplitTransport> cumMap = loadCumulativeMap(period);
ScaleSplitTransport province = getProvinceCumulative(period);
- // 褰撴湀锛堢浜岄〉锛夛細鍛ㄨ浆閲忔媶鍒嗚〃 MONTH 琛岋紙鍚綋鏈堝悓姣旓級
+ // 褰撴湀锛堢浜岄〉锛夛細鈶㈡彁渚涘悎璁�/瑙勪笅锛岃涓婂瓧娈电敱 鈶� H203-2 缁熶竴瑕嗙洊
+ Map<String, Map<Integer, ScaleSplitTransport>> monthData = loadMonthData(period);
Map<String, ScaleSplitTransport> monthTurnover = new HashMap<>();
- for (ScaleSplitTransport rec : scaleSplitMapper.selectList(
- new LambdaQueryWrapper<ScaleSplitTransport>()
- .eq(ScaleSplitTransport::getPeriodType, "MONTH")
- .eq(ScaleSplitTransport::getReportPeriod, period))) {
- String name = RegionUtil.normalizeCityName(rec.getRegionName());
- if (name != null) monthTurnover.put(name, rec);
+ for (String city : RegionUtil.cityList()) {
+ ScaleSplitTransport rec = getRecord(monthData, city, month);
+ if (rec != null) monthTurnover.put(city, rec);
}
- ScaleSplitTransport provinceMonth = monthTurnover.remove("婀栧寳鐪�");
+ ScaleSplitTransport provinceMonth = loadProvinceMonthMap(period).get(month);
// 浠� docs/璐ц繍/鐢熸垚_鍛ㄨ浆閲忔帓鍚�.xlsx 涓哄簳绋匡細淇濈暀琛ㄥご/鍚堝苟/鍒楀/鏍峰紡锛屼粎鏇挎崲鏁版嵁锛決/R 鍗犳瘮涓烘ā鏉跨紦瀛樺�硷紝鎸夋柊鏁版嵁閲嶇畻
File template = resolveFreightTemplate("鐢熸垚_鍛ㄨ浆閲忔帓鍚�.xlsx");
@@ -1436,6 +1434,7 @@
int month = parseMonth(record.getReportPeriod());
result.computeIfAbsent(city, k -> new HashMap<>()).put(month, record);
}
+ applyH2032MonthlyTurnoverAbove(result, period);
return result;
}
@@ -1457,6 +1456,7 @@
result.put(city, record);
}
}
+ applyH2032CumulativeTurnoverAbove(result, period);
return result;
}
@@ -1474,6 +1474,7 @@
int month = parseMonth(record.getReportPeriod());
result.put(month, record);
}
+ applyH2032ProvinceMonthTurnoverAbove(result, period);
return result;
}
@@ -1491,7 +1492,7 @@
if (!"婀栧寳鐪�".equals(name)) continue;
if (best == null || record.getReportPeriod().compareTo(best.getReportPeriod()) > 0) best = record;
}
- return best;
+ return applyH2032ProvinceCumulativeTurnoverAbove(best, period);
}
/** H2032瑙勪笂: city -> month -> 璐ц繍閲�(鍚�) */
@@ -1528,6 +1529,148 @@
return result;
}
+ /** H2032 瑙勪笂鍛ㄨ浆閲�: city -> month -> 涓囧惃鍏噷锛坱urnover_total 鍚ㄥ叕閲� 梅10000锛� */
+ private Map<String, Map<Integer, Double>> loadH2032TurnoverByMonth(String period) {
+ Map<String, Map<Integer, Double>> result = new HashMap<>();
+ String yearPrefix = period.length() >= 4 ? period.substring(0, 4) : null;
+ for (H2032EnterpriseMonthly record : h2032Mapper.selectList(null)) {
+ String rp = record.getReportPeriod();
+ if (rp == null || rp.compareTo(period) > 0) continue;
+ if (yearPrefix != null && !rp.startsWith(yearPrefix)) continue;
+ if (record.getTurnoverTotal() == null) continue;
+ String city = RegionUtil.cityByCode(record.getRegionCode());
+ if (city == null) continue;
+ int m = parseMonth(rp);
+ result.computeIfAbsent(city, k -> new HashMap<>())
+ .merge(m, record.getTurnoverTotal() / 10000.0, Double::sum);
+ }
+ return result;
+ }
+
+ /** H2032 瑙勪笂鍛ㄨ浆閲� 1..period 鏈堢疮璁�: city -> 涓囧惃鍏噷 */
+ private Map<String, Double> loadH2032TurnoverCumulative(String period) {
+ Map<String, Map<Integer, Double>> byMonth = loadH2032TurnoverByMonth(period);
+ int target = parseMonth(period);
+ Map<String, Double> result = new HashMap<>();
+ for (Map.Entry<String, Map<Integer, Double>> e : byMonth.entrySet()) {
+ double sum = 0.0;
+ boolean any = false;
+ for (int m = 1; m <= target; m++) {
+ Double v = e.getValue().get(m);
+ if (v != null) { sum += v; any = true; }
+ }
+ if (any) result.put(e.getKey(), sum);
+ }
+ return result;
+ }
+
+ /** 瑙勪笂瀛楁鍙 鈶� H203-2锛涒憿璁板綍鍙繚鐣欏悎璁★紝骞舵嵁姝ら噸绠楄涓嬨�� */
+ private void applyH2032MonthlyTurnoverAbove(Map<String, Map<Integer, ScaleSplitTransport>> data,
+ String period) {
+ int lastMonth = parseMonth(period);
+ Map<String, Map<Integer, Double>> current = loadH2032TurnoverByMonth(period);
+ Map<String, Map<Integer, Double>> prior = loadH2032TurnoverByMonth(previousYearPeriod(period));
+ for (String city : RegionUtil.cityList()) {
+ Map<Integer, ScaleSplitTransport> cityData = data.get(city);
+ for (int m = 1; m <= lastMonth; m++) {
+ ScaleSplitTransport rec = cityData == null ? null : cityData.get(m);
+ Double above = monthValueOf(current, city, m);
+ if (rec == null && above == null) continue;
+ if (cityData == null) {
+ cityData = new HashMap<>();
+ data.put(city, cityData);
+ }
+ if (rec == null) {
+ rec = new ScaleSplitTransport();
+ rec.setRegionName(city);
+ cityData.put(m, rec);
+ }
+ applyH2032TurnoverAbove(rec, above, growthYoy(above, monthValueOf(prior, city, m)));
+ }
+ }
+ }
+
+ private void applyH2032CumulativeTurnoverAbove(Map<String, ScaleSplitTransport> data, String period) {
+ Map<String, Double> current = loadH2032TurnoverCumulative(period);
+ Map<String, Double> prior = loadH2032TurnoverCumulative(previousYearPeriod(period));
+ for (String city : RegionUtil.cityList()) {
+ Double above = current.get(city);
+ ScaleSplitTransport rec = data.get(city);
+ if (rec == null && above == null) continue;
+ if (rec == null) {
+ rec = new ScaleSplitTransport();
+ rec.setRegionName(city);
+ data.put(city, rec);
+ }
+ applyH2032TurnoverAbove(rec, above, growthYoy(above, prior.get(city)));
+ }
+ }
+
+ private void applyH2032ProvinceMonthTurnoverAbove(Map<Integer, ScaleSplitTransport> data, String period) {
+ int lastMonth = parseMonth(period);
+ Map<String, Map<Integer, Double>> current = loadH2032TurnoverByMonth(period);
+ Map<String, Map<Integer, Double>> prior = loadH2032TurnoverByMonth(previousYearPeriod(period));
+ for (int m = 1; m <= lastMonth; m++) {
+ Double above = sumCitiesOfMonth(current, m);
+ ScaleSplitTransport rec = data.get(m);
+ if (rec == null && above == null) continue;
+ if (rec == null) {
+ rec = new ScaleSplitTransport();
+ rec.setRegionName("婀栧寳鐪�");
+ data.put(m, rec);
+ }
+ applyH2032TurnoverAbove(rec, above, growthYoy(above, sumCitiesOfMonth(prior, m)));
+ }
+ }
+
+ private ScaleSplitTransport applyH2032ProvinceCumulativeTurnoverAbove(ScaleSplitTransport province,
+ String period) {
+ Map<String, Double> current = loadH2032TurnoverCumulative(period);
+ Map<String, Double> prior = loadH2032TurnoverCumulative(previousYearPeriod(period));
+ Double above = sumCitiesOf(current);
+ if (province == null && above == null) return null;
+ if (province == null) {
+ province = new ScaleSplitTransport();
+ province.setRegionName("婀栧寳鐪�");
+ }
+ applyH2032TurnoverAbove(province, above, growthYoy(above, sumCitiesOf(prior)));
+ return province;
+ }
+
+ private void applyH2032TurnoverAbove(ScaleSplitTransport rec, Double above, Double yoy) {
+ rec.setAboveScaleTurnover(above);
+ rec.setAboveScaleYoy(yoy);
+ Double total = rec.getTotalTurnover();
+ rec.setBelowScaleTurnover(total == null || above == null ? null : total - above);
+ }
+
+ private String previousYearPeriod(String period) {
+ return (Integer.parseInt(period.substring(0, 4)) - 1) + period.substring(4);
+ }
+
+ private Double sumCitiesOf(Map<String, Double> values) {
+ Double sum = null;
+ for (String city : RegionUtil.cityList()) {
+ Double v = values.get(city);
+ if (v != null) sum = sum == null ? v : sum + v;
+ }
+ return sum;
+ }
+
+ private Double sumCitiesOfMonth(Map<String, Map<Integer, Double>> values, int month) {
+ Double sum = null;
+ for (String city : RegionUtil.cityList()) {
+ Double v = monthValueOf(values, city, month);
+ if (v != null) sum = sum == null ? v : sum + v;
+ }
+ return sum;
+ }
+
+ private Double monthValueOf(Map<String, Map<Integer, Double>> byMonth, String city, int month) {
+ Map<Integer, Double> buckets = byMonth.get(city);
+ return buckets == null ? null : buckets.get(month);
+ }
+
/** H2032瑙勪笂鍚屾瘮锛堥渶鍘诲勾鍚屾湡鐨凥2032鏁版嵁锛屾殏鏃犲垯涓虹┖锛� */
private Map<String, Double> computeH2032Yoy(String period) {
Map<String, Double> result = new HashMap<>();
--
Gitblit v1.9.1