From 7a17662bdadf36c4e30bd53b896571612d48abbb Mon Sep 17 00:00:00 2001
From: zhizhijie <zhizhijie@users.noreply.gitee.com>
Date: 星期三, 09 九月 2026 11:17:38 +0800
Subject: [PATCH] fix: 4项整改——审核结果按模板双Sheet导出(仅核实型+状态筛选)/明细表格化、数据查看分组选择与隐藏三列、报表页隐藏货运旅客城市客运小表、整本预览展示货运城市客运中口径当月累计同比 + 测试报告与工作日结

---
 traffic-audit-server/src/main/java/com/trafficaudit/dataimport/service/DataImportService.java |  221 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 211 insertions(+), 10 deletions(-)

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 50b64f8..0fe1227 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
@@ -18,6 +18,8 @@
 import com.trafficaudit.dataimport.entity.CityBusMonthly;
 import com.trafficaudit.dataimport.entity.CityTaxiMonthly;
 import com.trafficaudit.dataimport.entity.CityTaxiAuth;
+import com.trafficaudit.dataimport.entity.WycOrderMonthly;
+import com.trafficaudit.dataimport.entity.WycTotalMonthly;
 import com.trafficaudit.dataimport.entity.ScaleSplitTransport;
 import com.trafficaudit.dataimport.entity.TransportAuthVehicle;
 import com.trafficaudit.dataimport.entity.VehicleTrackMileage;
@@ -36,6 +38,8 @@
 import com.trafficaudit.dataimport.mapper.CityBusMonthlyMapper;
 import com.trafficaudit.dataimport.mapper.CityTaxiMonthlyMapper;
 import com.trafficaudit.dataimport.mapper.CityTaxiAuthMapper;
+import com.trafficaudit.dataimport.mapper.WycOrderMonthlyMapper;
+import com.trafficaudit.dataimport.mapper.WycTotalMonthlyMapper;
 import com.trafficaudit.dataimport.mapper.ScaleSplitTransportMapper;
 import com.trafficaudit.dataimport.mapper.TransportAuthVehicleMapper;
 import com.trafficaudit.dataimport.mapper.VehicleTrackMileageMapper;
@@ -162,6 +166,10 @@
     private CityTaxiMonthlyMapper cityTaxiMapper;
     @Resource
     private CityTaxiAuthMapper cityTaxiAuthMapper;
+    @Resource
+    private WycTotalMonthlyMapper wycTotalMapper;
+    @Resource
+    private WycOrderMonthlyMapper wycOrderMapper;
     @Resource
     private SqlSessionFactory sqlSessionFactory;
 
@@ -550,24 +558,30 @@
         }
     }
 
