From 87186c12f7c8864da8925aea3e91ecde1d16d255 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 03 十月 2023 14:35:53 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 1481 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 1,223 insertions(+), 258 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 f6980fd..4ecd592 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -2,6 +2,7 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.common.Cools;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
@@ -69,6 +70,8 @@
     @Autowired
     private BasShuttleErrLogService basShuttleErrLogService;
     @Autowired
+    private BasLiftErrLogService basLiftErrLogService;
+    @Autowired
     private BasShuttleErrService basShuttleErrService;
     @Autowired
     private BasCrnErrorMapper basCrnErrorMapper;
@@ -96,6 +99,9 @@
     private ShuttleDispatchUtils shuttleDispatchUtils;
     @Autowired
     private RedisUtil redisUtil;
+    @Autowired
+    private WrkMastLocMapper wrkMastLocMapper;
+
 
     /**
      * 缁勬墭
@@ -232,14 +238,14 @@
                             StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                             // plc 澶勭悊
                             barcodeThread.setBarcode("");
-                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
-                            staProtocol.setStaNo(dto.getStaNo().shortValue());
-                            devpThread.setPakMk(staProtocol.getSiteId(), false);
-
-                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
-                            if (!result) {
-                                throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
-                            }
+//                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
+//                            staProtocol.setStaNo(dto.getStaNo().shortValue());
+//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
+//
+//                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+//                            if (!result) {
+//                                throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
+//                            }
 
                             // 鍒ゆ柇閲嶅宸ヤ綔妗�
                             WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo());
@@ -261,10 +267,10 @@
                             }
                             News.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                         } else if (code == 700) {
-                            staProtocol.setWorkNo((short) 32002);
-                            staProtocol.setRollback102(1);//102绔欏洖閫�淇″彿
-                            devpThread.setPakMk(staProtocol.getSiteId(), false);
-                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, staProtocol));
+//                            staProtocol.setWorkNo((short) 32002);
+//                            staProtocol.setRollback102(1);//102绔欏洖閫�淇″彿
+//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
+//                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, staProtocol));
 
                             // led 寮傚父鏄剧ず
                             if (ledThread != null) {
@@ -635,11 +641,11 @@
                 }
 
                 Short shuttleNo = redisCommand.getShuttleNo();
-                ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo.intValue());
+                NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo.intValue());
                 if (shuttleThread == null) {
                     continue;
                 }
-                ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+                NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
                 if (shuttleProtocol == null) {
                     continue;
                 }
@@ -648,7 +654,7 @@
                 }
 
                 //鍥涘悜绌挎杞﹀浜庣┖闂茬姸鎬侊紝杩涜浠诲姟鐨勬仮澶�
-                shuttleProtocol.setTaskNo(redisCommand.getWrkNo());//灏嗗洓鍚戠┛姊溅绾跨▼鍒嗛厤浠诲姟鍙�
+                shuttleProtocol.setTaskNo(redisCommand.getWrkNo().intValue());//灏嗗洓鍚戠┛姊溅绾跨▼鍒嗛厤浠诲姟鍙�
                 shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);//宸ヤ綔鐘舵��
             }
         }
@@ -659,6 +665,34 @@
      * 鍏ュ簱  ===>>  鍥涘悜绌挎杞﹀叆搴撲綔涓氫笅鍙�
      */
     public synchronized void shuttleInExecute() {
+        List<WrkMast> wrkMasts = wrkMastMapper.selectInStep4();
+        for (WrkMast wrkMast : wrkMasts) {
+            //鑾峰彇婧愮珯
+            BasDevp sourceBasDevp = basDevpService.selectById(wrkMast.getSourceStaNo());
+            if (sourceBasDevp == null) {
+                continue;//绔欑偣涓嶅瓨鍦�
+            }
+
+            //鑾峰彇鐩爣绔�
+            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(sourceBasDevp.getLiftNo(), Utils.getLev(wrkMast.getLocNo()));
+            if (liftStaProtocol == null) {
+                continue;//绔欑偣涓嶅瓨鍦�
+            }
+
+            // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢锛岃嚜鍔ㄣ�佺┖闂层�佹湁鐗�
+            if (!(liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && liftStaProtocol.getHasTray())) {
+                continue;
+            }
+
+            boolean step1 = this.shuttleInExecuteStep1(wrkMast, liftStaProtocol);//灏忚溅鎼叆搴撲腑
+            if (!step1) {
+                continue;
+            }
+        }
+
+
+
+
         // 鏍规嵁杈撻�佺嚎plc閬嶅巻
         for (DevpSlave devp : slaveProperties.getDevp()) {
             // 閬嶅巻鍏ュ簱绔�
@@ -682,30 +716,64 @@
                     continue;
                 }
 
-                WrkMast wrkMast = wrkMastMapper.selectRackInStep4(workNo, staProtocol.getSiteId());
-                if (wrkMast == null) {
-                    continue;
-                }
 
-                boolean step1 = this.shuttleInExecuteStep1(wrkMast, basDevp);//灏忚溅鎼叆搴撲腑
-                if (!step1) {
-                    continue;
-                }
 
             }
         }
 
     }
 
+//    /**
+//     * 鍏ュ簱  ===>>  鍥涘悜绌挎杞﹀叆搴撲綔涓氫笅鍙�
+//     */
+//    public synchronized void shuttleInExecute() {
+//        // 鏍规嵁杈撻�佺嚎plc閬嶅巻
+//        for (DevpSlave devp : slaveProperties.getDevp()) {
+//            // 閬嶅巻鍏ュ簱绔�
+//            for (DevpSlave.StaRack staRack : devp.getRackInStn()) {
+//                // 鑾峰彇鍏ュ簱绔欎俊鎭�
+//                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+//                StaProtocol staProtocol = devpThread.getStation().get(staRack.getStaNo());
+//                if (staProtocol == null) {
+//                    continue;
+//                } else {
+//                    staProtocol = staProtocol.clone();
+//                }
+//                Short workNo = staProtocol.getWorkNo();
+//                BasDevp basDevp = basDevpService.selectById(staProtocol.getSiteId());
+//                if (basDevp == null) {
+//                    continue;//绔欑偣淇℃伅涓嶅瓨鍦�
+//                }
+//
+//                // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢锛岃嚜鍔ㄣ�佹湁鐗┿�佸洓鍚戠┛姊溅鍙彇淇″彿
+//                if (!(staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isShuttleTakeEnable())) {
+//                    continue;
+//                }
+//
+//                WrkMast wrkMast = wrkMastMapper.selectRackInStep4(workNo, staProtocol.getSiteId());
+//                if (wrkMast == null) {
+//                    continue;
+//                }
+//
+//                boolean step1 = this.shuttleInExecuteStep1(wrkMast, basDevp);//灏忚溅鎼叆搴撲腑
+//                if (!step1) {
+//                    continue;
+//                }
+//
+//            }
+//        }
+//
+//    }
+
     /**
      * 鍏ュ簱-灏忚溅鎼叆搴撲腑
      * 濡傞渶涓绘柟娉曟墽琛宑ontinue锛岃杩斿洖false
      * ps:杩斿洖鍊紅rue骞朵笉浠h〃璇ユ柟娉曟墽琛屾垚鍔燂紝杩斿洖鍊间粎鍋氭爣璁扮敤浜庝富鏂规硶鏄惁鎵цcontinue
      */
-    public boolean shuttleInExecuteStep1(WrkMast wrkMast, BasDevp basDevp) {
+    public boolean shuttleInExecuteStep1(WrkMast wrkMast, LiftStaProtocol liftStaProtocol) {
         if (wrkMast.getWrkSts() == 4) {
             if (wrkMast.getShuttleNo() == null) {//娌℃湁缁戝畾灏忚溅锛岃繘琛岃皟搴�
-                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐�
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), liftStaProtocol.getLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐�
                 return false;
             }
 
@@ -721,16 +789,26 @@
             if (!shuttleProtocol.isIdle()) {
                 return false;
             }
+            //鍒ゆ柇灏忚溅浠ょ墝鏄惁鏈鍗犻
+            if (shuttleProtocol.getToken() != 0) {
+                return false;//灏忚溅宸茶鐙崰锛岀姝㈠啀娲惧彂浠诲姟
+            }
+
+            //鍒ゆ柇灏忚溅鏄惁瀛樺湪绉诲姩浠诲姟
+            WrkMast hasMoveWorking = wrkMastMapper.selectShuttleHasMoveWorking(wrkMast.getShuttleNo());
+            if (hasMoveWorking != null) {
+                return false;//瀛樺湪绉诲姩浠诲姟锛岀姝㈡墽琛屽叆搴撲换鍔�
+            }
 
             //鍒ゆ柇灏忚溅鏄惁鍒拌揪杈撻�佺珯鐐瑰簱浣�
-            if (!shuttleProtocol.getCurrentLocNo().equals(basDevp.getLocNo())) {
+            if (!shuttleProtocol.getCurrentLocNo().equals(liftStaProtocol.getLocNo())) {
                 //灏忚溅涓嶅湪杈撻�佺珯鐐逛綅缃�
-                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐�
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), liftStaProtocol.getLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐�
                 return false;
             }
 
             //灏忚溅宸叉姷杈捐緭閫佺珯鐐逛綅缃紝杩涜鎼繍璐х墿
-            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), basDevp.getLocNo(), wrkMast.getLocNo());
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo());
             if (result == null) {//璺緞璁$畻澶辫触
                 return false;
             }
@@ -746,6 +824,7 @@
 
             wrkMast.setWrkSts(5L);//4.鎻愬崌鏈烘惉杩愬畬鎴� => 5.灏忚溅鎼繍涓�
             wrkMast.setModiTime(new Date());
+            shuttleProtocol.setToken(wrkMast.getWrkNo());//鐙崰灏忚溅浠ょ墝
             if (wrkMastMapper.updateById(wrkMast) > 0) {
                 //涓嬪彂浠诲姟
                 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
@@ -776,6 +855,34 @@
     public boolean shuttleOutExecuteStep1(WrkMast wrkMast) {
         //21.鐢熸垚鍑哄簱浠诲姟 => 22.灏忚溅鎼繍涓�
         if (wrkMast.getWrkSts() == 21) {
+            EntityWrapper<StaDesc> wrapper = new EntityWrapper<>();
+            wrapper.eq("type_no", wrkMast.getIoType());//璺緞绫诲瀷
+            wrapper.eq("stn_no", wrkMast.getStaNo());//鍑哄簱绔欑偣缂栧彿
+            StaDesc staDesc = staDescService.selectOne(wrapper);
+            if (staDesc == null) {
+                return false;//鍑哄簱璺緞涓嶅瓨鍦�
+            }
+
+            //鑾峰彇鍑哄簱绔欑偣
+            BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo());
+            if (basDevp == null) {
+                return false;//鍑哄簱绔欑偣涓嶅瓨鍦�
+            }
+
+            if (!basDevp.getOutEnable().equals("Y")) {
+                return false;//鍑哄簱绔欑偣涓嶅彲鍑�
+            }
+
+            //鑾峰彇婧愮珯
+            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(basDevp.getLiftNo(), Utils.getLev(wrkMast.getSourceLocNo()));
+            if (liftStaProtocol == null) {
+                return false;//鎵句笉鍒扮珯鐐�
+            }
+
+            if (!(liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && !liftStaProtocol.getHasTray())) {
+                return false;//绔欑偣蹇呴』鑷姩銆佺┖闂层�佹病鏈夋墭鐩�
+            }
+
             if (wrkMast.getShuttleNo() == null) {//娌℃湁缁戝畾灏忚溅锛岃繘琛岃皟搴�
                 shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄥ簱浣嶈繘琛屽彇璐�
                 return false;
@@ -793,22 +900,20 @@
             if (!shuttleProtocol.isIdle()) {
                 return false;
             }
-
-            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
-            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getLiftNo());
-            if (targetBasDevp == null) {
-                return false;//缂哄皯绔欑偣淇℃伅
+            //鍒ゆ柇灏忚溅浠ょ墝鏄惁鏈鍗犻
+            if (shuttleProtocol.getToken() != 0) {
+                return false;//灏忚溅宸茶鐙崰锛岀姝㈠啀娲惧彂浠诲姟
             }
 
             //鍒ゆ柇灏忚溅鏄惁鍒拌揪璐х墿搴撲綅
             if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
                 //灏忚溅涓嶅湪杈撻�佺珯鐐逛綅缃�
-                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐�
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄥ簱浣嶈繘琛屽彇璐�
                 return false;
             }
 
             //灏忚溅宸叉姷杈捐揣鐗╀綅缃紝杩涜鎼繍璐х墿
-            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), targetBasDevp.getLocNo());
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), liftStaProtocol.getLocNo());//灏嗚揣鐗╂惉杩愯嚦鎻愬崌鏈鸿緭閫佺珯鐐�
             if (result == null) {//鍑哄簱璺緞璁$畻澶辫触
                 return false;
             }
