From 944994450e3ba369e218e24c3f5ef3996f5c183c Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 20 九月 2023 16:32:35 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/utils/ShuttleDispatchUtils.java |   54 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 45 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/zy/common/utils/ShuttleDispatchUtils.java b/src/main/java/com/zy/common/utils/ShuttleDispatchUtils.java
index 917c4cd..f428467 100644
--- a/src/main/java/com/zy/common/utils/ShuttleDispatchUtils.java
+++ b/src/main/java/com/zy/common/utils/ShuttleDispatchUtils.java
@@ -18,6 +18,7 @@
 import com.zy.core.model.LiftSlave;
 import com.zy.core.model.ShuttleSlave;
 import com.zy.core.model.protocol.LiftProtocol;
+import com.zy.core.model.protocol.LiftStaProtocol;
 import com.zy.core.model.protocol.NyShuttleProtocol;
 import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.LiftThread;
@@ -111,6 +112,7 @@
                 if (currentAllDistance < recentAllDistance) {
                     //濡傛灉褰撳墠妤煎眰鐨勮溅璺緞鏇村皬锛屽垯鏇存柊鏈�杩戠┛姊溅
                     recentShuttle = shuttleThread;
+                    recentAllDistance = currentAllDistance;
                 }
             }
         }else {
@@ -137,6 +139,7 @@
                 if (currentAllDistance < recentAllDistance) {
                     //濡傛灉褰撳墠妤煎眰鐨勮溅璺緞鏇村皬锛屽垯鏇存柊鏈�杩戠┛姊溅
                     recentShuttle = shuttleThread;
+                    recentAllDistance = currentAllDistance;
                 }
             }
         }
@@ -188,15 +191,18 @@
             return false;
         }
 
-        Integer staNo = null;
-        if (Utils.getLev(locNo) == shuttleProtocol.getPoint().getZ()) {
+        Integer sourceStaNo = null;//灏忚溅鎹㈠眰婧愮珯鐐�
+        Integer staNo = null;//灏忚溅鎹㈠眰鐩爣绔欑偣
+        if (Utils.getLev(locNo) != shuttleProtocol.getPoint().getZ()) {
             //鐩爣搴撲綅鍜屽皬杞﹀簱浣嶅浜庝笉鍚屼竴妤煎眰锛岄渶瑕侀�氳繃鎻愬崌鏈鸿皟搴�
             //鑾峰彇绌挎杞︽渶杩戜笖绌洪棽鐨勬彁鍗囨満杈撻�佺珯鐐�
-            BasDevp liftSta = this.getRecentLiftSta(shuttleNo);
+            LiftStaProtocol liftSta = this.getRecentLiftSta(shuttleNo);
             if (liftSta == null) {
                 return false;//娌℃湁鍙敤涓旂┖闂茬殑杈撻�佺珯鐐�
             }
-            staNo = liftSta.getDevNo();
+            sourceStaNo = liftSta.getStaNo();//婧愮珯鐐�
+            //鎻愬崌鏈哄彿*100+鐩爣妤煎眰=鐩爣绔欑偣
+            staNo = liftSta.getLiftNo() * 100 + Utils.getLev(locNo);//鐩爣绔�
         }
 
         // 鑾峰彇宸ヤ綔鍙�
@@ -211,6 +217,7 @@
         wrkMast.setShuttleNo(shuttleNo);//绌挎杞﹀彿
         wrkMast.setSourceLocNo(shuttleProtocol.getCurrentLocNo()); // 婧愬簱浣� => 灏忚溅褰撳墠搴撲綅鍙�
         wrkMast.setLocNo(locNo); // 鐩爣搴撲綅
+        wrkMast.setSourceStaNo(sourceStaNo);//婧愮珯
         wrkMast.setStaNo(staNo);//鐩爣绔�
         wrkMast.setPicking("N"); // 鎷f枡
         wrkMast.setExitMk("N"); // 閫�鍑�
@@ -236,7 +243,7 @@
     /**
      * 鑾峰彇绌挎杞︽渶杩戜笖绌洪棽鐨勬彁鍗囨満杈撻�佺珯鐐�
      */
-    public BasDevp getRecentLiftSta(Integer shuttleNo) {
+    public LiftStaProtocol getRecentLiftSta(Integer shuttleNo) {
         //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
         NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
         if (shuttleThread == null) {
@@ -247,6 +254,9 @@
             return null;
         }
 
+        //鑾峰彇灏忚溅鍚屼竴妤煎眰鐨勭珯鐐�
+        ArrayList<LiftStaProtocol> list = new ArrayList<>();
+        int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//灏忚溅妤煎眰
         for (LiftSlave slave : slaveProperties.getLift()) {
             LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, slave.getId());
             if (liftThread == null) {
@@ -260,14 +270,40 @@
                 continue;
             }
 
-            BasDevp basDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(shuttleProtocol.getCurrentLocNo()), slave.getId());
-            if (basDevp == null) {
+            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(slave.getId(), lev);
+            if (liftStaProtocol == null) {
                 continue;
             }
-            return basDevp;
+
+            list.add(liftStaProtocol);
         }
 
-        return null;
+        if (list.isEmpty()) {
+            return null;
+        }
+
+        String currentLocNo = shuttleProtocol.getCurrentLocNo();//灏忚溅浣嶇疆
+        Integer recentAllDistance = 9999999;
+        LiftStaProtocol recentSta = null;//鏈�杩戠珯鐐�
+        //鎼滅储璺濈灏忚溅鏈�杩戠殑绔欑偣
+        for (LiftStaProtocol liftStaProtocol : list) {
+            Integer staNo = liftStaProtocol.getStaNo();//绔欑偣鍙�
+            String locNo = liftStaProtocol.getLocNo();//绔欑偣搴撲綅鍙�
+
+            //褰撳墠绌挎杞︾嚎绋嬪埌鐩爣鍦扮偣璺濈
+            List<NavigateNode> currentShuttlePath = NavigateUtils.calc(currentLocNo, locNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)));//浣跨敤姝e父閫氶亾鍦板浘
+            if (currentShuttlePath == null) {
+                continue;
+            }
+            Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+            if (currentAllDistance < recentAllDistance) {
+                //濡傛灉褰撳墠妤煎眰鐨勮溅璺緞鏇村皬锛屽垯鏇存柊鏈�杩戠珯鐐�
+                recentSta = liftStaProtocol;
+                recentAllDistance = currentAllDistance;
+            }
+        }
+
+        return recentSta;
     }
 
 }

--
Gitblit v1.9.1