From 03e68b2be24ea024eae645c47da1d4cb1773302a Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 13 十月 2023 19:47:13 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 1052 +++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 852 insertions(+), 200 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 70fc05b..5b6cae4 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,8 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.core.common.Cools;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
@@ -98,6 +100,9 @@
     private ShuttleDispatchUtils shuttleDispatchUtils;
     @Autowired
     private RedisUtil redisUtil;
+    @Autowired
+    private WrkMastLocMapper wrkMastLocMapper;
+
 
     /**
      * 缁勬墭
@@ -220,7 +225,7 @@
                         param.setBarcode(barcode);
                         param.setIoType(1);
                         param.setSourceStaNo(inSta.getStaNo());
-//                        param.setLocType1(locTypeDto.getLocType1());
+                        param.setLocType1(locTypeDto.getLocType1());
                         String response = new HttpHandler.Builder()
                                 .setUri(wmsUrl)
                                 .setPath("/rpc/pakin/loc/v1")
@@ -234,14 +239,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());
@@ -263,10 +268,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) {
@@ -401,8 +406,8 @@
                 }
                 if (staProtocol.isAutoing()
                         && staProtocol.isLoading()
-                        && (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9999)
-                        && staProtocol.getStaNo().equals(staProtocol.getSiteId().shortValue())
+//                        && (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9999)
+//                        && staProtocol.getStaNo().equals(staProtocol.getSiteId().shortValue())
                         && staProtocol.isPakMk()){
 
                     // 鑾峰彇鏉$爜鎵弿浠俊鎭�
@@ -503,12 +508,18 @@
                             }
 
                             String sourceLocNo = wrkMast.getSourceLocNo().trim();
+                            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(sourceLocNo));//鑾峰彇鍥炲簱鎻愬崌鏈虹洰鏍囩珯
+                            if (liftStaProtocol == null) {
+                                continue;
+                            }
+
                             // 鏇存柊宸ヤ綔妗f暟鎹姸鎬�
                             wrkMast.setIoType(wrkMast.getIoType() - 50); // 鍏ュ嚭搴撶被鍨�: 103->53,104->54,107->57
                             wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵��: 2.璁惧涓婅蛋
                             wrkMast.setSourceStaNo(pickSta.getStaNo()); // 婧愮珯
-                            wrkMast.setStaNo(dto.getStaNo()); // 鐩爣绔�
-                            wrkMast.setCrnNo(dto.getCrnNo());
+//                            wrkMast.setStaNo(dto.getStaNo()); // 鐩爣绔�
+//                            wrkMast.setCrnNo(dto.getCrnNo());
+                            wrkMast.setStaNo(liftStaProtocol.getStaNo());//鐩爣绔�
                             wrkMast.setLocNo(sourceLocNo); // 鐩爣搴撲綅 = 鍑哄簱鏃剁殑婧愬簱浣�
                             wrkMast.setShuttleNo(null); // 绌挎杞︽竻绌�
                             wrkMast.setModiTime(new Date());
@@ -527,14 +538,16 @@
                                 throw new CoolException("淇敼搴撲綅鐘舵�佸け璐�");
                             }
 
-                            // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
-                            staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
-                            staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
-                            devpThread.setPakMk(staProtocol.getSiteId(), false);
-                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
-                            if (!result) {
-                                News.error("鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
-                            }
+//                            // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
+//                            staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
+//                            staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
+//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
+//                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+//                            if (!result) {
+//                                News.error("鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
+//                            }
+
+                            barcodeThread.setBarcode("");//娓呯悊鏉$爜
 
                         } else if (code == 500){
                             if (ledThread != null) {
@@ -545,10 +558,10 @@
                             }
                             News.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                         } else {
-                            staProtocol.setWorkNo((short) 32002);
-                            staProtocol.setStaNo(pickSta.getBackSta().shortValue());
-                            devpThread.setPakMk(staProtocol.getSiteId(), false);
-                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+//                            staProtocol.setWorkNo((short) 32002);
+//                            staProtocol.setStaNo(pickSta.getBackSta().shortValue());
+//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
+//                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
 
                             // led 寮傚父鏄剧ず
                             if (ledThread != null) {
@@ -661,53 +674,83 @@
      * 鍏ュ簱  ===>>  鍥涘悜绌挎杞﹀叆搴撲綔涓氫笅鍙�
      */
     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;//绔欑偣淇℃伅涓嶅瓨鍦�
