From 15356da6eeca013fafc9bb6ed2d2a4a12422ce04 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期三, 02 四月 2025 16:41:52 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/ShuttleDispatcher.java |  104 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 99 insertions(+), 5 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 3f8a667..1971cbf 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
@@ -1,7 +1,6 @@
 package com.zy.asrs.wcs.core.utils;
 
 import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zy.asrs.framework.common.Cools;
 import com.zy.asrs.framework.common.SnowflakeIdWorker;
@@ -24,6 +23,7 @@
 import com.zy.asrs.wcs.system.service.DictService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
 
@@ -58,6 +58,63 @@
     private DictService dictService;
     @Autowired
     private NavigateUtils navigateUtils;
+
+    /**
+     * 璋冨害杞﹁締
+     */
+    public Device dispatchShuttle(Task task, String locNo) {
+        ArrayList<ShuttleThread> sameLev = new ArrayList<>();//鐩稿悓妤煎眰鐨勭┛姊溅
+        ArrayList<ShuttleThread> diffLev = new ArrayList<>();//涓嶅悓妤煎眰鐨勭┛姊溅
+
+        ShuttleThread resThread = null;
+        int lev = Utils.getLev(locNo);
+        List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>()
+                .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val())
+                .eq(Device::getHostId, task.getHostId())
+                .eq(Device::getStatus, 1));
+        //鑾峰彇鍚屽眰灏忚溅
+        List<Device> currentLevDevices = new ArrayList<>();
+        //鑾峰彇璺ㄥ眰灏忚溅
+        HashMap<Integer, List<Device>> diffLevDeviceMap = new HashMap<>();
+        for (Device device : list) {
+            //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
+            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
+            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+            if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
+                continue;
+            }
+
+            int shuttleLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());
+            if (shuttleLev == lev) {
+                currentLevDevices.add(device);
+            } else {
+                List<Device> devices = null;
+                if (diffLevDeviceMap.containsKey(shuttleLev)) {
+                    devices = diffLevDeviceMap.get(shuttleLev);
+                } else {
+                    devices = new ArrayList<>();
+                }
+                devices.add(device);
+                diffLevDeviceMap.put(shuttleLev, devices);
+            }
+        }
+
+        //鎼滅储鍚屽眰
+        resThread = this.searchCurrentLevShuttle(currentLevDevices, locNo);
+
+        //鍚屽眰娌℃湁鎼滅储鍒板悎閫傚皬杞︼紝璺ㄦゼ灞傛悳绱�
+        if (resThread == null) {
+            resThread = this.searchDiffLevShuttle(diffLevDeviceMap, locNo, task);
+        }
+
+        Task result = generateMoveTask(resThread.getDevice(), locNo);
+        if (result != null) {
+            return resThread.getDevice();
+        }
+
+        News.info("{}鐩爣搴撲綅娌℃湁鎼滅储鍒板彲鐢ㄧ┛姊溅", locNo);
+        return null;
+    }
 
     public synchronized ShuttleThread searchIdleShuttle(Task task) {
         String locNo = taskService.judgeInbound(task) ? task.getDestLoc() : task.getOriginLoc();
@@ -144,6 +201,12 @@
             }
 
             // 鏈夋病鏈夎鍏朵粬浠诲姟璋冨害
+            List<Task> taskList = taskService.selectWorkingByShuttle(Integer.valueOf(device.getDeviceNo()), null);
+            if (!taskList.isEmpty()) {
+                continue;
+            }
+
+
             int currentLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠灞傞珮
             String currentLocNo = shuttleProtocol.getCurrentLocNo();//灏忚溅褰撳墠搴撲綅鍙�
 
@@ -154,10 +217,10 @@
 
             // 鍚屾ゼ灞傜洿鎺ヨ绠楀埌鐩爣搴撲綅
             //褰撳墠绌挎杞︾嚎绋嬪埌褰撳墠杞﹀瓙鎵�鍦ㄦゼ灞傜殑鐩爣搴撲綅璺濈
-            List<NavigateNode> currentShuttlePath = navigateUtils.calc(
+            List<NavigateNode> currentShuttlePath = navigateUtils.calcWhiteList(
                     currentLocNo
                     , locNo
-                    , NavigationMapType.NORMAL.id
+                    , NavigationMapType.DFX.id
                     , Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), currentLev)
             );//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘
             if (currentShuttlePath == null) {
@@ -228,6 +291,11 @@
                 }
 
                 // 鏈夋病鏈夎鍏朵粬浠诲姟璋冨害
+                List<Task> taskList = taskService.selectWorkingByShuttle(Integer.valueOf(device.getDeviceNo()), null);
+                if (!taskList.isEmpty()) {
+                    continue;
+                }
+
                 int currentLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠灞傞珮
                 String currentLocNo = shuttleProtocol.getCurrentLocNo();//灏忚溅褰撳墠搴撲綅鍙�
 
@@ -254,7 +322,7 @@
                 List<NavigateNode> currentShuttlePath = navigateUtils.calc(
                         currentLocNo
                         , targetLocNo
-                        , NavigationMapType.NORMAL.id
+                        , NavigationMapType.DFX.id
                         , Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), currentLev)
                 );//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘
                 if (currentShuttlePath == null) {
@@ -307,6 +375,11 @@
             return null;
         }
 
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        if (shuttleProtocol == null) {
+            return null;
+        }
+
         Task task = new Task();
         task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
         task.setTaskNo(String.valueOf(Utils.getTaskNo("MOVE")));
@@ -314,7 +387,7 @@
         task.setTaskCtg(taskCtg.getId());
         task.setPriority(10);
         task.setOriginSite(null);
-        task.setOriginLoc(null);
+        task.setOriginLoc(shuttleProtocol.getCurrentLocNo());
         task.setDestSite(null);
         task.setDestLoc(locNo); // 杩佺Щ浣嶇疆
         task.setIoTime(new Date());
@@ -556,5 +629,26 @@
         return lastPathStartLoc;
     }
 
+    //鑾峰彇灏忚溅鍧愭爣
+    public String findShuttleLocNo(Integer shuttleNo, Long hostId) {
+        Device device = deviceService.getOne(new LambdaQueryWrapper<Device>()
+                .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val())
+                .eq(Device::getDeviceNo, shuttleNo)
+                .eq(Device::getHostId, hostId)
+                .eq(Device::getStatus, 1));
+        if(device == null) {
+            return null;
+        }
+
+        //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
+        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue());
+        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+        if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
+            return null;
+        }
+
+        return shuttleProtocol.getCurrentLocNo();
+    }
+
 
 }

--
Gitblit v1.9.1