From 633d680fdaba504255a12f190a8284c0a9e12de6 Mon Sep 17 00:00:00 2001
From: cpT <1@123>
Date: 星期五, 30 一月 2026 16:42:24 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/utils/DualCrnOperateProcessUtils.java   |   73 +++++++++++++----------
 src/main/java/com/zy/core/enums/RedisKeyType.java                 |    1 
 src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java |   55 +++++++++--------
 3 files changed, 71 insertions(+), 58 deletions(-)

diff --git a/src/main/java/com/zy/core/enums/RedisKeyType.java b/src/main/java/com/zy/core/enums/RedisKeyType.java
index 4e56779..e67dcf9 100644
--- a/src/main/java/com/zy/core/enums/RedisKeyType.java
+++ b/src/main/java/com/zy/core/enums/RedisKeyType.java
@@ -10,6 +10,7 @@
     LIFT_FLAG("lift_"),
 
     DUAL_CRN_COMMAND_("dual_crn_command_"),
+    DUAL_CRN_COMMAND_IDX("dual_crn_command_idx_"),
 
     QUEUE_CRN("queue_crn_"),
     QUEUE_DUAL_CRN("queue_dual_crn_"),
diff --git a/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java b/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
index 84b76a6..c33d25b 100644
--- a/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
@@ -85,6 +85,11 @@
 
                     if (step == 2) {
                         List<SendDualCrnCommandParam> commandList = (List<SendDualCrnCommandParam>) task.getData();
+                        for (SendDualCrnCommandParam sendDualCrnCommandParam : commandList) {
+                            DualCrnCommand dualCrnCommand = sendDualCrnCommandParam.getCommands().get(0);
+                            redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + dualCrnCommand.getTaskNo(), sendDualCrnCommandParam.getCommandIdx(), 60 * 60 * 24);
+                        }
+
                         redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo(), JSON.toJSONString(commandList, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24);
                     } else if (step == 3) {
                         sendCommand((DualCrnCommand) task.getData());
@@ -109,28 +114,21 @@
                         continue;
                     }
 
-//                    if (crnProtocol.getLoaded() == 1 && crnProtocol.getLoadedTwo() == 1) {
-//                        Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
-//                        if (wait != null) {
-//                            redisUtil.del(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
-//                        }
-//                    }
+                    if (!((crnProtocol.getStatusType().equals(DualCrnStatusType.IDLE) || crnProtocol.getStatusType().equals(DualCrnStatusType.FETCH_COMPLETE))
+                            && (crnProtocol.getStatusTypeTwo().equals(DualCrnStatusType.IDLE) || crnProtocol.getStatusTypeTwo().equals(DualCrnStatusType.FETCH_COMPLETE)))
+                    ) {
+                        continue;
+                    }
 
                     Object commandListObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo());
                     if (commandListObj == null) {
                         continue;
                     }
                     List<SendDualCrnCommandParam> commandList = JSON.parseArray(commandListObj.toString(), SendDualCrnCommandParam.class);
-
-                    List<SendDualCrnCommandParam> newCommandList = new ArrayList<>();
                     for (SendDualCrnCommandParam commandParam : commandList) {
-                        SendDualCrnCommandParam processed = processStation(commandParam);
-                        if(processed != null) {
-                            newCommandList.add(processed);
-                        }
+                        processStation(commandParam);
                     }
 
-                    redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getCrnNo(), JSON.toJSONString(newCommandList, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24);
                     Thread.sleep(100);
                 } catch (Exception e) {
                     log.error("DualCrnCommand Fail", e);
@@ -140,12 +138,17 @@
         commandThread.start();
     }
 
