fix(firstleg): allow confirmed preload reassign during loading
This commit is contained in:
@@ -136,8 +136,13 @@ public class SmartLoadingService {
|
|||||||
if (candidate == null) throw conflict("入库货物不存在或尚未完成入库");
|
if (candidate == null) throw conflict("入库货物不存在或尚未完成入库");
|
||||||
requireSameChannel(booking, candidate);
|
requireSameChannel(booking, candidate);
|
||||||
requireSameCustomerScope(booking, candidate);
|
requireSameCustomerScope(booking, candidate);
|
||||||
splitPreloadService.ensurePendingForLoadingAllocation(candidate.accountId(), candidate.inboundId(),
|
if ("LOADING".equals(plan.getPlanStatus())) {
|
||||||
operatorId, operatorName);
|
splitPreloadService.ensureForRunningLoadingAllocation(candidate.accountId(), candidate.inboundId(),
|
||||||
|
operatorId, operatorName);
|
||||||
|
} else {
|
||||||
|
splitPreloadService.ensurePendingForLoadingAllocation(candidate.accountId(), candidate.inboundId(),
|
||||||
|
operatorId, operatorName);
|
||||||
|
}
|
||||||
OrderCargoClient.CargoBinding cargo = loadCargo(candidate);
|
OrderCargoClient.CargoBinding cargo = loadCargo(candidate);
|
||||||
LoadingPlanItemEntity existing = repository.activeItem(planId, candidate.accountId(), request.inboundDetailId());
|
LoadingPlanItemEntity existing = repository.activeItem(planId, candidate.accountId(), request.inboundDetailId());
|
||||||
int total = request.packageCount() + (existing == null ? 0 : existing.getPackageCount());
|
int total = request.packageCount() + (existing == null ? 0 : existing.getPackageCount());
|
||||||
|
|||||||
@@ -68,11 +68,27 @@ public class SplitPreloadService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public void ensurePendingForLoadingAllocation(long tenantId, long inboundId, long operatorId,
|
public void ensurePendingForLoadingAllocation(long tenantId, long inboundId, long operatorId,
|
||||||
String operatorName) {
|
String operatorName) {
|
||||||
|
ensureForLoadingAllocation(tenantId, inboundId, operatorId, operatorName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A running loading task may re-add an inbound whose preload was confirmed by an earlier
|
||||||
|
* incremental allocation. Draft plans must still use the stricter pending-only entry point.
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void ensureForRunningLoadingAllocation(long tenantId, long inboundId, long operatorId,
|
||||||
|
String operatorName) {
|
||||||
|
ensureForLoadingAllocation(tenantId, inboundId, operatorId, operatorName, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureForLoadingAllocation(long tenantId, long inboundId, long operatorId,
|
||||||
|
String operatorName, boolean allowConfirmed) {
|
||||||
InboundSnapshot inbound = requireInbound(tenantId, inboundId);
|
InboundSnapshot inbound = requireInbound(tenantId, inboundId);
|
||||||
requireWaitingSplit(inbound, "仅待分柜订单可以建立智能装柜预装计划");
|
requireWaitingSplit(inbound, "仅待分柜订单可以建立智能装柜预装计划");
|
||||||
PreloadPlanEntity plan = repository.findPlan(tenantId, inboundId);
|
PreloadPlanEntity plan = repository.findPlan(tenantId, inboundId);
|
||||||
if (plan != null) {
|
if (plan != null) {
|
||||||
if (!PreloadStatus.PENDING.equals(plan.getStatus())) {
|
if (!PreloadStatus.PENDING.equals(plan.getStatus())
|
||||||
|
&& !(allowConfirmed && PreloadStatus.CONFIRMED.equals(plan.getStatus()))) {
|
||||||
throw new BizException(ResultCode.CONFLICT, "预装计划已进入确认流程,不能修改智能装柜分配");
|
throw new BizException(ResultCode.CONFLICT, "预装计划已进入确认流程,不能修改智能装柜分配");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -360,6 +360,8 @@ class SmartLoadingServiceTest {
|
|||||||
Plan result = service.assign(1, new AssignRequest(10L, 20L, 1, 5, "assign-loading"), 7, "u");
|
Plan result = service.assign(1, new AssignRequest(10L, 20L, 1, 5, "assign-loading"), 7, "u");
|
||||||
|
|
||||||
assertThat(result.status()).isEqualTo("LOADING");
|
assertThat(result.status()).isEqualTo("LOADING");
|
||||||
|
verify(splitPreloadService).ensureForRunningLoadingAllocation(9L, 10L, 7L, "u");
|
||||||
|
verify(splitPreloadService, never()).ensurePendingForLoadingAllocation(anyLong(), anyLong(), anyLong(), anyString());
|
||||||
var order = inOrder(loadingPickService, repository, loadingModelBridge);
|
var order = inOrder(loadingPickService, repository, loadingModelBridge);
|
||||||
order.verify(loadingPickService).lockMutable(1L);
|
order.verify(loadingPickService).lockMutable(1L);
|
||||||
order.verify(repository).touch(1, 5, 7, "u");
|
order.verify(repository).touch(1, 5, 7, "u");
|
||||||
|
|||||||
@@ -80,4 +80,16 @@ class SplitPreloadServiceTest {
|
|||||||
verify(repository, never()).createPlan(any());
|
verify(repository, never()).createPlan(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void runningLoadingAllocationMayReuseConfirmedPreload() {
|
||||||
|
when(repository.findInbound(10, 20)).thenReturn(new InboundSnapshot(20L, 10L, "WAIT_SPLIT", 3));
|
||||||
|
PreloadPlanEntity plan = new PreloadPlanEntity();
|
||||||
|
plan.setStatus("CONFIRMED");
|
||||||
|
when(repository.findPlan(10, 20)).thenReturn(plan);
|
||||||
|
|
||||||
|
service.ensureForRunningLoadingAllocation(10, 20, 7, "admin");
|
||||||
|
|
||||||
|
verify(repository, never()).createPlan(any());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user