From 4267b157278462ff6fd84bd0262fb50f641cdc83 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期三, 13 八月 2025 14:14:20 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 1090 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 822 insertions(+), 268 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 1381343..11b6336 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -6,6 +6,7 @@
 import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.core.common.Cools;
 import com.core.common.DateUtils;
+import com.core.common.R;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.mapper.BasCrnErrorMapper;
@@ -61,7 +62,6 @@
  */
 @Slf4j
 @Service("mainService")
-@Transactional
 public class MainServiceImpl {
 
     public static final long COMMAND_TIMEOUT = 5 * 1000;
@@ -130,7 +130,7 @@
                 LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
 
                 // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢
-                if (!staProtocol.isLoading()){
+                if (!staProtocol.isLoading()) {
                     continue;
                 }
 
@@ -138,18 +138,18 @@
                         && staProtocol.isInEnable()
                         && !staProtocol.isEmptyMk()
                         && staProtocol.getWorkNo() == 9999
-                        && staProtocol.isPakMk()) {
-                    News.warnNoLog(""+mark+" - 0"+" - 寮�濮嬫墽琛�");
+                        && staProtocol.isPakMk() && (staProtocol.getEmptyInType() != 1 && staProtocol.getEmptyInType() != 2)) {
+                    News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�");
 
                     String barcode = barcodeThread.getBarcode();
-                    if(!Cools.isEmpty(barcode)) {
-                        News.info(""+mark+" - 1"+" - {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", inSta.getBarcode(), barcode);
-                        if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
+                    if (!Cools.isEmpty(barcode)) {
+                        News.info("" + mark + " - 1" + " - {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", inSta.getBarcode(), barcode);
+                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
 //                            staProtocol.setWorkNo((short) 9992);
 //                            staProtocol.setStaNo(inSta.getBackSta().shortValue());
 //                            devpThread.setPakMk(staProtocol.getSiteId(), false);
 //                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
-                            News.info(""+mark+" - 2"+" - 鎵爜澶辫触1 ===>> {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{},绔欑偣:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
+                            News.info("" + mark + " - 2" + " - 鎵爜澶辫触1 ===>> {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{},绔欑偣:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
                             // led 寮傚父鏄剧ず
                             if (ledThread != null) {
                                 String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯";
@@ -163,7 +163,7 @@
 //                        devpThread.setPakMk(staProtocol.getSiteId(), false);
 //                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
 
-                        News.info(""+mark+" - 3"+" - 鎵爜澶辫触2 ===>> {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{},绔欑偣:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
+                        News.info("" + mark + " - 3" + " - 鎵爜澶辫触2 ===>> {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{},绔欑偣:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
                         // led 寮傚父鏄剧ず
                         if (ledThread != null) {
                             String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯";
@@ -176,13 +176,13 @@
                     WrkMast wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
                     //杩囨护鍒ゆ柇锛岄槻姝㈡嫞鏂欏啀鍏ュ簱璐х墿锛岀粡杩囧叆搴撶珯鍐嶅叆搴撴椂锛岃閫�鍥炲埌閫�搴撶珯
                     WrkMast wrkMast1 = wrkMastMapper.selectPakInStepBarcode(barcode);
-                    if (wrkMast1 !=null){
-                        if (wrkMast1.getIoType()==103 || wrkMast1.getIoType()==107 || wrkMast1.getIoType()==104){
+                    if (wrkMast1 != null) {
+                        if (wrkMast1.getIoType() == 103 || wrkMast1.getIoType() == 107 || wrkMast1.getIoType() == 104) {
                             continue;
                         }
                     }
                     if (wrkMast != null) {
-                        News.error(""+mark+" - 4"+" - 宸ヤ綔妗d腑宸插瓨鍦ㄨ绔欑姸鎬佷负锛� 2.璁惧涓婅蛋 锛夌殑鏁版嵁,宸ヤ綔鍙�={}", wrkMast.getWrkNo());
+                        News.error("" + mark + " - 4" + " - 宸ヤ綔妗d腑宸插瓨鍦ㄨ绔欑姸鎬佷负锛� 2.璁惧涓婅蛋 锛夌殑鏁版嵁,宸ヤ綔鍙�={}", wrkMast.getWrkNo());
 //                        staProtocol.setWorkNo((short)9992);
 //                        staProtocol.setStaNo(inSta.getBackSta().shortValue());
 //                        devpThread.setPakMk(staProtocol.getSiteId(), false);
@@ -206,7 +206,7 @@
                                 .in("sta_no", 1003, 1007)
                         );
                         if (!wrkMasts.isEmpty()) {
-                            News.error(""+mark+" - 4"+" - 1003绔欏叆搴擄紝妫�娴嬪瓨鍦ㄥ嚭搴撲换鍔★紝绛夊緟鍑哄簱浠诲姟鎵ц瀹屾垚,鎵樼洏鐮�={}", barcode);
+                            News.error("" + mark + " - 4" + " - 1003绔欏叆搴擄紝妫�娴嬪瓨鍦ㄥ嚭搴撲换鍔★紝绛夊緟鍑哄簱浠诲姟鎵ц瀹屾垚,鎵樼洏鐮�={}", barcode);
                             continue;
                         }
                     }
@@ -263,7 +263,7 @@
 ////                                ledThread.errorReset();
 //                            }
                         } else {
-                            News.error(""+mark+" - 5"+" - 璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
+                            News.error("" + mark + " - 5" + " - 璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
 //                            staProtocol.setWorkNo((short)9992);
 //                            staProtocol.setStaNo(inSta.getBackSta().shortValue());
 //                            devpThread.setPakMk(staProtocol.getSiteId(), false);
@@ -284,15 +284,15 @@
                         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                     }
 
-                }else {
-                    News.errorNoLog(""+mark+" - 6"+" - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒"+" 鑷姩淇″彿锛�"+staProtocol.isAutoing()+"銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable()
-                            +"銆佺┖鏉夸俊鍙凤細"+ staProtocol.isEmptyMk()+"銆佸伐浣滃彿锛�" + staProtocol.getWorkNo()
-                            +"銆侀攣瀹氭爣璁�"+ staProtocol.isPakMk());
+                } else {
+                    News.errorNoLog("" + mark + " - 6" + " - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒" + " 鑷姩淇″彿锛�" + staProtocol.isAutoing() + "銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable()
+                            + "銆佺┖鏉夸俊鍙凤細" + staProtocol.isEmptyMk() + "銆佸伐浣滃彿锛�" + staProtocol.getWorkNo()
+                            + "銆侀攣瀹氭爣璁�" + staProtocol.isPakMk());
                 }
 
             }
         }
-        News.infoNoLog(""+mark+" - 0"+" - 缁勬墭  ===銆嬫墽琛屽畬鎴�");
+        News.infoNoLog("" + mark + " - 0" + " - 缁勬墭  ===銆嬫墽琛屽畬鎴�");
 
     }
 
@@ -315,7 +315,7 @@
                 }
 
                 // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢
-                if (!staProtocol.isLoading()){
+                if (!staProtocol.isLoading()) {
                     continue;
                 }
 
@@ -324,7 +324,7 @@
                         && !staProtocol.isEmptyMk()
                         && staProtocol.getWorkNo() > 0
                         && staProtocol.isPakMk()) {
-                    News.warnNoLog(""+mark+" - 0"+" - 寮�濮嬫墽琛�");
+                    News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�");
                     // 鍒ゆ柇閲嶅宸ヤ綔妗�
                     WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo());
                     if (wrkMast == null) {
@@ -343,20 +343,20 @@
                         wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵�侊細2.璁惧涓婅蛋
                         wrkMast.setModiTime(new Date());
                         if (wrkMastMapper.updateById(wrkMast) == 0) {
-                            News.error(""+mark+" - 1"+" - 鏇存柊宸ヤ綔妗eけ璐ワ紒锛侊紒 [宸ヤ綔鍙凤細{}]", wrkMast.getWrkNo());
+                            News.error("" + mark + " - 1" + " - 鏇存柊宸ヤ綔妗eけ璐ワ紒锛侊紒 [宸ヤ綔鍙凤細{}]", wrkMast.getWrkNo());
                         }
                     } else {
-                        News.error(""+mark+" - 2"+" - 鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
+                        News.error("" + mark + " - 2" + " - 鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
                     }
 
-                }else {
-                    News.errorNoLog(""+mark+" - 6"+" - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒"+" 鑷姩淇″彿锛�"+staProtocol.isLoading()+"銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable()
-                            +"銆佺┖鏉夸俊鍙凤細"+ staProtocol.isEmptyMk()+"銆佸伐浣滃彿锛�" + staProtocol.getWorkNo()
-                            +"銆侀攣瀹氭爣璁�"+ staProtocol.isPakMk());
+                } else {
+                    News.errorNoLog("" + mark + " - 6" + " - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒" + " 鑷姩淇″彿锛�" + staProtocol.isLoading() + "銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable()
+                            + "銆佺┖鏉夸俊鍙凤細" + staProtocol.isEmptyMk() + "銆佸伐浣滃彿锛�" + staProtocol.getWorkNo()
+                            + "銆侀攣瀹氭爣璁�" + staProtocol.isPakMk());
                 }
             }
         }
-        News.infoNoLog(""+mark+" - 0"+" - wms鍏ュ簱  ===銆嬫墽琛屽畬鎴�");
+        News.infoNoLog("" + mark + " - 0" + " - wms鍏ュ簱  ===銆嬫墽琛屽畬鎴�");
 
     }
 
@@ -381,7 +381,7 @@
                         && staProtocol.isInEnable()
                         && staProtocol.getWorkNo() > 0
                         && staProtocol.isPakMk()) {
-                    News.warnNoLog(""+mark+" - 0"+" - 寮�濮嬫墽琛�");
+                    News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�");
 
 //                    // 鑾峰彇鏉$爜鎵弿浠俊鎭�
 //                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
@@ -434,7 +434,7 @@
                         LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed());
                         // led 寮傚父鏄剧ず
                         if (ledThread != null) {
-                            String errorMsg = "姝や负鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱.璇锋斁鍦�"+pickSta.getBackSta().shortValue()+"绔欑偣";
+                            String errorMsg = "姝や负鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱.璇锋斁鍦�" + pickSta.getBackSta().shortValue() + "绔欑偣";
                             MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(5, errorMsg));
                         }
                         continue;
@@ -462,6 +462,7 @@
                         wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 鐩爣搴撲綅 = 鍑哄簱鏃剁殑婧愬簱浣�
                         wrkMast.setSourceLocNo(""); // 婧愬簱浣嶆竻绌�
                         wrkMast.setModiTime(now);
+                        wrkMast.setUpdMk("");//鍏佽鍐嶆绉诲簱
                         if (wrkMastMapper.updateById(wrkMast) == 0) {
                             throw new CoolException("鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
                         }
@@ -488,94 +489,234 @@
                     devpThread.setPakMk(staProtocol.getSiteId(), false);
                     boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                     if (!result) {
-                        News.error(""+mark+" - 3"+" - 鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
+                        News.error("" + mark + " - 3" + " - 鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
                     }
 
-                }else {
-                    News.errorNoLog(""+mark+" - 6"+" - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒"+" 鑷姩淇″彿锛�"+staProtocol.isLoading()+"銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable()
-                            +"銆佺┖鏉夸俊鍙凤細"+ staProtocol.isEmptyMk());
+                } else {
+                    News.errorNoLog("" + mark + " - 6" + " - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒" + " 鑷姩淇″彿锛�" + staProtocol.isLoading() + "銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable()
+                            + "銆佺┖鏉夸俊鍙凤細" + staProtocol.isEmptyMk());
                 }
 
             }
 
         }
-        News.infoNoLog(""+mark+" - 0"+" - 鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱  ===銆嬫墽琛屽畬鎴�");
+        News.infoNoLog("" + mark + " - 0" + " - 鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱  ===銆嬫墽琛屽畬鎴�");
+    }
+
+    /**
+     * 鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱-鏉$爜
+     */
+    public synchronized void stnToCrnStnPickBarcode(Integer mark) {
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            // 閬嶅巻鎷f枡鍏ュ簱鍙�
+            for (DevpSlave.Sta insta : devp.getInSta()) {
+                // 鑾峰彇鎷f枡鍏ュ簱绔欎俊鎭�
+                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+                StaProtocol staProtocol = devpThread.getStation().get(insta.getStaNo());
+                if (staProtocol == null) {
+                    continue;
+                } else {
+                    staProtocol = staProtocol.clone();
+                }
+
+                if (staProtocol.isAutoing()
+                        && staProtocol.isLoading()
+                        && staProtocol.isInEnable()
+                        && staProtocol.getWorkNo() > 0
+                        && staProtocol.isPakMk()) {
+                    News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�");
+
+                    // 鑾峰彇鏉$爜鎵弿浠俊鎭�
+                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, insta.getBarcode());
+                    if (barcodeThread == null) {
+                        continue;
+                    }
+                    String barcode = barcodeThread.getBarcode();
+                    if (!Cools.isEmpty(barcode)) {
+                        News.info("" + mark + " - 1" + " - {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", insta.getBarcode(), barcode);
+                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
+                            continue;
+                        }
+                    } else {
+                        continue;
+                    }
+
+                    WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode);
+                    if (wrkMast == null) {
+                        // 鏃犳嫞鏂欐暟鎹�
+                        continue;
+                    }
+                    if ((wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107)
+                            || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo())) {
+                        continue;
+                    }
+
+                    // 鎷c�佺洏銆佸苟 浣滀笟绔欒浆鎹�
+//                    int stnNo = 0;
+//                    if (wrkMast.getStaNo() == 109) {
+//                        stnNo = 127;
+//                    } else if (wrkMast.getStaNo() == 113) {
+//                        stnNo = 128;
+//                    } else {
+//                        log.error("{}鍙蜂换鍔℃暟鎹紓甯革紒", wrkMast.getWrkNo());
+//                    }
+                    // 鑾峰彇鐩爣绔�
+                    Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
+                            .eq("type_no", wrkMast.getIoType() - 50)
+                            .eq("stn_no", insta.getStaNo()) // 浣滀笟绔欑偣 = 鎷f枡鍑哄簱鐨勭洰鏍囩珯
+                            .eq("crn_no", wrkMast.getCrnNo()); // 鍫嗗灈鏈哄彿
+                    StaDesc staDesc = staDescService.selectOne(wrapper);
+                    if (Cools.isEmpty(staDesc)) {
+//                        News.error(""+mark+" - 2"+" - 鍏ュ簱璺緞涓嶅瓨鍦紒type_no={},stn_no={},crn_no={}", wrkMast.getIoType(), pickSta.getStaNo(), wrkMast.getCrnNo());
+//                        staProtocol.setWorkNo((short) 9989);
+//                        staProtocol.setStaNo((short) (pickSta.getStaNo().shortValue()-(short)1));
+//                        devpThread.setPakMk(staProtocol.getSiteId(), false);
+//                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+                        //LED
+                        LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, insta.getLed());
+                        // led 寮傚父鏄剧ず
+                        if (ledThread != null) {
+                            String errorMsg = "姝や负鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱.璇锋斁鍦�" + insta.getBackSta().shortValue() + "绔欑偣";
+                            MessageQueue.offer(SlaveType.Led, insta.getLed(), new Task(5, errorMsg));
+                        }
+                        continue;
+                    }
+
+                    try {
+                        // 淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。
+                        if (wrkMastMapper.saveWrkDetlLog(wrkMast.getWrkNo()) == 0) {
+                            throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。澶辫触");
+                        }
+                        // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
+                        if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
+                            throw new CoolException("淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗eけ璐�");
+                        }
+
+                        Date now = new Date();
+                        // 鍫嗗灈鏈虹珯鐐�(鐩爣绔�)
+                        Integer staNo = staDesc.getCrnStn();
+                        // 鏇存柊宸ヤ綔妗f暟鎹姸鎬�
+                        wrkMast.setIoTime(now);
+                        wrkMast.setIoType(wrkMast.getIoType() - 50); // 鍏ュ嚭搴撶被鍨�: 103->53,104->54,107->57
+                        wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵��: 2.璁惧涓婅蛋
+                        wrkMast.setSourceStaNo(wrkMast.getStaNo()); // 婧愮珯
+                        wrkMast.setStaNo(staNo); // 鐩爣绔�
+                        wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 鐩爣搴撲綅 = 鍑哄簱鏃剁殑婧愬簱浣�
+                        wrkMast.setSourceLocNo(""); // 婧愬簱浣嶆竻绌�
+                        wrkMast.setModiTime(now);
+                        wrkMast.setUpdMk("");//鍏佽鍐嶆绉诲簱
+                        if (wrkMastMapper.updateById(wrkMast) == 0) {
+                            throw new CoolException("鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
+                        }
+                        // 鏇存柊鏄庣粏妗o_time (鍘嗗彶妗e叧鑱斾娇鐢級
+                        wrkDetlService.updateIoTime(wrkMast.getWrkNo(), now);
+                        // 淇敼搴撲綅鐘舵�� Q.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴�
+                        LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
+                        locMast.setLocSts("Q");
+                        locMast.setModiTime(new Date());
+                        if (!locMastService.updateById(locMast)) {
+                            throw new CoolException("淇敼搴撲綅鐘舵�佸け璐�");
+                        }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                        continue;
+                    }
+
+                    LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
+                    // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
+                    staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
+                    staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
+                    staProtocol.setPalletSize(locMast.getLocType2());
+                    devpThread.setPakMk(staProtocol.getSiteId(), false);
+                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+                    if (!result) {
+                        News.error("" + mark + " - 3" + " - 鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
+                    }
+
+                } else {
+                    News.errorNoLog("" + mark + " - 6" + " - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒" + " 鑷姩淇″彿锛�" + staProtocol.isLoading() + "銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable()
+                            + "銆佺┖鏉夸俊鍙凤細" + staProtocol.isEmptyMk());
+                }
+
+            }
+
+        }
+        News.infoNoLog("" + mark + " - 0" + " - 鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱  ===銆嬫墽琛屽畬鎴�");
     }
 
     /**
      * 鍫嗗灈鏈虹珯鍑哄簱鍒板嚭搴撶珯
      */
     public synchronized void crnStnToOutStn(Integer mark) {
+        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
+                .eq("wrk_sts", 12)
+        );
 
