From 710deccd42576ad2dcbdc22e75f18b455d5ce2ff Mon Sep 17 00:00:00 2001
From: zhangc <zc@123>
Date: 星期一, 14 四月 2025 18:04:00 +0800
Subject: [PATCH] 1

---
 src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java |  376 ++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 254 insertions(+), 122 deletions(-)

diff --git a/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java b/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
index 72f341a..9b14b9f 100644
--- a/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
+++ b/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
@@ -1,24 +1,28 @@
 package com.zy.core.dispatcher;
 
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.mapper.Wrapper;
+import com.core.common.Cools;
 import com.core.exception.CoolException;
+import com.zy.asrs.domain.ShuttleGatherResult;
+import com.zy.asrs.domain.param.ShuttleGatherParam;
+import com.zy.asrs.entity.BasShuttle;
 import com.zy.asrs.entity.WrkMast;
+import com.zy.asrs.service.BasShuttleService;
 import com.zy.asrs.service.WrkMastService;
 import com.zy.asrs.utils.Utils;
 import com.zy.common.model.NavigateNode;
 import com.zy.common.model.enums.NavigationMapType;
 import com.zy.common.service.CommonService;
-import com.zy.common.utils.ForkLiftUtils;
 import com.zy.common.utils.NavigateUtils;
 import com.zy.core.News;
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.SlaveType;
+import com.zy.core.enums.WrkIoType;
 import com.zy.core.enums.WrkStsType;
-import com.zy.core.model.ForkLiftSlave;
 import com.zy.core.model.ShuttleSlave;
-import com.zy.core.model.protocol.*;
+import com.zy.core.model.protocol.ShuttleProtocol;
 import com.zy.core.properties.SlaveProperties;
-import com.zy.core.thread.ForkLiftThread;
 import com.zy.core.thread.ShuttleThread;
 import com.zy.system.entity.Config;
 import com.zy.system.service.ConfigService;
@@ -44,6 +48,15 @@
     private NavigateUtils navigateUtils;
     @Autowired
     private ConfigService configService;
+    @Autowired
+    private BasShuttleService basShuttleService;
+
+    /**
+     * 璋冨害杞﹁締-璋冨害鎸囧畾绌挎杞�
+     */
+    public boolean dispatchShuttle(Integer wrkNo, String sourceLocNo, String locNo, Integer shuttleNo, String flag) {
+        return shuttleMoveGenerate(wrkNo, sourceLocNo, locNo, shuttleNo, flag, false);
+    }
 
     /**
      * 璋冨害杞﹁締-璋冨害鎸囧畾绌挎杞�
@@ -55,19 +68,7 @@
     /**
      * 璋冨害杞﹁締
      */
-    public boolean dispatchShuttle(Integer wrkNo, String locNo) {
-        //妫�娴嬬洰鏍囧簱浣嶇粍鏄惁瀛樺湪灏忚溅锛屽瀛樺湪灏忚溅鍒欑洿鎺ユ寚瀹氳杞�
-        WrkMast wrkMast = wrkMastService.selectByWorkNo(wrkNo);
-        if (wrkMast != null) {
-            String targetLocNo = wrkMast.getIoType() < 100 ? wrkMast.getLocNo() : wrkMast.getSourceLocNo();
-            List<String> groupLoc = Utils.getGroupLoc(targetLocNo);
-            Integer groupShuttleNo = Utils.checkGroupLocHasShuttle(groupLoc);
-            if (groupShuttleNo != null) {
-                //瀛樺湪灏忚溅锛岀洿鎺ヨ皟搴﹁杞�
-                return shuttleMoveGenerate(wrkNo, locNo, groupShuttleNo);
-            }
-        }
-
+    public boolean searchDispatchShuttle(Integer wrkNo, String sourceLocNo, String locNo, String flag) {
         ArrayList<ShuttleThread> sameLev = new ArrayList<>();//鐩稿悓妤煎眰鐨勭┛姊溅
         ArrayList<ShuttleThread> diffLev = new ArrayList<>();//涓嶅悓妤煎眰鐨勭┛姊溅
 
@@ -85,6 +86,13 @@
 
             if (!shuttleThread.isIdle()) {
                 continue;//灏忚溅蹇欑涓�
+            }
+
+            BasShuttle basShuttle = basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttle.getId()));
+            if (basShuttle != null) {
+                if (basShuttle.getStatus() == 0) {
+                    continue;//灏忚溅琚鐢�
+                }
             }
 
             int currentLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠灞傞珮