-                }
+        List<WrkMast> wrkMasts = wrkMastMapper.selectInStep4();
+        for (WrkMast wrkMast : wrkMasts) {
+            //鑾峰彇婧愮珯
+            BasDevp sourceBasDevp = basDevpService.selectById(wrkMast.getSourceStaNo());
+            if (sourceBasDevp == null) {
+                continue;//绔欑偣涓嶅瓨鍦�
+            }
 
-                // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢锛岃嚜鍔ㄣ�佹湁鐗┿�佸洓鍚戠┛姊溅鍙彇淇″彿
-                if (!(staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isShuttleTakeEnable())) {
-                    continue;
-                }
+            //鑾峰彇鐩爣绔�
+            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(sourceBasDevp.getLiftNo(), Utils.getLev(wrkMast.getLocNo()));
+            if (liftStaProtocol == null) {
+                continue;//绔欑偣涓嶅瓨鍦�
+            }
 
-                WrkMast wrkMast = wrkMastMapper.selectRackInStep4(workNo, staProtocol.getSiteId());
-                if (wrkMast == null) {
-                    continue;
-                }
+            // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢锛岃嚜鍔ㄣ�佺┖闂层�佹湁鐗�
+            if (!(liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && liftStaProtocol.getHasTray())) {
+                continue;
+            }
 
-                boolean step1 = this.shuttleInExecuteStep1(wrkMast, basDevp);//灏忚溅鎼叆搴撲腑
-                if (!step1) {
-                    continue;
-                }
-
+            boolean step1 = this.shuttleInExecuteStep1(wrkMast, liftStaProtocol);//灏忚溅鎼叆搴撲腑
+            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;
             }
 
@@ -728,15 +771,21 @@
                 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;
             }
@@ -783,6 +832,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;
@@ -805,21 +882,15 @@
                 return false;//灏忚溅宸茶鐙崰锛岀姝㈠啀娲惧彂浠诲姟
             }
 
-            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
-            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getLiftNo());
-            if (targetBasDevp == null) {
-                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;
             }
@@ -858,6 +929,8 @@
             }
 
             //鍥涘悜绌挎杞︾姸鎬佷负绛夊緟纭銆佸皬杞﹀浜庣┖闂茬姸鎬�
+
+
             if (shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.WAITING.id  //浠诲姟瀹屾垚绛夊緟纭
                     && shuttleProtocol.getTaskNo() != 0
                     && shuttleProtocol.getFree() == ShuttleStatusType.IDLE.id
@@ -868,14 +941,16 @@
                     switch (wrkMast.getWrkSts().intValue()) {
                         case 5://5.灏忚溅鎼繍涓� ==> 9.鍏ュ簱瀹屾垚
                             wrkMast.setWrkSts(9L);
-                            if (shuttleProtocol.getToken() == wrkMast.getWrkNo()) {
+                            shuttleProtocol.setTaskNo(0);
+                            if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
                                 //閲婃斁灏忚溅浠ょ墝
                                 shuttleProtocol.setToken(0);
                             }
                             break;
                         case 22://22.灏忚溅鎼繍涓� ==> 23.灏忚溅鎼繍瀹屾垚
                             wrkMast.setWrkSts(23L);
-                            if (shuttleProtocol.getToken() == wrkMast.getWrkNo()) {
+                            shuttleProtocol.setTaskNo(0);
+                            if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
                                 //閲婃斁灏忚溅浠ょ墝
                                 shuttleProtocol.setToken(0);
                             }
@@ -885,13 +960,15 @@
                             break;
                         case 104://104.灏忚溅杩佸叆鎻愬崌鏈轰腑 ==> 105.灏忚溅杩佸叆鎻愬崌鏈哄畬鎴�
                             wrkMast.setWrkSts(105L);
+                            shuttleProtocol.setTaskNo(0);//娓呯悊宸ヤ綔鍙�
                             break;
                         case 108://108.灏忚溅杩佸嚭鎻愬崌鏈轰腑 ==> 109.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴�
                             wrkMast.setWrkSts(109L);
                             break;
                         case 110://110.灏忚溅绉诲姩涓� ==> 111.灏忚溅绉诲姩瀹屾垚
                             wrkMast.setWrkSts(111L);
-                            if (shuttleProtocol.getToken() == wrkMast.getWrkNo()) {
+                            shuttleProtocol.setTaskNo(0);
+                            if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
                                 //閲婃斁灏忚溅浠ょ墝
                                 shuttleProtocol.setToken(0);
                             }
@@ -900,6 +977,17 @@
                     }
 
                     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);
                         //婧愬簱浣嶆竻闆�
@@ -911,6 +999,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());
                     }
                 }
 
@@ -934,6 +1040,11 @@
             }
 
             if (!liftProtocol.isIdle()) {
+                continue;
+            }
+
+            //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚﹁鍗犵敤
+            if (liftProtocol.getToken() != 0) {
                 continue;
             }
 
@@ -975,7 +1086,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;
             }
@@ -983,30 +1104,52 @@
             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());
+            if (wrkMast.getIoType() == 53) {
+                //鎷f枡鍐嶅洖搴擄紝閲嶆柊鍒嗛厤璁惧宸ヤ綔鍙�
+                Random random = new Random();
+                int deviceWrk = Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999)));//鑾峰彇璁惧宸ヤ綔鍙�
+                liftCommand.setTaskNo((short) deviceWrk);
+            }
             ArrayList<NyLiftCommand> commands = new ArrayList<>();
             commands.add(liftCommand);
 
@@ -1042,7 +1185,39 @@
 
         //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;
