feat(H202): 新增货运车辆拥有情况导入与查看
| | |
| | | created_at DATETIME DEFAULT CURRENT_TIMESTAMP |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='交ä¼ç»H203-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 ( |
| New file |
| | |
| | | -- 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'; |
| | |
| | | | 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 |
| | | |
| | |
| | | created_at DATETIME DEFAULT CURRENT_TIMESTAMP |
| | | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='交ä¼ç»H203-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 ( |
| New file |
| | |
| | | -- 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'; |
| | |
| | | } |
| | | } |
| | | |
| | | /** 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() + " æ¡è®°å½"; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | |
| | | @Resource |
| | | private H2032EnterpriseMonthlyMapper h2032Mapper; |
| | | @Resource |
| | | private H202FreightVehicleOwnershipMapper h202Mapper; |
| | | @Resource |
| | | private TransportAuthVehicleMapper transportAuthMapper; |
| | | @Resource |
| | |
| | | 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) |
| | |
| | | return Result.ok(result); |
| | | } |
| | | |
| | | /** åºå代ç -> å¸å·åï¼æ æ³è¯å«è¿åç©ºä¸²ï¼ */ |
| | | /** 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()); |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | 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<>(); |
| | |
| | | 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", "ä¼ä¸ä»£ç ", 130)); |
| New file |
| | |
| | | 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; |
| | | } |
| New file |
| | |
| | | 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> {} |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | |
| | | @Resource |
| | | private H2032EnterpriseMonthlyMapper h2032Mapper; |
| | | @Resource |
| | | private H202FreightVehicleOwnershipMapper h202Mapper; |
| | | @Resource |
| | | private TransportAuthVehicleMapper transportAuthMapper; |
| | | @Resource |
| | |
| | | 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 ææ¥ä¸è´ï¼æè¡¨å¤´åç§°å®ä½åï¼å顺åºååä¹è½æ£ç¡®å¯¼å
¥ */ |
| | |
| | | |
| | | 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"); |
| | |
| | | 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"}); |
| | |
| | | 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>() |
| | |
| | | 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)); |
| | |
| | | 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) ? "客è¿ç«åº" : "ç©æµååº"; |
| | |
| | | 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); |
| New file |
| | |
| | | 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; |
| | | } |
| | | } |
| | | } |
| New file |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | </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> |
| | |
| | | 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: 'æèµç³»ç»å¯¼åº', |
| | |
| | | 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', |
| | |
| | | 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', |
| | |
| | | { |
| | | key: 'freight', name: 'é路货è¿', types: [ |
| | | { value: 'h2032', label: 'é路货ç©è¿è¾æåº¦ç产æ
åµ' }, |
| | | { value: 'h202', label: 'å
¬è·¯è´§ç©è¥è¿è½¦è¾æ¥ææ
åµ(H202)' }, |
| | | { value: 'transportAuth', label: 'è¿æ¿è½¦è¾' }, |
| | | { value: 'trackMileage', label: '轨迹éç¨' }, |
| | | { value: 'scaleSplit', label: 'è§ä¸è§ä¸æå' }, |
| | |
| | | templateName() { |
| | | const map = { |
| | | h2032: '模æ¿_交ä¼ç»H203-2表_é路货ç©è¿è¾æåº¦ç产æ
åµ.xlsx', |
| | | h202: 'RP_JTB_FreightVehicle_å
¨ç.xlsxï¼å¯¼å
¥åå°æä»¶åâå
¨çâå表å
L3 æ¥è¡¨æ¥ææ¹ä¸ºå®é
å°åºãæ¥è¡¨ææ«æ¥æï¼', |
| | | transportAuth: '模æ¿_è¿æ¿è½¦è¾.xlsx', |
| | | trackMileage: '模æ¿_轨迹éç¨.xlsx', |
| | | scaleSplit: '模æ¿_è§ä¸è§ä¸æåè¿è¾é.xlsx', |
| | |
| | | templateUrl() { |
| | | const map = { |
| | | h2032: 'è´§è¿/模æ¿_交ä¼ç»H203-2表_é路货ç©è¿è¾æåº¦ç产æ
åµ.xlsx', |
| | | h202: 'è´§è¿/RP_JTB_FreightVehicle_å
¨ç.xlsx', |
| | | transportAuth: 'è´§è¿/模æ¿_è¿æ¿è½¦è¾.xlsx', |
| | | trackMileage: 'è´§è¿/模æ¿_轨迹éç¨.xlsx', |
| | | scaleSplit: 'è´§è¿/模æ¿_è§ä¸è§ä¸æåè¿è¾é.xlsx', |
| | |
| | | endpoint(t) { |
| | | const map = { |
| | | h2032: '/import/h2032', |
| | | h202: '/import/h202', |
| | | transportAuth: '/import/transportAuth', |
| | | trackMileage: '/import/trackMileage', |
| | | scaleSplit: '/import/scaleSplit', |
| | |
| | | } |
| | | return map[t] || '' |
| | | }, |
| | | pickH202Folder(key) { |
| | | if (this.importing) { this.$message.warning('æ£å¨å¯¼å
¥ä¸ï¼è¯·ç¨ååéæ©æä»¶å¤¹'); 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('æ£å¨å¯¼å
¥ä¸ï¼è¯·ç¨ååéæ©æä»¶å¤¹'); 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 |
| | |
| | | { |
| | | key: 'freight', name: 'é路货è¿', types: [ |
| | | { value: 'h2032', label: 'é路货ç©è¿è¾æåº¦ç产æ
åµ' }, |
| | | { value: 'h202', label: 'å
¬è·¯è´§ç©è¥è¿è½¦è¾æ¥ææ
åµ(H202)' }, |
| | | { value: 'transportAuth', label: 'è¿æ¿è½¦è¾' }, |
| | | { value: 'trackMileage', label: '轨迹éç¨' }, |
| | | { value: 'scaleSplit', label: 'è§ä¸è§ä¸æå' }, |
| | |
| | | // - å
¶ä½æ°å¼ååä½ãä¿ç两ä½å°æ°ï¼æ´æ°åæ ·ã |
| | | 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) |
| | |
| | | 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() { |