-        for (CrnSlave crnSlave : slaveProperties.getCrn()) {
-            // 閬嶅巻鍫嗗灈鏈哄嚭搴撶珯
-            for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) {
-                // 鑾峰彇鍫嗗灈鏈哄嚭搴撶珯淇℃伅
-                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
-                StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
-                if (staProtocol == null) {
-                    continue;
-                } else {
-                    staProtocol = staProtocol.clone();
+        for (WrkMast wrkMast : wrkMasts) {
+            // 鍒ゆ柇宸ヤ綔妗f潯浠�
+            if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) {
+                continue;
+            }
+
+            Integer devpId = null;
+            Integer sourceStaNo = wrkMast.getSourceStaNo();
+            for (CrnSlave crnSlave : slaveProperties.getCrn()) {
+                for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) {
+                    if (crnStn.getStaNo().equals(sourceStaNo)) {
+                        devpId = crnStn.getDevpPlcId();
+                        break;
+                    }
                 }
-                if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
-                    // 鏌ヨ宸ヤ綔妗�
-                    WrkMast wrkMast = wrkMastMapper.selectPakOutStep2(staProtocol.getSiteId());
-                    if (wrkMast == null) {
+            }
+
+            if (devpId == null) {
+                News.error("" + mark + " - 0" + " - 鍫嗗灈鏈虹珯鍑哄簱鍒板嚭搴撶珯锛屾湭鎵惧埌瀵瑰簲PLC");
+                continue;
+            }
+
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devpId);
+            StaProtocol staProtocol = devpThread.getStation().get(sourceStaNo);
+            if (staProtocol == null) {
+                continue;
+            } else {
+                staProtocol = staProtocol.clone();
+            }
+
+            if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
+                CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo());
+                CrnProtocol crnProtocol = crnThread.getCrnProtocol();
+
+                if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue())
+                        && (crnProtocol.statusType == CrnStatusType.PUTTING || crnProtocol.statusType == CrnStatusType.WAITING)) {
+                    //鏀捐揣涓� 鎴� 绛夊緟纭
+                    News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�");
+
+                    // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
+                    LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
+                            .eq("loc_no", wrkMast.getSourceLocNo()));
+
+                    // 涓嬪彂绔欑偣淇℃伅
+                    staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
+                    staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
+                    staProtocol.setPalletSize(locMast.getLocType2());
+                    if (!MessageQueue.offer(SlaveType.Devp, devpId, new Task(2, staProtocol))) {
                         continue;
                     }
-                    // 鍒ゆ柇宸ヤ綔妗f潯浠�
-                    if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) {
-                        continue;
+
+                    // 鏇存柊宸ヤ綔妗g姸鎬佷负14澶辫触
+                    wrkMast.setWrkSts(14L);
+                    wrkMast.setCrnEndTime(new Date());
+                    if (wrkMastMapper.updateById(wrkMast) != 0) {
+                        News.info("" + mark + " - 1" + " - 鏇存柊宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负14鎴愬姛锛侊紒锛� [宸ヤ綔鍙�:{}]", wrkMast.getWrkNo());
+                    } else {
+                        News.error("" + mark + " - 1" + " - 鏇存柊宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负14澶辫触锛侊紒锛� [宸ヤ綔鍙�:{}]", wrkMast.getWrkNo());
                     }
-                    // 鍒ゆ柇鍚婅溅鏄惁瀹為檯宸插畬鎴愶紝涓旂數鑴戠姸鎬佸湪move涓紝浠ュ鐢佃剳杩涜鏇存柊宸ヤ綔妗�
-                    CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo());
-                    CrnProtocol crnProtocol = crnThread.getCrnProtocol();
-                    if (crnProtocol.statusType == CrnStatusType.FETCHING || crnProtocol.statusType == CrnStatusType.PUTTING) {
-                        // 绉诲姩涓�
-                        continue;
-                    }
-                    //  鍒ゆ柇鍫嗗灈鏈虹姸鎬佺瓑寰呯‘璁�
-                    if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue())
-                            && crnProtocol.statusType == CrnStatusType.WAITING
-                            && crnProtocol.forkPosType == CrnForkPosType.HOME) {
-                        News.warnNoLog(""+mark+" - 0"+" - 寮�濮嬫墽琛�");
-
-                        // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
-
-                        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
-                                .eq("loc_no", wrkMast.getSourceLocNo()));
-
-                        // 涓嬪彂绔欑偣淇℃伅
-                        staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
-                        staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
-                        staProtocol.setPalletSize(locMast.getLocType2());
-                        if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) {
-                            continue;
-                        }
-
-                        // 鏇存柊宸ヤ綔妗g姸鎬佷负14澶辫触
-                        wrkMast.setWrkSts(14L);
-                        wrkMast.setCrnEndTime(new Date());
-                        if (wrkMastMapper.updateById(wrkMast) != 0) {
-                            // 澶嶄綅鍫嗗灈鏈�
-                            crnThread.setResetFlag(true);
-                        } else {
-                            News.error(""+mark+" - 1"+" - 鏇存柊宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负14澶辫触锛侊紒锛� [宸ヤ綔鍙�:{}]", wrkMast.getWrkNo());
-                        }
-
-                    }else {
-                        News.errorNoLog(""+mark+" - 6"+" - 鍫嗗灈鏈轰俊鎭笉绗﹀悎鍏ュ簱鏉′欢锛侊紒锛�"
-                                +" 鍫嗗灈鏈虹姸鎬侊細"+crnProtocol.modeType+"==鑷姩AUTO锛�" + CrnModeType.AUTO
-                                +"銆佸爢鍨涙満浠诲姟鍙凤細"+crnProtocol.getTaskNo()+"==宸ヤ綔妗d换鍔″彿锛�" + wrkMast.getWrkNo().shortValue()
-                                +"銆佺姸鎬佹灇涓撅細"+crnProtocol.statusType+"==WAITING锛�90 //浠诲姟瀹屾垚绛夊緟WCS纭)锛�" + CrnStatusType.WAITING
-                                +"銆佽揣鍙変綅缃細"+crnProtocol.forkPosType+"==HOME锛�0  // 璐у弶鍘熶綅锛�" + CrnForkPosType.HOME);
-                    }
-
                 }
             }
         }