+            }
+
+            //鑾峰彇鍑哄簱绔欑偣(鐩爣绔�)
+            BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo());
+            if (basDevp == null) {
+                return false;//鍑哄簱绔欑偣涓嶅瓨鍦�
+            }
+
+            //鑾峰彇婧愮珯瀵瑰簲鐨勭墰鐪兼彁鍗囨満绔欑偣缂栧彿(璧风偣缂栧彿)
+            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(basDevp.getLiftNo(), Utils.getLev(wrkMast.getSourceLocNo()));
+            if (liftStaProtocol == null) {
+                return false;//鎵句笉鍒扮珯鐐�
+            }
+            Integer startSta = liftStaProtocol.getStaNo();
+
+            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+            if (shuttleProtocol.getCurrentLocNo().equals(liftStaProtocol.getLocNo())) {
+                //灏忚溅杩樺湪杈撻�佺珯鐐�
+                //璋冨害灏忚溅閬胯
+                boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getShuttleNo(), shuttleThread);
+                if (!result) {
+                    return false;
+                }
+            }
+
+            if (!basDevp.getOutEnable().equals("Y")) {
+                return false;//鍑哄簱绔欑偣涓嶅彲鍑�
+            }
+
+            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, basDevp.getLiftNo());
             if (liftThread == null) {
                 return false;
             }
@@ -1050,7 +1225,8 @@
             if (liftProtocol == null) {
                 return false;
             }
-            if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
+
+            if (!liftProtocol.isIdle()) {
                 return false;
             }
             //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚︽湭琚崰棰�
@@ -1063,16 +1239,16 @@
                 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;//缂哄皯绔欑偣淇℃伅
+            //鑾风洰鏍囩珯婧愮珯瀵瑰簲鐨勮緭閫佺珯鐐�
+            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);
@@ -1115,7 +1291,6 @@
                     && liftProtocol.getTaskNo() != 0
                     && !liftProtocol.getBusy()
             ) {
-
                 //灏嗕换鍔℃。鏍囪涓哄畬鎴�
                 WrkMast wrkMast = wrkMastMapper.selectByWorkNo324104(liftProtocol.getTaskNo().intValue());
                 if (wrkMast != null) {
@@ -1123,7 +1298,7 @@
                         case 3://3.鎻愬崌鏈烘惉杩愪腑 ==> 4.鎻愬崌鏈烘惉杩愬畬鎴�
                             wrkMast.setWrkSts(4L);
                             wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈�
-                            if (liftProtocol.getToken() == wrkMast.getWrkNo()) {
+                            if (liftProtocol.getToken().equals(wrkMast.getWrkNo())) {
                                 //閲婃斁鎻愬崌鏈轰护鐗�
                                 liftProtocol.setToken(0);
                             }
@@ -1133,10 +1308,16 @@
                             if (wrkMast.getIoType() == 11) {//搴撲綅绉昏浆
                                 wrkMast.setWrkSts(4L);//4.鎻愬崌鏈烘惉杩愬畬鎴�
                             }
-                            if (liftProtocol.getToken() == wrkMast.getWrkNo()) {
+                            if (liftProtocol.getToken().equals(wrkMast.getWrkNo())) {
                                 //閲婃斁鎻愬崌鏈轰护鐗�
                                 liftProtocol.setToken(0);
                             }
+
+                            if (wrkMast.getMk() == null || !wrkMast.getMk().equals("Y")) {
+                                //涓嶉渶瑕佺敤鍒版満姊拌噦锛岀洿鎺ヨ浆29.鍑哄簱瀹屾垚
+                                wrkMast.setWrkSts(29L);
+                            }
+
                             break;
                         case 106://106.鎻愬崌鏈烘惉杩愪腑 ==> 107.鎻愬崌鏈烘惉杩愬畬鎴�
                             wrkMast.setWrkSts(107L);
@@ -1153,8 +1334,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());
+                        }
+                    }
                 }
-
             }
         }
     }
@@ -1173,7 +1365,7 @@
         //鏌ヨ搴撲綅绉昏浆宸ヤ綔妗�
         List<WrkMast> wrkMasts1 = wrkMastMapper.selectLocToLocWrkMast();
         for (WrkMast wrkMast : wrkMasts1) {
-            if (wrkMast.getSourceLocNo().equals(wrkMast.getLocNo())) {
+            if (Utils.getLev(wrkMast.getSourceLocNo()) == Utils.getLev(wrkMast.getLocNo())) {
                 boolean step1 = this.locToLocExecuteStep1(wrkMast);//鍚屾ゼ灞傚簱浣嶇Щ杞�
                 if (!step1) {
                     continue;
@@ -1190,7 +1382,7 @@
                     continue;
                 }
 
-                boolean step4 = this.locToLocExecuteStep4(wrkMast);//璋冨害杞﹁締鍙栬揣骞惰繍閫佸埌鍑哄簱鍙�
+                boolean step4 = this.locToLocExecuteStep4(wrkMast);//璋冨害杞﹁締鍙栬揣骞惰繍閫佸埌鐩爣搴撲綅
                 if (!step4) {
                     continue;
                 }
@@ -1233,7 +1425,7 @@
             }
 
             //灏忚溅宸叉姷杈炬簮搴撲綅锛岃繘琛屾惉杩愯揣鐗�
-            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), wrkMast.getLocNo());
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getLocNo());
             if (result == null) {//璺緞璁$畻澶辫触
                 return false;
             }