@@ -824,6 +929,7 @@
 
             wrkMast.setWrkSts(22L);//21.鐢熸垚鍑哄簱浠诲姟 => 22.灏忚溅鎼繍涓�
             wrkMast.setModiTime(new Date());
+            shuttleProtocol.setToken(wrkMast.getWrkNo());//鐙崰灏忚溅浠ょ墝
             if (wrkMastMapper.updateById(wrkMast) > 0) {
                 //涓嬪彂浠诲姟
                 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
@@ -846,35 +952,65 @@
             }
 
             //鍥涘悜绌挎杞︾姸鎬佷负绛夊緟纭銆佸皬杞﹀浜庣┖闂茬姸鎬�
+
+
             if (shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.WAITING.id  //浠诲姟瀹屾垚绛夊緟纭
                     && shuttleProtocol.getTaskNo() != 0
                     && shuttleProtocol.getFree() == ShuttleStatusType.IDLE.id
             ) {
                 //灏嗕换鍔℃。鏍囪涓哄畬鎴�
-                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(shuttleProtocol.getTaskNo().intValue());
+                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(shuttleProtocol.getTaskNo());
                 if (wrkMast != null) {
                     switch (wrkMast.getWrkSts().intValue()) {
                         case 5://5.灏忚溅鎼繍涓� ==> 9.鍏ュ簱瀹屾垚
                             wrkMast.setWrkSts(9L);
-                            //浠诲姟鍙锋竻闆�
                             shuttleProtocol.setTaskNo(0);
+                            if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
+                                //閲婃斁灏忚溅浠ょ墝
+                                shuttleProtocol.setToken(0);
+                            }
                             break;
                         case 22://22.灏忚溅鎼繍涓� ==> 23.灏忚溅鎼繍瀹屾垚
                             wrkMast.setWrkSts(23L);
+                            shuttleProtocol.setTaskNo(0);
+                            if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
+                                //閲婃斁灏忚溅浠ょ墝
+                                shuttleProtocol.setToken(0);
+                            }
                             break;
-                        case 102://102.灏忚溅鍒版彁鍗囨満涓� ==> 103.灏忚溅鍒版彁鍗囨満瀹屾垚
+                        case 102://102.灏忚溅绉诲姩鑷崇珯鐐� ==> 103.灏忚溅绉诲姩鑷崇珯鐐瑰畬鎴�
                             wrkMast.setWrkSts(103L);
                             break;
-                        case 106://106.灏忚溅杩佸嚭鎻愬崌鏈轰腑 ==> 107.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴�
-                            wrkMast.setWrkSts(107L);
+                        case 104://104.灏忚溅杩佸叆鎻愬崌鏈轰腑 ==> 105.灏忚溅杩佸叆鎻愬崌鏈哄畬鎴�
+                            wrkMast.setWrkSts(105L);
+                            shuttleProtocol.setTaskNo(0);//娓呯悊宸ヤ綔鍙�
                             break;
-                        case 108://108.灏忚溅绉诲姩涓� ==> 109.灏忚溅绉诲姩瀹屾垚
+                        case 108://108.灏忚溅杩佸嚭鎻愬崌鏈轰腑 ==> 109.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴�
                             wrkMast.setWrkSts(109L);
+                            break;
+                        case 110://110.灏忚溅绉诲姩涓� ==> 111.灏忚溅绉诲姩瀹屾垚
+                            wrkMast.setWrkSts(111L);
+                            shuttleProtocol.setTaskNo(0);
+                            if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
+                                //閲婃斁灏忚溅浠ょ墝
+                                shuttleProtocol.setToken(0);
+                            }
                             break;
                         default:
                     }
 
                     if (wrkMastMapper.updateById(wrkMast) > 0) {
+                        if (wrkMast.getWrkSts() == 111) {
+                            // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
+                            if (wrkMastLocMapper.save(wrkMast.getWrkNo()) <= 0) {
+                                log.info("淇濆瓨宸ヤ綔鍘嗗彶妗workNo={0}]澶辫触", wrkMast.getWrkNo());
+                            }
+                            // 鍒犻櫎宸ヤ綔涓绘。
+                            if (!wrkMastService.deleteById(wrkMast)) {
+                                log.info("鍒犻櫎宸ヤ綔涓绘。[workNo={0}]澶辫触", wrkMast.getWrkNo());
+                            }
+                        }
+
                         //璁剧疆鍥涘悜绌挎杞︿负绌洪棽鐘舵��
                         shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                         //婧愬簱浣嶆竻闆�
@@ -886,6 +1022,24 @@
                         News.info("鍥涘悜绌挎杞﹀凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅銆傚洓鍚戠┛姊溅鍙�={}", shuttleProtocol.getShuttleNo());
                     } else {
                         News.error("鍥涘悜绌挎杞﹀凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅澶辫触锛屼絾鏈壘鍒板伐浣滄。銆傚洓鍚戠┛姊溅鍙�={}锛屽伐浣滃彿={}", shuttleProtocol.getShuttleNo(), shuttleProtocol.getTaskNo());
+                    }
+                }else {
+                    ShuttleAssignCommand assignCommand = shuttleProtocol.getAssignCommand();
+                    if (!assignCommand.getAuto()) {
+                        //鎵嬪姩妯″紡
+                        //宸ヤ綔鍙锋竻闆�
+                        shuttleProtocol.setTaskNo(0);
+                        //璁剧疆鍥涘悜绌挎杞︿负绌洪棽鐘舵��
+                        shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+                        //婧愬簱浣嶆竻闆�
+                        shuttleProtocol.setSourceLocNo(null);
+                        //鐩爣搴撲綅娓呴浂
+                        shuttleProtocol.setLocNo(null);
+                        //浠诲姟鎸囦护娓呴浂
+                        shuttleProtocol.setAssignCommand(null);
+                        //娓呴浂浠ょ墝
+                        shuttleProtocol.setToken(0);
+                        News.info("鍥涘悜绌挎杞﹀凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅銆傚洓鍚戠┛姊溅鍙�={}", shuttleProtocol.getShuttleNo());
                     }
                 }
 
@@ -909,6 +1063,11 @@
             }
 
             if (!liftProtocol.isIdle()) {
+                continue;
+            }
+
+            //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚﹁鍗犵敤
+            if (liftProtocol.getToken() != 0) {
                 continue;
             }
 
@@ -950,7 +1109,17 @@
 
         //2.璁惧涓婅蛋 ==> 3.鎻愬崌鏈烘惉杩愪腑
         if (wrkMast.getWrkSts() == 2) {
-            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
+            //鑾峰彇婧愮珯
+            BasDevp sourceBasDevp = basDevpService.selectById(wrkMast.getSourceStaNo());
+            if (sourceBasDevp == null) {
+                return false;//鎵句笉鍒扮珯鐐�
+            }
+
+            if (!sourceBasDevp.getInEnable().equals("Y")) {
+                return false;//绔欑偣涓嶅彲鍏�
+            }
+
+            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, sourceBasDevp.getLiftNo());
             if (liftThread == null) {
                 return false;
             }
@@ -958,26 +1127,46 @@
             if (liftProtocol == null) {
                 return false;
             }
-            if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
+            if (!liftProtocol.isIdle()) {
                 return false;
             }
+            //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚︽湭琚崰棰�
+            if (liftProtocol.getToken() != 0) {
+                return false;//鎻愬崌鏈哄凡琚嫭鍗狅紝绂佹鍐嶆淳鍙戜换鍔�
+            }
+
+            //鍒ゆ柇鎻愬崌鏈哄唴鏄惁鏈夊皬杞�
+            if (liftProtocol.getHasCar()) {
+                return false;//鏈夊皬杞︼紝绂佹娲惧彂
+            }
+
+            //鍒ゆ柇鎻愬崌鏈哄唴鏄惁鏈夋墭鐩�
+            if (liftProtocol.getHasTray()) {
+                return false;//鏈夋墭鐩橈紝绂佹娲惧彂
+            }
+
             //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟
             WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId());
             if (liftWrkMast != null) {
                 return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇�
             }
 
-            //鑾峰彇婧愮珯瀵瑰簲鐨勮緭閫佺珯鐐�
-            BasDevp sourceBasDevp = basDevpService.selectById(wrkMast.getSourceStaNo());
-            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
-            BasDevp targetBasDevp = basDevpService.selectById(wrkMast.getStaNo());
-            if (sourceBasDevp == null || targetBasDevp == null) {
-                return false;//缂哄皯绔欑偣淇℃伅
+            //鑾峰彇婧愮珯瀵瑰簲鐨勭墰鐪兼彁鍗囨満绔欑偣缂栧彿(璧风偣缂栧彿)
+            Integer startSta = Integer.parseInt(sourceBasDevp.getQrCodeValue());
+            //鑾峰彇鎻愬崌鏈虹珯鐐�
+            LiftStaProtocol targetStaProtocol = NyLiftUtils.getLiftStaByLev(liftThread.getSlave().getId(), Utils.getLev(wrkMast.getLocNo()));
+            if (targetStaProtocol == null) {
+                return false;//绔欑偣涓嶅瓨鍦�
             }
 
-            //鑾峰彇鎻愬崌鏈哄懡浠�
-            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), wrkMast.getWrkNo());
+            if (targetStaProtocol.getHasTray()) {
+                return false;//鎻愬崌鏈虹珯鐐规湁鎵樼洏锛岀姝㈡淳鍙�
+            }
 
+            Integer targetSta = targetStaProtocol.getStaNo();
+
+            //鑾峰彇鎻愬崌鏈哄懡浠�
+            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, startSta, targetSta, wrkMast.getWrkNo());
             ArrayList<NyLiftCommand> commands = new ArrayList<>();
             commands.add(liftCommand);
 
@@ -991,6 +1180,7 @@
             wrkMast.setWrkSts(3L);//2.璁惧涓婅蛋 ==> 3.鎻愬崌鏈烘惉杩愪腑
             wrkMast.setLiftNo(liftThread.getSlave().getId());//浠诲姟妗g粦瀹氭彁鍗囨満鍙�
             wrkMast.setModiTime(now);
+            liftProtocol.setToken(wrkMast.getWrkNo());//鐙崰鎻愬崌鏈轰护鐗�
             if (wrkMastMapper.updateById(wrkMast) > 0) {
                 //涓嬪彂浠诲姟
                 MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
@@ -1012,7 +1202,28 @@
 
         //23.灏忚溅鎼繍瀹屾垚 ==> 24.鎻愬崌鏈烘惉杩愪腑
         if (wrkMast.getWrkSts() == 23) {
-            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
+            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
+            if (shuttleThread == null) {
+                return false;
+            }
+
+            //璋冨害灏忚溅閬胯
+            boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getShuttleNo(), shuttleThread);
+            if (!result) {
+                return false;
+            }
+
+            //鑾峰彇鍑哄簱绔欑偣(鐩爣绔�)
+            BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo());
+            if (basDevp == null) {
+                return false;//鍑哄簱绔欑偣涓嶅瓨鍦�
+            }
+
+            if (!basDevp.getOutEnable().equals("Y")) {
+                return false;//鍑哄簱绔欑偣涓嶅彲鍑�
+            }
+
+            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, basDevp.getLiftNo());
             if (liftThread == null) {
                 return false;
             }
@@ -1020,8 +1231,12 @@
             if (liftProtocol == null) {
                 return false;
             }
-            if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
+            if (!liftProtocol.isIdle()) {
                 return false;
+            }
+            //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚︽湭琚崰棰�
+            if (liftProtocol.getToken() != 0) {
+                return false;//鎻愬崌鏈哄凡琚嫭鍗狅紝绂佹鍐嶆淳鍙戜换鍔�
             }
             //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟
             WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId());
@@ -1029,16 +1244,23 @@
                 return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇�
             }
 
