贴标申请,仓储转运

This commit is contained in:
2026-09-24 14:42:24 +08:00
parent 56f4e6e35c
commit bcf44affd7
2 changed files with 29 additions and 1 deletions
@@ -758,10 +758,16 @@ public class WarehouseTransferService {
&& pallet.getPalletNo().equals(request.palletCode().trim())) return detail(transfer.getCustomerId(), transferNo);
if (!"GENERATED".equals(pallet.getStatus())) throw conflict("Only a generated pallet can be scan-bound");
if (!pallet.getPalletNo().equals(request.palletCode().trim())) throw conflict("Scanned pallet code does not match this generated pallet");
var physical = warehouseResources.resolvePallet(request.palletCode().trim());
// Generation already persisted the warehouse pallet's immutable physical id.
// Resolve by that id during binding instead of relying on the warehouse code
// index, which can lag immediately after a new pallet is confirmed.
var physical = warehouseResources.resolvePallet(pallet.getWarehousePalletId());
if (physical.palletId() != pallet.getWarehousePalletId() || physical.warehouseId() != warehouseId) {
throw conflict("Scanned pallet does not belong to this transfer and warehouse");
}
if (!pallet.getPalletNo().equals(physical.palletNo())) {
throw conflict("Generated pallet identity does not match the warehouse pallet");
}
pallet.setStatus("BOUND"); pallet.setBindIdempotencyKey(request.idempotencyKey());
pallet.setBoundAt(LocalDateTime.now()); pallet.setUpdatedAt(LocalDateTime.now()); transferPallets.updateById(pallet);
return detail(transfer.getCustomerId(), transferNo);
@@ -229,6 +229,28 @@ class WarehouseTransferServiceTest {
verify(warehouseResources, never()).resolvePallet(anyString());
}
@Test
void scanBindingResolvesNewlyGeneratedPalletByPersistedPhysicalId() {
WarehouseTransferOrder transfer = transfer(WarehouseTransferService.WAIT_PDA_RECEIVING);
transfer.setOperatingWarehouseId("77");
WarehouseTransferPallet pallet = measuredPallet("GENERATED");
when(transfers.lockForPda("WTR-1", "77")).thenReturn(transfer);
when(transferPallets.lockOne("TENANT-A", transfer.getId(), pallet.getId())).thenReturn(pallet);
when(warehouseResources.resolvePallet(701L)).thenReturn(new WarehouseResourceGateway.WarehousePalletReference(
701L, "NEW-PALLET-1", 77L, 801L, "OCCUPIED", "ONT8", 0));
when(transfers.findNo("TENANT-A", "WTR-1")).thenReturn(transfer);
when(transferItems.selectList(any())).thenReturn(List.of());
when(sourceOrders.selectList(any())).thenReturn(List.of());
when(transferPallets.listOrder("TENANT-A", transfer.getId())).thenReturn(List.of(pallet));
service.bindPallet(77L, "WTR-1", pallet.getId(),
new WarehouseTransferRequests.PalletBind("NEW-PALLET-1", "BIND-1"));
assertEquals("BOUND", pallet.getStatus());
verify(warehouseResources).resolvePallet(701L);
verify(warehouseResources, never()).resolvePallet(anyString());
}
@Test
void palletizeRejectsWhenAnyPersistedPalletIsNotBound() {
WarehouseTransferOrder transfer = transfer(WarehouseTransferService.WAIT_PDA_RECEIVING);