This commit is contained in:
2026-10-16 17:43:07 +08:00
parent c9186c37a5
commit 9ea03eb540
7 changed files with 168 additions and 29 deletions
@@ -230,6 +230,11 @@ class RelabelApplicationServiceTest {
});
lenient().when(pdaTasks.updateWithVersion(any(), any())).thenReturn(1);
ReflectionTestUtils.setField(service, "applications", applications);
var statusRepository = new com.baiyue.lastleg.relabel.repository.RelabelStatusRepository();
ReflectionTestUtils.setField(statusRepository, "applications", applications);
ReflectionTestUtils.setField(statusRepository, "orders", orders);
ReflectionTestUtils.setField(statusRepository, "returnOrders", returnOrders);
ReflectionTestUtils.setField(service, "statusRepository", statusRepository);
ReflectionTestUtils.setField(service, "transferRelabelCompletion", transferRelabelCompletion);
ReflectionTestUtils.setField(service, "items", items);
ReflectionTestUtils.setField(service, "histories", histories);
@@ -1305,6 +1310,58 @@ class RelabelApplicationServiceTest {
verify(applications, never()).insert(any(RelabelApplication.class));
}
@org.junit.jupiter.params.ParameterizedTest
@org.junit.jupiter.params.provider.ValueSource(strings = {"PENDING_REVIEW", "PENDING_PROCESSING", "PROCESSING", "CUSTOMER_CONFIRM_PENDING", "REJECTED"})
void unfinishedApplicationsCanBeVoidedAndRetainTransferMainStatus(String status) {
var app = application(11L, "RL-VOID", "10001", "void-key", "hash", status);
app.setLastlegOrderId(21L); app.setWalletStatus("FROZEN");
when(applications.lockNo("10001", "RL-VOID")).thenReturn(app);
stubDetail(app);
var tail = order(21L, "10001", "WT-1", "INBOUND_COMPLETED"); tail.setOrderType("WAREHOUSE_TRANSFER");
when(orders.selectById(21L)).thenReturn(tail);
service.changeStatus("10001", "RL-VOID", "operator", new RelabelRequests.ChangeStatus("CANCELLED", "废弃预填换标要求"));
assertEquals("CANCELLED", app.getStatus());
assertEquals("INBOUND_COMPLETED", tail.getCurrentStatus());
assertEquals("CANCELLED", tail.getRelabelStatus());
assertEquals("RELEASE_PENDING", app.getWalletStatus());
verify(walletCommands).publish(eq("RELEASE"), eq(10001L), eq("RELABEL_ORDER"), eq("RL-VOID"), isNull(), anyString(), eq(2L));
verify(histories).insert(any(RelabelStatusHistory.class));
}
@Test void repeatedVoidReturnsExistingRecordWithoutReleasingAgain() {
var app = application(11L, "RL-VOID-AGAIN", "10001", "key", "hash", "CANCELLED");
app.setLastlegOrderId(21L);
when(applications.lockNo("10001", app.getRelabelNo())).thenReturn(app); stubDetail(app);
var result = service.changeStatus("10001", app.getRelabelNo(), "operator", new RelabelRequests.ChangeStatus("CANCELLED", "作废"));
assertEquals("CANCELLED", result.application().status());
verify(applications, never()).updateById(any(RelabelApplication.class));
verify(inventoryCommands, never()).release(anyString(), anyString(), any());
verify(histories, never()).insert(any(RelabelStatusHistory.class));
}
@Test void directPendingReviewApplicationCanBeVoidedOutsideTailOrderReview() {
var app = application(11L, "RL-DIRECT-VOID", "10001", "void-key", "hash", "PENDING_REVIEW");
app.setLastlegOrderId(21L);
when(applications.lockNo("10001", app.getRelabelNo())).thenReturn(app); stubDetail(app);
var tail = order(21L, "10001", "RL-ORDER", "WAIT_RELABEL"); tail.setOrderType("RELABEL_APPLICATION");
when(orders.selectById(21L)).thenReturn(tail);
service.changeStatus("10001", app.getRelabelNo(), "operator", new RelabelRequests.ChangeStatus("CANCELLED", "作废"));
assertEquals("CANCELLED", tail.getCurrentStatus());
}
@org.junit.jupiter.params.ParameterizedTest
@org.junit.jupiter.params.provider.ValueSource(strings = {"READY_FOR_OUTBOUND", "COMPLETED"})
void completedRelabelCannotBeVoided(String status) {
var app = application(11L, "RL-DONE", "10001", "key", "hash", status);
app.setLastlegOrderId(21L);
when(applications.lockNo("10001", "RL-DONE")).thenReturn(app);
when(orders.selectById(21L)).thenReturn(order(21L, "10001", "ORDER", "COMPLETED"));
var failure = assertThrows(ResponseStatusException.class, () -> service.changeStatus("10001", "RL-DONE", "operator", new RelabelRequests.ChangeStatus("CANCELLED", "作废")));
assertTrue(failure.getReason().contains("不能作废"));
verify(applications, never()).updateById(any(RelabelApplication.class));
verify(walletCommands, never()).publish(anyString(), anyLong(), anyString(), anyString(), any(), any(), anyLong());
}
private void stubDetail(RelabelApplication application) {
when(applications.findNo(application.getCustomerId(), application.getRelabelNo())).thenReturn(application);
when(items.selectList(any())).thenReturn(List.of(item(31L, application.getId(), "SKU-A", 10, 6)));
@@ -619,7 +619,7 @@ class WarehouseTransferServiceTest {
new BigDecimal("0.2500"), "WAREHOUSE_PICKUP", LocalDateTime.of(2026, 9, 12, 10, 0),
null, null, "TRACK-MUST-NOT-BE-SAVED", null, "Incoming transit cargo", true,
null, null, null, null, null, "key-incoming",
List.of(new WarehouseTransferRequests.Item("SKU-1", "Product A", 2, null),
List.of(new WarehouseTransferRequests.Item("SKU-1", "Product A", 2, null, null, List.of("BX-PRINTED1", "BX-PRINTED2")),
new WarehouseTransferRequests.Item("SKU-2", "Product B", 3, null)), null);
when(transfers.findNo(eq("TENANT-A"), anyString())).thenAnswer(invocation -> transfer(WarehouseTransferService.DRAFT));
when(transferItems.selectList(any())).thenReturn(List.of());
@@ -647,6 +647,8 @@ class WarehouseTransferServiceTest {
assertEquals("PENDING_BINDING", tailOrder.getValue().getRelabelStatus());
assertEquals(List.of(1, 2, 3, 4, 5), cartons.getAllValues().stream()
.map(WarehouseTransferCarton::getCartonIndex).toList());
assertEquals(List.of("BX-PRINTED1", "BX-PRINTED2"), cartons.getAllValues().subList(0, 2).stream()
.map(WarehouseTransferCarton::getCartonMark).toList());
assertTrue(cartons.getAllValues().stream().allMatch(value -> value.getCartonMark()
.matches("BX-[0-9A-Z]+")));
when(transfers.findKey("TENANT-A", request.idempotencyKey())).thenReturn(transfer.getValue());
@@ -814,7 +816,20 @@ class WarehouseTransferServiceTest {
verify(transfers, never()).updateById(any(WarehouseTransferOrder.class));
}
/** 草稿预先打印与后续正式提交使用同一服务端箱唛。 */
/** 未建单时生成的箱唛必须完整且不重复。 */
@Test
void duplicateOrMismatchedPreprintedMarksRejectBeforeCreatingOrder() throws Exception {
var mapper = new ObjectMapper().findAndRegisterModules();
for (var marks : List.of(List.of("BX-ONE"), List.of("BX-ONE", "BX-ONE", "BX-3", "BX-4", "BX-5"))) {
com.fasterxml.jackson.databind.node.ObjectNode json = mapper.valueToTree(request(false));
json.remove("inboundModeValid");
((com.fasterxml.jackson.databind.node.ObjectNode) json.get("items").get(0)).set("cartonMarks", mapper.valueToTree(marks));
var input = mapper.treeToValue(json, WarehouseTransferRequests.Create.class);
assertThrows(ResponseStatusException.class, () -> service.create("TENANT-A", "USER-1", input));
}
verify(transfers, never()).insert(any(WarehouseTransferOrder.class));
}
@Test
void draftCanPrintPersistedCartonLabels() {
WarehouseTransferOrder transfer = persistedTransfer(); transfer.setStatus(WarehouseTransferService.DRAFT);