From ad79ba405b2d1ac96423f88f4e8a76c584b9d38a Mon Sep 17 00:00:00 2001
From: zwl <1051256694@qq.com>
Date: 星期一, 09 二月 2026 15:57:06 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/utils/StationOperateProcessUtils.java |  201 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 159 insertions(+), 42 deletions(-)

diff --git a/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java b/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
index c3c8516..4a14a33 100644
--- a/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
+++ b/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -4,8 +4,10 @@
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.exception.CoolException;
+import com.zy.asrs.domain.enums.NotifyMsgType;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.service.*;
+import com.zy.asrs.utils.NotifyUtils;
 import com.zy.common.entity.FindCrnNoResult;
 import com.zy.common.model.StartupDto;
 import com.zy.common.service.CommonService;
@@ -13,13 +15,13 @@
 import com.zy.core.News;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.SlaveConnection;
-import com.zy.core.enums.RedisKeyType;
-import com.zy.core.enums.SlaveType;
-import com.zy.core.enums.WrkStsType;
+import com.zy.core.enums.*;
 import com.zy.core.model.StationObjModel;
 import com.zy.core.model.Task;
 import com.zy.core.model.command.StationCommand;
+import com.zy.core.model.protocol.CrnProtocol;
 import com.zy.core.model.protocol.StationProtocol;
+import com.zy.core.thread.CrnThread;
 import com.zy.core.thread.StationThread;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -38,18 +40,22 @@
     @Autowired
     private BasCrnpService basCrnpService;
     @Autowired
+    private BasDualCrnpService basDualCrnpService;
+    @Autowired
     private RedisUtil redisUtil;
     @Autowired
     private LocMastService locMastService;
     @Autowired
     private WmsOperateUtils wmsOperateUtils;
