修改库位选择逻辑,优先使用2深度库位,当2深度库位耗尽后启用1深度库位,防止前期还未入库很多物料的情况下,出库时就需要移库

This commit is contained in:
李宇奇 2025-09-21 13:11:20 +08:00
parent 0747c31143
commit c81c639a19

View File

@ -130,6 +130,13 @@ public class StackerTaskServiceImpl implements IStackerTaskService {
.eq(TAppLocation::getEquipmentId, equipmentId);
// 查询库位
List<TAppLocation> locationList = appLocationService.list(queryWrapper);
if (locationList == null || locationList.isEmpty()) {
continue;
}
// 计算当前设备的最大深度默认2
int maxDepth = locationList.stream().mapToInt(TAppLocation::getLDepth).max().orElse(2);
// 候选库位先按过滤条件筛选并按 LRow -> LCol -> LLayer 排序
List<TAppLocation> candidateLocationList = locationList.stream().filter(item -> {
boolean filterResult = item.getIsWorking() == 0 && item.getIsLock() == 0 && item.getIsOccupy() == 0;
if (locationFilter != null) {
@ -144,39 +151,73 @@ public class StackerTaskServiceImpl implements IStackerTaskService {
}
}
return filterResult;
}).sorted(Comparator.comparingInt(TAppLocation::getLDepth).reversed())
.sorted(Comparator.comparingInt(location -> location.getLCol() + location.getLLayer()))
}).sorted(Comparator.comparingInt(TAppLocation::getLRow)
.thenComparingInt(TAppLocation::getLCol)
.thenComparingInt(TAppLocation::getLLayer))
.toList();
// 判断是否输入了subArea
// 若指定了 subArea则基于上述排序优先同 subArea 的库位
if (locationFilter != null && StringUtils.isNotEmpty(locationFilter.getSubArea())) {
// 对candidateLocationList进行排序
List<TAppLocation> firstList = candidateLocationList.stream()
.filter(item -> item.getSubArea().equals(locationFilter.getSubArea())).toList();
List<TAppLocation> lastList = candidateLocationList.stream()
.filter(item -> !item.getSubArea().equals(locationFilter.getSubArea())).toList();
candidateLocationList = new ArrayList<>(firstList);// 先添加符合subArea的库位
candidateLocationList.addAll(lastList);// 再添加不符合subArea的库位
candidateLocationList = new ArrayList<>(firstList);
candidateLocationList.addAll(lastList);
}
// 找一个空闲的库位
// 第一轮只尝试最大深度例如 2 深度库位
for (TAppLocation candidateLocation : candidateLocationList) {
if (!Objects.equals(candidateLocation.getLDepth(), maxDepth)) {
continue; // 只处理最大深度
}
if (candidateLocation.getIsWorking() == 1 || candidateLocation.getIsLock() == 1
|| candidateLocation.getIsOccupy() == 1) {
continue;
}
if (isMaxDepthAvailable(locationList, candidateLocation)) {
try {
// 尝试锁定库位锁定成功就返回
// 申请当前库位如果成功则返回
if (appLocationService.update(new LambdaUpdateWrapper<TAppLocation>()
.set(TAppLocation::getIsOccupy, 1)
.set(TAppLocation::getVehicleId, requestVehicleId)
.eq(TAppLocation::getLocationId, candidateLocation.getLocationId())
.eq(TAppLocation::getIsOccupy, 0))) {
// 当前库位可用
targetLocation = candidateLocation;
break;
}
} catch (Exception e) {
log.error("锁定库位{}失败。", candidateLocation.getLocationId());
log.error("请求库位{}失败.", candidateLocation.getLocationId());
}
}
}
if (targetLocation != null) {
// 找到了目标库位
break;
}
// 第二轮若最大深度库位都不可用再尝试其它深度 1 深度库位
for (TAppLocation candidateLocation : candidateLocationList) {
if (Objects.equals(candidateLocation.getLDepth(), maxDepth)) {
continue; // 第一轮已经尝试
}
if (candidateLocation.getIsWorking() == 1 || candidateLocation.getIsLock() == 1
|| candidateLocation.getIsOccupy() == 1) {
continue;
}
if (isMaxDepthAvailable(locationList, candidateLocation)) {
try {
// 申请当前库位如果成功则返回
if (appLocationService.update(new LambdaUpdateWrapper<TAppLocation>()
.set(TAppLocation::getIsOccupy, 1)
.set(TAppLocation::getVehicleId, requestVehicleId)
.eq(TAppLocation::getLocationId, candidateLocation.getLocationId())
.eq(TAppLocation::getIsOccupy, 0))) {
targetLocation = candidateLocation;
break;
}
} catch (Exception e) {
log.error("请求库位{}失败.", candidateLocation.getLocationId());
}
}
}
@ -189,7 +230,7 @@ public class StackerTaskServiceImpl implements IStackerTaskService {
appCommon.updateWorkingLocations(targetLocation.getLocationId(), 1);
}
// 返回库位如果返回null则表示没有可用库位
// 返回库位若为 null 表示无可用库位
return targetLocation;
}