-            //鑾峰彇婧愮珯瀵瑰簲鐨勮緭閫佺珯鐐�
-            BasDevp sourceBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getSourceLocNo()), liftProtocol.getLiftNo().intValue());
-            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
-            BasDevp targetBasDevp = basDevpService.selectById(wrkMast.getSourceStaNo());
-            if (sourceBasDevp == null || targetBasDevp == null) {
-                return false;//缂哄皯绔欑偣淇℃伅
+            //鑾峰彇婧愮珯瀵瑰簲鐨勭墰鐪兼彁鍗囨満绔欑偣缂栧彿(璧风偣缂栧彿)
+            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(liftThread.getSlave().getId(), Utils.getLev(wrkMast.getSourceLocNo()));
+            if (liftStaProtocol == null) {
+                return false;//鎵句笉鍒扮珯鐐�
             }
+            Integer startSta = liftStaProtocol.getStaNo();
+
+            //鑾风洰鏍囩珯婧愮珯瀵瑰簲鐨勮緭閫佺珯鐐�
+            BasDevp targetBasDevp = basDevpService.selectById(wrkMast.getStaNo());
+            if (targetBasDevp == null) {
+                return false;//绔欑偣涓嶅瓨鍦�
+            }
+            //鑾峰彇鐗涚溂鎻愬崌鏈虹珯鐐圭紪鍙�(鐩爣缂栧彿)
+            Integer targetSta = Integer.parseInt(targetBasDevp.getQrCodeValue());
 
             //鑾峰彇鎻愬崌鏈哄懡浠�
-            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), wrkMast.getWrkNo());
+            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftThread.getSlave().getId(), NyLiftTaskModelType.MOVE_TRAY.id, startSta, targetSta, wrkMast.getWrkNo());
 
             ArrayList<NyLiftCommand> commands = new ArrayList<>();
             commands.add(liftCommand);
@@ -1053,6 +1275,7 @@
             wrkMast.setWrkSts(24L);//23.灏忚溅鎼繍瀹屾垚 ==> 24.鎻愬崌鏈烘惉杩愪腑
             wrkMast.setLiftNo(liftThread.getSlave().getId());//浠诲姟妗g粦瀹氭彁鍗囨満鍙�
             wrkMast.setModiTime(now);
+            liftProtocol.setToken(wrkMast.getWrkNo());//鐙崰鎻愬崌鏈轰护鐗�
             if (wrkMastMapper.updateById(wrkMast) > 0) {
                 //涓嬪彂浠诲姟
                 MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
@@ -1080,7 +1303,6 @@
                     && liftProtocol.getTaskNo() != 0
                     && !liftProtocol.getBusy()
             ) {
-
                 //灏嗕换鍔℃。鏍囪涓哄畬鎴�
                 WrkMast wrkMast = wrkMastMapper.selectByWorkNo324104(liftProtocol.getTaskNo().intValue());
                 if (wrkMast != null) {
@@ -1088,12 +1310,29 @@
                         case 3://3.鎻愬崌鏈烘惉杩愪腑 ==> 4.鎻愬崌鏈烘惉杩愬畬鎴�
                             wrkMast.setWrkSts(4L);
                             wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈�
+                            if (liftProtocol.getToken().equals(wrkMast.getWrkNo())) {
+                                //閲婃斁鎻愬崌鏈轰护鐗�
+                                liftProtocol.setToken(0);
+                            }
                             break;
                         case 24://24.鎻愬崌鏈烘惉杩愪腑 ==> 25.鎻愬崌鏈烘惉杩愬畬鎴�
                             wrkMast.setWrkSts(25L);
+                            if (wrkMast.getIoType() == 11) {//搴撲綅绉昏浆
+                                wrkMast.setWrkSts(4L);//4.鎻愬崌鏈烘惉杩愬畬鎴�
+                            }
+                            if (liftProtocol.getToken().equals(wrkMast.getWrkNo())) {
+                                //閲婃斁鎻愬崌鏈轰护鐗�
+                                liftProtocol.setToken(0);
+                            }
+
+                            if (wrkMast.getMk() == null || !wrkMast.getMk().equals("Y")) {
+                                //涓嶉渶瑕佺敤鍒版満姊拌噦锛岀洿鎺ヨ浆29.鍑哄簱瀹屾垚
+                                wrkMast.setWrkSts(29L);
+                            }
+
                             break;
-                        case 104://104.鎻愬崌鏈烘惉杩愪腑 ==> 105.鎻愬崌鏈烘惉杩愬畬鎴�
-                            wrkMast.setWrkSts(105L);
+                        case 106://106.鎻愬崌鏈烘惉杩愪腑 ==> 107.鎻愬崌鏈烘惉杩愬畬鎴�
+                            wrkMast.setWrkSts(107L);
                             break;
                         default:
                     }
@@ -1107,8 +1346,19 @@
                     } else {
                         News.error("鎻愬崌鏈哄凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅澶辫触锛屼絾鏈壘鍒板伐浣滄。銆傛彁鍗囨満鍙�={}锛屽伐浣滃彿={}", liftProtocol.getLiftNo(), liftProtocol.getTaskNo());
                     }
+                }else {
+                    LiftAssignCommand assignCommand = liftProtocol.getAssignCommand();
+                    if (assignCommand != null) {
+                        if (!assignCommand.getAuto()) {
+                            //鎵嬪姩鎿嶄綔
+                            //璁剧疆鎻愬崌鏈轰负绌洪棽鐘舵��
+                            liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE);
+                            //浠诲姟鎸囦护娓呴浂
+                            liftProtocol.setAssignCommand(null);
+                            News.info("鎻愬崌鏈哄凡纭鎵嬪姩鎿嶄綔銆傛彁鍗囨満鍙�={}", liftProtocol.getLiftNo());
+                        }
+                    }
                 }
-
             }
         }
     }
@@ -1127,67 +1377,288 @@
         //鏌ヨ搴撲綅绉昏浆宸ヤ綔妗�
         List<WrkMast> wrkMasts1 = wrkMastMapper.selectLocToLocWrkMast();
         for (WrkMast wrkMast : wrkMasts1) {
-            boolean step1 = this.locToLocExecuteStep1(wrkMast);//搴撲綅绉昏浆
-            if (!step1) {
-                continue;
+            if (Utils.getLev(wrkMast.getSourceLocNo()) == Utils.getLev(wrkMast.getLocNo())) {
+                boolean step1 = this.locToLocExecuteStep1(wrkMast);//鍚屾ゼ灞傚簱浣嶇Щ杞�
+                if (!step1) {
+                    continue;
+                }
+            }else {
+                //璺ㄦゼ灞傚簱浣嶇Щ杞�
+                boolean step2 = this.locToLocExecuteStep2(wrkMast);//璋冨害杞﹁締鍙栬揣骞惰繍閫佸埌鍑哄簱鍙�
+                if (!step2) {
+                    continue;
+                }
+
+                boolean step3 = this.locToLocExecuteStep3(wrkMast);//鎻愬崌鏈烘惉杩愯揣鐗�
+                if (!step3) {
+                    continue;
+                }
+
+                boolean step4 = this.locToLocExecuteStep4(wrkMast);//璋冨害杞﹁締鍙栬揣骞惰繍閫佸埌鍑哄簱鍙�
+                if (!step4) {
+                    continue;
+                }
+
             }
 
         }
     }
 
     /**
-     * 搴撲綅绉昏浆
+     * 鍚屾ゼ灞傚簱浣嶇Щ杞�
      * 濡傞渶涓绘柟娉曟墽琛宑ontinue锛岃杩斿洖false
      * ps:杩斿洖鍊紅rue骞朵笉浠h〃璇ユ柟娉曟墽琛屾垚鍔燂紝杩斿洖鍊间粎鍋氭爣璁扮敤浜庝富鏂规硶鏄惁鎵цcontinue
      */
     private boolean locToLocExecuteStep1(WrkMast wrkMast) {
-        if (wrkMast.getShuttleNo() == null) {
-            shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//璋冨害灏忚溅鍒版簮搴撲綅杩涜鍙栬揣
+        if (wrkMast.getWrkSts() == 21) {//21.鐢熸垚鍑哄簱浠诲姟
+            if (wrkMast.getShuttleNo() == null) {
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//璋冨害灏忚溅鍒版簮搴撲綅杩涜鍙栬揣
+                return false;
+            }
+
+            //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
+            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
+            if (shuttleThread == null) {
+                return false;
+            }
+            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+            if (shuttleProtocol == null) {
+                return false;
+            }
+            if (!shuttleProtocol.isIdle()) {
+                return false;
+            }
+
+            //鍒ゆ柇灏忚溅鏄惁鍒拌揪婧愬簱浣�
+            if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
+                //灏忚溅涓嶅湪婧愬簱浣嶄綅缃�
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒版簮搴撲綅杩涜鍙栬揣
+                return false;
+            }
+
+            //灏忚溅宸叉姷杈炬簮搴撲綅锛岃繘琛屾惉杩愯揣鐗�
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getLocNo());
+            if (result == null) {//璺緞璁$畻澶辫触
+                return false;
+            }
+
+            //鍒涘缓鍒嗛厤鍛戒护
+            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
+            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//鍥涘悜绌挎杞﹀彿
+            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//浠诲姟鍙�
+            assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());//鍏ュ簱妯″紡
+            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//婧愬簱浣�(灏忚溅褰撳墠浣嶇疆)
+            assignCommand.setCommands(result.getCommands());//杩愯鍛戒护
+            assignCommand.setNodes(result.getNodes());//璺緞鑺傜偣
+
+            wrkMast.setWrkSts(5L);//21.鐢熸垚鍑哄簱浠诲姟 => 5.灏忚溅鎼繍涓�
+            wrkMast.setModiTime(new Date());
+            if (wrkMastMapper.updateById(wrkMast) > 0) {
+                //涓嬪彂浠诲姟
+                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
+            }
+
             return false;
         }
+        return true;
+    }
 
-        //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
-        NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
-        if (shuttleThread == null) {
+    /**
+     * 璺ㄦゼ灞傚簱浣嶇Щ杞�-璋冨害杞﹁締鍙栬揣骞惰繍閫佸埌鍑哄簱鍙�
+     * 濡傞渶涓绘柟娉曟墽琛宑ontinue锛岃杩斿洖false
+     * ps:杩斿洖鍊紅rue骞朵笉浠h〃璇ユ柟娉曟墽琛屾垚鍔燂紝杩斿洖鍊间粎鍋氭爣璁扮敤浜庝富鏂规硶鏄惁鎵цcontinue
+     */
+    private boolean locToLocExecuteStep2(WrkMast wrkMast) {
+        if (wrkMast.getWrkSts() == 21) {//21.鐢熸垚鍑哄簱浠诲姟
+            if (wrkMast.getShuttleNo() == null) {
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//璋冨害灏忚溅鍒版簮搴撲綅杩涜鍙栬揣
+                return false;
+            }
+
+            //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
+            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
+            if (shuttleThread == null) {
+                return false;
+            }
+            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+            if (shuttleProtocol == null) {
+                return false;
+            }
+            if (!shuttleProtocol.isIdle()) {
+                return false;
+            }
+
+            //鍒ゆ柇灏忚溅鏄惁鍒拌揪婧愬簱浣�
+            if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
+                //灏忚溅涓嶅湪婧愬簱浣嶄綅缃�
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒版簮搴撲綅杩涜鍙栬揣
+                return false;
+            }
+
+            //鑾峰彇绌挎杞︽渶杩戜笖绌洪棽鐨勬彁鍗囨満杈撻�佺珯鐐�
+            LiftStaProtocol liftSta = shuttleDispatchUtils.getRecentLiftSta(shuttleThread.getSlave().getId());
+            if (liftSta == null) {
+                return false;//娌℃湁鍙敤涓旂┖闂茬殑杈撻�佺珯鐐�
+            }
+            //婧愮珯
+            Integer sourceStaNo = liftSta.getStaNo();
+            //鎻愬崌鏈哄彿*100+鐩爣妤煎眰=鐩爣绔欑偣
+            Integer staNo = liftSta.getLiftNo() * 100 + Utils.getLev(wrkMast.getLocNo());//鐩爣绔�
+
+            //灏忚溅宸叉姷杈炬簮搴撲綅锛屽皢璐х墿鎼繍鍒拌緭閫佺珯鐐�
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), liftSta.getLocNo());
+            if (result == null) {//璺緞璁$畻澶辫触
+                return false;
+            }
+
+            //鍒涘缓鍒嗛厤鍛戒护
+            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
+            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//鍥涘悜绌挎杞﹀彿
+            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//浠诲姟鍙�
+            assignCommand.setTaskMode(ShuttleTaskModeType.SHUTTLE_LOC_TO_LOC.id.shortValue());//搴撲綅绉昏浆妯″紡
+            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//婧愬簱浣�(灏忚溅褰撳墠浣嶇疆)
+            assignCommand.setCommands(result.getCommands());//杩愯鍛戒护
+            assignCommand.setNodes(result.getNodes());//璺緞鑺傜偣
+
+            wrkMast.setWrkSts(22L);//21.鐢熸垚鍑哄簱浠诲姟 => 22.灏忚溅鎼繍涓�
+            wrkMast.setSourceStaNo(sourceStaNo);//婧愮珯
+            wrkMast.setStaNo(staNo);//鐩爣绔�
+            wrkMast.setModiTime(new Date());
+            if (wrkMastMapper.updateById(wrkMast) > 0) {
+                //涓嬪彂浠诲姟
+                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
+            }
+
             return false;
         }
