fix: resolve cross-plan pallet allocations

This commit is contained in:
2026-09-11 16:10:49 +08:00
parent 64fa620c19
commit 2d928d667b
4 changed files with 78 additions and 3 deletions
@@ -49,7 +49,8 @@ public record InboundPlanResponse(
int actualPackageCount) {
}
public record Allocation(Long lineId, Long palletId, BigDecimal allocatedVolumeCbm,
public record Allocation(Long lineId, Long palletId, String palletNo, String palletOwnerPlanNo,
boolean palletOwnedByCurrentPlan, BigDecimal allocatedVolumeCbm,
int plannedPackageCount, int countedPackageCount, int pickedPackageCount,
BigDecimal actualVolumeCbm, String status, int version) {
}
@@ -1026,6 +1026,34 @@ public class InboundPlanService {
new LambdaQueryWrapper<InboundPlanPalletAllocation>()
.eq(InboundPlanPalletAllocation::getPlanId, plan.getId())
.orderByAsc(InboundPlanPalletAllocation::getId));
List<Long> referencedPalletIds = allocations.stream()
.map(InboundPlanPalletAllocation::getPalletId)
.filter(Objects::nonNull)
.distinct()
.toList();
Map<Long, InboundPlanPallet> referencedPallets = referencedPalletIds.isEmpty()
? Map.of()
: palletMapper.selectBatchIds(referencedPalletIds).stream()
.collect(Collectors.toMap(InboundPlanPallet::getId, pallet -> pallet));
if (referencedPallets.size() != referencedPalletIds.size()) {
throw new ResponseStatusException(HttpStatus.CONFLICT, "入库计划分配引用的托盘不存在");
}
List<Long> externalOwnerPlanIds = referencedPallets.values().stream()
.map(InboundPlanPallet::getPlanId)
.filter(Objects::nonNull)
.filter(ownerPlanId -> !Objects.equals(ownerPlanId, plan.getId()))
.distinct()
.toList();
Map<Long, String> palletOwnerPlanNos = new HashMap<>();
palletOwnerPlanNos.put(plan.getId(), plan.getPlanNo());
if (!externalOwnerPlanIds.isEmpty()) {
palletOwnerPlanNos.putAll(planMapper.selectBatchIds(externalOwnerPlanIds).stream()
.collect(Collectors.toMap(InboundPlan::getId, InboundPlan::getPlanNo)));
}
if (referencedPallets.values().stream().anyMatch(pallet ->
pallet.getPlanId() == null || !palletOwnerPlanNos.containsKey(pallet.getPlanId()))) {
throw new ResponseStatusException(HttpStatus.CONFLICT, "入库计划分配引用的托盘所属计划不存在");
}
return new InboundPlanResponse(plan.getId(), plan.getPlanNo(), plan.getCustomerId(), plan.getSourceOrderId(),
sourceOrder == null ? null : sourceOrder.orderNo(),
sourceOrder == null ? null : sourceOrder.customerName(),
@@ -1043,9 +1071,14 @@ public class InboundPlanService {
pallet.getWarehousePalletId(), pallet.getWarehouseLocationId(), pallet.getWarehouseResourceLockId(),
pallet.getPalletType(), pallet.getAssignmentStatus(), pallet.getLockedAt(), pallet.getActualVolumeCbm(),
pallet.getActualPackageCount())).toList(),
allocations.stream().map(item -> new InboundPlanResponse.Allocation(item.getLineId(), item.getPalletId(),
allocations.stream().map(item -> {
InboundPlanPallet referencedPallet = referencedPallets.get(item.getPalletId());
return new InboundPlanResponse.Allocation(item.getLineId(), item.getPalletId(),
referencedPallet.getPalletNo(), palletOwnerPlanNos.get(referencedPallet.getPlanId()),
Objects.equals(referencedPallet.getPlanId(), plan.getId()),
item.getAllocatedVolumeCbm(), item.getPlannedPackageCount(), item.getCountedPackageCount(),
item.getPickedPackageCount(), item.getActualVolumeCbm(), item.getStatus(), item.getVersion())).toList(),
item.getPickedPackageCount(), item.getActualVolumeCbm(), item.getStatus(), item.getVersion());
}).toList(),
plan.getVersion() == null ? 0 : plan.getVersion(), plan.getPlannedArrivalDate(), plan.getPalletType(),
Boolean.TRUE.equals(plan.getAssignedFlag()), Boolean.TRUE.equals(plan.getMergeRequired()),
Boolean.TRUE.equals(plan.getUrgentFlag()), plan.getCreationMode(), plan.getPlanRemark(),