@@ -1292,13 +1484,17 @@
             }
 
             //鑾峰彇绌挎杞︽渶杩戜笖绌洪棽鐨勬彁鍗囨満杈撻�佺珯鐐�
-            BasDevp liftSta = shuttleDispatchUtils.getRecentLiftSta(shuttleThread.getSlave().getId());
+            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(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), liftSta.getLocNo());
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), liftSta.getLocNo());
             if (result == null) {//璺緞璁$畻澶辫触
                 return false;
             }
@@ -1313,7 +1509,8 @@
             assignCommand.setNodes(result.getNodes());//璺緞鑺傜偣
 
             wrkMast.setWrkSts(22L);//21.鐢熸垚鍑哄簱浠诲姟 => 22.灏忚溅鎼繍涓�
-            wrkMast.setLiftNo(liftSta.getLiftNo());//璁剧疆鎻愬崌鏈哄彿
+            wrkMast.setSourceStaNo(sourceStaNo);//婧愮珯
+            wrkMast.setStaNo(staNo);//鐩爣绔�
             wrkMast.setModiTime(new Date());
             if (wrkMastMapper.updateById(wrkMast) > 0) {
                 //涓嬪彂浠诲姟
@@ -1353,16 +1550,16 @@
                 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;//缂哄皯绔欑偣淇℃伅
+            //婧愮珯
+            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, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), wrkMast.getWrkNo());
+            NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, sourceStaNo, staNo, wrkMast.getWrkNo());
 
             ArrayList<NyLiftCommand> commands = new ArrayList<>();
             commands.add(liftCommand);
@@ -1388,7 +1585,7 @@
     }
 
     /**
-     * 璺ㄦゼ灞傚簱浣嶇Щ杞�-璋冨害杞﹁締鍙栬揣骞惰繍閫佸埌鐩爣鏋悗
+     * 璺ㄦゼ灞傚簱浣嶇Щ杞�-璋冨害杞﹁締鍙栬揣骞惰繍閫佸埌鐩爣搴撲綅
      * 濡傞渶涓绘柟娉曟墽琛宑ontinue锛岃杩斿洖false
      * ps:杩斿洖鍊紅rue骞朵笉浠h〃璇ユ柟娉曟墽琛屾垚鍔燂紝杩斿洖鍊间粎鍋氭爣璁扮敤浜庝富鏂规硶鏄惁鎵цcontinue
      */
@@ -1426,7 +1623,7 @@
             }
 
             //灏忚溅宸叉姷杈剧洰鏍囪緭閫佺珯鐐癸紝灏嗚揣鐗╂惉杩愬埌鐩爣搴撲綅
-            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), targetBasDevp.getLocNo(), wrkMast.getLocNo());
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), targetBasDevp.getLocNo(), wrkMast.getLocNo());
             if (result == null) {//璺緞璁$畻澶辫触
                 return false;
             }
@@ -1441,6 +1638,7 @@
             assignCommand.setNodes(result.getNodes());//璺緞鑺傜偣
 
             wrkMast.setWrkSts(5L);//4.鎻愬崌鏈烘惉杩愬畬鎴� => 5.灏忚溅鎼繍涓�
+            wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈�
             wrkMast.setModiTime(new Date());
             if (wrkMastMapper.updateById(wrkMast) > 0) {
                 //涓嬪彂浠诲姟
@@ -1706,6 +1904,13 @@
                         }
                     }
 
+                    if (!Cools.isEmpty(barcode)) {
+                        WrkMast wrkMast = wrkMastMapper.selectByBarcode(barcode);//鏉$爜瀛樺湪宸ヤ綔妗�
+                        if (wrkMast != null) {
+                            continue;
+                        }
+                    }
+
                     LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, emptyInSta.getLed());
 
                     try {
@@ -1728,15 +1933,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");
@@ -1754,6 +1959,248 @@
                 }
 
 
