From 233c0e20548cadafb77efdcb3418f38c6658bbad Mon Sep 17 00:00:00 2001 From: jiazx0107@163.com <jiazx0107@163.com> Date: 星期四, 26 十月 2023 14:20:57 +0800 Subject: [PATCH] 四川省网关接口相关7 --- src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java | 39 ++++++++++++++++----------------------- 1 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java b/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java index 5a738b1..fd196ab 100644 --- a/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java +++ b/src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java @@ -6,22 +6,22 @@ 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; - @Resource - private RedisUtil redisUtil; - /** * gatewayDeviceService#listAll @@ -30,10 +30,7 @@ */ @DataProvider public List<GatewayDevice> listAll() { - - List<GatewayDevice> list = gatewayDeviceRep.findAll(); - - return list; + return gatewayDeviceRep.findAll(); } /** @@ -48,6 +45,15 @@ 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); @@ -66,6 +72,8 @@ BeanUtils.copyProperties(data, data2); gatewayDeviceRep.delete(data2); + GatewayUtils.removeCache(data2); + flushCache(); return null; } @@ -78,23 +86,8 @@ public void flushCache() { List<GatewayDevice> list = listAll(); if (null == list || list.isEmpty()) return; - String key; for (GatewayDevice device : list) { - key = RedisConst.buildKey(RedisConst.KYE_GATE_DEVICE, device.getDeviceId()); - redisUtil.set(key, device); + GatewayUtils.add2Cache(device); } } - - /** - * 缂撳瓨鑾峰彇璁惧淇℃伅 - * - * @param deviceId - * @return - */ - public GatewayDevice getCacheDevice(String deviceId) { - String key = RedisConst.buildKey(RedisConst.KYE_GATE_DEVICE, deviceId); - return (GatewayDevice) redisUtil.get(key); - } - - } -- Gitblit v1.9.3