From 998ab39b718e4342a81616fea35fdf5059029bc3 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 30 三月 2026 15:46:32 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/impl/ZySiemensCrnV2Thread.java |   56 ++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/impl/ZySiemensCrnV2Thread.java b/src/main/java/com/zy/core/thread/impl/ZySiemensCrnV2Thread.java
index 2541dd5..abc04e9 100644
--- a/src/main/java/com/zy/core/thread/impl/ZySiemensCrnV2Thread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZySiemensCrnV2Thread.java
@@ -12,6 +12,7 @@
 import com.zy.common.utils.RedisUtil;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.OutputQueue;
+import com.zy.core.enums.CrnModeType;
 import com.zy.core.enums.CrnTaskModeType;
 import com.zy.core.enums.RedisKeyType;
 import com.zy.core.enums.SlaveType;
@@ -22,7 +23,9 @@
 import com.zy.core.network.DeviceConnectPool;
 import com.zy.core.network.ZyCrnV2ConnectDriver;
 import com.zy.core.network.entity.ZyCrnStatusEntity;
+import com.zy.core.service.WrkCommandRollbackService;
 import com.zy.core.thread.CrnThread;
+import com.zy.core.utils.DeviceLogRedisKeyBuilder;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
@@ -58,7 +61,7 @@
                 try {
                     deviceLogCollectTime = Utils.getDeviceLogCollectTime();
                     readStatus();
-                    Thread.sleep(50);
+                    Thread.sleep(100);
                 } catch (Exception e) {
                     log.error("CrnThread Fail", e);
                 }
@@ -149,6 +152,7 @@
     private void readStatus(){
         ZyCrnStatusEntity crnStatus = zyCrnConnectDriver.getStatus();
         if (crnStatus == null) {
+            crnProtocol.setMode(CrnModeType.NONE);
             OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戣鍙栧爢鍨涙満plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()));
             return;
         }
@@ -195,7 +199,7 @@
             deviceDataLog.setDeviceNo(crnProtocol.getCrnNo());
             deviceDataLog.setCreateTime(new Date());
 
-            redisUtil.set(RedisKeyType.DEVICE_LOG_KEY.key + System.currentTimeMillis(), deviceDataLog, 60 * 60 * 24);
+            redisUtil.set(DeviceLogRedisKeyBuilder.build(deviceDataLog), deviceDataLog, 60 * 60 * 24);
             //鏇存柊閲囬泦鏃堕棿
             crnProtocol.setDeviceDataLog(System.currentTimeMillis());
         }
@@ -307,27 +311,35 @@
             response = zyCrnConnectDriver.sendCommand(command);
             return response;
         } finally {
-            String sourceLocNo = Utils.getLocNo(command.getSourcePosX(), command.getSourcePosY(), command.getSourcePosZ());
-            String targetLocNo = Utils.getLocNo(command.getDestinationPosX(), command.getDestinationPosY(), command.getDestinationPosZ());
-            BasCrnpOptService bean = SpringUtils.getBean(BasCrnpOptService.class);
-            ZyCrnStatusEntity statusEntity = zyCrnConnectDriver.getStatus();
-            BasCrnpOpt basCrnpOpt = new BasCrnpOpt(
-                    command.getTaskNo().intValue(),
-                    command.getCrnNo(),
-                    new Date(),
-                    String.valueOf(command.getTaskMode()),
-                    sourceLocNo,
-                    targetLocNo,
-                    null,
-                    null,
-                    null,
-                    JSON.toJSONString(command),
-                    JSON.toJSONString(statusEntity),
-                    1,
-                    JSON.toJSONString(response)
-            );
-            if (bean != null) {
+            if (command != null) {
+                String sourceLocNo = Utils.getLocNo(command.getSourcePosX(), command.getSourcePosY(), command.getSourcePosZ());
+                String targetLocNo = Utils.getLocNo(command.getDestinationPosX(), command.getDestinationPosY(), command.getDestinationPosZ());
+                BasCrnpOptService bean = SpringUtils.getBean(BasCrnpOptService.class);
+                ZyCrnStatusEntity statusEntity = zyCrnConnectDriver.getStatus();
+                BasCrnpOpt basCrnpOpt = new BasCrnpOpt(
+                        command.getTaskNo(),
+                        command.getCrnNo(),
+                        new Date(),
+                        String.valueOf(command.getTaskMode()),
+                        sourceLocNo,
+                        targetLocNo,
+                        null,
+                        null,
+                        null,
+                        JSON.toJSONString(command),
+                        JSON.toJSONString(statusEntity),
+                        1,
+                        JSON.toJSONString(response)
+                );
                 bean.save(basCrnpOpt);
+                try {
+                    WrkCommandRollbackService rollbackService = SpringUtils.getBean(WrkCommandRollbackService.class);
+                    if (rollbackService != null) {
+                        rollbackService.handleSingleCrnSendResult(command, response, "鍗曞伐浣嶅爢鍨涙満V2");
+                    }
+                } catch (Exception e) {
+                    log.error("澶勭悊鍗曞伐浣峍2鍛戒护涓嬪彂缁撴灉澶辫触, wrkNo={}", command.getTaskNo(), e);
+                }
             }
         }
     }

--
Gitblit v1.9.1