根据现场设备情况,一层偏差3毫米,优先分配排列,后层深,先将低层2深度排列库位占满才分配高层库位

This commit is contained in:
李宇奇 2025-10-13 15:26:21 +08:00
parent 6ae0891cf7
commit 6af6bd1209

View File

@ -127,6 +127,8 @@ public class StackerTaskServiceImpl implements IStackerTaskService {
.eq(TAppLocation::getEquipmentId, equipmentId);
// 查询库位
List<TAppLocation> locationList = appLocationService.list(queryWrapper);
// 计算当前设备的最大深度默认2
int maxDepth = locationList.stream().mapToInt(TAppLocation::getLDepth).max().orElse(2);
List<TAppLocation> candidateLocationList = locationList.stream().filter(item -> {
boolean filterResult = item.getIsWorking() == 0 && item.getIsLock() == 0 && item.getIsOccupy() == 0;
if (locationFilter != null) {
@ -141,8 +143,9 @@ 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::getLLayer).reversed()
.thenComparingInt(TAppLocation::getLCol).reversed())
.toList();
// 判断是否输入了subArea
if (locationFilter != null && StringUtils.isNotEmpty(locationFilter.getSubArea())) {
@ -154,26 +157,59 @@ public class StackerTaskServiceImpl implements IStackerTaskService {
candidateLocationList = new ArrayList<>(firstList);// 先添加符合subArea的库位
candidateLocationList.addAll(lastList);// 再添加不符合subArea的库位
}
// 找一个空闲的库位
// 第一轮只尝试最大深度例如 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());
}
}
}
@ -430,14 +466,14 @@ public class StackerTaskServiceImpl implements IStackerTaskService {
// int times = 0;
// MesApiResponse response = null;
// do {
// Thread.sleep(15000L * times);
// response = externalApiService.invokeOrderInCB(orderInCBReq);
// times++;
// Thread.sleep(15000L * times);
// response = externalApiService.invokeOrderInCB(orderInCBReq);
// times++;
// } while (response.getCode() != 0 && times <= 10);
// if (response.getCode() != 0) {
// log.error("[wms]上报失败");
// log.error("[wms]上报失败");
// } else {
// log.info("[wms]上报成功");
// log.info("[wms]上报成功");
// }
}
}
@ -545,24 +581,24 @@ public class StackerTaskServiceImpl implements IStackerTaskService {
}
}
// for (TAppOrderOut orderOut : orderOuts) {
// OrderOutCBReq orderOutCBReq = new OrderOutCBReq();
// orderOutCBReq.setTaskId(orderOut.getOrderId());
// orderOutCBReq.setVehicleNo(vehicleId);
// orderOutCBReq.setResult(OrderOutCBEnums.COMPLETE.getCode());
// orderOutCBReq.setResultMessage("出库完成");
// OrderOutCBReq orderOutCBReq = new OrderOutCBReq();
// orderOutCBReq.setTaskId(orderOut.getOrderId());
// orderOutCBReq.setVehicleNo(vehicleId);
// orderOutCBReq.setResult(OrderOutCBEnums.COMPLETE.getCode());
// orderOutCBReq.setResultMessage("出库完成");
// int times = 0;
// MesApiResponse response = null;
// do {
// response = externalApiService.invokeOrderOutCB(orderOutCBReq);
// times++;
// Thread.sleep(15000L * times);
// } while (response.getCode() != 0 && times <= 10);
// if (response.getCode() != 0) {
// log.error("[WMS]上报失败");
// } else {
// log.info("[WMS]上报成功");
// }
// int times = 0;
// MesApiResponse response = null;
// do {
// response = externalApiService.invokeOrderOutCB(orderOutCBReq);
// times++;
// Thread.sleep(15000L * times);
// } while (response.getCode() != 0 && times <= 10);
// if (response.getCode() != 0) {
// log.error("[WMS]上报失败");
// } else {
// log.info("[WMS]上报成功");
// }
// }
}
}