-        NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
-        if (shuttleProtocol == null) {
+        return true;
+    }
+
+    /**
+     * 璺ㄦゼ灞傚簱浣嶇Щ杞�-鎻愬崌鏈烘惉杩愯揣鐗�
+     * 濡傞渶涓绘柟娉曟墽琛宑ontinue锛岃杩斿洖false
+     * ps:杩斿洖鍊紅rue骞朵笉浠h〃璇ユ柟娉曟墽琛屾垚鍔燂紝杩斿洖鍊间粎鍋氭爣璁扮敤浜庝富鏂规硶鏄惁鎵цcontinue
+     */
+    private boolean locToLocExecuteStep3(WrkMast wrkMast) {
+        Date now = new Date();
+        if (wrkMast.getWrkSts() == 23) {//23.灏忚溅鎼繍瀹屾垚
+            //鑾峰彇鎻愬崌鏈虹嚎绋�
+            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
+            if (liftThread == null) {
+                return false;
+            }
+            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
+            if (liftProtocol == null) {
+                return false;
+            }
+
+            if (!liftProtocol.isIdle()) {
+                return false;
+            }
+
+            //鎼滅储鏄惁鏈夊叾浠栦换鍔″崰鐢ㄤ簡鎻愬崌鏈猴紝濡傛灉鍗犵敤鎻愬崌鏈虹殑浠诲姟鍜屽綋鍓嶄换鍔$浉鍚岋紝鍒欒繍琛屾墽琛�
+            WrkMast wrkMast1 = wrkMastMapper.selectLiftWrkMast(liftProtocol.getLiftNo().intValue());
+            if (wrkMast1 != null && wrkMast1.getWrkNo().intValue() != wrkMast.getWrkNo().intValue()) {
+                return false;
+            }
+
+            //婧愮珯
+            Integer sourceStaNo = wrkMast.getSourceStaNo();
+            //鐩爣绔�
+            Integer staNo = wrkMast.getStaNo();
+            if (sourceStaNo == null || staNo == null) {
+                return false;//婧愮珯鎴栫洰鏍囩珯涓虹┖
+            }
+
+            //鑾峰彇鎻愬崌鏈哄懡浠�
+            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, sourceStaNo, staNo, wrkMast.getWrkNo());
+
+            ArrayList<NyLiftCommand> commands = new ArrayList<>();
+            commands.add(liftCommand);
+
+            //鎻愪氦鍒扮嚎绋嬪幓宸ヤ綔
+            LiftAssignCommand assignCommand = new LiftAssignCommand();
+            assignCommand.setCommands(commands);
+            assignCommand.setLiftNo(liftProtocol.getLiftNo());
+            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
+            assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_TRAY.id.shortValue());
+
+            wrkMast.setWrkSts(24L);//23.灏忚溅鎼繍瀹屾垚 ==> 24.鎻愬崌鏈烘惉杩愪腑
+            wrkMast.setLiftNo(liftThread.getSlave().getId());//浠诲姟妗g粦瀹氭彁鍗囨満鍙�
+            wrkMast.setShuttleNo(null);//娓呯┖灏忚溅鍙凤紝绛夎揣鐗╂惉杩愬畬鎴愬悗锛屽埌鐩爣妤煎眰閲嶆柊鎼滅储灏忚溅
+            wrkMast.setModiTime(now);
+            if (wrkMastMapper.updateById(wrkMast) > 0) {
+                //涓嬪彂浠诲姟
+                MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
+            }
             return false;
         }
-        if (!shuttleProtocol.isIdle()) {
+        return true;
+    }
+
+    /**
+     * 璺ㄦゼ灞傚簱浣嶇Щ杞�-璋冨害杞﹁締鍙栬揣骞惰繍閫佸埌鐩爣搴撲綅
+     * 濡傞渶涓绘柟娉曟墽琛宑ontinue锛岃杩斿洖false
+     * ps:杩斿洖鍊紅rue骞朵笉浠h〃璇ユ柟娉曟墽琛屾垚鍔燂紝杩斿洖鍊间粎鍋氭爣璁扮敤浜庝富鏂规硶鏄惁鎵цcontinue
+     */
+    private boolean locToLocExecuteStep4(WrkMast wrkMast) {
+        if (wrkMast.getWrkSts() == 4) {//4.鎻愬崌鏈烘惉杩愬畬鎴�
+            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
+            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), wrkMast.getLiftNo());
+            if (targetBasDevp == null) {
+                return false;//缂哄皯绔欑偣淇℃伅
+            }
+
+            if (wrkMast.getShuttleNo() == null) {
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), targetBasDevp.getLocNo());//璋冨害灏忚溅鍒扮洰鏍囪緭閫佺珯鐐硅繘琛屽彇璐�
+                return false;
+            }
+
+            //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
+            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
+            if (shuttleThread == null) {
+                return false;
+            }
+            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+            if (shuttleProtocol == null) {
+                return false;
+            }
+            if (!shuttleProtocol.isIdle()) {
+                return false;
+            }
+
+            //鍒ゆ柇灏忚溅鏄惁鍒拌揪鐩爣杈撻�佺珯鐐�
+            if (!shuttleProtocol.getCurrentLocNo().equals(targetBasDevp.getLocNo())) {
+                //灏忚溅涓嶅湪鐩爣杈撻�佺珯鐐�
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), targetBasDevp.getLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒扮洰鏍囪緭閫佺珯鐐硅繘琛屽彇璐�
+                return false;
+            }
+
+            //灏忚溅宸叉姷杈剧洰鏍囪緭閫佺珯鐐癸紝灏嗚揣鐗╂惉杩愬埌鐩爣搴撲綅
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), targetBasDevp.getLocNo(), wrkMast.getLocNo());
+            if (result == null) {//璺緞璁$畻澶辫触
+                return false;
+            }
+
+            //鍒涘缓鍒嗛厤鍛戒护
+            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
+            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//鍥涘悜绌挎杞﹀彿
+            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//浠诲姟鍙�
+            assignCommand.setTaskMode(ShuttleTaskModeType.SHUTTLE_LOC_TO_LOC.id.shortValue());//搴撲綅绉昏浆妯″紡
+            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//婧愬簱浣�(灏忚溅褰撳墠浣嶇疆)
+            assignCommand.setCommands(result.getCommands());//杩愯鍛戒护
+            assignCommand.setNodes(result.getNodes());//璺緞鑺傜偣
+
+            wrkMast.setWrkSts(5L);//4.鎻愬崌鏈烘惉杩愬畬鎴� => 5.灏忚溅鎼繍涓�
+            wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈�
+            wrkMast.setModiTime(new Date());
+            if (wrkMastMapper.updateById(wrkMast) > 0) {
+                //涓嬪彂浠诲姟
+                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
+            }
+
             return false;
         }
-
-        //鍒ゆ柇灏忚溅鏄惁鍒拌揪婧愬簱浣�
-        if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) {
-            //灏忚溅涓嶅湪婧愬簱浣嶄綅缃�
-            shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒版簮搴撲綅杩涜鍙栬揣
-            return false;
-        }
-
-        //灏忚溅宸叉姷杈炬簮搴撲綅锛岃繘琛屾惉杩愯揣鐗�
-        NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), wrkMast.getLocNo());
-        if (result == null) {//璺緞璁$畻澶辫触
-            return false;
-        }
-
-        //鍒涘缓鍒嗛厤鍛戒护
-        ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
-        assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//鍥涘悜绌挎杞﹀彿
-        assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//浠诲姟鍙�
-        assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());//鍏ュ簱妯″紡
-        assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//婧愬簱浣�(灏忚溅褰撳墠浣嶇疆)
-        assignCommand.setCommands(result.getCommands());//杩愯鍛戒护
-        assignCommand.setNodes(result.getNodes());//璺緞鑺傜偣
-
-        wrkMast.setWrkSts(5L);//1.鐢熸垚鍏ュ簱浠诲姟 => 5.灏忚溅鎼繍涓�
-        wrkMast.setModiTime(new Date());
-        if (wrkMastMapper.updateById(wrkMast) > 0) {
-            //涓嬪彂浠诲姟
-            MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
-        }
-
         return true;
     }
 
@@ -1197,6 +1668,7 @@
     public void recErr() {
         try {
             this.recShuttleErr();
+            this.recLiftErr();
         } catch (Exception e) {
             News.error("recErr fail", e);
         }
@@ -1228,7 +1700,7 @@
                         if (wrkMast == null) {
                             continue;
                         }
-                        BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getErrCode().get(0));
+                        BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getErrCode());
                         String errName = basShuttleErr==null? "鏈煡寮傚父":basShuttleErr.getErrName();
                         BasShuttleErrLog basShuttleErrLog = new BasShuttleErrLog(
                                 null,    // 缂栧彿
@@ -1244,14 +1716,15 @@
                                 wrkMast.getSourceStaNo(),    // 婧愮珯
                                 wrkMast.getSourceLocNo(),    // 婧愬簱浣�
                                 wrkMast.getBarcode(),    // 鏉$爜
-                                shuttleProtocol.getErrCode().get(0),    // 寮傚父鐮�
+                                shuttleProtocol.getErrCode(),    // 寮傚父鐮�
                                 errName,    // 寮傚父
                                 1,    // 寮傚父鎯呭喌
                                 now,    // 娣诲姞鏃堕棿
                                 null,    // 娣诲姞浜哄憳
                                 now,    // 淇敼鏃堕棿
                                 null,    // 淇敼浜哄憳
-                                "浠诲姟涓紓甯�"    // 澶囨敞
+                                "浠诲姟涓紓甯�",    // 澶囨敞
+                                JSON.toJSONString(shuttleProtocol)    // 绯荤粺鐘舵�佹暟鎹�
                         );
                         if (!basShuttleErrLogService.insert(basShuttleErrLog)) {
                             News.error("鍥涘悜绌挎杞lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName);
@@ -1320,6 +1793,91 @@
         }
     }
 
