From 22c00fb3f44e8ddda0380e156fa1500f01e323d5 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期一, 11 八月 2025 16:08:14 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  148 +++++++++++++++++++++++++++----------------------
 1 files changed, 81 insertions(+), 67 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 b37c954..7a71fb3 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -650,75 +650,73 @@
      * 鍫嗗灈鏈虹珯鍑哄簱鍒板嚭搴撶珯
      */
     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.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;
-                    }
-                    // 鍒ゆ柇鍚婅溅鏄惁瀹為檯宸插畬鎴愶紝涓旂數鑴戠姸鎬佸湪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());
-                        }
-
+                    // 鏇存柊宸ヤ綔妗g姸鎬佷负14澶辫触
+                    wrkMast.setWrkSts(14L);
+                    wrkMast.setCrnEndTime(new Date());
+                    if (wrkMastMapper.updateById(wrkMast) != 0) {
+                        News.info("" + 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.error("" + mark + " - 1" + " - 鏇存柊宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负14澶辫触锛侊紒锛� [宸ヤ綔鍙�:{}]", wrkMast.getWrkNo());
                     }
-
                 }
             }
         }
+
         News.infoNoLog("" + mark + " - 0" + " - 鍫嗗灈鏈虹珯鍑哄簱鍒板嚭搴撶珯  ===銆嬫墽琛屽畬鎴�");
     }
 
@@ -1627,20 +1625,25 @@
                 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))) {
                         wrkMast.setWrkSts(4L);
                     } else {
                         continue;
                     }
-                    Date now = new Date();
+
                     wrkMast.setCrnEndTime(now);
                     wrkMast.setModiTime(now);
                     // 淇敼鎴愬姛鍚庡浣嶅爢鍨涙満
@@ -1649,6 +1652,17 @@
                         News.warnNoLog("" + mark + " - 2" + " - 淇敼鎴愬姛鍚庡浣嶅爢鍨涙満 : 鍫嗗灈鏈哄彿={}", crnThread.getCrnProtocol().getCrnNo());
                         crnThread.setResetFlag(true);
                     }
+                }else {
+                    if (wrkMast.getWrkSts() != 14) {
+                        News.error("" + mark + " - 1" + " - 鍫嗗灈鏈哄浜庣瓑寰呯‘璁や絾宸ヤ綔妗g姸鎬佹湭瀹屾垚銆傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crn.getId(), crnProtocol.getTaskNo());
+                        continue;
+                    }
+
+                    wrkMast.setCrnEndTime(now);
+                    if (wrkMastMapper.updateById(wrkMast) != 0) {
+                        // 澶嶄綅鍫嗗灈鏈�
+                        crnThread.setResetFlag(true);
+                    }
                 }
 
             }

--
Gitblit v1.9.1