From 3f797dd834a2de283cf5eff2ff1124e5a0ccb233 Mon Sep 17 00:00:00 2001
From: Administrator <XS@163.COM>
Date: 星期六, 25 四月 2026 11:18:50 +0800
Subject: [PATCH] 更改 2026-4-25

---
 src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java |  407 ++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 258 insertions(+), 149 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 7bf7e62..2f643ae 100644
--- a/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZySiemensDualCrnThread.java
@@ -9,6 +9,7 @@
 import com.zy.asrs.entity.*;
 import com.zy.asrs.service.BasDualCrnpOptService;
 import com.zy.asrs.service.BasDualCrnpService;
+import com.zy.asrs.service.WrkMastService;
 import com.zy.asrs.utils.Utils;
 import com.zy.common.utils.RedisUtil;
 import com.zy.core.News;
@@ -20,6 +21,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 +33,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;
 
@@ -49,7 +49,7 @@
     private RedisUtil redisUtil;
     private ZyDualCrnConnectDriver zyDualCrnConnectDriver;
     private DualCrnProtocol crnProtocol;
-    private int deviceLogCollectTime = 200;
+    private volatile int deviceLogCollectTime = 200;
 
     public ZySiemensDualCrnThread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
         this.deviceConfig = deviceConfig;
@@ -67,7 +67,7 @@
                 try {
                     deviceLogCollectTime = Utils.getDeviceLogCollectTime();
                     readStatus();
-                    Thread.sleep(50);
+                    Thread.sleep(100);
                 } catch (Exception e) {
                     log.error("DualCrnThread Fail", e);
                 }
@@ -85,15 +85,17 @@
                     }
 
                     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);
-                        redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_STATION_TASK_NO.key + crnProtocol.getCrnNo() + "_" + command.getStation(), command.getTaskNo(), 60 * 60 * 24);
-                        sendCommand(command);
+                        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(), 0, 60 * 60 * 24);
+                            redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_.key + dualCrnCommand.getTaskNo(), JSON.toJSONString(sendDualCrnCommandParam, SerializerFeature.DisableCircularReferenceDetect), 60 * 60 * 24);
+                            if (sendDualCrnCommandParam.getStation() == 1) {
+                                redisUtil.set(RedisKeyType.DUAL_CRN_STATION1_FLAG.key + crnProtocol.getCrnNo(), dualCrnCommand.getTaskNo(), 60 * 60 * 24);
+                            } else {
+                                redisUtil.set(RedisKeyType.DUAL_CRN_STATION2_FLAG.key + crnProtocol.getCrnNo(), dualCrnCommand.getTaskNo(), 60 * 60 * 24);
+                            }
+                        }
                     } else if (step == 3) {
                         sendCommand((DualCrnCommand) task.getData());
                     }
@@ -109,136 +111,165 @@
         Thread commandThread = new Thread(() -> {
             while (true) {
                 try {
-                    if(crnProtocol.getMode() != DualCrnModeType.AUTO.id) {
-                        continue;
-                    }
-
-                    if(crnProtocol.getAlarm() != 0) {
-                        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.getTaskNo() == 0 && crnProtocol.getStatus().equals(DualCrnStatusType.FETCH_COMPLETE.id)) {
-                        Integer taskNo = null;
-                        Object stationObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_STATION_TASK_NO.key + crnProtocol.getCrnNo() + "_" + 1);
-                        if(stationObj != null) {
-                            taskNo = Integer.parseInt(String.valueOf(stationObj));
-                        }
-
-                        if (taskNo == null) {
-                            News.error("鍙屽伐浣嶅爢鍨涙満锛屽伐浣�1绌洪棽绛夊緟涓嬪彂鍛戒护锛屼絾鏈壘鍒板伐浣滃彿銆傚爢鍨涙満鍙�={}", crnProtocol.getCrnNo());
-                            continue;
-                        }
-
-                        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().equals(DualCrnStatusType.FETCH_COMPLETE.id)) {
-                        Integer taskNo = null;
-                        Object stationObj = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_STATION_TASK_NO.key + crnProtocol.getCrnNo() + "_" + 2);
-                        if(stationObj != null) {
-                            taskNo = Integer.parseInt(String.valueOf(stationObj));
-                        }
-
-                        if (taskNo == null) {
-                            News.error("鍙屽伐浣嶅爢鍨涙満锛屽伐浣�1绌洪棽绛夊緟涓嬪彂鍛戒护锛屼絾鏈壘鍒板伐浣滃彿銆傚爢鍨涙満鍙�={}", crnProtocol.getCrnNo());
-                            continue;
-                        }
-
-                        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);
-                    }
-
                     Thread.sleep(100);
+
+                    if (crnProtocol.getMode() != DualCrnModeType.AUTO.id) {
+                        continue;
+                    }
+
+                    if (crnProtocol.getAlarm() != 0) {
+                        continue;
+                    }
+
+                    if (!((crnProtocol.getStatusType().equals(DualCrnStatusType.IDLE) || crnProtocol.getStatusType().equals(DualCrnStatusType.FETCH_COMPLETE))
+                            && (crnProtocol.getStatusTypeTwo().equals(DualCrnStatusType.IDLE) || crnProtocol.getStatusTypeTwo().equals(DualCrnStatusType.FETCH_COMPLETE)))
+                    ) {
+                        continue;
+                    }
+
+                    List<SendDualCrnCommandParam> commandList = getDualCrnCommandList();
+                    for (SendDualCrnCommandParam commandParam : commandList) {
+                        processStation(commandParam);
+                    }
+
                 } catch (Exception e) {
                     log.error("DualCrnCommand Fail", e);
                 }
             }
         });
         commandThread.start();
