From 57ce50108ffe8d85f9508529dbffea0c064c44a2 Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期四, 26 十月 2023 14:50:14 +0800
Subject: [PATCH] 四川省网关接口相关8

---
 src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java |   40 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java b/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java
index e7a1784..fd196ab 100644
--- a/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java
+++ b/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java
@@ -4,20 +4,24 @@
 import com.bstek.dorado.annotation.DataResolver;
 import com.bstek.dorado.annotation.Expose;
 import com.fzzy.api.utils.ContextUtil;
+import com.fzzy.api.utils.RedisConst;
+import com.fzzy.api.utils.RedisUtil;
+import com.fzzy.gateway.GatewayUtils;
 import com.fzzy.gateway.entity.GatewayDevice;
 import com.fzzy.gateway.service.repository.GatewayDeviceRep;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Component
 public class GatewayDeviceService {
 
     @Resource
     private GatewayDeviceRep gatewayDeviceRep;
-
 
     /**
      * gatewayDeviceService#listAll
@@ -26,10 +30,7 @@
      */
     @DataProvider
     public List<GatewayDevice> listAll() {
-
-        List<GatewayDevice> list = gatewayDeviceRep.findAll();
-
-        return list;
+        return gatewayDeviceRep.findAll();
     }
 
     /**
@@ -45,7 +46,19 @@
         if (null == data.getId()) {
             data.setId(ContextUtil.getUUID());
         }
+
+
+        if (null == data.getDeviceSn()) {
+            if (null != entity.getIp()) {
+                data.setDeviceSn(entity.getIp());
+            } else {
+                data.setDeviceSn(data.getDeviceId());
+            }
+        }
+
         gatewayDeviceRep.save(data);
+
+        flushCache();
     }
 
     /**
@@ -58,6 +71,23 @@
         GatewayDevice data2 = new GatewayDevice();
         BeanUtils.copyProperties(data, data2);
         gatewayDeviceRep.delete(data2);
+
+        GatewayUtils.removeCache(data2);
+
+        flushCache();
         return null;
     }
+
+
+    /**
+     * gatewayDeviceService#flushCache
+     */
+    @Expose
+    public void flushCache() {
+        List<GatewayDevice> list = listAll();
+        if (null == list || list.isEmpty()) return;
+        for (GatewayDevice device : list) {
+            GatewayUtils.add2Cache(device);
+        }
+    }
 }

--
Gitblit v1.9.3