+            }
+        }
+    }
+
+    /**
+     * 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) {
+                        //鍚慉GV鍙戣捣缁勬墭璇锋眰
+//                        try {
+//                            HashMap<String, Object> param = new HashMap<>();
+//                            param.put("wrkNo", wrkMast.getWrkNo());
+//                            String response = new HttpHandler.Builder()
+//                                    .setUri(wmsUrl)
+//                                    .setPath("/openAGV")
+//                                    .setJson(JSON.toJSONString(param))
+//                                    .build()
+//                                    .doPost();
+//                            JSONObject jsonObject = JSON.parseObject(response);
+//                            Integer code = jsonObject.getInteger("code");
+//                            if (code.equals(200)) {//AGV缁勬墭鎴愬姛
+//                                //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
+//                                wrkMast.setStaNo(targetSta.intValue());
+//                                wrkMast.setShuttleNo(null);//閲婃斁灏忚溅
+//                                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;
+//                                }
+//                            }
+//                        } catch (Exception e) {
+//                            e.printStackTrace();
+//                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+//                        }
+
+                        //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
+                        wrkMast.setStaNo(targetSta.intValue());
+                        wrkMast.setShuttleNo(null);//閲婃斁灏忚溅
+                        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;
+                }
+                List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
+                if (wrkDetls.isEmpty()) {
+                    continue;
+                }
+
+                if (wrkMast.getInvWh() == null) {
+                    wrkMast.setInvWh("Y");//鏍囪宸茬粡涓嬪彂鏈烘鑷備换鍔�
+                    if (wrkMastMapper.updateById(wrkMast) > 0) {
+                        RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetls.size(), "303");
+                    }
+                }
+            }else if (staProtocol317.isAutoing() && staProtocol317.isLoading() && staProtocol317.getWorkNo() != 0) {
+                //璋冨害鏈烘鑷�
+                //鏌ヨ鏄惁鏈夊伐浣滄。
+                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol317.getWorkNo().intValue());
+                if (wrkMast == null) {
+                    continue;
+                }
+                List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
+                if (wrkDetls.isEmpty()) {
+                    continue;
+                }
+                if (wrkMast.getInvWh() == null) {
+                    wrkMast.setInvWh("Y");//鏍囪宸茬粡涓嬪彂鏈烘鑷備换鍔�
+                    if (wrkMastMapper.updateById(wrkMast) > 0) {
+                        RobotUtils.sendTask(staProtocol317.getWorkNo().toString(), wrkDetls.size(), "317");
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * AGV琛ヨ揣(閫氱煡AGV鍙栬揣)
+     */
+    public void agvRestockInto() {
+        //妫�娴�309鍜�312绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗�
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            // 鑾峰彇鍏ュ簱绔欎俊鎭�
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+            StaProtocol staProtocol309 = devpThread.getStation().get(309);
+            StaProtocol staProtocol312 = devpThread.getStation().get(312);
+            if (staProtocol309 == null || staProtocol312 == null) {
+                continue;
+            }
+
+            if (staProtocol309.isAutoing() && staProtocol309.isLoading()) {
+                // 鑾峰彇鏉$爜鎵弿浠俊鎭�
+                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 11);//308绔欐潯鐮佸櫒
+                if (barcodeThread == null) {
+                    continue;
+                }
+                String barcode = barcodeThread.getBarcode();
+                if(!Cools.isEmpty(barcode)) {
+                    //閫氱煡AGV鍙栬揣
+                    agvRestockCall("CS-301-001-01@3", barcode);
+                }
+            } else if (staProtocol312.isAutoing() && staProtocol312.isLoading()) {
+                // 鑾峰彇鏉$爜鎵弿浠俊鎭�
+                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 12);//311绔欐潯鐮佸櫒
+                if (barcodeThread == null) {
+                    continue;
+                }
+                String barcode = barcodeThread.getBarcode();
+                if(!Cools.isEmpty(barcode)) {
+                    //閫氱煡AGV鍙栬揣
+                    agvRestockCall("CS-302-001-01@3", barcode);
+                }
+            }
+        }
+    }
+
+    //閫氱煡AGV鍙栬揣
+    private boolean agvRestockCall(String staNo, String barcode) {
+        try {
+            HashMap<String, Object> param = new HashMap<>();
+            param.put("staNo", staNo);
+            param.put("barcode", barcode);
+            String response = new HttpHandler.Builder()
+                    .setUri(wmsUrl)
+                    .setPath("/callAGV")
+                    .setJson(JSON.toJSONString(param))
+                    .build()
+                    .doPost();
+            JSONObject jsonObject = JSON.parseObject(response);
+            Integer code = jsonObject.getInteger("code");
+            if (code.equals(200)) {//鍛煎彨AGV
+                return true;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+        }
+        return false;
+    }
+
+    // 300绔欐嫞鏂�
+    public void pick300() {
+        //妫�娴�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) {
+                    Integer sourceStaNo = wrkMast.getSourceStaNo();//婧愮珯
+                    Integer staNo = wrkMast.getStaNo();//鐩爣绔�
+                    //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
+                    wrkMast.setStaNo(sourceStaNo);
+                    wrkMast.setSourceStaNo(staNo);
+                    if (wrkMastMapper.updateById(wrkMast) > 0) {
+                        //鍚�300绔欏啓鍏ョ洰鏍囩珯
+                        staProtocol = staProtocol.clone();
+                        staProtocol.setStaNo(wrkMast.getStaNo().shortValue());//绉诲姩鍒扮洰鏍囩珯
+                        boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+                        try {
+                            Thread.sleep(500);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
             }
         }
     }
@@ -1944,11 +2391,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;
+                    }
                 }
             }
 
@@ -1971,7 +2446,6 @@
                 continue;
             }
 
-            shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING);//鍏呯數涓�
             News.info("淇濆瓨{}鍙峰洓鍚戠┛姊溅鍏呯數浠诲姟鎴愬姛!!!", shuttle.getId());
         }
     }
