From 7f009833770cb819d3bc26c2e24b23cd13ef8918 Mon Sep 17 00:00:00 2001 From: btobab Date: Tue, 23 Sep 2025 22:32:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=98=E7=9B=98=E5=BA=93?= =?UTF-8?q?=E5=BA=93=E4=BD=8D=E9=80=89=E6=8B=A9=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=BB=8E=E4=B8=AD=E9=97=B4=E7=9A=8443?= =?UTF-8?q?=EF=BC=8C44=E5=88=97=E5=90=91=E4=B8=A4=E8=BE=B9=E6=89=A9?= =?UTF-8?q?=E6=95=A3=EF=BC=8C=E5=85=88=E5=B7=A6=E5=90=8E=E5=8F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceImpl/StackerTaskServiceImpl.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/202504-Wms-MengYang-tp/wms_serve_mengyang/src/main/java/com/wms_main/service/business/serviceImpl/StackerTaskServiceImpl.java b/202504-Wms-MengYang-tp/wms_serve_mengyang/src/main/java/com/wms_main/service/business/serviceImpl/StackerTaskServiceImpl.java index 0e2b74a..6addcac 100644 --- a/202504-Wms-MengYang-tp/wms_serve_mengyang/src/main/java/com/wms_main/service/business/serviceImpl/StackerTaskServiceImpl.java +++ b/202504-Wms-MengYang-tp/wms_serve_mengyang/src/main/java/com/wms_main/service/business/serviceImpl/StackerTaskServiceImpl.java @@ -1,4 +1,4 @@ -package com.wms_main.service.business.serviceImpl; +package com.wms_main.service.business.serviceImpl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -101,7 +101,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; // 设备号优先级序列 @@ -148,10 +148,11 @@ public class StackerTaskServiceImpl implements IStackerTaskService { } } return filterResult; - }).sorted(Comparator.comparingInt(TAppLocation::getLRow) - .thenComparingInt(TAppLocation::getLCol) - .thenComparingInt(TAppLocation::getLLayer)) - .toList(); + }).collect(Collectors.toList()); + int maxCol = locationList.stream().mapToInt(TAppLocation::getLCol).max().orElse(86); + candidateLocationList.sort(Comparator.comparingInt(TAppLocation::getLRow) + .thenComparingInt(loc -> computeColOrder(loc.getLCol(), maxCol)) + .thenComparingInt(TAppLocation::getLLayer)); // 若指定了 subArea,则基于上述排序优先同 subArea 的库位 if (locationFilter != null && StringUtils.isNotEmpty(locationFilter.getSubArea())) { @@ -349,6 +350,17 @@ public class StackerTaskServiceImpl implements IStackerTaskService { } return result; } + /** + * 列排序权重:以列数中点为中心(86列 => 中点在43/44之间), + * 先靠近中点的列优先,等距时优先左侧(43)再右侧(44)。 + * 计算采用整数运算:distance2 = |col*2 - (maxCol + 1)|。 + */ + private int computeColOrder(int col, int maxCol) { + int centerTimes2 = maxCol + 1; // 偶数列的两个中心之和(如86=>87) + int distance2 = Math.abs(col * 2 - centerTimes2); // 与中心的“距离”×2 + int side = (col <= centerTimes2 / 2) ? 0 : 1; // 左侧优先(43 再 44) + return distance2 * 2 + side; // 组合为稳定的权重 + } /** * 找到最空闲的那台设备