@@ -105,7 +113,7 @@
             if (currentLev == Utils.getLev(locNo)) {
                 //宸ヤ綔妗fゼ灞傜浉鍚岀殑绌挎杞�
                 sameLev.add(shuttleThread);
-            }else {
+            } else {
                 //宸ヤ綔妗d笉鍚屾ゼ灞傜殑绌挎杞�
                 diffLev.add(shuttleThread);
             }
@@ -120,6 +128,11 @@
                 Integer shuttleNo = shuttleProtocol.getShuttleNo();
                 //褰撳墠绌挎杞﹀簱浣嶅彿
                 String currentLocNo = shuttleProtocol.getCurrentLocNo();
+                if (currentLocNo.equals(locNo)) {
+                    sameShuttles.put(-1, shuttleThread);
+                    continue;
+                }
+
                 //褰撳墠绌挎杞︾嚎绋嬪埌鐩爣鍦扮偣璺濈
                 List<NavigateNode> currentShuttlePath = navigateUtils.calc(currentLocNo, locNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)), null);//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘
                 if (currentShuttlePath == null) {
@@ -135,7 +148,7 @@
                 ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
                 Integer shuttleNo = shuttleProtocol.getShuttleNo();
                 //灏濊瘯璋冨害灏忚溅
-                boolean result = shuttleMoveGenerate(wrkNo, locNo, shuttleNo);
+                boolean result = shuttleMoveGenerate(wrkNo, sourceLocNo, locNo, shuttleNo, flag, false);
                 if (result) {
                     return true;//璋冨害鎴愬姛
                 }
@@ -182,7 +195,149 @@
                     ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
                     Integer shuttleNo = shuttleProtocol.getShuttleNo();
                     //灏濊瘯璋冨害灏忚溅
-                    boolean result = shuttleMoveGenerate(wrkNo, locNo, shuttleNo);
+                    boolean result = shuttleMoveGenerate(wrkNo, sourceLocNo, locNo, shuttleNo, flag, false);
+                    if (result) {
+                        return true;//璋冨害鎴愬姛
+                    }
+                }
+            }
+        }
+
+        News.info("{}鐩爣搴撲綅娌℃湁鎼滅储鍒板彲鐢ㄧ┛姊溅", locNo);
+        return false;
+    }
+
+    /**
+     * 璋冨害杞﹁締
+     */
+    public boolean searchDispatchShuttleS(Integer wrkNo, String sourceLocNo, String locNo, String flag) {
+        ArrayList<ShuttleThread> sameLev = new ArrayList<>();//鐩稿悓妤煎眰鐨勭┛姊溅
+        ArrayList<ShuttleThread> diffLev = new ArrayList<>();//涓嶅悓妤煎眰鐨勭┛姊溅
+
+        for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
+            //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
+            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
+            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+            if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
+                continue;
+            }
+
+            if (checkChargeWrk(shuttle.getId())) {
+                continue;//瀛樺湪鍏呯數浠诲姟锛岃繃婊ゅ皬杞�
+            }
+
+            if (!shuttleThread.isIdle()) {
+                continue;//灏忚溅蹇欑涓�
+            }
+
+            BasShuttle basShuttle = basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttle.getId()));
+            if (basShuttle != null) {
+                if (basShuttle.getStatus() == 0) {
+                    continue;//灏忚溅琚鐢�
+                }
+            }
+
+            int currentLev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅褰撳墠灞傞珮
+            String currentLocNo = shuttleProtocol.getCurrentLocNo();//灏忚溅褰撳墠搴撲綅鍙�
+
+            if (currentLocNo.equals(locNo)) {
+                //杞﹁締褰撳墠浣嶇疆宸茬粡鏄洰鏍囧簱浣嶏紝璋冨害璇ヨ溅
+                //缁欏伐浣滄。缁戝畾灏忚溅鍙�
+                WrkMast wrkMast1 = wrkMastService.selectByWorkNo(wrkNo);
+                if (wrkMast1 != null) {
+                    wrkMast1.setShuttleNo(shuttleProtocol.getShuttleNo());
+                    wrkMastService.updateById(wrkMast1);
+                    return true;
+                }
+                break;
+            }
+            if (currentLev == Utils.getLev(sourceLocNo)) {
+                //宸ヤ綔妗fゼ灞傜浉鍚岀殑绌挎杞�
+                sameLev.add(shuttleThread);
+            } else {
+                //宸ヤ綔妗d笉鍚屾ゼ灞傜殑绌挎杞�
+                diffLev.add(shuttleThread);
+            }
+
+
+        }
+
+        //浼樺厛璋冨害鍚屾ゼ灞傚皬杞︼紝瀵绘壘绂讳换鍔℃渶杩戠殑绌挎杞�
+        if (!sameLev.isEmpty()) {
+            Map<Integer, ShuttleThread> sameShuttles = new TreeMap<>();//鑷劧鎺掑簭灏忚溅Map
+            for (ShuttleThread shuttleThread : sameLev) {
+                ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+                Integer shuttleNo = shuttleProtocol.getShuttleNo();
+                //褰撳墠绌挎杞﹀簱浣嶅彿
+                String currentLocNo = shuttleProtocol.getCurrentLocNo();
+                if (currentLocNo.equals(sourceLocNo)) {
+                    sameShuttles.put(-1, shuttleThread);
+                    continue;
+                }
+
+                //褰撳墠绌挎杞︾嚎绋嬪埌鐩爣鍦扮偣璺濈
+                List<NavigateNode> currentShuttlePath = navigateUtils.calc(currentLocNo, locNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)), null);//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘
+                if (currentShuttlePath == null) {
+                    continue;
+                }
+                Integer currentAllDistance = navigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+                sameShuttles.put(currentAllDistance, shuttleThread);
+            }
+
+            //灏濊瘯璋冨害鍚屾ゼ灞傚皬杞�
+            for (Map.Entry<Integer, ShuttleThread> entry : sameShuttles.entrySet()) {
+                ShuttleThread shuttleThread = entry.getValue();
+                ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+                Integer shuttleNo = shuttleProtocol.getShuttleNo();
+                //灏濊瘯璋冨害灏忚溅
+                boolean result = shuttleMoveGenerate(wrkNo, sourceLocNo, locNo, shuttleNo, flag, false);
+                if (result) {
+                    return true;//璋冨害鎴愬姛
+                }
+            }
+        }
+
+        //鎵ц鍒版澶勶紝鍚屾ゼ灞傛棤璋冨害鎴愬姛灏忚溅銆傞渶瑕佽繘琛岃法妤煎眰璋冨害灏忚溅
+        //瀵绘壘绂讳换鍔℃ゼ灞傛渶杩戠殑绌挎杞�(涓嶈�冭檻璺ㄦゼ灞傚皬杞︾Щ鍔ㄨ窛绂�)
+        if (!diffLev.isEmpty()) {
+            Map<Integer, ShuttleThread> diffShuttles = new TreeMap<>();//鑷劧鎺掑簭灏忚溅Map
+            //鑾峰彇浠诲姟
+            WrkMast wrkMast1 = wrkMastService.selectByWorkNo(wrkNo);
+            if (wrkMast1 != null) {
+                String targetLoc = wrkMast1.getIoType() < 100 ? wrkMast1.getLocNo() : wrkMast1.getSourceLocNo();
+                int lev = Utils.getLev(targetLoc);//鐩爣妤煎眰
+
+                //妫�娴嬬洰鏍囨ゼ灞傝溅鏁伴噺鏄惁灏忎簬鍏佽鐨勬渶澶ф暟閲�
+                boolean checkDispatchMaxNum = checkDispatchMaxNum(lev);
+                if (!checkDispatchMaxNum) {
+                    News.info("{}浠诲姟锛寋}灞傦紝宸茬粡杈惧埌褰撳墠妤煎眰璋冨害杞﹁締鏈�澶у��", wrkMast1.getWrkNo(), lev);
+                    return false;
+                }
+
+                for (ShuttleThread shuttleThread : diffLev) {
+                    ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+                    //褰撳墠绌挎杞﹀簱浣嶅彿
+                    String currentLocNo = shuttleProtocol.getCurrentLocNo();
+                    int currentLev = Utils.getLev(currentLocNo);
+                    List<WrkMast> wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//鍒ゆ柇褰撳墠绌挎杞︽ゼ灞傛槸鍚︽湁寰呭垎閰嶈溅杈嗙殑浠诲姟锛屽鏋滄湁鍒欎笉鍒嗛厤杩欒締杞�
+                    int shuttleCount = this.getShuttleCountByLev(currentLev);//鑾峰彇绌挎杞︽ゼ灞傝溅杈嗘暟閲�
+                    if (!wrkMasts1.isEmpty() && shuttleCount <= 1) {
+                        //瀛樺湪鍏朵粬浠诲姟涓斿彲鐢ㄥ皬杞︽暟閲忓皬浜庣瓑浜�1锛岃烦杩囪繖杈嗚溅
+                        continue;
+                    }
+
+                    //ABS(鐩爣妤煎眰 - 褰撳墠妤煎眰) 寰楀埌宸窛锛屽彇鏈�灏忓樊鍊�
+                    int currentValue = Math.abs(lev - currentLev);
+                    diffShuttles.put(currentValue, shuttleThread);
+                }
+
+                //灏濊瘯璋冨害璺ㄦゼ灞傚皬杞�
+                for (Map.Entry<Integer, ShuttleThread> entry : diffShuttles.entrySet()) {
+                    ShuttleThread shuttleThread = entry.getValue();
+                    ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+                    Integer shuttleNo = shuttleProtocol.getShuttleNo();
+                    //灏濊瘯璋冨害灏忚溅
+                    boolean result = shuttleMoveGenerate(wrkNo, sourceLocNo, locNo, shuttleNo, flag, false);
                     if (result) {
                         return true;//璋冨害鎴愬姛
                     }
@@ -199,6 +354,14 @@
      */
     @Transactional
     public boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) {
+        return shuttleMoveGenerate(wrkNo, null, locNo, shuttleNo, null, false);
+    }
+
+    /**
+     * 灏忚溅杩佺Щ浠诲姟鐢熸垚
+     */
+    @Transactional
+    public boolean shuttleMoveGenerate(Integer wrkNo, String sourceLocNo, String locNo, Integer shuttleNo, String flag, boolean disableCheck) {
         Date now = new Date();
         //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
         ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
@@ -220,49 +383,54 @@
 
         //鍒ゆ柇绌挎杞︽槸鍚﹀瓨鍦ㄦ湭瀹屾垚鐨勫皬杞︾Щ搴撲换鍔�
         WrkMast hasMoveWorking = wrkMastService.selectShuttleHasMoveWorking(shuttleNo);
-        if (hasMoveWorking != null) {//灏忚溅瀛樺湪绉诲簱浠诲姟锛岀瓑寰呮墽琛屽畬鎴愬悗鍐嶇敓鎴愭柊鐨勪换鍔�
+        if (hasMoveWorking != null && !disableCheck) {//灏忚溅瀛樺湪绉诲簱浠诲姟锛岀瓑寰呮墽琛屽畬鎴愬悗鍐嶇敓鎴愭柊鐨勪换鍔�
             News.info("{}鍙峰皬杞︼紝瀛樺湪绉诲姩浠诲姟锛岀瓑寰呮墽琛屽畬鎴愬悗鍐嶇敓鎴愭柊鐨勪换鍔�", shuttleNo);
             return false;
         }
 
+        //鑾峰彇涓诲伐浣滄。淇℃伅
+        WrkMast mainWrkMast = wrkMastService.selectByWorkNo(wrkNo);
+
         //鍒ゆ柇鏄惁鏈夊叾浠栦换鍔℃鍦ㄤ娇鐢ㄧ┛姊溅
         WrkMast wrkMast2 = wrkMastService.selectShuttleWorking(shuttleNo);
-        if (wrkMast2 != null) {//灏忚溅瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍚庡啀鐢熸垚鏂扮殑浠诲姟
-            News.info("{}鍙峰皬杞︼紝瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍐嶇敓鎴愭柊鐨勪换鍔�", shuttleNo);
-            return false;
+        if (wrkMast2 != null && !disableCheck) {//灏忚溅瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍚庡啀鐢熸垚鏂扮殑浠诲姟
+            if (mainWrkMast == null) {
+                News.info("{}鍙峰皬杞︼紝瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍐嶇敓鎴愭柊鐨勪换鍔�", shuttleNo);
+                return false;
+            } else {
+                if (!mainWrkMast.getShuttleNo().equals(shuttleNo)) {
+                    News.info("{}鍙峰皬杞︼紝瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍐嶇敓鎴愭柊鐨勪换鍔�", shuttleNo);
+                    return false;
+                }
+            }
         }
 
-        Integer sourceStaNo = null;//灏忚溅鎹㈠眰婧愮珯鐐�
-        Integer staNo = null;//灏忚溅鎹㈠眰鐩爣绔欑偣
-        if (Utils.getLev(locNo) != Utils.getLev(shuttleProtocol.getCurrentLocNo())) {
-            //鐩爣搴撲綅鍜屽皬杞﹀簱浣嶅浜庝笉鍚屼竴妤煎眰锛岄渶瑕侀�氳繃鎻愬崌鏈鸿皟搴�
-            //鑾峰彇绌挎杞︽渶杩戜笖绌洪棽鐨勬彁鍗囨満杈撻�佺珯鐐�
-            ForkLiftStaProtocol liftSta = this.getRecentLiftSta(shuttleNo, Utils.getLev(locNo));
-            if (liftSta == null) {
-                News.info("{}鍙峰皬杞︼紝{}鐩爣搴撲綅锛屾病鏈夊彲鐢ㄧ┖闂茶緭閫佺珯鐐�", shuttleNo, locNo);
-                return false;//娌℃湁鍙敤涓旂┖闂茬殑杈撻�佺珯鐐�
-            }
-            sourceStaNo = liftSta.getStaNo();//婧愮珯鐐�
-            //鎻愬崌鏈哄彿*100+鐩爣妤煎眰=鐩爣绔欑偣
-            staNo = liftSta.getLiftNo() * 100 + Utils.getLev(locNo);//鐩爣绔�
+        String currentLocNo = shuttleProtocol.getCurrentLocNo();
+        if (sourceLocNo != null) {
+            currentLocNo = sourceLocNo;
         }
 
         // 鑾峰彇宸ヤ綔鍙�
-        int workNo = commonService.getWorkNo(0);
+        int workNo = commonService.getWorkNo(WrkIoType.SHUTTLE_MOVE.id);
         // 淇濆瓨宸ヤ綔妗�
         WrkMast wrkMast = new WrkMast();
+        wrkMast.setMk(flag);
         wrkMast.setWrkNo(workNo);
         wrkMast.setIoTime(now);
         wrkMast.setWrkSts(WrkStsType.NEW_MOVE.sts); // 宸ヤ綔鐘舵�侊細301.鐢熸垚杩佺Щ浠诲姟
-        wrkMast.setIoType(200); // 鍏ュ嚭搴撶姸鎬侊細 200.灏忚溅杩佺Щ
-        wrkMast.setIoPri(20D);
+        wrkMast.setIoType(WrkIoType.SHUTTLE_MOVE.id); // 鍏ュ嚭搴撶姸鎬侊細 200.灏忚溅杩佺Щ
+        wrkMast.setIoPri(800D);
         wrkMast.setShuttleNo(shuttleNo);//绌挎杞﹀彿
-        wrkMast.setSourceLocNo(shuttleProtocol.getCurrentLocNo()); // 婧愬簱浣� => 灏忚溅褰撳墠搴撲綅鍙�
+        wrkMast.setSourceLocNo(currentLocNo); // 婧愬簱浣�
         wrkMast.setLocNo(locNo); // 鐩爣搴撲綅
-        wrkMast.setSourceStaNo(sourceStaNo);//婧愮珯
-        wrkMast.setStaNo(staNo);//鐩爣绔�
         wrkMast.setAppeTime(now);
         wrkMast.setModiTime(now);
+        wrkMast.setMainWrkNo(mainWrkMast.getWrkNo());
+
+        if ("TRANSPORT_LIFT".equals(flag)) {
+            wrkMast.setMainWrkNo(wrkNo);
+        }
+
         boolean res = wrkMastService.insert(wrkMast);
         if (!res) {
             News.error("灏忚溅杩佺Щ --- 淇濆瓨宸ヤ綔妗eけ璐ワ紒 绌挎杞﹀彿锛�" + shuttleNo);
@@ -270,13 +438,42 @@
         }
 
         //缁欏伐浣滄。缁戝畾灏忚溅鍙�
-        WrkMast wrkMast1 = wrkMastService.selectByWorkNo(wrkNo);
-        if (wrkMast1 != null) {
-            wrkMast1.setShuttleNo(shuttleNo);
-            wrkMastService.updateById(wrkMast1);
+        if (mainWrkMast != null) {
+            mainWrkMast.setShuttleNo(shuttleNo);
+            wrkMastService.updateById(mainWrkMast);
         }
 
         return true;
+    }
+
+    /**
+     * 灏忚溅闆嗗悎
+     */
+    public List<ShuttleGatherResult> shuttleGather(ShuttleGatherParam param) {
+        Wrapper<BasShuttle> wrapper = new EntityWrapper<BasShuttle>().eq("status", 1);
+        if (param != null) {
+            if (!param.getShuttleNos().isEmpty()) {
+                wrapper.in("shuttle_no", param.getShuttleNos());
+            }
+        }
+
+        List<BasShuttle> basShuttles = basShuttleService.selectList(wrapper);
+        List<ShuttleGatherResult> list = new ArrayList<>();
+        for (BasShuttle basShuttle : basShuttles) {
+            String idleLoc = basShuttle.getIdleLoc();
+            if (Cools.isEmpty(idleLoc)) {
+                continue;
+            }
+
+            boolean result = shuttleMoveGenerate(null, idleLoc, basShuttle.getShuttleNo());
+
+            ShuttleGatherResult gatherResult = new ShuttleGatherResult();
+            gatherResult.setShuttleNo(basShuttle.getShuttleNo());
+            gatherResult.setIdleLoc(idleLoc);
+            gatherResult.setResult(result);
+            list.add(gatherResult);
+        }
+        return list;
     }
 
     /**
@@ -297,6 +494,16 @@
             ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
             ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
             if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
+                continue;
+            }
+
+            //灏忚溅鏈夊厖鐢典换鍔�
+            if (shuttleThread.isCharging()) {
+                continue;
+            }
+
+            //灏忚溅鏁呴殰璺宠繃
+            if (shuttleThread.isFault()) {
                 continue;
             }
 
@@ -336,81 +543,6 @@
         return levCount < Integer.parseInt(config.getValue());
     }
 
-    /**
-     * 鑾峰彇绌挎杞︽渶杩戜笖绌洪棽鐨勬彁鍗囨満杈撻�佺珯鐐�
-     */
-    public ForkLiftStaProtocol getRecentLiftSta(Integer shuttleNo, Integer targetLev) {
-        //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
-        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
-        if (shuttleThread == null) {
-            return null;
-        }
-        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
-        if (shuttleProtocol == null) {
-            return null;
-        }
-
-        //鑾峰彇灏忚溅鍚屼竴妤煎眰鐨勭珯鐐�
-        ArrayList<ForkLiftStaProtocol> list = new ArrayList<>();
-        int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅妤煎眰
-        for (ForkLiftSlave slave : slaveProperties.getForkLift()) {
-            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, slave.getId());
-            if (forkLiftThread == null) {
-                continue;
-            }
-            ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
-            if (forkLiftProtocol == null) {
-                continue;
-            }
-            if (!forkLiftThread.isIdle()) {
-                continue;
-            }
-
-            ForkLiftStaProtocol forkLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(slave.getId(), lev);
-            if (forkLiftStaProtocol == null) {
-                continue;
-            }
-
-            //鍒ゆ柇鐩爣妤煎眰绔欑偣鏄惁鏃犳墭鐩�
-            ForkLiftStaProtocol targetLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(slave.getId(), targetLev);
-            if (targetLiftStaProtocol == null) {
-                continue;
-            }
-
-            if (targetLiftStaProtocol.getHasTray()) {
-                continue;//鏈夋墭鐩樿烦杩�
-            }
-
-            list.add(forkLiftStaProtocol);
-        }
-
-        if (list.isEmpty()) {
-            return null;
-        }
-
-        String currentLocNo = shuttleProtocol.getCurrentLocNo();//灏忚溅浣嶇疆
-        Integer recentAllDistance = 9999999;
-        ForkLiftStaProtocol recentSta = null;//鏈�杩戠珯鐐�
-        //鎼滅储璺濈灏忚溅鏈�杩戠殑绔欑偣
-        for (ForkLiftStaProtocol forkLiftStaProtocol : list) {
-            Integer staNo = forkLiftStaProtocol.getStaNo();//绔欑偣鍙�
-            String locNo = forkLiftStaProtocol.getLocNo();//绔欑偣搴撲綅鍙�
-
-            //褰撳墠绌挎杞︾嚎绋嬪埌鐩爣鍦扮偣璺濈
-            List<NavigateNode> currentShuttlePath = navigateUtils.calc(currentLocNo, locNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)), null);//浣跨敤姝e父閫氶亾鍦板浘
-            if (currentShuttlePath == null) {
-                continue;
-            }
-            Integer currentAllDistance = navigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
-            if (currentAllDistance < recentAllDistance) {
-                //濡傛灉褰撳墠妤煎眰鐨勮溅璺緞鏇村皬锛屽垯鏇存柊鏈�杩戠珯鐐�
-                recentSta = forkLiftStaProtocol;
-                recentAllDistance = currentAllDistance;
-            }
-        }
-
-        return recentSta;
-    }
 
     /**
      * 妫�娴嬫槸鍚︾┛姊溅鏄惁鏈夊厖鐢典换鍔�

--
Gitblit v1.9.1