-    /** 鍏矾鏃呭杩愭斂杞﹁締鏁帮紙鐙珛妯℃澘锛氫紒涓氫唬鐮�/浼佷笟鍚嶇О/杞﹁締鏁�/杞藉浣嶆暟锛� */
+    /** 鍏矾鏃呭杩愭斂杞﹁締鏁帮紙鍏煎涓ょ琛ㄥご锛氣憼 浼佷笟浠g爜/浼佷笟鍚嶇О/杞﹁締鏁�/杞藉浣嶆暟锛涒憽 杩愭斂搴撳鍑� OWNERNAME/鎬昏溅杈嗘暟/瀹綅鏁帮紝鏃犱紒涓氫唬鐮佸垪锛� */
     public ImportResult importPassengerAuth(MultipartFile file, String period) throws Exception {
         List<PassengerAuthVehicle> authList = new ArrayList<>();
         try (Workbook wb = WorkbookFactory.create(file.getInputStream())) {
             Sheet sheet = wb.getSheetAt(0);
-            Map<String, Integer> colMap = buildHeaderMap(sheet.getRow(0));
-            requireHeaderCols(sheet, "鏃呭杩愭斂杞﹁締鏁�", "浼佷笟鍚嶇О", "杞﹁締鏁�", "杞藉浣嶆暟");
+            Map<String, Integer> colMap = buildHeaderMapCompat(sheet.getRow(0));
+            Integer nameCol = firstColIdx(colMap, "浼佷笟鍚嶇О", "OWNERNAME");
+            Integer vehicleCol = firstColIdx(colMap, "杞﹁締鏁�", "鎬昏溅杈嗘暟");
+            Integer seatCol = firstColIdx(colMap, "杞藉浣嶆暟", "瀹綅鏁�");
+            Integer codeCol = firstColIdx(colMap, "浼佷笟浠g爜");
+            if (nameCol == null || vehicleCol == null || seatCol == null) {
+                throw new RuntimeException("鎵�閫夋暟鎹被鍨嬨�愭梾瀹㈣繍鏀胯溅杈嗘暟銆戜笌鏂囦欢鍐呭涓嶇锛氳〃澶撮渶鍚�愪紒涓氬悕绉�/杞﹁締鏁�/杞藉浣嶆暟銆戞垨銆怬WNERNAME/鎬昏溅杈嗘暟/瀹綅鏁般�戯紝璇风‘璁ゆ槸鍚﹂�夐敊浜嗘暟鎹被鍨嬫垨浣跨敤浜嗘棫妯℃澘");
+            }
             for (int r = 1; r <= sheet.getLastRowNum(); r++) {
                 Row row = sheet.getRow(r);
                 if (row == null) continue;
-                String name = gs(row, colMap, "浼佷笟鍚嶇О");
+                String name = getString(row, nameCol);
                 if (name == null || name.trim().isEmpty()) continue;
                 PassengerAuthVehicle auth = new PassengerAuthVehicle();
                 auth.setReportPeriod(period);
-                auth.setEnterpriseCode(gs(row, colMap, "浼佷笟浠g爜"));
+                auth.setEnterpriseCode(codeCol == null ? null : getString(row, codeCol));
                 auth.setEnterpriseName(name.trim());
-                auth.setVehicleCount(gi(row, colMap, "杞﹁締鏁�"));
-                auth.setSeatCount(gi(row, colMap, "杞藉浣嶆暟"));
+                auth.setVehicleCount(getInt(row, vehicleCol));
+                auth.setSeatCount(getInt(row, seatCol));
                 authList.add(auth);
             }
         } catch (Exception e) {
@@ -916,10 +930,11 @@
         List<ScaleSplitTransport> list = new ArrayList<>();
         int failRows = 0;
         try (Workbook wb = WorkbookFactory.create(file.getInputStream())) {
+            int targetMonth = Integer.parseInt(period.split("-")[1]); // 浠呭鍏ョ洰鏍囨湡鎵�鍦ㄦ湀鐨勯〉绛撅紙1-N鏈堟枃浠舵寜鐩爣鏈熷彇褰撴湀/绱锛�
             boolean hasPeriodSheet = false;
             for (int i = 0; i < wb.getNumberOfSheets(); i++) {
                 String sn = wb.getSheetAt(i).getSheetName();
-                if (sn != null && (sn.contains("褰撴湀") || sn.contains("绱"))) { hasPeriodSheet = true; break; }
+                if (sn != null && (sn.contains("褰撴湀") || sn.contains("鏈堜唤") || sn.contains("绱"))) { hasPeriodSheet = true; break; }
             }
             if (!hasPeriodSheet) {
                 throw new RuntimeException("鎵�閫夋暟鎹被鍨嬨�愯涓婅涓嬫媶鍒嗐�戜笌鏂囦欢鍐呭涓嶇锛氭湭鎵惧埌鍚� 褰撴湀/绱 鐨� sheet锛岃纭鏄惁閫夐敊浜嗘暟鎹被鍨�");
@@ -928,8 +943,16 @@
                 Sheet sheet = wb.getSheetAt(i);
                 String sheetName = sheet.getSheetName();
                 String periodType = null;
-                if (sheetName.contains("褰撴湀")) periodType = "MONTH";
-                else if (sheetName.contains("绱")) periodType = "CUMULATIVE";
+                java.util.regex.Matcher mSheetMonth = java.util.regex.Pattern.compile("(\\d{1,2})\\u6708(\\u4efd|\\u7d2f\\u8ba1)").matcher(sheetName);
+                if (mSheetMonth.find()) {
+                    int sheetMonth = Integer.parseInt(mSheetMonth.group(1));
+                    if (sheetMonth == targetMonth) {
+                        periodType = "浠�".equals(mSheetMonth.group(2)) ? "MONTH" : "CUMULATIVE";
+                    }
+                } else {
+                    if (sheetName.contains("褰撴湀")) periodType = "MONTH";
+                    else if (sheetName.contains("绱")) periodType = "CUMULATIVE";
+                }
                 if (periodType == null) continue;
 
                 // 鏍¢獙 sheet 甯冨眬锛氱2琛屽簲鍚�屽競宸�/瑙勪笂浼佷笟杩愯緭閲忋�嶏紝绗�3琛屽瓙琛ㄥご搴斿惈銆屽懆杞噺銆嶆垨銆岃揣杩愰噺銆嶏紙鎵╁睍甯冨眬锛�
@@ -1377,6 +1400,33 @@
             }
         }
         return colMap;
+    }
+
+    /** 鍏煎琛ㄥご鏄犲皠锛氬幓寮曞彿/鍘荤┖鐧斤紱绾嫳鏂囪〃澶寸粺涓�澶у啓锛堝 'OWNERNAME' 鈫� OWNERNAME锛夛紝渚夸簬鏂版棫妯℃澘娣风敤 */
+    private Map<String, Integer> buildHeaderMapCompat(Row header) {
+        Map<String, Integer> colMap = new HashMap<>();
+        if (header == null) return colMap;
+        for (Cell cell : header) {
+            if (cell == null) continue;
+            String h = FORMATTER.formatCellValue(cell).replace("'", "").replace("\"", "").trim();
+            if (h.isEmpty()) continue;
+            boolean ascii = true;
+            for (int i = 0; i < h.length(); i++) {
+                if (h.charAt(i) > 127) { ascii = false; break; }
+            }
+            if (ascii) h = h.toUpperCase();
+            if (!colMap.containsKey(h)) colMap.put(h, cell.getColumnIndex());
+        }
+        return colMap;
+    }
+
+    /** 鎸夊埆鍚嶉『搴忓彇绗竴涓瓨鍦ㄧ殑鍒楀彿锛屽叏閮ㄧ己澶辫繑鍥� null */
+    private Integer firstColIdx(Map<String, Integer> colMap, String... aliases) {
+        for (String a : aliases) {
+            Integer idx = colMap.get(a);
+            if (idx != null) return idx;
+        }
+        return null;
     }
 
     private int colIdx(Map<String, Integer> colMap, String header) {
@@ -2704,6 +2754,155 @@
         return success;
     }
 
+
+    // ========== 缃戠害杞︽湀搴﹁緭鍏ュ鍏ワ紙鍏ㄧ渷 pin / 璁㈠崟锛� ==========
+
+    /** 缃戠害杞︽�绘暟鏈堝害杈撳叆锛氭ā鏉縚缃戠害杞︽�绘暟.xlsx锛坰heet1锛汚 鍒�=鏈堜唤鏃ユ湡锛汢=鍏ㄧ渷瀹㈣繍閲� C=鍏朵腑鍩庡競鍐� D=鍛ㄨ浆閲� E=鍏朵腑鍩庡競鍐呭懆杞噺锛夈�傛暣琛ㄦ寜鎶ヨ〃鏈熻鐩栥�� */
+    public synchronized int importWycTotal(MultipartFile file, String period) throws Exception {
+        Map<String, WycTotalMonthly> rows = new LinkedHashMap<>();
+        try (Workbook wb = WorkbookFactory.create(file.getInputStream())) {
+            Sheet sheet = wb.getSheetAt(0);
+            for (int r = 2; r <= sheet.getLastRowNum(); r++) {
+                Row row = sheet.getRow(r);
+                if (row == null) continue;
+                String rp = periodOfCell(row.getCell(0));
+                if (rp == null) continue;
+                double pk = dbl(row, 1), pck = dbl(row, 2), pz = dbl(row, 3), pcz = dbl(row, 4);
+                if (pk <= 0 && pck <= 0 && pz <= 0 && pcz <= 0) continue;
+                WycTotalMonthly item = new WycTotalMonthly();
+                item.setReportPeriod(rp);
+                item.setPinK(pk > 0 ? pk : null);
+                item.setPinCK(pck > 0 ? pck : null);
+                item.setPinZ(pz > 0 ? pz : null);
+                item.setPinCZ(pcz > 0 ? pcz : null);
+                rows.put(rp, item);
+            }
+        }
+        if (rows.isEmpty()) throw new RuntimeException("鏈瘑鍒埌鏈夋晥鏈堜唤琛岋細A 鍒楀簲涓烘棩鏈燂紙濡� 2026-07锛夛紝B-E 涓哄叏鐪佸杩愰噺/鍩庡競鍐�/鍛ㄨ浆閲�/鍩庡競鍐呭懆杞噺");
+        int ok = upsertWycTotal(rows);
+        log.info("WycTotal imported: {} periods ok={}", rows.size(), ok);
+        return ok;
+    }
+
+    /** 缃戠害杞﹁鍗曞強鍏ㄧ渷鎬婚噺锛氭ā鏉縚缃戠害杞﹁鍗曞強鍏ㄧ渷鎬婚噺.xlsx 棣栦釜鏁版嵁 sheet锛圓=鏈堜唤锛汢-E=鍏ㄧ渷 pin锛汧=璁㈠崟鍚堣锛汫-W=17 甯傚窞璁㈠崟锛� */
+    public synchronized int importWycOrder(MultipartFile file, String period) throws Exception {
+        Map<String, WycOrderMonthly> rows = new LinkedHashMap<>();
+        try (Workbook wb = WorkbookFactory.create(file.getInputStream())) {
+            Sheet sheet = wb.getSheetAt(0);
+            int head = -1;
+            for (int r = 0; r <= Math.min(sheet.getLastRowNum(), 4); r++) {
+                Row row = sheet.getRow(r);
+                if (row == null) continue;
+                String a = getString(row, 0);
+                if (a != null && a.contains("鏈堜唤")) { head = r; break; }
+            }
+            if (head < 0) throw new RuntimeException("鏈壘鍒拌〃澶达細A 鍒楅渶鍚�滄湀浠解��");
+            for (int r = head + 1; r <= sheet.getLastRowNum(); r++) {
+                Row row = sheet.getRow(r);
+                if (row == null) continue;
+                String rp = periodOfCell(row.getCell(0));
+                if (rp == null) continue;
+                double pk = dbl(row, 1), pck = dbl(row, 2), pz = dbl(row, 3), pcz = dbl(row, 4), sum = dbl(row, 5);
+                double citySum = 0;
+                for (int k = 0; k < 17; k++) citySum += dbl(row, 6 + k);
+                if (pk <= 0 && pck <= 0 && pz <= 0 && pcz <= 0 && sum <= 0 && citySum <= 0) continue;
+                WycOrderMonthly it = new WycOrderMonthly();
+                it.setReportPeriod(rp);
+                it.setPinK(pk > 0 ? pk : null);
+                it.setPinCK(pck > 0 ? pck : null);
+                it.setPinZ(pz > 0 ? pz : null);
+                it.setPinCZ(pcz > 0 ? pcz : null);
+                if (sum <= 0 && citySum > 0) sum = citySum;
+                it.setOrderSum(sum > 0 ? sum : null);
+                it.setOrderWuhan(dblN(row, 6));
+                it.setOrderHuangshi(dblN(row, 7));
+                it.setOrderShiyan(dblN(row, 8));
+                it.setOrderYichang(dblN(row, 9));
+                it.setOrderXiangyang(dblN(row, 10));
+                it.setOrderEzhou(dblN(row, 11));
+                it.setOrderJingmen(dblN(row, 12));
+                it.setOrderXiaogan(dblN(row, 13));
+                it.setOrderJingzhou(dblN(row, 14));
+                it.setOrderHuanggang(dblN(row, 15));
+                it.setOrderXianning(dblN(row, 16));
+                it.setOrderSuizhou(dblN(row, 17));
+                it.setOrderEnshi(dblN(row, 18));
+                it.setOrderXiantao(dblN(row, 19));
+                it.setOrderQianjiang(dblN(row, 20));
+                it.setOrderTianmen(dblN(row, 21));
+                it.setOrderShennong(dblN(row, 22));
+                rows.put(rp, it);
+            }
+        }
+        if (rows.isEmpty()) throw new RuntimeException("鏈瘑鍒埌鏈夋晥鏈堜唤琛岋細A 鍒楀簲涓� yyyy-MM锛孊-E 鍏ㄧ渷 pin / F 鍚堣 / G-W 17 甯傚窞璁㈠崟");
+        int ok = upsertWyc(rows);
+        log.info("WycOrder imported: {} periods ok={}", rows.size(), ok);
+        return ok;
+    }
+
+    private int upsertWyc(Map<String, WycOrderMonthly> rows) {
+        int ok = 0, fail = 0;
+        for (WycOrderMonthly item : rows.values()) {
+            try {
+                wycOrderMapper.delete(new LambdaQueryWrapper<WycOrderMonthly>().eq(WycOrderMonthly::getReportPeriod, item.getReportPeriod()));
+                wycOrderMapper.insert(item);
+                recordBatch("缃戠害杞﹁鍗曞強鍏ㄧ渷鎬婚噺", "WYC_ORDER", item.getReportPeriod(), 1, 1, 0, null);
+                ok++;
+            } catch (Exception e) {
+                fail++;
+                log.error("WycOrder insert error period={}", item.getReportPeriod(), e);
+            }
+        }
+        return ok;
+    }
+
+    private int upsertWycTotal(Map<String, WycTotalMonthly> rows) {
+        int ok = 0, fail = 0;
+        for (WycTotalMonthly item : rows.values()) {
+            try {
+                wycTotalMapper.delete(new LambdaQueryWrapper<WycTotalMonthly>().eq(WycTotalMonthly::getReportPeriod, item.getReportPeriod()));
+                wycTotalMapper.insert(item);
+                recordBatch("缃戠害杞︽�绘暟", "WYC_TOTAL", item.getReportPeriod(), 1, 1, 0, null);
+                ok++;
+            } catch (Exception e) {
+                fail++;
+                log.error("WycTotal insert error period={}", item.getReportPeriod(), e);
+            }
+        }
+        return ok;
+    }
+
+    private String periodOfCell(Cell c) {
+        if (c == null) return null;
+        if (c.getCellType() == CellType.NUMERIC) {
+            try {
+                double v = c.getNumericCellValue();
+                if (v >= 40000 && v <= 60000) {
+                    java.util.Date d = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(v);
+                    java.text.SimpleDateFormat f = new java.text.SimpleDateFormat("yyyy-MM");
+                    return f.format(d);
+                }
+            } catch (Exception ignore) { }
+        }
+        String s = null;
+        try { s = c.getStringCellValue(); } catch (Exception ignore) { }
+        if (s != null) {
+            java.util.regex.Matcher m = java.util.regex.Pattern.compile("(\\d{4})[-/.骞碷(\\d{1,2})").matcher(s.trim());
+            if (m.find()) return String.format("%04d-%02d", Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)));
+        }
+        return null;
+    }
+
+    private double dbl(Row row, int idx) {
+        Double v = getDecimal(row, idx);
+        return v == null ? 0.0 : v;
+    }
+
+    private Double dblN(Row row, int idx) {
+        Double v = getDecimal(row, idx);
+        return (v == null || v <= 0) ? null : v;
+    }
+
     /** 杩愭斂鍑虹杞﹀競宸炴彁鍙栵細閬撹矾杩愯緭璇佸瓧鍙封啋妗f鍙封啋缁忚惀鏉冨彿鈫掍笟鎴峰湴鍧�锛屽彇 6 浣嶅尯鍒掍唬鐮� */
     private static final java.util.regex.Pattern TAXI_REGION_PAT =
         java.util.regex.Pattern.compile("(4290\\d{2}|42(?:0[1-9]|1[0-3]|28)\\d{2})");
@@ -3040,6 +3239,8 @@
             case "trackMileage": return new ImportResult(importTrackMileage(file, period), 0, new ArrayList<>());
             case "freightTurnover": return new ImportResult(importFreightTurnover(file, period), 0, new ArrayList<>());
             case "scaleSplit": return new ImportResult(importScaleSplit(file, period), 0, new ArrayList<>());
+            case "wycTotal": return new ImportResult(importWycTotal(file, period), 0, new ArrayList<>());
+            case "wycOrder": return new ImportResult(importWycOrder(file, period), 0, new ArrayList<>());
             default: throw new RuntimeException("涓嶆敮鎸佺殑瀵煎叆绫诲瀷锛�" + type);
         }
     }

--
Gitblit v1.9.1