@@ -1996,6 +2470,10 @@
             }
 
             if (wrkCharge.getWrkSts() == 51) {
+                if (!shuttleProtocol.isIdleNoCharge()) {
+                    continue;
+                }
+
                 if (!shuttleProtocol.getCurrentLocNo().equals(wrkCharge.getLocNo())) {
                     //灏忚溅涓嶅湪鍏呯數妗╀綅缃�
                     shuttleDispatchUtils.dispatchShuttle(wrkCharge.getWrkNo(), wrkCharge.getLocNo(), shuttle.getId());//璋冨害灏忚溅鍘诲厖鐢垫々
@@ -2022,7 +2500,8 @@
                 }
             } else if (wrkCharge.getWrkSts() == 52) {
                 //妫�娴嬪皬杞︽槸鍚︽弧鐢�
-                if (shuttleProtocol.getPowerPercent() < 100) {
+                int maxPower = 95;
+                if (shuttleProtocol.getPowerPercent() < maxPower) {
                     continue;
                 }
 
@@ -2038,21 +2517,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) {
+
+                    }
+                }
             }
 
         }
@@ -2091,6 +2583,8 @@
                 continue;
             }
 
+//            this.shuttleMoveExecuteStepClearWrkMast(wrkMast);//娓呯悊111.灏忚溅绉诲姩瀹屾垚
+
         }
     }
 
@@ -2116,7 +2610,7 @@
             }
 
             //灏忚溅澶勪簬绌洪棽鐘舵��
-            if (!shuttleProtocol.isIdleNoCharge()) {
+            if (!shuttleProtocol.isIdleNoCharge(wrkMast.getWrkNo())) {
                 return false;
             }
 
@@ -2137,14 +2631,20 @@
                 return false;
             }
 
-            //鑾峰彇鐩爣杈撻�佺珯
-            BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo());
-            if (basDevp == null) {
-                return false;//鎵句笉鍒拌緭閫佺珯鐐�
+            //鑾峰彇婧愯緭閫佺珯
+            LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
+            if (liftSta == null) {
+                return false;//鎵句笉鍒扮珯鐐�
+            }
+
+            //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟(璇ヤ换鍔¢渶瑕佹崲灞傚繀椤绘彁鍓嶇嫭鍗犳彁鍗囨満)
+            WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftSta.getLiftNo());
+            if (liftWrkMast != null) {
+                return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇�
             }
 
             //鑾峰彇灏忚溅鍒拌緭閫佺珯鐐硅璧板懡浠�
-            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), basDevp.getLocNo());
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), liftSta.getLocNo(), NavigationMapType.NORMAL.id);
             List<NyShuttleHttpCommand> commands = result.getCommands();
 
             ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
@@ -2157,6 +2657,7 @@
 
             wrkMast.setWrkSts(102L);//灏忚溅绉诲姩鍒版彁鍗囨満涓�  101.鐢熸垚灏忚溅绉诲簱浠诲姟 ==> 102.灏忚溅绉诲姩鑷崇珯鐐�
             wrkMast.setModiTime(now);
+            wrkMast.setLiftNo(liftSta.getLiftNo());//鎻愬墠閿佸畾鎻愬崌鏈�
             shuttleProtocol.setToken(wrkMast.getWrkNo());//鐙崰璇ュ皬杞︿护鐗�
             if (wrkMastMapper.updateById(wrkMast) > 0) {
                 //涓嬪彂浠诲姟
@@ -2179,14 +2680,20 @@
 
         //灏忚溅绉诲姩鍒版彁鍗囨満涓�  103.灏忚溅绉诲姩鑷崇珯鐐瑰畬鎴� ==> 104.灏忚溅杩佸叆鎻愬崌鏈轰腑
         if (wrkMast.getWrkSts() == 103) {
+            //鑾峰彇婧愮珯
+            LiftStaProtocol sourceLiftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getSourceStaNo());
+            if (sourceLiftSta == null) {
+                return false;//鎵句笉鍒扮珯鐐�
+            }
+
             //鑾峰彇鐩爣杈撻�佺珯
-            BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo());
-            if (basDevp == null) {
-                return false;//鎵句笉鍒拌緭閫佺珯鐐�
+            LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
+            if (liftSta == null) {
+                return false;//鎵句笉鍒扮珯鐐�
             }
 
             //鑾峰彇鎻愬崌鏈烘暟鎹�
-            BasLift basLift = basLiftService.selectById(basDevp.getLiftNo());
+            BasLift basLift = basLiftService.selectById(liftSta.getLiftNo());
             if (basLift == null) {
                 return false;//娌℃湁鎻愬崌鏈烘暟鎹�
             }
@@ -2198,10 +2705,12 @@
             //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟
             WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(basLift.getLiftNo());
             if (liftWrkMast != null) {
-                return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇�
+                if (!liftWrkMast.getWrkNo().equals(wrkMast.getWrkNo())) {//鎻愬崌鏈轰换鍔″拰褰撳墠浠诲姟涓嶇浉鍚�
+                    return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇�
+                }
             }
 
-            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, basDevp.getLiftNo());
+            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSta.getLiftNo());
             if (liftThread == null) {
                 return false;
             }
@@ -2209,6 +2718,7 @@
             if (liftProtocol == null) {
                 return false;
             }