-    private SendDualCrnCommandParam processStation(SendDualCrnCommandParam commandParam) {
+    private void processStation(SendDualCrnCommandParam commandParam) {
         Integer station = commandParam.getStation();
-        Integer idx = commandParam.getCommandIdx();
         List<DualCrnCommand> commandList = commandParam.getCommands();
+        DualCrnCommand firstCommand = commandList.get(0);
+        Object idxObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo());
+        if(idxObj == null) {
+            return;
+        }
+        Integer idx = (Integer) idxObj;
         if (idx >= commandList.size()) {
-            return commandParam;
+            return;
         }
         DualCrnCommand dualCommand = commandList.get(idx);
 
@@ -167,17 +170,17 @@
         if (idx == 0) {
             if(send) {
                 idx++;
-                commandParam.setCommandIdx(idx);
+                redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo(), idx, 60 * 60 * 24);
                 sendCommand(dualCommand);
                 redisUtil.set(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo(), "lock", 5);
             }
-            return commandParam;
+            return;
         }else {
             if (dualCommand.getTaskMode() == DualCrnTaskModeType.PUT.id.shortValue()) {
                 //绛夊緟涓嬩竴涓换鍔�
                 Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
                 if (wait != null) {
-                    return commandParam;
+                    return;
                 }
 
                 Integer taskNo = dualCommand.getTaskNo();
@@ -187,35 +190,35 @@
                     StationObjModel stationObjModel = JSON.parseObject(outTaskStationInfoObj.toString(), StationObjModel.class);
                     StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
                     if (stationThread == null) {
-                        return commandParam;
+                        return;
                     }
 
                     Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
                     StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId());
                     if (stationProtocol == null) {
-                        return commandParam;
+                        return;
                     }
 
                     if (!stationProtocol.isAutoing()) {
-                        return commandParam;
+                        return;
                     }
 
                     if (stationProtocol.isLoading()) {
-                        return commandParam;
+                        return;
                     }
 
                     if (stationProtocol.getTaskNo() > 0) {
-                        return commandParam;
+                        return;
                     }
                 }
             }
 
             if(send) {
                 idx++;
-                commandParam.setCommandIdx(idx);
+                redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo(), idx, 60 * 60 * 24);
                 sendCommand(dualCommand);
             }
-            return commandParam;
+            return;
         }
     }
 
diff --git a/src/main/java/com/zy/core/utils/DualCrnOperateProcessUtils.java b/src/main/java/com/zy/core/utils/DualCrnOperateProcessUtils.java
index 3d66a89..ba6a2f0 100644
--- a/src/main/java/com/zy/core/utils/DualCrnOperateProcessUtils.java
+++ b/src/main/java/com/zy/core/utils/DualCrnOperateProcessUtils.java
@@ -107,22 +107,40 @@
 
         // 濡傛灉鏈�杩戜竴娆℃槸鍑哄簱妯″紡
         if (dualCrnProtocol.getLastIo().equals("O")) {
-            processLoveMove(basDualCrnp, dualCrnThread);
-            processIn(basDualCrnp, dualCrnThread);
-            processOut(basDualCrnp, dualCrnThread);
+            boolean executeResult1 = processLoveMove(basDualCrnp, dualCrnThread);
+            if (executeResult1) {
+                return;
+            }
+            boolean executeResult2 = processIn(basDualCrnp, dualCrnThread);
+            if (executeResult2) {
+                return;
+            }
+            boolean executeResult3 = processOut(basDualCrnp, dualCrnThread);
+            if (executeResult3) {
+                return;
+            }
         }
         // 濡傛灉鏈�杩戜竴娆℃槸鍏ュ簱妯″紡
         else if (dualCrnProtocol.getLastIo().equals("I")) {
-            processLoveMove(basDualCrnp, dualCrnThread);
-            processOut(basDualCrnp, dualCrnThread);
-            processIn(basDualCrnp, dualCrnThread);
+            boolean executeResult1 = processLoveMove(basDualCrnp, dualCrnThread);
+            if (executeResult1) {
+                return;
+            }
+            boolean executeResult2 = processOut(basDualCrnp, dualCrnThread);
+            if (executeResult2) {
+                return;
+            }
+            boolean executeResult3 = processIn(basDualCrnp, dualCrnThread);
+            if (executeResult3) {
+                return;
+            }
         }
     }
 
-    private void processIn(BasDualCrnp basDualCrnp, DualCrnThread dualCrnThread) {
+    private boolean processIn(BasDualCrnp basDualCrnp, DualCrnThread dualCrnThread) {
         List<WrkMast> inTaskList = getInTaskList(basDualCrnp);
         if (inTaskList.isEmpty()) {
-            return;
+            return false;
         }
 
         WrkMast stationOneWrkMast = inTaskList.get(0);
@@ -158,13 +176,15 @@
             MessageQueue.offer(SlaveType.DualCrn, crnNo, new Task(2, list));
             News.info("鍙屽伐浣嶅爢鍨涙満鍛戒护涓嬪彂鎴愬姛锛屽爢鍨涙満鍙�={}锛屼换鍔℃暟鎹�={}", crnNo, JSON.toJSON(list));
             dualCrnProtocol.setLastIo("I");
+            return true;
         }
+        return false;
     }
 
