| | |
| | | } |
| | | } |
| | | |
| | | /** 公路旅客运政车辆数(独立模板:企业代码/企业名称/车辆数/载客位数) */ |
| | | /** 公路旅客运政车辆数(兼容两种表头:① 企业代码/企业名称/车辆数/载客位数;② 运政库导出 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, "企业代码"); |
| | | if (nameCol == null || vehicleCol == null || seatCol == null) { |
| | | throw new RuntimeException("所选数据类型【旅客运政车辆数】与文件内容不符:表头需含【企业名称/车辆数/载客位数】或【OWNERNAME/总车辆数/客位数】,请确认是否选错了数据类型或使用了旧模板"); |
| | | } |
| | | 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, "企业代码")); |
| | | 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) { |
| | |
| | | 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(); |
| | |
| | | Sheet sheet = wb.getSheetAt(i); |
| | | String sheetName = sheet.getSheetName(); |
| | | String periodType = null; |
| | | if (sheetName.contains("当月") || 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行子表头应含「周转量」或「货运量」(扩展布局) |
| | |
| | | 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) { |
| | | Integer idx = colMap.get(header); |
| | | return idx == null ? -1 : idx; |