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/thread/impl/ZySiemensDualCrnThread.java |   55 +++++++++++++++++++++++++++++--------------------------
 1 files changed, 29 insertions(+), 26 deletions(-)

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;
         }
     }
 

--
Gitblit v1.9.1