diff --git a/src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java b/src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java index bf78b11e..6ec5756b 100644 --- a/src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java +++ b/src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java @@ -74,8 +74,11 @@ public class ExcelTemplate { moveShape = false; moveSeal = false; cellStyle = false; + cellStyle2 = false; rangeStyle = false; priceRight = false; + intRight = false; + delRight = false; } private boolean findAndRemoveMergedRegion(XSSFSheet sheet, int rowIndex) { @@ -211,8 +214,18 @@ public class ExcelTemplate { c.setCellValue(result); // 字符串 } else { try { - double num = Double.parseDouble(result.replace(",", "")); - c.setCellValue(num); // 数值 + // 更严格的数字检查 + String cleanResult = result.replace(",", "").trim(); + if (!cleanResult.isEmpty() && !cleanResult.equals("-") && !cleanResult.equals(".")) { + double num = Double.parseDouble(cleanResult); + if (Double.isFinite(num)) { + c.setCellValue(num); // 数值 + } else { + c.setCellValue(result); // 字符串 + } + } else { + c.setCellValue(result); // 字符串 + } } catch (NumberFormatException e) { c.setCellValue(result); // 字符串 } @@ -223,24 +236,29 @@ public class ExcelTemplate { while (matcherDtl.find()) { for (int ri = 1; ri <= matcherDtl.groupCount(); ri++) { String field = matcherDtl.group(ri); - c.setCellValue(cellValue.replace(matcherDtl.group(0), String.valueOf(listVariables.get(i - dtlRowIndex).getOrDefault(field, "")))); + // 检查数组边界,避免越界异常 + int listIndex = i - dtlRowIndex; + if (listIndex >= 0 && listIndex < listVariables.size()) { + c.setCellValue(cellValue.replace(matcherDtl.group(0), String.valueOf(listVariables.get(listIndex).getOrDefault(field, "")))); + } } - // 设置样式 - if (cellStyle) { - XSSFCellStyle style = c.getCellStyle(); - style.setBorderBottom(BorderStyle.NONE); - style.setBorderTop(BorderStyle.NONE); - style.setWrapText(true); - style.setAlignment(HorizontalAlignment.LEFT); - c.setCellStyle(style); - if (rangeStyle && j < 4) { - for (int mi = 0; mi < 3; mi++) { - XSSFCell nextc = sheet.getRow(i).getCell(c.getColumnIndex()+mi+1); - if (nextc == null) { - continue; - } - nextc.setCellStyle(style); + } + + // 设置样式 + if (cellStyle && dtlRowIndex >= 0 && i >= dtlRowIndex && i < dtlRowIndex + listVariables.size()) { + XSSFCellStyle style = c.getCellStyle(); + style.setBorderBottom(BorderStyle.NONE); + style.setBorderTop(BorderStyle.NONE); + style.setWrapText(true); + style.setAlignment(HorizontalAlignment.LEFT); + c.setCellStyle(style); + if (rangeStyle && j < 4) { + for (int mi = 0; mi < 3; mi++) { + XSSFCell nextc = sheet.getRow(i).getCell(c.getColumnIndex()+mi+1); + if (nextc == null) { + continue; } + nextc.setCellStyle(style); } } } @@ -282,9 +300,13 @@ public class ExcelTemplate { style2.setAlignment(HorizontalAlignment.LEFT); style2.setWrapText(true); c2.setCellStyle(style2); - if (priceRight) { //仅供发票excel使用,第8、9是价格列居右 + if (priceRight) { //仅供发票excel使用,第6、7、8是价格列居右 for (int i = 6; i < 9; i++) { - XSSFCell c7 = sheet.getRow(dtlRow).getCell(i); + XSSFRow row = sheet.getRow(dtlRow); + if (row == null) { + continue; + } + XSSFCell c7 = row.getCell(i); if (c7 == null) { continue; } @@ -326,11 +348,14 @@ public class ExcelTemplate { c7.setCellStyle(style7); } - } if (intRight) { //仅供箱单excel使用 for (int i = 4; i < 9; i++) { - XSSFCell c7 = sheet.getRow(dtlRow).getCell(i); + XSSFRow row = sheet.getRow(dtlRow); + if (row == null) { + continue; + } + XSSFCell c7 = row.getCell(i); if (c7 == null) { continue; } @@ -372,7 +397,6 @@ public class ExcelTemplate { } c7.setCellStyle(style7); } - } } } @@ -380,7 +404,11 @@ public class ExcelTemplate { for (Integer dtlRow : dtlRows) { for (int i = 6; i < 12; i++) { if (i==6 || i==11) { - XSSFCell c7 = sheet.getRow(dtlRow).getCell(i); + XSSFRow row = sheet.getRow(dtlRow); + if (row == null) { + continue; + } + XSSFCell c7 = row.getCell(i); if (c7 == null) { continue; } diff --git a/src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java b/src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java index 0c6d36c6..b140cb5d 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java +++ b/src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java @@ -405,45 +405,38 @@ public class CoDelController { } @PostMapping("/downloadDeclarationElements") - public R downloadDeclarationElements(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { + public void downloadDeclarationElements(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { coDelService.downloadDeclarationElements(response, data); - return R.ok(); } @PostMapping("/downloadDeclaration") - public R downloadDeclaration(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { + public void downloadDeclaration(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { coDelService.downloadDeclaration(response, data); - return R.ok(); } @PostMapping("/downloadInvoice") - public R downloadInvoice(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { + public void downloadInvoice(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { coDelService.downloadInvoice(response, data); - return R.ok(); } @PostMapping("/downloadPackingList") - public R downloadPackingList(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { + public void downloadPackingList(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { coDelService.downloadPackingList(response, data); - return R.ok(); } @PostMapping("/downloadExportGoods") - public R downloadExportGoods(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { + public void downloadExportGoods(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { coDelService.downloadExportGoods(response, data); - return R.ok(); } @PostMapping("/downloadContract") - public R downloadContract(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { + public void downloadContract(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { coDelService.downloadContract(response, data); - return R.ok(); } @PostMapping("/downloadAll") - public R downloadAll(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { + public void downloadAll(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { coDelService.downloadAll(response, data); - return R.ok(); } @PostMapping("/saveOneClickPacking") diff --git a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java index ac3b824e..8f5211b3 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java +++ b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java @@ -1604,34 +1604,41 @@ public class CoDelServiceImpl implements CoDelService { XSSFWorkbook workbook = null; try { ExcelTemplate template = ExcelTemplate.load(new ClassPathResource(xlsx).getInputStream()); + + // 第一个sheet - 出口货物委托书 extractedExportGoods(data, template); workbook = template.render(0); - // 出口货物委托书、发票、箱单、报关单、申报要素 - // 开始第二个sheet 发票 + + // 第二个sheet - 发票 template.clearAll(); - extractedInvoice(data, template,notifyHeader); - workbook = template.render(1); - // 第三个sheet 箱单 + extractedInvoice(data, template, notifyHeader); + template.render(1); + + // 第三个sheet - 箱单 template.clearAll(); - exportPackingList(data, template,notifyHeader,0); - workbook = template.render(2); - // 第四个sheet 报关单 + exportPackingList(data, template, notifyHeader, 0); + template.render(2); + + // 第四个sheet - 报关单 template.clearAll(); extractedDeclaration(data, template); - workbook = template.render(3); - // 第五个sheet 申报要素 + template.render(3); + + // 第五个sheet - 申报要素 template.clearAll(); extractedElements(data, template); - workbook = template.render(4); - // 第六个sheet 合同 + template.render(4); + + // 第六个sheet - 合同 (仅特定BU需要) if (notifyHeader.getBuNo().equals("04-MHM") || notifyHeader.getBuNo().equals("02-Hardtag")) { template.clearAll(); extractedContract(data, template); - workbook = template.render(5); + template.render(5); } - workbook.write(response.getOutputStream()); + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("Content-Disposition", "attachment; filename=\"单证信息.xlsx\""); + workbook.write(response.getOutputStream()); response.flushBuffer(); } catch (IOException e) { log.error("报关导出所有异常:{}", e.getMessage()); diff --git a/src/main/resources/templates/declaration-all-seal-template.xlsx b/src/main/resources/templates/declaration-all-seal-template.xlsx index 4f6ee4dd..42211187 100644 Binary files a/src/main/resources/templates/declaration-all-seal-template.xlsx and b/src/main/resources/templates/declaration-all-seal-template.xlsx differ diff --git a/src/main/resources/templates/declaration-all-template.xlsx b/src/main/resources/templates/declaration-all-template.xlsx index d82863f5..67f9a84e 100644 Binary files a/src/main/resources/templates/declaration-all-template.xlsx and b/src/main/resources/templates/declaration-all-template.xlsx differ diff --git a/src/main/resources/templates/declaration-all2-template.xlsx b/src/main/resources/templates/declaration-all2-template.xlsx index 4d3454b1..56b4f472 100644 Binary files a/src/main/resources/templates/declaration-all2-template.xlsx and b/src/main/resources/templates/declaration-all2-template.xlsx differ diff --git a/src/main/resources/templates/declaration-invoice-seal-template.xlsx b/src/main/resources/templates/declaration-invoice-seal-template.xlsx index a8887c74..0c7ba408 100644 Binary files a/src/main/resources/templates/declaration-invoice-seal-template.xlsx and b/src/main/resources/templates/declaration-invoice-seal-template.xlsx differ diff --git a/src/main/resources/templates/declaration-invoice2-template.xlsx b/src/main/resources/templates/declaration-invoice2-template.xlsx index cf3dc946..71c9a583 100644 Binary files a/src/main/resources/templates/declaration-invoice2-template.xlsx and b/src/main/resources/templates/declaration-invoice2-template.xlsx differ diff --git a/src/main/resources/templates/declaration-packingList2-template.xlsx b/src/main/resources/templates/declaration-packingList2-template.xlsx index 01d4be76..78249662 100644 Binary files a/src/main/resources/templates/declaration-packingList2-template.xlsx and b/src/main/resources/templates/declaration-packingList2-template.xlsx differ