From 6200ba627af8af4045155c1bd7e65220ce59d6ba Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期四, 15 一月 2026 14:36:36 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java |  350 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 348 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java b/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
index e09a1e2..89f2361 100644
--- a/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
+++ b/src/main/java/com/zy/core/utils/CrnOperateProcessUtils.java
@@ -30,6 +30,7 @@
 import org.springframework.stereotype.Component;
 
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -49,8 +50,20 @@
     @Autowired
     private CommonService commonService;
 
-    //鍏ュ嚭搴�  ===>>  鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂
     public synchronized void crnIoExecute() {
+        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+        if (systemConfigMapObj != null) {
+            HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
+            if (systemConfigMap.get("crnRunMethod").equals("solver")) {
+                plannerExecute();
+            }else {
+                crnIoExecuteNormal();
+            }
+        }
+    }
+
+    //鍏ュ嚭搴�  ===>>  鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂
+    public synchronized void crnIoExecuteNormal() {
         List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
         for (BasCrnp basCrnp : basCrnps) {
             CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo());
@@ -162,7 +175,6 @@
             }
 
             if(wrkMast.getWrkSts() != WrkStsType.INBOUND_DEVICE_RUN.sts){
-                News.taskInfo(stationProtocol.getTaskNo(), "宸ヤ綔鍙�:{} 浠诲姟鐘舵�佸紓甯�", stationProtocol.getTaskNo());
                 continue;
             }
 
@@ -290,6 +302,182 @@
         }
     }
 
