xyc
3 天以前 1c9505d00bd076898cdc5a7d916106e175a91119
traffic-audit-server/src/main/java/com/trafficaudit/dataimport/service/DataImportService.java
@@ -167,6 +167,7 @@
    // ========== H2032 月报 ==========
    @Transactional(rollbackFor = Exception.class)
    public synchronized ImportResult importH2032(MultipartFile file, String period) throws Exception {
        List<H2032Row> rows = new ArrayList<>();
        Map<String, Integer> colMap;
@@ -239,6 +240,19 @@
            throw e;
        }
        if (rows.isEmpty()) {
            throw new IllegalArgumentException("货运月报未解析到企业数据");
        }
        Map<String, Integer> seenEnterprises = new HashMap<>();
        for (H2032Row item : rows) {
            String key = normalizeEnterpriseNameKey(item.entity.getEnterpriseName());
            Integer firstRow = seenEnterprises.put(key, item.excelRow);
            if (firstRow != null) {
                throw new IllegalArgumentException("第 " + item.excelRow + " 行企业名称与第 " + firstRow
                        + " 行重复:" + item.entity.getEnterpriseName());
            }
        }
        // 幂等:同报表期重新导入,先删除旧数据(只清 H2032 规则的审核结果)
        h2032Mapper.delete(new LambdaQueryWrapper<H2032EnterpriseMonthly>()
            .eq(H2032EnterpriseMonthly::getReportPeriod, period));
@@ -274,6 +288,9 @@
        String errorDetail = String.join("\n", failDetails);
        if (errorDetail.length() > 4000) {
            errorDetail = errorDetail.substring(0, 4000) + "\n……";
        }
        if (!failDetails.isEmpty()) {
            throw new IllegalArgumentException("H2032 月报写入失败,已整体回滚:\n" + errorDetail);
        }
        Long batchId = recordBatch(file.getOriginalFilename(), "H2032", period, rows.size(), success, failDetails.size(), errorDetail);
        attachBatchId("h2032_enterprise_monthly", period, batchId);
@@ -2495,6 +2512,11 @@
    }
    /** H2032 行记录:保留 Excel 行号用于失败定位 */
    private static String normalizeEnterpriseNameKey(String value) {
        if (value == null) return "";
        return value.trim().replace('(', '(').replace(')', ')').replaceAll("\\s+", "");
    }
    private static class H2032Row {
        final int excelRow;
        final H2032EnterpriseMonthly entity;