From b63790fa580ea78777f16bff6bc79373d675dd10 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期四, 21 八月 2025 16:50:47 +0800
Subject: [PATCH] #

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

diff --git a/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java b/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
index 5e0d93c..18ec992 100644
--- a/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
+++ b/src/main/java/com/zy/core/dispatcher/ShuttleDispatchUtils.java
@@ -5,27 +5,25 @@
 import com.core.common.Cools;
 import com.core.exception.CoolException;
 import com.zy.asrs.domain.ShuttleGatherResult;
+import com.zy.asrs.domain.param.ShuttleDemoParam;
 import com.zy.asrs.domain.param.ShuttleGatherParam;
 import com.zy.asrs.entity.BasShuttle;
+import com.zy.asrs.entity.DeviceConfig;
 import com.zy.asrs.entity.WrkMast;
 import com.zy.asrs.service.BasShuttleService;
+import com.zy.asrs.service.DeviceConfigService;
 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.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;
@@ -42,8 +40,6 @@
 public class ShuttleDispatchUtils {
 
     @Autowired
-    private SlaveProperties slaveProperties;
-    @Autowired
     private WrkMastService wrkMastService;
     @Autowired
     private CommonService commonService;
@@ -53,6 +49,8 @@
     private ConfigService configService;
     @Autowired
     private BasShuttleService basShuttleService;
+    @Autowired
+    private DeviceConfigService deviceConfigService;
 
     /**
      * 璋冨害杞﹁締-璋冨害鎸囧畾绌挎杞�
@@ -68,15 +66,17 @@
         ArrayList<ShuttleThread> sameLev = new ArrayList<>();//鐩稿悓妤煎眰鐨勭┛姊溅
         ArrayList<ShuttleThread> diffLev = new ArrayList<>();//涓嶅悓妤煎眰鐨勭┛姊溅
 
-        for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
+        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
+        for (DeviceConfig device : shuttleList) {
             //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
-            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
+            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
             ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
             if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
                 continue;
             }
 
-            if (checkChargeWrk(shuttle.getId())) {
+            if (checkChargeWrk(device.getDeviceNo())) {
                 continue;//瀛樺湪鍏呯數浠诲姟锛岃繃婊ゅ皬杞�
             }
 
@@ -84,7 +84,7 @@
                 continue;//灏忚溅蹇欑涓�
             }
 
-            BasShuttle basShuttle = basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", shuttle.getId()));
+            BasShuttle basShuttle = basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", device.getDeviceNo()));
             if (basShuttle != null) {
                 if (basShuttle.getStatus() == 0) {
                     continue;//灏忚溅琚鐢�
@@ -125,7 +125,7 @@
                 //褰撳墠绌挎杞﹀簱浣嶅彿
                 String currentLocNo = shuttleProtocol.getCurrentLocNo();
                 //褰撳墠绌挎杞︾嚎绋嬪埌鐩爣鍦扮偣璺濈
-                List<NavigateNode> currentShuttlePath = navigateUtils.calc(currentLocNo, locNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)), null);//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘
+                List<NavigateNode> currentShuttlePath = navigateUtils.calc(currentLocNo, locNo, NavigationMapType.getMapTypes(NavigationMapType.NORMAL), Utils.getShuttlePoints(shuttleNo, Utils.getLev(currentLocNo)), null);//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘
                 if (currentShuttlePath == null) {
                     continue;
                 }
@@ -170,7 +170,7 @@
                     int currentLev = Utils.getLev(currentLocNo);
                     //鍒ゆ柇褰撳墠妤煎眰鏄惁鏈変换鍔★紝濡傛灉鏈夊垯涓嶅垎閰嶈繖杈嗚溅
                     List<WrkMast> wrkMasts1 = wrkMastService.selectWrkByLev(currentLev);
-                    int shuttleCount = this.getShuttleCountByLev(currentLev);//鑾峰彇绌挎杞︽ゼ灞傝溅杈嗘暟閲�
+                    int shuttleCount = this.getShuttleEnableUseCountByLev(currentLev);//鑾峰彇绌挎杞︽ゼ灞傝溅杈嗘暟閲�
                     if (!wrkMasts1.isEmpty() && shuttleCount <= 1) {
                         //瀛樺湪鍏朵粬浠诲姟涓斿彲鐢ㄥ皬杞︽暟閲忓皬浜庣瓑浜�1锛岃烦杩囪繖杈嗚溅
                         continue;
@@ -247,27 +247,6 @@
             }
         }
 
-        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();//婧愮珯鐐�
-
-            ForkLiftStaProtocol targetLiftSta = ForkLiftUtils.getLiftStaByLev(liftSta.getLiftNo(), Utils.getLev(locNo));
-            if (targetLiftSta == null) {
-                News.info("{}鍙峰皬杞︼紝{}鐩爣搴撲綅锛屾病鏈夌洰鏍囩珯鐐�", shuttleNo, locNo);
-                return false;//娌℃湁鎵惧埌鐩爣绔欑偣
-            }
-            //鐩爣绔欑偣
-            staNo = targetLiftSta.getStaNo();//鐩爣绔�
-        }
-
         // 鑾峰彇宸ヤ綔鍙�
         int workNo = commonService.getWorkNo(WrkIoType.SHUTTLE_MOVE.id);
         // 淇濆瓨宸ヤ綔妗�
@@ -280,8 +259,6 @@
         wrkMast.setShuttleNo(shuttleNo);//绌挎杞﹀彿
         wrkMast.setSourceLocNo(shuttleProtocol.getCurrentLocNo()); // 婧愬簱浣� => 灏忚溅褰撳墠搴撲綅鍙�
         wrkMast.setLocNo(locNo); // 鐩爣搴撲綅
-        wrkMast.setSourceStaNo(sourceStaNo);//婧愮珯
-        wrkMast.setStaNo(staNo);//鐩爣绔�
         wrkMast.setAppeTime(now);
         wrkMast.setModiTime(now);
         boolean res = wrkMastService.insert(wrkMast);
@@ -330,6 +307,25 @@
     }
 
     /**
+     * 灏忚溅婕旂ず
+     */
+    public void shuttleDemo(ShuttleDemoParam param) {
+        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Shuttle))
+                .in("device_no", param.getShuttleNos())
+        );
+
+        for (DeviceConfig device : shuttleList) {
+            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
+            if (shuttleThread == null) {
+                continue;
+            }
+
+            shuttleThread.enableDemo(param.getStatus() == 1);
+        }
+    }
+
+    /**
      * 妫�娴嬬洰鏍囨ゼ灞傝溅鏁伴噺鏄惁灏忎簬鍏佽鐨勬渶澶ф暟閲�
      * true: 灏忎簬鏈�澶ф暟閲�  false: 澶т簬鎴栫瓑浜庢渶澶ф暟閲�
      */
