From 54b4f53323d0833cbac86fd18932c5fa5a5447a8 Mon Sep 17 00:00:00 2001
From: zjj <3272660260@qq.com>
Date: 星期一, 17 二月 2025 14:19:17 +0800
Subject: [PATCH] #移库任务
---
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java | 201 +++++++++++++++++++++++++++-----------------------
1 files changed, 109 insertions(+), 92 deletions(-)
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java
index 2f10b29..3f8a667 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java
@@ -56,6 +56,8 @@
private ShuttleStandbyService shuttleStandbyService;
@Autowired
private DictService dictService;
+ @Autowired
+ private NavigateUtils navigateUtils;
public synchronized ShuttleThread searchIdleShuttle(Task task) {
String locNo = taskService.judgeInbound(task) ? task.getDestLoc() : task.getOriginLoc();
@@ -68,7 +70,7 @@
//鑾峰彇鍚屽眰灏忚溅
List<Device> currentLevDevices = new ArrayList<>();
//鑾峰彇璺ㄥ眰灏忚溅
- List<Device> diffLevDevices = new ArrayList<>();
+ HashMap<Integer,List<Device>> diffLevDeviceMap = new HashMap<>();
for (Device device : list) {
//鑾峰彇鍥涘悜绌挎杞︾嚎绋�
ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
@@ -77,10 +79,18 @@
continue;
}
- if (Utils.getLev(shuttleProtocol.getCurrentLocNo()) == lev) {
+ int shuttleLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());
+ if (shuttleLev == lev) {
currentLevDevices.add(device);
}else {
- diffLevDevices.add(device);
+ List<Device> devices = null;
+ if(diffLevDeviceMap.containsKey(shuttleLev)) {
+ devices = diffLevDeviceMap.get(shuttleLev);
+ }else {
+ devices = new ArrayList<>();
+ }
+ devices.add(device);
+ diffLevDeviceMap.put(shuttleLev, devices);
}
}
//鎼滅储鍚屽眰
@@ -88,7 +98,7 @@
//鍚屽眰娌℃湁鎼滅储鍒板悎閫傚皬杞︼紝璺ㄦゼ灞傛悳绱�
if(resThread == null) {
- resThread = this.searchDiffLevShuttle(diffLevDevices, locNo, task);
+ resThread = this.searchDiffLevShuttle(diffLevDeviceMap, locNo, task);
}
return resThread;
@@ -144,7 +154,7 @@
// 鍚屾ゼ灞傜洿鎺ヨ绠楀埌鐩爣搴撲綅
//褰撳墠绌挎杞︾嚎绋嬪埌褰撳墠杞﹀瓙鎵�鍦ㄦゼ灞傜殑鐩爣搴撲綅璺濈
- List<NavigateNode> currentShuttlePath = NavigateUtils.calc(
+ List<NavigateNode> currentShuttlePath = navigateUtils.calc(
currentLocNo
, locNo
, NavigationMapType.NORMAL.id
@@ -154,7 +164,7 @@
continue;
}
- Integer currDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+ Integer currDistance = navigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
// 鎸傝浇浠诲姟鏉冮噸
List<Task> tasks = taskService.selectWorkingByShuttle(Integer.valueOf(device.getDeviceNo()), null);
@@ -171,102 +181,109 @@
return resThread;
}
- private synchronized ShuttleThread searchDiffLevShuttle(List<Device> devices, String locNo, Task task) {
+ private synchronized ShuttleThread searchDiffLevShuttle(HashMap<Integer,List<Device>> devicesMap, String locNo, Task task) {
ShuttleThread resThread = null;
Integer finalDistance = ShuttleDispatcher.INF;
//妫�娴嬬洰鏍囨ゼ灞傝溅鏁伴噺鏄惁灏忎簬鍏佽鐨勬渶澶ф暟閲�
boolean checkDispatchMaxNum = checkDispatchMaxNum(Utils.getLev(locNo), task.getHostId());
- for (Device device : devices) {
- if (taskService.hasBusyOutboundByShuttle(Integer.parseInt(device.getDeviceNo()))) {
- continue;
- }
- //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
- ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
- ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
- if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
- continue;
- }
+ for (Map.Entry<Integer, List<Device>> entry : devicesMap.entrySet()) {
+ Integer lev = entry.getKey();
+ List<Device> devices = entry.getValue();
+ for (Device device : devices) {
+ if (taskService.hasBusyOutboundByShuttle(Integer.parseInt(device.getDeviceNo()))) {
+ continue;
+ }
+ //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
+ continue;
+ }
- if (!shuttleThread.isIdle()) {
- continue;
- }
+ if (!shuttleThread.isIdle()) {
+ continue;
+ }
- BasShuttle basShuttle = basShuttleService.getOne(new LambdaQueryWrapper<BasShuttle>()
- .eq(BasShuttle::getShuttleNo, device.getDeviceNo())
- .eq(BasShuttle::getHostId, device.getHostId()));
- if (basShuttle == null) {
- continue;//灏忚溅鍩虹鏁版嵁涓嶅瓨鍦�
- }
+ BasShuttle basShuttle = basShuttleService.getOne(new LambdaQueryWrapper<BasShuttle>()
+ .eq(BasShuttle::getShuttleNo, device.getDeviceNo())
+ .eq(BasShuttle::getHostId, device.getHostId()));
+ if (basShuttle == null) {
+ continue;//灏忚溅鍩虹鏁版嵁涓嶅瓨鍦�
+ }
- if (!Cools.isEmpty(basShuttle.getDisableLev())) {
- List<Integer> disableLev = JSON.parseArray(basShuttle.getDisableLev(), Integer.class);
- //妫�鏌ュ皬杞︽槸鍚︾鐢ㄨ妤煎眰
- if (disableLev.contains(Utils.getLev(locNo))) {
- continue;//灏忚溅绂佺敤璇ユゼ灞傝烦杩囪杞�
+ if (!Cools.isEmpty(basShuttle.getDisableLev())) {
+ List<Integer> disableLev = JSON.parseArray(basShuttle.getDisableLev(), Integer.class);
+ //妫�鏌ュ皬杞︽槸鍚︾鐢ㄨ妤煎眰
+ if (disableLev.contains(Utils.getLev(locNo))) {
+ continue;//灏忚溅绂佺敤璇ユゼ灞傝烦杩囪杞�
+ }
+ }
+
+ //妫�娴嬫槸鍚﹀瓨鍦ㄥ厖鐢典换鍔�
+ Task taskCharge = taskService.selectChargeWorking(Integer.valueOf(device.getDeviceNo()));
+ if (taskCharge != null) {
+ continue;
+ }
+
+ // 鏈夋病鏈夎鍏朵粬浠诲姟璋冨害
+ int currentLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠灞傞珮
+ String currentLocNo = shuttleProtocol.getCurrentLocNo();//灏忚溅褰撳墠搴撲綅鍙�
+
+ if (!checkDispatchMaxNum) {
+ News.info("{}浠诲姟锛寋}灞傦紝宸茬粡杈惧埌褰撳墠妤煎眰璋冨害杞﹁締鏈�澶у��", task.getTaskNo(), Utils.getLev(locNo));
+ continue;
+ }
+
+ //鑾峰彇璺濈灏忚溅浣嶇疆鏈�杩戠殑绌洪棽鍙崲灞傛彁鍗囨満
+ LiftThread liftThread = liftDispatcher.searchIdleLift(currentLocNo, task.getHostId(), true);
+ if (liftThread == null) {
+ continue;
+ }
+ Device recentTransferLift = liftThread.getDevice();
+
+ //鑾峰彇灏忚溅妤煎眰鎻愬崌鏈哄緟鏈轰綅
+ ShuttleStandby shuttleStandby = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
+ .eq(ShuttleStandby::getDeviceId, recentTransferLift.getId())
+ .eq(ShuttleStandby::getDeviceLev, currentLev)
+ .eq(ShuttleStandby::getStatus, 1));
+ String targetLocNo = shuttleStandby.getDeviceLoc();
+
+ //褰撳墠绌挎杞︾嚎绋嬪埌褰撳墠杞﹀瓙鎵�鍦ㄦゼ灞傜殑鎻愬崌鏈哄緟鏈轰綅璺濈
+ List<NavigateNode> currentShuttlePath = navigateUtils.calc(
+ currentLocNo
+ , targetLocNo
+ , NavigationMapType.NORMAL.id
+ , Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), currentLev)
+ );//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘
+ if (currentShuttlePath == null) {
+ continue;
+ }
+
+ Integer currDistance = navigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+
+ // 涓嶅悓妤煎眰鏉冮噸
+ if (currentLev != Utils.getLev(locNo)) {
+ currDistance += WEIGHT;
+ }
+
+ // 鎸傝浇浠诲姟鏉冮噸
+ List<Task> tasks = taskService.selectWorkingByShuttle(Integer.valueOf(device.getDeviceNo()), null);
+ if (!Cools.isEmpty(tasks)) {
+ currDistance += tasks.size() * WEIGHT;
+ }
+
+ if (currDistance < finalDistance) {
+ finalDistance = currDistance;
+ resThread = shuttleThread;
}
}
- //妫�娴嬫槸鍚﹀瓨鍦ㄥ厖鐢典换鍔�
- Task taskCharge = taskService.selectChargeWorking(Integer.valueOf(device.getDeviceNo()));
- if (taskCharge != null) {
- continue;
- }
-
- // 鏈夋病鏈夎鍏朵粬浠诲姟璋冨害
- int currentLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠灞傞珮
- String currentLocNo = shuttleProtocol.getCurrentLocNo();//灏忚溅褰撳墠搴撲綅鍙�
-
- if (!checkDispatchMaxNum) {
- News.info("{}浠诲姟锛寋}灞傦紝宸茬粡杈惧埌褰撳墠妤煎眰璋冨害杞﹁締鏈�澶у��", task.getTaskNo(), Utils.getLev(locNo));
- continue;
- }
-
- //鑾峰彇璺濈灏忚溅浣嶇疆鏈�杩戠殑绌洪棽鍙崲灞傛彁鍗囨満
- LiftThread liftThread = liftDispatcher.searchIdleLift(currentLocNo, task.getHostId(), true);
- if (liftThread == null) {
- continue;
- }
- Device recentTransferLift = liftThread.getDevice();
-
- //鑾峰彇灏忚溅妤煎眰鎻愬崌鏈哄緟鏈轰綅
- ShuttleStandby shuttleStandby = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
- .eq(ShuttleStandby::getDeviceId, recentTransferLift.getId())
- .eq(ShuttleStandby::getDeviceLev, currentLev)
- .eq(ShuttleStandby::getStatus, 1));
- String targetLocNo = shuttleStandby.getDeviceLoc();
-
- //褰撳墠绌挎杞︾嚎绋嬪埌褰撳墠杞﹀瓙鎵�鍦ㄦゼ灞傜殑鎻愬崌鏈哄緟鏈轰綅璺濈
- List<NavigateNode> currentShuttlePath = NavigateUtils.calc(
- currentLocNo
- , targetLocNo
- , NavigationMapType.NORMAL.id
- , Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), currentLev)
- );//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘
- if (currentShuttlePath == null) {
- continue;
- }
-
- Integer currDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
-
- // 涓嶅悓妤煎眰鏉冮噸
- if (currentLev != Utils.getLev(locNo)) {
- currDistance += WEIGHT;
- }
-
- // 鎸傝浇浠诲姟鏉冮噸
- List<Task> tasks = taskService.selectWorkingByShuttle(Integer.valueOf(device.getDeviceNo()), null);
- if (!Cools.isEmpty(tasks)) {
- currDistance += tasks.size() * WEIGHT;
- }
-
- if (currDistance < finalDistance) {
- finalDistance = currDistance;
- resThread = shuttleThread;
+ if (resThread != null) {
+ break;
}
}
-
return resThread;
}
@@ -401,7 +418,7 @@
String recentLoc = null;
for (String loc : locNos) {
//褰撳墠绌挎杞﹀埌閬胯浣嶈绠�
- List<NavigateNode> currentShuttlePath = NavigateUtils.calc(
+ List<NavigateNode> currentShuttlePath = navigateUtils.calc(
currentLocNo
, loc
, NavigationMapType.NORMAL.id
@@ -411,7 +428,7 @@
continue;
}
- Integer currDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+ Integer currDistance = navigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
if (currDistance < finalDistance) {
finalDistance = currDistance;
recentLoc = loc;
@@ -521,13 +538,13 @@
//鍒嗘瀽鍑哄簱璺緞寰呮満搴撲綅
public String analyzeOutPathWaitLoc(String startLoc, String targetLoc, Device shuttleDevice) {
//璁$畻璺緞骞跺垎瑙f垚涓ゆ鍔ㄤ綔
- List<NavigateNode> nodeList = NavigateUtils.calc(startLoc, targetLoc, NavigationMapType.DFX.id, Utils.getShuttlePoints(Integer.parseInt(shuttleDevice.getDeviceNo()), Utils.getLev(startLoc)));
+ List<NavigateNode> nodeList = navigateUtils.calc(startLoc, targetLoc, NavigationMapType.DFX.id, Utils.getShuttlePoints(Integer.parseInt(shuttleDevice.getDeviceNo()), Utils.getLev(startLoc)));
if (nodeList == null) {
News.error("{} dash {} can't find navigate path!", startLoc, targetLoc);
return null;
}
//鑾峰彇鍒嗘璺緞
- ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(nodeList);
+ ArrayList<ArrayList<NavigateNode>> data = navigateUtils.getSectionPath(nodeList);
if (data.size() <= 1) {
return startLoc;//涓ょ偣涔嬮棿鍙湁涓�娈佃矾寰勶紝鍦ㄨ捣鐐逛綅缃瓑寰�
}
--
Gitblit v1.9.1