diff --git a/lastleg-service/src/main/java/com/baiyue/lastleg/delivery/service/DeliveryTransferService.java b/lastleg-service/src/main/java/com/baiyue/lastleg/delivery/service/DeliveryTransferService.java index 4b5349e75..46a1a9ed0 100644 --- a/lastleg-service/src/main/java/com/baiyue/lastleg/delivery/service/DeliveryTransferService.java +++ b/lastleg-service/src/main/java/com/baiyue/lastleg/delivery/service/DeliveryTransferService.java @@ -26,10 +26,13 @@ import com.baiyue.lastleg.entity.LastlegOrder; import com.baiyue.lastleg.entity.LastlegOrderStatusHistory; import com.baiyue.lastleg.entity.LastlegOrderDetail; import com.baiyue.lastleg.inboundplan.entity.InboundPlanLine; +import com.baiyue.lastleg.inboundplan.entity.InboundPlanPallet; import com.baiyue.lastleg.inboundplan.entity.InboundPlanPalletAllocation; import com.baiyue.lastleg.inboundplan.mapper.InboundPlanLineMapper; import com.baiyue.lastleg.inboundplan.mapper.InboundPlanCartonMapper; import com.baiyue.lastleg.inboundplan.mapper.InboundPlanPalletAllocationMapper; +import com.baiyue.lastleg.inboundplan.mapper.InboundPlanPalletMapper; +import com.baiyue.lastleg.inboundplan.pda.gateway.WarehouseResourceGateway; import com.baiyue.lastleg.delivery.entity.OutboundPdaTask; import com.baiyue.lastleg.delivery.entity.OutboundPdaPick; import com.baiyue.lastleg.delivery.mapper.OutboundPdaTaskMapper; @@ -107,6 +110,8 @@ public class DeliveryTransferService { @Resource private DropshipSkuInventoryMapper dropshipSkuInventory; @Resource private ReturnInventoryCartonMapper returnCartons; @Resource private InboundPlanPalletAllocationMapper planAllocations; + @Resource private InboundPlanPalletMapper inboundPlanPallets; + @Resource private WarehouseResourceGateway warehouseResources; @Resource private InboundPlanLineMapper planLines; @Resource private InboundPlanCartonMapper inboundCartons; @Resource private LastlegOrderMapper tailOrders; @@ -930,9 +935,41 @@ public class DeliveryTransferService { } } } + releaseEmptyOutboundPalletLocations(customerId, outbound.getOverseasWarehouseId(), items); return taskResult(outbound, task); } + /** Release the physical location only after the whole pallet has left inventory. */ + private void releaseEmptyOutboundPalletLocations(String customerId, String warehouseId, + List items) { + if (!StringUtils.hasText(warehouseId)) return; + Set palletIds = items.stream().map(OutboundPalletItem::getWarehousePalletId) + .filter(Objects::nonNull).collect(Collectors.toCollection(LinkedHashSet::new)); + for (Long palletId : palletIds) { + long remaining = inventoryPositions.listPallet(customerId, palletId).stream() + .filter(position -> warehouseId.equals(position.getOverseasWarehouseId())) + .mapToLong(position -> value(position.getAvailablePackages()) + + value(position.getHoldPackages()) + value(position.getAllocatedPackages()) + + value(position.getPickedPackages()) + value(position.getReceivingPackages())) + .sum(); + if (remaining != 0) continue; + Long lockId = null; + WarehouseTransferPallet transferPallet = warehouseTransferPallets.selectOne(new LambdaQueryWrapper() + .eq(WarehouseTransferPallet::getCustomerId, customerId) + .eq(WarehouseTransferPallet::getWarehousePalletId, palletId) + .last("LIMIT 1")); + if (transferPallet != null) lockId = transferPallet.getWarehouseResourceLockId(); + if (lockId == null && inboundPlanPallets != null) { + InboundPlanPallet planPallet = inboundPlanPallets.selectOne(new LambdaQueryWrapper() + .eq(InboundPlanPallet::getCustomerId, customerId) + .eq(InboundPlanPallet::getWarehousePalletId, palletId) + .last("LIMIT 1")); + if (planPallet != null) lockId = planPallet.getWarehouseResourceLockId(); + } + if (lockId != null) warehouseResources.release(customerId, lockId); + } + } + @Transactional public void cancelOutbound(String outboundNo, DeliveryRequests.Cancel request) { OutboundOrder outbound = outboundOrders.lockGlobalByNo(trim(outboundNo));