From 456273f11d75782e676d43763f0f0601ea5c37f8 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 03 七月 2025 16:40:18 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/Utils/DeviceMsgUtils.java |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/zy/core/Utils/DeviceMsgUtils.java b/src/main/java/com/zy/core/Utils/DeviceMsgUtils.java
index def7c52..97399f9 100644
--- a/src/main/java/com/zy/core/Utils/DeviceMsgUtils.java
+++ b/src/main/java/com/zy/core/Utils/DeviceMsgUtils.java
@@ -23,6 +23,21 @@
     @Autowired
     private RedisUtil redisUtil;
 
+
+    public Object getDeviceCommandMsg(SlaveType deviceType, Integer deviceId) {
+        TreeSet<String> listKey = getDeviceCommandMsgListKey(deviceType, deviceId);
+        if (listKey.isEmpty()) {
+            return null;
+        }
+
+        String firstKey = listKey.first();
+        Object data = redisUtil.get(firstKey);
+        if (destroyAfterReading) {
+            redisUtil.del(firstKey);
+        }
+        return data;
+    }
+
     public DeviceMsgModel getDeviceMsg(SlaveType deviceType, Integer deviceId) {
         TreeSet<String> listKey = getDeviceMsgListKey(deviceType, deviceId);
         if (listKey.isEmpty()) {
@@ -53,7 +68,17 @@
         redisUtil.set(key, msgModel, 60 * 60);
     }
 
-    public String sendCommand(SlaveType deviceType, Integer deviceId, Object command) {
+    public String sendDeviceMsg(SlaveType deviceType, Integer deviceId, Object command) {
+        String key = parseDeviceMsgKey(deviceType, deviceId) + System.currentTimeMillis();
+
+        DeviceMsgModel deviceMsgModel = new DeviceMsgModel();
+        deviceMsgModel.setDeviceId(deviceId);
+        deviceMsgModel.setDeviceMsg(command);
+        redisUtil.set(key, deviceMsgModel, 60 * 60 * 24);
+        return key;
+    }
+
+    public String sendDeviceCommand(SlaveType deviceType, Integer deviceId, Object command) {
         String key = parseDeviceCommandMsgKey(deviceType, deviceId) + System.currentTimeMillis();
         redisUtil.set(key, command, 60 * 60 * 24);
         return key;
@@ -61,6 +86,18 @@
 
     public TreeSet<String> getDeviceMsgListKey(SlaveType deviceType, Integer deviceId) {
         String listKey = parseDeviceMsgKey(deviceType, deviceId);
+        Set<String> keys = redisUtil.searchKeys(listKey);
+
+        TreeSet<String> treeSet = new TreeSet<>();
+        for (String key : keys) {
+            treeSet.add(key);
+        }
+
+        return treeSet;
+    }
+
+    public TreeSet<String> getDeviceCommandMsgListKey(SlaveType deviceType, Integer deviceId) {
+        String listKey = parseDeviceCommandMsgKey(deviceType, deviceId);
         Set<String> keys = redisUtil.searchKeys(listKey);
 
         TreeSet<String> treeSet = new TreeSet<>();
@@ -99,4 +136,5 @@
         }
     }
 
+
 }

--
Gitblit v1.9.1