diff --git a/src/main/java/com/gaotao/modules/other/service/impl/InventoryMoveServiceImpl.java b/src/main/java/com/gaotao/modules/other/service/impl/InventoryMoveServiceImpl.java index 52d0b76..e7c5a98 100644 --- a/src/main/java/com/gaotao/modules/other/service/impl/InventoryMoveServiceImpl.java +++ b/src/main/java/com/gaotao/modules/other/service/impl/InventoryMoveServiceImpl.java @@ -105,7 +105,7 @@ public class InventoryMoveServiceImpl implements InventoryMoveService { try { // 2. 验证HandlingUnit - List handlingUnits = validateHandlingUnits(dto); + List handlingUnits = validateHandlingUnitsForPallet(dto); // 3. 先保存原库位信息用于IFS同步,然后处理每个HandlingUnit Map originalLocations = new HashMap<>(); @@ -247,6 +247,35 @@ public class InventoryMoveServiceImpl implements InventoryMoveService { return handlingUnits; } + private List validateHandlingUnitsForPallet(InventoryMoveRequestDto dto) { + List handlingUnits = handlingUnitService.lambdaQuery() + .eq(HandlingUnit::getSite, dto.getSite()) + .in(HandlingUnit::getUnitId, dto.getHandlingUnitIds()) + .list(); + + if (handlingUnits.size() != dto.getHandlingUnitIds().size()) { + throw new XJException("部分HandlingUnit不存在或site不匹配"); + } + + // 使用 Iterator 安全地遍历并删除 + Iterator iterator = handlingUnits.iterator(); + while (iterator.hasNext()) { + HandlingUnit hu = iterator.next(); + + // 校验是否在库 + if (!"Y".equals(hu.getInStockFlag())) { + throw new XJException("HandlingUnit不在库,无法移库: " + hu.getUnitId()); + } + + // 如果目标库位和当前库位相同,跳过(从列表中移除) + if (dto.getTargetLocationId().equals(hu.getLocationId())) { + iterator.remove(); // ✅ 安全删除 + } + } + + return handlingUnits; + } + /** * 批量同步到IFS - 按site、partNo、locationNo、lotBatchNo合并后调用 */