+    /**
+     * 鎻愬崌鏈哄紓甯镐俊鎭褰�
+     */
+    private void recLiftErr() {
+        Date now = new Date();
+        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.getTaskNo() != 0) {
+                //鏈変换鍔�
+                BasLiftErrLog latest = basLiftErrLogService.findLatestByTaskNo(liftSlave.getId(), liftProtocol.getTaskNo().intValue());
+                // 鏈夊紓甯�
+                if (latest == null) {
+                    if (liftProtocol.getDeviceError() != null && liftProtocol.getDeviceError()) {
+                        WrkMast wrkMast = wrkMastMapper.selectById(liftProtocol.getTaskNo());
+                        if (wrkMast == null) {
+                            continue;
+                        }
+
+                        String errName = "";
+                        if (liftProtocol.getFrontOverrun()) {
+                            errName = "鍓嶈秴闄�";
+                        } else if (liftProtocol.getBackOverrun()) {
+                            errName = "鍚庤秴闄�";
+                        } else if (liftProtocol.getLeftOverrun()) {
+                            errName = "宸﹁秴闄�";
+                        } else if (liftProtocol.getRightOverrun()) {
+                            errName = "鍙宠秴闄�";
+                        } else if (liftProtocol.getOverHeight()) {
+                            errName = "瓒呴珮";
+                        } else if (liftProtocol.getOverWeight()) {
+                            errName = "瓒呴噸";
+                        }
+
+                        BasLiftErrLog basLiftErrLog = new BasLiftErrLog(
+                                null,    // 缂栧彿
+                                wrkMast.getWrkNo(),    // 宸ヤ綔鍙�
+                                now,    // 鍙戠敓鏃堕棿
+                                null,    // 缁撴潫鏃堕棿
+                                wrkMast.getWrkSts(),    // 宸ヤ綔鐘舵��
+                                wrkMast.getIoType(),    // 鍏ュ嚭搴撶被鍨�
+                                liftSlave.getId(),    // 鎻愬崌鏈�
+                                null,    // plc
+                                wrkMast.getLocNo(),    // 鐩爣搴撲綅
+                                wrkMast.getStaNo(),    // 鐩爣绔�
+                                wrkMast.getSourceStaNo(),    // 婧愮珯
+                                wrkMast.getSourceLocNo(),    // 婧愬簱浣�
+                                wrkMast.getBarcode(),    // 鏉$爜
+                                null,    // 寮傚父鐮�
+                                errName,    // 寮傚父
+                                1,    // 寮傚父鎯呭喌
+                                now,    // 娣诲姞鏃堕棿
+                                null,    // 娣诲姞浜哄憳
+                                now,    // 淇敼鏃堕棿
+                                null,    // 淇敼浜哄憳
+                                "浠诲姟涓紓甯�",    // 澶囨敞
+                                JSON.toJSONString(liftProtocol)    // 绯荤粺鐘舵�佹暟鎹�
+                        );
+                        if (!basLiftErrLogService.insert(basLiftErrLog)) {
+                            News.error("鎻愬崌鏈簆lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", liftSlave.getId(), errName);
+                        }
+                    }
+                } else {
+                    // 寮傚父淇
+                    if (liftProtocol.getDeviceError() == null || !liftProtocol.getDeviceError()) {
+                        latest.setEndTime(now);
+                        latest.setUpdateTime(now);
+                        latest.setStatus(2);
+                        if (!basLiftErrLogService.updateById(latest)) {
+                            News.error("鎻愬崌鏈簆lc寮傚父璁板綍淇澶辫触 ===>> [id:{}] [errLogId:{}]", liftSlave.getId(), latest.getId());
+                        }
+                    }
+                }
+            }
+        }
+    }
+
     // -------------------------------------------------------------------------------
 
     /**
@@ -1380,15 +1938,15 @@
                         Integer code = jsonObject.getInteger("code");
                         if (code.equals(200)) {
                             StartupDto dto = jsonObject.getObject("data", StartupDto.class);
-
-                            // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
-                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
-                            staProtocol.setStaNo(dto.getStaNo().shortValue());
-                            devpThread.setPakMk(staProtocol.getSiteId(), false);
-                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
-                            if (!result) {
-                                throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
-                            }
+                            barcodeThread.setBarcode("");
+//                            // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
+//                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
+//                            staProtocol.setStaNo(dto.getStaNo().shortValue());
+//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
+//                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+//                            if (!result) {
+//                                throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
+//                            }
                         } else {
                             if (ledThread != null) {
                                 String errorMsg = jsonObject.getString("msg");
@@ -1406,6 +1964,97 @@
                 }
 
 
+            }
+        }
+    }
+
+    /**
+     * AGV琛ヨ揣 => 鏈烘鑷傛嫞鏂�
+     */
+    public void agvRestockByRobot() {
+        //妫�娴�300绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗┿�佸伐浣滃彿
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            // 鑾峰彇鍏ュ簱绔欎俊鎭�
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+            StaProtocol staProtocol = devpThread.getStation().get(300);
+            if (staProtocol == null) {
+                continue;
+            }
+            if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() != 0) {
+                //鏌ヨ鏄惁鏈夊伐浣滄。
+                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue());
+                if (wrkMast == null) {
+                    continue;
+                }
+
+                if (wrkMast.getWrkSts() != 25) {//25.鎻愬崌鏈烘惉杩愬畬鎴�
+                    continue;
+                }
+
+                if (wrkMast.getMk() != null && wrkMast.getMk().equals("Y")) {//鏍囪涓篩琛ㄧず闇�瑕佺敤鍒版満姊拌噦鎷f枡
+                    Short targetSta = null;//鐩爣绔�
+                    //鍒ゆ柇鏈烘鑷傛嫞鏂欑珯鏄惁绌洪棽
+                    StaProtocol staProtocol303 = devpThread.getStation().get(303);
+                    StaProtocol staProtocol317 = devpThread.getStation().get(317);
+                    if (staProtocol303.isAutoing() && !staProtocol303.isLoading()) {
+                        //鑷姩銆佹棤鐗�
+                        targetSta = (short) 303;
+                    } else if (staProtocol317.isAutoing() && !staProtocol317.isLoading()) {
+                        //鑷姩銆佹棤鐗�
+                        targetSta = (short) 317;
+                    }else {
+                        continue;//娌℃湁绌洪棽绔欑偣
+                    }
+
+                    targetSta = (short) 317;
+
+                    if (wrkMast.getStaNo() != 303 && wrkMast.getStaNo() != 317) {
+                        //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
+                        wrkMast.setStaNo(targetSta.intValue());
+                        if (wrkMastMapper.updateById(wrkMast) > 0) {
+                            //鍚�300绔欏啓鍏ョ洰鏍囩珯
+                            staProtocol = staProtocol.clone();
+                            staProtocol.setStaNo(targetSta);//绉诲姩鍒扮洰鏍囩珯
+                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+                            try {
+                                Thread.sleep(500);
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }
+                            continue;
+                        }
+                    }
+                }
+            }
+
+            StaProtocol staProtocol303 = devpThread.getStation().get(303);
+            StaProtocol staProtocol317 = devpThread.getStation().get(317);
+            if (staProtocol303.isAutoing() && staProtocol303.isLoading() && staProtocol303.getWorkNo() != 0) {
+                //璋冨害鏈烘鑷�
+//                //鏌ヨ鏄惁鏈夊伐浣滄。
+//                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol303.getWorkNo().intValue());
+//                if (wrkMast == null) {
+//                    continue;
+//                }
+//                WrkDetl wrkDetl = wrkDetlService.selectById(wrkMast.getWrkNo());
+//                if (wrkDetl == null) {
+//                    continue;
+//                }
+//                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetl.getAnfme().intValue(), "303");
+                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), -1, "303");
+            }else if (staProtocol317.isAutoing() && staProtocol317.isLoading() && staProtocol317.getWorkNo() != 0) {
+                //璋冨害鏈烘鑷�
+//                //鏌ヨ鏄惁鏈夊伐浣滄。
+//                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol317.getWorkNo().intValue());
+//                if (wrkMast == null) {
+//                    continue;
+//                }
+//                WrkDetl wrkDetl = wrkDetlService.selectById(wrkMast.getWrkNo());
+//                if (wrkDetl == null) {
+//                    continue;
+//                }
+//                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetl.getAnfme().intValue(), "317");
+                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), -1, "317");
             }
         }
     }
@@ -1596,11 +2245,39 @@
                 continue;
             }
 
+            //灏忚溅鎵�鍦ㄦゼ灞�
+            int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());
             ShuttleChargeType shuttleCharge = null;
+
+            //鎼滅储灏忚溅鎵�鍦ㄦゼ灞傛湁娌℃湁鍏呯數妗�
             for (ShuttleChargeType chargeType : ShuttleChargeType.values()) {
+                if (lev != Utils.getLev(chargeType.locNo)) {
+                    continue;//灏忚溅鍜屽厖鐢垫々涓嶅湪鍚屼竴灞�
+                }
+
+                //灏忚溅鍜屽厖鐢垫々鍦ㄥ悓涓�灞�
                 if (wrkChargeService.selectWorkingOfCharge(chargeType.id) == null) {
                     shuttleCharge = chargeType;
                     break;
+                }
+            }
+
+            if (shuttleCharge == null) {
+                //鍚屾ゼ灞傛病鏈夋壘鍒板厖鐢垫々锛屾壘鍙敤鍏呯數妗�
+                //灏忚溅鍚屾ゼ灞傛病鏈夊厖鐢垫々锛屽彧瑕佸厖鐢垫々鍙敤灏辩敓鎴愬厖鐢典换鍔�
+                for (ShuttleChargeType chargeType : ShuttleChargeType.values()) {
+                    if (wrkChargeService.selectWorkingOfCharge(chargeType.id) == null) {
+                        //鍒ゆ柇褰撳墠鍏呯數妗╂ゼ灞傛槸鍚︽湁灏忚溅锛屽鏈夊皬杞︼紝涓嶅垎閰嶈鍏呯數妗�
+                        int chargeLev = Utils.getLev(chargeType.locNo);//鍏呯數妗╂ゼ灞�
+                        boolean checkLevHasShuttle = Utils.checkLevHasShuttle(chargeLev);//妫�娴嬫ゼ灞傛槸鍚︽湁绌挎杞�
+                        if (checkLevHasShuttle) {
+                            //褰撳墠鍏呯數妗╂ゼ灞傛湁绌挎杞︼紝涓嶅垎閰嶈鍏呯數妗�
+                            continue;
+                        }
+
+                        shuttleCharge = chargeType;
+                        break;
+                    }
                 }
             }
 
@@ -1623,7 +2300,6 @@
                 continue;
             }
 
-            shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING);//鍏呯數涓�
             News.info("淇濆瓨{}鍙峰洓鍚戠┛姊溅鍏呯數浠诲姟鎴愬姛!!!", shuttle.getId());
         }
     }
@@ -1648,6 +2324,10 @@
             }
 
             if (wrkCharge.getWrkSts() == 51) {
+                if (!shuttleProtocol.isIdleNoCharge()) {
+                    continue;
+                }
+
                 if (!shuttleProtocol.getCurrentLocNo().equals(wrkCharge.getLocNo())) {
                     //灏忚溅涓嶅湪鍏呯數妗╀綅缃�
                     shuttleDispatchUtils.dispatchShuttle(wrkCharge.getWrkNo(), wrkCharge.getLocNo(), shuttle.getId());//璋冨害灏忚溅鍘诲厖鐢垫々
@@ -1674,7 +2354,8 @@
                 }
             } else if (wrkCharge.getWrkSts() == 52) {
                 //妫�娴嬪皬杞︽槸鍚︽弧鐢�
-                if (shuttleProtocol.getPowerPercent() < 100) {
+                int maxPower = 95;
+                if (shuttleProtocol.getPowerPercent() < maxPower) {
                     continue;
                 }
 
@@ -1690,21 +2371,34 @@
                 assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//婧愬簱浣�(灏忚溅褰撳墠浣嶇疆)
                 assignCommand.setCommands(commands);//杩愯鍛戒护
 
+                //涓嬪彂浠诲姟
+                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
+                try {
+                    Thread.sleep(3000);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+
                 wrkCharge.setWrkSts(53L);//52.灏忚溅鍘诲厖鐢典腑 => 53.灏忚溅鍏呯數瀹屾垚
                 wrkCharge.setModiTime(new Date());
                 if (wrkChargeMapper.updateById(wrkCharge) > 0) {
-                    //涓嬪彂浠诲姟
-                    MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
+                    shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE.id);
+                    shuttleProtocol.setTaskNo(0);
+                    shuttleProtocol.setPakMk(false);
                 }
             } else if (wrkCharge.getWrkSts() == 53) {
-                boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkCharge.getLocNo()), shuttleThread.getSlave().getId(), shuttleThread);
-                if (!result) {
-                    continue;
-                }
+                if (shuttleProtocol.getChargState() == 0) {//灏忚溅澶勪簬鏈厖鐢电姸鎬�
+                    boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkCharge.getLocNo()), shuttleThread.getSlave().getId(), shuttleThread);
+                    if (!result) {
+                        continue;
+                    }
 
-                wrkCharge.setWrkSts(60L);//53.灏忚溅鍏呯數瀹屾垚 => 60.鍏呯數浠诲姟瀹屾垚
-                wrkCharge.setModiTime(new Date());
-                wrkChargeMapper.updateById(wrkCharge);
+                    wrkCharge.setWrkSts(60L);//53.灏忚溅鍏呯數瀹屾垚 => 60.鍏呯數浠诲姟瀹屾垚
+                    wrkCharge.setModiTime(new Date());
+                    if (wrkChargeMapper.updateById(wrkCharge) > 0) {
+
+                    }
+                }
             }
 
         }
