refactor(wms): 优化库位拆分与合并逻辑

- 修改库位占用检查范围从父库位扩展到整列
- 更新库位启用状态设置逻辑
- 调整子库位删除标记和启用状态更新方式
- 优化合并操作中的子库位过滤逻辑
- 统一异常提示信息格式
This commit is contained in:
2025-12-22 13:50:31 +08:00
parent 185ffb9963
commit d5881dc43f

View File

@@ -455,25 +455,21 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
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<>();
for (WmsActualWarehouse parent : toSplitParents) {
for (WmsActualWarehouse location : columnLocations) {
// 锁定状态=0 → 被占用
boolean isOccupied = parent.getIsEnabled() != null && parent.getIsEnabled() == 0;
boolean isOccupied = location.getIsEnabled() != null && location.getIsEnabled() == 0;
if (isOccupied) {
occupiedCodes.add(parent.getActualWarehouseCode());
occupiedCodes.add(location.getActualWarehouseCode());
}
}
// 3. 存在被占用的父库位,抛出异常提示
// 如果有任何库位被占用,抛出异常提示
if (!occupiedCodes.isEmpty()) {
throw new ServiceException("以下库位被占用,无法拆分:" + String.join(",", occupiedCodes));
throw new ServiceException("以下库位被占用,无法拆分:" + String.join(",", occupiedCodes));
}
// 批量查询所有子库位(一次性查询,避免循环查询)
List<Long> parentIds = columnLocations.stream()
.map(WmsActualWarehouse::getActualWarehouseId)
@@ -500,6 +496,7 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
upd.setActualWarehouseId(location.getActualWarehouseId());
upd.setSplitStatus(1);
upd.setSplitType(splitType);
upd.setIsEnabled(0);
toUpdate.add(upd);
}
if (!toUpdate.isEmpty()) {
@@ -537,6 +534,7 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
childUpdate.setActualWarehouseId(child.getActualWarehouseId());
childUpdate.setDelFlag(0);
childUpdate.setSplitStatus(1);
childUpdate.setIsEnabled(1);
childUpdate.setSplitType(splitType);
toUpdate.add(childUpdate);
}
@@ -709,7 +707,7 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
}
// 批量查询所有子库位
List<Long> parentIds = locationsToMerge.stream()
List<Long> parentIds = columnLocations.stream()
.map(WmsActualWarehouse::getActualWarehouseId)
.collect(Collectors.toList());
@@ -717,20 +715,13 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
.in(WmsActualWarehouse::getParentId, parentIds)
.eq(WmsActualWarehouse::getActualWarehouseType, 4)); // 四级子库位
// 按父ID分组子库位
Map<Long, List<WmsActualWarehouse>> childrenByParent = allChildren.stream()
.collect(Collectors.groupingBy(WmsActualWarehouse::getParentId));
// 检查是否有子库位被占用
for (WmsActualWarehouse location : locationsToMerge) {
List<WmsActualWarehouse> children = childrenByParent.get(location.getActualWarehouseId());
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());
}
// 检查整列中是否有任何子库位被占用
if (CollUtil.isNotEmpty(allChildren)) {
boolean anyOccupied = allChildren.stream()
.filter(c -> c.getDelFlag() == 0)
.anyMatch(c -> !Objects.equals(c.getIsEnabled(), 1));
if (anyOccupied) {
throw new ServiceException("该列存在被占用的子库位,不能合并");
}
}
@@ -739,7 +730,9 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
List<WmsActualWarehouse> parentsToUpdate = new ArrayList<>();
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)) {
@@ -747,7 +740,8 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
if (child.getDelFlag() == 0) {
WmsActualWarehouse childUpdate = new WmsActualWarehouse();
childUpdate.setActualWarehouseId(child.getActualWarehouseId());
childUpdate.setDelFlag(2);
childUpdate.setDelFlag(1);
childUpdate.setIsEnabled(0);
childrenToUpdate.add(childUpdate);
}
}
@@ -758,6 +752,7 @@ public class WmsActualWarehouseServiceImpl implements IWmsActualWarehouseService
parentUpdate.setActualWarehouseId(location.getActualWarehouseId());
parentUpdate.setSplitStatus(0);
parentUpdate.setSplitType(0);
parentUpdate.setIsEnabled(1);
parentsToUpdate.add(parentUpdate);
}