-        News.infoNoLog(""+mark+" - 0"+" - 鍫嗗灈鏈虹珯鍑哄簱鍒板嚭搴撶珯  ===銆嬫墽琛屽畬鎴�");
+
+        News.infoNoLog("" + mark + " - 0" + " - 鍫嗗灈鏈虹珯鍑哄簱鍒板嚭搴撶珯  ===銆嬫墽琛屽畬鎴�");
     }
 
     /**
@@ -592,7 +733,7 @@
             }
             BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
             if (basCrnp == null) {
-                News.error(""+mark+" - 1"+" - {}鍙峰爢鍨涙満灏氭湭鍦ㄦ暟鎹簱杩涜缁存姢锛�", crn.getId());
+                News.error("" + mark + " - 1" + " - {}鍙峰爢鍨涙満灏氭湭鍦ㄦ暟鎹簱杩涜缁存姢锛�", crn.getId());
                 continue;
             }
 
@@ -604,38 +745,38 @@
             // 鍙湁褰撳爢鍨涙満绌洪棽 骞朵笖 鏃犱换鍔℃椂鎵嶇户缁墽琛�
             if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO
                     && crnProtocol.getLoaded() == 0 && crnProtocol.getForkPos() == 0) {
-                News.warnNoLog(""+mark+" - 0"+" - 寮�濮嬫墽琛屽爢鍨涙満鍏ュ嚭搴撲綔涓氫笅鍙�");
+                News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛屽爢鍨涙満鍏ュ嚭搴撲綔涓氫笅鍙�");
                 // 濡傛灉鏈�杩戜竴娆℃槸鍏ュ簱妯″紡
                 if (crnProtocol.getLastIo().equals("I")) {
                     if (basCrnp.getInEnable().equals("Y")) {
                         //mark - 1 - ....
-                        this.crnStnToLoc(crn, crnProtocol,mark); //  鍏ュ簱
+                        this.crnStnToLoc(crn, crnProtocol, mark); //  鍏ュ簱
                         crnProtocol.setLastIo("O");
                     } else if (basCrnp.getOutEnable().equals("Y")) {
                         //mark - 2 - ....
-                        this.locToCrnStn(crn, crnProtocol,mark); //  鍑哄簱
+                        this.locToCrnStn(crn, crnProtocol, mark); //  鍑哄簱
                         crnProtocol.setLastIo("I");
                     }
                 }
                 // 濡傛灉鏈�杩戜竴娆℃槸鍑哄簱妯″紡
                 else if (crnProtocol.getLastIo().equals("O")) {
                     if (basCrnp.getOutEnable().equals("Y")) {
-                        this.locToCrnStn(crn, crnProtocol,mark); //  鍑哄簱
+                        this.locToCrnStn(crn, crnProtocol, mark); //  鍑哄簱
                         crnProtocol.setLastIo("I");
                     } else if (basCrnp.getInEnable().equals("Y")) {
-                        this.crnStnToLoc(crn, crnProtocol,mark); //  鍏ュ簱
+                        this.crnStnToLoc(crn, crnProtocol, mark); //  鍏ュ簱
                         crnProtocol.setLastIo("O");
                     }
                 }
             }
             // 搴撲綅绉昏浆
             //mark - 3 - ....
-            this.locToLoc(crn, crnProtocol,mark);
-            this.locToLoc111(crn, crnProtocol,mark);
+            this.locToLoc(crn, crnProtocol, mark);
+            this.locToLoc111(crn, crnProtocol, mark);
 //            this.crnRebackHp(crnProtocol, crnThread);
 
         }
-        News.infoNoLog(""+mark+" - 0"+" - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂鎵ц瀹屾垚");
+        News.infoNoLog("" + mark + " - 0" + " - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂鎵ц瀹屾垚");
     }
 
     /**
@@ -643,6 +784,10 @@
      */
     public synchronized void crnMove() {
         for (CrnSlave crn : slaveProperties.getCrn()) {
+            if (crn.getId() == 1) {
+                continue;
+            }
+
             // 鑾峰彇鍫嗗灈鏈轰俊鎭�
             CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
             CrnProtocol crnProtocol = crnThread.getCrnProtocol();
@@ -707,17 +852,89 @@
     }
 
     /**
+     * 鍫嗗灈鏈烘湁鍏ュ簱浠诲姟鏃讹紝鍥炲叆搴撳彛寰呮満
+     */
+    public synchronized void crnMoveByInTask() {
+        for (CrnSlave crn : slaveProperties.getCrn()) {
+            if (crn.getId() == 1) {
+                continue;
+            }
+
+            // 鑾峰彇鍫嗗灈鏈轰俊鎭�
+            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
+            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
+            if (crnProtocol == null) {
+                continue;
+            }
+            BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
+            if (basCrnp == null) {
+                log.error("{}鍙峰爢鍨涙満灏氭湭鍦ㄦ暟鎹簱杩涜缁存姢锛�", crn.getId());
+                continue;
+            }
+
+            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO) {
+                if (crnProtocol.getBay() == 1 && crnProtocol.getLevel() == 1) {
+                    continue;
+                }
+
+                if (System.currentTimeMillis() - crnProtocol.getLastCommandTime() < 1000 * 60) {
+                    continue;
+                }
+
+                Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK);
+                if (object != null) {
+                    continue;
+                }
+
+                List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
+                        .eq("crn_no", crn.getId())
+                        .eq("wrk_sts", 2)
+                );
+                if (wrkMasts.isEmpty()) {
+                    continue;
+                }
+
+                CrnSlave.CrnStn crnStn = crn.getCrnInStn().get(0);
+
+                News.info("鍫嗗灈鏈烘湁鍏ュ簱浠诲姟鏃讹紝鍥炲叆搴撳彛寰呮満==>>" + crnProtocol.getCrnNo() + "鍙峰爢鍨涙満");
+                // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
+                CrnCommand crnCommand = new CrnCommand();
+                crnCommand.setCrnNo(crnProtocol.getCrnNo()); // 鍫嗗灈鏈虹紪鍙�
+                crnCommand.setTaskNo((short) 9999); // 宸ヤ綔鍙�
+                crnCommand.setAckFinish((short) 0);  // 浠诲姟瀹屾垚纭浣�
+                crnCommand.setTaskMode(CrnTaskModeType.CRN_MOVE); // 浠诲姟妯″紡:  鍫嗗灈鏈虹Щ鍔�
+                crnCommand.setSourcePosX(crnStn.getRow().shortValue());     // 婧愬簱浣嶆帓
+                crnCommand.setSourcePosY((short) 1);     // 婧愬簱浣嶅垪
+                crnCommand.setSourcePosZ((short) 1);     // 婧愬簱浣嶅眰
+                crnCommand.setDestinationPosX((short) 0);     // 鐩爣搴撲綅鎺�
+                crnCommand.setDestinationPosY((short) 0);     // 鐩爣搴撲綅鍒�
+                crnCommand.setDestinationPosZ((short) 0);     // 鐩爣搴撲綅灞�
+                if (!MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, crnCommand))) {
+                    News.error("鍫嗗灈鏈虹Щ鍔ㄥ懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand));
+                }
+                crnThread.setBackHpFlag(true);
+                redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 60);
+                try {
+                    Thread.sleep(500);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    /**
      * 鍏ュ簱  ===>>  鍫嗗灈鏈虹珯鍒板簱浣�
      */
-    public synchronized void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol,Integer mark) {
-        News.warnNoLog(""+mark+" - 1"+" - 0"+" - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氭墽琛屽叆搴�");
+    public synchronized void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol, Integer mark) {
+        News.warnNoLog("" + mark + " - 1" + " - 0" + " - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氭墽琛屽叆搴�");
         for (CrnSlave.CrnStn crnStn : slave.getCrnInStn()) {
             boolean flag = false;
             // 鑾峰彇鍫嗗灈鏈哄叆搴撶珯淇℃伅
             DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
             StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
             if (staProtocol == null) {
-                News.infoNoLog(""+mark+" - 1"+" - 1"+" - 鍫嗗灈鏈哄叆搴撶珯淇℃伅(staProtocol!=null缁х画鎵ц)锛歴taProtocol="+staProtocol);
+                News.infoNoLog("" + mark + " - 1" + " - 1" + " - 鍫嗗灈鏈哄叆搴撶珯淇℃伅(staProtocol!=null缁х画鎵ц)锛歴taProtocol=" + staProtocol);
                 continue;
             } else {
                 staProtocol = staProtocol.clone();
@@ -725,7 +942,7 @@
             // 鏌ヨ绔欑偣璇︾粏淇℃伅
             BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
             if (staDetl == null) {
-                News.error(""+mark+" - 1"+" - 2"+" - 鍏ュ簱 ===>> 鍫嗗灈鏈虹珯鐐瑰湪鏁版嵁搴撲笉瀛樺湪, 绔欑偣缂栧彿={}", crnStn.getStaNo());
+                News.error("" + mark + " - 1" + " - 2" + " - 鍏ュ簱 ===>> 鍫嗗灈鏈虹珯鐐瑰湪鏁版嵁搴撲笉瀛樺湪, 绔欑偣缂栧彿={}", crnStn.getStaNo());
                 continue;
             }
             if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable()
@@ -733,27 +950,27 @@
                 flag = true;
             }
             if (!flag) {
-                News.errorNoLog(""+mark+" - 1"+" - 3"+" - 鍫嗗灈鏈哄叆搴撶珯淇℃伅(浠ヤ笅闇�瑕佸叏true):"
-                        +"鑷姩淇″彿"+staProtocol.isAutoing()+"鏈夌墿淇″彿"+staProtocol.isLoading()
-                        +"宸ヤ綔鍙�>0"+staProtocol.getWorkNo()+"鍙叆淇″彿"+staProtocol.isInEnable()
-                        +"鑳藉叆淇″彿锛坵ms璁剧疆锛�.equals(\"Y\")"+staDetl.getCanining());
+                News.errorNoLog("" + mark + " - 1" + " - 3" + " - 鍫嗗灈鏈哄叆搴撶珯淇℃伅(浠ヤ笅闇�瑕佸叏true):"
+                        + "鑷姩淇″彿" + staProtocol.isAutoing() + "鏈夌墿淇″彿" + staProtocol.isLoading()
+                        + "宸ヤ綔鍙�>0" + staProtocol.getWorkNo() + "鍙叆淇″彿" + staProtocol.isInEnable()
+                        + "鑳藉叆淇″彿锛坵ms璁剧疆锛�.equals(\"Y\")" + staDetl.getCanining());
                 continue;
             }
             // 鑾峰彇宸ヤ綔鐘舵�佷负2锛堣澶囦笂璧帮級鐨勫叆搴撳伐浣滄。
             WrkMast wrkMast = wrkMastMapper.selectPakInStep2(slave.getId(), staProtocol.getWorkNo().intValue(), crnStn.getStaNo());
             if (null == wrkMast) {
-                News.infoNoLog(""+mark+" - 1"+" - 4"+" - 鏌ヨ鏃犲緟鍏ュ簱鏁版嵁--wrk_sts=2, 宸ヤ綔鍙�={}", staProtocol.getWorkNo());
+                News.infoNoLog("" + mark + " - 1" + " - 4" + " - 鏌ヨ鏃犲緟鍏ュ簱鏁版嵁--wrk_sts=2, 宸ヤ綔鍙�={}", staProtocol.getWorkNo());
 //                log.error("鏌ヨ鏃犲緟鍏ュ簱鏁版嵁--wrk_sts=2, 宸ヤ綔鍙�={}", staProtocol.getWorkNo());
                 continue;
             }
             // 鑾峰彇搴撲綅淇℃伅
             LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
             if (locMast == null) {
-                News.error(""+mark+" - 1"+" - 5"+" - 鏌ヨ搴撳瓨鏃犳暟鎹�--搴撲綅鍙穥}", wrkMast.getLocNo());
+                News.error("" + mark + " - 1" + " - 5" + " - 鏌ヨ搴撳瓨鏃犳暟鎹�--搴撲綅鍙穥}", wrkMast.getLocNo());
                 continue;
             }
             if (!locMast.getLocSts().equals("S") && !locMast.getLocSts().equals("Q")) {
-                News.error(""+mark+" - 1"+" - 6"+" - 鍏ュ簱鎿嶄綔搴撲綅鐘舵�佷笉绗﹀悎--鐘舵��, 搴撲綅鍙�={}锛屽簱浣嶇姸鎬�={}", wrkMast.getLocNo(), locMast.getLocSts());
+                News.error("" + mark + " - 1" + " - 6" + " - 鍏ュ簱鎿嶄綔搴撲綅鐘舵�佷笉绗﹀悎--鐘舵��, 搴撲綅鍙�={}锛屽簱浣嶇姸鎬�={}", wrkMast.getLocNo(), locMast.getLocSts());
                 continue;
             }
 
@@ -773,37 +990,43 @@
                 if (Utils.getLaneByLocNo(wrkMast.getLocNo()) != crnProtocol.getCrnLane()) {
                     //鍒ゆ柇鍫嗗灈鏈烘墍鍦ㄥ贩閬撴槸鍚﹀瓨鍦ㄥ叾浠栦换鍔★紝濡傚瓨鍦ㄥ垯浼樺厛鎵ц
                     List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false);
-                    if (!currentWrkMasts.isEmpty()) {
-                        continue;//褰撳墠鍫嗗灈鏈烘墍鍦ㄥ贩閬撳瓨鍦ㄤ换鍔�
-                    }
+//                    if (!currentWrkMasts.isEmpty()) {
+//                        continue;//褰撳墠鍫嗗灈鏈烘墍鍦ㄥ贩閬撳瓨鍦ㄤ换鍔�
+//                    }
                 }
             }
 
             // 鍙屾繁搴撲綅涓旀祬搴撲綅鏈夎揣锛屽垯闇�鍏堝娴呭簱浣嶈繘琛屽簱浣嶇Щ杞�
             if (Utils.isDeepLoc(slaveProperties, wrkMast.getLocNo())) {
-                News.warnNoLog(""+mark+" - 1"+" - 8"+" - 鍙屾繁搴撲綅涓旀祬搴撲綅鏈夎揣锛屽垯闇�鍏堝娴呭簱浣嶈繘琛屽簱浣嶇Щ杞� : 寮�濮嬫墽琛� 浠诲姟鍙�={}",wrkMast.getWrkNo());
+                News.warnNoLog("" + mark + " - 1" + " - 8" + " - 鍙屾繁搴撲綅涓旀祬搴撲綅鏈夎揣锛屽垯闇�鍏堝娴呭簱浣嶈繘琛屽簱浣嶇Щ杞� : 寮�濮嬫墽琛� 浠诲姟鍙�={}", wrkMast.getWrkNo());
                 String shallowLocNo = Utils.getShallowLoc(slaveProperties, wrkMast.getLocNo());
                 LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                 // O.绌哄簱浣嶃�丵.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴撱�丼.鍏ュ簱棰勭害銆乆.绂佺敤 鐩存帴鎼紒
                 if (shallowLoc.getLocSts().equals("P") || shallowLoc.getLocSts().equals("R")) {
-                    News.warnNoLog(""+mark+" - 1"+" - 9"+" - // O.绌哄簱浣嶃�丵.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴撱�丼.鍏ュ簱棰勭害銆乆.绂佺敤 鐩存帴鎼紒搴撲綅鐘舵��={}",shallowLoc.getLocSts());
+                    News.warn("" + mark + " - 1" + " - 9" + " - // O.绌哄簱浣嶃�丵.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴撱�丼.鍏ュ簱棰勭害銆乆.绂佺敤 鐩存帴鎼紒搴撲綅={},搴撲綅鐘舵��={}", shallowLoc.getLocNo(), shallowLoc.getLocSts());
                     WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                     if (null == waitWrkMast) {
-                        News.error(""+mark+" - 1"+" - 10"+" - {}搴撲綅寮傚父锛屾湭妫�绱㈠埌鐩稿簲宸ヤ綔妗o紒", shallowLocNo);
+                        News.error("" + mark + " - 1" + " - 10" + " - {}搴撲綅寮傚父锛屾湭妫�绱㈠埌鐩稿簲宸ヤ綔妗o紒", shallowLocNo);
                     } else {
-                        waitWrkMast.setIoPri(15D);
-                        waitWrkMast.setModiTime(new Date());
-                        if (wrkMastMapper.updateById(waitWrkMast) == 0) {
-                            News.error(""+mark+" - 1"+" - 11"+" - 璋冩暣宸ヤ綔妗d紭鍏堢骇澶辫触锛佸伐浣滃彿={}", waitWrkMast.getWrkNo());
+                        if (waitWrkMast.getWrkSts() != 14 && waitWrkMast.getIoType() > 100) {
+                            waitWrkMast.setIoPri(15D);
+                            waitWrkMast.setModiTime(new Date());
+                            if (wrkMastMapper.updateById(waitWrkMast) == 0) {
+                                News.error("" + mark + " - 1" + " - 11" + " - 璋冩暣宸ヤ綔妗d紭鍏堢骇澶辫触锛佸伐浣滃彿={}", waitWrkMast.getWrkNo());
+                            }
+                            continue;
                         }
-                        continue;
+
+                        if (waitWrkMast.getWrkSts() < 5 && waitWrkMast.getIoType() < 100) {
+                            continue;//鏈変换鍔$姝㈡惉杩愶紝鏈夊彲鑳芥祬搴撲綅鐘舵�佽繕鏈彉鏇村畬鎴�
+                        }
                     }
 
                 } else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
-                    News.warnNoLog(""+mark+" - 1"+" - 12"+" - // F銆丏  搴撲綅鐘舵��={}",shallowLoc.getLocSts());
+                    News.warn("" + mark + " - 1" + " - 12" + " - // F銆丏  搴撲綅={},搴撲綅鐘舵��={}", shallowLoc.getLocNo(), shallowLoc.getLocSts());
                     // 姝ゆ爣璁伴伩鍏嶅娆℃墽琛岀Щ搴撲换鍔�
                     if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())) {
-                        if (moveLocForDeepLoc(slave, shallowLoc,mark)){
+                        if (moveLocForDeepLoc(slave, shallowLoc, mark)) {
                             wrkMast.setUpdMk("Y");
                             wrkMast.setIoPri(14D);
                             wrkMastMapper.updateById(wrkMast);
@@ -818,17 +1041,17 @@
                     }
                     continue;
                 } else if (shallowLoc.getLocSts().equals("Q")) {
-                    News.warnNoLog(""+mark+" - 1"+" - 13"+" - // Q  搴撲綅鐘舵��={}",shallowLoc.getLocSts());
+                    News.warn("" + mark + " - 1" + " - 13" + " - // Q  搴撲綅={},搴撲綅鐘舵��={}", shallowLoc.getLocNo(), shallowLoc.getLocSts());
                     WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                     if (null != waitWrkMast && waitWrkMast.getWrkSts() == 4) {
-                        News.infoNoLog(""+mark+" - 1"+" - 14"+" - // F銆丏  宸ヤ綔鐘舵��(鍒ゆ柇鏉′欢涓�==4)={}",waitWrkMast.getWrkSts());
+                        News.infoNoLog("" + mark + " - 1" + " - 14" + " - // F銆丏  宸ヤ綔鐘舵��(鍒ゆ柇鏉′欢涓�==4)={}", waitWrkMast.getWrkSts());
                         continue;
                     }
                 }
             }