+
             if (!liftProtocol.isIdle(wrkMast.getWrkNo().shortValue())) {
                 return false;
             }
@@ -2224,7 +2734,12 @@
             }
 
             //灏忚溅澶勪簬绌洪棽鐘舵��
-            if (!shuttleProtocol.isIdleNoCharge()) {
+            if (!shuttleProtocol.isIdleNoCharge(wrkMast.getWrkNo())) {
+                return false;
+            }
+
+            //灏忚溅浠ょ墝鏄惁琚换鍔$嫭鍗�
+            if (!shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
                 return false;
             }
 
@@ -2233,10 +2748,16 @@
                 //鎻愬崌鏈轰笉鍦ㄥ皬杞︽ゼ灞�
                 //璋冨害鎻愬崌鏈�
 
-                //鑾峰彇婧愮珯瀵瑰簲鐨勮緭閫佺珯鐐�
-                BasDevp sourceBasDevp = basDevpService.selectByLevAndLiftNo(liftProtocol.getLev().intValue(), liftProtocol.getLiftNo().intValue());
-                //鑾峰彇鎻愬崌鏈哄懡浠�
-                NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceBasDevp.getDevNo(), basDevp.getDevNo(), wrkMast.getWrkNo());
+                if (liftProtocol.getToken() != 0) {
+                    return false;//鎻愬崌鏈轰护鐗岃鍗犵敤
+                }
+
+                //鑾峰彇鎻愬崌鏈哄懡浠わ紝璋冨害鎻愬崌鏈哄埌婧愮珯浣嶇疆
+                NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceLiftSta.getStaNo(), sourceLiftSta.getStaNo(), wrkMast.getWrkNo());
+
+                Random random = new Random();
+                int deviceWrk = Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999)));//鑾峰彇璁惧宸ヤ綔鍙�
+                liftCommand.setTaskNo((short) deviceWrk);//鏇存崲闅忔満浠诲姟鍙�
 
                 ArrayList<NyLiftCommand> commands = new ArrayList<>();
                 commands.add(liftCommand);
@@ -2247,6 +2768,7 @@
                 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);
@@ -2258,22 +2780,28 @@
                 return false;//绛夊緟鎻愬崌鏈哄埌灏忚溅妤煎眰
             }
 
+            if (liftProtocol.getToken() == 0) {//鎻愬崌鏈轰护鐗屾湭琚崰鐢�
+                //鐙崰鎻愬崌鏈�
+                liftProtocol.setToken(wrkMast.getShuttleNo());
+                return false;//绛夊緟涓嬩竴娆℃墽琛�
+            }
+
             //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚︿负褰撳墠灏忚溅
-            if (liftProtocol.getToken() != wrkMast.getShuttleNo()) {
+            if (!liftProtocol.getToken().equals(wrkMast.getShuttleNo())) {
                 return false;//鎻愬崌鏈哄凡琚嫭鍗狅紝绂佹鍐嶆淳鍙戜换鍔�
             }
 
             //鍒ゆ柇灏忚溅鏄惁涓哄綋鍓嶄换鍔$嫭鍗�
-            if (shuttleProtocol.getToken() != wrkMast.getWrkNo()) {
+            if (!shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
                 return false;
             }
 
             //绔欑偣鑺傜偣
-            NavigateNode staNode = NavigatePositionConvert.locNoToNode(basDevp.getLocNo());
+            NavigateNode staNode = NavigatePositionConvert.locNoToNode(sourceLiftSta.getLocNo());
 
             //鎻愬崌鏈鸿妭鐐�
             NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY());
-            liftNode.setZ(basLift.getPoint$().getZ());
+            liftNode.setZ(staNode.getZ());
 
             //鑾峰彇灏忚溅杩涙彁鍗囨満琛岃蛋鍛戒护
             NyShuttleHttpCommand moveCommand = NyHttpUtils.getInOutLiftCommand(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), staNode, liftNode, true);
@@ -2293,6 +2821,8 @@
 
             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.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
@@ -2327,9 +2857,22 @@
             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() != wrkMast.getShuttleNo()) {
+            if (!liftProtocol.getToken().equals(wrkMast.getShuttleNo())) {
                 return false;//鎻愬崌鏈轰护鐗屽拰褰撳墠灏忚溅涓嶄竴鑷达紝绂佹娲惧彂
+            }
+
+            //鍒ゆ柇鎻愬崌鏈哄唴鏄惁鏈夊皬杞�
+            if (!liftProtocol.getHasCar()) {
+                return false;//鎻愬崌鏈哄唴鏃犲皬杞�
             }
 
             //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
@@ -2348,20 +2891,20 @@
             }
 
             //鍒ゆ柇灏忚溅鏄惁涓哄綋鍓嶄换鍔$嫭鍗�
-            if (shuttleProtocol.getToken() != wrkMast.getWrkNo()) {
+            if (!shuttleProtocol.getToken().equals(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) {
+            //鑾峰彇婧愮珯
+            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, sourceBasDevp.getDevNo(), targetBasDevp.getDevNo(), wrkMast.getWrkNo());
+            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);
@@ -2408,8 +2951,16 @@
                 return false;
             }
 
