diff --git a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelTXServiceImpl.java b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelTXServiceImpl.java index b762712e..6b57a0e2 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelTXServiceImpl.java +++ b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelTXServiceImpl.java @@ -64,6 +64,8 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { "PO", "ERP编码", "名称", "Currency", "TP", "Total Revanue", "托数", "总体积", "净重", "毛重", "箱数","Qty" ); + private static final String LOADING_NO_HIDE_MARKER = "__HIDE_LOADING_NO__"; + private static final float LOADING_NO_COMPRESS_HEIGHT_POINTS = 4F; @Override public Map previewExcelTX(MultipartFile file, EcssCoDelNotifyHeaderData inData) { String site = coDelMapper.getSiteByBu(inData.getBuNo()); @@ -974,6 +976,87 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { || "02-Hardtag".equalsIgnoreCase(buNoTrim); } + /** + * Alpha/硬标场景按客户名称、客户地址、收货地址是否包含 Spain/España 决定是否显示 Loading No. + */ + private String resolveLoadingNoTemplateValue(EcssDeclarationHeaderData data, EcssCoDelNotifyHeaderData notifyHeader) { + String buNo = notifyHeader != null && StringUtils.isNotBlank(notifyHeader.getBuNo()) + ? notifyHeader.getBuNo() : (data == null ? "" : data.getBuNo()); + if (!isShowOrderNoBu(buNo)) { + return ""; + } + + boolean containsSpain = containsSpainKeyword( + notifyHeader == null ? "" : notifyHeader.getCustomerName(), + notifyHeader == null ? "" : notifyHeader.getLocalShipAddress(), + notifyHeader == null ? "" : notifyHeader.getOverseasAddress(), + data == null ? "" : data.getLocalShipper(), + data == null ? "" : data.getLocalShipAddress(), + data == null ? "" : data.getOverseasAddress() + ); + return containsSpain ? "Loading No." : LOADING_NO_HIDE_MARKER; + } + + private boolean containsSpainKeyword(String... sourceTexts) { + if (sourceTexts == null || sourceTexts.length == 0) { + return false; + } + for (String sourceText : sourceTexts) { + if (StringUtils.isBlank(sourceText)) { + continue; + } + String normalizedText = normalizeCountryCompareText(sourceText); + if (normalizedText.contains("SPAIN") || normalizedText.contains("ESPANA")) { + return true; + } + } + return false; + } + + private String normalizeCountryCompareText(String sourceText) { + if (StringUtils.isBlank(sourceText)) { + return ""; + } + String normalized = java.text.Normalizer.normalize(sourceText, java.text.Normalizer.Form.NFD); + normalized = normalized.replaceAll("\\p{M}+", ""); + return normalized.toUpperCase(Locale.ROOT); + } + + /** + * 渲染后压缩隐藏 Loading No. 的行高,避免空白占高。 + */ + private void compactLoadingNoRowIfNeeded(XSSFWorkbook workbook) { + if (workbook == null) { + return; + } + for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) { + Sheet sheet = workbook.getSheetAt(sheetIndex); + if (sheet == null) { + continue; + } + for (Row row : sheet) { + if (row == null) { + continue; + } + boolean needCompress = false; + for (Cell cell : row) { + if (cell == null || cell.getCellType() != CellType.STRING) { + continue; + } + if (LOADING_NO_HIDE_MARKER.equals(cell.getStringCellValue())) { + cell.setCellValue(""); + needCompress = true; + } + } + if (needCompress) { + float defaultHeight = sheet.getDefaultRowHeightInPoints(); + float targetHeight = Math.min(defaultHeight, LOADING_NO_COMPRESS_HEIGHT_POINTS); + row.setHeightInPoints(targetHeight); + } + } + } + } + /** * 当前“天线”BU仅对 04-MHM 做报关单数值格式特殊处理。 */ @@ -1344,6 +1427,7 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { ExcelTemplateTX template = ExcelTemplateTX.load(new ClassPathResource(xlsx).getInputStream()); extractedInvoice(data, new TxExcelTemplateAdapter(template), notifyHeader); try (XSSFWorkbook workbook = template.render(0)) { + compactLoadingNoRowIfNeeded(workbook); workbook.write(response.getOutputStream()); } response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); @@ -1621,6 +1705,7 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { template.render(4); } + compactLoadingNoRowIfNeeded(workbook); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("Content-Disposition", "attachment; filename=\"danzheng.xlsx\""); workbook.write(response.getOutputStream()); @@ -1739,6 +1824,7 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { template.render(3); } + compactLoadingNoRowIfNeeded(excelWorkbook); // 将Excel转换为PDF byte[] pdfBytes = convertExcelToPdf(excelWorkbook); @@ -2137,6 +2223,7 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { template.addVar("Currency", currency); template.addVar("Incoterm", "EXW "); template.addVar("shippingMode", stringInput(notifyHeader.getShippingMode())); + template.addVar("loadingNo", resolveLoadingNoTemplateValue(data, notifyHeader)); Map notifyDetailMap = notifyDetailList.stream().collect( Collectors.toMap(EcssCoDelNotifyDetailData::getPartNo,e->e)); // 装箱数据 diff --git a/src/main/resources/templates/ALPHA/declaration-all-template-pdf.xlsx b/src/main/resources/templates/ALPHA/declaration-all-template-pdf.xlsx index 80bf4b86..cfbb9cc1 100644 Binary files a/src/main/resources/templates/ALPHA/declaration-all-template-pdf.xlsx and b/src/main/resources/templates/ALPHA/declaration-all-template-pdf.xlsx differ diff --git a/src/main/resources/templates/ALPHA/declaration-all-template.xlsx b/src/main/resources/templates/ALPHA/declaration-all-template.xlsx index c33f6367..1784dbcf 100644 Binary files a/src/main/resources/templates/ALPHA/declaration-all-template.xlsx and b/src/main/resources/templates/ALPHA/declaration-all-template.xlsx differ diff --git a/src/main/resources/templates/TX/declaration-all-template-pdf.xlsx b/src/main/resources/templates/TX/declaration-all-template-pdf.xlsx index 6a985a15..8c9c3475 100644 Binary files a/src/main/resources/templates/TX/declaration-all-template-pdf.xlsx and b/src/main/resources/templates/TX/declaration-all-template-pdf.xlsx differ diff --git a/src/main/resources/templates/TX/declaration-all-template.xlsx b/src/main/resources/templates/TX/declaration-all-template.xlsx index c7c6ca73..9c6d6ad8 100644 Binary files a/src/main/resources/templates/TX/declaration-all-template.xlsx and b/src/main/resources/templates/TX/declaration-all-template.xlsx differ diff --git a/src/main/resources/templates/TX/declaration-invoice2-template.xlsx b/src/main/resources/templates/TX/declaration-invoice2-template.xlsx index 81df4803..91334fb0 100644 Binary files a/src/main/resources/templates/TX/declaration-invoice2-template.xlsx and b/src/main/resources/templates/TX/declaration-invoice2-template.xlsx differ diff --git a/src/main/resources/templates/TX/export-goods-template.xlsx b/src/main/resources/templates/TX/export-goods-template.xlsx index d9aa5a37..be697c3d 100644 Binary files a/src/main/resources/templates/TX/export-goods-template.xlsx and b/src/main/resources/templates/TX/export-goods-template.xlsx differ diff --git a/src/main/resources/templates/YB/declaration-all-template-invoice-pdf.xlsx b/src/main/resources/templates/YB/declaration-all-template-invoice-pdf.xlsx index fed29018..6b8c5074 100644 Binary files a/src/main/resources/templates/YB/declaration-all-template-invoice-pdf.xlsx and b/src/main/resources/templates/YB/declaration-all-template-invoice-pdf.xlsx differ diff --git a/src/main/resources/templates/YB/declaration-all-template-invoice.xlsx b/src/main/resources/templates/YB/declaration-all-template-invoice.xlsx index 78497983..00ce5d58 100644 Binary files a/src/main/resources/templates/YB/declaration-all-template-invoice.xlsx and b/src/main/resources/templates/YB/declaration-all-template-invoice.xlsx differ diff --git a/src/main/resources/templates/YB/declaration-all-template-pdf.xlsx b/src/main/resources/templates/YB/declaration-all-template-pdf.xlsx index 3a1b2913..a35d99ef 100644 Binary files a/src/main/resources/templates/YB/declaration-all-template-pdf.xlsx and b/src/main/resources/templates/YB/declaration-all-template-pdf.xlsx differ diff --git a/src/main/resources/templates/YB/declaration-all-template.xlsx b/src/main/resources/templates/YB/declaration-all-template.xlsx index 6ae7cea3..e44c2ed1 100644 Binary files a/src/main/resources/templates/YB/declaration-all-template.xlsx and b/src/main/resources/templates/YB/declaration-all-template.xlsx differ diff --git a/src/main/resources/templates/YB/declaration-packingList-template.xlsx b/src/main/resources/templates/YB/declaration-packingList-template.xlsx index 79c31e4c..dd930b76 100644 Binary files a/src/main/resources/templates/YB/declaration-packingList-template.xlsx and b/src/main/resources/templates/YB/declaration-packingList-template.xlsx differ