-            News.warnNoLog(""+mark+" - 1"+" - 15"+" - 鍛戒护涓嬪彂 : 宸ヤ綔鍙�={},婧愭帓={},婧愬垪={},婧愬眰={},鐩爣鎺�={},鐩爣鍒�={},鐩爣灞�={}",wrkMast.getWrkNo().shortValue()
-                    ,crnStn.getRow().shortValue(),crnStn.getBay().shortValue(),crnStn.getLev().shortValue()
-                    ,locMast.getRow1().shortValue(),locMast.getBay1().shortValue(),locMast.getLev1().shortValue());
+            News.info("" + mark + " - 1" + " - 15" + " - 鍛戒护涓嬪彂 : 宸ヤ綔鍙�={},婧愭帓={},婧愬垪={},婧愬眰={},鐩爣鎺�={},鐩爣鍒�={},鐩爣灞�={}", wrkMast.getWrkNo().shortValue()
+                    , crnStn.getRow().shortValue(), crnStn.getBay().shortValue(), crnStn.getLev().shortValue()
+                    , locMast.getRow1().shortValue(), locMast.getBay1().shortValue(), locMast.getLev1().shortValue());
 
             // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
             CrnCommand crnCommand = new CrnCommand();
@@ -843,7 +1066,7 @@
             crnCommand.setDestinationPosY(locMast.getBay1().shortValue());     // 鐩爣搴撲綅鍒�
             crnCommand.setDestinationPosZ(locMast.getLev1().shortValue());     // 鐩爣搴撲綅灞�
             if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
-                News.error(""+mark+" - 1"+" - 16"+" - 鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
+                News.error("" + mark + " - 1" + " - 16" + " - 鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
             } else {
 
 //                long startTime = System.currentTimeMillis();
@@ -864,19 +1087,40 @@
                 wrkMast.setCrnStrTime(now);
                 wrkMast.setModiTime(now);
                 if (wrkMastMapper.updateById(wrkMast) == 0) {
-                    News.error(""+mark+" - 1"+" - 17"+" - 淇敼宸ヤ綔妗g姸鎬� 2.璁惧涓婅蛋 => 3.鍚婅溅鍏ュ簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo());
+                    News.error("" + mark + " - 1" + " - 17" + " - 淇敼宸ヤ綔妗g姸鎬� 2.璁惧涓婅蛋 => 3.鍚婅溅鍏ュ簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo());
                 }
             }
         }
-        News.infoNoLog(""+mark+" - 1"+" - 0"+" - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂 锛� 鍏ュ簱鎵ц瀹屾瘯");
+        News.infoNoLog("" + mark + " - 1" + " - 0" + " - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂 锛� 鍏ュ簱鎵ц瀹屾瘯");
     }
 
     /**
      * 鍑哄簱  ===>>  搴撲綅鍒板爢鍨涙満绔�
      * 2022-06-09 TQS淇敼锛屾煡璇㈠伐浣滄。LIST锛岄亶鍘嗕笅鍙戯紝闃叉绗竴涓换鍔″牭濉炲嚭搴�
      */
-    public synchronized void locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol,Integer mark) {
-        News.warnNoLog(""+mark+" - 2"+" - 0"+" - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氭墽琛屽嚭搴�");
+    public synchronized void locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol, Integer mark) {
+        News.warnNoLog("" + mark + " - 2" + " - 0" + " - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氭墽琛屽嚭搴�");
+
+        int devpTaskStackOver = 20;
+        Config config = configService.selectOne(new EntityWrapper<Config>()
+                .eq("code", "devpTaskStackOver"));
+        if (config != null) {
+            devpTaskStackOver = Integer.parseInt(config.getValue());
+        }
+        int devpCheckTaskStackOver = 2;
+        Config config2 = configService.selectOne(new EntityWrapper<Config>()
+                .eq("code", "devpCheckTaskStackOver"));
+        if (config2 != null) {
+            devpCheckTaskStackOver = Integer.parseInt(config2.getValue());
+        }
+
+
+        Integer devpWorkingCount = commonService.queryDevpWorkingCount();
+        if (devpWorkingCount > devpTaskStackOver) {
+            News.warn("" + mark + " - 2" + " - 0" + " - 杈撻�佺嚎浠诲姟杩囪浇锛屽綋鍓嶈緭閫佺嚎鎵胯浇鏁伴噺:{}", devpWorkingCount);
+            return;
+        }
+
         for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) {
             // 鑾峰彇宸ヤ綔鐘舵�佷负11锛堢敓鎴愬嚭搴揑D锛夌殑鍑哄簱宸ヤ綔妗�
 //            WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(slave.getId(), crnStn.getStaNo());
@@ -887,20 +1131,20 @@
                 }
                 // 宸ヤ綔妗g姸鎬佸垽鏂�
                 if (wrkMast.getIoType() < 100 || wrkMast.getSourceStaNo() == null) {
-                    News.error(""+mark+" - 2"+" - 1"+" - 鏌ヨ宸ヤ綔妗f暟鎹笉绗﹀悎鏉′欢--鍏ュ嚭绫诲瀷/绔欑偣, 宸ヤ綔鍙�={}锛屾簮搴撲綅={}锛屽叆鍑虹被鍨�={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getIoType());
+                    News.error("" + mark + " - 2" + " - 1" + " - 鏌ヨ宸ヤ綔妗f暟鎹笉绗﹀悎鏉′欢--鍏ュ嚭绫诲瀷/绔欑偣, 宸ヤ綔鍙�={}锛屾簮搴撲綅={}锛屽叆鍑虹被鍨�={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getIoType());
                     continue;
                 }
                 // 鑾峰彇婧愬簱浣嶄俊鎭�
                 LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
                 if (!sourceSta.getLocSts().equals("R") && !sourceSta.getLocSts().equals("P")) {
-                    News.error(""+mark+" - 2"+" - 2"+" - 鍑哄簱鎿嶄綔搴撲綅鐘舵�佷笉绗﹀悎--鐘舵��, 搴撲綅鍙�={}锛屽簱浣嶇姸鎬�={}", wrkMast.getLocNo(), sourceSta.getLocSts());
+                    News.error("" + mark + " - 2" + " - 2" + " - 鍑哄簱鎿嶄綔搴撲綅鐘舵�佷笉绗﹀悎--鐘舵��, 搴撲綅鍙�={}锛屽簱浣嶇姸鎬�={}", wrkMast.getLocNo(), sourceSta.getLocSts());
                     continue;
                 }
                 // 鑾峰彇鍫嗗灈鏈哄嚭搴撶珯淇℃伅
                 SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
                 StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
                 if (staProtocol == null) {
-                    News.infoNoLog(""+mark+" - 2"+" - 3"+" - 鍫嗗灈鏈哄嚭搴撶珯淇℃伅(staProtocol!=null缁х画鎵ц,鍚﹀垯寰幆缁堟)锛歴taProtocol="+staProtocol);
+                    News.infoNoLog("" + mark + " - 2" + " - 3" + " - 鍫嗗灈鏈哄嚭搴撶珯淇℃伅(staProtocol!=null缁х画鎵ц,鍚﹀垯寰幆缁堟)锛歴taProtocol=" + staProtocol);
                     break;
 //                    continue;
                 } else {
@@ -919,6 +1163,29 @@
                     }
                 }
 
+                //zhangc
+                if (wrkMast.getIoType() == 103 || wrkMast.getIoType() == 107) {
+                    if (wrkMast.getStaNo() == 1058) {
+                        List<WrkMast> inWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
+                                .in("wrk_sts", 12, 14)
+                                .eq("sta_no", 1058)
+                        );
+                        if (!Cools.isEmpty(inWrkMasts) && inWrkMasts.size() >= devpCheckTaskStackOver) {
+                            News.error("" + mark + " - 2" + " - 妫�娴嬪瓨鍦�1058绔欑偣锛屽瓨鍦ㄤ袱绗斿伐浣滀腑鐨勪换鍔★紝宸ヤ綔鍙�={}" + wrkMast.getWrkNo());
+                            continue;
+                        }
+                    } else if (wrkMast.getStaNo() == 1062) {
+                        List<WrkMast> inWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
+                                .in("wrk_sts", 12, 14)
+                                .eq("sta_no", 1062)
+                        );
+                        if (!Cools.isEmpty(inWrkMasts) && inWrkMasts.size() >= devpCheckTaskStackOver) {
+                            News.error("" + mark + " - 2" + " - 妫�娴嬪瓨鍦�1062绔欑偣锛屽瓨鍦ㄤ袱绗斿伐浣滀腑鐨勪换鍔★紝宸ヤ綔鍙�={}" + wrkMast.getWrkNo());
+                            continue;
+                        }
+                    }
+                }
+
 //            // 鍏ュ嚭搴撴ā寮忓垽鏂�
 //            if (devpThread.ioMode != IoModeType.PAKOUT_MODE) { continue; }
 //                if (wrkMast.getStaNo() == 204 && devpThread.ioModeOf2F != IoModeType.PAKOUT_MODE) {
@@ -929,7 +1196,7 @@
                 // 鏌ヨ绔欑偣璇︾粏淇℃伅
                 BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
                 if (staDetl == null) {
-                    News.error(""+mark+" - 2"+" - 5"+" - 鍑哄簱 ===>> 鍫嗗灈鏈虹珯鐐瑰湪鏁版嵁搴撲笉瀛樺湪, 绔欑偣缂栧彿={}", crnStn.getStaNo());
+                    News.error("" + mark + " - 2" + " - 5" + " - 鍑哄簱 ===>> 鍫嗗灈鏈虹珯鐐瑰湪鏁版嵁搴撲笉瀛樺湪, 绔欑偣缂栧彿={}", crnStn.getStaNo());
                     break;
 //                    continue;
                 }
@@ -941,7 +1208,7 @@
                     String crnOutVerifyOut = "Y";
                     Config crnOutVerifyOutEnableConfig = configService.selectOne(new EntityWrapper<Config>()
                             .eq("code", "crnOutVerifyOutEnable"));
