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