From ddeaa535350db85a54a041da6a4d74e50877d637 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 04 四月 2023 14:34:02 +0800
Subject: [PATCH] 修复寻路算法路线数据4(站点)无法移动问题

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  266 +++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 209 insertions(+), 57 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 e3d8031..0db902b 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -23,10 +23,7 @@
 import com.zy.core.enums.*;
 import com.zy.core.model.*;
 import com.zy.core.model.command.*;
-import com.zy.core.model.protocol.CrnProtocol;
-import com.zy.core.model.protocol.ShuttleProtocol;
-import com.zy.core.model.protocol.StaProtocol;
-import com.zy.core.model.protocol.SteProtocol;
+import com.zy.core.model.protocol.*;
 import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.*;
 import lombok.extern.slf4j.Slf4j;
@@ -636,15 +633,28 @@
                 if (true || staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable()) {
                     WrkMast wrkMast = wrkMastMapper.selectRackInStep48(workNo, staProtocol.getSiteId());
                     if (wrkMast != null) {
-                        if (wrkMast.getWrkSts() == 4) {
-                            //瀵绘壘鏈�杩戜笖绌洪棽鐨勫洓鍚戠┛姊溅
-                            HashMap<String, Object> searchIdleShuttle = this.searchIdleShuttle(wrkMast);
-                            ShuttleThread shuttleThread = (ShuttleThread) searchIdleShuttle.get("result");
+                        if (wrkMast.getWrkSts() == 4 || wrkMast.getWrkSts() == 8) {
+                            ShuttleThread shuttleThread = null;
+                            HashMap<String, Object> searchIdleShuttle = null;
+                            if (wrkMast.getWrkSts() == 4) {
+                                //瀵绘壘鏈�杩戜笖绌洪棽鐨勫洓鍚戠┛姊溅
+                                searchIdleShuttle = this.searchIdleShuttle(wrkMast);
+                                shuttleThread = (ShuttleThread) searchIdleShuttle.get("result");
+                            }else {
+                                //鐘舵��8锛屽洓鍚戠┛姊溅宸插湪鎻愬崌鏈哄彛锛岀瓑寰呭懡浠よ繘琛屽叆搴撴惉杩愬姩浣�
+                                Integer shuttleNo = wrkMast.getShuttleNo();//鍥涘悜绌挎杞﹀彿
+                                shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
+                            }
+
                             if (shuttleThread == null) {
                                 continue;
                             }
 
                             ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+                            if (!shuttleProtocol.isIdle()) {
+                                continue;
+                            }
+
                             wrkMast.setShuttleNo(shuttleProtocol.getShuttleNo().intValue());//缁欏伐浣滄。鍒嗛厤鍥涘悜绌挎杞﹀彿
 
                             //鍒嗛厤浠诲姟鍙�
@@ -660,56 +670,32 @@
                             //鍏ュ嚭搴撴ā寮�
                             assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());
                             //婧愬簱浣�(灏忚溅褰撳墠浣嶇疆)
-                            Short currentCode = shuttleProtocol.getCurrentCode();
-                            LocMast currentLocMast = locMastService.queryByQrCode(currentCode.toString());
-                            assignCommand.setSourceLocNo(currentLocMast.getLocNo());
+                            String currentLocNo = shuttleProtocol.getCurrentLocNo();
+                            assignCommand.setSourceLocNo(currentLocNo);
 
-                            if (Boolean.parseBoolean(searchIdleShuttle.get("sameLay").toString())) {
+                            if (wrkMast.getWrkSts() == 8 || Boolean.parseBoolean(searchIdleShuttle.get("sameLay").toString())) {
                                 //鍚屼竴灞�
                                 //鍒嗛厤鐩爣搴撲綅
                                 shuttleProtocol.setLocNo(wrkMast.getLocNo());
                                 //鐩爣搴撲綅
-                                assignCommand.setDistLocNo(wrkMast.getLocNo());
+                                assignCommand.setLocNo(wrkMast.getLocNo());
                                 wrkMast.setWrkSts(9L);//灏忚溅鍏ュ簱涓�
                             }else {
                                 //涓嶅悓灞傦紝灏嗙洰鏍囧簱浣嶅垎閰嶆垚鎻愬崌鏈哄簱浣嶅彿
-                                //鍒嗛厤鐩爣搴撲綅
-                                shuttleProtocol.setLocNo("1800201");
+
+                                //灏忚溅褰撳墠灞傞珮
+                                Integer currentLev = Integer.parseInt(currentLocNo.substring(currentLocNo.length() - 2, currentLocNo.length()));
+
+                                //鑾峰彇鎻愬崌鏈�
+                                LiftSlave liftSlave = slaveProperties.getLift().get(0);
+                                //鎻愬崌鏈哄簱浣嶅彿
+                                String liftLocNo = liftSlave.getLiftLocNo(currentLev);
+                                shuttleProtocol.setLocNo(liftLocNo);
                                 //鐩爣搴撲綅
-                                assignCommand.setDistLocNo("1800201");
+                                assignCommand.setLocNo(liftLocNo);
                                 wrkMast.setWrkSts(5L);//灏忚溅杩佺Щ鐘舵��
                             }
 
-                            if (wrkMastMapper.updateById(wrkMast) > 0) {
-                                //涓嬪彂浠诲姟
-                                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
-                            }
-                        }else {
-                            //鐘舵��8锛屽洓鍚戠┛姊溅宸插湪鎻愬崌鏈哄彛锛岀瓑寰呭懡浠よ繘琛屽叆搴撴惉杩愬姩浣�
-                            Integer shuttleNo = wrkMast.getShuttleNo();//鍥涘悜绌挎杞﹀彿
-                            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
-                            if (shuttleThread == null) {
-                                continue;
-                            }
-                            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
-
-                            //鍒嗛厤鐩爣搴撲綅
-                            shuttleProtocol.setLocNo(wrkMast.getLocNo());
-
-                            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
-                            //鍥涘悜绌挎杞﹀彿
-                            assignCommand.setShuttleNo(shuttleNo.shortValue());
-                            //浠诲姟鍙�
-                            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
-                            //鍏ュ嚭搴撴ā寮�
-                            assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());
-                            //婧愬簱浣�(灏忚溅褰撳墠浣嶇疆)
-                            Short currentCode = shuttleProtocol.getCurrentCode();
-                            LocMast currentLocMast = locMastService.queryByQrCode(currentCode.toString());
-                            assignCommand.setSourceLocNo(currentLocMast.getLocNo());
-                            //鐩爣搴撲綅
-                            assignCommand.setDistLocNo(wrkMast.getLocNo());
-                            wrkMast.setWrkSts(9L);//灏忚溅鍏ュ簱涓�
                             if (wrkMastMapper.updateById(wrkMast) > 0) {
                                 //涓嬪彂浠诲姟
                                 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
@@ -745,9 +731,7 @@
                 continue;
             }
 
-            Short currentCode = shuttleProtocol.getCurrentCode();//鍥涘悜绌挎杞﹀綋鍓嶄綅缃簩缁寸爜
-            LocMast shuttleLocMast = locMastService.queryByQrCode(currentCode.toString());//鎵惧埌浜岀淮鐮佸搴旂殑搴撲綅璁板綍
-            String shuttleLocNo = shuttleLocMast.getLocNo();//浜岀淮鐮佸搴斿簱浣嶅彿
+            String shuttleLocNo = shuttleProtocol.getCurrentLocNo();//浜岀淮鐮佸搴斿簱浣嶅彿
             String shuttleLocNoLay = shuttleLocNo.substring(shuttleLocNo.length() - 2, shuttleLocNo.length());//搴撲綅鍙峰搴斿眰楂�
             if (lay.equals(shuttleLocNoLay)) {
                 //褰撳墠鍥涘悜绌挎杞﹀拰宸ヤ綔妗d换鍔″湪鍚屼竴灞傦紝鍒欒皟閰嶈杞﹁締
@@ -761,9 +745,7 @@
                 recentShuttle = shuttleThread;
             }else {
                 ShuttleProtocol recentShuttleProtocol = recentShuttle.getShuttleProtocol();//鐩墠鏈�杩戠┛姊溅
-                Short recentShuttleCurrentCode = recentShuttleProtocol.getCurrentCode();//鐩墠鏈�杩戠┛姊溅浣嶇疆浜岀淮鐮�
-                LocMast recentShuttleLocMast = locMastService.queryByQrCode(recentShuttleCurrentCode.toString());//鎵惧埌浜岀淮鐮佸搴旂殑搴撲綅璁板綍
-                String recentShuttleLocNo = recentShuttleLocMast.getLocNo();//浜岀淮鐮佸搴斿簱浣嶅彿
+                String recentShuttleLocNo = recentShuttleProtocol.getCurrentLocNo();//浜岀淮鐮佸搴斿簱浣嶅彿
                 String recentShuttleLocNoLay = recentShuttleLocNo.substring(recentShuttleLocNo.length() - 2, recentShuttleLocNo.length());//搴撲綅鍙峰搴斿眰楂�
 
                 int recentShuttleLocNoLayInt = Integer.parseInt(recentShuttleLocNoLay);
@@ -778,10 +760,23 @@
                     //妤煎眰鐩稿悓鎯呭喌
                     //鎵捐窛绂诲嚭搴撶偣鏈�杩戠殑杞�
 
+                    if (!(recentShuttleProtocol.isIdle() && shuttleProtocol.isIdle())) {
+                        //鍙鏈変竴杈嗚溅涓嶆槸绌洪棽鍒欎笉杩涜璋冨害
+                        map.put("sameLay", false);//涓嶅悓灞�
+                        map.put("result", null);
+                        return map;
+                    }
+
+                    //鑾峰彇鎻愬崌鏈�
+                    LiftSlave liftSlave = slaveProperties.getLift().get(0);
+                    //鎻愬崌鏈哄簱浣嶅彿
+                    String recentLiftLocNo = liftSlave.getLiftLocNo(recentShuttleLocNoLayInt);
+                    String shuttleLiftLocNo = liftSlave.getLiftLocNo(shuttleLocNoLayInt);
+
                     //褰撳墠鏈�杩戝洓鍚戠┛姊溅鍒版彁鍗囨満璺緞
-                    List<NavigateNode> recentShuttlePath = NavigateUtils.calc(recentShuttleLocNo, "1800201", ShuttleTaskModeType.PAK_IN.id);
+                    List<NavigateNode> recentShuttlePath = NavigateUtils.calc(recentShuttleLocNo, recentLiftLocNo, ShuttleTaskModeType.PAK_IN.id);
                     //褰撳墠妤煎眰鍥涘悜绌挎杞﹀埌鎻愬崌鏈鸿矾寰�
-                    List<NavigateNode> shuttlePath = NavigateUtils.calc(shuttleLocNo, "1800201", ShuttleTaskModeType.PAK_IN.id);
+                    List<NavigateNode> shuttlePath = NavigateUtils.calc(shuttleLocNo, shuttleLiftLocNo, ShuttleTaskModeType.PAK_IN.id);
                     //鍒ゆ柇鍝竴涓矾寰勬渶鐭�
                     if (shuttlePath.size() < recentShuttlePath.size()) {
                         //濡傛灉褰撳墠妤煎眰鐨勮溅璺緞鏇村皬锛屽垯鏇存柊鏈�杩戠┛姊溅
@@ -811,9 +806,18 @@
             //鍥涘悜绌挎杞︾姸鎬佷负绛夊緟纭
             if (shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.WAITING.id && shuttleProtocol.getTaskNo() != 0) {
                 //灏嗕换鍔℃。鏍囪涓哄畬鎴�
-                WrkMast wrkMast = wrkMastMapper.selectByWorkNo9(shuttleProtocol.getTaskNo().intValue());
+                WrkMast wrkMast = wrkMastMapper.selectByWorkNo59(shuttleProtocol.getTaskNo().intValue());
                 if (wrkMast != null) {
-                    wrkMast.setWrkSts(14L);
+                    switch (wrkMast.getWrkSts().intValue()) {
+                        case 9:
+                            wrkMast.setWrkSts(14L);
+                            break;
+                        case 5:
+                            wrkMast.setWrkSts(6L);
+                            break;
+                        default:
+                    }
+
                     if (wrkMastMapper.updateById(wrkMast) > 0) {
                         //璁剧疆鍥涘悜绌挎杞︿负绌洪棽鐘舵��
                         shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
@@ -825,7 +829,9 @@
                         shuttleProtocol.setLocNo(null);
                         //鏍囪澶嶄綅
                         shuttleProtocol.setPakMk(true);
-                        News.error("鍥涘悜绌挎杞﹀凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅銆傚爢鍨涙満鍙�={}", shuttleProtocol.getShuttleNo());
+                        //浠诲姟鎸囦护娓呴浂
+                        shuttleProtocol.setAssignCommand(null);
+                        News.info("鍥涘悜绌挎杞﹀凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅銆傚洓鍚戠┛姊溅鍙�={}", shuttleProtocol.getShuttleNo());
                     } else {
                         News.error("鍥涘悜绌挎杞﹀凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅澶辫触锛屼絾鏈壘鍒板伐浣滄。銆傚洓鍚戠┛姊溅鍙�={}锛屽伐浣滃彿={}", shuttleProtocol.getShuttleNo(), shuttleProtocol.getTaskNo());
                     }
@@ -836,6 +842,152 @@
     }
 
     /**
+     * 鎻愬崌鏈轰换鍔�
+     */
+    public synchronized void liftIoExecute() {
+        for (LiftSlave liftSlave : slaveProperties.getLift()) {
+            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId());
+            if (liftThread == null) {
+                continue;
+            }
+            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
+            if (liftProtocol == null) {
+                continue;
+            }
+
+            //鍒ゆ柇鎻愬崌鏈烘槸鍚﹀浜庣┖闂茬姸鎬�
+            if (!liftProtocol.isIdle()) {
+                continue;
+            }
+
+            //鎼滅储鏄惁鏈夊緟澶勭悊鐨勪换鍔�
+            WrkMast wrkMast = wrkMastMapper.selectLiftStep6();
+            if (wrkMast == null) {
+                continue;
+            }
+
+            //缁欐彁鍗囨満鍒嗛厤浠诲姟
+            liftProtocol.setLiftLock(true);//閿佸畾鎻愬崌鏈�
+            liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//璁剧疆浠诲姟鍙�
+            liftProtocol.setShuttleNo(wrkMast.getShuttleNo().shortValue());//璁剧疆鍥涘悜绌挎杞﹀彿
+            liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//璁剧疆鎻愬崌鏈虹姸鎬佷负宸ヤ綔涓�
+
+            //鎵惧埌鍥涘悜绌挎杞︾殑绾跨▼
+            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, liftProtocol.getShuttleNo().intValue());
+            if (shuttleThread == null) {
+                continue;
+            }
+            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+            if (shuttleProtocol == null) {
+                continue;
+            }
+
+            //鍛戒护list
+            ArrayList<LiftCommand> commands = new ArrayList<>();
+
+            //褰撳墠绌挎杞﹀簱浣嶅彿
+            String currentLocNo = shuttleProtocol.getCurrentLocNo();
+            //褰撳墠绌挎杞︽ゼ灞�
+            int currentLocNoLey = Integer.parseInt(currentLocNo.substring(currentLocNo.length() - 2, currentLocNo.length()));
+
+            //宸ヤ綔妗g洰鏍囧簱浣嶅彿
+            String wrkMastLocNo = wrkMast.getLocNo();
+            //宸ヤ綔妗g洰鏍囧簱浣嶆ゼ灞�
+            int wrkMastLocNoLey = Integer.parseInt(wrkMastLocNo.substring(wrkMastLocNo.length() - 2, wrkMastLocNo.length()));
+
+            //鎻愬崌鏈哄綋鍓嶆ゼ灞�
+            int liftLev = liftProtocol.getLev().intValue();
+            if (liftLev != currentLocNoLey) {
+                //涓嶅悓妤煎眰
+                LiftCommand command1 = new LiftCommand();
+                command1.setLiftNo(liftProtocol.getLiftNo());//鎻愬崌鏈哄彿
+                command1.setTaskNo(liftProtocol.getTaskNo());//浠诲姟鍙�
+                command1.setRun((short) 1);//鍗囬檷
+                command1.setDistPosition((short) currentLocNoLey);//鐩爣妤煎眰(绌挎杞︽墍鍦ㄦゼ灞�)
+                command1.setLiftLock(true);//閿佸畾鎻愬崌鏈�
+
+                commands.add(command1);//灏嗗懡浠ゆ坊鍔犺繘list
+            }
+
+            //杈撻�佺嚎灏嗗洓鍚戠┛姊溅绉诲姩杩涙潵
+            LiftCommand command2 = new LiftCommand();
+            command2.setLiftNo(liftProtocol.getLiftNo());//鎻愬崌鏈哄彿
+            command2.setTaskNo(liftProtocol.getTaskNo());//浠诲姟鍙�
+            command2.setRun((short) 6);//杈撻�佺嚎杩愪綔
+            command2.setLiftLock(true);//閿佸畾鎻愬崌鏈�
+
+            commands.add(command2);//灏嗗懡浠ゆ坊鍔犺繘list
+
+            //鎻愬崌鏈烘惉杩愬洓鍚戠┛姊溅
+            LiftCommand command3 = new LiftCommand();
+            command3.setLiftNo(liftProtocol.getLiftNo());//鎻愬崌鏈哄彿
+            command3.setTaskNo(liftProtocol.getTaskNo());//浠诲姟鍙�
+            command3.setRun((short) 1);//鍗囬檷
+            command3.setDistPosition((short) wrkMastLocNoLey);//宸ヤ綔妗g洰鏍囨ゼ灞�
+            command3.setLiftLock(true);//閿佸畾鎻愬崌鏈�
+
+            commands.add(command3);//灏嗗懡浠ゆ坊鍔犺繘list
+
+            //鎻愬崌鏈哄埌杈炬寚瀹氭ゼ灞傦紝杈撻�佺嚎灏嗗洓鍚戠┛姊溅绉诲嚭鍘�
+            //杈撻�佺嚎灏嗗洓鍚戠┛姊溅绉诲姩杩涙潵
+            LiftCommand command4 = new LiftCommand();
+            command4.setLiftNo(liftProtocol.getLiftNo());//鎻愬崌鏈哄彿
+            command4.setTaskNo(liftProtocol.getTaskNo());//浠诲姟鍙�
+            command4.setRun((short) 3);//杈撻�佺嚎杩愪綔
+            command4.setLiftLock(true);//閿佸畾鎻愬崌鏈�
+
+            commands.add(command4);//灏嗗懡浠ゆ坊鍔犺繘list
+
+            wrkMast.setWrkSts(7L);//绉诲姩浠诲姟
+            //鎵�闇�鍛戒护缁勫悎瀹屾瘯锛屾洿鏂版暟鎹簱锛屾彁浜ゅ埌绾跨▼鍘诲伐浣�
+            LiftAssignCommand assignCommand = new LiftAssignCommand();
+            assignCommand.setCommands(commands);
+            assignCommand.setLiftNo(liftProtocol.getLiftNo());
+            assignCommand.setTaskNo(liftProtocol.getTaskNo());
+            if (wrkMastMapper.updateById(wrkMast) > 0) {
+                //涓嬪彂浠诲姟
+                MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
+            }
+        }
+    }
+
+    /**
+     * 鎻愬崌鏈轰换鍔″畬鎴�
+     */
+    public synchronized void liftFinished() {
+        for (LiftSlave liftSlave : slaveProperties.getLift()) {
+            //鑾峰彇鎻愬崌鏈轰俊鎭�
+            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId());
+            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
+            if (liftProtocol == null) {
+                continue;
+            }
+
+            //鎻愬崌鏈轰负绛夊緟纭
+            if (liftProtocol.getProtocolStatus() == LiftProtocolStatusType.WAITING.id && liftProtocol.getTaskNo() != 0) {
+                //灏嗕换鍔℃。鏍囪涓哄畬鎴�
+                WrkMast wrkMast = wrkMastMapper.selectByWorkNo7(liftProtocol.getTaskNo().intValue());
+                if (wrkMast != null) {
+                    wrkMast.setWrkSts(8L);
+                    if (wrkMastMapper.updateById(wrkMast) > 0) {
+                        //璁剧疆鎻愬崌鏈轰负绌洪棽鐘舵��
+                        liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE);
+                        //浠诲姟鍙锋竻闆�
+                        liftProtocol.setTaskNo((short) 0);
+                        //鏍囪澶嶄綅
+                        liftProtocol.setPakMk(true);
+                        //浠诲姟鎸囦护娓呴浂
+                        liftProtocol.setAssignCommand(null);
+                        News.info("鎻愬崌鏈哄凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅銆傛彁鍗囨満鍙�={}", liftProtocol.getLiftNo());
+                    } else {
+                        News.error("鎻愬崌鏈哄凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅澶辫触锛屼絾鏈壘鍒板伐浣滄。銆傛彁鍗囨満鍙�={}锛屽伐浣滃彿={}", liftProtocol.getLiftNo(), liftProtocol.getTaskNo());
+                    }
+                }
+            }
+        }
+    }
+
+    /**
      * 鍏ュ嚭搴�  ===>>  鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂
      */
     public synchronized void crnIoExecute(){

--
Gitblit v1.9.1