diff --git a/src/main/java/com/xujie/sys/common/utils/ExcelTemplateALPHA.java b/src/main/java/com/xujie/sys/common/utils/ExcelTemplateALPHA.java index e1179514..e5beafc8 100644 --- a/src/main/java/com/xujie/sys/common/utils/ExcelTemplateALPHA.java +++ b/src/main/java/com/xujie/sys/common/utils/ExcelTemplateALPHA.java @@ -26,6 +26,8 @@ public class ExcelTemplateALPHA { private List mergeRegions = new ArrayList<>(); // 存储需要设置行高的行信息:[起始行索引, 结束行索引, 行高] private List rowHeights = new ArrayList<>(); + // 需要隐藏的列(0-based) + private Set hiddenColumns = new LinkedHashSet<>(); // 是否下移形状格式 @Setter private boolean moveShape = false; @@ -138,11 +140,21 @@ public class ExcelTemplateALPHA { } } + /** + * 隐藏指定列(0-based) + */ + public void hideColumn(int colIndex) { + if (colIndex >= 0) { + hiddenColumns.add(colIndex); + } + } + public void clearAll(){ variables.clear(); listVariables.clear(); mergeRegions.clear(); rowHeights.clear(); + hiddenColumns.clear(); moveShape = false; moveSeal = false; cellStyle = false; @@ -511,7 +523,7 @@ public class ExcelTemplateALPHA { DataFormat dataFormat = workbook.createDataFormat(); String numFmt; if (fixedInvoicePriceScale && invoiceUnitPriceCols.contains(i)) { - numFmt = "#,##0.00000"; + numFmt = "#,##0.0000"; } else if (fixedInvoicePriceScale && invoiceTotalPriceCols.contains(i)) { numFmt = "#,##0.00"; } else if (c7.getCellType() == CellType.NUMERIC) { @@ -587,7 +599,7 @@ public class ExcelTemplateALPHA { } else { numFmt2 = "#,##0"; } - style7.setDataFormat(dataFormat.getFormat(numFmt2)); + style7.setDataFormat(i==9||i==10?dataFormat.getFormat("#,##0.00"):dataFormat.getFormat(numFmt2)); } c7.setCellStyle(style7); } @@ -671,7 +683,7 @@ public class ExcelTemplateALPHA { DataFormat dataFormat = workbook.createDataFormat(); String numFmt3; if (declarationFixedFiveScaleColumn) { - numFmt3 = "#,##0.00000"; + numFmt3 = "#,##0.0000"; } else if (declarationFixedTwoScaleColumn) { numFmt3 = "#,##0.00"; } else if (declarationQtyColumn) { @@ -802,6 +814,15 @@ public class ExcelTemplateALPHA { } } + // 处理列隐藏 + if (!hiddenColumns.isEmpty()) { + for (Integer colIndex : hiddenColumns) { + if (colIndex != null && colIndex >= 0) { + sheet.setColumnHidden(colIndex, true); + } + } + } + return workbook; } 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 3fecdacf..16e20460 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 @@ -1155,12 +1155,8 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { } 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() + notifyHeader == null ? "" : notifyHeader.getDestination(), + data == null ? "" : data.getDestination() ); return containsSpain ? "Loading No." : LOADING_NO_HIDE_MARKER; } @@ -1181,6 +1177,52 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { return false; } + private boolean isUsaCanadaPackageUnitBu(String buNo) { + if (StringUtils.isBlank(buNo)) { + return false; + } + String buNoTrim = buNo.trim(); + return "05-Alpha".equalsIgnoreCase(buNoTrim) + || "02-Hardtag".equalsIgnoreCase(buNoTrim) + || "04-MHM".equalsIgnoreCase(buNoTrim); + } + + private boolean containsUsaOrCanadaKeyword(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("USA") || normalizedText.contains("CANADA")) { + return true; + } + } + return false; + } + + /** + * Alpha/硬标/天线场景按目的地 Destination 是否包含 USA/Canada 决定默认包装单位。 + */ + private String resolveDeclarationPackageUnit(EcssDeclarationHeaderData data, EcssCoDelNotifyHeaderData notifyHeader) { + String packageUnit = data == null ? "" : stringInput(data.getPackageUnit()).trim(); + if (StringUtils.isNotBlank(packageUnit)) { + return packageUnit; + } + String buNo = notifyHeader != null && StringUtils.isNotBlank(notifyHeader.getBuNo()) + ? notifyHeader.getBuNo() : (data == null ? "" : data.getBuNo()); + if (!isUsaCanadaPackageUnitBu(buNo)) { + return packageUnit; + } + boolean containsUsaOrCanada = containsUsaOrCanadaKeyword( + notifyHeader == null ? "" : notifyHeader.getDestination(), + data == null ? "" : data.getDestination() + ); + return containsUsaOrCanada ? "箱" : packageUnit; + } + private String normalizeCountryCompareText(String sourceText) { if (StringUtils.isBlank(sourceText)) { return ""; @@ -2181,8 +2223,9 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { .map(EcssCoDelPalletHeaderData::getPalletQty) .filter(Objects::nonNull) // 防止空指针 .reduce(0, Integer::sum); - template.addVar("packageQty", data.getPackageUnit()!=null&&data.getPackageUnit().equals("箱")?ecHeader.getBoxQty():totalPlt); - template.addVar("packageUnit", data.getPackageUnit()); + String packageUnit = resolveDeclarationPackageUnit(data, notifyHeader); + template.addVar("packageQty", "箱".equals(packageUnit) ? ecHeader.getBoxQty() : totalPlt); + template.addVar("packageUnit", packageUnit); // 托盘重量=根据每个pallet的重量*数量累加 BigDecimal palletWeight = BigDecimal.ZERO; for (EcssCoDelPalletHeaderData palletHeader : palletHeaderDataList) { @@ -2860,6 +2903,11 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { .map(EcssCoDelPalletHeaderData::getPalletQty) .filter(Objects::nonNull) // 防止空指针 .reduce(0, Integer::sum); + boolean hasPalletData = !palletHeaderDataList.isEmpty() && totalPlt > 0; + if (!hasPalletData) { + // Alpha箱单:无托盘时隐藏Pallet列(第9列,索引8) + template.hideColumn(8); + } // 发货通知单明细 List detailList = coDelMapper.exportEcssCoDelNotifyDetail(data); Set poNoSet = detailList.stream() @@ -2939,7 +2987,7 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { } Integer palletQty = palletQtyMap.get(palletSeqNo); // 第一列展示托号(pallet_no),按托盘首行显示,后续行留空再做按托合并 - eorder.put("seq_no", showPalletQty ? palletNo : ""); + eorder.put("seq_no", !hasPalletData?(showPalletQty ? palletNo : ""):boxNo); eorder.put("total_pallets", showPalletQty ? (palletQty != null ? palletQty : "") : ""); eorder.put("volume", isFirstRow ? volume : ""); eorder.put("gross_weight", isFirstRow ? ((BigDecimal) list.get(m).get("gross_weight")).setScale(2, RoundingMode.HALF_UP) : ""); @@ -3025,7 +3073,15 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService { } else { totalPlt = totalCartons.setScale(0, RoundingMode.HALF_UP).intValue(); } - template.addVar("total_plt", totalPlt+plt); + if (hasPalletData) { + template.addVar("total_plt", totalPlt+"PLT"); + template.addVar("plt(", "(="); + template.addVar("plt)", ")"); + template.addVar("PLT", "PLT"); + template.addVar("InclPalletWeight", "(Incl.Pallet Weight)"); + } else { + template.addVar("PLT", "CTN"); + } // 孟加拉需要的 if (data.getMaterial()!=null && data.getMaterial()) { template.addVar("RFIDBase", "RFID Base Material"); 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 42acd5ad..d7605ea3 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 415af505..372231d8 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/ALPHA/declaration-packingList-template.xlsx b/src/main/resources/templates/ALPHA/declaration-packingList-template.xlsx index e18b090c..88aabf6a 100644 Binary files a/src/main/resources/templates/ALPHA/declaration-packingList-template.xlsx and b/src/main/resources/templates/ALPHA/declaration-packingList-template.xlsx differ