From caf2599a9869244ded811018811c37a2aabac3fc Mon Sep 17 00:00:00 2001
From: vince <757871790@qq.com>
Date: 星期三, 08 一月 2025 11:29:05 +0800
Subject: [PATCH] 优化测温协议

---
 src/main/java/com/fzzy/gateway/service/GatewayConfService.java |   47 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/src/main/java/com/fzzy/gateway/service/GatewayConfService.java b/src/main/java/com/fzzy/gateway/service/GatewayConfService.java
index eabbf30..8c87457 100644
--- a/src/main/java/com/fzzy/gateway/service/GatewayConfService.java
+++ b/src/main/java/com/fzzy/gateway/service/GatewayConfService.java
@@ -3,19 +3,27 @@
 import com.bstek.dorado.annotation.DataProvider;
 import com.bstek.dorado.annotation.DataResolver;
 import com.bstek.dorado.annotation.Expose;
+import com.fzzy.api.utils.RedisConst;
+import com.fzzy.api.utils.RedisUtil;
 import com.fzzy.gateway.entity.GatewayConf;
 import com.fzzy.gateway.service.repository.GatewayConfRep;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 
+@Slf4j
 @Component
 public class GatewayConfService {
 
     @Resource
     private GatewayConfRep gatewayConfRep;
+    @Resource
+    private RedisUtil redisUtil;
 
 
     /**
@@ -41,6 +49,7 @@
         GatewayConf data = new GatewayConf();
         BeanUtils.copyProperties(entity, data);
         gatewayConfRep.save(data);
+        updateCache(data);
     }
 
     /**
@@ -56,19 +65,31 @@
         gatewayConfRep.delete(data2);
         return null;
     }
+    
 
-
-    /**
-     * gatewayConfService#delData
-     *
-     * @param data
-     */
-    @Expose
-    public String flush(GatewayConf data) {
-
-        GatewayConf data2 = new GatewayConf();
-        BeanUtils.copyProperties(data, data2);
-        gatewayConfRep.delete(data2);
-        return null;
+    public void updateCache(GatewayConf conf) {
+        String key = RedisConst.buildKey(RedisConst.KYE_CONF_GATEWAY, conf.getKqdm());
+        redisUtil.set(key, conf);
     }
+
+    public GatewayConf getCacheConf(String kqdm) {
+        try {
+            String key = RedisConst.buildKey(RedisConst.KYE_CONF_GATEWAY, kqdm);
+            return (GatewayConf) redisUtil.get(key);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return null;
+        }
+    }
+
+    public List<GatewayConf> getCacheConfList() {
+        String tag = RedisConst.buildKey(RedisConst.KYE_CONF_GATEWAY);
+        Set<String> keys = redisUtil.keys(tag);
+        List<GatewayConf> result = new ArrayList<>();
+        for (String key : keys) {
+            result.add((GatewayConf) redisUtil.get(key));
+        }
+        return result;
+    }
+
 }

--
Gitblit v1.9.3