From af2f9443ec9241de3aa2c8eed3d31eef382f89d0 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期四, 18 十二月 2025 15:36:35 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/utils/StationOperateProcessUtils.java |  216 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 204 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java b/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
index a00dd68..5c31a55 100644
--- a/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
+++ b/src/main/java/com/zy/core/utils/StationOperateProcessUtils.java
@@ -4,16 +4,18 @@
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.common.Cools;
-import com.zy.asrs.entity.BasCrnp;
-import com.zy.asrs.entity.BasDevp;
-import com.zy.asrs.entity.WrkMast;
-import com.zy.asrs.service.BasCrnpService;
-import com.zy.asrs.service.BasDevpService;
-import com.zy.asrs.service.WrkMastService;
+import com.zy.asrs.domain.param.CreateInTaskParam;
+import com.zy.asrs.entity.*;
+import com.zy.asrs.service.*;
+import com.zy.asrs.utils.Utils;
+import com.zy.common.model.StartupDto;
 import com.zy.common.service.CommonService;
+import com.zy.common.utils.HttpHandler;
+import com.zy.common.utils.RedisUtil;
 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.model.StationObjModel;
@@ -21,12 +23,12 @@
 import com.zy.core.model.command.StationCommand;
 import com.zy.core.model.protocol.StationProtocol;
 import com.zy.core.thread.StationThread;
+import com.zy.system.entity.Config;
+import com.zy.system.service.ConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 @Component
 public class StationOperateProcessUtils {
@@ -39,6 +41,14 @@
     private CommonService commonService;
     @Autowired
     private BasCrnpService basCrnpService;
+    @Autowired
+    private RedisUtil redisUtil;
+    @Autowired
+    private ConfigService configService;
+    @Autowired
+    private HttpRequestLogService httpRequestLogService;
+    @Autowired
+    private LocMastService locMastService;
 
     //鎵ц杈撻�佺珯鐐瑰叆搴撲换鍔�
     public synchronized void stationInExecute() {
@@ -51,7 +61,7 @@
 
             Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
 
-            List<StationObjModel> list = basDevp.getInStationList$();
+            List<StationObjModel> list = basDevp.getBarcodeStationList$();
             for (StationObjModel entity : list) {
                 Integer stationId = entity.getStationId();
                 if(!stationMap.containsKey(stationId)){
@@ -63,10 +73,15 @@
                     continue;
                 }
 
-                //婊¤冻鑷姩銆佹湁鐗┿�佸伐浣滃彿9999
+                Object lock = redisUtil.get(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId);
+                if(lock != null){
+                    continue;
+                }
+
+                //婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙�
                 if (stationProtocol.isAutoing()
                         && stationProtocol.isLoading()
-                        && stationProtocol.getTaskNo() == 9999
+                        && stationProtocol.getTaskNo() > 0
                 ) {
                     //妫�娴嬩换鍔℃槸鍚︾敓鎴�
                     WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
@@ -75,6 +90,11 @@
                     }
 
                     if (wrkMast.getWrkSts() == WrkStsType.INBOUND_DEVICE_RUN.sts) {
+                        continue;
+                    }
+
+                    if (!wrkMast.getWrkNo().equals(stationProtocol.getTaskNo())) {
+                        News.taskInfo(stationProtocol.getStationId(), "杈撻�佺珯鐐瑰伐浣滃彿:{}涓庢潯鐮佹悳绱㈠埌鐨勪换鍔″伐浣滃彿:{}涓嶄竴鑷�", stationProtocol.getTaskNo(), wrkMast.getWrkNo());
                         continue;
                     }
 
@@ -105,6 +125,7 @@
                     if (wrkMastService.updateById(wrkMast)) {
                         MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                         News.info("杈撻�佺珯鐐瑰叆搴撳懡浠や笅鍙戞垚鍔燂紝绔欑偣鍙�={}锛屽伐浣滃彿={}锛屽懡浠ゆ暟鎹�={}", stationId, wrkMast.getWrkNo(), JSON.toJSONString(command));
+                        redisUtil.set(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId, "lock", 5);
                     }
                 }
             }
@@ -138,6 +159,11 @@
                     continue;
                 }
 