+    @Autowired
+    private NotifyUtils notifyUtils;
 
     //鎵ц杈撻�佺珯鐐瑰叆搴撲换鍔�
     public synchronized void stationInExecute() {
         List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
         for (BasDevp basDevp : basDevps) {
             StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
-            if(stationThread == null){
+            if (stationThread == null) {
                 continue;
             }
 
@@ -58,7 +64,7 @@
             List<StationObjModel> list = basDevp.getBarcodeStationList$();
             for (StationObjModel entity : list) {
                 Integer stationId = entity.getStationId();
-                if(!stationMap.containsKey(stationId)){
+                if (!stationMap.containsKey(stationId)) {
                     continue;
                 }
 
@@ -68,7 +74,7 @@
                 }
 
                 Object lock = redisUtil.get(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId);
-                if(lock != null){
+                if (lock != null) {
                     continue;
                 }
 
@@ -87,27 +93,22 @@
                         continue;
                     }
 
-                    if (!wrkMast.getWrkNo().equals(stationProtocol.getTaskNo())) {
-                        News.taskInfo(stationProtocol.getStationId(), "杈撻�佺珯鐐瑰伐浣滃彿:{}涓庢潯鐮佹悳绱㈠埌鐨勪换鍔″伐浣滃彿:{}涓嶄竴鑷�", stationProtocol.getTaskNo(), wrkMast.getWrkNo());
-                        continue;
-                    }
-
                     String locNo = wrkMast.getLocNo();
                     FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(locNo);
                     if (findCrnNoResult == null) {
-                        News.taskInfo(wrkMast.getWrkNo(), "鏈尮閰嶅埌鍫嗗灈鏈�");
+                        News.taskInfo(wrkMast.getWrkNo(), "{}宸ヤ綔,鏈尮閰嶅埌鍫嗗灈鏈�", wrkMast.getWrkNo());
                         continue;
                     }
 
                     Integer targetStationId = commonService.findInStationId(findCrnNoResult, stationId);
                     if (targetStationId == null) {
-                        News.taskInfo(wrkMast.getWrkNo(), "鎼滅储鍏ュ簱绔欑偣澶辫触");
+                        News.taskInfo(wrkMast.getWrkNo(), "{}绔欑偣,鎼滅储鍏ュ簱绔欑偣澶辫触", stationId);
                         continue;
                     }
 
-                    StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationId, targetStationId, 0);
-                    if(command == null){
-                        News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
+                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationId, targetStationId, 0);
+                    if (command == null) {
+                        News.taskInfo(wrkMast.getWrkNo(), "{}宸ヤ綔,鑾峰彇杈撻�佺嚎鍛戒护澶辫触", wrkMast.getWrkNo());
                         continue;
                     }
 
@@ -130,20 +131,29 @@
     public synchronized void stationOutExecute() {
         List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.OUTBOUND_RUN_COMPLETE.sts));
         for (WrkMast wrkMast : wrkMasts) {
+            List<StationObjModel> outStationList = new ArrayList<>();
+
             BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", wrkMast.getCrnNo()));
-            if (basCrnp == null) {
-                continue;
+            if (basCrnp != null) {
+                outStationList = basCrnp.getOutStationList$();
+                if (outStationList.isEmpty()) {
+                    News.info("鍫嗗灈鏈�:{} 鍑哄簱绔欑偣鏈缃�", basCrnp.getCrnNo());
+                    continue;
+                }
             }
 
-            List<StationObjModel> outStationList = basCrnp.getOutStationList$();
-            if(outStationList.isEmpty()){
-                News.info("鍫嗗灈鏈�:{} 鍑哄簱绔欑偣鏈缃�", basCrnp.getCrnNo());
-                continue;
+            BasDualCrnp basDualCrnp = basDualCrnpService.selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", wrkMast.getDualCrnNo()));
+            if (basDualCrnp != null) {
+                outStationList = basDualCrnp.getOutStationList$();
+                if (outStationList.isEmpty()) {
+                    News.info("鍙屽伐浣嶅爢鍨涙満:{} 鍑哄簱绔欑偣鏈缃�", basDualCrnp.getCrnNo());
+                    continue;
+                }
             }
 
             for (StationObjModel stationObjModel : outStationList) {
                 StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
-                if(stationThread == null){
+                if (stationThread == null) {
                     continue;
                 }
 
@@ -163,8 +173,8 @@
                         && stationProtocol.isLoading()
                         && stationProtocol.getTaskNo() == 0
                 ) {
-                    StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
-                    if(command == null){
+                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
+                    if (command == null) {
                         News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
                         continue;
                     }
@@ -176,17 +186,104 @@
                         MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                         News.info("杈撻�佺珯鐐瑰嚭搴撳懡浠や笅鍙戞垚鍔燂紝绔欑偣鍙�={}锛屽伐浣滃彿={}锛屽懡浠ゆ暟鎹�={}", stationProtocol.getStationId(), wrkMast.getWrkNo(), JSON.toJSONString(command));
                         redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId(), "lock", 5);
+                        redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkMast.getWrkNo(), "lock", 60 * 5);
+                        redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_DESTINATION_LIMIT.key + wrkMast.getWrkNo(), "lock", 60 * 5);
                     }
                 }
             }
         }
     }
 
