From 4a1aabe58c417352b62504255603f790b0a6228b Mon Sep 17 00:00:00 2001
From: cpT <1@123>
Date: 星期五, 30 一月 2026 15:37:43 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java |  211 ++++++++++++++++++++++++++--------------------------
 1 files changed, 105 insertions(+), 106 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 a9eb174..84b76a6 100644
--- a/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
@@ -20,6 +20,7 @@
 import com.zy.core.model.StationObjModel;
 import com.zy.core.model.Task;
 import com.zy.core.model.command.DualCrnCommand;
+import com.zy.core.model.param.SendDualCrnCommandParam;
 import com.zy.core.model.protocol.DualCrnProtocol;
 import com.zy.core.model.protocol.StationProtocol;
 import com.zy.core.network.DeviceConnectPool;
@@ -31,10 +32,8 @@
 import lombok.extern.slf4j.Slf4j;
 
 import java.text.MessageFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+
 import com.zy.asrs.entity.BasDualCrnpErrLog;
 import com.zy.asrs.service.BasDualCrnpErrLogService;
 
@@ -67,7 +66,7 @@
                 try {
                     deviceLogCollectTime = Utils.getDeviceLogCollectTime();
                     readStatus();
-                    Thread.sleep(100);
+                    Thread.sleep(50);
                 } catch (Exception e) {
                     log.error("DualCrnThread Fail", e);
                 }
@@ -85,14 +84,8 @@
                     }
 
                     if (step == 2) {
-                        List<DualCrnCommand> commandList = (List<DualCrnCommand>) task.getData();
-                        DualCrnCommand command = commandList.get(0);
-
-                        HashMap<String, Object> map = new HashMap<>();
-                        map.put("commands", commandList);
-                        map.put("idx", 1);
-                        redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + command.getTaskNo(), JSON.toJSONString(map, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24);
-                        sendCommand(command);
+                        List<SendDualCrnCommandParam> commandList = (List<SendDualCrnCommandParam>) task.getData();
+                        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());
                     }
@@ -116,101 +109,28 @@
                         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.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());
+//                        }
+//                    }
+
+                    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);
                         }
                     }
 
-                    if(crnProtocol.getTaskNo() > 0 && crnProtocol.getStatus() == DualCrnStatusType.IDLE.id) {
-                        Integer taskNo = crnProtocol.getTaskNo();
-                        Object commandObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo);
-                        if (commandObj == null) {
-                            News.error("鍙屽伐浣嶅爢鍨涙満锛屽伐浣�1绌洪棽绛夊緟涓嬪彂鍛戒护锛屼絾鏈壘鍒板懡浠ゃ�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crnProtocol.getCrnNo(), taskNo);
-                            continue;
-                        }
-
-                        JSONObject commandMap = JSON.parseObject(commandObj.toString());
-                        Integer idx = commandMap.getInteger("idx");
-                        List<DualCrnCommand> commandList = commandMap.getJSONArray("commands").toJavaList(DualCrnCommand.class);
-                        if (idx >= commandList.size()) {
-                            continue;
-                        }
-                        DualCrnCommand dualCommand = commandList.get(idx);
-
-                        if (dualCommand.getTaskMode() == DualCrnTaskModeType.PUT.id.shortValue()) {
-                            //绛夊緟涓嬩竴涓换鍔�
-                            Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
-                            if (wait != null) {
-                                continue;
-                            }
-
-                            Object outTaskStationInfoObj = redisUtil.get(RedisKeyType.DUAL_CRN_OUT_TASK_STATION_INFO.key + taskNo);
-                            if (outTaskStationInfoObj != null) {
-                                //妫�娴嬪嚭鍙g珯鏄惁鍙墽琛屾斁璐у姩浣�
-                                StationObjModel stationObjModel = JSON.parseObject(outTaskStationInfoObj.toString(), StationObjModel.class);
-                                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
-                                if (stationThread == null) {
-                                    continue;
-                                }
-
-                                Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
-                                StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId());
-                                if (stationProtocol == null) {
-                                    continue;
-                                }
-
-                                if (!stationProtocol.isAutoing()) {
-                                    continue;
-                                }
-
-                                if (stationProtocol.isLoading()) {
-                                    continue;
-                                }
-
-                                if (stationProtocol.getTaskNo() > 0) {
-                                    continue;
-                                }
-                            }
-                        }
-
-                        idx++;
-                        commandMap.put("idx", idx);
-                        sendCommand(dualCommand);
-                        redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo, commandMap.toJSONString(), 60 * 60 * 24);
-                    }
-
-                    if(crnProtocol.getTaskNoTwo() > 0 && crnProtocol.getStatusTwo() == DualCrnStatusType.IDLE.id) {
-                        Integer taskNo = crnProtocol.getTaskNoTwo();
-                        Object commandObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo);
-                        if (commandObj == null) {
-                            News.error("鍙屽伐浣嶅爢鍨涙満锛屽伐浣�2绌洪棽绛夊緟涓嬪彂鍛戒护锛屼絾鏈壘鍒板懡浠ゃ�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crnProtocol.getCrnNo(), taskNo);
-                            continue;
-                        }
-
-                        JSONObject commandMap = JSON.parseObject(commandObj.toString());
-                        Integer idx = commandMap.getInteger("idx");
-                        List<DualCrnCommand> commandList = commandMap.getJSONArray("commands").toJavaList(DualCrnCommand.class);
-                        if (idx >= commandList.size()) {
-                            continue;
-                        }
-                        DualCrnCommand dualCommand = commandList.get(idx);
-
-                        if (dualCommand.getTaskMode() == DualCrnTaskModeType.PUT.id.shortValue()) {
-                            //绛夊緟涓嬩竴涓换鍔�
-                            Object wait = redisUtil.get(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo());
-                            if (wait != null) {
-                                continue;
-                            }
-                        }
-
-                        idx++;
-                        commandMap.put("idx", idx);
-                        sendCommand(dualCommand);
-                        redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + taskNo, commandMap.toJSONString(), 60 * 60 * 24);
-                    }
-
+                    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);
@@ -218,6 +138,85 @@
             }
         });
         commandThread.start();
