fix: keep pallet labels on A4 templates
This commit is contained in:
+6
-5
@@ -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) {}
|
||||
}
|
||||
|
||||
+4
-7
@@ -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:
|
||||
|
||||
+13
-12
@@ -56,7 +56,6 @@ class PalletLabelPrintServiceTest {
|
||||
assertThat(response.getBody()).isEqualTo(pdf);
|
||||
verify(resources).pallet(0L, 200L, 9L);
|
||||
verifyNoMoreInteractions(resources);
|
||||
verify(print, never()).generateInboundMarks(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,18 +63,20 @@ class PalletLabelPrintServiceTest {
|
||||
pallet.setPalletCode("ABCD1234567-ABE3-003");
|
||||
pallet.setFbaWarehouseCode(null);
|
||||
byte[] pdf = "%PDF-transfer-label".getBytes(java.nio.charset.StandardCharsets.US_ASCII);
|
||||
when(print.generateInboundMarks(anyString(), anyString(), any()))
|
||||
when(print.generatePalletA4Labels(anyString(), anyString(), any()))
|
||||
.thenReturn(ResponseEntity.ok().contentType(MediaType.APPLICATION_PDF).body(pdf));
|
||||
|
||||
service.printTransfer(200L, 9L, "WTR-20260916-1", "request-transfer");
|
||||
|
||||
var request = ArgumentCaptor.forClass(PrintPdfClient.Request.class);
|
||||
verify(print).generateInboundMarks(eq("test-token"), eq("request-transfer"), request.capture());
|
||||
var request = ArgumentCaptor.forClass(PrintPdfClient.PalletA4Request.class);
|
||||
verify(print).generatePalletA4Labels(eq("test-token"), eq("request-transfer"), request.capture());
|
||||
assertThat(request.getValue().templateCode()).isEqualTo("PALLET_A4_LANDSCAPE_V1");
|
||||
assertThat(request.getValue().pageSpec().widthMm()).isEqualByComparingTo("297");
|
||||
assertThat(request.getValue().pageSpec().heightMm()).isEqualByComparingTo("210");
|
||||
assertThat(request.getValue().labels()).singleElement().satisfies(label -> {
|
||||
assertThat(label.topCode()).isEqualTo("ABCD1234567-ABE3-003");
|
||||
assertThat(label.cartonText()).isEqualTo("转运单 WTR-20260916-1");
|
||||
assertThat(label.warehouseText()).isEqualTo("目的仓待定");
|
||||
assertThat(label.routeText()).isEqualTo("洛杉矶仓");
|
||||
assertThat(label.heading()).isEqualTo("洛杉矶仓");
|
||||
assertThat(label.reference()).isEqualTo("转运单 WTR-20260916-1");
|
||||
assertThat(label.palletCode()).isEqualTo("ABCD1234567-ABE3-003");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -120,12 +121,12 @@ class PalletLabelPrintServiceTest {
|
||||
@Test
|
||||
void keepsNonFbaLabelsOnTheirOwnTemplate() {
|
||||
pallet.setFbaWarehouseCode(null);
|
||||
when(print.generateInboundMarks(anyString(), anyString(), any()))
|
||||
when(print.generatePalletA4Labels(anyString(), anyString(), any()))
|
||||
.thenReturn(ResponseEntity.ok().contentType(MediaType.APPLICATION_PDF).body("%PDF-other".getBytes()));
|
||||
service.print(200L, 9L, "request-1");
|
||||
var captor = ArgumentCaptor.forClass(PrintPdfClient.Request.class);
|
||||
verify(print).generateInboundMarks(anyString(), anyString(), captor.capture());
|
||||
assertThat(captor.getValue().templateCode()).isEqualTo("INBOUND_MARK_V1");
|
||||
var captor = ArgumentCaptor.forClass(PrintPdfClient.PalletA4Request.class);
|
||||
verify(print).generatePalletA4Labels(anyString(), anyString(), captor.capture());
|
||||
assertThat(captor.getValue().templateCode()).isEqualTo("PALLET_A4_LANDSCAPE_V1");
|
||||
verify(print, never()).generateFbaPalletLabels(any(), any(), any());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user