+    }
+
+    private void processStation(SendDualCrnCommandParam commandParam) {
+        Integer station = commandParam.getStation();
+        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;
+        }
+        DualCrnCommand dualCommand = commandList.get(idx);
+
+        boolean send = false;
+        //TODO 鍒ゆ柇绔欑偣1锛�2浠诲姟绫诲瀷鏄惁涓�鑷�
+        if (station == 1) {
+            log.info("宸ヤ綅2浠诲姟==========>{}, 浠诲姟妯″紡---->{}", crnProtocol.getTaskNoTwo(), crnProtocol.getMode());
+            log.info("宸ヤ綅1浠诲姟==========>{}, 浠诲姟妯″紡---->{}", crnProtocol.getTaskNo(), crnProtocol.getMode());
+            Integer taskNo = crnProtocol.getTaskNoTwo();
+            if (crnProtocol.getTaskSend() == 0) {
+                //涓や釜宸ヤ綅鍙厑璁告斁鐩稿悓绫诲瀷浠诲姟
+//                if (taskNo != null && taskNo > 0) {
+//                    WrkMastService mastService = SpringUtils.getBean(WrkMastService.class);
+//                    WrkMast wrkMast = mastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", taskNo));
+//                    WrkMast wrkMast1 = mastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", dualCommand.getTaskNo()));
+//                    if (!Objects.isNull(wrkMast) && !Objects.isNull(wrkMast1)) {
+//                        if (wrkMast1.getIoType() != wrkMast.getIoType()) {
+////                            return;
+//                        }
+//                    }
+//                }
+                // && sendComm(taskNo, dualCommand.getTaskNo())
+                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 {
+            log.info("宸ヤ綅1浠诲姟==========>{}, 浠诲姟妯″紡---->{}", crnProtocol.getTaskNo(), crnProtocol.getMode());
+            log.info("宸ヤ綅2浠诲姟==========>{}, 浠诲姟妯″紡---->{}", crnProtocol.getTaskNoTwo(), crnProtocol.getMode());
+            Integer taskNo = crnProtocol.getTaskNo();
+            // && sendComm(taskNo, dualCommand.getTaskNo())
+            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++;
+                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", 3);
+            }
+            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;
+                }
+
+                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;
+                    }
+
+                    Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
+                    StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId());
+                    if (stationProtocol == null) {
+                        return;
+                    }
+
+                    if (!stationProtocol.isAutoing()) {
+                        return;
+                    }
+
+                    if (stationProtocol.isLoading()) {
+                        return;
+                    }
+
+                    if (stationProtocol.getTaskNo() > 0) {
+                        return;
+                    }
+                }
+            }
+
+            if (send) {
+                idx++;
+                redisUtil.set(RedisKeyType.DUAL_CRN_COMMAND_IDX.key + firstCommand.getTaskNo(), idx, 60 * 60 * 24);
+                sendCommand(dualCommand);
+            }
+            return;
+        }
+    }
+
+    public boolean sendComm(Integer taskNo, Integer current) {
+        //涓や釜宸ヤ綅鍙厑璁告斁鐩稿悓绫诲瀷浠诲姟
+        if (taskNo != null && taskNo > 0) {
+            WrkMastService mastService = SpringUtils.getBean(WrkMastService.class);
+            WrkMast wrkMast = mastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", taskNo));
+            WrkMast wrkMast1 = mastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", current));
+            if (!Objects.isNull(wrkMast) && !Objects.isNull(wrkMast1)) {
+                if (wrkMast1.getIoType() != wrkMast.getIoType()) {
+                    return false;
+                }
+            }
+        }
+
+        return true;
     }
 
     /**
@@ -253,6 +284,7 @@
 
         //宸ヤ綅1
         crnProtocol.setTaskNo(0);
+        crnProtocol.setDeviceTaskNo(0);
         crnProtocol.setStatus(-1);
         crnProtocol.setBay(0);
         crnProtocol.setLevel(0);
@@ -263,6 +295,7 @@
 
         //宸ヤ綅2
         crnProtocol.setTaskNoTwo(0);
+        crnProtocol.setDeviceTaskNoTwo(0);
         crnProtocol.setStatusTwo(-1);
         crnProtocol.setBayTwo(0);
         crnProtocol.setLevelTwo(0);
@@ -283,12 +316,12 @@
         BasDualCrnpService basDualCrnpService = null;
         try {
             basDualCrnpService = SpringUtils.getBean(BasDualCrnpService.class);
-        }catch (Exception e){
+        } catch (Exception e) {
 
         }
         if (basDualCrnpService != null) {
             BasDualCrnp basDualCrnp = basDualCrnpService.selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", deviceConfig.getDeviceNo()));
-            if(basDualCrnp == null) {
+            if (basDualCrnp == null) {
                 basDualCrnp = new BasDualCrnp();
                 basDualCrnp.setCrnNo(deviceConfig.getDeviceNo());
                 basDualCrnp.setStatus(1);
@@ -313,7 +346,7 @@
     /**
      * 璇诲彇鐘舵��
      */