+    }
+
+    private SendDualCrnCommandParam processStation(SendDualCrnCommandParam commandParam) {
+        Integer station = commandParam.getStation();
+        Integer idx = commandParam.getCommandIdx();
+        List<DualCrnCommand> commandList = commandParam.getCommands();
+        if (idx >= commandList.size()) {
+            return commandParam;
+        }
+        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;
+            }
+        }else {
+            if (crnProtocol.getStatusTwo().equals(DualCrnStatusType.FETCH_COMPLETE.id)
+                    || crnProtocol.getStatusTwo().equals(DualCrnStatusType.IDLE.id)
+            ) {
+                send = true;
+            }
+        }
+
+        if (idx == 0) {
+            if(send) {
+                idx++;
+                commandParam.setCommandIdx(idx);
+                sendCommand(dualCommand);
+                redisUtil.set(RedisKeyType.DUAL_CRN_PICK_WAIT_NEXT_TASK.key + crnProtocol.getCrnNo(), "lock", 5);
+            }
+            return commandParam;
+        }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;
+                }
+
+                Integer taskNo = dualCommand.getTaskNo();
+                Object outTaskStationInfoObj = redisUtil.get(RedisKeyType.DUAL_CRN_OUT_TASK_STATION_INFO.key + taskNo);
+                if (outTaskStationInfoObj != null) {
+                    //妫�娴嬪嚭鍙g珯鏄惁鍙墽琛屾斁璐у姩浣�
+                    StationObjModel stationObjModel = JSON.parseObject(outTaskStationInfoObj.toString(), StationObjModel.class);
+                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
+                    if (stationThread == null) {
+                        return commandParam;
+                    }
+
+                    Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
+                    StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId());
+                    if (stationProtocol == null) {
+                        return commandParam;
+                    }
+
+                    if (!stationProtocol.isAutoing()) {
+                        return commandParam;
+                    }
+
+                    if (stationProtocol.isLoading()) {
+                        return commandParam;
+                    }
+
+                    if (stationProtocol.getTaskNo() > 0) {
+                        return commandParam;
+                    }
+                }
+            }
+
+            if(send) {
+                idx++;
+                commandParam.setCommandIdx(idx);
+                sendCommand(dualCommand);
+            }
+            return commandParam;
+        }
     }
 
     /**
@@ -492,7 +491,7 @@
     }
 
     @Override
-    public synchronized CommandResponse sendCommand(DualCrnCommand command) {
+    public CommandResponse sendCommand(DualCrnCommand command) {
         this.crnProtocol.setLastCommandTime(System.currentTimeMillis());
         CommandResponse response = null;
         try {

--
Gitblit v1.9.1