@@ -1718,38 +2412,46 @@
         //鏌ヨ灏忚溅绉诲簱浠诲姟
         List<WrkMast> wrkMasts = wrkMastMapper.selectShuttleMoveWrk();
         for (WrkMast wrkMast : wrkMasts) {
-            boolean step1 = this.shuttleMoveExecuteStep1(wrkMast);//灏忚溅绉诲姩鍒版彁鍗囨満涓�
-            if (!step1) {
+            boolean stepMoveSta = this.shuttleMoveExecuteStepMoveSta(wrkMast);//灏忚溅绉诲姩鍒扮珯鐐�
+            if (!stepMoveSta) {
                 continue;
             }
 
-            boolean step2 = this.shuttleMoveExecuteStep2(wrkMast);//鎻愬崌鏈烘惉杩愪腑
-            if (!step2) {
+            boolean stepIntoLift = this.shuttleMoveExecuteStepIntoLift(wrkMast);//灏忚溅杩佸叆鎻愬崌鏈�
+            if (!stepIntoLift) {
                 continue;
             }
 
-            boolean step3 = this.shuttleMoveExecuteStep3(wrkMast);//灏忚溅杩佸嚭鎻愬崌鏈轰腑
-            if (!step3) {
+            boolean stepLiftMove = this.shuttleMoveExecuteStepLiftMove(wrkMast);//鎻愬崌鏈烘惉杩愪腑
+            if (!stepLiftMove) {
                 continue;
             }
 
-            boolean step4 = this.shuttleMoveExecuteStep4(wrkMast);//灏忚溅绉诲姩鍒扮洰鏍囧簱浣嶄腑
-            if (!step4) {
+            boolean stepOutLift = this.shuttleMoveExecuteStepOutLift(wrkMast);//灏忚溅杩佸嚭鎻愬崌鏈�
+            if (!stepOutLift) {
                 continue;
             }
+
+            boolean stepMoveLoc = this.shuttleMoveExecuteStepMoveLoc(wrkMast);//灏忚溅绉诲姩鍒扮洰鏍囧簱浣嶄腑
+            if (!stepMoveLoc) {
+                continue;
+            }
+
+//            this.shuttleMoveExecuteStepClearWrkMast(wrkMast);//娓呯悊111.灏忚溅绉诲姩瀹屾垚
+
         }
     }
 
     /**
-     * 灏忚溅杩佺Щ-灏忚溅绉诲姩鍒版彁鍗囨満涓�
+     * 灏忚溅杩佺Щ-灏忚溅绉诲姩鍒扮珯鐐�
      * 濡傞渶涓绘柟娉曟墽琛宑ontinue锛岃杩斿洖false
      * ps:杩斿洖鍊紅rue骞朵笉浠h〃璇ユ柟娉曟墽琛屾垚鍔燂紝杩斿洖鍊间粎鍋氭爣璁扮敤浜庝富鏂规硶鏄惁鎵цcontinue
      */
-    private boolean shuttleMoveExecuteStep1(WrkMast wrkMast) {
-        //--------------------------------------灏忚溅绉诲姩鍒版彁鍗囨満涓�-----------------------------------------//
+    private boolean shuttleMoveExecuteStepMoveSta(WrkMast wrkMast) {
+        //--------------------------------------灏忚溅绉诲姩鑷崇珯鐐�-----------------------------------------//
         Date now = new Date();
 
-        //灏忚溅绉诲姩鍒版彁鍗囨満涓�  101.鐢熸垚灏忚溅绉诲簱浠诲姟 ==> 102.灏忚溅鍒版彁鍗囨満涓�
+        //灏忚溅绉诲姩鑷崇珯鐐�  101.鐢熸垚灏忚溅绉诲簱浠诲姟 ==> 102.灏忚溅绉诲姩鑷崇珯鐐逛腑
         if (wrkMast.getWrkSts() == 101) {
             //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
             NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
@@ -1762,76 +2464,42 @@
             }
 
             //灏忚溅澶勪簬绌洪棽鐘舵��
-            if (!shuttleProtocol.isIdleNoCharge()) {
+            if (!shuttleProtocol.isIdleNoCharge(wrkMast.getWrkNo())) {
                 return false;
             }
 
+            //鍒ゆ柇灏忚溅浠ょ墝鏄惁鏈鍗犻
+            if (shuttleProtocol.getToken() != 0) {
+                return false;//灏忚溅宸茶鐙崰锛岀姝㈠啀娲惧彂浠诲姟
+            }
+
             if (Utils.getLev(wrkMast.getLocNo()) == shuttleProtocol.getPoint().getZ()) {
-                //鐩爣搴撲綅鍜屽皬杞﹀簱浣嶅浜庡悓涓�妤煎眰锛岄渶瑕侀�氳繃鎻愬崌鏈鸿皟搴�
-                return true;//鐩存帴杩涘叆108.灏忚溅绉诲姩涓�
+                //鐩爣搴撲綅鍜屽皬杞﹀簱浣嶅浜庡悓涓�妤煎眰锛屼笉闇�瑕侀�氳繃鎻愬崌鏈鸿皟搴�
+                wrkMast.setWrkSts(109L);// 109.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴� ==> 110.灏忚溅绉诲姩涓�
+                wrkMast.setModiTime(now);
+                shuttleProtocol.setToken(wrkMast.getWrkNo());//鐙崰璇ュ皬杞︿护鐗�
+                if (wrkMastMapper.updateById(wrkMast) > 0) {
+                    //涓嬪彂浠诲姟
+                    return true;//鐩存帴杩涘叆109.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴� ==> 110.灏忚溅绉诲姩涓�
+                }
+                return false;
             }
 
-            //璁$畻璺濈灏忚溅鏈�杩戠殑鎻愬崌鏈虹珯鐐�
-            //鏌ヨ灏忚溅鎵�鍦ㄦゼ灞傛彁鍗囨満杈撻�佺珯鐐�
-            int recentAllDistance = 9999999;//榛樿鏈�杩戣窛绂�
-            BasDevp recentDevp = null;//鏈�杩戠珯鐐�
-            List<BasDevp> basDevps = basDevpService.selectHasLiftNoByLev(shuttleProtocol.getPoint().getZ());
-            for (BasDevp basDevp : basDevps) {
-                LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, basDevp.getLiftNo());
-                if (liftThread == null) {
-                    continue;
-                }
-                LiftProtocol liftProtocol = liftThread.getLiftProtocol();
-                if (liftProtocol == null) {
-                    continue;
-                }
-                if (!liftProtocol.isIdle()) {
-                    continue;
-                }
-
-                //璁$畻璺緞
-                List<NavigateNode> calc = NavigateUtils.calc(shuttleProtocol.getCurrentLocNo(), basDevp.getLocNo(), NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), Utils.getLev(shuttleProtocol.getCurrentLocNo())));
-                if (calc == null) {
-                    continue;//璁$畻澶辫触锛屾壘涓嬩竴涓珯鐐�
-                }
-
-                Integer allDistance = NavigateUtils.getOriginPathAllDistance(calc);//鏍规嵁鍘熷鑺傜偣缁撴灉锛岃绠楁�昏璧拌窛绂�
-                if (recentAllDistance > allDistance) {
-                    recentAllDistance = allDistance;//鏇存柊璺濈
-                    recentDevp = basDevp;//鏇存柊杈撻�佺珯鐐�
-                }
+            //鑾峰彇婧愯緭閫佺珯
+            LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
+            if (liftSta == null) {
+                return false;//鎵句笉鍒扮珯鐐�
             }
 
-            if (recentDevp == null) {
-                //娌℃湁鎵惧埌鍙敤杈撻�佺珯鐐�
-                return false;//绛夊緟涓嬩竴娆¤疆璇�
-            }
-
-            //鑾峰彇鎻愬崌鏈烘暟鎹�
-            BasLift basLift = basLiftService.selectById(recentDevp.getLiftNo());
-            if (basLift == null) {
-                return false;//娌℃湁鎻愬崌鏈烘暟鎹�
-            }
-            if (basLift.getPoint() == null) {
-                return false;//娌℃湁璁剧疆鎻愬崌鏈虹偣浣嶅潗鏍�
-            }
-            //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟
-            WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(basLift.getLiftNo());
+            //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟(璇ヤ换鍔¢渶瑕佹崲灞傚繀椤绘彁鍓嶇嫭鍗犳彁鍗囨満)
+            WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftSta.getLiftNo());
             if (liftWrkMast != null) {
                 return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇�
             }
-            NavigateNode liftNode = new NavigateNode(basLift.getPoint().getX(), basLift.getPoint().getY());
-            liftNode.setZ(basLift.getPoint().getZ());
 
             //鑾峰彇灏忚溅鍒拌緭閫佺珯鐐硅璧板懡浠�
-            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), recentDevp.getLocNo());
-            //鑾峰彇灏忚溅杩涙彁鍗囨満琛岃蛋鍛戒护
-            NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), NavigatePositionConvert.locNoToNode(recentDevp.getLocNo()), liftNode, true);
-            if (result.getCommands() == null) {
-                return false;//璺緞璁$畻澶辫触
-            }
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.NORMAL.id);
             List<NyShuttleHttpCommand> commands = result.getCommands();
-            commands.add(moveCommand);//娣诲姞灏忚溅杩佸叆鎻愬崌鏈哄懡浠�
 
             ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
             assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 鍥涘悜绌挎杞︾紪鍙�
@@ -1841,30 +2509,62 @@
             assignCommand.setCommands(commands);
             assignCommand.setNodes(result.getNodes());
 
-            wrkMast.setWrkSts(102L);//灏忚溅绉诲姩鍒版彁鍗囨満涓�  101.鐢熸垚灏忚溅绉诲簱浠诲姟 ==> 102.灏忚溅鍒版彁鍗囨満涓�
-            wrkMast.setLiftNo(basLift.getLiftNo());//鎻愬崌鏈哄彿(閿佸畾鎻愬崌鏈洪槻姝㈣鍏朵粬浠诲姟鎶㈠崰)
+            wrkMast.setWrkSts(102L);//灏忚溅绉诲姩鍒版彁鍗囨満涓�  101.鐢熸垚灏忚溅绉诲簱浠诲姟 ==> 102.灏忚溅绉诲姩鑷崇珯鐐�
             wrkMast.setModiTime(now);
+            wrkMast.setLiftNo(liftSta.getLiftNo());//鎻愬墠閿佸畾鎻愬崌鏈�
+            shuttleProtocol.setToken(wrkMast.getWrkNo());//鐙崰璇ュ皬杞︿护鐗�
             if (wrkMastMapper.updateById(wrkMast) > 0) {
                 //涓嬪彂浠诲姟
                 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
+                return false;
             }
+            return false;
         }
         return true;
     }
 
     /**
-     * 灏忚溅杩佺Щ-鎻愬崌鏈烘惉杩愪腑
+     * 灏忚溅杩佺Щ-灏忚溅杩佸叆鎻愬崌鏈�
      * 濡傞渶涓绘柟娉曟墽琛宑ontinue锛岃杩斿洖false
      * ps:杩斿洖鍊紅rue骞朵笉浠h〃璇ユ柟娉曟墽琛屾垚鍔燂紝杩斿洖鍊间粎鍋氭爣璁扮敤浜庝富鏂规硶鏄惁鎵цcontinue
      */
-    private boolean shuttleMoveExecuteStep2(WrkMast wrkMast) {
-        //--------------------------------------鎻愬崌鏈烘惉杩愪腑-----------------------------------------//
+    private boolean shuttleMoveExecuteStepIntoLift(WrkMast wrkMast) {
+        //--------------------------------------灏忚溅杩佸叆鎻愬崌鏈�-----------------------------------------//
         Date now = new Date();
 
-        //鎻愬崌鏈烘惉杩愪腑  103.灏忚溅鍒版彁鍗囨満瀹屾垚 ==> 104.鎻愬崌鏈烘惉杩愪腑
+        //灏忚溅绉诲姩鍒版彁鍗囨満涓�  103.灏忚溅绉诲姩鑷崇珯鐐瑰畬鎴� ==> 104.灏忚溅杩佸叆鎻愬崌鏈轰腑
         if (wrkMast.getWrkSts() == 103) {
+            //鑾峰彇婧愮珯
+            LiftStaProtocol sourceLiftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
+            if (sourceLiftSta == null) {
+                return false;//鎵句笉鍒扮珯鐐�
+            }
 
-            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
+            //鑾峰彇鐩爣杈撻�佺珯
+            LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
+            if (liftSta == null) {
+                return false;//鎵句笉鍒扮珯鐐�
+            }
+
+            //鑾峰彇鎻愬崌鏈烘暟鎹�
+            BasLift basLift = basLiftService.selectById(liftSta.getLiftNo());
+            if (basLift == null) {
+                return false;//娌℃湁鎻愬崌鏈烘暟鎹�
+            }
+
+            if (basLift.getPoint() == null) {
+                return false;//娌℃湁璁剧疆鎻愬崌鏈虹偣浣嶅潗鏍�
+            }
+
+            //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟
+            WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(basLift.getLiftNo());
+            if (liftWrkMast != null) {
+                if (!liftWrkMast.getWrkNo().equals(wrkMast.getWrkNo())) {//鎻愬崌鏈轰换鍔″拰褰撳墠浠诲姟涓嶇浉鍚�
+                    return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇�
+                }
+            }
+
+            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSta.getLiftNo());
             if (liftThread == null) {
                 return false;
             }
@@ -1872,6 +2572,7 @@
             if (liftProtocol == null) {
                 return false;
             }
+
             if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
                 return false;
             }
@@ -1887,53 +2588,115 @@
             }
 
             //灏忚溅澶勪簬绌洪棽鐘舵��
