From 3709a9295cf72fe531b954c14257a6a76cba9f21 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 02 八月 2023 08:38:58 +0800
Subject: [PATCH] 小车调度分离

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  184 +--------------------------------------------
 1 files changed, 7 insertions(+), 177 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
index e5de957..75868e7 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -93,6 +93,8 @@
     @Autowired
     private BasLiftService basLiftService;
     @Autowired
+    private ShuttleDispatchUtils shuttleDispatchUtils;
+    @Autowired
     private RedisUtil redisUtil;
 
     /**
@@ -703,7 +705,7 @@
     public boolean shuttleInExecuteStep1(WrkMast wrkMast, BasDevp basDevp) {
         if (wrkMast.getWrkSts() == 4) {
             if (wrkMast.getShuttleNo() == null) {//娌℃湁缁戝畾灏忚溅锛岃繘琛岃皟搴�
-                dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐�
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐�
                 return false;
             }
 
@@ -723,7 +725,7 @@
             //鍒ゆ柇灏忚溅鏄惁鍒拌揪杈撻�佺珯鐐瑰簱浣�
             if (!shuttleProtocol.getCurrentLocNo().equals(basDevp.getLocNo())) {
                 //灏忚溅涓嶅湪杈撻�佺珯鐐逛綅缃�
-                dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐�
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐�
                 return false;
             }
 
@@ -970,7 +972,7 @@
         //21.鐢熸垚鍑哄簱浠诲姟 => 22.灏忚溅鎼繍涓�
         if (wrkMast.getWrkSts() == 21) {
             if (wrkMast.getShuttleNo() == null) {//娌℃湁缁戝畾灏忚溅锛岃繘琛岃皟搴�
-                dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄥ簱浣嶈繘琛屽彇璐�
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄥ簱浣嶈繘琛屽彇璐�
                 return false;
             }
 
@@ -996,7 +998,7 @@
             //鍒ゆ柇灏忚溅鏄惁鍒拌揪璐х墿搴撲綅
             if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
                 //灏忚溅涓嶅湪杈撻�佺珯鐐逛綅缃�
-                dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐�
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐�
                 return false;
             }
 
@@ -2117,7 +2119,7 @@
             if (wrkCharge.getWrkSts() == 51) {
                 if (!shuttleProtocol.getCurrentLocNo().equals(wrkCharge.getLocNo())) {
                     //灏忚溅涓嶅湪鍏呯數妗╀綅缃�
-                    dispatchShuttle(wrkCharge.getWrkNo(), wrkCharge.getLocNo(), shuttle.getId());//璋冨害灏忚溅鍘诲厖鐢垫々
+                    shuttleDispatchUtils.dispatchShuttle(wrkCharge.getWrkNo(), wrkCharge.getLocNo(), shuttle.getId());//璋冨害灏忚溅鍘诲厖鐢垫々
                     continue;
                 }
 
@@ -2167,178 +2169,6 @@
 
         }
 
-    }
-
-    /**
-     * 璋冨害杞﹁締-璋冨害鎸囧畾绌挎杞�
-     */
-    public void dispatchShuttle(Integer wrkNo, String locNo, Integer shuttleNo) {
-        shuttleMoveGenerate(wrkNo, locNo, shuttleNo);
-    }
-
-    /**
-     * 璋冨害杞﹁締
-     */
-    public void dispatchShuttle(Integer wrkNo, String locNo) {
-        ArrayList<NyShuttleThread> sameLev = new ArrayList<>();//鐩稿悓妤煎眰鐨勭┛姊溅
-        ArrayList<NyShuttleThread> diffLev = new ArrayList<>();//涓嶅悓妤煎眰鐨勭┛姊溅
-
-        for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
-            //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
-            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
-            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
-            if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
-                continue;
-            }
-
-            if (!shuttleProtocol.isIdle()) {
-                continue;
-            }
-
-            int currentLev = shuttleProtocol.getPoint().getZ();//灏忚溅褰撳墠灞傞珮
-            String currentLocNo = shuttleProtocol.getCurrentLocNo();//灏忚溅褰撳墠搴撲綅鍙�
-
-            if (currentLocNo.equals(locNo)) {
-                //杞﹁締褰撳墠浣嶇疆宸茬粡鏄洰鏍囧簱浣嶏紝璋冨害璇ヨ溅
-                shuttleMoveGenerate(wrkNo, locNo, shuttleProtocol.getShuttleNo().intValue());
-                break;
-            }
-
-            if (currentLev == Utils.getLev(locNo)) {
-                //宸ヤ綔妗fゼ灞傜浉鍚岀殑绌挎杞�
-                sameLev.add(shuttleThread);
-            }else {
-                //宸ヤ綔妗d笉鍚屾ゼ灞傜殑绌挎杞�
-                diffLev.add(shuttleThread);
-            }
-
-        }
-
-        Integer recentAllDistance = 9999999;
-        NyShuttleThread recentShuttle = null;//褰撳墠璺濈鏈�杩戠殑鍥涘悜绌挎杞︾嚎绋�
-        if (sameLev.size() > 0) {
-            //鍚屼竴妤煎眰鏈夌┖闂茬┛姊溅锛屽垯鍙湪宸ヤ綔妗fゼ灞傚鎵�
-            //瀵绘壘绂讳换鍔℃渶杩戠殑绌挎杞�
-            for (NyShuttleThread shuttleThread : sameLev) {
-                //褰撳墠绌挎杞﹀簱浣嶅彿
-                String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo();
-                //褰撳墠绌挎杞︾嚎绋嬪埌鐩爣鍦扮偣璺濈
-                List<NavigateNode> currentShuttlePath = NavigateUtils.calc(currentLocNo, locNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), Utils.getLev(currentLocNo)));//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘
-                if (currentShuttlePath == null) {
-                    continue;
-                }
-                Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
-                if (currentAllDistance < recentAllDistance) {
-                    //濡傛灉褰撳墠妤煎眰鐨勮溅璺緞鏇村皬锛屽垯鏇存柊鏈�杩戠┛姊溅
-                    recentShuttle = shuttleThread;
-                }
-            }
-        }else {
-            //鍚屼竴妤煎眰锛屾病鏈夌┖闂茬┛姊溅锛屽彧鑳戒粠鍏朵粬妤煎眰璋冨害
-            //瀵绘壘绂讳换鍔℃渶杩戠殑绌挎杞�
-            for (NyShuttleThread shuttleThread : diffLev) {
-
-                //褰撳墠绌挎杞﹀簱浣嶅彿
-                String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo();
-                int currentLev = Utils.getLev(currentLocNo);
-                List<WrkMast> wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//鍒ゆ柇褰撳墠绌挎杞︽ゼ灞傛槸鍚︽湁寰呭垎閰嶈溅杈嗙殑浠诲姟锛屽鏋滄湁鍒欎笉鍒嗛厤杩欒締杞�
-                if (wrkMasts1.size() > 0) {
-                    //瀛樺湪鍏朵粬浠诲姟锛岃烦杩囪繖杈嗚溅
-                    continue;
-                }
-
-                //褰撳墠绌挎杞︾嚎绋嬪埌褰撳墠杞﹀瓙鎵�鍦ㄦゼ灞傜殑鎻愬崌鏈哄彛璺濈
-                List<NavigateNode> currentShuttlePath = NavigateUtils.calc(currentLocNo, Utils.levToOutInStaLocNo(currentLev), NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), currentLev));//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘
-                if (currentShuttlePath == null) {
-                    continue;
-                }
-
-                Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
-                if (currentAllDistance < recentAllDistance) {
-                    //濡傛灉褰撳墠妤煎眰鐨勮溅璺緞鏇村皬锛屽垯鏇存柊鏈�杩戠┛姊溅
-                    recentShuttle = shuttleThread;
-                }
-            }
-        }
-
-        if (recentShuttle == null) {//娌℃湁鎼滅储鍒板彲鐢ㄧ┛姊溅
-            return;
-        }
-
-        //鎼滅储鍒板彲鐢ㄧ┛姊溅锛岃皟搴﹁杞�
-        shuttleMoveGenerate(wrkNo, locNo, recentShuttle.getSlave().getId());
-    }
-
-    /**
-     * 灏忚溅杩佺Щ浠诲姟鐢熸垚
-     */
-    @Transactional
-    public boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) {
-        Date now = new Date();
-        //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
-        NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
-        if (shuttleThread == null) {
-            return false;
-        }
-        NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
-        if (shuttleProtocol == null) {
-            return false;
-        }
-
-        //灏忚溅澶勪簬绌洪棽鐘舵��
-        if (!shuttleProtocol.isIdleNoCharge()) {
-            return false;
-        }
-
-        //鍒ゆ柇绌挎杞︽槸鍚﹀瓨鍦ㄦ湭瀹屾垚鐨勫皬杞︾Щ搴撲换鍔�
-        WrkMast hasMoveWorking = wrkMastMapper.selectShuttleHasMoveWorking(shuttleNo);
-        if (hasMoveWorking != null) {//灏忚溅瀛樺湪绉诲簱浠诲姟锛岀瓑寰呮墽琛屽畬鎴愬悗鍐嶇敓鎴愭柊鐨勪换鍔�
-            return false;
-        }
-
-        //鍒ゆ柇鏄惁鏈夊叾浠栦换鍔℃鍦ㄤ娇鐢ㄧ┛姊溅
-        WrkMast wrkMast2 = wrkMastMapper.selectShuttleWorking(shuttleNo);
-        if (wrkMast2 != null) {//灏忚溅瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍚庡啀鐢熸垚鏂扮殑浠诲姟
-            return false;
-        }
-
-        //鍒ゆ柇鏄惁鏈夊厖鐢典换鍔℃鍦ㄤ娇鐢ㄧ┛姊溅
-        WrkCharge wrkCharge = wrkChargeMapper.selectWorking(shuttleNo);
-        if (wrkCharge != null) {//灏忚溅瀛樺湪鍏呯數浠诲姟锛岀瓑寰呮墽琛屽畬鎴愬悗鍐嶇敓鎴愭柊鐨勪换鍔�
-            return false;
-        }
-
-        // 鑾峰彇宸ヤ綔鍙�
-        int workNo = commonService.getWorkNo(0);
-        // 淇濆瓨宸ヤ綔妗�
-        WrkMast wrkMast = new WrkMast();
-        wrkMast.setWrkNo(workNo);
-        wrkMast.setIoTime(now);
-        wrkMast.setWrkSts(101L); // 宸ヤ綔鐘舵�侊細101.绉诲姩鍒拌繎鐐圭瓑寰呰縼鍑�
-        wrkMast.setIoType(200); // 鍏ュ嚭搴撶姸鎬侊細 200.灏忚溅绉诲簱
-        wrkMast.setIoPri(20D);
-        wrkMast.setShuttleNo(shuttleNo);//绌挎杞﹀彿
-        wrkMast.setSourceLocNo(shuttleProtocol.getCurrentLocNo()); // 婧愬簱浣� => 灏忚溅褰撳墠搴撲綅鍙�
-        wrkMast.setLocNo(locNo); // 鐩爣搴撲綅
-        wrkMast.setPicking("N"); // 鎷f枡
-        wrkMast.setExitMk("N"); // 閫�鍑�
-        wrkMast.setLinkMis("N");
-        wrkMast.setAppeTime(now);
-        wrkMast.setModiTime(now);
-        int res = wrkMastMapper.insert(wrkMast);
-        if (res == 0) {
-            News.error("灏忚溅杩佺Щ --- 淇濆瓨宸ヤ綔妗eけ璐ワ紒 绌挎杞﹀彿锛�" + shuttleNo);
-            throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
-        }
-
-        //缁欏伐浣滄。缁戝畾灏忚溅鍙�
-        WrkMast wrkMast1 = wrkMastMapper.selectByWorkNo(wrkNo);
-        if (wrkMast1 != null) {
-            wrkMast1.setShuttleNo(shuttleNo);
-            wrkMastMapper.updateById(wrkMast1);
-        }
-
-        return true;
     }
 
     /**

--
Gitblit v1.9.1