This commit is contained in:
2026-09-16 15:21:08 +08:00
parent 912feca56f
commit 8f0622058d
20 changed files with 447 additions and 41 deletions
@@ -624,8 +624,7 @@ public class SmartLoadingService {
}
ContainerBookingEntity booking = requireBooking(plan.getContainerBookingId());
InboundOrderEntity lockedInbound = repository.inboundForUpdate(request.customerId(), inboundId);
if (lockedInbound == null || !Set.of("PREPARING", "WAIT_MEASURE", "WAIT_SPLIT")
.contains(lockedInbound.getProcessStatus())) {
if (lockedInbound == null || !SplitPreloadService.supportsPreAllocation(lockedInbound.getProcessStatus())) {
throw conflict("订单当前状态不能加入装柜清单");
}
if (!repository.activeItemsByInbound(request.customerId(), inboundId).isEmpty()) {
@@ -1170,8 +1169,13 @@ public class SmartLoadingService {
if(repository.remove(planId,item.getId(),item.getVersion(),operatorId,operatorName)!=1)
throw conflict("整托装柜明细已被并发修改");
}
LoadingPlanItemEntity first=palletItems.get(0);
loadingModelBridge.removeIfUnallocated(planId,first.getAccountId(),first.getInboundId());
Set<String> releasedInbounds = new HashSet<>();
for (LoadingPlanItemEntity item : palletItems) {
String key = item.getAccountId() + "|" + item.getInboundId();
if (releasedInbounds.add(key)) {
loadingModelBridge.removeIfUnallocated(planId, item.getAccountId(), item.getInboundId());
}
}
history(planId,null,"REMOVE_PALLET",plan.getPlanStatus(),plan.getPlanStatus(),operation,
json(values("palletId",palletId,"version",request.expectedPlanVersion())),
json(values("requestHash",requestHash,"removedLineCount",palletItems.size())),operatorId,operatorName);
@@ -27,6 +27,9 @@ import java.util.Set;
@Service
public class SplitPreloadService {
private static final String SMART_SPLIT = "SMART_SPLIT";
private static final Set<String> PRE_ALLOCATION_STATES = Set.of(
"PREPARING", "WAIT_MEASURE", "MEASURING", "MEASURE_PENDING", "MEASURE_REJECTED",
"WAIT_PRICING", "FEE_CONFIRMING", "INBOUNDING", "WAIT_SPLIT");
@Resource private SplitRepository repository;
@Resource private ObjectMapper objectMapper;
@@ -72,12 +75,12 @@ public class SplitPreloadService {
ensureLoadingAllocationLifecycle(tenantId, inboundId, operatorId, operatorName, false);
}
/** Creates a provisional preload lifecycle for an order selected before review/measurement. */
/** Creates a provisional preload lifecycle for an order selected before it reaches WAIT_SPLIT. */
@Transactional
public void ensurePendingForPreAllocation(long tenantId, long inboundId, long operatorId,
String operatorName) {
InboundSnapshot inbound = requireInbound(tenantId, inboundId);
if (!Set.of("PREPARING", "WAIT_MEASURE", "WAIT_SPLIT").contains(inbound.processStatus())) {
if (!supportsPreAllocation(inbound.processStatus())) {
throw new BizException(ResultCode.CONFLICT, "订单当前状态不能加入装柜清单");
}
PreloadPlanEntity plan = repository.findPlan(tenantId, inboundId);
@@ -89,7 +92,7 @@ public class SplitPreloadService {
}
plan = new PreloadPlanEntity();
plan.setTenantId(tenantId); plan.setInboundId(inboundId); plan.setStatus(PreloadStatus.PENDING);
plan.setVersion(0); plan.setItemsJson("[]"); plan.setRemark("订单审核前加入装柜清单自动建立");
plan.setVersion(0); plan.setItemsJson("[]"); plan.setRemark("智能装柜提前分配自动建立");
plan.setCreatedBy(operatorId); plan.setCreatedByName(operatorName);
plan.setUpdatedBy(operatorId); plan.setUpdatedByName(operatorName);
try {
@@ -102,6 +105,10 @@ public class SplitPreloadService {
}
}
public static boolean supportsPreAllocation(String processStatus) {
return PRE_ALLOCATION_STATES.contains(processStatus);
}
/** Reuses the confirmed preload lifecycle while a running PDA task owns the mutation lock. */
@Transactional
public void ensureForRunningLoadingAllocation(long tenantId, long inboundId, long operatorId,