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-web/src/views/DataImport.vue | 46 ++
deploy-templates/db/init.sql | 27 +
docs/货运/RP_JTB_FreightVehicle_全省.xlsx | 0
traffic-audit-server/src/main/java/com/trafficaudit/dataimport/mapper/H202FreightVehicleOwnershipMapper.java | 8
traffic-audit-server/src/main/java/com/trafficaudit/dataimport/service/DataImportService.java | 155 +++++++
traffic-audit-server/src/main/java/com/trafficaudit/dataimport/service/H202WorkbookParser.java | 397 +++++++++++++++++++
docs/init.sql | 27 +
traffic-audit-server/src/main/java/com/trafficaudit/dataimport/entity/H202FreightVehicleOwnership.java | 40 ++
traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataViewController.java | 58 ++
docs/sql_h202_freight_vehicle_ownership.sql | 26 +
traffic-audit-server/src/test/java/com/trafficaudit/dataimport/service/H202WorkbookParserTest.java | 316 +++++++++++++++
docs/database.md | 32 +
deploy-templates/db/sql_h202_freight_vehicle_ownership.sql | 26 +
traffic-audit-web/src/views/DataView.vue | 13
traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataImportController.java | 14
15 files changed, 1,181 insertions(+), 4 deletions(-)
diff --git a/deploy-templates/db/init.sql b/deploy-templates/db/init.sql
index 6349e47..b4c7983 100644
--- a/deploy-templates/db/init.sql
+++ b/deploy-templates/db/init.sql
@@ -135,6 +135,33 @@
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='浜や紒缁烪203-2琛╛閬撹矾璐х墿杩愯緭鏈堝害鐢熶骇鎯呭喌';
+-- H202 highway freight operating vehicle ownership matrix.
+DROP TABLE IF EXISTS h202_freight_vehicle_ownership;
+CREATE TABLE h202_freight_vehicle_ownership (
+ id BIGINT AUTO_INCREMENT PRIMARY KEY,
+ report_period VARCHAR(20) NOT NULL COMMENT 'Report period yyyy-MM',
+ region_name VARCHAR(50) NOT NULL COMMENT 'Hubei province or prefecture-level region',
+ report_date DATE NOT NULL COMMENT 'Report date from cell L3',
+ item_code VARCHAR(10) NOT NULL COMMENT 'H202 indicator code 01-93',
+ item_name VARCHAR(200) NOT NULL COMMENT 'Indicator name inherited from the matrix row',
+ unit VARCHAR(20) NULL COMMENT 'Measurement unit',
+ total_value DECIMAL(30,15) NULL,
+ individual_value DECIMAL(30,15) NULL,
+ large_value DECIMAL(30,15) NULL,
+ large_heavy_value DECIMAL(30,15) NULL,
+ large_heavy_individual_value DECIMAL(30,15) NULL,
+ large_individual_value DECIMAL(30,15) NULL,
+ medium_value DECIMAL(30,15) NULL,
+ medium_individual_value DECIMAL(30,15) NULL,
+ small_value DECIMAL(30,15) NULL,
+ small_individual_value DECIMAL(30,15) NULL,
+ source_file_name VARCHAR(255) NULL COMMENT 'Source workbook file name',
+ import_batch_id BIGINT NULL COMMENT 'Import batch id',
+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ UNIQUE KEY uk_h202_period_region_item (report_period, region_name, item_code),
+ KEY idx_h202_period_region (report_period, region_name)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='H202 highway freight operating vehicle ownership';
+
-- 杩愭斂杞﹁締鏁版嵁
DROP TABLE IF EXISTS transport_auth_vehicle;
CREATE TABLE transport_auth_vehicle (
diff --git a/deploy-templates/db/sql_h202_freight_vehicle_ownership.sql b/deploy-templates/db/sql_h202_freight_vehicle_ownership.sql
new file mode 100644
index 0000000..e886470
--- /dev/null
+++ b/deploy-templates/db/sql_h202_freight_vehicle_ownership.sql
@@ -0,0 +1,26 @@
+-- H202 highway freight operating vehicle ownership.
+-- Safe to run on an existing MySQL 5.7 database.
+CREATE TABLE IF NOT EXISTS h202_freight_vehicle_ownership (
+ id BIGINT AUTO_INCREMENT PRIMARY KEY,
+ report_period VARCHAR(20) NOT NULL COMMENT 'Report period yyyy-MM',
+ region_name VARCHAR(50) NOT NULL COMMENT 'Hubei province or prefecture-level region',
+ report_date DATE NOT NULL COMMENT 'Report date from cell L3',
+ item_code VARCHAR(10) NOT NULL COMMENT 'H202 indicator code 01-93',
+ item_name VARCHAR(200) NOT NULL COMMENT 'Indicator name inherited from the matrix row',
+ unit VARCHAR(20) NULL COMMENT 'Measurement unit',
+ total_value DECIMAL(30,15) NULL,
+ individual_value DECIMAL(30,15) NULL,
+ large_value DECIMAL(30,15) NULL,
+ large_heavy_value DECIMAL(30,15) NULL,
+ large_heavy_individual_value DECIMAL(30,15) NULL,
+ large_individual_value DECIMAL(30,15) NULL,
+ medium_value DECIMAL(30,15) NULL,
+ medium_individual_value DECIMAL(30,15) NULL,
+ small_value DECIMAL(30,15) NULL,
+ small_individual_value DECIMAL(30,15) NULL,
+ source_file_name VARCHAR(255) NULL COMMENT 'Source workbook file name',
+ import_batch_id BIGINT NULL COMMENT 'Import batch id',
+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ UNIQUE KEY uk_h202_period_region_item (report_period, region_name, item_code),
+ KEY idx_h202_period_region (report_period, region_name)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='H202 highway freight operating vehicle ownership';
diff --git a/docs/database.md b/docs/database.md
index ab51cc9..f7f7833 100644
--- a/docs/database.md
+++ b/docs/database.md
@@ -140,6 +140,38 @@
| import_batch_id | bigint | 瀵煎叆鎵规 |
| created_at | datetime | 鍒涘缓鏃堕棿 |
+### h202_freight_vehicle_ownership (H202 highway freight operating vehicle ownership)
+
+Source: transport authority comprehensive ledger workbook `RP_JTB_FreightVehicle_<region>.xlsx`.
+One row contains one report period, one region, and one indicator code (`01`-`93`).
+All numeric values use `DECIMAL(30,15)` and Java `BigDecimal`; Excel values are converted
+through their exact text and are never routed through `double`.
+
+| Field | Type | Description |
+|------|------|------|
+| id | bigint | Primary key |
+| report_period | varchar(20) | Report period `yyyy-MM` |
+| region_name | varchar(50) | Hubei province or one of 17 prefecture-level regions |
+| report_date | date | Report date read from cell `L3` |
+| item_code | varchar(10) | H202 indicator code `01`-`93` |
+| item_name | varchar(200) | Indicator name inherited from the matrix row |
+| unit | varchar(20) | Measurement unit |
+| total_value | decimal(30,15) | Total |
+| individual_value | decimal(30,15) | Individual |
+| large_value | decimal(30,15) | Large |
+| large_heavy_value | decimal(30,15) | Large-heavy |
+| large_heavy_individual_value | decimal(30,15) | Large-heavy-individual |
+| large_individual_value | decimal(30,15) | Large-individual |
+| medium_value | decimal(30,15) | Medium |
+| medium_individual_value | decimal(30,15) | Medium-individual |
+| small_value | decimal(30,15) | Small |
+| small_individual_value | decimal(30,15) | Small-individual |
+| source_file_name | varchar(255) | Source workbook file name |
+| import_batch_id | bigint | Import batch |
+| created_at | datetime | Creation time |
+
+Unique key: `(report_period, region_name, item_code)`.
+
### transport_auth_vehicle锛堣繍鏀胯溅杈嗘暟鎹級
> 鏁版嵁鏉ユ簮锛氭ā鏉縚杩愭斂杞﹁締.xlsx
diff --git a/docs/init.sql b/docs/init.sql
index 6349e47..b4c7983 100644
--- a/docs/init.sql
+++ b/docs/init.sql
@@ -135,6 +135,33 @@
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='浜や紒缁烪203-2琛╛閬撹矾璐х墿杩愯緭鏈堝害鐢熶骇鎯呭喌';
+-- H202 highway freight operating vehicle ownership matrix.
+DROP TABLE IF EXISTS h202_freight_vehicle_ownership;
+CREATE TABLE h202_freight_vehicle_ownership (
+ id BIGINT AUTO_INCREMENT PRIMARY KEY,
+ report_period VARCHAR(20) NOT NULL COMMENT 'Report period yyyy-MM',
+ region_name VARCHAR(50) NOT NULL COMMENT 'Hubei province or prefecture-level region',
+ report_date DATE NOT NULL COMMENT 'Report date from cell L3',
+ item_code VARCHAR(10) NOT NULL COMMENT 'H202 indicator code 01-93',
+ item_name VARCHAR(200) NOT NULL COMMENT 'Indicator name inherited from the matrix row',
+ unit VARCHAR(20) NULL COMMENT 'Measurement unit',
+ total_value DECIMAL(30,15) NULL,
+ individual_value DECIMAL(30,15) NULL,
+ large_value DECIMAL(30,15) NULL,
+ large_heavy_value DECIMAL(30,15) NULL,
+ large_heavy_individual_value DECIMAL(30,15) NULL,
+ large_individual_value DECIMAL(30,15) NULL,
+ medium_value DECIMAL(30,15) NULL,
+ medium_individual_value DECIMAL(30,15) NULL,
+ small_value DECIMAL(30,15) NULL,
+ small_individual_value DECIMAL(30,15) NULL,
+ source_file_name VARCHAR(255) NULL COMMENT 'Source workbook file name',
+ import_batch_id BIGINT NULL COMMENT 'Import batch id',
+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ UNIQUE KEY uk_h202_period_region_item (report_period, region_name, item_code),
+ KEY idx_h202_period_region (report_period, region_name)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='H202 highway freight operating vehicle ownership';
+
-- 杩愭斂杞﹁締鏁版嵁
DROP TABLE IF EXISTS transport_auth_vehicle;
CREATE TABLE transport_auth_vehicle (
diff --git a/docs/sql_h202_freight_vehicle_ownership.sql b/docs/sql_h202_freight_vehicle_ownership.sql
new file mode 100644
index 0000000..e886470
--- /dev/null
+++ b/docs/sql_h202_freight_vehicle_ownership.sql
@@ -0,0 +1,26 @@
+-- H202 highway freight operating vehicle ownership.
+-- Safe to run on an existing MySQL 5.7 database.
+CREATE TABLE IF NOT EXISTS h202_freight_vehicle_ownership (
+ id BIGINT AUTO_INCREMENT PRIMARY KEY,
+ report_period VARCHAR(20) NOT NULL COMMENT 'Report period yyyy-MM',
+ region_name VARCHAR(50) NOT NULL COMMENT 'Hubei province or prefecture-level region',
+ report_date DATE NOT NULL COMMENT 'Report date from cell L3',
+ item_code VARCHAR(10) NOT NULL COMMENT 'H202 indicator code 01-93',
+ item_name VARCHAR(200) NOT NULL COMMENT 'Indicator name inherited from the matrix row',
+ unit VARCHAR(20) NULL COMMENT 'Measurement unit',
+ total_value DECIMAL(30,15) NULL,
+ individual_value DECIMAL(30,15) NULL,
+ large_value DECIMAL(30,15) NULL,
+ large_heavy_value DECIMAL(30,15) NULL,
+ large_heavy_individual_value DECIMAL(30,15) NULL,
+ large_individual_value DECIMAL(30,15) NULL,
+ medium_value DECIMAL(30,15) NULL,
+ medium_individual_value DECIMAL(30,15) NULL,
+ small_value DECIMAL(30,15) NULL,
+ small_individual_value DECIMAL(30,15) NULL,
+ source_file_name VARCHAR(255) NULL COMMENT 'Source workbook file name',
+ import_batch_id BIGINT NULL COMMENT 'Import batch id',
+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ UNIQUE KEY uk_h202_period_region_item (report_period, region_name, item_code),
+ KEY idx_h202_period_region (report_period, region_name)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='H202 highway freight operating vehicle ownership';
diff --git "a/docs/\350\264\247\350\277\220/RP_JTB_FreightVehicle_\345\205\250\347\234\201.xlsx" "b/docs/\350\264\247\350\277\220/RP_JTB_FreightVehicle_\345\205\250\347\234\201.xlsx"
new file mode 100644
index 0000000..4e9ae98
--- /dev/null
+++ "b/docs/\350\264\247\350\277\220/RP_JTB_FreightVehicle_\345\205\250\347\234\201.xlsx"
Binary files differ
diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataImportController.java b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataImportController.java
index fb76ba4..672845c 100644
--- a/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataImportController.java
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataImportController.java
@@ -42,6 +42,20 @@
}
}
+ /** H202 highway freight operating vehicle ownership. */
+ @PostMapping("/h202")
+ public Result<String> importH202(@RequestParam("file") MultipartFile file,
+ @RequestParam("period") String period) {
+ try {
+ ImportResult result = importService.importH202(file, period);
+ return Result.ok("\u516c\u8def\u8d27\u7269\u8425\u8fd0\u8f66\u8f86\u62e5\u6709\u60c5\u51b5(H202)\u5bfc\u5165\u6210\u529f\uff0c\u5171 "
+ + result.getSuccess() + " \u4e2a\u6307\u6807");
+ } catch (Exception e) {
+ log.error("H202 import error", e);
+ return Result.error("\u5bfc\u5165\u5931\u8d25: " + e.getMessage());
+ }
+ }
+
private String buildH2032Message(ImportResult r) {
if (r.getFail() == 0) {
return "H2032鏈堟姤瀵煎叆鎴愬姛锛屽叡 " + r.getSuccess() + " 鏉¤褰�";
diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataViewController.java b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataViewController.java
index 1942f82..e5aa260 100644
--- a/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataViewController.java
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataViewController.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.trafficaudit.common.Result;
import com.trafficaudit.dataimport.entity.FreightTurnoverImport;
+import com.trafficaudit.dataimport.entity.H202FreightVehicleOwnership;
import com.trafficaudit.dataimport.entity.H2032EnterpriseMonthly;
import com.trafficaudit.dataimport.entity.PassengerAuthVehicle;
import com.trafficaudit.dataimport.entity.CityBusMonthly;
@@ -27,6 +28,7 @@
import com.trafficaudit.dataimport.service.CityRollupService;
import javax.servlet.http.HttpServletResponse;
import com.trafficaudit.dataimport.mapper.FreightTurnoverImportMapper;
+import com.trafficaudit.dataimport.mapper.H202FreightVehicleOwnershipMapper;
import com.trafficaudit.dataimport.mapper.H2032EnterpriseMonthlyMapper;
import com.trafficaudit.dataimport.mapper.PassengerAuthVehicleMapper;
import com.trafficaudit.dataimport.mapper.CityBusMonthlyMapper;
@@ -66,6 +68,8 @@
@Resource
private H2032EnterpriseMonthlyMapper h2032Mapper;
+ @Resource
+ private H202FreightVehicleOwnershipMapper h202Mapper;
@Resource
private TransportAuthVehicleMapper transportAuthMapper;
@Resource
@@ -121,6 +125,22 @@
result.put("columns", columnsOf(type));
switch (type) {
+ case "h202": {
+ LambdaQueryWrapper<H202FreightVehicleOwnership> w = new LambdaQueryWrapper<H202FreightVehicleOwnership>()
+ .eq(notEmpty(period), H202FreightVehicleOwnership::getReportPeriod, period)
+ .and(!kw.isEmpty(), q -> q.like(H202FreightVehicleOwnership::getRegionName, kw)
+ .or().like(H202FreightVehicleOwnership::getItemName, kw)
+ .or().like(H202FreightVehicleOwnership::getItemCode, kw))
+ .orderByAsc(H202FreightVehicleOwnership::getRegionName)
+ .orderByAsc(H202FreightVehicleOwnership::getItemCode);
+ Page<H202FreightVehicleOwnership> p = new Page<>(safePage, safeSize);
+ Page<H202FreightVehicleOwnership> r = h202Mapper.selectPage(p, w);
+ List<Map<String, Object>> rows = toMaps(r.getRecords(), propsOf(H202_COLUMNS));
+ stringifyH202Decimals(rows);
+ result.put("records", rows);
+ fillPage(result, r);
+ break;
+ }
case "h2032": {
LambdaQueryWrapper<H2032EnterpriseMonthly> w = new LambdaQueryWrapper<H2032EnterpriseMonthly>()
.eq(notEmpty(period), H2032EnterpriseMonthly::getReportPeriod, period)
@@ -369,7 +389,23 @@
return Result.ok(result);
}
- /** 鍖哄垝浠g爜 -> 甯傚窞鍚嶏紙鏃犳硶璇嗗埆杩斿洖绌轰覆锛� */
+ /** Keep H202 decimal values as exact JSON strings instead of routing through JavaScript Number. */
+ private void stringifyH202Decimals(List<Map<String, Object>> rows) {
+ String[] props = {"totalValue", "individualValue", "largeValue", "largeHeavyValue",
+ "largeHeavyIndividualValue", "largeIndividualValue", "mediumValue",
+ "mediumIndividualValue", "smallValue", "smallIndividualValue"};
+ for (Map<String, Object> row : rows) {
+ for (String prop : props) {
+ Object value = row.get(prop);
+ if (value instanceof java.math.BigDecimal) {
+ String plain = ((java.math.BigDecimal) value).stripTrailingZeros().toPlainString();
+ row.put(prop, "0".equals(plain) ? "0" : plain);
+ }
+ }
+ }
+ }
+
+ /** \u533a\u5212\u4ee3\u7801 -> \u5e02\u5dde\u540d\uff08\u65e0\u6cd5\u8bc6\u522b\u8fd4\u56de\u7a7a\u4e32\uff09 */
private String cityOf(String regionCode) {
if (regionCode == null || regionCode.trim().isEmpty()) return "";
String city = RegionUtil.cityByCode(regionCode.trim());
@@ -536,6 +572,7 @@
private List<Map<String, Object>> columnsOf(String type) {
switch (type) {
case "h2032": return H2032_COLUMNS;
+ case "h202": return H202_COLUMNS;
case "transportAuth": return AUTH_COLUMNS;
case "trackMileage": return TRACK_COLUMNS;
case "scaleSplit": return SPLIT_COLUMNS;
@@ -567,6 +604,7 @@
}
private static final List<Map<String, Object>> H2032_COLUMNS = new ArrayList<>();
+ private static final List<Map<String, Object>> H202_COLUMNS = new ArrayList<>();
private static final List<Map<String, Object>> AUTH_COLUMNS = new ArrayList<>();
private static final List<Map<String, Object>> TRACK_COLUMNS = new ArrayList<>();
private static final List<Map<String, Object>> SPLIT_COLUMNS = new ArrayList<>();
@@ -586,7 +624,23 @@
private static final List<Map<String, Object>> WYC_ORDER_COLUMNS = new ArrayList<>();
static {
- H2032_COLUMNS.add(col("reportPeriod", "鎶ヨ〃鏈�", 100));
+ H202_COLUMNS.add(col("reportPeriod", "\u62a5\u8868\u671f", 100));
+ H202_COLUMNS.add(col("regionName", "\u5730\u533a", 120));
+ H202_COLUMNS.add(col("reportDate", "\u62a5\u8868\u65e5\u671f", 110));
+ H202_COLUMNS.add(col("itemCode", "\u6307\u6807\u4ee3\u7801", 90));
+ H202_COLUMNS.add(col("itemName", "\u6307\u6807\u540d\u79f0", 240));
+ H202_COLUMNS.add(col("unit", "\u8ba1\u91cf\u5355\u4f4d", 90));
+ H202_COLUMNS.add(col("totalValue", "\u603b\u8ba1", 130));
+ H202_COLUMNS.add(col("individualValue", "\u4e2a\u4f53", 130));
+ H202_COLUMNS.add(col("largeValue", "\u5927\u578b", 120));
+ H202_COLUMNS.add(col("largeHeavyValue", "\u5927\u578b-\u91cd\u578b", 130));
+ H202_COLUMNS.add(col("largeHeavyIndividualValue", "\u5927\u578b-\u91cd\u578b-\u4e2a\u4f53", 160));
+ H202_COLUMNS.add(col("largeIndividualValue", "\u5927\u578b-\u4e2a\u4f53", 130));
+ H202_COLUMNS.add(col("mediumValue", "\u4e2d\u578b", 120));
+ H202_COLUMNS.add(col("mediumIndividualValue", "\u4e2d\u578b-\u4e2a\u4f53", 130));
+ H202_COLUMNS.add(col("smallValue", "\u5c0f\u578b", 120));
+ H202_COLUMNS.add(col("smallIndividualValue", "\u5c0f\u578b-\u4e2a\u4f53", 130));
+ H2032_COLUMNS.add(col("reportPeriod", "\u62a5\u8868\u671f", 100));
H2032_COLUMNS.add(col("regionCode", "鎵�灞炲湴鍖�", 100));
H2032_COLUMNS.add(col("city", "甯傚窞", 110));
H2032_COLUMNS.add(col("enterpriseCode", "浼佷笟浠g爜", 130));
diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/entity/H202FreightVehicleOwnership.java b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/entity/H202FreightVehicleOwnership.java
new file mode 100644
index 0000000..ac4a4bf
--- /dev/null
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/entity/H202FreightVehicleOwnership.java
@@ -0,0 +1,40 @@
+package com.trafficaudit.dataimport.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+/**
+ * H202 highway freight operating vehicle ownership matrix.
+ * One row represents one report period, region, and indicator code.
+ */
+@Data
+@TableName("h202_freight_vehicle_ownership")
+public class H202FreightVehicleOwnership {
+ @TableId(type = IdType.AUTO)
+ private Long id;
+ private String reportPeriod;
+ private String regionName;
+ private LocalDate reportDate;
+ private String itemCode;
+ private String itemName;
+ private String unit;
+ private BigDecimal totalValue;
+ private BigDecimal individualValue;
+ private BigDecimal largeValue;
+ private BigDecimal largeHeavyValue;
+ private BigDecimal largeHeavyIndividualValue;
+ private BigDecimal largeIndividualValue;
+ private BigDecimal mediumValue;
+ private BigDecimal mediumIndividualValue;
+ private BigDecimal smallValue;
+ private BigDecimal smallIndividualValue;
+ private String sourceFileName;
+ private Long importBatchId;
+ private LocalDateTime createdAt;
+}
diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/mapper/H202FreightVehicleOwnershipMapper.java b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/mapper/H202FreightVehicleOwnershipMapper.java
new file mode 100644
index 0000000..71a5571
--- /dev/null
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/mapper/H202FreightVehicleOwnershipMapper.java
@@ -0,0 +1,8 @@
+package com.trafficaudit.dataimport.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.trafficaudit.dataimport.entity.H202FreightVehicleOwnership;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface H202FreightVehicleOwnershipMapper extends BaseMapper<H202FreightVehicleOwnership> {}
diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/service/DataImportService.java b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/service/DataImportService.java
index fceec17..f7fa8e8 100644
--- a/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/service/DataImportService.java
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/service/DataImportService.java
@@ -11,6 +11,7 @@
import com.trafficaudit.dataimport.entity.EnergyAuthVehicle;
import com.trafficaudit.dataimport.entity.EnergyVehicleQuarterly;
import com.trafficaudit.dataimport.entity.FreightTurnoverImport;
+import com.trafficaudit.dataimport.entity.H202FreightVehicleOwnership;
import com.trafficaudit.dataimport.entity.H2032EnterpriseMonthly;
import com.trafficaudit.dataimport.entity.PassengerAuthVehicle;
import com.trafficaudit.dataimport.entity.PassengerEnterpriseMonthly;
@@ -30,6 +31,7 @@
import com.trafficaudit.dataimport.mapper.EnergyAuthVehicleMapper;
import com.trafficaudit.dataimport.mapper.EnergyVehicleQuarterlyMapper;
import com.trafficaudit.dataimport.mapper.FreightTurnoverImportMapper;
+import com.trafficaudit.dataimport.mapper.H202FreightVehicleOwnershipMapper;
import com.trafficaudit.dataimport.mapper.H2032EnterpriseMonthlyMapper;
import com.trafficaudit.dataimport.mapper.PassengerAuthVehicleMapper;
import com.trafficaudit.dataimport.mapper.PassengerEnterpriseMonthlyMapper;
@@ -114,6 +116,8 @@
@Resource
private H2032EnterpriseMonthlyMapper h2032Mapper;
+ @Resource
+ private H202FreightVehicleOwnershipMapper h202Mapper;
@Resource
private TransportAuthVehicleMapper transportAuthMapper;
@Resource
@@ -1121,6 +1125,146 @@
return val == null ? null : val.intValue();
}
+
+ // ========== H202 highway freight vehicle ownership ==========
+
+ /** Imports one regional H202 workbook and atomically replaces that region's report period. */
+ public ImportResult importH202(MultipartFile file, String period) throws Exception {
+ H202WorkbookParser.ParsedWorkbook parsed;
+ try (Workbook wb = WorkbookFactory.create(file.getInputStream())) {
+ parsed = H202WorkbookParser.parse(wb, file.getOriginalFilename(), period);
+ }
+ int success = replaceH202Rows(parsed);
+ Long batchId = recordBatch(file.getOriginalFilename(), "H202", period, parsed.getRows().size(), success, 0, null);
+ attachBatchId("h202_freight_vehicle_ownership", period, batchId);
+ log.info("H202 imported: region={}, period={}, rows={}", parsed.getRegionName(), period, success);
+ return new ImportResult(success, 0, new ArrayList<String>());
+ }
+
+ /** Batch H202 import: parse every file first; duplicate regions are rejected as a whole group. */
+ public Map<String, Object> importH202BatchFiles(String period, List<MultipartFile> files) throws Exception {
+ List<Map<String, Object>> fileResults = new ArrayList<Map<String, Object>>();
+ List<H202ParsedFile> parsedFiles = new ArrayList<H202ParsedFile>();
+ int totalSuccess = 0;
+ int totalFail = 0;
+
+ for (MultipartFile file : files) {
+ Map<String, Object> fileResult = new LinkedHashMap<String, Object>();
+ fileResult.put("fileName", file.getOriginalFilename());
+ try (Workbook wb = WorkbookFactory.create(file.getInputStream())) {
+ H202WorkbookParser.ParsedWorkbook parsed = H202WorkbookParser.parse(
+ wb, file.getOriginalFilename(), period);
+ fileResult.put("city", parsed.getRegionName());
+ fileResult.put("period", period);
+ parsedFiles.add(new H202ParsedFile(file.getOriginalFilename(), parsed, fileResult));
+ } catch (Exception e) {
+ markH202FileFailure(fileResult, e);
+ totalFail++;
+ }
+ fileResults.add(fileResult);
+ }
+
+ Map<String, List<H202ParsedFile>> regionGroups = new LinkedHashMap<String, List<H202ParsedFile>>();
+ for (H202ParsedFile item : parsedFiles) {
+ String region = item.parsed.getRegionName();
+ List<H202ParsedFile> group = regionGroups.get(region);
+ if (group == null) {
+ group = new ArrayList<H202ParsedFile>();
+ regionGroups.put(region, group);
+ }
+ group.add(item);
+ }
+
+ List<H202ParsedFile> importable = new ArrayList<H202ParsedFile>();
+ for (Map.Entry<String, List<H202ParsedFile>> entry : regionGroups.entrySet()) {
+ List<H202ParsedFile> group = entry.getValue();
+ if (group.size() == 1) {
+ importable.add(group.get(0));
+ continue;
+ }
+ List<String> names = new ArrayList<String>();
+ for (H202ParsedFile item : group) {
+ names.add(item.fileName);
+ }
+ String message = "\u540c\u4e00\u6279\u6b21\u4e2d\u5730\u533a\u3010" + entry.getKey()
+ + "\u3011\u91cd\u590d\uff1a" + String.join("\u3001", names)
+ + "\uff1b\u4e3a\u907f\u514d\u91cd\u590d\u8986\u76d6\uff0c\u8be5\u7ec4\u6587\u4ef6\u5747\u672a\u5bfc\u5165";
+ for (H202ParsedFile item : group) {
+ markH202FileFailure(item.fileResult, message);
+ totalFail++;
+ }
+ }
+
+ for (H202ParsedFile item : importable) {
+ try {
+ int success = replaceH202Rows(item.parsed);
+ Long batchId = recordBatch(item.fileName, "H202", period, item.parsed.getRows().size(), success, 0, null);
+ attachBatchId("h202_freight_vehicle_ownership", period, batchId);
+ item.fileResult.put("success", success);
+ item.fileResult.put("fail", 0);
+ totalSuccess += success;
+ } catch (Exception e) {
+ markH202FileFailure(item.fileResult, e);
+ totalFail++;
+ log.error("H202 batch import error: file={}", item.fileName, e);
+ }
+ }
+
+ Map<String, Object> result = new LinkedHashMap<String, Object>();
+ result.put("type", "h202");
+ result.put("total", files.size());
+ result.put("success", totalSuccess);
+ result.put("fail", totalFail);
+ result.put("files", fileResults);
+ return result;
+ }
+
+ private void markH202FileFailure(Map<String, Object> fileResult, Exception error) {
+ String message = error.getMessage() == null ? error.toString() : error.getMessage();
+ markH202FileFailure(fileResult, message);
+ }
+
+ private void markH202FileFailure(Map<String, Object> fileResult, String message) {
+ fileResult.put("success", 0);
+ fileResult.put("fail", 1);
+ fileResult.put("error", message);
+ }
+
+ private int replaceH202Rows(H202WorkbookParser.ParsedWorkbook parsed) {
+ String period = parsed.getRows().isEmpty() ? null : parsed.getRows().get(0).getReportPeriod();
+ String region = parsed.getRegionName();
+ try (SqlSession session = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
+ try {
+ H202FreightVehicleOwnershipMapper batchMapper = session.getMapper(H202FreightVehicleOwnershipMapper.class);
+ batchMapper.delete(new LambdaQueryWrapper<H202FreightVehicleOwnership>()
+ .eq(H202FreightVehicleOwnership::getReportPeriod, period)
+ .eq(H202FreightVehicleOwnership::getRegionName, region));
+ for (H202FreightVehicleOwnership row : parsed.getRows()) {
+ batchMapper.insert(row);
+ }
+ session.flushStatements();
+ session.commit();
+ return parsed.getRows().size();
+ } catch (Exception e) {
+ session.rollback();
+ throw e;
+ }
+ }
+ }
+
+ private static final class H202ParsedFile {
+ private final String fileName;
+ private final H202WorkbookParser.ParsedWorkbook parsed;
+ private final Map<String, Object> fileResult;
+
+ private H202ParsedFile(String fileName, H202WorkbookParser.ParsedWorkbook parsed,
+ Map<String, Object> fileResult) {
+ this.fileName = fileName;
+ this.parsed = parsed;
+ this.fileResult = fileResult;
+ }
+ }
+
// ========== 杩愭斂杞﹁締 ==========
/** 杩愭斂杞﹁締瀵煎叆锛氫笌 H203-2 鏈堟姤涓�鑷达紝鎸夎〃澶村悕绉板畾浣嶅垪锛屽垪椤哄簭鍙樺寲涔熻兘姝g‘瀵煎叆 */
@@ -1759,6 +1903,7 @@
static {
CLEAR_TYPE_TO_OP.put("h2032", "H2032");
+ CLEAR_TYPE_TO_OP.put("h202", "H202");
CLEAR_TYPE_TO_OP.put("transportAuth", "TRANSPORT_AUTH");
CLEAR_TYPE_TO_OP.put("trackMileage", "TRACK_MILEAGE");
CLEAR_TYPE_TO_OP.put("scaleSplit", "SCALE_SPLIT");
@@ -1802,6 +1947,7 @@
String[] investPassengerBatch = {"INVEST_瀹㈣繍绔欏満", "INVEST_瀹㈣繍绔欏満_CITY"};
String[] investLogisticsBatch = {"INVEST_鐗╂祦鍥尯", "INVEST_鐗╂祦鍥尯_CITY"};
CLEAR_TYPE_TO_BATCH.put("h2032", new String[]{"H2032"});
+ CLEAR_TYPE_TO_BATCH.put("h202", new String[]{"H202"});
CLEAR_TYPE_TO_BATCH.put("transportAuth", new String[]{"TRANSPORT_AUTH"});
CLEAR_TYPE_TO_BATCH.put("trackMileage", new String[]{"TRACK_MILEAGE"});
CLEAR_TYPE_TO_BATCH.put("scaleSplit", new String[]{"SCALE_SPLIT"});
@@ -1848,6 +1994,8 @@
if (clearAll) {
dataRows += h2032Mapper.delete(new LambdaQueryWrapper<H2032EnterpriseMonthly>()
.eq(H2032EnterpriseMonthly::getReportPeriod, period));
+ dataRows += h202Mapper.delete(new LambdaQueryWrapper<H202FreightVehicleOwnership>()
+ .eq(H202FreightVehicleOwnership::getReportPeriod, period));
dataRows += transportAuthMapper.delete(new LambdaQueryWrapper<TransportAuthVehicle>()
.eq(TransportAuthVehicle::getReportPeriod, period));
dataRows += trackMileageMapper.delete(new LambdaQueryWrapper<VehicleTrackMileage>()
@@ -1951,6 +2099,9 @@
case "H2032":
return h2032Mapper.delete(new LambdaQueryWrapper<H2032EnterpriseMonthly>()
.eq(H2032EnterpriseMonthly::getReportPeriod, period));
+ case "H202":
+ return h202Mapper.delete(new LambdaQueryWrapper<H202FreightVehicleOwnership>()
+ .eq(H202FreightVehicleOwnership::getReportPeriod, period));
case "TRANSPORT_AUTH":
return transportAuthMapper.delete(new LambdaQueryWrapper<TransportAuthVehicle>()
.eq(TransportAuthVehicle::getReportPeriod, period));
@@ -2661,6 +2812,9 @@
public Map<String, Object> importBatchFiles(String type, String period, List<MultipartFile> files) throws Exception {
if (files == null || files.isEmpty()) {
throw new RuntimeException("鏈帴鏀跺埌浠讳綍鏂囦欢");
+ }
+ if ("h202".equals(type)) {
+ return importH202BatchFiles(period, files);
}
if ("investment".equals(type) || "investmentLogistics".equals(type)) {
String category = "investment".equals(type) ? "瀹㈣繍绔欏満" : "鐗╂祦鍥尯";
@@ -4464,6 +4618,7 @@
private ImportResult importDirFile(String type, MultipartFile file, String period) throws Exception {
switch (type) {
case "h2032": return importH2032(file, period);
+ case "h202": return importH202(file, period);
case "passengerMonthly": return importPassengerMonthly(file, period);
case "passengerIndividual": return importPassengerIndividual(file, period);
case "passengerAuth": return importPassengerAuth(file, period);
diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/service/H202WorkbookParser.java b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/service/H202WorkbookParser.java
new file mode 100644
index 0000000..a13f047
--- /dev/null
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/service/H202WorkbookParser.java
@@ -0,0 +1,397 @@
+package com.trafficaudit.dataimport.service;
+
+import com.trafficaudit.common.util.RegionUtil;
+import com.trafficaudit.dataimport.entity.H202FreightVehicleOwnership;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.usermodel.DateUtil;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Strict parser for the transport authority H202 workbook.
+ * Excel numbers are read from the raw XLSX decimal text before BigDecimal.
+ */
+public final class H202WorkbookParser {
+ public static final String TYPE_LABEL = "\u516c\u8def\u8d27\u7269\u8425\u8fd0\u8f66\u8f86\u62e5\u6709\u60c5\u51b5(H202)";
+ public static final String SHEET_NAME = "RP_JTB_FreightVehicle";
+ private static final String TITLE = "\u516c\u8def\u8d27\u7269\u8425\u8fd0\u8f66\u8f86\u62e5\u6709\u60c5\u51b5";
+ private static final ThreadLocal<DataFormatter> FORMATTER = new ThreadLocal<DataFormatter>() {
+ @Override
+ protected DataFormatter initialValue() {
+ return new DataFormatter();
+ }
+ };
+ private static final Pattern FILE_REGION = Pattern.compile(
+ "^RP_JTB_FreightVehicle_(.+?)\\.xlsx$", Pattern.CASE_INSENSITIVE);
+ private static final Pattern DATE_PATTERN = Pattern.compile(
+ "(\\d{4})\\s*[/.-]\\s*(\\d{1,2})\\s*[/.-]\\s*(\\d{1,2})");
+ private static final String[] COLUMN_LABELS = {
+ "\u603b\u8ba1", "\u4e2a\u4f53", "\u5927\u578b", "\u5927\u578b-\u91cd\u578b",
+ "\u5927\u578b-\u91cd\u578b-\u4e2a\u4f53", "\u5927\u578b-\u4e2a\u4f53", "\u4e2d\u578b",
+ "\u4e2d\u578b-\u4e2a\u4f53", "\u5c0f\u578b", "\u5c0f\u578b-\u4e2a\u4f53"
+ };
+
+ private H202WorkbookParser() {
+ }
+
+ public static ParsedWorkbook parse(Workbook workbook, String fileName, String reportPeriod) {
+ if (workbook == null) {
+ throw new IllegalArgumentException("\u672a\u63d0\u4f9b H202 \u5de5\u4f5c\u7c3f");
+ }
+ Sheet sheet = workbook.getSheet(SHEET_NAME);
+ if (sheet == null) {
+ throw new IllegalArgumentException(TYPE_LABEL + " \u4e0e\u6587\u4ef6\u5185\u5bb9\u4e0d\u7b26\uff1a\u672a\u627e\u5230 sheet\u3010"
+ + SHEET_NAME + "\u3011");
+ }
+ Row titleRow = sheet.getRow(1);
+ String title = text(titleRow == null ? null : titleRow.getCell(0));
+ if (!TITLE.equals(title)) {
+ throw new IllegalArgumentException(TYPE_LABEL + " \u4e0e\u6587\u4ef6\u5185\u5bb9\u4e0d\u7b26\uff1aA2 \u5e94\u4e3a\u3010"
+ + TITLE + "\u3011\uff0c\u5b9e\u9645\u4e3a\u3010" + title + "\u3011");
+ }
+ validateHeaders(sheet);
+ String regionName = regionFromFileName(fileName);
+ Row metaRow = sheet.getRow(2);
+ LocalDate reportDate = parseReportDate(metaRow == null ? null : metaRow.getCell(11));
+ if (reportDate == null) {
+ throw new IllegalArgumentException("\u672a\u8bfb\u53d6\u5230\u62a5\u8868\u65e5\u671f\uff0c\u8bf7\u68c0\u67e5 L3 \u5355\u5143\u683c\uff1a\u5e94\u4e3a\u300c\u62a5\u8868\u65e5\u671f\uff1a2026/9/30\u300d");
+ }
+ String reportMonth = String.format("%04d-%02d", reportDate.getYear(), reportDate.getMonthValue());
+ if (reportPeriod == null || !reportPeriod.matches("\\d{4}-\\d{2}")) {
+ throw new IllegalArgumentException("\u62a5\u8868\u671f\u683c\u5f0f\u4e0d\u6b63\u786e\uff0c\u5e94\u4e3a yyyy-MM");
+ }
+ if (!reportPeriod.equals(reportMonth)) {
+ throw new IllegalArgumentException("\u6587\u4ef6\u62a5\u8868\u65e5\u671f " + reportDate
+ + " \u4e0e\u6240\u9009\u62a5\u8868\u671f " + reportPeriod + " \u4e0d\u4e00\u81f4");
+ }
+
+ List<H202FreightVehicleOwnership> rows = new ArrayList<H202FreightVehicleOwnership>();
+ Set<String> seenCodes = new LinkedHashSet<String>();
+ String currentItemName = null;
+ for (int rowIndex = 8; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
+ Row row = sheet.getRow(rowIndex);
+ if (row == null) {
+ continue;
+ }
+ String code = normalizeCode(text(row.getCell(2)));
+ boolean hasValue = hasAnyValue(row);
+ if (code.isEmpty()) {
+ if (hasValue) {
+ throw new IllegalArgumentException("\u7b2c " + (rowIndex + 1)
+ + " \u884c\u6709\u6570\u503c\u4f46\u6307\u6807\u4ee3\u7801\u4e3a\u7a7a");
+ }
+ continue;
+ }
+ if (!code.matches("\\d{2}")) {
+ throw new IllegalArgumentException("\u7b2c " + (rowIndex + 1)
+ + " \u884c\u6307\u6807\u4ee3\u7801\u4e0d\u5408\u6cd5\uff1a" + code);
+ }
+ if (!seenCodes.add(code)) {
+ throw new IllegalArgumentException("\u6307\u6807\u4ee3\u7801 " + code + " \u5728\u7b2c "
+ + (rowIndex + 1) + " \u884c\u91cd\u590d");
+ }
+ String sourceName = text(row.getCell(0));
+ if (!sourceName.isEmpty()) {
+ currentItemName = sourceName;
+ }
+ if (currentItemName == null || currentItemName.isEmpty()) {
+ throw new IllegalArgumentException("\u7b2c " + (rowIndex + 1)
+ + " \u884c\u6307\u6807\u540d\u79f0\u4e3a\u7a7a\uff0c\u4e14\u65e0\u4e0a\u65b9\u6307\u6807\u540d\u53ef\u7ee7\u627f");
+ }
+
+ H202FreightVehicleOwnership entity = new H202FreightVehicleOwnership();
+ entity.setReportPeriod(reportPeriod);
+ entity.setRegionName(regionName);
+ entity.setReportDate(reportDate);
+ entity.setItemCode(code);
+ entity.setItemName(currentItemName);
+ entity.setUnit(text(row.getCell(1)));
+ entity.setSourceFileName(fileName);
+ entity.setTotalValue(decimal(row, 3));
+ entity.setIndividualValue(decimal(row, 4));
+ entity.setLargeValue(decimal(row, 5));
+ entity.setLargeHeavyValue(decimal(row, 6));
+ entity.setLargeHeavyIndividualValue(decimal(row, 7));
+ entity.setLargeIndividualValue(decimal(row, 8));
+ entity.setMediumValue(decimal(row, 9));
+ entity.setMediumIndividualValue(decimal(row, 10));
+ entity.setSmallValue(decimal(row, 11));
+ entity.setSmallIndividualValue(decimal(row, 12));
+ rows.add(entity);
+ }
+
+ validateContiguousCodes(seenCodes);
+ recomputeTotals(rows);
+ return new ParsedWorkbook(regionName, reportDate, rows);
+ }
+
+ private static void validateContiguousCodes(Set<String> seenCodes) {
+ int expected = 1;
+ for (String code : seenCodes) {
+ String expectedCode = String.format("%02d", expected);
+ if (!expectedCode.equals(code)) {
+ throw new IllegalArgumentException("H202 \u6307\u6807\u4ee3\u7801\u5fc5\u987b\u4ece 01 \u5f00\u59cb\u8fde\u7eed\uff1a"
+ + "\u671f\u671b " + expectedCode + "\uff0c\u5b9e\u9645 " + code);
+ }
+ expected++;
+ }
+ if (expected <= 2) {
+ throw new IllegalArgumentException("H202 \u6307\u6807\u4ee3\u7801\u4e0d\u5b8c\u6574");
+ }
+ }
+
+ private static void recomputeTotals(List<H202FreightVehicleOwnership> rows) {
+ H202FreightVehicleOwnership vehicleTotal = requireCode(rows, "01", "\u603b\u8ba1", "\u8f86");
+ H202FreightVehicleOwnership tonnageTotal = requireCode(rows, "02", "\u603b\u8ba1", "\u5428\u4f4d");
+ H202FreightVehicleOwnership truckVehicle = requireItem(rows, "1.\u8d27\u8f66", "\u8f86");
+ H202FreightVehicleOwnership tractorVehicle = requireItem(rows, "2.\u7275\u5f15\u8f66", "\u8f86");
+ H202FreightVehicleOwnership trailerVehicle = requireItem(rows, "3.\u6302\u8f66", "\u8f86");
+ H202FreightVehicleOwnership otherVehicle = requireItem(rows, "\u4e8c\u3001\u5176\u5b83\u8f7d\u8d27\u673a\u52a8\u8f66", "\u8f86");
+ H202FreightVehicleOwnership truckTonnage = requireItem(rows, "1.\u8d27\u8f66", "\u5428\u4f4d");
+ H202FreightVehicleOwnership trailerTonnage = requireItem(rows, "3.\u6302\u8f66", "\u5428\u4f4d");
+ H202FreightVehicleOwnership otherTonnage = requireItem(rows, "\u4e8c\u3001\u5176\u5b83\u8f7d\u8d27\u673a\u52a8\u8f66", "\u5428\u4f4d");
+
+ vehicleTotal.setTotalValue(addRequired(vehicleTotal,
+ new H202FreightVehicleOwnership[]{truckVehicle, tractorVehicle, trailerVehicle, otherVehicle}));
+ tonnageTotal.setTotalValue(addRequired(tonnageTotal,
+ new H202FreightVehicleOwnership[]{truckTonnage, trailerTonnage, otherTonnage}));
+ }
+
+ private static H202FreightVehicleOwnership requireCode(List<H202FreightVehicleOwnership> rows,
+ String code, String itemName, String unit) {
+ H202FreightVehicleOwnership found = null;
+ for (H202FreightVehicleOwnership row : rows) {
+ if (!code.equals(row.getItemCode())) {
+ continue;
+ }
+ if (found != null) {
+ throw new IllegalArgumentException("H202 \u6307\u6807\u4ee3\u7801\u91cd\u590d\uff1a" + code);
+ }
+ found = row;
+ }
+ if (found == null) {
+ throw new IllegalArgumentException("H202 \u7f3a\u5c11\u603b\u8ba1\u6307\u6807\uff1a" + code);
+ }
+ if (!itemName.equals(found.getItemName()) || !unit.equals(found.getUnit())) {
+ throw new IllegalArgumentException("H202 \u6307\u6807 " + code + " \u7684\u540d\u79f0\u6216\u5355\u4f4d\u4e0d\u7b26\uff1a"
+ + found.getItemName() + "/" + found.getUnit());
+ }
+ return found;
+ }
+
+ private static H202FreightVehicleOwnership requireItem(List<H202FreightVehicleOwnership> rows,
+ String itemName, String unit) {
+ H202FreightVehicleOwnership found = null;
+ for (H202FreightVehicleOwnership row : rows) {
+ if (!itemName.equals(row.getItemName()) || !unit.equals(row.getUnit())) {
+ continue;
+ }
+ if (found != null) {
+ throw new IllegalArgumentException("H202 \u5206\u9879\u6307\u6807\u91cd\u590d\uff1a" + itemName + "/" + unit);
+ }
+ found = row;
+ }
+ if (found == null) {
+ throw new IllegalArgumentException("H202 \u7f3a\u5c11\u5206\u9879\u6307\u6807\uff1a" + itemName + "/" + unit);
+ }
+ return found;
+ }
+
+ private static BigDecimal addRequired(H202FreightVehicleOwnership totalRow,
+ H202FreightVehicleOwnership[] parts) {
+ BigDecimal sum = BigDecimal.ZERO;
+ for (H202FreightVehicleOwnership part : parts) {
+ if (part.getTotalValue() == null) {
+ throw new IllegalArgumentException("H202 \u5206\u9879\u603b\u8ba1\u4e3a\u7a7a\uff0c\u65e0\u6cd5\u91cd\u7b97\uff1a"
+ + part.getItemCode() + " " + part.getItemName() + "/" + part.getUnit());
+ }
+ sum = sum.add(part.getTotalValue());
+ }
+ if (sum.scale() < 0) {
+ sum = sum.setScale(0);
+ }
+ return sum.stripTrailingZeros();
+ }
+
+ public static String regionFromFileName(String fileName) {
+ if (fileName == null) {
+ throw new IllegalArgumentException("\u6587\u4ef6\u540d\u4e3a\u7a7a\uff0c\u65e0\u6cd5\u8bc6\u522b\u5730\u533a");
+ }
+ String baseName = new java.io.File(fileName).getName();
+ Matcher matcher = FILE_REGION.matcher(baseName);
+ if (!matcher.matches()) {
+ throw new IllegalArgumentException("\u6587\u4ef6\u540d\u4e0d\u7b26\u5408 H202 \u547d\u540d\u89c4\u5219\uff1aRP_JTB_FreightVehicle_\u5730\u533a.xlsx");
+ }
+ String region = RegionUtil.normalizeCityName(matcher.group(1));
+ if (!"\u6e56\u5317\u7701".equals(region) && !RegionUtil.CITY_LIST.contains(region)) {
+ throw new IllegalArgumentException("\u65e0\u6cd5\u4ece\u6587\u4ef6\u540d\u8bc6\u522b\u6e56\u5317\u7701\u6216 17 \u4e2a\u5e02\u5dde\uff1a"
+ + matcher.group(1));
+ }
+ return region;
+ }
+
+ private static void validateHeaders(Sheet sheet) {
+ Row header = sheet.getRow(4);
+ String[] expected = {"\u6307\u6807\u540d\u79f0", "\u8ba1\u91cf", "\u4ee3\u7801", "\u603b\u8ba1", "\u4e2a\u4f53",
+ "\u5927\u578b", "", "", "", "\u4e2d\u578b", "", "\u5c0f\u578b", ""};
+ for (int col = 0; col < expected.length; col++) {
+ if (expected[col].isEmpty()) {
+ continue;
+ }
+ String actual = text(header == null ? null : header.getCell(col));
+ if (!expected[col].equals(actual)) {
+ throw new IllegalArgumentException(TYPE_LABEL + " \u8868\u5934\u4e0e\u6a21\u677f\u4e0d\u4e00\u81f4\uff1a"
+ + CellReference.convertNumToColString(col) + "5 \u5e94\u4e3a\u3010" + expected[col]
+ + "\u3011\uff0c\u5b9e\u9645\u4e3a\u3010" + actual + "\u3011");
+ }
+ }
+ }
+
+ private static boolean hasAnyValue(Row row) {
+ for (int col = 3; col <= 12; col++) {
+ Cell cell = row.getCell(col);
+ if (cell == null || cell.getCellType() == CellType.BLANK) {
+ continue;
+ }
+ String value = text(cell);
+ if (!value.isEmpty() && !isDash(value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static BigDecimal decimal(Row row, int col) {
+ Cell cell = row.getCell(col);
+ String label = COLUMN_LABELS[col - 3];
+ String itemName = text(row.getCell(0));
+ if (itemName.isEmpty() && row.getRowNum() > 0) {
+ itemName = text(row.getSheet().getRow(row.getRowNum() - 1).getCell(0));
+ }
+ String context = "\u7b2c " + (row.getRowNum() + 1) + " \u884c " + CellReference.convertNumToColString(col)
+ + " \u5217\u300c" + label + "\u300d" + (itemName.isEmpty() ? "" : "\uff08" + itemName + "\uff09");
+ if (cell == null || cell.getCellType() == CellType.BLANK) {
+ return null;
+ }
+ CellType type = cell.getCellType();
+ if (type == CellType.FORMULA) {
+ throw new IllegalArgumentException(context
+ + "\u4e0d\u652f\u6301\u516c\u5f0f\uff0c\u8bf7\u5c06\u5176\u8f6c\u4e3a\u6570\u503c\u6216\u6587\u672c\u540e\u518d\u5bfc\u5165");
+ }
+ if (type == CellType.NUMERIC) {
+ return parseDecimal(rawNumericText(cell, context), context);
+ }
+ if (type == CellType.STRING) {
+ return parseDecimal(cell.getStringCellValue(), context);
+ }
+ throw new IllegalArgumentException(context + "\u4e0d\u662f\u6709\u6548\u6570\u5b57\uff1a" + text(cell));
+ }
+
+ private static BigDecimal parseDecimal(String raw, String context) {
+ if (raw == null) {
+ return null;
+ }
+ String value = raw.trim();
+ if (value.isEmpty() || isDash(value)) {
+ return null;
+ }
+ String compact = value.replace(",", "").replace("\u00a0", "").replace(" ", "");
+ BigDecimal decimal;
+ try {
+ decimal = new BigDecimal(compact).stripTrailingZeros();
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(context + "\u4e0d\u662f\u6709\u6548\u6570\u5b57\uff1a" + value, e);
+ }
+ if (decimal.scale() < 0) {
+ decimal = decimal.setScale(0);
+ }
+ if (decimal.scale() > 15 || decimal.precision() - decimal.scale() > 15) {
+ throw new IllegalArgumentException(context + "\u8d85\u51fa DECIMAL(30,15) \u8303\u56f4\uff1a" + value);
+ }
+ return decimal;
+ }
+
+ private static String rawNumericText(Cell cell, String context) {
+ if (!(cell instanceof XSSFCell)) {
+ throw new IllegalArgumentException(context + "\u4ec5\u652f\u6301 .xlsx \u539f\u59cb\u6570\u503c\uff0c\u8bf7\u53e6\u5b58\u4e3a .xlsx");
+ }
+ String raw = ((XSSFCell) cell).getRawValue();
+ if (raw == null || raw.trim().isEmpty()) {
+ throw new IllegalArgumentException(context + "\u672a\u8bfb\u53d6\u5230\u539f\u59cb\u6570\u503c");
+ }
+ return raw;
+ }
+
+ private static LocalDate parseReportDate(Cell cell) {
+ if (cell == null) {
+ return null;
+ }
+ if (cell.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell)) {
+ return cell.getLocalDateTimeCellValue().toLocalDate();
+ }
+ String value = text(cell);
+ Matcher matcher = DATE_PATTERN.matcher(value);
+ if (!matcher.find()) {
+ return null;
+ }
+ return LocalDate.of(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)),
+ Integer.parseInt(matcher.group(3)));
+ }
+
+ private static boolean isDash(String value) {
+ return "-".equals(value) || "\u2014".equals(value) || "\u2013".equals(value);
+ }
+
+ private static String normalizeCode(String value) {
+ String code = value == null ? "" : value.trim();
+ if (code.matches("\\d")) {
+ return "0" + code;
+ }
+ return code;
+ }
+
+ private static String text(Cell cell) {
+ if (cell == null) {
+ return "";
+ }
+ return FORMATTER.get().formatCellValue(cell).trim();
+ }
+
+ public static final class ParsedWorkbook {
+ private final String regionName;
+ private final LocalDate reportDate;
+ private final List<H202FreightVehicleOwnership> rows;
+
+ ParsedWorkbook(String regionName, LocalDate reportDate, List<H202FreightVehicleOwnership> rows) {
+ this.regionName = regionName;
+ this.reportDate = reportDate;
+ this.rows = rows;
+ }
+
+ public String getRegionName() {
+ return regionName;
+ }
+
+ public LocalDate getReportDate() {
+ return reportDate;
+ }
+
+ public List<H202FreightVehicleOwnership> getRows() {
+ return rows;
+ }
+ }
+}
diff --git a/traffic-audit-server/src/test/java/com/trafficaudit/dataimport/service/H202WorkbookParserTest.java b/traffic-audit-server/src/test/java/com/trafficaudit/dataimport/service/H202WorkbookParserTest.java
new file mode 100644
index 0000000..01b7d79
--- /dev/null
+++ b/traffic-audit-server/src/test/java/com/trafficaudit/dataimport/service/H202WorkbookParserTest.java
@@ -0,0 +1,316 @@
+package com.trafficaudit.dataimport.service;
+
+import com.trafficaudit.dataimport.entity.H202FreightVehicleOwnership;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.Test;
+
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.LocalDate;
+import java.time.YearMonth;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class H202WorkbookParserTest {
+ private static final String SHEET = H202WorkbookParser.SHEET_NAME;
+ private static final String TITLE = "\u516c\u8def\u8d27\u7269\u8425\u8fd0\u8f66\u8f86\u62e5\u6709\u60c5\u51b5";
+ private static final String HEADER_NAME = "\u6307\u6807\u540d\u79f0";
+ private static final String HEADER_UNIT = "\u8ba1\u91cf";
+ private static final String HEADER_CODE = "\u4ee3\u7801";
+ private static final String HEADER_TOTAL = "\u603b\u8ba1";
+ private static final String HEADER_INDIVIDUAL = "\u4e2a\u4f53";
+ private static final String HEADER_LARGE = "\u5927\u578b";
+ private static final String HEADER_MEDIUM = "\u4e2d\u578b";
+ private static final String HEADER_SMALL = "\u5c0f\u578b";
+ private static final String TOTAL = "\u603b\u8ba1";
+
+ @Test
+ void parsesAllIndicatorsFromRawXlsxDecimalText() throws Exception {
+ try (Workbook workbook = validWorkbook("2026/9/30")) {
+ Sheet sheet = workbook.getSheet(SHEET);
+ Row first = sheet.getRow(8);
+ first.getCell(3).setCellValue(1.0d);
+ first.getCell(4).setCellValue("-");
+ first.getCell(5).setCellValue("235346.125");
+ first.getCell(6).setCellValue("");
+ sheet.getRow(12).getCell(3).setCellValue(339067.0d);
+
+ H202WorkbookParser.ParsedWorkbook parsed = H202WorkbookParser.parse(
+ workbook, "RP_JTB_FreightVehicle_\u6b66\u6c49\u5e02.xlsx", "2026-09");
+
+ assertEquals("\u6b66\u6c49\u5e02", parsed.getRegionName());
+ assertEquals(LocalDate.of(2026, 9, 30), parsed.getReportDate());
+ assertEquals(93, parsed.getRows().size());
+ H202FreightVehicleOwnership row = parsed.getRows().get(0);
+ assertDecimal("339067", row.getTotalValue());
+ assertNull(row.getIndividualValue());
+ assertDecimal("235346.125", row.getLargeValue());
+ assertNull(row.getLargeHeavyValue());
+ assertEquals("01", row.getItemCode());
+ assertEquals(TOTAL, row.getItemName());
+ }
+ }
+
+ @Test
+ void supportsShiftedOctoberCodesAndRecomputesTotals() throws Exception {
+ try (Workbook workbook = validWorkbook("2026/10/31", 95)) {
+ Sheet sheet = workbook.getSheet(SHEET);
+ setTotal(sheet, "01", "165346");
+ setTotal(sheet, "02", "2021140.8");
+ setTotal(sheet, "05", "154783");
+ setTotal(sheet, "06", "1791290.4");
+ setTotal(sheet, "50", "92647");
+ setTotal(sheet, "61", "73452");
+ setTotal(sheet, "62", "2360098.2");
+ setTotal(sheet, "94", "315");
+ setTotal(sheet, "95", "2517.2");
+
+ H202WorkbookParser.ParsedWorkbook parsed = H202WorkbookParser.parse(
+ workbook, "RP_JTB_FreightVehicle_\u5168\u7701.xlsx", "2026-10");
+
+ assertEquals(95, parsed.getRows().size());
+ assertEquals("50", parsed.getRows().get(49).getItemCode());
+ assertEquals("2.\u7275\u5f15\u8f66", parsed.getRows().get(49).getItemName());
+ assertEquals("94", parsed.getRows().get(93).getItemCode());
+ assertDecimal("321197", parsed.getRows().get(0).getTotalValue());
+ assertDecimal("4153905.8", parsed.getRows().get(1).getTotalValue());
+ }
+ }
+
+ @Test
+ void mapsFileNameToCanonicalRegion() {
+ assertEquals("\u6e56\u5317\u7701", H202WorkbookParser.regionFromFileName(
+ "RP_JTB_FreightVehicle_\u5168\u7701.xlsx"));
+ assertEquals("\u795e\u519c\u67b6\u6797\u533a", H202WorkbookParser.regionFromFileName(
+ "RP_JTB_FreightVehicle_\u6797\u533a.xlsx"));
+ assertEquals("\u6069\u65bd\u5dde", H202WorkbookParser.regionFromFileName(
+ "RP_JTB_FreightVehicle_\u6069\u65bd.xlsx"));
+ }
+
+ @Test
+ void rejectsReportPeriodMismatch() throws Exception {
+ try (Workbook workbook = validWorkbook("2026/9/30")) {
+ IllegalArgumentException error = assertThrows(IllegalArgumentException.class,
+ () -> H202WorkbookParser.parse(workbook,
+ "RP_JTB_FreightVehicle_\u5168\u7701.xlsx", "2026-08"));
+ assertTrue(error.getMessage().contains("2026-09-30"));
+ assertTrue(error.getMessage().contains("2026-08"));
+ }
+ }
+
+ @Test
+ void rejectsInvalidNumericWithExcelPosition() throws Exception {
+ try (Workbook workbook = validWorkbook("2026/9/30")) {
+ workbook.getSheet(SHEET).getRow(8).getCell(3).setCellValue("not-a-number");
+ IllegalArgumentException error = assertThrows(IllegalArgumentException.class,
+ () -> H202WorkbookParser.parse(workbook,
+ "RP_JTB_FreightVehicle_\u5168\u7701.xlsx", "2026-09"));
+ assertTrue(error.getMessage().contains("\u7b2c 9 \u884c"));
+ assertTrue(error.getMessage().contains("D \u5217"));
+ assertTrue(error.getMessage().contains("\u603b\u8ba1"));
+ }
+ }
+
+ @Test
+ void rejectsFormulaValuesToAvoidNumericDoubleEvaluation() throws Exception {
+ try (Workbook workbook = validWorkbook("2026/9/30")) {
+ workbook.getSheet(SHEET).getRow(8).getCell(3).setCellFormula("SUM(1,2)");
+ IllegalArgumentException error = assertThrows(IllegalArgumentException.class,
+ () -> H202WorkbookParser.parse(workbook,
+ "RP_JTB_FreightVehicle_\u5168\u7701.xlsx", "2026-09"));
+ assertTrue(error.getMessage().contains("\u4e0d\u652f\u6301\u516c\u5f0f"));
+ }
+ }
+
+ @Test
+ void rejectsDuplicateIndicatorCode() throws Exception {
+ try (Workbook workbook = validWorkbook("2026/9/30")) {
+ workbook.getSheet(SHEET).getRow(9).getCell(2).setCellValue("01");
+ IllegalArgumentException error = assertThrows(IllegalArgumentException.class,
+ () -> H202WorkbookParser.parse(workbook,
+ "RP_JTB_FreightVehicle_\u5168\u7701.xlsx", "2026-09"));
+ assertTrue(error.getMessage().contains("\u91cd\u590d"));
+ }
+ }
+
+ @Test
+ void readsAndReconcilesAllEighteenSourceWorkbooksWhenConfigured() throws Exception {
+ String configured = System.getProperty("h202.source.dir",
+ System.getenv("H202_SOURCE_DIR"));
+ String period = System.getProperty("h202.source.period",
+ System.getenv("H202_SOURCE_PERIOD"));
+ Assumptions.assumeTrue(configured != null && !configured.trim().isEmpty(),
+ "H202_SOURCE_DIR is not configured");
+ Assumptions.assumeTrue(period != null && period.matches("\\d{4}-\\d{2}"),
+ "H202_SOURCE_PERIOD is not configured");
+ Path dir = Paths.get(configured);
+ Assumptions.assumeTrue(Files.isDirectory(dir), "H202 source directory does not exist");
+
+ List<Path> files;
+ try (Stream<Path> stream = Files.list(dir)) {
+ files = stream
+ .filter(path -> path.getFileName().toString().startsWith("RP_JTB_FreightVehicle_"))
+ .filter(path -> path.getFileName().toString().endsWith(".xlsx"))
+ .filter(path -> !path.getFileName().toString().startsWith("~$"))
+ .sorted()
+ .collect(Collectors.toList());
+ }
+ assertEquals(18, files.size());
+
+ Map<String, Map<String, H202FreightVehicleOwnership>> byRegion =
+ new LinkedHashMap<String, Map<String, H202FreightVehicleOwnership>>();
+ for (Path file : files) {
+ H202WorkbookParser.ParsedWorkbook parsed;
+ try (InputStream input = Files.newInputStream(file);
+ Workbook workbook = WorkbookFactory.create(input)) {
+ parsed = H202WorkbookParser.parse(workbook, file.getFileName().toString(), period);
+ }
+ int expectedRows = "2026-10".equals(period) ? 95 : 93;
+ assertEquals(expectedRows, parsed.getRows().size(), file.toString());
+ assertEquals(YearMonth.parse(period).atEndOfMonth(),
+ parsed.getReportDate(), file.toString());
+ Map<String, H202FreightVehicleOwnership> byCode =
+ new LinkedHashMap<String, H202FreightVehicleOwnership>();
+ for (H202FreightVehicleOwnership row : parsed.getRows()) {
+ byCode.put(row.getItemCode(), row);
+ }
+ byRegion.put(parsed.getRegionName(), byCode);
+ }
+
+ assertEquals(18, byRegion.size());
+ Map<String, H202FreightVehicleOwnership> province = byRegion.get("\u6e56\u5317\u7701");
+ String[] codes;
+ if ("2026-10".equals(period)) {
+ assertDecimal("321197", province.get("01").getTotalValue());
+ assertDecimal("4153905.8", province.get("02").getTotalValue());
+ assertDecimal("92647", province.get("50").getTotalValue());
+ assertDecimal("73452", province.get("61").getTotalValue());
+ assertDecimal("2360098.2", province.get("62").getTotalValue());
+ assertDecimal("315", province.get("94").getTotalValue());
+ assertDecimal("2517.2", province.get("95").getTotalValue());
+ codes = new String[]{"01", "02", "50", "61", "62", "94", "95"};
+ } else {
+ assertDecimal("339067", province.get("01").getTotalValue());
+ assertDecimal("4746671.4", province.get("02").getTotalValue());
+ assertDecimal("92131", province.get("49").getTotalValue());
+ assertDecimal("91819", province.get("59").getTotalValue());
+ assertDecimal("2945849.9", province.get("60").getTotalValue());
+ assertDecimal("322", province.get("92").getTotalValue());
+ assertDecimal("2625.2", province.get("93").getTotalValue());
+ codes = new String[]{"01", "02", "49", "59", "60", "92", "93"};
+ }
+ List<BigDecimal> citySums = new ArrayList<BigDecimal>();
+ for (String code : codes) {
+ BigDecimal sum = BigDecimal.ZERO;
+ for (Map.Entry<String, Map<String, H202FreightVehicleOwnership>> item : byRegion.entrySet()) {
+ if (!"\u6e56\u5317\u7701".equals(item.getKey())) {
+ BigDecimal value = item.getValue().get(code).getTotalValue();
+ if (value != null) {
+ sum = sum.add(value);
+ }
+ }
+ }
+ citySums.add(sum);
+ }
+ for (int i = 0; i < codes.length; i++) {
+ BigDecimal provinceValue = province.get(codes[i]).getTotalValue();
+ BigDecimal tolerance = BigDecimal.ZERO;
+ if ("60".equals(codes[i]) || "02".equals(codes[i])) {
+ tolerance = new BigDecimal("0.1");
+ } else if ("62".equals(codes[i])) {
+ tolerance = new BigDecimal("0.2");
+ }
+ assertTrue(provinceValue.subtract(citySums.get(i)).abs().compareTo(tolerance) <= 0,
+ codes[i]);
+ }
+ }
+
+ private static Workbook validWorkbook(String reportDate) {
+ return validWorkbook(reportDate, 93);
+ }
+
+ private static Workbook validWorkbook(String reportDate, int indicatorCount) {
+ XSSFWorkbook workbook = new XSSFWorkbook();
+ Sheet sheet = workbook.createSheet(SHEET);
+ sheet.createRow(1).createCell(0).setCellValue(TITLE);
+ Row meta = sheet.createRow(2);
+ meta.createCell(0).setCellValue("\u586b\u62a5\u5355\u4f4d\uff1a\u5168\u7701");
+ meta.createCell(11).setCellValue("\u62a5\u8868\u65e5\u671f\uff1a" + reportDate);
+ Row header = sheet.createRow(4);
+ header.createCell(0).setCellValue(HEADER_NAME);
+ header.createCell(1).setCellValue(HEADER_UNIT);
+ header.createCell(2).setCellValue(HEADER_CODE);
+ header.createCell(3).setCellValue(HEADER_TOTAL);
+ header.createCell(4).setCellValue(HEADER_INDIVIDUAL);
+ header.createCell(5).setCellValue(HEADER_LARGE);
+ header.createCell(9).setCellValue(HEADER_MEDIUM);
+ header.createCell(11).setCellValue(HEADER_SMALL);
+
+ int tractorVehicle = indicatorCount == 95 ? 50 : 49;
+ int trailerVehicle = indicatorCount == 95 ? 61 : 59;
+ int trailerTonnage = trailerVehicle + 1;
+ int otherVehicle = indicatorCount == 95 ? 94 : 92;
+ int otherTonnage = otherVehicle + 1;
+ for (int i = 1; i <= indicatorCount; i++) {
+ Row row = sheet.createRow(7 + i);
+ String name = "";
+ String unit = "";
+ if (i == 1) { name = TOTAL; unit = "\u8f86"; }
+ else if (i == 2) { unit = "\u5428\u4f4d"; }
+ else if (i == 3) { name = "\u4e00\u3001\u8f7d\u8d27\u6c7d\u8f66"; unit = "\u8f86"; }
+ else if (i == 4) { unit = "\u5428\u4f4d"; }
+ else if (i == 5) { name = "1.\u8d27\u8f66"; unit = "\u8f86"; }
+ else if (i == 6) { unit = "\u5428\u4f4d"; }
+ else if (i == tractorVehicle) { name = "2.\u7275\u5f15\u8f66"; unit = "\u8f86"; }
+ else if (i == trailerVehicle) { name = "3.\u6302\u8f66"; unit = "\u8f86"; }
+ else if (i == trailerTonnage) { unit = "\u5428\u4f4d"; }
+ else if (i == otherVehicle) { name = "\u4e8c\u3001\u5176\u5b83\u8f7d\u8d27\u673a\u52a8\u8f66"; unit = "\u8f86"; }
+ else if (i == otherTonnage) { unit = "\u5428\u4f4d"; }
+ if (!name.isEmpty()) {
+ row.createCell(0).setCellValue(name);
+ }
+ if (!unit.isEmpty()) {
+ row.createCell(1).setCellValue(unit);
+ }
+ row.createCell(2).setCellValue(String.format("%02d", i));
+ for (int col = 3; col <= 12; col++) {
+ row.createCell(col).setCellValue("0");
+ }
+ }
+ return workbook;
+ }
+
+ private static void setTotal(Sheet sheet, String code, String value) {
+ for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
+ Row row = sheet.getRow(rowIndex);
+ if (row != null && row.getCell(2) != null
+ && code.equals(row.getCell(2).getStringCellValue())) {
+ row.getCell(3).setCellValue(value);
+ return;
+ }
+ }
+ throw new AssertionError("Missing test indicator code " + code);
+ }
+
+ private static void assertDecimal(String expected, BigDecimal actual) {
+ assertEquals(0, new BigDecimal(expected).compareTo(actual),
+ "expected " + expected + " but was " + actual);
+ }
+}
diff --git a/traffic-audit-web/src/views/DataImport.vue b/traffic-audit-web/src/views/DataImport.vue
index 3ccd61d..34ad19d 100644
--- a/traffic-audit-web/src/views/DataImport.vue
+++ b/traffic-audit-web/src/views/DataImport.vue
@@ -59,11 +59,17 @@
</div>
<div v-else-if="moduleSel[g.key] && !isDirOnlyType(moduleSel[g.key])" class="module-file">
<div class="file-name" :title="fileNamesText(moduleSel[g.key])">{{ fileNamesText(moduleSel[g.key]) || '鏈�夋嫨鏂囦欢' }}</div>
+ <div v-if="moduleSel[g.key] === 'h202'" class="tip" style="margin:0 0 6px">閫夋嫨鏂囦欢澶瑰悗锛岃嚜鍔ㄨ瘑鍒苟瀵煎叆鐩綍鍐呯鍚� H202 鍛藉悕瑙勫垯鐨勫叏閮� .xlsx 鏂囦欢銆�</div>
<div class="file-btns">
<el-upload action="#" :auto-upload="false" :show-file-list="false" multiple :accept="acceptOf(moduleSel[g.key])"
:ref="'up' + g.key" :on-change="f => onFilePicked(g.key, f)" style="display:inline-block">
<el-button size="mini" type="primary" plain icon="el-icon-folder-opened" :disabled="importing">閫夋嫨鏂囦欢</el-button>
</el-upload>
+ <input v-if="moduleSel[g.key] === 'h202'" :ref="'folder' + g.key" type="file" webkitdirectory directory multiple accept=".xlsx"
+ style="display:none" @change="onFolderPicked(g.key, $event)">
+ <el-button v-if="moduleSel[g.key] === 'h202'" size="mini" type="primary" icon="el-icon-folder-opened"
+ :disabled="importing" title="閫夋嫨鏂囦欢澶瑰悗鑷姩鎵归噺瀵煎叆"
+ @click="pickH202Folder(g.key)">閫夋嫨鏂囦欢澶瑰苟瀵煎叆</el-button>
<el-button size="mini" type="primary" icon="el-icon-upload2" :loading="importing" :disabled="importing || !fileCount(moduleSel[g.key])"
@click="importNow(g.key)">{{ fileCount(moduleSel[g.key]) > 1 ? '鎵归噺瀵煎叆 ' + fileCount(moduleSel[g.key]) + ' 涓枃浠�' : '绔嬪嵆瀵煎叆' }}</el-button>
</div>
@@ -198,7 +204,7 @@
import api from '@/api'
import { granularityOfMany, disabledDateFor, granularityHint, snapPeriod } from '@/utils/periodGranularity'
const TYPE_LABELS = {
- h2032: 'H203-2鏈堟姤', transportAuth: '杩愭斂杞﹁締', trackMileage: '杞ㄨ抗閲岀▼', scaleSplit: '瑙勪笂瑙勪笅鎷嗗垎',
+ h2032: 'H203-2鏈堟姤', h202: 'H202杞﹁締鎷ユ湁鎯呭喌', transportAuth: '杩愭斂杞﹁締', trackMileage: '杞ㄨ抗閲岀▼', scaleSplit: '瑙勪笂瑙勪笅鎷嗗垎',
freightTurnover: '璐ц繍閲忓懆杞噺', passengerMonthly: 'H203-1鏃呭鏈堟姤', passengerIndividual: '涓綋瀹㈣繍閲�/鍛ㄨ浆閲�',
passengerAuth: '鏃呭杩愭斂杞﹁締鏁�', energyMonthly: 'H204鑳借�楀鎶�', energyAuth: '鑳借�楄溅杈嗚繍鏀夸俊鎭�',
investment: '鎶曡祫鏈堟姤锛堝杩愮珯鍦猴級', investmentLogistics: '鎶曡祫鏈堟姤锛堢墿娴佸洯鍖猴級', investmentSystem: '鎶曡祫绯荤粺瀵煎嚭',
@@ -212,7 +218,7 @@
INVEST_SYSTEM: '鎶曡祫绯荤粺瀵煎嚭', CITY_BUS: '鍩庡競鍏氦鏈堟姤', CITY_TAXI: '宸℃父鍑虹鏈堟姤', CITY_TAXI_AUTH: '鍑虹杞﹁繍鏀胯溅杈�', WYC_TOTAL: '缃戠害杞︽�绘暟', WYC_ORDER: '缃戠害杞﹁鍗曞強鍏ㄧ渷鎬婚噺', WYC_ORDER_REPORT: '缃戠害杞﹁鍗曟姤鍛�'
}
const BATCH_TYPE_MAP = {
- H2032: 'h2032', TRANSPORT_AUTH: 'transportAuth', TRACK_MILEAGE: 'trackMileage',
+ H2032: 'h2032', H202: 'h202', TRANSPORT_AUTH: 'transportAuth', TRACK_MILEAGE: 'trackMileage',
SCALE_SPLIT: 'scaleSplit', FREIGHT_TURNOVER: 'freightTurnover',
H2031: 'passengerMonthly', PASSENGER_AUTH: 'passengerAuth', PASSENGER_INDIVIDUAL: 'passengerIndividual',
H204: 'energyMonthly', ENERGY_AUTH: 'energyAuth',
@@ -220,6 +226,7 @@
WYC_TOTAL: 'wycTotal', WYC_ORDER: 'wycOrder', WYC_ORDER_REPORT: 'wycOrderReport',
INVEST_SYSTEM: 'investmentSystem'
}
+const H202_FOLDER_FILE_PATTERN = /^RP_JTB_FreightVehicle_.+\.xlsx$/i
export default {
components: { AppHeader },
name: 'DataImport',
@@ -248,6 +255,7 @@
{
key: 'freight', name: '閬撹矾璐ц繍', types: [
{ value: 'h2032', label: '閬撹矾璐х墿杩愯緭鏈堝害鐢熶骇鎯呭喌' },
+ { value: 'h202', label: '鍏矾璐х墿钀ヨ繍杞﹁締鎷ユ湁鎯呭喌(H202)' },
{ value: 'transportAuth', label: '杩愭斂杞﹁締' },
{ value: 'trackMileage', label: '杞ㄨ抗閲岀▼' },
{ value: 'scaleSplit', label: '瑙勪笂瑙勪笅鎷嗗垎' },
@@ -349,6 +357,7 @@
templateName() {
const map = {
h2032: '妯℃澘_浜や紒缁烪203-2琛╛閬撹矾璐х墿杩愯緭鏈堝害鐢熶骇鎯呭喌.xlsx',
+ h202: 'RP_JTB_FreightVehicle_鍏ㄧ渷.xlsx锛堝鍏ュ墠灏嗘枃浠跺悕鈥滃叏鐪佲�濆拰琛ㄥ唴 L3 鎶ヨ〃鏃ユ湡鏀逛负瀹為檯鍦板尯銆佹姤琛ㄦ湡鏈棩鏈燂級',
transportAuth: '妯℃澘_杩愭斂杞﹁締.xlsx',
trackMileage: '妯℃澘_杞ㄨ抗閲岀▼.xlsx',
scaleSplit: '妯℃澘_瑙勪笂瑙勪笅鎷嗗垎杩愯緭閲�.xlsx',
@@ -375,6 +384,7 @@
templateUrl() {
const map = {
h2032: '璐ц繍/妯℃澘_浜や紒缁烪203-2琛╛閬撹矾璐х墿杩愯緭鏈堝害鐢熶骇鎯呭喌.xlsx',
+ h202: '璐ц繍/RP_JTB_FreightVehicle_鍏ㄧ渷.xlsx',
transportAuth: '璐ц繍/妯℃澘_杩愭斂杞﹁締.xlsx',
trackMileage: '璐ц繍/妯℃澘_杞ㄨ抗閲岀▼.xlsx',
scaleSplit: '璐ц繍/妯℃澘_瑙勪笂瑙勪笅鎷嗗垎杩愯緭閲�.xlsx',
@@ -437,6 +447,7 @@
endpoint(t) {
const map = {
h2032: '/import/h2032',
+ h202: '/import/h202',
transportAuth: '/import/transportAuth',
trackMileage: '/import/trackMileage',
scaleSplit: '/import/scaleSplit',
@@ -458,6 +469,37 @@
}
return map[t] || ''
},
+ pickH202Folder(key) {
+ if (this.importing) { this.$message.warning('姝e湪瀵煎叆涓紝璇风◢鍊欏啀閫夋嫨鏂囦欢澶�'); return }
+ if (!this.period) { this.$message.warning('璇峰厛閫夋嫨鎶ヨ〃鏈�'); return }
+ const ref = this.$refs['folder' + key]
+ const input = Array.isArray(ref) ? ref[0] : ref
+ if (!input) { this.$message.error('鏂囦欢澶归�夋嫨鎺т欢鏈氨缁紝璇峰埛鏂伴〉闈㈠悗閲嶈瘯'); return }
+ input.value = ''
+ input.click()
+ },
+ onFolderPicked(key, event) {
+ const input = event && event.target
+ const selected = Array.from((input && input.files) || [])
+ if (input) input.value = ''
+ const type = this.moduleSel[key]
+ if (type !== 'h202' || !selected.length) return
+ if (this.importing) { this.$message.warning('姝e湪瀵煎叆涓紝璇风◢鍊欏啀閫夋嫨鏂囦欢澶�'); return }
+ if (!this.period) { this.$message.warning('璇峰厛閫夋嫨鎶ヨ〃鏈�'); return }
+ const fileList = selected
+ .filter(f => H202_FOLDER_FILE_PATTERN.test(f.name))
+ .sort((a, b) => String(a.webkitRelativePath || a.name).localeCompare(String(b.webkitRelativePath || b.name), 'zh-CN'))
+ const ignored = selected.length - fileList.length
+ if (!fileList.length) {
+ this.$message.warning('鎵�閫夋枃浠跺す涓病鏈夌鍚� H202 鍛藉悕瑙勫垯鐨� .xlsx 鏂囦欢')
+ return
+ }
+ this.$set(this.files, type, fileList)
+ this.$set(this.fileNames, type, fileList.map(f => f.name))
+ if (ignored > 0) this.$message.warning('宸插拷鐣� ' + ignored + ' 涓笉绗﹀悎 H202 鍛藉悕瑙勫垯鐨勬枃浠�')
+ this.importing = true
+ this.batchImport(type, key, fileList).finally(() => { this.importing = false })
+ },
onFilePicked(key, file) {
const type = this.moduleSel[key]
if (!type) return
diff --git a/traffic-audit-web/src/views/DataView.vue b/traffic-audit-web/src/views/DataView.vue
index 120590d..092ee9f 100644
--- a/traffic-audit-web/src/views/DataView.vue
+++ b/traffic-audit-web/src/views/DataView.vue
@@ -100,6 +100,7 @@
{
key: 'freight', name: '閬撹矾璐ц繍', types: [
{ value: 'h2032', label: '閬撹矾璐х墿杩愯緭鏈堝害鐢熶骇鎯呭喌' },
+ { value: 'h202', label: '鍏矾璐х墿钀ヨ繍杞﹁締鎷ユ湁鎯呭喌(H202)' },
{ value: 'transportAuth', label: '杩愭斂杞﹁締' },
{ value: 'trackMileage', label: '杞ㄨ抗閲岀▼' },
{ value: 'scaleSplit', label: '瑙勪笂瑙勪笅鎷嗗垎' },
@@ -405,6 +406,7 @@
// - 鍏朵綑鏁板�煎崈鍒嗕綅銆佷繚鐣欎袱浣嶅皬鏁帮紱鏁存暟鍘熸牱銆�
formatCell(v, prop) {
if (v === null || v === undefined || v === '') return '-'
+ if (this.type === 'h202' && /Value$/.test(String(prop || ''))) return this.formatExactDecimal(v)
const s = typeof v === 'string' ? v.trim() : v
if (typeof v !== 'number' && !/^-?\d+(\.\d+)?$/.test(String(s))) return v
const n = Number(s)
@@ -414,6 +416,17 @@
if (/(rate|yoy|mom|growth|ratio|percent|share)/.test(key)) return (n * 100).toFixed(2) + '%'
if (Number.isInteger(n)) return n.toLocaleString('zh-CN')
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
+ },
+ // H202 values arrive as exact decimal strings. Format without Number() to preserve source precision.
+ formatExactDecimal(v) {
+ const text = String(v === null || v === undefined ? '' : v).trim()
+ if (!/^-?\d+(?:\.\d+)?$/.test(text)) return v
+ const negative = text.charAt(0) === '-'
+ const unsigned = negative ? text.slice(1) : text
+ const parts = unsigned.split('.')
+ const integer = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',')
+ const fraction = (parts[1] || '').replace(/0+$/, '')
+ return (negative ? '-' : '') + integer + (fraction ? '.' + fraction : '')
}
},
mounted() {
--
Gitblit v1.9.1