优化
This commit is contained in:
+9
@@ -12,6 +12,15 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
||||
@FeignClient(name = "print-service", contextId = "overseasWarehousePrintPdfClient",
|
||||
url = "${baiyue.clients.print.url:}", path = "/internal/print/v1/pdfs")
|
||||
public interface PrintPdfClient {
|
||||
@PostMapping(value = "/fba-pallet-labels", consumes = "application/json")
|
||||
ResponseEntity<byte[]> generateFbaPalletLabels(
|
||||
@RequestHeader("X-Internal-Service-Token") String token,
|
||||
@RequestHeader(value = "X-Request-Id", required = false) String requestId,
|
||||
@RequestBody FbaPalletRequest request);
|
||||
|
||||
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(
|
||||
@RequestHeader("X-Internal-Service-Token") String token,
|
||||
|
||||
+12
-5
@@ -27,19 +27,26 @@ public class PalletLabelPrintService {
|
||||
public ResponseEntity<byte[]> print(long warehouseId, long palletId, String requestId) {
|
||||
var pallet = resources.pallet(WarehouseResourceService.PUBLIC_RESOURCE_SCOPE, warehouseId, palletId);
|
||||
String code = pallet.getPalletCode();
|
||||
// Keep the stored business code intact, including the QR payload.
|
||||
if (code == null || !code.matches("[\\x20-\\x7E]{1,34}") || code.isBlank()) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "当前标签模板要求托盘编码为 1–34 位可打印 ASCII 字符,请核对托盘编码");
|
||||
String fbaCode = pallet.getFbaWarehouseCode();
|
||||
boolean fba = fbaCode != null && !fbaCode.isBlank();
|
||||
int maxCodeLength = fba ? 80 : 34;
|
||||
// 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())) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "当前标签模板要求托盘编码为 1–" + maxCodeLength + " 位可打印 ASCII 字符,且无首尾空格,请核对托盘编码");
|
||||
}
|
||||
var warehouse = warehouses.required(warehouseId);
|
||||
String fbaCode = pallet.getFbaWarehouseCode();
|
||||
String fileName = code.replaceAll("[\\\\/:*?\"<>|]", "-") + "-托盘码.pdf";
|
||||
var label = new PrintPdfClient.Label(code, fbaCode == null || fbaCode.isBlank() ? "—" : fbaCode,
|
||||
"PALLET", 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 = print.generateInboundMarks(internalToken, requestId, request);
|
||||
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);
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user