优化
This commit is contained in:
@@ -16,6 +16,7 @@ import com.baiyue.firstleg.entity.LoadingPickHistoryEntity;
|
||||
import com.baiyue.firstleg.entity.LoadingPickItemEntity;
|
||||
import com.baiyue.firstleg.entity.LoadingPickOperationEntity;
|
||||
import com.baiyue.firstleg.entity.LoadingPickTaskEntity;
|
||||
import com.baiyue.firstleg.entity.LoadingPlanItemEntity;
|
||||
import com.baiyue.firstleg.repository.LoadingPickRepository;
|
||||
import com.baiyue.firstleg.repository.SmartLoadingRepository;
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -352,6 +353,69 @@ class LoadingPickServiceTest {
|
||||
verify(repository, never()).touchTask(any(Long.class), any(Integer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void staleTaskVersionDoesNotDriftItemAndFollowingValidBatchSucceeds() {
|
||||
LoadingPickTaskEntity task = task();
|
||||
LoadingPickItemEntity item = item();
|
||||
when(repository.taskForUpdate(20L)).thenReturn(task);
|
||||
when(repository.task(20L)).thenReturn(task);
|
||||
when(repository.assignment(20L)).thenReturn(assignment());
|
||||
when(repository.items(20L)).thenReturn(List.of(item));
|
||||
when(repository.items(20L, 101L)).thenReturn(List.of(item));
|
||||
when(repository.pick(30L, 2, "MANUAL", "[]", 0, 101L)).thenReturn(1);
|
||||
when(repository.allTaskItemsResolved(20L)).thenReturn(true);
|
||||
when(repository.touchTask(20L, 0)).thenReturn(1);
|
||||
when(warehouse.occupiedResources(any(), any(Long.class), any(), any(Long.class))).thenReturn(
|
||||
ApiResponse.success(List.of(new WarehousePalletLocationClient.OccupiedResource(
|
||||
71L, 72L, 0, 101L, 73L, 74L, "A-01", false, 2))));
|
||||
String snapshotToken = service.inventorySnapshot(20L, 101L).snapshotToken();
|
||||
BatchItemRequest line = new BatchItemRequest(
|
||||
30L, "PICK", 2, null, "MANUAL", List.of(), 0, null);
|
||||
|
||||
assertThatThrownBy(() -> service.batch(20L, "batch-stale", new BatchRequest(
|
||||
101L, 10L, 99L, "CSLU1234567", 1, snapshotToken, List.of(line)), 9L, "operator"))
|
||||
.isInstanceOf(BizException.class)
|
||||
.hasMessageContaining("任务版本已变化");
|
||||
|
||||
assertThat(item.getVersion()).isZero();
|
||||
assertThat(item.getPickedPackageCount()).isZero();
|
||||
service.batch(20L, "batch-valid", new BatchRequest(
|
||||
101L, 10L, 99L, "CSLU1234567", 0, snapshotToken, List.of(line)), 9L, "operator");
|
||||
|
||||
verify(repository, times(1)).pick(30L, 2, "MANUAL", "[]", 0, 101L);
|
||||
verify(repository, times(1)).touchTask(20L, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedTaskBeginDoesNotChangePendingItemBeforeRejectedStaleBatch() {
|
||||
LoadingPickTaskEntity task = task();
|
||||
LoadingPickItemEntity pending = item();
|
||||
var planItem = new LoadingPlanItemEntity();
|
||||
planItem.setId(40L);
|
||||
planItem.setInboundId(50L);
|
||||
planItem.setInboundDetailId(60L);
|
||||
planItem.setPackageCount(2);
|
||||
when(repository.taskByPlan(10L)).thenReturn(task);
|
||||
when(repository.itemByPlanItem(40L)).thenReturn(pending);
|
||||
when(repository.taskForUpdate(20L)).thenReturn(task);
|
||||
|
||||
service.begin(10L, "CSLU1234567", 9L, "operator", List.of(planItem));
|
||||
|
||||
BatchRequest staleRequest = new BatchRequest(101L, 10L, 99L, "CSLU1234567", 1,
|
||||
"stale-token", List.of(
|
||||
new BatchItemRequest(30L, "PICK", 2, null, "AUTO", null, 0, null)));
|
||||
assertThatThrownBy(() -> service.batch(20L, "batch-stale-after-resync", staleRequest,
|
||||
9L, "operator")).isInstanceOf(BizException.class);
|
||||
|
||||
assertThat(pending.getVersion()).isZero();
|
||||
assertThat(pending.getPickedPackageCount()).isZero();
|
||||
assertThat(pending.getItemStatus()).isEqualTo("PENDING");
|
||||
verify(repository, never()).update(any(LoadingPickItemEntity.class));
|
||||
verify(repository, never()).pick(any(Long.class), any(Integer.class), any(), any(),
|
||||
any(Integer.class), any(Long.class));
|
||||
verify(repository, never()).touchTask(any(Long.class), any(Integer.class));
|
||||
}
|
||||
|
||||
private void preparePick(LoadingPickTaskEntity task, LoadingPickItemEntity item, String operationId) {
|
||||
when(repository.history(operationId)).thenReturn(null);
|
||||
when(repository.task(20L)).thenReturn(task);
|
||||
|
||||
Reference in New Issue
Block a user