From 4dbce6777784f9e4f0da92d03d8b966188bf2393 Mon Sep 17 00:00:00 2001
From: ytfl <ytfl@qq.com>
Date: 星期五, 18 七月 2025 14:31:31 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  173 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 151 insertions(+), 22 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 f662ddf..9ead8e8 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -13,7 +13,6 @@
 import com.zy.asrs.mapper.WrkMastMapper;
 import com.zy.asrs.service.*;
 import com.zy.asrs.utils.Utils;
-import com.zy.asrs.utils.VersionUtils;
 import com.zy.common.constant.RedisConstantType;
 import com.zy.common.model.LocTypeDto;
 import com.zy.common.model.MatDto;
@@ -463,6 +462,7 @@
                         wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 鐩爣搴撲綅 = 鍑哄簱鏃剁殑婧愬簱浣�
                         wrkMast.setSourceLocNo(""); // 婧愬簱浣嶆竻绌�
                         wrkMast.setModiTime(now);
+                        wrkMast.setUpdMk("");//鍏佽鍐嶆绉诲簱
                         if (wrkMastMapper.updateById(wrkMast) == 0) {
                             throw new CoolException("鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
                         }
@@ -644,6 +644,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();
@@ -681,6 +685,78 @@
                 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 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()); // 鍫嗗灈鏈虹紪鍙�
@@ -787,21 +863,27 @@
                 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);
                     } 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)){
@@ -819,7 +901,7 @@
                     }
                     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());
@@ -827,7 +909,7 @@
                     }
                 }
             }
-            News.warnNoLog(""+mark+" - 1"+" - 15"+" - 鍛戒护涓嬪彂 : 宸ヤ綔鍙�={},婧愭帓={},婧愬垪={},婧愬眰={},鐩爣鎺�={},鐩爣鍒�={},鐩爣灞�={}",wrkMast.getWrkNo().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());
 
@@ -963,7 +1045,7 @@
 
                     if (crnProtocol.getCrnNo() == 1) {
                         //鍒ゆ柇鍫嗗灈鏈哄拰褰撳墠浠诲姟鏄惁澶勪簬涓�涓贩閬�
-                        if (Utils.getLaneByLocNo(wrkMast.getLocNo()) != crnProtocol.getCrnLane()) {
+                        if (Utils.getLaneByLocNo(wrkMast.getSourceLocNo()) != crnProtocol.getCrnLane()) {
                             //鍒ゆ柇鍫嗗灈鏈烘墍鍦ㄥ贩閬撴槸鍚﹀瓨鍦ㄥ叾浠栦换鍔★紝濡傚瓨鍦ㄥ垯浼樺厛鎵ц
                             List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false);
                             if (!currentWrkMasts.isEmpty()) {
@@ -979,7 +1061,7 @@
                         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);
@@ -996,7 +1078,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);
@@ -1017,7 +1099,7 @@
                             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());
@@ -2207,13 +2289,16 @@
         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;
+                rgvStaNoDevpId = 2;
             }else {
                 devpId = 2;
                 rgvStaNo = 2003;
+                rgvStaNoDevpId = 1;
             }
 
             SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devpId);
@@ -2229,12 +2314,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;
                 }
 
@@ -2255,6 +2382,7 @@
                 wrkMast.setWrkSts(201L);//201.RGV鎼繍涓�
                 wrkMast.setModiTime(new Date());
                 wrkMastService.updateById(wrkMast);
+                redisUtil.set(RedisConstantType.RGV_MOVE_LOCK + wrkMast.getWrkNo(), "lock", 60 * 60);
             }
         }
     }
@@ -2283,18 +2411,23 @@
                     continue;
                 }
 
+                if (wrkMast.getWrkSts() != 201) {
+                    continue;
+                }
+
                 Integer devpId = null;
                 Integer devpStaNo = null;
                 String locNo = null;
+                Long updateWrkSts = null;
                 if (wrkMast.getIoType() < 100) {
                     //鍏ュ簱
-                    wrkMast.setWrkSts(2L);
+                    updateWrkSts = 2L;
                     devpId = 1;
                     devpStaNo = 2003;
                     locNo = wrkMast.getLocNo();
                 }else {
                     //鍑哄簱
-                    wrkMast.setWrkSts(15L);
+                    updateWrkSts = 15L;
                     devpId = 2;
                     devpStaNo = 2002;
                     locNo = wrkMast.getSourceLocNo();
@@ -2323,11 +2456,7 @@
                     if (!result) {
                         throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
                     }
-
-                    Date now = new Date();
-                    wrkMast.setModiTime(now);
-                    wrkMastService.updateById(wrkMast);
-
+                    wrkMastMapper.updateWrkSts(updateWrkSts, wrkMast.getWrkNo());
                     rgvThread.setResetFlag1(true);
                 }
             }

--
Gitblit v1.9.1