-                    if(crnOutVerifyOutEnableConfig != null) {
+                    if (crnOutVerifyOutEnableConfig != null) {
                         crnOutVerifyOut = crnOutVerifyOutEnableConfig.getValue();
                     }
 
@@ -961,24 +1228,34 @@
                     }
 
                     if (crnProtocol.getCrnNo() == 1) {
-                        //鍒ゆ柇鍫嗗灈鏈哄拰褰撳墠浠诲姟鏄惁澶勪簬涓�涓贩閬�
-                        if (Utils.getLaneByLocNo(wrkMast.getLocNo()) != crnProtocol.getCrnLane()) {
-                            //鍒ゆ柇鍫嗗灈鏈烘墍鍦ㄥ贩閬撴槸鍚﹀瓨鍦ㄥ叾浠栦换鍔★紝濡傚瓨鍦ㄥ垯浼樺厛鎵ц
-                            List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false);
-                            if (!currentWrkMasts.isEmpty()) {
-                                continue;//褰撳墠鍫嗗灈鏈烘墍鍦ㄥ贩閬撳瓨鍦ㄤ换鍔�
+                        String turnCrnExecuteCurrentChannel = "Y";
+                        Config turnCrnExecuteCurrentChannelConfig = configService.selectOne(new EntityWrapper<Config>()
+                                .eq("code", "turnCrnExecuteCurrentChannel")
+                        );
+                        if (turnCrnExecuteCurrentChannelConfig != null) {
+                            turnCrnExecuteCurrentChannel = turnCrnExecuteCurrentChannelConfig.getValue();
+                        }
+
+                        if(turnCrnExecuteCurrentChannel.equals("Y")) {
+                            //鍒ゆ柇鍫嗗灈鏈哄拰褰撳墠浠诲姟鏄惁澶勪簬涓�涓贩閬�
+                            if (Utils.getLaneByLocNo(wrkMast.getSourceLocNo()) != crnProtocol.getCrnLane()) {
+                                //鍒ゆ柇鍫嗗灈鏈烘墍鍦ㄥ贩閬撴槸鍚﹀瓨鍦ㄥ叾浠栦换鍔★紝濡傚瓨鍦ㄥ垯浼樺厛鎵ц
+                                List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false);
+                                if (!currentWrkMasts.isEmpty()) {
+                                    continue;//褰撳墠鍫嗗灈鏈烘墍鍦ㄥ贩閬撳瓨鍦ㄤ换鍔�
+                                }
                             }
                         }
                     }
 
                     // 鍙屾繁搴撲綅涓旀祬搴撲綅鏈夎揣锛屽垯闇�鍏堝娴呭簱浣嶈繘琛屽簱浣嶇Щ杞�
                     if (Utils.isDeepLoc(slaveProperties, wrkMast.getSourceLocNo())) {
-                        News.warnNoLog(""+mark+" - 2"+" - 6"+" - 鍙屾繁搴撲綅涓旀祬搴撲綅鏈夎揣锛屽垯闇�鍏堝娴呭簱浣嶈繘琛屽簱浣嶇Щ杞� : 寮�濮嬫墽琛� 浠诲姟鍙�={}",wrkMast.getWrkNo());
+                        News.warnNoLog("" + mark + " - 2" + " - 6" + " - 鍙屾繁搴撲綅涓旀祬搴撲綅鏈夎揣锛屽垯闇�鍏堝娴呭簱浣嶈繘琛屽簱浣嶇Щ杞� : 寮�濮嬫墽琛� 浠诲姟鍙�={}", wrkMast.getWrkNo());
                         String shallowLocNo = Utils.getShallowLoc(slaveProperties, wrkMast.getSourceLocNo());
                         LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                         // O.绌哄簱浣嶃�丵.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴撱�丼.鍏ュ簱棰勭害銆乆.绂佺敤 鐩存帴鎼紒
                         if (shallowLoc.getLocSts().equals("P") || shallowLoc.getLocSts().equals("R")) {
-                            News.warnNoLog(""+mark+" - 2"+" - 7"+" - // O.绌哄簱浣嶃�丵.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴撱�丼.鍏ュ簱棰勭害銆乆.绂佺敤 鐩存帴鎼紒搴撲綅鐘舵��={}",shallowLoc.getLocSts());
+                            News.warnNoLog("" + mark + " - 2" + " - 7" + " - // O.绌哄簱浣嶃�丵.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴撱�丼.鍏ュ簱棰勭害銆乆.绂佺敤 鐩存帴鎼紒搴撲綅={},搴撲綅鐘舵��={}", shallowLoc.getLocNo(), shallowLoc.getLocSts());
                             WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                             if (null == waitWrkMast) {
                                 News.error("{}搴撲綅寮傚父锛屾湭妫�绱㈠埌鐩稿簲宸ヤ綔妗o紒", shallowLocNo);
@@ -987,7 +1264,7 @@
                                     waitWrkMast.setIoPri(15D);
                                     waitWrkMast.setModiTime(new Date());
                                     if (wrkMastMapper.updateById(waitWrkMast) == 0) {
-                                        News.error(""+mark+" - 2"+" - 8"+" - 璋冩暣宸ヤ綔妗d紭鍏堢骇澶辫触锛佸伐浣滃彿={}", waitWrkMast.getWrkNo());
+                                        News.error("" + mark + " - 2" + " - 8" + " - 璋冩暣宸ヤ綔妗d紭鍏堢骇澶辫触锛佸伐浣滃彿={}", waitWrkMast.getWrkNo());
                                     }
                                     continue;
                                 } else {
@@ -995,7 +1272,7 @@
                                 }
                             }
                         } else if (shallowLoc.getLocSts().equals("F") || shallowLoc.getLocSts().equals("D")) {
-                            News.warnNoLog(""+mark+" - 2"+" - 9"+" - // F銆丏  搴撲綅鐘舵��={}",shallowLoc.getLocSts());
+                            News.warnNoLog("" + mark + " - 2" + " - 9" + " - // F銆丏  搴撲綅={},搴撲綅鐘舵��={}", shallowLoc.getLocNo(), shallowLoc.getLocSts());
 //                            WrkMast waitWrkMast = wrkMastMapper.selectByLocNo(shallowLocNo);
                             //2022-08-16 modify,涓嶆牴鎹畊pdmk鏍囪绉诲簱浠诲姟(瀹规槗琚彇娑堝鑷村牭濉�)锛屾煡璇㈠伐浣滄。鏄惁瀛樺湪浠诲姟
                             WrkMast waitWrkMast = wrkMastMapper.selectByLocNo1(shallowLocNo);
@@ -1003,7 +1280,7 @@
 //                            if (Cools.isEmpty(wrkMast.getUpdMk()) || "N".equals(wrkMast.getUpdMk())
 //                                || Cools.isEmpty(waitWrkMast)) {
                             if (Cools.isEmpty(waitWrkMast)) {
-                                if (moveLocForDeepLoc(slave, shallowLoc,mark)){
+                                if (moveLocForDeepLoc(slave, shallowLoc, mark)) {
                                     wrkMast.setUpdMk("Y");
 //                                    wrkMast.setIoPri(14D);
                                     wrkMastMapper.updateById(wrkMast);
@@ -1016,10 +1293,10 @@
                             News.error("{}浠诲姟鍑哄簱澶辫触锛屾祬搴撲綅鍫靛锛佹祬搴撲綅鍙�:{}", wrkMast.getWrkNo(), shallowLocNo);
                             continue;
                         } else if (shallowLoc.getLocSts().equals("Q") || shallowLoc.getLocSts().equals("S")) {
-                            News.warnNoLog(""+mark+" - 2"+" - 10"+" - // Q銆丼  搴撲綅鐘舵��={}",shallowLoc.getLocSts());
+                            News.warnNoLog("" + mark + " - 2" + " - 10" + " - // Q銆丼  搴撲綅={},搴撲綅鐘舵��={}", shallowLoc.getLocNo(), shallowLoc.getLocSts());
                             WrkMast waitWrkMast = wrkMastMapper.selectByLocNo1(shallowLocNo);
                             if (null != waitWrkMast && waitWrkMast.getWrkSts() == 4) {
-                                News.infoNoLog(""+mark+" - 2"+" - 11"+" - // F銆丏  宸ヤ綔鐘舵��(鍒ゆ柇鏉′欢涓�==4)={}",waitWrkMast.getWrkSts());
+                                News.infoNoLog("" + mark + " - 2" + " - 11" + " - // F銆丏  宸ヤ綔鐘舵��(鍒ゆ柇鏉′欢涓�==4)={}", waitWrkMast.getWrkSts());
                                 continue;
                             }
                         }
@@ -1031,9 +1308,9 @@
 //                        return;
                     }
 
-                    News.warnNoLog(""+mark+" - 2"+" - 12"+" - 鍛戒护涓嬪彂 : 宸ヤ綔鍙�={},婧愭帓={},婧愬垪={},婧愬眰={},鐩爣鎺�={},鐩爣鍒�={},鐩爣灞�={}",wrkMast.getWrkNo().shortValue()
-                            ,sourceSta.getRow1().shortValue(),sourceSta.getBay1().shortValue(),sourceSta.getLev1().shortValue()
-                            ,crnStn.getRow().shortValue(),crnStn.getBay().shortValue(),crnStn.getLev().shortValue());
+                    News.warnNoLog("" + mark + " - 2" + " - 12" + " - 鍛戒护涓嬪彂 : 宸ヤ綔鍙�={},婧愭帓={},婧愬垪={},婧愬眰={},鐩爣鎺�={},鐩爣鍒�={},鐩爣灞�={}", wrkMast.getWrkNo().shortValue()
+                            , sourceSta.getRow1().shortValue(), sourceSta.getBay1().shortValue(), sourceSta.getLev1().shortValue()
+                            , crnStn.getRow().shortValue(), crnStn.getBay().shortValue(), crnStn.getLev().shortValue());
 
                     // 1.鍫嗗灈鏈哄紑濮嬬Щ鍔�
                     CrnCommand crnCommand = new CrnCommand();
@@ -1048,7 +1325,7 @@
                     crnCommand.setDestinationPosY(crnStn.getBay().shortValue());     // 鐩爣搴撲綅鍒�
                     crnCommand.setDestinationPosZ(crnStn.getLev().shortValue());     // 鐩爣搴撲綅灞�
                     if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
-                        News.error(""+mark+" - 2"+" - 13"+" - 鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
+                        News.error("" + mark + " - 2" + " - 13" + " - 鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
                     } else {
                         // 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓�
                         Date now = new Date();
@@ -1056,14 +1333,14 @@
                         wrkMast.setCrnStrTime(now);
                         wrkMast.setModiTime(now);
                         if (wrkMastMapper.updateById(wrkMast) == 0) {
-                            News.error(""+mark+" - 2"+" - 14"+" - 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo());
+                            News.error("" + mark + " - 2" + " - 14" + " - 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo());
                         }
                         break;
                     }
                 }
             }
         }
-        News.infoNoLog(""+mark+" - 2"+" - 0"+" - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂 锛� 鍑哄簱鎵ц瀹屾瘯");
+        News.infoNoLog("" + mark + " - 2" + " - 0" + " - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂 锛� 鍑哄簱鎵ц瀹屾瘯");
     }
 
 //    /**
@@ -1186,17 +1463,17 @@
     /**
      * 搴撲綅绉昏浆
      */
-    public synchronized void locToLoc(CrnSlave slave, CrnProtocol crnProtocol,Integer mark) {
+    public synchronized void locToLoc(CrnSlave slave, CrnProtocol crnProtocol, Integer mark) {
         // 鑾峰彇宸ヤ綔妗d俊鎭�
         WrkMast wrkMast = wrkMastMapper.selectLocMove(slave.getId());
         if (null == wrkMast) {
             return;
         }
-        News.warnNoLog(""+mark+" - 3"+" - 0"+" - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氭墽琛屽簱浣嶇Щ杞�");
+        News.warnNoLog("" + mark + " - 3" + " - 0" + " - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氭墽琛屽簱浣嶇Щ杞�");
         // 鑾峰彇婧愬簱浣嶄俊鎭�
         LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
         if (null == sourceSta) {
-            News.error(""+mark+" - 3"+" - 1"+" - 宸ヤ綔妗e簱浣嶇Щ杞け璐ワ紝鍘熷洜锛氭绱㈡簮搴撲綅澶辫触锛佸伐浣滃彿={}锛屾簮搴撲綅={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
+            News.error("" + mark + " - 3" + " - 1" + " - 宸ヤ綔妗e簱浣嶇Щ杞け璐ワ紝鍘熷洜锛氭绱㈡簮搴撲綅澶辫触锛佸伐浣滃彿={}锛屾簮搴撲綅={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
             return;
         }
         // 婧愬簱浣�  搴撲綅鐘舵�佸垽鏂�
@@ -1206,7 +1483,7 @@
         // 鑾峰彇鐩爣搴撲綅淇℃伅
         LocMast sta = locMastService.selectById(wrkMast.getLocNo());
         if (null == sta) {
-            News.error(""+mark+" - 3"+" - 2"+" - 宸ヤ綔妗e簱浣嶇Щ杞け璐ワ紝鍘熷洜锛氭绱㈢洰鏍囧簱浣嶅け璐ワ紒宸ヤ綔鍙�={}锛屾簮搴撲綅={}", wrkMast.getWrkNo(), wrkMast.getLocNo());
+            News.error("" + mark + " - 3" + " - 2" + " - 宸ヤ綔妗e簱浣嶇Щ杞け璐ワ紝鍘熷洜锛氭绱㈢洰鏍囧簱浣嶅け璐ワ紒宸ヤ綔鍙�={}锛屾簮搴撲綅={}", wrkMast.getWrkNo(), wrkMast.getLocNo());
             return;
         }
         // 鑾峰彇鍫嗗灈鏈轰俊鎭� 骞� 鍒ゆ柇鏄惁鍙叆鍑�
@@ -1225,9 +1502,9 @@
             return;
         }
 
-        News.warnNoLog(""+mark+" - 3"+" - 3"+" - 鍛戒护涓嬪彂 : 宸ヤ綔鍙�={},婧愭帓={},婧愬垪={},婧愬眰={},鐩爣鎺�={},鐩爣鍒�={},鐩爣灞�={}",wrkMast.getWrkNo().shortValue()
-                ,sourceSta.getRow1().shortValue(),sourceSta.getBay1().shortValue(),sourceSta.getLev1().shortValue()
-                ,sta.getRow1().shortValue(),sta.getBay1().shortValue(),sta.getLev1().shortValue());
+        News.warnNoLog("" + mark + " - 3" + " - 3" + " - 鍛戒护涓嬪彂 : 宸ヤ綔鍙�={},婧愭帓={},婧愬垪={},婧愬眰={},鐩爣鎺�={},鐩爣鍒�={},鐩爣灞�={}", wrkMast.getWrkNo().shortValue()
+                , sourceSta.getRow1().shortValue(), sourceSta.getBay1().shortValue(), sourceSta.getLev1().shortValue()
+                , sta.getRow1().shortValue(), sta.getBay1().shortValue(), sta.getLev1().shortValue());
 
         // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
         CrnCommand crnCommand = new CrnCommand();
@@ -1242,7 +1519,7 @@
         crnCommand.setDestinationPosY(sta.getBay1().shortValue());     // 鐩爣搴撲綅鍒�
         crnCommand.setDestinationPosZ(sta.getLev1().shortValue());     // 鐩爣搴撲綅灞�
         if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
-            News.error(""+mark+" - 3"+" - 4"+" - 鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
+            News.error("" + mark + " - 3" + " - 4" + " - 鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
         } else {
             // 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓�
             Date now = new Date();
@@ -1250,36 +1527,37 @@
             wrkMast.setCrnStrTime(now);
             wrkMast.setModiTime(now);
             if (wrkMastMapper.updateById(wrkMast) == 0) {
-                News.error(""+mark+" - 3"+" - 5"+" - 銆愬簱浣嶇Щ杞�� 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo());
+                News.error("" + mark + " - 3" + " - 5" + " - 銆愬簱浣嶇Щ杞�� 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo());
             }
+            crnProtocol.setLastIo("O");
         }
-        News.infoNoLog(""+mark+" - 3"+" - 0"+" - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氬簱浣嶇Щ杞畬鎴�");
+        News.infoNoLog("" + mark + " - 3" + " - 0" + " - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氬簱浣嶇Щ杞畬鎴�");
 
     }
 
     /**
      * 搴撲綅绉昏浆
      */
-    public synchronized void locToLoc111(CrnSlave slave, CrnProtocol crnProtocol,Integer mark) {
+    public synchronized void locToLoc111(CrnSlave slave, CrnProtocol crnProtocol, Integer mark) {
         // 鑾峰彇宸ヤ綔妗d俊鎭�
         WrkMast wrkMast = wrkMastMapper.selectLocMove111(slave.getId());
         if (null == wrkMast) {
             return;
         }
-        News.warnNoLog(""+mark+" - 3"+" - 0"+" - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氭墽琛屽簱浣嶇Щ杞�");
+        News.warnNoLog("" + mark + " - 3" + " - 0" + " - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氭墽琛屽簱浣嶇Щ杞�");
         // 鑾峰彇婧愬簱浣嶄俊鎭�
         LocMast sourceLoc = locMastService.selectById(wrkMast.getSourceLocNo());
         if (null == sourceLoc) {
-            News.error(""+mark+" - 3"+" - 1"+" - 宸ヤ綔妗e簱浣嶇Щ杞け璐ワ紝鍘熷洜锛氭绱㈡簮搴撲綅澶辫触锛佸伐浣滃彿={}锛屾簮搴撲綅={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
+            News.error("" + mark + " - 3" + " - 1" + " - 宸ヤ綔妗e簱浣嶇Щ杞け璐ワ紝鍘熷洜锛氭绱㈡簮搴撲綅澶辫触锛佸伐浣滃彿={}锛屾簮搴撲綅={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
             return;
         }
         // 婧愬簱浣�  搴撲綅鐘舵�佸垽鏂�
         if (!sourceLoc.getLocSts().equals("R")) {
-            News.error(""+mark+" - 3"+" - 11"+" - 宸ヤ綔妗e簱浣嶇Щ杞け璐ワ紝鍘熷洜锛氭簮搴撲綅鐘舵�佷笉涓篟锛佸伐浣滃彿={}锛屾簮搴撲綅={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
+            News.error("" + mark + " - 3" + " - 11" + " - 宸ヤ綔妗e簱浣嶇Щ杞け璐ワ紝鍘熷洜锛氭簮搴撲綅鐘舵�佷笉涓篟锛佸伐浣滃彿={}锛屾簮搴撲綅={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
             return;
         }
 
-        if(wrkMast.getIoType() != 111) {
+        if (wrkMast.getIoType() != 111) {
             // 鑾峰彇鐩爣搴撲綅淇℃伅
             LocMast loc = locMastService.selectById(wrkMast.getLocNo());
             if (null == loc) {
@@ -1288,7 +1566,7 @@
             }
             // 婧愬簱浣�  搴撲綅鐘舵�佸垽鏂�
             if (!loc.getLocSts().equals("S")) {
-                News.error(""+mark+" - 3"+" - 21"+" - 宸ヤ綔妗e簱浣嶇Щ杞け璐ワ紝鍘熷洜锛氱洰鏍囧簱浣嶇姸鎬佷笉涓篟锛佸伐浣滃彿={}锛屾簮搴撲綅={}", wrkMast.getWrkNo(), wrkMast.getLocNo());
+                News.error("" + mark + " - 3" + " - 21" + " - 宸ヤ綔妗e簱浣嶇Щ杞け璐ワ紝鍘熷洜锛氱洰鏍囧簱浣嶇姸鎬佷笉涓篟锛佸伐浣滃彿={}锛屾簮搴撲綅={}", wrkMast.getWrkNo(), wrkMast.getLocNo());
                 return;
             }
         }
@@ -1308,9 +1586,9 @@
             return;
         }
 
-        News.warnNoLog(""+mark+" - 3"+" - 3"+" - 鍛戒护涓嬪彂 : 宸ヤ綔鍙�={},婧愭帓={},婧愬垪={},婧愬眰={},鐩爣鎺�={},鐩爣鍒�={},鐩爣灞�={}",wrkMast.getWrkNo().shortValue()
-                ,sourceLoc.getRow1().shortValue(),sourceLoc.getBay1().shortValue(),sourceLoc.getLev1().shortValue()
-                ,sourceLoc.getRow1().shortValue(),sourceLoc.getBay1().shortValue(),sourceLoc.getLev1().shortValue());
+        News.warnNoLog("" + mark + " - 3" + " - 3" + " - 鍛戒护涓嬪彂 : 宸ヤ綔鍙�={},婧愭帓={},婧愬垪={},婧愬眰={},鐩爣鎺�={},鐩爣鍒�={},鐩爣灞�={}", wrkMast.getWrkNo().shortValue()
+                , sourceLoc.getRow1().shortValue(), sourceLoc.getBay1().shortValue(), sourceLoc.getLev1().shortValue()
+                , sourceLoc.getRow1().shortValue(), sourceLoc.getBay1().shortValue(), sourceLoc.getLev1().shortValue());
 
         // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
         CrnCommand crnCommand = new CrnCommand();
@@ -1325,7 +1603,7 @@
         crnCommand.setDestinationPosY(sourceLoc.getBay1().shortValue());     // 鐩爣搴撲綅鍒�
         crnCommand.setDestinationPosZ(sourceLoc.getLev1().shortValue());     // 鐩爣搴撲綅灞�
         if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
-            News.error(""+mark+" - 3"+" - 4"+" - 鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
+            News.error("" + mark + " - 3" + " - 4" + " - 鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
         } else {
             // 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓�
             Date now = new Date();
@@ -1333,10 +1611,10 @@
             wrkMast.setCrnStrTime(now);
             wrkMast.setModiTime(now);
             if (wrkMastMapper.updateById(wrkMast) == 0) {
-                News.error(""+mark+" - 3"+" - 5"+" - 銆愬簱浣嶇Щ杞�� 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo());
+                News.error("" + mark + " - 3" + " - 5" + " - 銆愬簱浣嶇Щ杞�� 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo());
             }
         }
-        News.infoNoLog(""+mark+" - 3"+" - 0"+" - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氬簱浣嶇Щ杞畬鎴�");
+        News.infoNoLog("" + mark + " - 3" + " - 0" + " - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氬簱浣嶇Щ杞畬鎴�");
 
     }
 
@@ -1353,37 +1631,56 @@
             }
             //  鐘舵�侊細绛夊緟纭 骞朵笖  浠诲姟瀹屾垚浣� = 1
             if (crnProtocol.statusType == CrnStatusType.WAITING && crnProtocol.getTaskNo() != 0) {
-                News.warnNoLog(""+mark+" - 0"+" - 寮�濮嬫墽琛屽宸ヤ綔妗g殑瀹屾垚鎿嶄綔");
+                News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛屽宸ヤ綔妗g殑瀹屾垚鎿嶄綔");
                 if (crnProtocol.getTaskNo() == 9999) {
                     // 鍫嗗灈鏈哄浣�
                     crnThread.setResetFlag(true);
-                } else {
-                    // 鑾峰彇鍏ュ簱寰呯‘璁ゅ伐浣滄。
-                    WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue());
-                    if (wrkMast == null) {
-                        News.error(""+mark+" - 1"+" - 鍫嗗灈鏈哄浜庣瓑寰呯‘璁や笖浠诲姟瀹屾垚鐘舵�侊紝浣嗘湭鎵惧埌宸ヤ綔妗c�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crn.getId(), crnProtocol.getTaskNo());
-                        continue;
-                    }
+                    continue;
+                }
+
+                // 鑾峰彇寰呯‘璁ゅ伐浣滄。
+                WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue());
+                if (wrkMast == null) {
+                    News.error("" + mark + " - 1" + " - 鍫嗗灈鏈哄浜庣瓑寰呯‘璁や笖浠诲姟瀹屾垚鐘舵�侊紝浣嗘湭鎵惧埌宸ヤ綔妗c�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crn.getId(), crnProtocol.getTaskNo());
+                    continue;
+                }
+
+                Date now = new Date();
+                if(wrkMast.getIoType() < 100){
                     // 鍏ュ簱 + 搴撲綅杞Щ  ==> 4.鍏ュ簱瀹屾垚
-                    if (wrkMast.getWrkSts() == 3 || (wrkMast.getWrkSts() == 12 && (wrkMast.getIoType() == 11 || wrkMast.getIoType()==111))) {
+                    if (wrkMast.getWrkSts() == 3 || (wrkMast.getWrkSts() == 12 && (wrkMast.getIoType() == 11 || wrkMast.getIoType() == 111))) {
                         wrkMast.setWrkSts(4L);
                     } else {
                         continue;
                     }
-                    Date now = new Date();
+
                     wrkMast.setCrnEndTime(now);
                     wrkMast.setModiTime(now);
                     // 淇敼鎴愬姛鍚庡浣嶅爢鍨涙満
                     if (wrkMastMapper.updateById(wrkMast) > 0) {
                         // 鍫嗗灈鏈哄浣�
-                        News.warnNoLog(""+mark+" - 2"+" - 淇敼鎴愬姛鍚庡浣嶅爢鍨涙満 : 鍫嗗灈鏈哄彿={}",crnThread.getCrnProtocol().getCrnNo());
+                        News.warnNoLog("" + mark + " - 2" + " - 淇敼鎴愬姛鍚庡浣嶅爢鍨涙満 : 鍫嗗灈鏈哄彿={}", crnThread.getCrnProtocol().getCrnNo());
+                        crnThread.setResetFlag(true);
+                    }
+                }else {
+                    List<Long> list = new ArrayList<>();
+                    list.add(14L);
+                    list.add(15L);
+                    if (!list.contains(wrkMast.getWrkSts())) {
+                        News.error("" + mark + " - 1" + " - 鍫嗗灈鏈哄浜庣瓑寰呯‘璁や絾宸ヤ綔妗g姸鎬佹湭瀹屾垚銆傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crn.getId(), crnProtocol.getTaskNo());
+                        continue;
+                    }
+
+                    wrkMast.setCrnEndTime(now);
+                    if (wrkMastMapper.updateById(wrkMast) != 0) {
+                        // 澶嶄綅鍫嗗灈鏈�
                         crnThread.setResetFlag(true);
                     }
                 }
 
             }
         }
-        News.infoNoLog(""+mark+" - 0"+" - 瀵瑰伐浣滄。鐨勫畬鎴愭搷浣滄墽琛屽畬鎴�");
+        News.infoNoLog("" + mark + " - 0" + " - 瀵瑰伐浣滄。鐨勫畬鎴愭搷浣滄墽琛屽畬鎴�");
     }
 
     /**
@@ -1406,7 +1703,7 @@
                     BasErrLog latest = basErrLogService.findLatestByTaskNo(crn.getId(), crnProtocol.getTaskNo().intValue());
                     // 鏈夊紓甯�
                     if (latest == null) {
-                        News.warnNoLog(""+mark+" - 1"+" - 寮�濮嬫墽琛岋細鍫嗗灈鏈哄紓甯镐俊鎭褰� 锛� 鏈変换鍔★紝鏈夊紓甯�");
+                        News.warnNoLog("" + mark + " - 1" + " - 寮�濮嬫墽琛岋細鍫嗗灈鏈哄紓甯镐俊鎭褰� 锛� 鏈変换鍔★紝鏈夊紓甯�");
                         if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) {
                             WrkMast wrkMast = wrkMastMapper.selectById(crnProtocol.getTaskNo());
                             if (wrkMast == null) {
@@ -1438,7 +1735,7 @@
                                     "浠诲姟涓紓甯�"    // 澶囨敞
                             );
                             if (!basErrLogService.insert(basErrLog)) {
-                                News.error(""+mark+" - 2"+" - 鍫嗗灈鏈簆lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", crn.getId(), errName);
+                                News.error("" + mark + " - 2" + " - 鍫嗗灈鏈簆lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", crn.getId(), errName);
                             }
                         }
                     } else {
@@ -1448,7 +1745,7 @@
                             latest.setUpdateTime(now);
                             latest.setStatus(2);
                             if (!basErrLogService.updateById(latest)) {
-                                News.error(""+mark+" - 3"+" - 鍫嗗灈鏈簆lc寮傚父璁板綍淇澶辫触 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
+                                News.error("" + mark + " - 3" + " - 鍫嗗灈鏈簆lc寮傚父璁板綍淇澶辫触 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
                             }
                         }
                     }
@@ -1457,7 +1754,7 @@
                     BasErrLog latest = basErrLogService.findLatest(crn.getId());
                     // 鏈夊紓甯�
                     if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) {
-                        News.warnNoLog(""+mark+" - 4"+" - 寮�濮嬫墽琛岋細鍫嗗灈鏈哄紓甯镐俊鎭褰� 锛� 鏃犱换鍔★紝鏈夊紓甯�");
+                        News.warnNoLog("" + mark + " - 4" + " - 寮�濮嬫墽琛岋細鍫嗗灈鏈哄紓甯镐俊鎭褰� 锛� 鏃犱换鍔★紝鏈夊紓甯�");
                         // 璁板綍鏂板紓甯�
                         if (latest == null || (latest.getErrCode() != crnProtocol.getAlarm().intValue())) {
                             BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm());
@@ -1486,7 +1783,7 @@
                                     "鏃犱换鍔″紓甯�"    // 澶囨敞
                             );
                             if (!basErrLogService.insert(basErrLog)) {
-                                News.error(""+mark+" - 5"+" - 鍫嗗灈鏈簆lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", crn.getId(), errName);
+                                News.error("" + mark + " - 5" + " - 鍫嗗灈鏈簆lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", crn.getId(), errName);
                             }
                         }
                         // 鏃犲紓甯�
@@ -1497,7 +1794,7 @@
                             latest.setUpdateTime(now);
                             latest.setStatus(2);
                             if (!basErrLogService.updateById(latest)) {
-                                News.error(""+mark+" - 6"+" - 鍫嗗灈鏈簆lc寮傚父璁板綍淇澶辫触 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
+                                News.error("" + mark + " - 6" + " - 鍫嗗灈鏈簆lc寮傚父璁板綍淇澶辫触 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
                             }
                         }
                     }
@@ -1505,7 +1802,7 @@
             }
 
         }
-        News.infoNoLog(""+mark+" - 0"+" - 鍫嗗灈鏈哄紓甯镐俊鎭褰曟墽琛屽畬鎴�");
+        News.infoNoLog("" + mark + " - 0" + " - 鍫嗗灈鏈哄紓甯镐俊鎭褰曟墽琛屽畬鎴�");
     }
 
 
@@ -1529,11 +1826,17 @@
                 }
 
                 LedThread ledThread = null;
-                if (!Cools.isEmpty(emptyInSta.getLed()))  {
+                if (!Cools.isEmpty(emptyInSta.getLed())) {
                     ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, emptyInSta.getLed());
                 }
 
-                if (!staProtocol.isLoading()){
+                if (!staProtocol.isLoading()) {
+                    continue;
+                }
+
+                // 鑾峰彇鏉$爜鎵弿浠俊鎭�
+                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, emptyInSta.getBarcode());
+                if (barcodeThread == null) {
                     continue;
                 }
 
@@ -1542,8 +1845,32 @@
                         && staProtocol.isInEnable()
                         && staProtocol.isEmptyMk()
                         && (staProtocol.getWorkNo() > 9990 && staProtocol.getWorkNo() <= 9999)
-                        && staProtocol.isPakMk()) {
-                    News.warnNoLog(""+mark+" - 0"+" - 寮�濮嬫墽琛岋細绌烘爤鏉垮垵濮嬪寲鍏ュ簱,鍙夎溅鍏ュ簱绔欐斁璐�");
+                        && staProtocol.isPakMk()
+                        && staProtocol.getEmptyInType() == 1
+                ) {
+                    News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛岋細绌烘爤鏉垮垵濮嬪寲鍏ュ簱,鍙夎溅鍏ュ簱绔欐斁璐�");
+
+                    String barcode = barcodeThread.getBarcode();
+                    if (!Cools.isEmpty(barcode)) {
+                        News.info("" + mark + " - 1" + " - {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", emptyInSta.getBarcode(), barcode);
+                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
+                            News.info("" + mark + " - 2" + " - 鎵爜澶辫触1 ===>> {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{},绔欑偣:{}", emptyInSta.getBarcode(), barcode, emptyInSta.getStaNo());
+                            // led 寮傚父鏄剧ず
+                            if (ledThread != null) {
+                                String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯";
+                                MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
+                            }
+                            continue;
+                        }
+                    } else {
+                        News.info("" + mark + " - 3" + " - 鎵爜澶辫触2 ===>> {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{},绔欑偣:{}", emptyInSta.getBarcode(), barcode, emptyInSta.getStaNo());
+                        // led 寮傚父鏄剧ず
+                        if (ledThread != null) {
+                            String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯";
+                            MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
+                        }
+                        continue;
+                    }
 
                     try {
                         LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
@@ -1552,6 +1879,7 @@
                         param.setIoType(10);
                         param.setSourceStaNo(emptyInSta.getStaNo());
                         param.setLocType1(locTypeDto.getLocType1());
+                        param.setBarcode(barcode);
                         String response = new HttpHandler.Builder()
                                 .setUri(wmsUrl)
                                 .setPath("/rpc/pakin/loc/v1")
@@ -1562,61 +1890,148 @@
                         if (jsonObject.getInteger("code").equals(200)) {
                             StartupDto dto = jsonObject.getObject("data", StartupDto.class);
 
+                            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
+                                    .eq("loc_no", dto.getLocNo()));
+
                             // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
                             staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                             staProtocol.setStaNo(dto.getStaNo().shortValue());
+                            staProtocol.setPalletSize(locMast.getLocType2());
                             devpThread.setPakMk(staProtocol.getSiteId(), false);
                             boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                             if (!result) {
-                                News.errorNoLog(""+mark+" - 1"+" - 鏇存柊plc绔欑偣淇℃伅澶辫触");
+                                News.errorNoLog("" + mark + " - 1" + " - 鏇存柊plc绔欑偣淇℃伅澶辫触");
                                 throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
-                            }
-
-                            if (ledThread != null) {
-                                // 鍛戒护闆嗗悎
-                                List<LedCommand> commands = new ArrayList<>();
-                                // 缁勮鍛戒护
-                                LedCommand ledCommand = new LedCommand();
-                                ledCommand.setWorkNo(dto.getWorkNo());
-                                ledCommand.setIoType(1);
-                                ledCommand.setTitle("鍏ㄦ澘鍏ュ簱");
-                                ledCommand.setLocNo(dto.getLocNo());
-                                ledCommand.setStaNo(dto.getStaNo());
-                                commands.add(ledCommand);
-                                MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(3, commands));
-//                                ledThread.errorReset();
                             }
                         } else {
-                            staProtocol.setWorkNo((short)9992);
-                            staProtocol.setStaNo(emptyInSta.getBackSta().shortValue());
-                            devpThread.setPakMk(staProtocol.getSiteId(), false);
-                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
-                            if (!result) {
-                                News.errorNoLog(""+mark+" - 2"+" - 鏇存柊plc绔欑偣淇℃伅澶辫触");
-                                throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
-                            }
-
                             if (ledThread != null) {
                                 String errorMsg = jsonObject.getString("msg");
                                 if (!Cools.isEmpty(errorMsg)) {
                                     MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
                                 }
                             }
-                            News.error(""+mark+" - 3"+" - 璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
+                            News.error("" + mark + " - 3" + " - 璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                         }
                     } catch (Exception e) {
                         e.printStackTrace();
-                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                     }
-
                 } else {
-                    News.errorNoLog(""+mark+" - 4"+" - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒"+" 鑷姩淇″彿锛�"+staProtocol.isAutoing()+"銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable()
-                            +"銆佺┖鏉夸俊鍙凤細"+ staProtocol.isEmptyMk()+"銆佸伐浣滃彿锛�" + staProtocol.getWorkNo()
-                            +"銆侀攣瀹氭爣璁�"+ staProtocol.isPakMk());
+                    News.errorNoLog("" + mark + " - 4" + " - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒" + " 鑷姩淇″彿锛�" + staProtocol.isAutoing() + "銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable()
+                            + "銆佺┖鏉夸俊鍙凤細" + staProtocol.isEmptyMk() + "銆佸伐浣滃彿锛�" + staProtocol.getWorkNo()
+                            + "銆侀攣瀹氭爣璁�" + staProtocol.isPakMk());
                 }
             }
         }
-        News.infoNoLog(""+mark+" - 0"+" - 绌烘爤鏉垮垵濮嬪寲鍏ュ簱,鍙夎溅鍏ュ簱绔欐斁璐ф墽琛屽畬鎴�");
+        News.infoNoLog("" + mark + " - 0" + " - 绌烘爤鏉垮垵濮嬪寲鍏ュ簱,鍙夎溅鍏ュ簱绔欐斁璐ф墽琛屽畬鎴�");
+    }
+
+    /**
+     * 绌烘墭鐩樺叆搴�-浜х嚎
+     */
+    public synchronized void storeEmptyPltLine(Integer mark) {
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            // 閬嶅巻绌烘澘鍏ュ簱鍙�
+            for (DevpSlave.Sta emptyInSta : devp.getEmptyInSta()) {
+                // 鑾峰彇绌烘澘鍏ュ簱绔欎俊鎭�
+                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+                StaProtocol staProtocol = devpThread.getStation().get(emptyInSta.getStaNo());
+                if (staProtocol == null) {
+                    continue;
+                } else {
+                    staProtocol = staProtocol.clone();
+                }
+
+                LedThread ledThread = null;
+                if (!Cools.isEmpty(emptyInSta.getLed())) {
+                    ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, emptyInSta.getLed());
+                }
+
+                if (!staProtocol.isLoading()) {
+                    continue;
+                }
+
+                // 鑾峰彇鏉$爜鎵弿浠俊鎭�
+                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, emptyInSta.getBarcode());
+                if (barcodeThread == null) {
+                    continue;
+                }
+
+                // 绔欑偣鏉′欢鍒ゆ柇
+                if (staProtocol.isAutoing()
+                        && staProtocol.isInEnable()
+                        && staProtocol.isEmptyMk()
+                        && (staProtocol.getWorkNo() > 9990 && staProtocol.getWorkNo() <= 9999)
+                        && staProtocol.isPakMk()
+                        && staProtocol.getEmptyInType() == 2
+                ) {
+                    News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛岋細绌烘爤鏉垮垵濮嬪寲鍏ュ簱,鍙夎溅鍏ュ簱绔欐斁璐�");
+
+                    String barcode = barcodeThread.getBarcode();
+                    if (!Cools.isEmpty(barcode)) {
+                        News.info("" + mark + " - 1" + " - {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", emptyInSta.getBarcode(), barcode);
+                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
+                            News.info("" + mark + " - 2" + " - 鎵爜澶辫触1 ===>> {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{},绔欑偣:{}", emptyInSta.getBarcode(), barcode, emptyInSta.getStaNo());
+                            // led 寮傚父鏄剧ず
+                            if (ledThread != null) {
+                                String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯";
+                                MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
+                            }
+                            continue;
+                        }
+                    } else {
+                        News.info("" + mark + " - 3" + " - 鎵爜澶辫触2 ===>> {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{},绔欑偣:{}", emptyInSta.getBarcode(), barcode, emptyInSta.getStaNo());
+                        // led 寮傚父鏄剧ず
+                        if (ledThread != null) {
+                            String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯";
+                            MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
+                        }
+                        continue;
+                    }
+
+                    WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
+                            .eq("barcode", barcode)
+                    );
+                    if (wrkMast != null) {
+                        continue;
+                    }
+
+                    int workNo = commonService.getWorkNo(3);
+                    // 鐢熸垚宸ヤ綔妗�
+                    WrkMast wrkMast1 = new WrkMast();
+                    wrkMast1.setWrkNo(workNo);
+                    wrkMast1.setIoTime(new Date());
+                    wrkMast1.setWrkSts(2L); // 宸ヤ綔鐘舵�侊細璁惧涓婅蛋
+                    wrkMast1.setIoType(3); // 鍏ュ嚭搴撶姸鎬侊細3.绔欏埌绔�
+                    wrkMast1.setIoPri(13D); // 浼樺厛绾�
+                    wrkMast1.setSourceStaNo(emptyInSta.getStaNo());
+                    wrkMast1.setStaNo(1007);
+                    wrkMast1.setBarcode(barcode);
+                    // 鎿嶄綔浜哄憳鏁版嵁
+                    wrkMast1.setAppeTime(new Date());
+                    wrkMast1.setModiTime(new Date());
+                    boolean res = wrkMastService.insert(wrkMast1);
+                    if (!res) {
+                        throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
+                    }
+
+                    // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
+                    staProtocol.setWorkNo((short) workNo);
+                    staProtocol.setStaNo((short) 2003);
+                    staProtocol.setPalletSize((short) 1);
+                    devpThread.setPakMk(staProtocol.getSiteId(), false);
+                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+                    if (!result) {
+                        News.errorNoLog("" + mark + " - 1" + " - 鏇存柊plc绔欑偣淇℃伅澶辫触");
+                        throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
+                    }
+                } else {
+                    News.errorNoLog("" + mark + " - 4" + " - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒" + " 鑷姩淇″彿锛�" + staProtocol.isAutoing() + "銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable()
+                            + "銆佺┖鏉夸俊鍙凤細" + staProtocol.isEmptyMk() + "銆佸伐浣滃彿锛�" + staProtocol.getWorkNo()
+                            + "銆侀攣瀹氭爣璁�" + staProtocol.isPakMk());
+                }
+            }
+        }
+        News.infoNoLog("" + mark + " - 0" + " - 绌烘爤鏉垮垵濮嬪寲鍏ュ簱,鍙夎溅鍏ュ簱绔欐斁璐ф墽琛屽畬鎴�");
     }
 
     /**
@@ -1645,7 +2060,7 @@
                 if (null == wrkMast) {
                     continue;
                 }
-                News.warnNoLog(""+mark+" - 0"+" - 寮�濮嬫墽琛�:鍑哄簱  ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣�");
+                News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�:鍑哄簱  ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣�");
                 wrkMasts.add(wrkMast);
                 // 缁勮鍛戒护
                 LedCommand ledCommand = new LedCommand();
@@ -1685,7 +2100,7 @@
                         ledCommand.setTitle("骞舵澘鍏ュ簱");
                         break;
                     default:
-                        News.error(""+mark+" - 1"+" - 浠诲姟鍏ュ嚭搴撶被鍨嬮敊璇紒锛侊紒[宸ヤ綔鍙凤細{}] [鍏ュ嚭搴撶被鍨嬶細{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
+                        News.error("" + mark + " - 1" + " - 浠诲姟鍏ュ嚭搴撶被鍨嬮敊璇紒锛侊紒[宸ヤ綔鍙凤細{}] [鍏ュ嚭搴撶被鍨嬶細{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
                         break;
                 }
                 ledCommand.setSourceLocNo(wrkMast.getSourceLocNo());
@@ -1723,6 +2138,7 @@
                             , wrkDetl.getSupp()
                             , wrkDetl.getKpCstmrName()
                             , wrkDetl.getOrderNo()
+                            , wrkDetl.getCstateid$()
                     )));
                 }
                 commands.add(ledCommand);
@@ -1758,7 +2174,7 @@
                 if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) {
                     News.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
                     continue;
-                }else {
+                } else {
                     ledThread.setLedMk(false);
                 }
             }
@@ -1769,7 +2185,7 @@
                     wrkMast.setOveMk("Y");
                     wrkMast.setModiTime(new Date());
                     if (wrkMastMapper.updateById(wrkMast) == 0) {
-                        News.errorNoLog(""+mark+" - 4"+" - 鏇存柊宸ヤ綔妗eけ璐�");
+                        News.errorNoLog("" + mark + " - 4" + " - 鏇存柊宸ヤ綔妗eけ璐�");
                         throw new CoolException("鏇存柊宸ヤ綔妗eけ璐�");
                     }
                 }
@@ -1783,7 +2199,7 @@
             }
 
         }
-        News.infoNoLog(""+mark+" - 0"+" - 鍑哄簱  ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣ㄦ墽琛屽畬鎴�");
+        News.infoNoLog("" + mark + " - 0" + " - 鍑哄簱  ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣ㄦ墽琛屽畬鎴�");
     }
 
     /**
@@ -1791,7 +2207,7 @@
      */
     public synchronized void ledReset(Integer mark) {
 
-        News.warnNoLog(""+mark+" - 0"+" - 寮�濮嬫墽琛�:鍏朵粬  ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅");
+        News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�:鍏朵粬  ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅");
         for (LedSlave led : slaveProperties.getLed()) {
 
             // 鑾峰彇杈撻�佺嚎plc绾跨▼
@@ -1815,13 +2231,13 @@
             if (reset && !ledThread.isLedMk()) {
                 ledThread.setLedMk(true);
                 if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
-                    News.error(""+mark+" - 1"+" - {}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                    News.error("" + mark + " - 1" + " - {}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
                 } else {
 
                 }
             }
         }
-        News.infoNoLog(""+mark+" - 0"+" - 鎵ц瀹屾垚锛氬叾浠�  ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅");
+        News.infoNoLog("" + mark + " - 0" + " - 鎵ц瀹屾垚锛氬叾浠�  ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅");
     }
 
     /**
@@ -1905,10 +2321,10 @@
      * 鍥犲弻娣卞簱浣嶉樆濉烇紝瀵规祬搴撲綅杩涜绉昏浆锛堢珛鍗虫墽琛岀増)
      * tip锛氬悓姝�
      */
-    private synchronized boolean moveLocForDeepLoc(CrnSlave crn, LocMast shallowLoc,Integer mark) {
+    private synchronized boolean moveLocForDeepLoc(CrnSlave crn, LocMast shallowLoc, Integer mark) {
 
         try {
-            News.warnNoLog(""+mark+"moveLocForDeepLoc"+" - 0"+" - 寮�濮嬫墽琛�:鍥犲弻娣卞簱浣嶉樆濉烇紝瀵规祬搴撲綅杩涜绉昏浆锛堢珛鍗虫墽琛岀増)");
+            News.warnNoLog("" + mark + "moveLocForDeepLoc" + " - 0" + " - 寮�濮嬫墽琛�:鍥犲弻娣卞簱浣嶉樆濉烇紝瀵规祬搴撲綅杩涜绉昏浆锛堢珛鍗虫墽琛岀増)");
             List<Integer> rows = locMastService.queryDistinctRow(crn.getId());
             LocMast loc = null;
             for (Integer row : rows) {
@@ -1950,7 +2366,7 @@
             }
 
             if (null == loc) {
-                News.error(""+mark+"moveLocForDeepLoc"+" - 1"+" - 鍙屾繁搴撲綅 --- 娴呭簱浣嶉樆濉炲紓甯革紒 寰呯Щ杞祬搴撲綅锛�" + shallowLoc.getLocNo());
+                News.error("" + mark + "moveLocForDeepLoc" + " - 1" + " - 鍙屾繁搴撲綅 --- 娴呭簱浣嶉樆濉炲紓甯革紒 寰呯Щ杞祬搴撲綅锛�" + shallowLoc.getLocNo());
                 return false;
 //                throw new CoolException("鍙屾繁搴撲綅 --- 娴呭簱浣嶉樆濉炲紓甯革紒 寰呯Щ杞祬搴撲綅锛�" + shallowLoc.getLocNo());
             } else {
@@ -1978,7 +2394,7 @@
                     wrkMast.setModiTime(new Date());
                     int res = wrkMastMapper.insert(wrkMast);
                     if (res == 0) {
-                        News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 2"+" - 淇濆瓨宸ヤ綔妗eけ璐�");
+                        News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 2" + " - 淇濆瓨宸ヤ綔妗eけ璐�");
 //                        throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
                         return true;
                     }
@@ -1996,7 +2412,7 @@
                             wrkDetl.setAppeTime(new Date());
                             wrkDetl.setModiTime(new Date());
                             if (!wrkDetlService.insert(wrkDetl)) {
-                                News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 3"+" - 淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
+                                News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 3" + " - 淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
 //                                throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
                                 return true;
                             }
@@ -2007,12 +2423,12 @@
                         shallowLoc.setLocSts("R"); // R.鍑哄簱棰勭害
                         shallowLoc.setModiTime(new Date());
                         if (!locMastService.updateById(shallowLoc)) {
-                            News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 4"+" - 鏇存柊婧愬簱浣嶇姸鎬佸け璐�");
+                            News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 4" + " - 鏇存柊婧愬簱浣嶇姸鎬佸け璐�");
 //                            throw new CoolException("鏇存柊婧愬簱浣嶇姸鎬佸け璐�");
                             return true;
                         }
                     } else {
-                        News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 5"+" - 婧愬簱浣嶅嚭搴撳け璐�");
+                        News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 5" + " - 婧愬簱浣嶅嚭搴撳け璐�");
 //                        throw new CoolException("婧愬簱浣嶅嚭搴撳け璐�");
                         return true;
                     }
@@ -2021,23 +2437,23 @@
                         loc.setLocSts("S"); // S.鍏ュ簱棰勭害
                         loc.setModiTime(new Date());
                         if (!locMastService.updateById(loc)) {
-                            News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 6"+" - 鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
+                            News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 6" + " - 鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
 //                            throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
                             return true;
                         }
                     } else {
-                        News.errorNoLog(""+mark+"moveLocForDeepLoc"+" - 7"+" - 绉昏浆澶辫触");
+                        News.errorNoLog("" + mark + "moveLocForDeepLoc" + " - 7" + " - 绉昏浆澶辫触");
 //                        throw new CoolException("绉昏浆澶辫触");
                         return true;
                     }
-                } catch (Exception e){
-                    News.error(""+mark+"moveLocForDeepLoc"+" - 8"+" - 鍙屾繁搴撲綅闃诲锛屽娴呭簱浣嶈繘琛岀Щ杞け璐�", e);
+                } catch (Exception e) {
+                    News.error("" + mark + "moveLocForDeepLoc" + " - 8" + " - 鍙屾繁搴撲綅闃诲锛屽娴呭簱浣嶈繘琛岀Щ杞け璐�", e);
                 }
             }
 
 
         } catch (Exception e) {
-            News.error(""+mark+"moveLocForDeepLoc"+" - 8"+" - 鍙屾繁搴撲綅闃诲锛屽娴呭簱浣嶈繘琛岀Щ杞け璐�", e);
+            News.error("" + mark + "moveLocForDeepLoc" + " - 8" + " - 鍙屾繁搴撲綅闃诲锛屽娴呭簱浣嶈繘琛岀Щ杞け璐�", e);
 //            e.printStackTrace();
 //            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         }
@@ -2203,16 +2619,22 @@
 
     // RGV  ===>> 鎵ц瀵筊GV鎿嶄綔
     public synchronized void rgvExecute(Integer mark) {
-        ArrayList<Integer> list = new ArrayList<Integer>(){{add(2003);add(2002);}};
+        ArrayList<Integer> list = new ArrayList<Integer>() {{
+            add(2003);
+            add(2002);
+        }};
         for (Integer staNo : list) {
             Integer devpId = null;
+            Integer rgvStaNoDevpId = null;
             Integer rgvStaNo = null;
             if (staNo == 2003) {
                 devpId = 1;
                 rgvStaNo = 2002;
-            }else {
+                rgvStaNoDevpId = 2;
+            } else {
                 devpId = 2;
                 rgvStaNo = 2003;
+                rgvStaNoDevpId = 1;
             }
 
             SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devpId);
@@ -2228,12 +2650,54 @@
 
             if (staProtocol.isAutoing()
                     && staProtocol.isLoading()
-//                    && staProtocol.isInEnable()
+                    && staProtocol.isInEnable()
                     && staProtocol.getWorkNo() > 0
             ) {
                 WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
                         .eq("wrk_no", staProtocol.getWorkNo()));
+
+                if (wrkMast == null) {
+                    continue;
+                }
+
                 if (wrkMast.getWrkSts() == 201) {
+                    continue;
+                }
+
+                SiemensDevpThread devpThread2 = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, rgvStaNoDevpId);
+                if (devpThread2 == null) {
+                    continue;
+                }
+                StaProtocol staProtocolRgvStaNo = devpThread2.getStation().get(rgvStaNo);
+                if (staProtocolRgvStaNo == null) {
+                    continue;
+                }
+
+                if (!staProtocolRgvStaNo.isAutoing()) {
+                    continue;
+                }
+
+                if (staProtocolRgvStaNo.isLoading()) {
+                    continue;
+                }
+
+                // 鑾峰彇RGV淇℃伅
+                RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, 1);
+                if (rgvThread == null) {
+                    continue;
+                }
+
+                RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
+                if (rgvProtocol == null) {
+                    continue;
+                }
+
+                if (rgvProtocol.statusType1 != RgvStatusType.IDLE && rgvProtocol.getTaskNo1() != 0) {
+                    continue;
+                }
+
+                Object object = redisUtil.get(RedisConstantType.RGV_MOVE_LOCK + wrkMast.getWrkNo());
+                if (object != null) {
                     continue;
                 }
 
@@ -2254,6 +2718,7 @@
                 wrkMast.setWrkSts(201L);//201.RGV鎼繍涓�
                 wrkMast.setModiTime(new Date());
                 wrkMastService.updateById(wrkMast);
+                redisUtil.set(RedisConstantType.RGV_MOVE_LOCK + wrkMast.getWrkNo(), "lock", 60 * 60);
             }
         }
     }
@@ -2274,11 +2739,20 @@
 
             //  鐘舵�侊細绛夊緟纭 骞朵笖  浠诲姟瀹屾垚浣� = 1
             if (rgvProtocol.statusType1 == RgvStatusType.WAITING && rgvProtocol.getTaskNo1() != 0) {
-                News.warnNoLog(""+mark+" - 0"+" - 寮�濮嬫墽琛屽RGV宸ヤ綔妗g殑瀹屾垚鎿嶄綔");
+                News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛屽RGV宸ヤ綔妗g殑瀹屾垚鎿嶄綔");
                 // 鑾峰彇鍏ュ簱寰呯‘璁ゅ伐浣滄。
                 WrkMast wrkMast = wrkMastMapper.selectPakInStep3(rgvProtocol.getTaskNo1().intValue());
                 if (wrkMast == null) {
-                    News.error(""+mark+" - 1"+" - RGV澶勪簬绛夊緟纭涓斾换鍔″畬鎴愮姸鎬侊紝浣嗘湭鎵惧埌宸ヤ綔妗c�俁GV鍙�={}锛屽伐浣滃彿={}", rgvSlave.getId(), rgvProtocol.getTaskNo1());
+                    News.error("" + mark + " - 1" + " - RGV澶勪簬绛夊緟纭涓斾换鍔″畬鎴愮姸鎬侊紝浣嗘湭鎵惧埌宸ヤ綔妗c�俁GV鍙�={}锛屽伐浣滃彿={}", rgvSlave.getId(), rgvProtocol.getTaskNo1());
+                    continue;
+                }
+
+                if (wrkMast.getWrkSts() != 201) {
+                    continue;
+                }
+
+                if (wrkMast.getIoType() == 3) {
+                    //绔欏埌绔欒蛋鍙﹀涓�涓柟娉�
                     continue;
                 }
 
@@ -2292,7 +2766,7 @@
                     devpId = 1;
                     devpStaNo = 2003;
                     locNo = wrkMast.getLocNo();
-                }else {
+                } else {
                     //鍑哄簱
                     updateWrkSts = 15L;
                     devpId = 2;
@@ -2328,7 +2802,87 @@
                 }
             }
         }
-        News.infoNoLog(""+mark+" - 0"+" - 瀵瑰伐浣滄。鐨勫畬鎴愭搷浣滄墽琛屽畬鎴�");
+        News.infoNoLog("" + mark + " - 0" + " - 瀵瑰伐浣滄。鐨勫畬鎴愭搷浣滄墽琛屽畬鎴�");
+    }
+
+    // RGV  ===>> 鎵ц瀵筊GV宸ヤ綔妗g殑瀹屾垚鎿嶄綔 绔欏埌绔�
+    public synchronized void rgvFinished2(Integer mark) {
+        for (RgvSlave rgvSlave : slaveProperties.getRgv()) {
+            // 鑾峰彇RGV淇℃伅
+            RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId());
+            if (rgvThread == null) {
+                continue;
+            }
+
+            RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
+            if (rgvProtocol == null) {
+                continue;
+            }
+
+            //  鐘舵�侊細绛夊緟纭 骞朵笖  浠诲姟瀹屾垚浣� = 1
+            if (rgvProtocol.statusType1 == RgvStatusType.WAITING && rgvProtocol.getTaskNo1() != 0) {
+                News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛屽RGV宸ヤ綔妗g殑瀹屾垚鎿嶄綔");
+                // 鑾峰彇鍏ュ簱寰呯‘璁ゅ伐浣滄。
+                WrkMast wrkMast = wrkMastMapper.selectPakInStep3(rgvProtocol.getTaskNo1().intValue());
+                if (wrkMast == null) {
+                    News.error("" + mark + " - 1" + " - RGV澶勪簬绛夊緟纭涓斾换鍔″畬鎴愮姸鎬侊紝浣嗘湭鎵惧埌宸ヤ綔妗c�俁GV鍙�={}锛屽伐浣滃彿={}", rgvSlave.getId(), rgvProtocol.getTaskNo1());
+                    continue;
+                }
+
+                if (wrkMast.getWrkSts() != 201) {
+                    continue;
+                }
+
+                if (wrkMast.getIoType() != 3) {
+                    //涓嶆槸绔欏埌绔�
+                    continue;
+                }
+
+                Integer devpId = 2;
+                Integer devpStaNo = 2002;
+
+                // 鑾峰彇鍏ュ簱绔欎俊鎭�
+                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devpId);
+                StaProtocol staProtocol = devpThread.getStation().get(devpStaNo);
+                if (staProtocol == null) {
+                    continue;
+                } else {
+                    staProtocol = staProtocol.clone();
+                }
+
+                if (staProtocol.isAutoing()
+                        && staProtocol.isLoading()
+                        && staProtocol.getWorkNo() == 0
+                ) {
+
+                    short locType2 = 1;
+                    String barcode = wrkMast.getBarcode();
+                    if (barcode.startsWith("11")) {
+                        locType2 = 1;
+                    } else if (barcode.startsWith("13")) {
+                        locType2 = 2;
+                    } else if (barcode.startsWith("16")) {
+                        locType2 = 3;
+                    } else {
+                        continue;
+                    }
+
+                    staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
+                    staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
+                    staProtocol.setPalletSize(locType2);
+                    devpThread.setPakMk(staProtocol.getSiteId(), false);
+                    boolean result = MessageQueue.offer(SlaveType.Devp, devpId, new Task(2, staProtocol));
+                    if (!result) {
+                        throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
+                    }
+                    rgvThread.setResetFlag1(true);
+
+                    wrkMastService.delete(new EntityWrapper<WrkMast>()
+                            .eq("wrk_no", wrkMast.getWrkNo()));
+                }
+            }
+        }
+        News.infoNoLog("" + mark + " - 0" + " - 瀵瑰伐浣滄。鐨勫畬鎴愭搷浣滄墽琛屽畬鎴�");
     }
 
 //    /**

--
Gitblit v1.9.1