From 1ec7833aff728861936180a7e1159373272d9e2b Mon Sep 17 00:00:00 2001
From: zc <zc@123>
Date: 星期三, 23 四月 2025 18:10:32 +0800
Subject: [PATCH] 初步调试

---
 src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java |  291 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 276 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java b/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
index c5e2346..5fb8a40 100644
--- a/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
+++ b/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
@@ -68,7 +68,7 @@
     /**
      * 璋冨害杞﹁締
      */
-    public boolean dispatchShuttle(Integer wrkNo, String locNo) {
+    public boolean searchDispatchShuttle(Integer wrkNo, String sourceLocNo, String locNo, String flag) {
         ArrayList<ShuttleThread> sameLev = new ArrayList<>();//鐩稿悓妤煎眰鐨勭┛姊溅
         ArrayList<ShuttleThread> diffLev = new ArrayList<>();//涓嶅悓妤煎眰鐨勭┛姊溅
 
@@ -128,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) {
@@ -143,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;//璋冨害鎴愬姛
                 }
@@ -172,16 +177,20 @@
                     //褰撳墠绌挎杞﹀簱浣嶅彿
                     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;
-                    }
+//                    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);
+                    if (diffShuttles.get(currentValue) != null) {
+                        diffShuttles.put(currentValue + 1, shuttleThread);
+                    } else {
+                        diffShuttles.put(currentValue, shuttleThread);
+                    }
                 }
 
                 //灏濊瘯璋冨害璺ㄦゼ灞傚皬杞�
