|
|
|
@ -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<String, Object> 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<String, EcssCoDelNotifyDetailData> notifyDetailMap = notifyDetailList.stream().collect( |
|
|
|
Collectors.toMap(EcssCoDelNotifyDetailData::getPartNo,e->e)); |
|
|
|
// 装箱数据 |
|
|
|
|