fix(lastleg): scope inventory holds by cycle and align pick lock ordering

This commit is contained in:
2026-10-03 01:34:14 +08:00
parent 1db6e744c8
commit 7530a95fbd
9 changed files with 304 additions and 13 deletions
@@ -23,6 +23,7 @@ import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
@@ -80,6 +81,33 @@ class DispatchPickOrderAttributionServiceTest {
&& "PARTIALLY_SHIPPED".equals(value.getToStatus()) && value.getRemark().contains("6/10")));
}
@Test void pickingLocksDistinctSourcesInOrderBeforeRecheckingReceipts() {
when(attributions.availableReceipts("t1",91L)).thenReturn(List.of(receipt(2L,102L,1L,1L),
receipt(1L,101L,1L,1L),receipt(3L,102L,1L,1L)));
when(orders.lockById(eq("t1"),anyLong())).thenAnswer(call -> new LastlegOrder());
service().preparePicking("t1",91L,null);
var sequence=inOrder(attributions,orders);
sequence.verify(attributions).availableReceipts("t1",91L);
sequence.verify(orders).lockById("t1",101L);sequence.verify(orders).lockById("t1",102L);
sequence.verify(attributions).availableReceipts("t1",91L);
verify(orders,times(2)).lockById(eq("t1"),anyLong());
}
@Test void heldOrMissingSourcePreventsPickingPreparation() {
when(attributions.availableReceipts("t1",91L)).thenReturn(List.of(receipt(1L,101L,1L,1L)));
var held=new LastlegOrder();held.setDetained(true);
when(orders.lockById("t1",101L)).thenReturn(held).thenReturn(null);
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->service().preparePicking("t1",91L,null));
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->service().preparePicking("t1",91L,null));
verifyNoInteractions(history);
}
@Test void changedSourceSetAfterLockingFailsClosed() {
when(attributions.availableReceipts("t1",91L)).thenReturn(List.of(receipt(1L,101L,1L,1L)))
.thenReturn(List.of(receipt(2L,102L,1L,1L)));
when(orders.lockById("t1",101L)).thenReturn(new LastlegOrder());
assertThrows(org.springframework.web.server.ResponseStatusException.class,()->service().preparePicking("t1",91L,null));
verify(orders,never()).increasePicked(anyString(),anyLong(),anyLong());
}
private DispatchPickOrderAttributionService service() {
DispatchPickOrderAttributionService service = new DispatchPickOrderAttributionService();
ReflectionTestUtils.setField(service, "attributions", attributions);