优化
This commit is contained in:
@@ -356,7 +356,7 @@ paths:
|
||||
type: object
|
||||
required: [boxCode, length, width, height, machineNo, picture]
|
||||
properties:
|
||||
boxCode: {type: string, maxLength: 128, example: 'ZBYHK2608140897#4-1'}
|
||||
boxCode: {type: string, maxLength: 128, example: 'ZBYHK2608140001#4-1'}
|
||||
shipment_id: {type: string, maxLength: 64, example: 'FBA19L5KMY2CU000002', description: '可选;设备从Amazon FBA箱标实际扫描得到,有则原样上传;系统只保存,不生成且不覆盖客户下单值'}
|
||||
length: {type: number, format: decimal, minimum: 0.001}
|
||||
width: {type: number, format: decimal, minimum: 0.001}
|
||||
@@ -982,7 +982,7 @@ components:
|
||||
tenantId: {type: string, pattern: '^[1-9][0-9]*$', description: 当前客户隔离 ID}
|
||||
orderId: {type: string, pattern: '^[1-9][0-9]*$'}
|
||||
orderNo: {type: string, nullable: true}
|
||||
inboundCode: {type: string, minLength: 1, maxLength: 40, example: ZBYHK2608140897}
|
||||
inboundCode: {type: string, minLength: 1, maxLength: 40, example: ZBYHK2608140001}
|
||||
customerId: {type: string, pattern: '^[1-9][0-9]*$', nullable: true}
|
||||
customerName: {type: string, minLength: 1}
|
||||
warehouseId: {type: string, pattern: '^[1-9][0-9]*$'}
|
||||
@@ -1217,7 +1217,7 @@ components:
|
||||
eventNo: {type: string, maxLength: 128, pattern: '^[A-Za-z0-9._:-]+$', example: M202608010001}
|
||||
externalDetailNo: {type: string, maxLength: 128, pattern: '^[A-Za-z0-9._:-]+$', example: BOX-20260801-0001}
|
||||
warehouseCode: {type: string, maxLength: 50, example: CN-YW-01}
|
||||
inboundCode: {type: string, maxLength: 40, example: ZBYHK2608140897}
|
||||
inboundCode: {type: string, maxLength: 40, example: ZBYHK2608140001}
|
||||
inboundDetailId: {type: string, example: '190000000000000001', description: 柏悦订单货物明细ID}
|
||||
deviceCode: {type: string, maxLength: 64, example: DEVICE-01}
|
||||
measuredAt: {type: string, format: date-time, example: '2026-08-01T10:30:00+08:00'}
|
||||
|
||||
+17
-17
@@ -60,8 +60,8 @@ class InboundCartonLabelServiceTest {
|
||||
|
||||
assertThat(batch.totalCount()).isEqualTo(5);
|
||||
assertThat(batch.labels()).extracting(label -> label.boxCode())
|
||||
.containsExactly("PCHK2608040174#5-1", "PCHK2608040174#5-2", "PCHK2608040174#5-3",
|
||||
"PCHK2608040174#5-4", "PCHK2608040174#5-5");
|
||||
.containsExactly("PCHK2608140001#5-1", "PCHK2608140001#5-2", "PCHK2608140001#5-3",
|
||||
"PCHK2608140001#5-4", "PCHK2608140001#5-5");
|
||||
assertThat(batch.labels()).extracting(label -> label.inboundDetailId())
|
||||
.containsExactly(80001L, 80001L, 80001L, 80002L, 80002L);
|
||||
assertThat(batch.labels().get(0).boxSpecification()).isEqualTo("60x40x30cm");
|
||||
@@ -102,8 +102,8 @@ class InboundCartonLabelServiceTest {
|
||||
.thenReturn(ApiResponse.success(List.of(cargo(80001L, 1, 2, "60", "40", "30"))));
|
||||
var result = service.getOrCreate(10001L, 70001L);
|
||||
assertThat(result.labels()).extracting(label -> label.boxCode())
|
||||
.containsExactly("PCHK2608040174#5-1", "PCHK2608040174#5-2", "PCHK2608040174#5-3",
|
||||
"PCHK2608040174#5-4", "PCHK2608040174#5-5");
|
||||
.containsExactly("PCHK2608140001#5-1", "PCHK2608140001#5-2", "PCHK2608140001#5-3",
|
||||
"PCHK2608140001#5-4", "PCHK2608140001#5-5");
|
||||
verify(repository, never()).insert(any());
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ class InboundCartonLabelServiceTest {
|
||||
|
||||
assertThat(result.totalCount()).isEqualTo(2);
|
||||
assertThat(result.labels()).extracting(label -> label.boxCode())
|
||||
.containsExactly("PCHK2608040174#2-1", "PCHK2608040174#2-2");
|
||||
.containsExactly("PCHK2608140001#2-1", "PCHK2608140001#2-2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,35 +154,35 @@ class InboundCartonLabelServiceTest {
|
||||
var result = service.getOrCreate(10001L, 70001L);
|
||||
|
||||
assertThat(result.labels()).extracting(label -> label.boxCode())
|
||||
.containsExactly("PCHK2608040174#1-1");
|
||||
.containsExactly("PCHK2608140001#1-1");
|
||||
verify(repository, never()).insert(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesBoxCodeInsideCustomerBoundary() {
|
||||
InboundCartonLabelEntity label = labels(inbound(), 1).get(0);
|
||||
when(repository.findByBoxCode(10001L, "PCHK2608040174#1-1")).thenReturn(label);
|
||||
when(repository.findByBoxCode(10001L, "PCHK2608140001#1-1")).thenReturn(label);
|
||||
|
||||
var resolved = service.resolveByBoxCode(10001L, " PCHK2608040174#1-1 ");
|
||||
var resolved = service.resolveByBoxCode(10001L, " PCHK2608140001#1-1 ");
|
||||
|
||||
assertThat(resolved.inboundId()).isEqualTo(70001L);
|
||||
assertThat(resolved.inboundDetailId()).isEqualTo(80001L);
|
||||
assertThat(resolved.inboundCode()).isEqualTo("PCHK2608040174");
|
||||
assertThat(resolved.inboundCode()).isEqualTo("PCHK2608140001");
|
||||
assertThat(resolved.cartonIndex()).isEqualTo(1);
|
||||
assertThat(resolved.totalCartons()).isEqualTo(1);
|
||||
assertThat(resolved.boxSpecification()).isEqualTo("60x40x30cm");
|
||||
verify(repository).findByBoxCode(10001L, "PCHK2608040174#1-1");
|
||||
verify(repository).findByBoxCode(10001L, "PCHK2608140001#1-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void exposesDetailedResolutionForFirstlegConsumers() {
|
||||
InboundCartonLabelEntity label = labels(inbound(), 1).get(0);
|
||||
when(repository.findByBoxCode(10001L, "PCHK2608040174#1-1")).thenReturn(label);
|
||||
when(repository.findByBoxCode(10001L, "PCHK2608140001#1-1")).thenReturn(label);
|
||||
|
||||
var resolved = service.resolveDetailsByBoxCode(10001L, "PCHK2608040174#1-1");
|
||||
var resolved = service.resolveDetailsByBoxCode(10001L, "PCHK2608140001#1-1");
|
||||
|
||||
assertThat(resolved.orderId()).isEqualTo(60001L);
|
||||
assertThat(resolved.boxCode()).isEqualTo("PCHK2608040174#1-1");
|
||||
assertThat(resolved.boxCode()).isEqualTo("PCHK2608140001#1-1");
|
||||
assertThat(resolved.cargoItemNo()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@@ -190,9 +190,9 @@ class InboundCartonLabelServiceTest {
|
||||
void rejectsInactiveBoxCodeDuringScanResolution() {
|
||||
InboundCartonLabelEntity label = labels(inbound(), 1).get(0);
|
||||
label.setBatchStatus("VOID");
|
||||
when(repository.findByBoxCode(10001L, "PCHK2608040174#1-1")).thenReturn(label);
|
||||
when(repository.findByBoxCode(10001L, "PCHK2608140001#1-1")).thenReturn(label);
|
||||
|
||||
assertThatThrownBy(() -> service.resolveByBoxCode(10001L, "PCHK2608040174#1-1"))
|
||||
assertThatThrownBy(() -> service.resolveByBoxCode(10001L, "PCHK2608140001#1-1"))
|
||||
.isInstanceOf(BizException.class)
|
||||
.hasMessage("箱码已失效,请重新打印");
|
||||
}
|
||||
@@ -233,7 +233,7 @@ class InboundCartonLabelServiceTest {
|
||||
@Test
|
||||
void repairsMissingHistoricalInboundFromOwnedOrderSnapshot() {
|
||||
var snapshot = new com.baiyue.firstleg.dto.OrderApprovedInboundCommand(
|
||||
10001L, 60001L, "FL60001", "PCHK2608040174", 1L, "Customer",
|
||||
10001L, 60001L, "FL60001", "PCHK2608140001", 1L, "Customer",
|
||||
41L, "Warehouse", null, null, null, "EXPORT_SEA", null, null,
|
||||
null, null, null, null, null, false, "FBA", null, null, null,
|
||||
null, null, null, 2);
|
||||
@@ -251,7 +251,7 @@ class InboundCartonLabelServiceTest {
|
||||
inbound.setId(70001L);
|
||||
inbound.setTenantId(10001L);
|
||||
inbound.setOrderId(60001L);
|
||||
inbound.setInboundCode("PCHK2608040174");
|
||||
inbound.setInboundCode("PCHK2608140001");
|
||||
inbound.setProcessStatus("WAIT_MEASURE");
|
||||
inbound.setWarehouseName("MCC1");
|
||||
inbound.setChannelName("洛杉矶普船海卡");
|
||||
|
||||
+10
-10
@@ -48,12 +48,12 @@ class InboundOrderCreationServiceTest {
|
||||
|
||||
@Test
|
||||
void shouldUseSubmittedInboundCodeAndKeepReplayIdempotentWithoutCarrier() {
|
||||
OrderApprovedInboundCommand command = approvedCommand("RK-CUSTOM-77");
|
||||
OrderApprovedInboundCommand command = approvedCommand("PCHK2608140001");
|
||||
InboundOrderEntity existing = new InboundOrderEntity();
|
||||
existing.setId(900L);
|
||||
existing.setTenantId(10001L);
|
||||
existing.setOrderId(77L);
|
||||
existing.setInboundCode("RK-CUSTOM-77");
|
||||
existing.setInboundCode("PCHK2608140001");
|
||||
existing.setTaskId(700L);
|
||||
when(orders.selectOne(any(Wrapper.class))).thenReturn(null, existing);
|
||||
when(fulfillmentTasks.provision(any(), any())).thenReturn(task(700L));
|
||||
@@ -64,7 +64,7 @@ class InboundOrderCreationServiceTest {
|
||||
ArgumentCaptor<InboundOrderEntity> inboundCaptor = ArgumentCaptor.forClass(InboundOrderEntity.class);
|
||||
verify(orders, times(1)).insert(inboundCaptor.capture());
|
||||
verify(histories, times(1)).insert(any(InboundStatusHistoryEntity.class));
|
||||
assertThat(inboundCaptor.getValue().getInboundCode()).isEqualTo("RK-CUSTOM-77");
|
||||
assertThat(inboundCaptor.getValue().getInboundCode()).isEqualTo("PCHK2608140001");
|
||||
assertThat(inboundCaptor.getValue().getTaskId()).isEqualTo(700L);
|
||||
assertThat(inboundCaptor.getValue().getCarrierId()).isNull();
|
||||
assertThat(inboundCaptor.getValue().getTaxMode()).isEqualTo("BUY_DECLARATION");
|
||||
@@ -88,25 +88,25 @@ class InboundOrderCreationServiceTest {
|
||||
|
||||
@Test
|
||||
void shouldConvergeOnConcurrentDuplicateInsertWinner() {
|
||||
InboundOrderEntity winner = inbound(901L, "RK-CUSTOM-77", "UNPRICED", null, null);
|
||||
InboundOrderEntity winner = inbound(901L, "PCHK2608140001", "UNPRICED", null, null);
|
||||
winner.setTaskId(700L);
|
||||
when(orders.selectOne(any(Wrapper.class))).thenReturn(null, winner);
|
||||
when(fulfillmentTasks.provision(any(), any())).thenReturn(task(700L));
|
||||
doThrow(new org.springframework.dao.DuplicateKeyException("concurrent insert"))
|
||||
.when(orders).insert(any(InboundOrderEntity.class));
|
||||
|
||||
assertThat(service.createFromApprovedOrder(approvedCommand("RK-CUSTOM-77"))).isEqualTo(901L);
|
||||
assertThat(service.createFromApprovedOrder(approvedCommand("PCHK2608140001"))).isEqualTo(901L);
|
||||
verify(histories, never()).insert(any(InboundStatusHistoryEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldBackfillTaskLinkForInboundCreatedBeforeTaskProvisioning() {
|
||||
InboundOrderEntity existing = inbound(900L, "RK-CUSTOM-77", "UNPRICED", null, null);
|
||||
InboundOrderEntity existing = inbound(900L, "PCHK2608140001", "UNPRICED", null, null);
|
||||
when(orders.selectOne(any(Wrapper.class))).thenReturn(existing);
|
||||
when(orders.update(any(), any(Wrapper.class))).thenReturn(1);
|
||||
when(fulfillmentTasks.provision(any(), any())).thenReturn(task(700L));
|
||||
|
||||
assertThat(service.createFromApprovedOrder(approvedCommand("RK-CUSTOM-77"))).isEqualTo(900L);
|
||||
assertThat(service.createFromApprovedOrder(approvedCommand("PCHK2608140001"))).isEqualTo(900L);
|
||||
|
||||
assertThat(existing.getTaskId()).isEqualTo(700L);
|
||||
verify(orders).update(any(), any(Wrapper.class));
|
||||
@@ -115,14 +115,14 @@ class InboundOrderCreationServiceTest {
|
||||
|
||||
@Test
|
||||
void shouldPrepareDraftIdempotentlyAndUpgradeSameInboundOnApproval() {
|
||||
InboundOrderEntity prepared = inbound(900L, "RK-CUSTOM-77", "UNPRICED", null, null);
|
||||
InboundOrderEntity prepared = inbound(900L, "PCHK2608140001", "UNPRICED", null, null);
|
||||
prepared.setProcessStatus("PREPARING");
|
||||
when(orders.selectOne(any(Wrapper.class))).thenReturn(null, prepared, prepared);
|
||||
when(orders.update(any(), any(Wrapper.class))).thenReturn(1);
|
||||
when(fulfillmentTasks.provision(any(), any())).thenReturn(task(700L));
|
||||
|
||||
long preparedId = service.prepareFromDraft(approvedCommand("RK-CUSTOM-77"));
|
||||
long approvedId = service.createFromApprovedOrder(approvedCommand("RK-CUSTOM-77"));
|
||||
long preparedId = service.prepareFromDraft(approvedCommand("PCHK2608140001"));
|
||||
long approvedId = service.createFromApprovedOrder(approvedCommand("PCHK2608140001"));
|
||||
|
||||
assertThat(preparedId).isNotNull();
|
||||
assertThat(approvedId).isEqualTo(900L);
|
||||
|
||||
@@ -45,6 +45,7 @@ class MerchantPriceBookServiceTest {
|
||||
@Test
|
||||
void shouldResolveNormalAndOverseasInboundCodePrefixesFromChannelCatalog() {
|
||||
when(repository.activeVersionId()).thenReturn(7L);
|
||||
when(repository.channelAvailable(7L, 10L, "MATSON_CLX_TRUCK")).thenReturn(true);
|
||||
when(repository.channels(7L, 10L)).thenReturn(List.of(
|
||||
channel(7L, "MATSON_CLX_TRUCK", PriceModel.FBA_WAREHOUSE_RATE)));
|
||||
when(repository.channelPrefix("MATSON_CLX_TRUCK"))
|
||||
@@ -59,6 +60,7 @@ class MerchantPriceBookServiceTest {
|
||||
@Test
|
||||
void shouldFallBackToNormalPrefixWhenChannelHasNoOverseasVariant() {
|
||||
when(repository.activeVersionId()).thenReturn(7L);
|
||||
when(repository.channelAvailable(7L, 10L, "OA_HOUSTON_TRUCK")).thenReturn(true);
|
||||
when(repository.channels(7L, 10L)).thenReturn(List.of(
|
||||
channel(7L, "OA_HOUSTON_TRUCK", PriceModel.FBA_WAREHOUSE_RATE)));
|
||||
when(repository.channelPrefix("OA_HOUSTON_TRUCK"))
|
||||
|
||||
+6
-6
@@ -50,7 +50,7 @@ class MojiaMeasurementOpenApiServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void fixedAppKeyJsonIsConvertedToTheExistingCartonMeasurementFlow() throws Exception {
|
||||
void generatedDailyInboundCartonCodeFlowsThroughMojiaMeasurement() throws Exception {
|
||||
MeasurementRequestAuthenticator authenticator = mock(MeasurementRequestAuthenticator.class);
|
||||
CartonMeasurementService cartons = mock(CartonMeasurementService.class);
|
||||
MeasurementImageClient images = mock(MeasurementImageClient.class);
|
||||
@@ -62,17 +62,17 @@ class MojiaMeasurementOpenApiServiceTest {
|
||||
when(authenticator.authenticate("POST", MojiaMeasurementOpenApiService.CALLBACK_PATH,
|
||||
headers, json(), false)).thenReturn(new AuthenticatedMeasurementApp("mojia", 10001L, 90001L, Map.of()));
|
||||
when(cartons.upsert(eq(10001L), eq(90001L), any())).thenReturn(new CartonMeasurementResult(
|
||||
1L, 1, 2L, "RK-001#4-1", "FBA19L5KMY2CU000002", 1,
|
||||
1L, 1, 2L, "PCHK2608140001#5-1", "FBA19L5KMY2CU000002", 1,
|
||||
new BigDecimal("60.1"), new BigDecimal("40.2"),
|
||||
new BigDecimal("30.3"), new BigDecimal("12.5"), 3L, "MJ-01", LocalDateTime.now(), true));
|
||||
|
||||
UploadResponse result = service.receive(headers, json());
|
||||
|
||||
assertThat(result.matched()).isTrue();
|
||||
assertThat(result.boxCode()).isEqualTo("RK-001#4-1");
|
||||
assertThat(result.boxCode()).isEqualTo("PCHK2608140001#5-1");
|
||||
ArgumentCaptor<CartonMeasurementCommand> command = ArgumentCaptor.forClass(CartonMeasurementCommand.class);
|
||||
verify(cartons).upsert(eq(10001L), eq(90001L), command.capture());
|
||||
assertThat(command.getValue().boxCode()).isEqualTo("RK-001#4-1");
|
||||
assertThat(command.getValue().boxCode()).isEqualTo("PCHK2608140001#5-1");
|
||||
assertThat(command.getValue().scannedShipmentId()).isEqualTo("FBA19L5KMY2CU000002");
|
||||
assertThat(command.getValue().lengthCm()).isEqualByComparingTo("60.1");
|
||||
assertThat(command.getValue().image().getContentType()).isEqualTo("image/jpeg");
|
||||
@@ -108,7 +108,7 @@ class MojiaMeasurementOpenApiServiceTest {
|
||||
ArgumentCaptor<MojiaMeasurementReceiptEntity> receipt =
|
||||
ArgumentCaptor.forClass(MojiaMeasurementReceiptEntity.class);
|
||||
verify(receipts).insert(receipt.capture());
|
||||
assertThat(receipt.getValue().getBoxCode()).isEqualTo("RK-001#4-1");
|
||||
assertThat(receipt.getValue().getBoxCode()).isEqualTo("PCHK2608140001#5-1");
|
||||
assertThat(receipt.getValue().getScannedShipmentId()).isNull();
|
||||
assertThat(receipt.getValue().getLengthCm()).isEqualByComparingTo("60.1");
|
||||
assertThat(receipt.getValue().getImageFileId()).isEqualTo(3L);
|
||||
@@ -117,7 +117,7 @@ class MojiaMeasurementOpenApiServiceTest {
|
||||
|
||||
private String json() {
|
||||
return """
|
||||
{"boxCode":"RK-001#4-1","shipment_id":"FBA19L5KMY2CU000002",
|
||||
{"boxCode":"PCHK2608140001#5-1","shipment_id":"FBA19L5KMY2CU000002",
|
||||
"length":60.1,"width":40.2,"height":30.3,
|
||||
"weight":12.5,"machineNo":"MJ-01","picture":"data:image/jpeg;base64,/9j/2Q=="}
|
||||
""";
|
||||
|
||||
Reference in New Issue
Block a user