-    //妫�娴嬭緭閫佺珯鐐瑰嚭搴撲换鍔℃墽琛屽畬鎴�
-    public synchronized void stationOutExecuteFinish() {
+    //妫�娴嬪嚭搴撲换鍔″埌杈剧洰鐨勫湴
+    public synchronized void arriveAtTheDestination() {
         List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.STATION_RUN.sts));
         for (WrkMast wrkMast : wrkMasts) {
             Integer wrkNo = wrkMast.getWrkNo();
+
+//            Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_DESTINATION_LIMIT.key + wrkNo);
+//            if (lock != null) {
+//                continue;
+//            }
+
+            boolean complete = false;
+
+            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, 1);
+            if (stationThread == null) {
+                continue;
+            }
+            List<StationProtocol> list = stationThread.getStatus();
+            for (StationProtocol stationProtocol : list) {
+                if (stationProtocol.getTaskNo().equals(wrkNo)&&stationProtocol.getStationId().equals(wrkMast.getStaNo())) {
+                    complete = true;
+                }
+            }
+            if (complete) {
+                //涓婃姤--鍒拌揪鐩殑鍦颁笂鎶ms
+                notifyUtils.notify("task", 1, String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.ARRIVE_AT_THE_DESTINATION, JSON.toJSONString(wrkMast));
+                wrkMast.setWrkSts(WrkStsType.ARRIVE_AT_THE_DESTINATION.sts);
+                wrkMast.setIoTime(new Date());
+                wrkMastService.updateById(wrkMast);
+            }
+        }
+    }
+
+    //妫�娴嬪簱浣嶆鑹叉寜閽俊鍙� 1锛氬憳宸ョ‘璁わ紙甯镐寒锛� 2 锛氫笂浣嶆満纭锛堥棯鐑侊級0 锛氱唲鐏�
+    public synchronized void locNo() {
+        List<BasCrnp> basCrnps = basCrnpService.selectList(null);
+        for (BasCrnp basCrnp : basCrnps) {
+            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo());
+            if(crnThread == null){
+                continue;
+            }
+
+            CrnProtocol crnProtocol = crnThread.getStatus();
+            if(crnProtocol == null){
+                continue;
+            }
+
+
+        }
+//        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.ARRIVE_AT_THE_DESTINATION.sts));
+//        for (WrkMast wrkMast : wrkMasts) {
+//            Integer wrkNo = wrkMast.getWrkNo();
+//
+//            Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkNo);
+//            if (lock != null) {
+//                continue;
+//            }
+//
+//            boolean complete = false;
+//
+//            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, wrkMast.getStaNo());
+//            if (stationThread == null) {
+//                continue;
+//            }
+//            List<StationProtocol> list = stationThread.getStatus();
+//            for (StationProtocol stationProtocol : list) {
+//                if (stationProtocol.getTaskNo().equals(wrkNo)) {
+//                    complete = true;
+//                }
+//            }
+//            if (complete) {
+//                //涓婃姤--鍒拌揪鐩殑鍦颁笂鎶ms
+//                notifyUtils.notify("task", 1, String.valueOf(wrkMast.getWrkNo()), wrkMast.getWmsWrkNo(), NotifyMsgType.ARRIVE_AT_THE_DESTINATION, JSON.toJSONString(wrkMast));
+//                wrkMast.setWrkSts(WrkStsType.ARRIVE_AT_THE_DESTINATION.sts);
+//                wrkMast.setIoTime(new Date());
+//                wrkMastService.updateById(wrkMast);
+//            }
+//        }
+    }
+
+    //妫�娴嬭緭閫佺珯鐐瑰嚭搴撲换鍔℃墽琛屽畬鎴�
+    public synchronized void stationOutExecuteFinish() {
+        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", WrkStsType.ARRIVE_AT_THE_DESTINATION.sts));
+        for (WrkMast wrkMast : wrkMasts) {
+            Integer wrkNo = wrkMast.getWrkNo();
+
+            Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_COMPLETE_LIMIT.key + wrkNo);
+            if (lock != null) {
+                continue;
+            }
 
             boolean complete = true;
             List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
@@ -217,7 +314,7 @@
         List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
         for (BasDevp basDevp : basDevps) {
             StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
-            if(stationThread == null){
+            if (stationThread == null) {
                 continue;
             }
 
@@ -228,10 +325,10 @@
 
             List<StationProtocol> list = stationThread.getStatus();
             for (StationProtocol stationProtocol : list) {
-                if(stationProtocol.isAutoing()
-                    && stationProtocol.isLoading()
-                    && stationProtocol.getTaskNo() > 0
-                    && stationProtocol.isRunBlock()
+                if (stationProtocol.isAutoing()
+                        && stationProtocol.isLoading()
+                        && stationProtocol.getTaskNo() > 0
+                        && stationProtocol.isRunBlock()
                 ) {
                     WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
                     if (wrkMast == null) {
@@ -245,7 +342,7 @@
                     }
                     redisUtil.set(RedisKeyType.CHECK_STATION_RUN_BLOCK_LIMIT_.key + stationProtocol.getTaskNo(), "lock", 15);
 
-                    if (runBlockReassignLocStationList.contains(stationProtocol.getStationId())) {
+                    if (wrkMast.getIoType() == WrkIoType.IN.id && runBlockReassignLocStationList.contains(stationProtocol.getStationId())) {
                         //绔欑偣澶勪簬閲嶆柊鍒嗛厤搴撲綅鍖哄煙
                         //杩愯鍫靛锛岄噸鏂扮敵璇蜂换鍔�
                         String response = wmsOperateUtils.applyReassignTaskLocNo(wrkMast.getWrkNo(), stationProtocol.getStationId());
@@ -284,20 +381,20 @@
 
                             FindCrnNoResult findCrnNoResult = commonService.findCrnNoByLocNo(locNo);
                             if (findCrnNoResult == null) {
-                                News.taskInfo(wrkMast.getWrkNo(), "鏈尮閰嶅埌鍫嗗灈鏈�");
+                                News.taskInfo(wrkMast.getWrkNo(), "{}宸ヤ綔,鏈尮閰嶅埌鍫嗗灈鏈�", wrkMast.getWrkNo());
                                 continue;
                             }
                             Integer crnNo = findCrnNoResult.getCrnNo();
 
                             Integer targetStationId = commonService.findInStationId(findCrnNoResult, stationProtocol.getStationId());
                             if (targetStationId == null) {
-                                News.taskInfo(wrkMast.getWrkNo(), "鎼滅储鍏ュ簱绔欑偣澶辫触");
+                                News.taskInfo(wrkMast.getWrkNo(), "{}绔欑偣,鎼滅储鍏ュ簱绔欑偣澶辫触", stationProtocol.getStationId());
                                 continue;
                             }
 
-                            StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationProtocol.getStationId(), targetStationId, 0);
-                            if(command == null){
-                                News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
+                            StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), targetStationId, 0);
+                            if (command == null) {
+                                News.taskInfo(wrkMast.getWrkNo(), "{}宸ヤ綔,鑾峰彇杈撻�佺嚎鍛戒护澶辫触", wrkMast.getWrkNo());
                                 continue;
                             }
 
@@ -319,7 +416,7 @@
                                 wrkMast.setCrnNo(crnNo);
                             } else if (findCrnNoResult.getCrnType().equals(SlaveType.DualCrn)) {
                                 wrkMast.setDualCrnNo(crnNo);
-                            }else {
+                            } else {
                                 throw new CoolException("鏈煡璁惧绫诲瀷");
                             }
 
@@ -329,10 +426,10 @@
                         } else {
                             News.error("璇锋眰WMS鎺ュ彛澶辫触锛侊紒锛乺esponse锛歿}", response);
                         }
-                    }else {
+                    } else {
                         //杩愯鍫靛锛岄噸鏂拌绠楄矾绾�
-                        StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
-                        if(command == null){
+                        StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
+                        if (command == null) {
                             News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
                             continue;
                         }
@@ -345,5 +442,25 @@
         }
     }
 
+    //鑾峰彇杈撻�佺嚎浠诲姟鏁伴噺
+    public synchronized int getCurrentStationTaskCount() {
+        int currentStationTaskCount = 0;
+        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>());
+        for (BasDevp basDevp : basDevps) {
+            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getId());
+            if (stationThread == null) {
+                continue;
+            }
+
+            for (StationProtocol stationProtocol : stationThread.getStatus()) {
+                if (stationProtocol.getTaskNo() > 0) {
+                    currentStationTaskCount++;
+                }
+            }
+        }
+
+        return currentStationTaskCount;
+    }
+
 
 }

--
Gitblit v1.9.1