+                Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId());
+                if (lock != null) {
+                    continue;
+                }
+
                 //婊¤冻鑷姩銆佹湁鐗┿�佸伐浣滃彿0
                 if (stationProtocol.isAutoing()
                         && stationProtocol.isLoading()
@@ -155,6 +181,7 @@
                     if (wrkMastService.updateById(wrkMast)) {
                         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);
                     }
                 }
             }
@@ -191,5 +218,170 @@
         }
     }
 
+    //妫�娴嬭緭閫佺珯鐐规槸鍚﹁繍琛屽牭濉�
+    public synchronized void checkStationRunBlock() {
+        String wmsUrl = null;
+        Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
+        if (wmsSystemUriConfig != null) {
+            wmsUrl = wmsSystemUriConfig.getValue();
+        }
+
+        if(wmsUrl == null){
+            News.error("鏈厤缃甒MS绯荤粺URI锛岄厤缃枃浠禖ode缂栫爜锛歸msSystemUri");
+            return;
+        }
+
+        String wmsSystemReassignInTaskUrl = null;
+        Config wmsSystemReassignInTaskUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemReassignInTaskUrl"));
+        if (wmsSystemReassignInTaskUrlConfig != null) {
+            wmsSystemReassignInTaskUrl = wmsSystemReassignInTaskUrlConfig.getValue();
+        }
+
+        if(wmsSystemReassignInTaskUrl == null){
+            News.error("鏈厤缃甒MS浠诲姟閲嶆柊鍒嗛厤鍏ュ簱搴撲綅鎺ュ彛鍦板潃锛岄厤缃枃浠禖ode缂栫爜锛歸msSystemReassignInTaskUrl");
+            return;
+        }
+
+        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
+        for (BasDevp basDevp : basDevps) {
+            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
+            if(stationThread == null){
+                continue;
+            }
+
+            List<Integer> runBlockReassignLocStationList = new ArrayList<>();
+            for (StationObjModel stationObjModel : basDevp.getRunBlockReassignLocStationList$()) {
+                runBlockReassignLocStationList.add(stationObjModel.getStationId());
+            }
+
+            List<StationProtocol> list = stationThread.getStatus();
+            for (StationProtocol stationProtocol : list) {
+                if(stationProtocol.isAutoing()
+                    && stationProtocol.isLoading()
+                    && stationProtocol.getTaskNo() > 0
+                    && stationProtocol.isRunBlock()
+                ) {
+                    WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
+                    if (wrkMast == null) {
+                        News.info("杈撻�佺珯鐐瑰彿={} 杩愯闃诲锛屼絾鏃犳硶鎵惧埌瀵瑰簲浠诲姟锛屽伐浣滃彿={}", stationProtocol.getStationId(), stationProtocol.getTaskNo());
+                        continue;
+                    }
+
+                    Object lock = redisUtil.get(RedisKeyType.CHECK_STATION_RUN_BLOCK_LIMIT_.key + stationProtocol.getTaskNo());
+                    if (lock != null) {
+                        continue;
+                    }
+                    redisUtil.set(RedisKeyType.CHECK_STATION_RUN_BLOCK_LIMIT_.key + stationProtocol.getTaskNo(), "lock", 15);
+
+                    if (runBlockReassignLocStationList.contains(stationProtocol.getStationId())) {
+                        //绔欑偣澶勪簬閲嶆柊鍒嗛厤搴撲綅鍖哄煙
+                        //杩愯鍫靛锛岄噸鏂扮敵璇蜂换鍔�
+
+                        HashMap<String, Object> requestParam = new HashMap<>();
+                        String response = null;
+                        try {
+                            requestParam.put("taskNo", wrkMast.getWmsWrkNo());
+                            requestParam.put("row", Utils.getInTaskEnableRow(new ArrayList<>(basDevp.getDevpNo())));
+
+                            response = new HttpHandler.Builder()
+                                    .setUri(wmsUrl)
+                                    .setPath(wmsSystemReassignInTaskUrl)
+                                    .setJson(JSON.toJSONString(requestParam))
+                                    .build()
+                                    .doPost();
+                            JSONObject jsonObject = JSON.parseObject(response);
+                            if (jsonObject.getInteger("code").equals(200)) {
+                                StartupDto dto = jsonObject.getObject("data", StartupDto.class);
+
+                                String sourceLocNo = wrkMast.getLocNo();
+                                String locNo = dto.getLocNo();
+
+                                LocMast sourceLocMast = locMastService.queryByLoc(sourceLocNo);
+                                if (sourceLocMast == null) {
+                                    News.taskInfo(wrkMast.getWrkNo(), "搴撲綅鍙�:{} 婧愬簱浣嶄俊鎭笉瀛樺湪", sourceLocNo);
+                                    continue;
+                                }
+
+                                if (!sourceLocMast.getLocSts().equals("S")) {
+                                    News.taskInfo(wrkMast.getWrkNo(), "搴撲綅鍙�:{} 婧愬簱浣嶇姸鎬佷笉澶勪簬鍏ュ簱棰勭害", sourceLocNo);
+                                    continue;
+                                }
+
+                                LocMast locMast = locMastService.queryByLoc(locNo);
+                                if (locMast == null) {
+                                    News.taskInfo(wrkMast.getWrkNo(), "搴撲綅鍙�:{} 鐩爣搴撲綅淇℃伅涓嶅瓨鍦�", locNo);
+                                    continue;
+                                }
+
+                                if (!locMast.getLocSts().equals("O")) {
+                                    News.taskInfo(wrkMast.getWrkNo(), "搴撲綅鍙�:{} 鐩爣搴撲綅鐘舵�佷笉澶勪簬绌哄簱浣�", locNo);
+                                    continue;
+                                }
+
+                                Integer crnNo = commonService.findCrnNoByLocNo(locNo);
+                                if (crnNo == null) {
+                                    News.taskInfo(wrkMast.getWrkNo(), "鏈尮閰嶅埌鍫嗗灈鏈�");
+                                    continue;
+                                }
+
+                                Integer targetStationId = commonService.findInStationId(crnNo, stationProtocol.getStationId());
+                                if (targetStationId == null) {
+                                    News.taskInfo(wrkMast.getWrkNo(), "鎼滅储鍏ュ簱绔欑偣澶辫触");
+                                    continue;
+                                }
+
+                                StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationProtocol.getStationId(), targetStationId, 0);
+                                if(command == null){
+                                    News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
+                                    continue;
+                                }
+
+                                //鏇存柊婧愬簱浣�
+                                sourceLocMast.setLocSts("O");
+                                sourceLocMast.setModiTime(new Date());
+                                locMastService.updateById(sourceLocMast);
+
+                                //鏇存柊鐩爣搴撲綅
+                                locMast.setLocSts("S");
+                                locMast.setModiTime(new Date());
+                                locMastService.updateById(locMast);
+
+                                //鏇存柊宸ヤ綔妗f暟鎹�
+                                wrkMast.setLocNo(locNo);
+                                wrkMast.setCrnNo(crnNo);
+                                wrkMast.setStaNo(targetStationId);
+                                if (wrkMastService.updateById(wrkMast)) {
+                                    MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
+                                }
+                                News.info("璇锋眰WMS鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
+                            } else {
+                                News.error("璇锋眰WMS鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
+                            }
+                        } catch (Exception e) {
+                            News.error("璇锋眰WMS鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛� response锛歿}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response, e);
+                        } finally {
+                            HttpRequestLog httpRequestLog = new HttpRequestLog();
+                            httpRequestLog.setName(wmsUrl + wmsSystemReassignInTaskUrl);
+                            httpRequestLog.setRequest(JSON.toJSONString(requestParam));
+                            httpRequestLog.setResponse(response);
+                            httpRequestLog.setCreateTime(new Date());
+                            httpRequestLogService.insert(httpRequestLog);
+                        }
+                    }else {
+                        //杩愯鍫靛锛岄噸鏂拌绠楄矾绾�
+                        StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0);
+                        if(command == null){
+                            News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
+                            continue;
+                        }
+
+                        MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
+                        News.info("杈撻�佺珯鐐瑰牭濉炲悗閲嶆柊璁$畻璺緞鍛戒护涓嬪彂鎴愬姛锛岀珯鐐瑰彿={}锛屽伐浣滃彿={}锛屽懡浠ゆ暟鎹�={}", stationProtocol.getStationId(), wrkMast.getWrkNo(), JSON.toJSONString(command));
+                    }
+                }
+            }
+        }
+    }
+
 
 }

--
Gitblit v1.9.1