From d9280b0c2ceab9db2c60c0af1a74e83f91cc74fc Mon Sep 17 00:00:00 2001
From: zhangc <zc@123>
Date: 星期一, 14 四月 2025 12:56:20 +0800
Subject: [PATCH] 1

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

diff --git a/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java b/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
index 34dcb90..a52bde3 100644
--- a/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
+++ b/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
@@ -208,6 +208,158 @@
     }
 
     /**
+     * 璋冨害杞﹁締
+     */
+    public boolean searchDispatchShuttleIn(Integer wrkNo, String sourceLocNo, String locNo, String flag, boolean in) {
+        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 (in) {
+                if (currentLev == Utils.getLev(sourceLocNo)) {
+                    //宸ヤ綔妗fゼ灞傜浉鍚岀殑绌挎杞�
+                    sameLev.add(shuttleThread);
+                } else {
+                    //宸ヤ綔妗d笉鍚屾ゼ灞傜殑绌挎杞�
+                    diffLev.add(shuttleThread);
+                }
+//            } else {
+//                if (currentLev == Utils.getLev(locNo)) {
+//                    //宸ヤ綔妗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;//璋冨害鎴愬姛
+                    }
+                }
+            }
+        }
+
+        News.info("{}鐩爣搴撲綅娌℃湁鎼滅储鍒板彲鐢ㄧ┛姊溅", locNo);
+        return false;
+    }
+
+    /**
      * 灏忚溅杩佺Щ浠诲姟鐢熸垚
      */
     @Transactional

--
Gitblit v1.9.1