From 6af6bd12099ede9b8e9ae7b72d6d0fc31667dbae Mon Sep 17 00:00:00 2001 From: btobab Date: Mon, 13 Oct 2025 15:26:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=8E=B0=E5=9C=BA=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=83=85=E5=86=B5=EF=BC=8C=E4=B8=80=E5=B1=82=E5=81=8F?= =?UTF-8?q?=E5=B7=AE3=E6=AF=AB=E7=B1=B3=EF=BC=8C=E4=BC=98=E5=85=88?= =?UTF-8?q?=E5=88=86=E9=85=8D=E6=8E=92=E5=88=97=EF=BC=8C=E5=90=8E=E5=B1=82?= =?UTF-8?q?=E6=B7=B1=EF=BC=8C=E5=85=88=E5=B0=86=E4=BD=8E=E5=B1=822?= =?UTF-8?q?=E6=B7=B1=E5=BA=A6=E6=8E=92=E5=88=97=E5=BA=93=E4=BD=8D=E5=8D=A0?= =?UTF-8?q?=E6=BB=A1=E6=89=8D=E5=88=86=E9=85=8D=E9=AB=98=E5=B1=82=E5=BA=93?= =?UTF-8?q?=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceImpl/StackerTaskServiceImpl.java | 92 +++++++++++++------ 1 file changed, 64 insertions(+), 28 deletions(-) diff --git a/202504-Wms-MengYang-box/wms_serve_mengyang/src/main/java/com/wms_main/service/business/serviceImpl/StackerTaskServiceImpl.java b/202504-Wms-MengYang-box/wms_serve_mengyang/src/main/java/com/wms_main/service/business/serviceImpl/StackerTaskServiceImpl.java index c161e7b..69e12d7 100644 --- a/202504-Wms-MengYang-box/wms_serve_mengyang/src/main/java/com/wms_main/service/business/serviceImpl/StackerTaskServiceImpl.java +++ b/202504-Wms-MengYang-box/wms_serve_mengyang/src/main/java/com/wms_main/service/business/serviceImpl/StackerTaskServiceImpl.java @@ -127,6 +127,8 @@ public class StackerTaskServiceImpl implements IStackerTaskService { .eq(TAppLocation::getEquipmentId, equipmentId); // 查询库位 List locationList = appLocationService.list(queryWrapper); + // 计算当前设备的最大深度(默认2) + int maxDepth = locationList.stream().mapToInt(TAppLocation::getLDepth).max().orElse(2); List 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() .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() + .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]上报成功"); + // } // } } }