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 6ec5756b..d7d23df0 100644 --- a/src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java +++ b/src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java @@ -43,6 +43,9 @@ public class ExcelTemplate { // 报关单 @Setter private boolean delRight = false; + // 箱单 + @Setter + private boolean boxFlag = false; private ExcelTemplate(){} @@ -183,6 +186,7 @@ public class ExcelTemplate { } List dtlRows = new ArrayList<>(); + List boxRows = new ArrayList<>(); //整体填值 for (int i = 0; i <= sheet.getLastRowNum(); i++) { XSSFRow row = sheet.getRow(i); @@ -202,6 +206,9 @@ public class ExcelTemplate { if ("#{levy}".equals(cellValue)) { dtlRows.add(i); } + if ("#{cmcInvoice}".equals(cellValue)) { + boxRows.add(i); + } Matcher matcherHdr = PATTERN_HDR_FIELD.matcher(cellValue); String result = c.getStringCellValue(); while (matcherHdr.find()) { @@ -243,7 +250,7 @@ public class ExcelTemplate { } } } - + // 设置样式 if (cellStyle && dtlRowIndex >= 0 && i >= dtlRowIndex && i < dtlRowIndex + listVariables.size()) { XSSFCellStyle style = c.getCellStyle(); @@ -445,6 +452,54 @@ public class ExcelTemplate { } } } + if (boxFlag) { + for (Integer dtlRow : boxRows) { + for (int i = 1; i < 6; i++) { + if (i==1 || i==4 || i==5) { + XSSFRow row = sheet.getRow(dtlRow); + if (row == null) { + continue; + } + XSSFCell c7 = row.getCell(i); + if (c7 == null) { + continue; + } + // 尝试把字符串转成数值 + if (c7.getCellType() == CellType.STRING) { + String strVal = c7.getStringCellValue(); + if (strVal != null && !strVal.trim().isEmpty()) { + try { + double num = Double.parseDouble(strVal.replace(",", "")); + c7.setCellValue(num); // 转换为数值写回 + } catch (NumberFormatException e) { + // 如果不是数字就保留原字符串 + System.out.println("非数字,保持原值: " + strVal); + } + } + } + // 创建样式 + XSSFCellStyle style7 = workbook.createCellStyle(); + style7.setBorderRight(BorderStyle.THIN); + style7.setBorderLeft(BorderStyle.THIN); + style7.setBorderBottom(BorderStyle.THIN); + style7.setBorderTop(BorderStyle.THIN); + + Font font7 = workbook.createFont(); + font7.setFontName("DengXian"); // 等线 + font7.setFontHeightInPoints((short) 11); // 11号 + style7.setFont(font7); + + style7.setVerticalAlignment(VerticalAlignment.CENTER); + style7.setAlignment(HorizontalAlignment.RIGHT); + + // 设置千分位格式 + DataFormat dataFormat = workbook.createDataFormat(); + style7.setDataFormat(dataFormat.getFormat("#,##0")); + c7.setCellStyle(style7); + } + } + } + } return workbook; } } 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 e5039a0e..452fe029 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 @@ -429,6 +429,11 @@ public class CoDelController { coDelService.downloadPackingList(response, data); } + @PostMapping("/exportPackingTemplate") + public void exportPackingTemplate(HttpServletResponse response, @RequestBody EcssCoDelNotifyHeaderData data) { + coDelService.exportPackingTemplate(response, data); + } + @PostMapping("/downloadExportGoods") public void downloadExportGoods(HttpServletResponse response, @RequestBody EcssDeclarationHeaderData data) { coDelService.downloadExportGoods(response, data); diff --git a/src/main/java/com/xujie/sys/modules/ecss/service/CoDelService.java b/src/main/java/com/xujie/sys/modules/ecss/service/CoDelService.java index 5370f367..41b939b2 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/service/CoDelService.java +++ b/src/main/java/com/xujie/sys/modules/ecss/service/CoDelService.java @@ -125,6 +125,8 @@ public interface CoDelService { void downloadPackingList(HttpServletResponse response, EcssDeclarationHeaderData data); + void exportPackingTemplate(HttpServletResponse response, EcssCoDelNotifyHeaderData data); + void downloadExportGoods(HttpServletResponse response, EcssDeclarationHeaderData data); void downloadContract(HttpServletResponse response, EcssDeclarationHeaderData data); 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 81331481..65163c5d 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 @@ -1729,6 +1729,70 @@ public class CoDelServiceImpl implements CoDelService { } } + /** + * 导出装箱数据导入模版 + */ + @Override + public void exportPackingTemplate(HttpServletResponse response, EcssCoDelNotifyHeaderData data) { + try { + ExcelTemplate template = ExcelTemplate.load(new ClassPathResource("templates/packing-template.xlsx").getInputStream()); + template.setBoxFlag(true); + // 获取装箱数据 + List> palletList = sqlSession.selectList("ecssMapper.searchCoDelPalletData", data); + if (palletList == null || palletList.isEmpty()) { + // 如果没有装箱数据,获取通知单明细数据 + palletList = sqlSession.selectList("ecssMapper.searchEcssCoDelNotifyDetail", data); + } + //计算总数和总箱数 + int totalQty = 0; + int totalBoxQty = 0; + for (Map item : palletList) { + Object qtyObj = item.get("qty"); + Object boxQtyObj = item.get("boxQty"); + int qty = 0; + int boxQty = 0; + if (qtyObj instanceof Number) { + qty = ((Number) qtyObj).intValue(); + } else if (qtyObj instanceof String) { + try { + qty = Integer.parseInt((String) qtyObj); + } catch (NumberFormatException e) { + qty = 0; // 或者根据需求处理异常 + } + } + if (boxQtyObj instanceof Number) { + boxQty = ((Number) boxQtyObj).intValue(); + } else if (boxQtyObj instanceof String) { + try { + boxQty = Integer.parseInt((String) boxQtyObj); + } catch (NumberFormatException e) { + boxQty = 0; // 或者根据需求处理异常 + } + } + totalQty += qty; + totalBoxQty += boxQty; + item.put("qty", qty); + item.put("boxQty", boxQty); + } + + template.addVar("totalQty", totalQty); + template.addVar("totalBox", totalBoxQty); + // 添加数据列表 + template.addListVarAll( palletList); + + try (XSSFWorkbook workbook = template.render(0)) { + workbook.write(response.getOutputStream()); + } + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("Content-Disposition", "attachment; filename=\"装箱数据导入模版.xlsx\""); + response.flushBuffer(); + } catch (Exception e) { + log.error("导出装箱数据模版异常:{}", e.getMessage()); + e.printStackTrace(); + throw new RuntimeException("导出装箱数据模版异常:"+e.getMessage()); + } + } + /** * 导出出口货物委托书 */ diff --git a/src/main/resources/mapper/ecss/EcssCommonMapper.xml b/src/main/resources/mapper/ecss/EcssCommonMapper.xml index 2e1388c8..22159ef2 100644 --- a/src/main/resources/mapper/ecss/EcssCommonMapper.xml +++ b/src/main/resources/mapper/ecss/EcssCommonMapper.xml @@ -32,7 +32,8 @@ select b.po_no as customerPO,b.part_no,b.qty, a.box_qty as boxQty,b.rolls,b.pn,a.gross_weight as grossWeight,a.net_weight as netWeight, - #{cmcInvoice} as cmcInvoice,#{shippingMode} as shippingMode,#{destination} as destination + #{cmcInvoice} as cmcInvoice,#{shippingMode} as shippingMode,#{destination} as destination, + c.remark,CONVERT(varchar(10), #{readyDate}, 120) AS readyDate from ecss_CoDelBoxList a left join ecss_CoDelPalletDetail b on a.site=b.site and a.bu_no=b.bu_no and a.delNo=b.delNo and a.item_no=b.seq_no + left join ecss_CoDelNotifydetail c on b.site=c.site and b.bu_no=c.bu_no and b.delNo=c.delNo and b.notify_detail_item_no=c.item_no where a.site=#{site} and a.bu_no=#{buNo} and a.delNo=#{delNo} and b.site is not null diff --git a/src/main/resources/templates/packing-template.xlsx b/src/main/resources/templates/packing-template.xlsx new file mode 100644 index 00000000..61206dd4 Binary files /dev/null and b/src/main/resources/templates/packing-template.xlsx differ