This commit is contained in:
2026-09-20 15:49:29 +08:00
parent 75c2bd092f
commit 0dec690235
3 changed files with 34 additions and 1 deletions
@@ -52,4 +52,17 @@ public class IamCustomerSnapshotService {
throw new BizException(ResultCode.SERVICE_UNAVAILABLE, "客户主数据服务暂不可用");
}
}
/**
* 打印托盘信息单时客户昵称属于展示字段,客户资料尚未补全不应阻断 PDF 生成。
* 下游服务不可用等基础设施错误仍然向上抛出,避免静默生成不完整数据。
*/
public String customerNicknameForPrint(long customerId) {
try {
return customerNickname(customerId);
} catch (BizException exception) {
if (exception.getResultCode() == ResultCode.CONFLICT) return "—";
throw exception;
}
}
}
@@ -163,7 +163,7 @@ public class InboundCartonLabelPrintService {
List<PrintPdfClient.DropshipPalletInboundRow> inboundRows = inboundFacts.stream()
.map(row -> new PrintPdfClient.DropshipPalletInboundRow(
row.getInboundCode(),
customerNicknameCache.computeIfAbsent(row.getTenantId(), customerSnapshots::customerNickname),
customerNicknameCache.computeIfAbsent(row.getTenantId(), customerSnapshots::customerNicknameForPrint),
number(row.getCartonCount()), number(row.getItemQuantity())))
.toList();
String destinationWarehouse = inboundFacts.stream()
@@ -146,6 +146,26 @@ class InboundCartonLabelPrintServiceTest {
assertThat(request.getValue().documents().get(1).skuRows()).hasSize(1);
}
@Test
void printsPalletDocumentWhenCustomerNicknameIsMissing() {
Pallet pallet = dropshipPallet("OPEN");
stubPalletFacts(90001L);
when(customerSnapshots.customerNicknameForPrint(10001L)).thenReturn("—");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_PDF);
when(print.generateDropshipPalletA4Documents(org.mockito.ArgumentMatchers.anyString(),
org.mockito.ArgumentMatchers.eq("request-missing-nickname"), org.mockito.ArgumentMatchers.any()))
.thenReturn(new ResponseEntity<>(new byte[] {1}, headers, org.springframework.http.HttpStatus.OK));
service.generateDropshipPallet(pallet, "PCHK2608040174", "request-missing-nickname");
ArgumentCaptor<PrintPdfClient.DropshipPalletA4PdfRequest> request =
ArgumentCaptor.forClass(PrintPdfClient.DropshipPalletA4PdfRequest.class);
verify(print).generateDropshipPalletA4Documents(org.mockito.ArgumentMatchers.anyString(),
org.mockito.ArgumentMatchers.eq("request-missing-nickname"), request.capture());
assertThat(request.getValue().documents().get(0).inboundRows().get(0).customerNickname()).isEqualTo("—");
}
@Test
void forwardsStableLabelsWithoutSkuAndOnlySafePdfHeaders() throws Exception {
when(labels.list(10001L, 70001L, List.of(1))).thenReturn(batch());