修改库位选择逻辑,优先使用2深度库位,当2深度库位耗尽后启用1深度库位,防止前期还未入库很多物料的情况下,出库时就需要移库
This commit is contained in:
parent
0747c31143
commit
c81c639a19
|
|
@ -104,7 +104,7 @@ public class StackerTaskServiceImpl implements IStackerTaskService {
|
|||
* @return 申请到的库位,null表示无库位可用
|
||||
*/
|
||||
@Override
|
||||
public TAppLocation requestOneLocation(TAppLocation locationFilter, String requestVehicleId) {
|
||||
public TAppLocation requestOneLocation(TAppLocation locationFilter, String requestVehicleId) {
|
||||
// 目标库位
|
||||
TAppLocation targetLocation = null;
|
||||
// 设备号优先级序列
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user