-    private void readStatus(){
+    private void readStatus() {
         ZyDualCrnStatusEntity crnStatus = zyDualCrnConnectDriver.getStatus();
         if (crnStatus == null) {
             OutputQueue.DUAL_CRN.offer(MessageFormat.format("銆恵0}銆戣鍙栧弻宸ヤ綅鍫嗗灈鏈簆lc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()));
@@ -322,18 +355,20 @@
         crnProtocol.setMode(crnStatus.getMode());
 
         //宸ヤ綅1
-        crnProtocol.setTaskNo(crnStatus.getTaskNo());
+        crnProtocol.setDeviceTaskNo(crnStatus.getTaskNo());
         crnProtocol.setStatus(crnStatus.getStatus());
         crnProtocol.setForkPos(crnStatus.getForkPos());
         crnProtocol.setLoaded(crnStatus.getLoaded());
         crnProtocol.setTaskReceive(crnStatus.getTaskReceive());
+        crnProtocol.setTaskSend(crnStatus.getTaskSend());
 
         //宸ヤ綅2
-        crnProtocol.setTaskNoTwo(crnStatus.getTaskNoTwo());
+        crnProtocol.setDeviceTaskNoTwo(crnStatus.getTaskNoTwo());
         crnProtocol.setStatusTwo(crnStatus.getStatusTwo());
         crnProtocol.setForkPosTwo(crnStatus.getForkPosTwo());
         crnProtocol.setLoadedTwo(crnStatus.getLoadedTwo());
         crnProtocol.setTaskReceiveTwo(crnStatus.getTaskReceiveTwo());
+        crnProtocol.setTaskSendTwo(crnStatus.getTaskSendTwo());
 
         crnProtocol.setBay(crnStatus.getBay());
         crnProtocol.setLevel(crnStatus.getLevel());
@@ -354,7 +389,7 @@
         crnProtocol.setGoodsType(crnStatus.getGoodsType());
         crnProtocol.setBarcode(crnStatus.getBarcode());
 
-        OutputQueue.DUAL_CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), deviceConfig.getDeviceNo()));
+        OutputQueue.DUAL_CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛", DateUtils.convert(new Date()), deviceConfig.getDeviceNo()));
 
         if (crnProtocol.getAlarm() > 0) {
             crnProtocol.setLastCommandTime(-1L);
@@ -377,7 +412,7 @@
             //鏇存柊閲囬泦鏃堕棿
             crnProtocol.setDeviceDataLog(System.currentTimeMillis());
         }
-        
+
         try {
             BasDualCrnpErrLogService errLogService = SpringUtils.getBean(BasDualCrnpErrLogService.class);
             if (errLogService != null) {
@@ -413,7 +448,8 @@
                     }
                 }
             }
-        } catch (Exception ignore) {}
+        } catch (Exception ignore) {
+        }
     }
 
     @Override