+            //鍒ゆ柇鎻愬崌鏈烘槸鍚︽湁鍏朵粬浠诲姟
+            WrkMast liftWrkMast = wrkMastMapper.selectLiftWrkMast(liftThread.getSlave().getId());
+            if (liftWrkMast != null) {
+                if (!liftWrkMast.getWrkNo().equals(wrkMast.getWrkNo())) {//鎻愬崌鏈轰换鍔″拰褰撳墠浠诲姟涓嶇浉鍚�
+                    return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇�
+                }
+            }
+
             //鍒ゆ柇鎻愬崌鏈轰护鐗屾槸鍚︿负褰撳墠灏忚溅
-            if (liftProtocol.getToken() != wrkMast.getShuttleNo()) {
+            if (!liftProtocol.getToken().equals(wrkMast.getShuttleNo())) {
                 return false;//鎻愬崌鏈轰护鐗屽拰褰撳墠灏忚溅涓嶄竴鑷达紝绂佹娲惧彂
             }
 
@@ -2429,14 +2980,14 @@
             }
 
             //鍒ゆ柇灏忚溅鏄惁涓哄綋鍓嶄换鍔$嫭鍗�
-            if (shuttleProtocol.getToken() != wrkMast.getWrkNo()) {
+            if (!shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
                 return false;
             }
 
-            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
-            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), liftProtocol.getLiftNo().intValue());
-            if (targetBasDevp == null) {
-                return false;//缂哄皯绔欑偣淇℃伅
+            //鑾峰彇鐩爣绔�
+            LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
+            if (liftSta == null) {
+                return false;//鎵句笉鍒扮珯鐐�
             }
 
             //鑾峰彇鎻愬崌鏈烘暟鎹�
@@ -2448,11 +2999,15 @@
                 return false;//娌℃湁璁剧疆鎻愬崌鏈虹偣浣嶅潗鏍�
             }
             NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY());
-            liftNode.setZ(basLift.getPoint$().getZ());
+            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();
@@ -2487,15 +3042,6 @@
         //灏忚溅绉诲姩鍒扮洰鏍囧簱浣嶄腑  109.灏忚溅杩佸嚭鎻愬崌鏈哄畬鎴� ==> 110.灏忚溅绉诲姩涓�
         if (wrkMast.getWrkSts() == 109) {
 
-            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
-            if (liftThread == null) {
-                return false;
-            }
-            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
-            if (liftProtocol == null) {
-                return false;
-            }
-
             //鑾峰彇鍥涘悜绌挎杞︾嚎绋�
             NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
             if (shuttleThread == null) {
@@ -2507,34 +3053,61 @@
             }
 
             //灏忚溅澶勪簬绌洪棽鐘舵��
-            if (!shuttleProtocol.isIdleNoCharge()) {
+            if (!shuttleProtocol.isIdleNoCharge(wrkMast.getWrkNo())) {
                 return false;
             }
 
             //鍒ゆ柇灏忚溅浠ょ墝鏄惁涓哄綋鍓嶄换鍔�
-            if (shuttleProtocol.getToken() != wrkMast.getWrkNo()) {
+            if (shuttleProtocol.getToken() != 0 && !shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
                 return false;
             }
 
-            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
-            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), wrkMast.getLiftNo());
-            if (targetBasDevp == null) {
-                return false;//缂哄皯绔欑偣淇℃伅
+//            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
+//            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());
+
+            //灏忚溅宸茬粡鍦ㄧ洰鏍囧簱浣嶏紝鐩存帴璁ゅ畾灏忚溅绉诲姩浠诲姟瀹屾垚
+            if (shuttleProtocol.getCurrentLocNo().equals(wrkMast.getLocNo())) {
+                if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
+                    //閲婃斁灏忚溅浠ょ墝
+                    shuttleProtocol.setToken(0);
+                }
+                wrkMast.setWrkSts(111L);//111.灏忚溅绉诲姩瀹屾垚
+                wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈�
+                wrkMast.setModiTime(now);
+                wrkMastMapper.updateById(wrkMast);
+
+                shuttleProtocol.setShuttleNo((short) 0);//閲婃斁灏忚溅
+                shuttleProtocol.setToken(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());
+                    }
+                }
+                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());
+            //鑾峰彇灏忚溅鍒扮洰鏍囧簱浣嶅懡浠�
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.NORMAL.id);
             if (result == null) {
                 return false;//璺緞璁$畻澶辫触
             }
@@ -2547,11 +3120,27 @@
             assignCommand.setAuto(true);//鑷姩妯″紡
             assignCommand.setCommands(commands);
             assignCommand.setNodes(result.getNodes());
+            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//婧愬簱浣�
+            assignCommand.setLocNo(wrkMast.getLocNo());//鐩爣搴撲綅
+
+            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);
-            liftProtocol.setToken(0);//閲婃斁鎻愬崌鏈轰护鐗�
+
             if (wrkMastMapper.updateById(wrkMast) > 0) {
                 //涓嬪彂浠诲姟
                 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
@@ -2561,6 +3150,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