+    private synchronized boolean crnExecuteInPlanner(BasCrnp basCrnp, CrnThread crnThread, WrkMast wrkMast) {
+        CrnProtocol crnProtocol = crnThread.getStatus();
+        if (crnProtocol == null) {
+            return false;
+        }
+
+        if (!basCrnp.getInEnable().equals("Y")) {
+            News.info("鍫嗗灈鏈�:{} 鍙叆淇″彿涓嶆弧瓒�", basCrnp.getCrnNo());
+            return false;
+        }
+
+        List<StationObjModel> inStationList = basCrnp.getInStationList$();
+        if (inStationList.isEmpty()) {
+            News.info("鍫嗗灈鏈�:{} 鍏ュ簱绔欑偣鏈缃�", basCrnp.getCrnNo());
+            return false;
+        }
+
+        Integer crnNo = basCrnp.getCrnNo();
+
+        for (StationObjModel stationObjModel : inStationList) {
+            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
+            if (stationThread == null) {
+                continue;
+            }
+
+            Map<Integer, StationProtocol> stationProtocolMap = stationThread.getStatusMap();
+            StationProtocol stationProtocol = stationProtocolMap.get(stationObjModel.getStationId());
+            if (stationProtocol == null) {
+                continue;
+            }
+
+            if (!stationProtocol.isAutoing()) {
+                continue;
+            }
+
+            if (!stationProtocol.isLoading()) {
+                continue;
+            }
+
+            if (stationProtocol.getTaskNo() <= 0) {
+                continue;
+            }
+
+            if (!stationProtocol.isInEnable()) {
+                News.taskInfo(stationProtocol.getTaskNo(), "鍙栬揣绔欑偣:{} 娌℃湁鍙叆淇″彿", stationObjModel.getStationId());
+                continue;
+            }
+
+            if (!wrkMast.getWrkNo().equals(stationProtocol.getTaskNo())) {
+                continue;
+            }
+
+            if (wrkMast.getWrkSts() != WrkStsType.INBOUND_DEVICE_RUN.sts) {
+                continue;
+            }
+
+            // 鑾峰彇搴撲綅淇℃伅
+            LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
+            if (locMast == null) {
+                News.taskInfo(wrkMast.getWrkNo(), "鐩爣搴撲綅:{} 淇℃伅涓嶅瓨鍦�", wrkMast.getLocNo());
+                continue;
+            }
+
+            if (!locMast.getLocSts().equals("S")) {
+                News.taskInfo(wrkMast.getWrkNo(), "鐩爣搴撲綅:{} 鐘舵�佸紓甯�", wrkMast.getLocNo());
+                continue;
+            }
+
+            //妫�娴嬫祬搴撲綅鐘舵��
+            boolean checkStatus = checkShallowLocStatus(locMast.getLocNo(), wrkMast.getWrkNo());
+            if (!checkStatus) {
+                News.taskInfo(wrkMast.getWrkNo(), "鍥犳祬搴撲綅鍫靛鏃犳硶鎵ц");
+                continue;
+            }
+
+            String sourceLocNo = Utils.getLocNo(stationObjModel.getDeviceRow(), stationObjModel.getDeviceBay(), stationObjModel.getDeviceLev());
+
+            CrnCommand command = crnThread.getPickAndPutCommand(sourceLocNo, wrkMast.getLocNo(), wrkMast.getWrkNo(), crnNo);
+
+            wrkMast.setWrkSts(WrkStsType.INBOUND_RUN.sts);
+            wrkMast.setCrnNo(crnNo);
+            wrkMast.setSystemMsg("");
+            wrkMast.setIoTime(new Date());
+            if (wrkMastService.updateById(wrkMast)) {
+                MessageQueue.offer(SlaveType.Crn, crnNo, new Task(2, command));
+                News.info("鍫嗗灈鏈哄懡浠や笅鍙戞垚鍔燂紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", crnNo, JSON.toJSON(command));
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private synchronized boolean crnExecuteOutPlanner(BasCrnp basCrnp, CrnThread crnThread, WrkMast wrkMast) {
+        CrnProtocol crnProtocol = crnThread.getStatus();
+        if (crnProtocol == null) {
+            return false;
+        }
+
+        if (!basCrnp.getOutEnable().equals("Y")) {
+            News.info("鍫嗗灈鏈�:{} 鍙嚭淇″彿涓嶆弧瓒�", basCrnp.getCrnNo());
+            return false;
+        }
+
+        List<StationObjModel> outStationList = basCrnp.getOutStationList$();
+        if (outStationList.isEmpty()) {
+            News.info("鍫嗗灈鏈�:{} 鍑哄簱绔欑偣鏈缃�", basCrnp.getCrnNo());
+            return false;
+        }
+
+        Integer crnNo = basCrnp.getCrnNo();
+
+        for (StationObjModel stationObjModel : outStationList) {
+            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
+            if (stationThread == null) {
+                continue;
+            }
+
+            Map<Integer, StationProtocol> stationProtocolMap = stationThread.getStatusMap();
+            StationProtocol stationProtocol = stationProtocolMap.get(stationObjModel.getStationId());
+            if (stationProtocol == null) {
+                continue;
+            }
+
+            if (!stationProtocol.isAutoing()) {
+                continue;
+            }
+
+            if (stationProtocol.isLoading()) {
+                continue;
+            }
+
+            if (stationProtocol.getTaskNo() != 0) {
+                continue;
+            }
+
+            if (!stationProtocol.isOutEnable()) {
+                News.info("鏀捐揣绔欑偣:{} 娌℃湁鍙嚭淇″彿", stationObjModel.getStationId());
+                continue;
+            }
+
+            // 鑾峰彇搴撲綅淇℃伅
+            LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());
+            if (locMast == null) {
+                News.taskInfo(wrkMast.getWrkNo(), "婧愬簱浣�:{} 淇℃伅涓嶅瓨鍦�", wrkMast.getSourceLocNo());
+                continue;
+            }
+
+            if (!locMast.getLocSts().equals("R")) {
+                News.taskInfo(wrkMast.getWrkNo(), "婧愬簱浣�:{} 鐘舵�佸紓甯�", wrkMast.getSourceLocNo());
+                continue;
+            }
+
+            //妫�娴嬫祬搴撲綅鐘舵��
+            boolean checkStatus = checkShallowLocStatus(locMast.getLocNo(), wrkMast.getWrkNo());
+            if (!checkStatus) {
+                News.taskInfo(wrkMast.getWrkNo(), "鍥犳祬搴撲綅鍫靛鏃犳硶鎵ц");
+                continue;
+            }
+
+            String targetLocNo = Utils.getLocNo(stationObjModel.getDeviceRow(), stationObjModel.getDeviceBay(), stationObjModel.getDeviceLev());
+
+            CrnCommand command = crnThread.getPickAndPutCommand(wrkMast.getSourceLocNo(), targetLocNo, wrkMast.getWrkNo(), crnNo);
+
+            wrkMast.setWrkSts(WrkStsType.OUTBOUND_RUN.sts);
+            wrkMast.setCrnNo(crnNo);
+            wrkMast.setSystemMsg("");
+            wrkMast.setIoTime(new Date());
+            if (wrkMastService.updateById(wrkMast)) {
+                MessageQueue.offer(SlaveType.Crn, crnNo, new Task(2, command));
+                News.info("鍫嗗灈鏈哄懡浠や笅鍙戞垚鍔燂紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", crnNo, JSON.toJSON(command));
+                return true;
+            }
+        }
+        return false;
+    }
+
     private synchronized void crnExecuteLocTransfer(BasCrnp basCrnp, CrnThread crnThread) {
         CrnProtocol crnProtocol = crnThread.getStatus();
         if(crnProtocol == null){
@@ -398,8 +586,166 @@
         }
     }
 
+    public synchronized void plannerExecute() {
+        int nowSec = (int) (System.currentTimeMillis() / 1000);
+        List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
+        for (BasCrnp basCrnp : basCrnps) {
+            String key = RedisKeyType.PLANNER_SCHEDULE.key + "CRN-" + basCrnp.getCrnNo();
+            List<Object> items = redisUtil.lGet(key, 0, -1);
+            if (items == null || items.isEmpty()) {
+                continue;
+            }
+
+            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo());
+            if (crnThread == null) {
+                continue;
+            }
+            CrnProtocol crnProtocol = crnThread.getStatus();
+            if (crnProtocol == null) {
+                continue;
+            }
+            List<WrkMast> running = wrkMastService.selectList(new EntityWrapper<WrkMast>()
+                    .eq("crn_no", basCrnp.getCrnNo())
+                    .in("wrk_sts", WrkStsType.INBOUND_RUN.sts, WrkStsType.OUTBOUND_RUN.sts, WrkStsType.LOC_MOVE_RUN.sts)
+            );
+            if (!running.isEmpty()) {
+                continue;
+            }
+            if (!(crnProtocol.getMode() == CrnModeType.AUTO.id
+                    && crnProtocol.getTaskNo() == 0
+                    && crnProtocol.getStatus() == CrnStatusType.IDLE.id
+                    && crnProtocol.getLoaded() == 0
+                    && crnProtocol.getForkPos() == 0
+                    && crnProtocol.getAlarm() == 0)) {
+                continue;
+            }
+
+            for (Object v : items) {
+                String s = String.valueOf(v);
+                JSONObject obj = null;
+                try { obj = JSON.parseObject(s); } catch (Exception ignore) {}
+                if (obj == null) {
+                    continue;
+                }
+                Integer startEpochSec = obj.getInteger("startEpochSec");
+                Integer endEpochSec = obj.getInteger("endEpochSec");
+                Integer taskId = obj.getInteger("taskId");
+                String taskType = obj.getString("taskType");
+                if (startEpochSec == null || taskId == null || taskType == null) {
+                    continue;
+                }
+                int earlySlackSec = 5;
+                int lateSlackSec = 10;
+                Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+                if (systemConfigMapObj != null) {
+                    try {
+                        HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
+                        String es = systemConfigMap.getOrDefault("plannerEarlySlackSec", "60");
+                        String ls = systemConfigMap.getOrDefault("plannerLateSlackSec", "10");
+                        earlySlackSec = Integer.parseInt(es);
+                        lateSlackSec = Integer.parseInt(ls);
+                    } catch (Exception ignore) {}
+                }
+                if (nowSec < startEpochSec - earlySlackSec) {
+                    continue;
+                }
+                if (endEpochSec != null && nowSec > endEpochSec + lateSlackSec) {
+                    redisUtil.lRemove(key, 1, s);
+                    continue;
+                }
+
+                WrkMast wrkMast = wrkMastService.selectByWorkNo(taskId);
+                if (wrkMast == null) {
+                    redisUtil.lRemove(key, 1, s);
+                    continue;
+                }
+
+                if ("IN".equalsIgnoreCase(taskType)) {
+                    boolean result = this.crnExecuteInPlanner(basCrnp, crnThread, wrkMast);//鍏ュ簱
+                    if (result) {
+                        redisUtil.lRemove(key, 1, s);
+                        break;
+                    }
+                } else if ("OUT".equalsIgnoreCase(taskType)) {
+                    boolean result = this.crnExecuteOutPlanner(basCrnp, crnThread, wrkMast);//鍑哄簱
+                    if (result) {
+                        redisUtil.lRemove(key, 1, s);
+                        break;
+                    }
+                } else if ("MOVE".equalsIgnoreCase(taskType)) {
+                    boolean result = this.crnExecuteMovePlanner(basCrnp, crnThread, wrkMast);//绉诲簱
+                    if (result) {
+                        redisUtil.lRemove(key, 1, s);
+                        break;
+                    }
+                }
+            }
+        }
+    }
+
+    private synchronized boolean crnExecuteMovePlanner(BasCrnp basCrnp, CrnThread crnThread, WrkMast wrkMast) {
+        CrnProtocol crnProtocol = crnThread.getStatus();
+        if (crnProtocol == null) {
+            return false;
+        }
+
+        Integer crnNo = basCrnp.getCrnNo();
+
+        if (!wrkMast.getWrkSts().equals(WrkStsType.NEW_LOC_MOVE.sts)) {
+            return false;
+        }
+
+        // 鑾峰彇婧愬簱浣嶄俊鎭�
+        LocMast sourceLocMast = locMastService.selectById(wrkMast.getSourceLocNo());
+        if (sourceLocMast == null) {
+            News.taskInfo(wrkMast.getWrkNo(), "婧愬簱浣�:{} 淇℃伅涓嶅瓨鍦�", wrkMast.getSourceLocNo());
+            return false;
+        }
+
+        if(!sourceLocMast.getLocSts().equals("R")){
+            News.taskInfo(wrkMast.getWrkNo(), "婧愬簱浣�:{} 鐘舵�佸紓甯革紝涓嶅睘浜庡嚭搴撻绾︾姸鎬�", wrkMast.getSourceLocNo());
+            return false;
+        }
+
+        // 鑾峰彇搴撲綅淇℃伅
+        LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
+        if (locMast == null) {
+            News.taskInfo(wrkMast.getWrkNo(), "搴撲綅:{} 淇℃伅涓嶅瓨鍦�", wrkMast.getLocNo());
+            return false;
+        }
+
+        if (!locMast.getLocSts().equals("S")) {
+            News.taskInfo(wrkMast.getWrkNo(), "搴撲綅:{} 鐘舵�佸紓甯革紝涓嶅睘浜庡叆搴撻绾︾姸鎬�", wrkMast.getLocNo());
+            return false;
+        }
+
+        CrnCommand command = crnThread.getPickAndPutCommand(wrkMast.getSourceLocNo(), wrkMast.getLocNo(), wrkMast.getWrkNo(), crnNo);
+
+        wrkMast.setWrkSts(WrkStsType.LOC_MOVE_RUN.sts);
+        wrkMast.setCrnNo(crnNo);
+        wrkMast.setSystemMsg("");
+        wrkMast.setIoTime(new Date());
+        if (wrkMastService.updateById(wrkMast)) {
+            MessageQueue.offer(SlaveType.Crn, crnNo, new Task(2, command));
+            News.info("鍫嗗灈鏈哄懡浠や笅鍙戞垚鍔燂紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", crnNo, JSON.toJSON(command));
+            return true;
+        }
+        return false;
+    }
+
     //妫�娴嬫祬搴撲綅鐘舵��
     public synchronized boolean checkShallowLocStatus(String locNo, Integer taskNo) {
+        String checkDeepLocOutTaskBlockReport = "Y";
+        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+        if (systemConfigMapObj != null) {
+            HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
+            checkDeepLocOutTaskBlockReport = systemConfigMap.get("checkDeepLocOutTaskBlockReport");
+        }
+
+        if (!checkDeepLocOutTaskBlockReport.equals("Y")) {
+            return true;
+        }
+
         Object lock = redisUtil.get(RedisKeyType.CHECK_SHALLOW_LOC_STATUS_LIMIT.key + taskNo);
         if (lock != null) {
             return false;

--
Gitblit v1.9.1