fix: keep pallet labels on A4 templates

This commit is contained in:
2026-09-20 14:05:00 +08:00
parent ee97565f67
commit 493d62e04c
15 changed files with 269 additions and 27 deletions
@@ -21,13 +21,14 @@ public interface PrintPdfClient {
record FbaPalletRequest(String templateCode, PageSpec pageSpec, String downloadFileName, List<FbaPalletLabel> labels) {}
record FbaPalletLabel(String fbaWarehouseCode, String palletCode) {}
@PostMapping(value = "/inbound-marks", consumes = "application/json")
ResponseEntity<byte[]> generateInboundMarks(
@PostMapping(value = "/pallet-a4-labels", consumes = "application/json")
ResponseEntity<byte[]> generatePalletA4Labels(
@RequestHeader("X-Internal-Service-Token") String token,
@RequestHeader(value = "X-Request-Id", required = false) String requestId,
@RequestBody Request request);
@RequestBody PalletA4Request request);
record PalletA4Request(String templateCode, PageSpec pageSpec, String downloadFileName, List<PalletA4Label> labels) {}
record PalletA4Label(String heading, String reference, String palletCode) {}
record Request(String templateCode, PageSpec pageSpec, String downloadFileName, List<Label> labels) {}
record PageSpec(BigDecimal widthMm, BigDecimal heightMm) {}
record Label(String topCode, String warehouseText, String cartonText, String routeText, String qrContent) {}
}
@@ -39,7 +39,7 @@ public class PalletLabelPrintService {
String code = pallet.getPalletCode();
String fbaCode = pallet.getFbaWarehouseCode();
boolean fba = fbaCode != null && !fbaCode.isBlank();
int maxCodeLength = fba ? 80 : 34;
int maxCodeLength = 80;
// Preserve the authoritative pallet identity on both the barcode and visible text.
if (code == null || !code.matches("[\\x20-\\x7E]{1," + maxCodeLength + "}") || code.isBlank()
|| !code.equals(code.strip())) {
@@ -47,17 +47,14 @@ public class PalletLabelPrintService {
}
var warehouse = warehouses.required(warehouseId);
String fileName = code.replaceAll("[\\\\/:*?\"<>|]", "-") + "-托盘码.pdf";
var label = new PrintPdfClient.Label(code,
fbaCode == null || fbaCode.isBlank() ? "目的仓待定" : fbaCode,
reference, warehouse.warehouseName(), code);
var request = new PrintPdfClient.Request("INBOUND_MARK_V1",
new PrintPdfClient.PageSpec(new BigDecimal("100"), new BigDecimal("100")), fileName, List.of(label));
try {
var response = fba
? print.generateFbaPalletLabels(internalToken, requestId, new PrintPdfClient.FbaPalletRequest(
"FBA_PALLET_A4_LANDSCAPE_V1", new PrintPdfClient.PageSpec(new BigDecimal("297"), new BigDecimal("210")),
fileName, List.of(new PrintPdfClient.FbaPalletLabel(fbaCode, code))))
: print.generateInboundMarks(internalToken, requestId, request);
: print.generatePalletA4Labels(internalToken, requestId, new PrintPdfClient.PalletA4Request(
"PALLET_A4_LANDSCAPE_V1", new PrintPdfClient.PageSpec(new BigDecimal("297"), new BigDecimal("210")),
fileName, List.of(new PrintPdfClient.PalletA4Label(warehouse.warehouseName(), reference, code))));
byte[] body = response == null ? null : response.getBody();
MediaType type = response == null ? null : response.getHeaders().getContentType();
if (response == null || !response.getStatusCode().is2xxSuccessful() || body == null || body.length == 0
@@ -7,7 +7,7 @@ paths:
get:
operationId: printOverseasPalletLabel
summary: 下载指定托盘的一页标签 PDF
description: 平台公共资源,要求 platform:overseas-warehouse:pallet:list。校验仓库和托盘归属后,有 FBA 仓码的托盘统一调用 Print FBA_PALLET_A4_LANDSCAPE_V1(297×210mm),顶部显示 SCK8 等 FBA 仓码,托盘完整编码同时作为 Code 128 内容和底部文字;内部编号如 141 原样保留。FBA 编码限 1–80 位可打印 ASCII,禁止首尾空格。不创建或修改托盘。其他托盘继续使用其现有 INBOUND_MARK_V1(100×100mm,编码限 1–34 位)。
description: 平台公共资源,要求 platform:overseas-warehouse:pallet:list。校验仓库和托盘归属后,有 FBA 仓码的托盘统一调用 Print FBA_PALLET_A4_LANDSCAPE_V1(297×210mm),顶部显示 SCK8 等 FBA 仓码;其他托盘调用 PALLET_A4_LANDSCAPE_V1(297×210mm),展示仓库名称和业务参考。托盘完整编码同时作为 Code 128 内容和底部文字,限 1–80 位可打印 ASCII 且禁止首尾空格。不创建或修改托盘,不复用 100×100mm 箱唛模板。
security:
- bearerAuth: []
parameters: