From 27836d1b0bc74a5aa22a8b6c7cf40f2d0068db8a Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期三, 11 二月 2026 13:40:59 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java |   89 ++++++++++++++++++++++++++------------------
 1 files changed, 53 insertions(+), 36 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..e837329 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,44 +138,61 @@
         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);
 
         boolean send = false;
         if (station == 1) {
-            if (crnProtocol.getStatus().equals(DualCrnStatusType.FETCH_COMPLETE.id)
-                    || crnProtocol.getStatus().equals(DualCrnStatusType.IDLE.id)
-            ) {
-                send = true;
+            if (crnProtocol.getTaskSend() == 0) {
+                if (dualCommand.getTaskMode().intValue() == DualCrnTaskModeType.PICK.id) {
+                    if (crnProtocol.getStatus().equals(DualCrnStatusType.IDLE.id)) {
+                        send = true;
+                    }
+                } else if (dualCommand.getTaskMode().intValue() == DualCrnTaskModeType.PUT.id) {
+                    if (crnProtocol.getStatus().equals(DualCrnStatusType.FETCH_COMPLETE.id)) {
+                        send = true;
+                    }
+                }
             }
         }else {
-            if (crnProtocol.getStatusTwo().equals(DualCrnStatusType.FETCH_COMPLETE.id)
-                    || crnProtocol.getStatusTwo().equals(DualCrnStatusType.IDLE.id)
-            ) {
-                send = true;
+            if (crnProtocol.getTaskSendTwo() == 0) {
+                if (dualCommand.getTaskMode().intValue() == DualCrnTaskModeType.PICK.id) {
+                    if (crnProtocol.getStatusTwo().equals(DualCrnStatusType.IDLE.id)) {
+                        send = true;
+                    }
+                } else if (dualCommand.getTaskMode().intValue() == DualCrnTaskModeType.PUT.id) {
+                    if (crnProtocol.getStatusTwo().equals(DualCrnStatusType.FETCH_COMPLETE.id)) {
+                        send = true;
+                    }
+                }
             }
         }
 
         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 +202,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;
         }
     }
 
@@ -305,6 +320,7 @@
         crnProtocol.setForkPos(crnStatus.getForkPos());
         crnProtocol.setLoaded(crnStatus.getLoaded());
         crnProtocol.setTaskReceive(crnStatus.getTaskReceive());
+        crnProtocol.setTaskSend(crnStatus.getTaskSend());
 
         //宸ヤ綅2
         crnProtocol.setTaskNoTwo(crnStatus.getTaskNoTwo());
@@ -312,6 +328,7 @@
         crnProtocol.setForkPosTwo(crnStatus.getForkPosTwo());
         crnProtocol.setLoadedTwo(crnStatus.getLoadedTwo());
         crnProtocol.setTaskReceiveTwo(crnStatus.getTaskReceiveTwo());
+        crnProtocol.setTaskSendTwo(crnStatus.getTaskSendTwo());
 
         crnProtocol.setBay(crnStatus.getBay());
         crnProtocol.setLevel(crnStatus.getLevel());
@@ -474,10 +491,10 @@
     }
 
     @Override
-    public DualCrnCommand getResetCommand(Integer crnNo, Integer station) {
+    public DualCrnCommand getResetCommand(Integer taskNo, Integer crnNo, Integer station) {
         DualCrnCommand crnCommand = new DualCrnCommand();
         crnCommand.setCrnNo(crnNo); // 鍫嗗灈鏈虹紪鍙�
-        crnCommand.setTaskNo(0); // 宸ヤ綔鍙�
+        crnCommand.setTaskNo(taskNo); // 宸ヤ綔鍙�
         crnCommand.setTaskMode(DualCrnTaskModeType.CONFIRM.id); // 浠诲姟妯″紡:  纭
         crnCommand.setSourcePosX(0);     // 婧愬簱浣嶆帓
         crnCommand.setSourcePosY(0);     // 婧愬簱浣嶅垪

--
Gitblit v1.9.1