@@ -496,10 +532,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);     // 婧愬簱浣嶅垪
@@ -513,7 +549,7 @@
     }
 
     @Override
-    public synchronized CommandResponse sendCommand(DualCrnCommand command) {
+    public CommandResponse sendCommand(DualCrnCommand command) {
         this.crnProtocol.setLastCommandTime(System.currentTimeMillis());
         CommandResponse response = null;
         try {
@@ -544,4 +580,77 @@
             }
         }
     }
+
+    public List<SendDualCrnCommandParam> getDualCrnCommandList() {
+        List<SendDualCrnCommandParam> commandList = new ArrayList<>();
+        SendDualCrnCommandParam command1 = getDualCrnCommandList(1);
+        SendDualCrnCommandParam command2 = getDualCrnCommandList(2);
+        if (command1 != null) {
+            commandList.add(command1);
+        }
+
+        if (command2 != null) {
+            commandList.add(command2);
+        }
+
+        return commandList;
+    }
+
+    public SendDualCrnCommandParam getDualCrnCommandList(int station) {
+        SendDualCrnCommandParam sendDualCrnCommandParam = null;
+        String key = null;
+        if (station == 1 && crnProtocol.getTaskNo() > 0) {
+            key = RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getTaskNo();
+        } else if (station == 2 && crnProtocol.getTaskNoTwo() > 0) {
+            key = RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getTaskNoTwo();
+        }
+
+        if (key == null) {
+            return null;
+        }
+        Object commandObj = redisUtil.get(key);
+
+        if (commandObj == null) {
+            return null;
+        }
+
+        sendDualCrnCommandParam = JSON.parseObject(commandObj.toString(), SendDualCrnCommandParam.class);
+        if (sendDualCrnCommandParam == null) {
+            return null;
+        }
+
+        if (station == 1) {
+            if (crnProtocol.getTaskNoTwo() > 0) {
+                Object object = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getTaskNoTwo());
+                if (object != null) {
+                    SendDualCrnCommandParam jsonObject = JSON.parseObject(object.toString(), SendDualCrnCommandParam.class);
+                    ;
+                    if (!jsonObject.getCommands().get(0).getTaskMode().equals(sendDualCrnCommandParam.getCommands().get(0).getTaskMode())) {
+                        return null;
+                    }
+                }
+            }
+        } else {
+            if (crnProtocol.getTaskNo() > 0) {
+                WrkMastService mastService = SpringUtils.getBean(WrkMastService.class);
+                WrkMast wrkMast = mastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", crnProtocol.getTaskNo()));
+                WrkMast wrkMast1 = mastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", crnProtocol.getTaskNoTwo()));
+                if (!Objects.isNull(wrkMast) && !Objects.isNull(wrkMast1)) {
+                    if (!wrkMast1.getIoType().equals(wrkMast.getIoType())) {
+                        return null;
+                    }
+                }
+//                Object object = redisUtil.get(RedisKeyType.DUAL_CRN_COMMAND_.key + crnProtocol.getTaskNo());
+//                if (object != null) {
+//                    SendDualCrnCommandParam jsonObject = JSON.parseObject(object.toString(), SendDualCrnCommandParam.class);
+//                    ;
+//                    if (!jsonObject.getCommands().get(0).getTaskMode().equals(sendDualCrnCommandParam.getCommands().get(0).getTaskMode())) {
+//                        return null;
+//                    }
+//                }
+            }
+        }
+
+        return sendDualCrnCommandParam;
+    }
 }

--
Gitblit v1.9.1