@@ -190,7 +199,155 @@
                     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) || currentLocNo.equals(sourceLocNo)) {
+                //杞﹁締褰撳墠浣嶇疆宸茬粡鏄洰鏍囧簱浣嶏紝璋冨害璇ヨ溅
+                //缁欏伐浣滄。缁戝畾灏忚溅鍙�
+                WrkMast wrkMast1 = wrkMastService.selectByWorkNo(wrkNo);
+                if (wrkMast1 != null) {
+                    wrkMast1.setShuttleNo(shuttleProtocol.getShuttleNo());
+                    wrkMastService.updateById(wrkMast1);
+                    sameLev.add(0,shuttleThread);
+                    //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);
+                    if (diffShuttles.get(currentValue) != null) {
+                        diffShuttles.put(currentValue + 1, shuttleThread);
+                    } else {
+                        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;//璋冨害鎴愬姛
                     }
@@ -201,6 +358,104 @@
         News.info("{}鐩爣搴撲綅娌℃湁鎼滅储鍒板彲鐢ㄧ┛姊溅", locNo);
         return false;
     }
+
+    /**
+     * 璋冨害杞﹁締
+     */
+    public boolean searchDispatchShuttleNoLift(Integer wrkNo, String sourceLocNo, String locNo, String flag) {
+        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;//灏忚溅琚鐢�
+                }
+            }
+            diffLev.add(shuttleThread);
+        }
+
+        //瀵绘壘绂讳换鍔℃ゼ灞傛渶杩戠殑绌挎杞�(涓嶈�冭檻璺ㄦゼ灞傚皬杞︾Щ鍔ㄨ窛绂�)
+        if (!diffLev.isEmpty()) {
+            Map<Integer, ShuttleThread> diffShuttles = new TreeMap<>();//鑷劧鎺掑簭灏忚溅Map
+            //鑾峰彇浠诲姟
+            WrkMast wrkMast1 = wrkMastService.selectByWorkNo(wrkNo);
+            if (wrkMast1 != null) {
+                int lev = 1;
+                boolean b = wrkMast1.getIoType() < 100;
+                if (b) {
+                    //ruku
+                    if (wrkMast1.getStaNo() == 1015) {
+                        lev = 1;
+                    } else {
+                        lev = 5;
+                    }
+                } else {
+                    lev = Utils.getLev(wrkMast1.getSourceLocNo());//鐩爣妤煎眰
+                }
+
+
+                //妫�娴嬬洰鏍囨ゼ灞傝溅鏁伴噺鏄惁灏忎簬鍏佽鐨勬渶澶ф暟閲�
+                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);
+
+                    if (wrkMast1.getIoType() == 101 && currentLocNo.equals(locNo)) {
+                        //杞﹁締褰撳墠浣嶇疆宸茬粡鏄洰鏍囧簱浣嶏紝璋冨害璇ヨ溅
+                        //缁欏伐浣滄。缁戝畾灏忚溅鍙�
+                        diffShuttles.put(-1, shuttleThread);
+                    } else {
+                        //ABS(鐩爣妤煎眰 - 褰撳墠妤煎眰) 寰楀埌宸窛锛屽彇鏈�灏忓樊鍊�
+                        int currentValue = Math.abs(lev - currentLev);
+                        if (diffShuttles.get(currentValue) != null) {
+                            diffShuttles.put(currentValue + 1, shuttleThread);
+                        } else {
+                            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;//璋冨害鎴愬姛
+                    }
+                }
+            }
+        }
+
+        News.info("{}鐩爣搴撲綅娌℃湁鎼滅储鍒板彲鐢ㄧ┛姊溅", locNo);
+        return false;
+    }
+
 
     /**
      * 灏忚溅杩佺Щ浠诲姟鐢熸垚
@@ -240,18 +495,20 @@
             News.info("{}鍙峰皬杞︼紝瀛樺湪绉诲姩浠诲姟锛岀瓑寰呮墽琛屽畬鎴愬悗鍐嶇敓鎴愭柊鐨勪换鍔�", shuttleNo);
             return false;
         }
-
+        WrkMast mainWrkMast = null;
         //鑾峰彇涓诲伐浣滄。淇℃伅
-        WrkMast mainWrkMast = wrkMastService.selectByWorkNo(wrkNo);
+        if (wrkNo != null) {
+            mainWrkMast = wrkMastService.selectByWorkNo(wrkNo);
+        }
 
         //鍒ゆ柇鏄惁鏈夊叾浠栦换鍔℃鍦ㄤ娇鐢ㄧ┛姊溅
-        WrkMast wrkMast2 = wrkMastService.selectShuttleWorking(shuttleNo);
+        WrkMast wrkMast2 = wrkMastService.selectShuttleWorking2(shuttleNo, wrkNo, mainWrkMast != null ? mainWrkMast.getMainWrkNo() : null);
         if (wrkMast2 != null && !disableCheck) {//灏忚溅瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍚庡啀鐢熸垚鏂扮殑浠诲姟
             if (mainWrkMast == null) {
                 News.info("{}鍙峰皬杞︼紝瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍐嶇敓鎴愭柊鐨勪换鍔�", shuttleNo);
                 return false;
             } else {
-                if (!mainWrkMast.getShuttleNo().equals(shuttleNo)) {
+                if (mainWrkMast.getShuttleNo() != null && !mainWrkMast.getShuttleNo().equals(shuttleNo)) {
                     News.info("{}鍙峰皬杞︼紝瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍐嶇敓鎴愭柊鐨勪换鍔�", shuttleNo);
                     return false;
                 }
@@ -278,7 +535,11 @@
         wrkMast.setLocNo(locNo); // 鐩爣搴撲綅
         wrkMast.setAppeTime(now);
         wrkMast.setModiTime(now);
-        wrkMast.setMainWrkNo(mainWrkMast.getWrkNo());
+
+        if ("TRANSPORT_LIFT".equalsIgnoreCase(flag) || "TRANSPORT_DEVP".equalsIgnoreCase(flag)) {
+            wrkMast.setMainWrkNo(wrkNo);
+        }
+
         boolean res = wrkMastService.insert(wrkMast);
         if (!res) {
             News.error("灏忚溅杩佺Щ --- 淇濆瓨宸ヤ綔妗eけ璐ワ紒 绌挎杞﹀彿锛�" + shuttleNo);

--
Gitblit v1.9.1