-            if (!shuttleProtocol.isIdleNoCharge()) {
+            if (!shuttleProtocol.isIdleNoCharge(wrkMast.getWrkNo())) {
                 return false;
             }
 
-            //鑾峰彇婧愮珯瀵瑰簲鐨勮緭閫佺珯鐐�
-            BasDevp sourceBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getSourceLocNo()), liftProtocol.getLiftNo().intValue());
-            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
-            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), liftProtocol.getLiftNo().intValue());
-            if (sourceBasDevp == null || targetBasDevp == null) {
-                return false;//缂哄皯绔欑偣淇℃伅
+            //灏忚溅浠ょ墝鏄惁琚换鍔$嫭鍗�
+            if (!shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
+                return false;
             }
 
-            //鑾峰彇鎻愬崌鏈哄懡浠�
-            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), wrkMast.getWrkNo());
+            //鍒ゆ柇鎻愬崌鏈烘ゼ灞�
+            if (liftProtocol.getLev().intValue() != shuttleProtocol.getPoint().getZ()) {
+                //鎻愬崌鏈轰笉鍦ㄥ皬杞︽ゼ灞�
+                //璋冨害鎻愬崌鏈�
 
-            ArrayList<NyLiftCommand> commands = new ArrayList<>();
-            commands.add(liftCommand);
+                if (liftProtocol.getToken() != 0) {
+                    return false;//鎻愬崌鏈轰护鐗岃鍗犵敤
+                }
 
-            //鎻愪氦鍒扮嚎绋嬪幓宸ヤ綔
-            LiftAssignCommand assignCommand = new LiftAssignCommand();
+                //鑾峰彇鎻愬崌鏈哄懡浠わ紝璋冨害鎻愬崌鏈哄埌婧愮珯浣嶇疆
+                NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceLiftSta.getStaNo(), sourceLiftSta.getStaNo(), wrkMast.getWrkNo());
+
+                Random random = new Random();
+                liftCommand.setTaskNo((short) Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999))));//鏇存崲闅忔満浠诲姟鍙�
+
+                ArrayList<NyLiftCommand> commands = new ArrayList<>();
+                commands.add(liftCommand);
+
+                //鎻愪氦鍒扮嚎绋嬪幓宸ヤ綔
+                LiftAssignCommand assignCommand = new LiftAssignCommand();
+                assignCommand.setCommands(commands);
+                assignCommand.setLiftNo(liftProtocol.getLiftNo());
+                assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
+                assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_CAR.id.shortValue());
+                assignCommand.setAuto(false);
+
+                wrkMast.setLiftNo(liftThread.getSlave().getId());//閿佸畾鎻愬崌鏈洪槻姝㈣鍗犵敤
+                wrkMast.setModiTime(now);
+                liftProtocol.setToken(wrkMast.getShuttleNo());//鎻愬崌鏈轰护鐗岀粦瀹氬綋鍓嶅皬杞�
+                if (wrkMastMapper.updateById(wrkMast) > 0) {
+                    //涓嬪彂浠诲姟
+                    MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
+                }
+                return false;//绛夊緟鎻愬崌鏈哄埌灏忚溅妤煎眰
+            }
+
+            if (liftProtocol.getToken() == 0) {//鎻愬崌鏈轰护鐗屾湭琚崰鐢�
+                //鐙崰鎻愬崌鏈�
+                liftProtocol.setToken(wrkMast.getShuttleNo());
+                return false;//绛夊緟涓嬩竴娆℃墽琛�
+            }
+
+            //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚︿负褰撳墠灏忚溅
+            if (!liftProtocol.getToken().equals(wrkMast.getShuttleNo())) {
+                return false;//鎻愬崌鏈哄凡琚嫭鍗狅紝绂佹鍐嶆淳鍙戜换鍔�
+            }
+
+            //鍒ゆ柇灏忚溅鏄惁涓哄綋鍓嶄换鍔$嫭鍗�
+            if (!shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
+                return false;
+            }
+
+            //绔欑偣鑺傜偣
+            NavigateNode staNode = NavigatePositionConvert.locNoToNode(sourceLiftSta.getLocNo());
+
+            //鎻愬崌鏈鸿妭鐐�
+            NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY());
+            liftNode.setZ(staNode.getZ());
+
+            //鑾峰彇灏忚溅杩涙彁鍗囨満琛岃蛋鍛戒护
+            NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), staNode, liftNode, true);
+            List<NyShuttleHttpCommand> commands = new ArrayList<>();
+            commands.add(moveCommand);
+            List<NavigateNode> nodes = new ArrayList<>();//琛岃蛋鑺傜偣璺緞
+            nodes.add(staNode);
+            nodes.add(liftNode);
+
+            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
+            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 鍥涘悜绌挎杞︾紪鍙�
+            assignCommand.setTaskMode(ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO.id.shortValue());//灏忚溅绉诲簱浠诲姟
+            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//浠诲姟鍙�
+            assignCommand.setAuto(true);//鑷姩妯″紡
             assignCommand.setCommands(commands);
-            assignCommand.setLiftNo(liftProtocol.getLiftNo());
-            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
-            assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_CAR.id.shortValue());
+            assignCommand.setNodes(nodes);
 
-            wrkMast.setWrkSts(104L);//鎻愬崌鏈烘惉杩愪腑  103.灏忚溅鍒版彁鍗囨満瀹屾垚 ==> 104.鎻愬崌鏈烘惉杩愪腑
-            wrkMast.setLiftNo(liftThread.getSlave().getId());//閿佸畾鎻愬崌鏈洪槻姝㈣鍗犵敤
+            wrkMast.setWrkSts(104L);//灏忚溅绉诲姩鍒版彁鍗囨満涓�  103.灏忚溅绉诲姩鑷崇珯鐐瑰畬鎴� ==> 104.灏忚溅杩佸叆鎻愬崌鏈轰腑
             wrkMast.setModiTime(now);
+            wrkMast.setLiftNo(liftThread.getSlave().getId());//閿佸畾鎻愬崌鏈洪槻姝㈣鍗犵敤
+            liftProtocol.setToken(wrkMast.getShuttleNo());//鎻愬崌鏈轰护鐗岀粦瀹氬綋鍓嶅皬杞�
             if (wrkMastMapper.updateById(wrkMast) > 0) {
                 //涓嬪彂浠诲姟
-                MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
+                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
+                return false;
             }
-
+            return false;
         }
+
         return true;
     }
 
     /**
-     * 灏忚溅杩佺Щ-灏忚溅杩佸嚭鎻愬崌鏈轰腑
+     * 灏忚溅杩佺Щ-鎻愬崌鏈烘惉杩愪腑
      * 濡傞渶涓绘柟娉曟墽琛宑ontinue锛岃杩斿洖false
      * ps:杩斿洖鍊紅rue骞朵笉浠h〃璇ユ柟娉曟墽琛屾垚鍔燂紝杩斿洖鍊间粎鍋氭爣璁扮敤浜庝富鏂规硶鏄惁鎵цcontinue
      */
-    private boolean shuttleMoveExecuteStep3(WrkMast wrkMast) {
-        //--------------------------------------灏忚溅杩佸嚭鎻愬崌鏈轰腑-----------------------------------------//
+    private boolean shuttleMoveExecuteStepLiftMove(WrkMast wrkMast) {
+        //--------------------------------------鎻愬崌鏈烘惉杩愪腑-----------------------------------------//
         Date now = new Date();
 
-        //灏忚溅杩佸嚭鎻愬崌鏈轰腑  105.鎻愬崌鏈烘惉杩愬畬鎴� ==> 106.灏忚溅杩佸嚭鎻愬崌鏈轰腑
+        //鎻愬崌鏈烘惉杩愪腑  105.灏忚溅杩佸叆鎻愬崌鏈哄畬鎴� ==> 106.鎻愬崌鏈烘惉杩愪腑
         if (wrkMast.getWrkSts() == 105) {
 
             LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
@@ -1947,6 +2710,23 @@
             if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
                 return false;
             }
+            //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟
+            WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId());
+            if (liftWrkMast != null) {
+                if (!liftWrkMast.getWrkNo().equals(wrkMast.getWrkNo())) {//鎻愬崌鏈轰换鍔″拰褰撳墠浠诲姟涓嶇浉鍚�
+                    return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇�
+                }
+            }
+
+            //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚︿负褰撳墠灏忚溅
+            if (!liftProtocol.getToken().equals(wrkMast.getShuttleNo())) {
+                return false;//鎻愬崌鏈轰护鐗屽拰褰撳墠灏忚溅涓嶄竴鑷达紝绂佹娲惧彂
+            }
+
+            //鍒ゆ柇鎻愬崌鏈哄唴鏄惁鏈夊皬杞�
+            if (!liftProtocol.getHasCar()) {
+                return false;//鎻愬崌鏈哄唴鏃犲皬杞�
+            }
 
             //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
             NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
@@ -1963,26 +2743,124 @@
                 return false;
             }
 
-            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
-            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), liftProtocol.getLiftNo().intValue());
-            if (targetBasDevp == null) {
+            //鍒ゆ柇灏忚溅鏄惁涓哄綋鍓嶄换鍔$嫭鍗�
+            if (!shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
+                return false;
+            }
+
+            //鑾峰彇婧愮珯
+            LiftStaProtocol sourceLiftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
+            //鑾峰彇鐩爣绔�
+            LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
+            if (sourceLiftSta == null || liftSta == null) {
                 return false;//缂哄皯绔欑偣淇℃伅
             }
 
+            //鑾峰彇鎻愬崌鏈哄懡浠�
+            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceLiftSta.getStaNo(), liftSta.getStaNo(), wrkMast.getWrkNo());
+
+            ArrayList<NyLiftCommand> commands = new ArrayList<>();
+            commands.add(liftCommand);
+
+            //鎻愪氦鍒扮嚎绋嬪幓宸ヤ綔
+            LiftAssignCommand assignCommand = new LiftAssignCommand();
+            assignCommand.setCommands(commands);
+            assignCommand.setLiftNo(liftProtocol.getLiftNo());
+            assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
+            assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_CAR.id.shortValue());
+
+            wrkMast.setWrkSts(106L);//鎻愬崌鏈烘惉杩愪腑  105.灏忚溅杩佸叆鎻愬崌鏈哄畬鎴� ==> 106.鎻愬崌鏈烘惉杩愪腑
+            wrkMast.setLiftNo(liftThread.getSlave().getId());//閿佸畾鎻愬崌鏈洪槻姝㈣鍗犵敤
+            wrkMast.setModiTime(now);
+            if (wrkMastMapper.updateById(wrkMast) > 0) {
+                //涓嬪彂浠诲姟
+                MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand));
+            }
+
+        }
+        return true;
+    }
+
+    /**
+     * 灏忚溅杩佺Щ-灏忚溅杩佸嚭鎻愬崌鏈�
+     * 濡傞渶涓绘柟娉曟墽琛宑ontinue锛岃杩斿洖false
+     * ps:杩斿洖鍊紅rue骞朵笉浠h〃璇ユ柟娉曟墽琛屾垚鍔燂紝杩斿洖鍊间粎鍋氭爣璁扮敤浜庝富鏂规硶鏄惁鎵цcontinue
+     */
+    private boolean shuttleMoveExecuteStepOutLift(WrkMast wrkMast) {
+        //--------------------------------------灏忚溅杩佸嚭鎻愬崌鏈�-----------------------------------------//
+        Date now = new Date();
+        //灏忚溅绉诲姩鍒版彁鍗囨満涓�  107.鎻愬崌鏈烘惉杩愬畬鎴� ==> 108.灏忚溅杩佸嚭鎻愬崌鏈轰腑
+        if (wrkMast.getWrkSts() == 107) {
+
+            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
+            if (liftThread == null) {
+                return false;
+            }
+            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
+            if (liftProtocol == null) {
+                return false;
+            }
+            if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
+                return false;
+            }
+
+            //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟
+            WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId());
+            if (liftWrkMast != null) {
+                if (!liftWrkMast.getWrkNo().equals(wrkMast.getWrkNo())) {//鎻愬崌鏈轰换鍔″拰褰撳墠浠诲姟涓嶇浉鍚�
+                    return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇�
+                }
+            }
+
+            //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚︿负褰撳墠灏忚溅
+            if (!liftProtocol.getToken().equals(wrkMast.getShuttleNo())) {
+                return false;//鎻愬崌鏈轰护鐗屽拰褰撳墠灏忚溅涓嶄竴鑷达紝绂佹娲惧彂
+            }
+
+            //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
+            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
+            if (shuttleThread == null) {
+                return false;
+            }
+            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+            if (shuttleProtocol == null) {
+                return false;
+            }
+
+            //灏忚溅澶勪簬绌洪棽鐘舵��
+            if (!shuttleProtocol.isIdleNoCharge()) {
+                return false;
+            }
+
+            //鍒ゆ柇灏忚溅鏄惁涓哄綋鍓嶄换鍔$嫭鍗�
+            if (!shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
+                return false;
+            }
+
+            //鑾峰彇鐩爣绔�
+            LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
+            if (liftSta == null) {
+                return false;//鎵句笉鍒扮珯鐐�
+            }
+
             //鑾峰彇鎻愬崌鏈烘暟鎹�
