Merge branch '0.8.X' of https://gitee.com/hdka/klp-oa into 0.8.X

This commit is contained in:
砂糖
2025-12-22 16:36:23 +08:00

View File

@@ -455,25 +455,21 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
throw new ServiceException("未找到列标识为 " + columnFlag + " 的库位"); throw new ServiceException("未找到列标识为 " + columnFlag + " 的库位");
} }
// 1. 筛选出待拆分的父库位(只校验需要拆分的库位,非拆分库位不限制) // 检查整个列中是否有任何库位被占用
List<WmsActualWarehouse> toSplitParents = columnLocations.stream()
.filter(loc -> splitIds.contains(loc.getActualWarehouseId()))
.collect(Collectors.toList());
// 2. 批量校验占用状态
List<String> occupiedCodes = new ArrayList<>(); List<String> occupiedCodes = new ArrayList<>();
for (WmsActualWarehouse parent : toSplitParents) { for (WmsActualWarehouse location : columnLocations) {
// 锁定状态=0 → 被占用 // 锁定状态=0 → 被占用
boolean isOccupied = parent.getIsEnabled() != null && parent.getIsEnabled() == 0; boolean isOccupied = location.getIsEnabled() != null && location.getIsEnabled() == 0;
if (isOccupied) { if (isOccupied) {
occupiedCodes.add(parent.getActualWarehouseCode()); occupiedCodes.add(location.getActualWarehouseCode());
} }
} }
// 3. 存在被占用的父库位,抛出异常提示 // 如果有任何库位被占用,抛出异常提示
if (!occupiedCodes.isEmpty()) { if (!occupiedCodes.isEmpty()) {
throw new ServiceException("以下库位被占用,无法拆分:" + String.join(",", occupiedCodes)); throw new ServiceException("以下库位被占用,无法拆分:" + String.join(",", occupiedCodes));
} }
// 批量查询所有子库位(一次性查询,避免循环查询) // 批量查询所有子库位(一次性查询,避免循环查询)
List<Long> parentIds = columnLocations.stream() List<Long> parentIds = columnLocations.stream()
.map(WmsActualWarehouse::getActualWarehouseId) .map(WmsActualWarehouse::getActualWarehouseId)
@@ -709,7 +705,7 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
} }
// 批量查询所有子库位 // 批量查询所有子库位
List<Long> parentIds = locationsToMerge.stream() List<Long> parentIds = columnLocations.stream()
.map(WmsActualWarehouse::getActualWarehouseId) .map(WmsActualWarehouse::getActualWarehouseId)
.collect(Collectors.toList()); .collect(Collectors.toList());
@@ -717,20 +713,13 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
.in(WmsActualWarehouse::getParentId, parentIds) .in(WmsActualWarehouse::getParentId, parentIds)
.eq(WmsActualWarehouse::getActualWarehouseType, 4)); // 四级子库位 .eq(WmsActualWarehouse::getActualWarehouseType, 4)); // 四级子库位
// 按父ID分组子库位 // 检查整列中是否有任何子库位被占用
Map<Long, List<WmsActualWarehouse>> childrenByParent = allChildren.stream() if (CollUtil.isNotEmpty(allChildren)) {
.collect(Collectors.groupingBy(WmsActualWarehouse::getParentId)); boolean anyOccupied = allChildren.stream()
.filter(c -> c.getDelFlag() == 0)
// 检查是否有子库位被占用 .anyMatch(c -> !Objects.equals(c.getIsEnabled(), 1));
for (WmsActualWarehouse location : locationsToMerge) { if (anyOccupied) {
List<WmsActualWarehouse> children = childrenByParent.get(location.getActualWarehouseId()); throw new ServiceException("该列存在被占用的子库位,不能合并");
if (CollUtil.isNotEmpty(children)) {
boolean anyOccupied = children.stream()
.filter(c -> c.getDelFlag() == 0)
.anyMatch(c -> !Objects.equals(c.getIsEnabled(), 1));
if (anyOccupied) {
throw new ServiceException("子库位被占用,不能合并:" + location.getActualWarehouseCode());
}
} }
} }
@@ -739,7 +728,9 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
List<WmsActualWarehouse> parentsToUpdate = new ArrayList<>(); List<WmsActualWarehouse> parentsToUpdate = new ArrayList<>();
for (WmsActualWarehouse location : locationsToMerge) { for (WmsActualWarehouse location : locationsToMerge) {
List<WmsActualWarehouse> children = childrenByParent.get(location.getActualWarehouseId()); List<WmsActualWarehouse> children = allChildren.stream()
.filter(c -> Objects.equals(c.getParentId(), location.getActualWarehouseId()))
.collect(Collectors.toList());
// 隐藏所有子库位 // 隐藏所有子库位
if (CollUtil.isNotEmpty(children)) { if (CollUtil.isNotEmpty(children)) {
@@ -747,7 +738,7 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
if (child.getDelFlag() == 0) { if (child.getDelFlag() == 0) {
WmsActualWarehouse childUpdate = new WmsActualWarehouse(); WmsActualWarehouse childUpdate = new WmsActualWarehouse();
childUpdate.setActualWarehouseId(child.getActualWarehouseId()); childUpdate.setActualWarehouseId(child.getActualWarehouseId());
childUpdate.setDelFlag(2); childUpdate.setDelFlag(1);
childrenToUpdate.add(childUpdate); childrenToUpdate.add(childUpdate);
} }
} }