@@ -341,10 +337,12 @@
             return false;
         }
 
+        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
         int levCount = 0;//鐩爣妤煎眰杞﹁締鏁伴噺
-        for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
+        for (DeviceConfig device : shuttleList) {
             //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
-            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
+            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
             ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
             if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
                 continue;
@@ -397,95 +395,6 @@
     }
 
     /**
-     * 鑾峰彇绌挎杞︽渶杩戜笖绌洪棽鐨勬彁鍗囨満杈撻�佺珯鐐�
-     */
-    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;
-            }
-
-            //鍒ゆ柇褰撳墠灞傛槸鍚︽棤鎵樼洏
-            if (forkLiftStaProtocol.getHasTray()) {
-                continue;
-            }
-
-            if (forkLiftStaProtocol.getHasCar()) {
-                continue;
-            }
-
-            //鍒ゆ柇鐩爣妤煎眰绔欑偣鏄惁鏃犳墭鐩�
-            ForkLiftStaProtocol targetLiftStaProtocol = ForkLiftUtils.getLiftStaByLev(slave.getId(), targetLev);
-            if (targetLiftStaProtocol == null) {
-                continue;
-            }
-
-            if (targetLiftStaProtocol.getHasTray()) {
-                continue;//鏈夋墭鐩樿烦杩�
-            }
-
-            if (targetLiftStaProtocol.getHasCar()) {
-                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;
-    }
-
-    /**
      * 妫�娴嬫槸鍚︾┛姊溅鏄惁鏈夊厖鐢典换鍔�
      */
     public boolean checkChargeWrk(int shuttleNo) {
@@ -500,11 +409,13 @@
     /**
      * 鑾峰彇妤煎眰鍙敤灏忚溅鏁伴噺
      */
-    public int getShuttleCountByLev(int lev) {
+    public int getShuttleEnableUseCountByLev(int lev) {
+        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
         int count = 0;
-        for (ShuttleSlave slave : slaveProperties.getShuttle()) {
+        for (DeviceConfig device : shuttleList) {
             //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
-            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
+            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
             if (shuttleThread == null) {
                 continue;
             }
@@ -514,7 +425,7 @@
                 continue;
             }
 
-            if (checkChargeWrk(slave.getId())) {
+            if (checkChargeWrk(device.getDeviceNo())) {
                 continue;//瀛樺湪鍏呯數浠诲姟锛岃繃婊ゅ皬杞�
             }
 
@@ -531,4 +442,36 @@
         return count;
     }
 
+    /**
+     * 鑾峰彇妤煎眰灏忚溅鏁伴噺
+     */
+    public int getShuttleCountByLev(int lev) {
+        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
+        int count = 0;
+        for (DeviceConfig device : shuttleList) {
+            //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
+            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
+            if (shuttleThread == null) {
+                continue;
+            }
+
+            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+            if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
+                continue;
+            }
+
+            if (shuttleProtocol.getCurrentLocNo() == null) {
+                continue;
+            }
+
+            if (Utils.getLev(shuttleProtocol.getCurrentLocNo()) == lev) {
+                //鍚屼竴妤煎眰鍙敤灏忚溅
+                count++;
+                continue;
+            }
+        }
+        return count;
+    }
+
 }

--
Gitblit v1.9.1