-    private void processOut(BasDualCrnp basDualCrnp, DualCrnThread dualCrnThread) {
+    private boolean processOut(BasDualCrnp basDualCrnp, DualCrnThread dualCrnThread) {
         List<WrkMast> outTaskList = getOutTaskList(basDualCrnp);
         if (outTaskList.isEmpty()) {
-            return;
+            return false;
         }
 
         WrkMast stationOneWrkMast = null;
@@ -214,13 +234,15 @@
             MessageQueue.offer(SlaveType.DualCrn, crnNo, new Task(2, list));
             News.info("鍙屽伐浣嶅爢鍨涙満鍛戒护涓嬪彂鎴愬姛锛屽爢鍨涙満鍙�={}锛屼换鍔℃暟鎹�={}", crnNo, JSON.toJSON(list));
             dualCrnProtocol.setLastIo("O");
+            return true;
         }
+        return false;
     }
 
-    private void processLoveMove(BasDualCrnp basDualCrnp, DualCrnThread dualCrnThread) {
+    private boolean processLoveMove(BasDualCrnp basDualCrnp, DualCrnThread dualCrnThread) {
         List<WrkMast> locMoveTaskList = getLocMoveTaskList(basDualCrnp);
         if (locMoveTaskList.isEmpty()) {
-            return;
+            return false;
         }
 
         WrkMast stationOneWrkMast = null;
@@ -270,7 +292,9 @@
             MessageQueue.offer(SlaveType.DualCrn, crnNo, new Task(2, list));
             News.info("鍙屽伐浣嶅爢鍨涙満鍛戒护涓嬪彂鎴愬姛锛屽爢鍨涙満鍙�={}锛屼换鍔℃暟鎹�={}", crnNo, JSON.toJSON(list));
             dualCrnProtocol.setLastIo("O");
+            return true;
         }
+        return false;
     }
 
     private List<WrkMast> getInTaskList(BasDualCrnp basDualCrnp) {
@@ -678,28 +702,13 @@
             return;
         }
 
-        Object commandListObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + basDualCrnp.getCrnNo());
-        if (commandListObj == null) {
-            News.error("鍙屽伐浣嶅爢鍨涙満澶勪簬绛夊緟纭涓斾换鍔″畬鎴愮姸鎬侊紝浣嗘湭鎵惧埌鍛戒护銆傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", basDualCrnp.getCrnNo(), taskNo);
-            return;
-        }
-        List<SendDualCrnCommandParam> dualCrnCommandParamList = JSON.parseArray(commandListObj.toString(), SendDualCrnCommandParam.class);
-        SendDualCrnCommandParam taskCommand = null;
-        for (SendDualCrnCommandParam sendDualCrnCommandParam : dualCrnCommandParamList) {
-            DualCrnCommand dualCrnCommand = sendDualCrnCommandParam.getCommands().get(0);
-            if(dualCrnCommand.getTaskNo() == taskNo){
-                taskCommand = sendDualCrnCommandParam;
-                break;
-            }
-        }
-        if (taskCommand == null) {
-            News.error("鍙屽伐浣嶅爢鍨涙満澶勪簬绛夊緟纭涓斾换鍔″畬鎴愮姸鎬侊紝浣嗘湭鎵惧埌鍛戒护銆傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", basDualCrnp.getCrnNo(), taskNo);
-            return;
+        int idx = 10;
+        Object idxObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + wrkMast.getWrkNo());
+        if(idxObj != null) {
+            idx = (Integer) idxObj;
         }
 
-        Integer idx = taskCommand.getCommandIdx();
-        List<DualCrnCommand> commandList = taskCommand.getCommands();
-        if (idx >= commandList.size()) {
+        if (idx >= 2) {
             Long updateWrkSts = null;
             if (wrkMast.getWrkSts() == WrkStsType.INBOUND_RUN.sts) {
                 updateWrkSts = WrkStsType.COMPLETE_INBOUND.sts;

--
Gitblit v1.9.1