-            BasLift basLift = basLiftService.selectById(targetBasDevp.getLiftNo());
+            BasLift basLift = basLiftService.selectById(liftProtocol.getLiftNo().intValue());
             if (basLift == null) {
                 return false;//娌℃湁鎻愬崌鏈烘暟鎹�
             }
             if (basLift.getPoint() == null) {
                 return false;//娌℃湁璁剧疆鎻愬崌鏈虹偣浣嶅潗鏍�
             }
-            NavigateNode liftNode = new NavigateNode(basLift.getPoint().getX(), basLift.getPoint().getY());
-            liftNode.setZ(basLift.getPoint().getZ());
+            NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY());
+            liftNode.setZ(liftSta.getLev());
 
             List<NyShuttleHttpCommand> commands = new ArrayList<>();
+            //鑾峰彇灏忚溅鏇存柊妤煎眰鍛戒护
+            NyShuttleHttpCommand updateZCommand = NyHttpUtils.getUpdateZCommand(shuttleThread.getSlave().getId(), liftProtocol.getLev().intValue(), wrkMast.getWrkNo());
+            commands.add(updateZCommand);
+
             //鑾峰彇灏忚溅鍑烘彁鍗囨満琛岃蛋鍛戒护
-            NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), liftNode, NavigatePositionConvert.locNoToNode(targetBasDevp.getLocNo()), false);
+            NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), liftNode, NavigatePositionConvert.locNoToNode(liftSta.getLocNo()), false);
             commands.add(moveCommand);//娣诲姞灏忚溅杩佸嚭鎻愬崌鏈哄懡浠�
 
             ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
@@ -1993,12 +2871,14 @@
             assignCommand.setCommands(commands);
             assignCommand.setNodes(null);
 
-            wrkMast.setWrkSts(106L);//灏忚溅杩佸嚭鎻愬崌鏈轰腑  105.鎻愬崌鏈烘惉杩愬畬鎴� ==> 106.灏忚溅杩佸嚭鎻愬崌鏈轰腑
+            wrkMast.setWrkSts(108L);//灏忚溅杩佸嚭鎻愬崌鏈轰腑  107.鎻愬崌鏈烘惉杩愬畬鎴� ==> 108.灏忚溅杩佸嚭鎻愬崌鏈轰腑
             wrkMast.setModiTime(now);
             if (wrkMastMapper.updateById(wrkMast) > 0) {
                 //涓嬪彂浠诲姟
                 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
+                return false;
             }
+            return false;
         }
         return true;
     }
@@ -2008,12 +2888,12 @@
      * 濡傞渶涓绘柟娉曟墽琛宑ontinue锛岃杩斿洖false
      * ps:杩斿洖鍊紅rue骞朵笉浠h〃璇ユ柟娉曟墽琛屾垚鍔燂紝杩斿洖鍊间粎鍋氭爣璁扮敤浜庝富鏂规硶鏄惁鎵цcontinue
      */
-    private boolean shuttleMoveExecuteStep4(WrkMast wrkMast) {
+    private boolean shuttleMoveExecuteStepMoveLoc(WrkMast wrkMast) {
         //--------------------------------------灏忚溅绉诲姩鍒扮洰鏍囧簱浣嶄腑-----------------------------------------//
         Date now = new Date();
 
-        //灏忚溅绉诲姩鍒扮洰鏍囧簱浣嶄腑  107.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴� ==> 108.灏忚溅绉诲姩涓�
-        if (wrkMast.getWrkSts() == 107) {
+        //灏忚溅绉诲姩鍒扮洰鏍囧簱浣嶄腑  109.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴� ==> 110.灏忚溅绉诲姩涓�
+        if (wrkMast.getWrkSts() == 109) {
 
             //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
             NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
@@ -2026,30 +2906,35 @@
             }
 
             //灏忚溅澶勪簬绌洪棽鐘舵��
-            if (!shuttleProtocol.isIdleNoCharge()) {
+            if (!shuttleProtocol.isIdleNoCharge(wrkMast.getWrkNo())) {
                 return false;
             }
 
-            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
-            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), wrkMast.getLiftNo());
-            if (targetBasDevp == null) {
-                return false;//缂哄皯绔欑偣淇℃伅
+            //鍒ゆ柇灏忚溅浠ょ墝鏄惁涓哄綋鍓嶄换鍔�
+            if (shuttleProtocol.getToken() != 0 && !shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
+                return false;
             }
 
-            //鑾峰彇鎻愬崌鏈烘暟鎹�
-            BasLift basLift = basLiftService.selectById(targetBasDevp.getLiftNo());
-            if (basLift == null) {
-                return false;//娌℃湁鎻愬崌鏈烘暟鎹�
-            }
-            if (basLift.getPoint() == null) {
-                return false;//娌℃湁璁剧疆鎻愬崌鏈虹偣浣嶅潗鏍�
-            }
-            NavigateNode liftNode = new NavigateNode(basLift.getPoint().getX(), basLift.getPoint().getY());
-            liftNode.setZ(basLift.getPoint().getZ());
+//            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
+//            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), wrkMast.getLiftNo());
+//            if (targetBasDevp == null) {
+//                return false;//缂哄皯绔欑偣淇℃伅
+//            }
+//
+//            //鑾峰彇鎻愬崌鏈烘暟鎹�
+//            BasLift basLift = basLiftService.selectById(targetBasDevp.getLiftNo());
+//            if (basLift == null) {
+//                return false;//娌℃湁鎻愬崌鏈烘暟鎹�
+//            }
+//            if (basLift.getPoint() == null) {
+//                return false;//娌℃湁璁剧疆鎻愬崌鏈虹偣浣嶅潗鏍�
+//            }
+//            NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY());
+//            liftNode.setZ(basLift.getPoint$().getZ());
 
-            //鑾峰彇灏忚溅浠庤緭閫佺珯鍒扮洰鏍囧簱浣嶅懡浠�
-            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), targetBasDevp.getLocNo(), wrkMast.getLocNo());
-            if (result.getCommands() == null) {
+            //鑾峰彇灏忚溅鍒扮洰鏍囧簱浣嶅懡浠�
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.NORMAL.id);
+            if (result == null) {
                 return false;//璺緞璁$畻澶辫触
             }
             List<NyShuttleHttpCommand> commands = result.getCommands();
@@ -2061,10 +2946,27 @@
             assignCommand.setAuto(true);//鑷姩妯″紡
             assignCommand.setCommands(commands);
             assignCommand.setNodes(result.getNodes());
+            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//婧愬簱浣�
+            assignCommand.setLocNo(wrkMast.getLocNo());//鐩爣搴撲綅
 
-            wrkMast.setWrkSts(108L);//灏忚溅绉诲姩鍒扮洰鏍囧簱浣嶄腑  107.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴� ==> 108.灏忚溅绉诲姩涓�
+            if (wrkMast.getLiftNo() != null) {
+                LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
+                if (liftThread == null) {
+                    return false;
+                }
+                LiftProtocol liftProtocol = liftThread.getLiftProtocol();
+                if (liftProtocol == null) {
+                    return false;
+                }
+                if (liftProtocol.getToken().equals(shuttleProtocol.getShuttleNo().intValue())) {
+                    liftProtocol.setToken(0);//閲婃斁鎻愬崌鏈轰护鐗�
+                }
+            }
+
+            wrkMast.setWrkSts(110L);//灏忚溅绉诲姩鍒扮洰鏍囧簱浣嶄腑  109.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴� ==> 110.灏忚溅绉诲姩涓�
             wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈�
             wrkMast.setModiTime(now);
+
             if (wrkMastMapper.updateById(wrkMast) > 0) {
                 //涓嬪彂浠诲姟
                 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
@@ -2074,6 +2976,69 @@
     }
 
     /**
+     * 灏忚溅杩佺Щ-娓呯悊111.灏忚溅绉诲姩瀹屾垚
+     */
+    private boolean shuttleMoveExecuteStepClearWrkMast(WrkMast wrkMast) {
+        if (wrkMast.getWrkSts() == 111) {
+            //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
+            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
+            if (shuttleThread == null) {
+                return false;
+            }
+            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+            if (shuttleProtocol == null) {
+                return false;
+            }
+
+            //灏忚溅澶勪簬绌洪棽鐘舵��
+            if (!shuttleProtocol.isIdleNoCharge(wrkMast.getWrkNo())) {
+                return false;
+            }
+
+            Object o = redisUtil.get("shuttle_wrk_no_" + shuttleProtocol.getTaskNo());
+            if (o != null) {
+                ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class);
+                ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand();
+                int size = assignCommand.getCommands().size();
+                NyShuttleHttpCommand command = assignCommand.getCommands().get(size - 1);//鑾峰彇鏈�鍚庝竴娈靛懡浠�
+                if (!command.getComplete()) {
+                    return false;//鏈�鍚庝竴娈靛懡浠よ繕鏈畬鎴愶紝涓嶅仛鎿嶄綔
+                }
+                NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(shuttleProtocol.getCurrentLocNo()));
+                navigateMapData.writeNavigateNodeToRedisMap(assignCommand.getNodes(), false);//瑙i攣璺緞
+
+                //鍒犻櫎redis
+                redisUtil.del("shuttle_wrk_no_" + redisCommand.getWrkNo());
+            }
+
+            // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
+            if (wrkMastLocMapper.save(wrkMast.getWrkNo()) <= 0) {
+                log.info("淇濆瓨宸ヤ綔鍘嗗彶妗workNo={0}]澶辫触", wrkMast.getWrkNo());
+            }
+            // 鍒犻櫎宸ヤ綔涓绘。
+            if (!wrkMastService.deleteById(wrkMast)) {
+                log.info("鍒犻櫎宸ヤ綔涓绘。[workNo={0}]澶辫触", wrkMast.getWrkNo());
+            }
+
+            //璁剧疆鍥涘悜绌挎杞︿负绌洪棽鐘舵��
+            shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+            //婧愬簱浣嶆竻闆�
+            shuttleProtocol.setSourceLocNo(null);
+            //鐩爣搴撲綅娓呴浂
+            shuttleProtocol.setLocNo(null);
+            //浠诲姟鎸囦护娓呴浂
+            shuttleProtocol.setAssignCommand(null);
+            //宸ヤ綔鍙锋竻闆�
+            shuttleProtocol.setTaskNo(0);
+            //娓呴櫎浠ょ墝
+            shuttleProtocol.setToken(0);
+            News.info("鍥涘悜绌挎杞﹀凡纭涓旂Щ鍔ㄤ换鍔″畬鎴愮姸鎬�,澶嶄綅銆傚洓鍚戠┛姊溅鍙�={}", shuttleProtocol.getShuttleNo());
+        }
+
+        return true;
+    }
+
+    /**
      * 鍑哄叆搴撴ā寮忓垏鎹�
      */
     public synchronized void outAndIn() {

--
Gitblit v1.9.1