設備初始化時增加redis緩存

This commit is contained in:
wulin 2023-09-22 09:42:36 +08:00
parent 6f1a085a76
commit b754f49c52
9 changed files with 774 additions and 8467 deletions

View File

@ -5,6 +5,16 @@ package com.qiuguo.iot.base.constans;
* **/
public class RedisConstans {
public static Long ONE_DAY = 86400l;
public static Long ONE_HOUR = 3600l;
public static Long ONE_MINUTE = 60l;
public static Long TEN_SECOND = 10l;
public static Long ONE_WEEK = ONE_DAY * 7;
public static Long ONE_MONTH_30 = ONE_DAY * 30;
public static String DEVICE_INFO = "device::info::";
public static String IOT_TOKEN = "iot_token:";

View File

@ -1,12 +1,12 @@
spring:
cloud:
config:
# 如果本地配置优先级高,那么 override-none 设置为 true包括系统环境变量、本地配置文件等配置
override-none: true
# 如果想要远程配置优先级高,那么 allow-override 设置为 false如果想要本地配置优先级高那么 allow-override 设置为 true
allow-override: true
# 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
override-system-properties: false
# config:
# # 如果本地配置优先级高,那么 override-none 设置为 true包括系统环境变量、本地配置文件等配置
# override-none: true
# # 如果想要远程配置优先级高,那么 allow-override 设置为 false如果想要本地配置优先级高那么 allow-override 设置为 true
# allow-override: true
# # 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
# override-system-properties: false
nacos:
discovery:
# 服务注册地址

View File

@ -2,6 +2,8 @@ package com.qiuguo.iot.user.api.controller.device;
import cn.hutool.crypto.digest.MD5;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qiuguo.iot.base.constans.RedisConstans;
import com.qiuguo.iot.base.enums.DeviceTypeEnum;
import com.qiuguo.iot.base.utils.StringUtils;
import com.qiuguo.iot.data.entity.device.DeviceInfoEntity;
@ -14,6 +16,8 @@ import lombok.extern.slf4j.Slf4j;
import org.hswebframework.web.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.data.redis.core.ReactiveValueOperations;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
@ -38,6 +42,9 @@ public class DeviceController {
@Resource
private TuyaDeviceConnector tuyaDeviceConnector;
@Resource
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
@Value("${device.timeout}")
private Long timeOut;//2分钟
@ -93,12 +100,18 @@ public class DeviceController {
}else{
entity.setKey( com.qiuguo.iot.base.utils.StringUtils.getRandomStr(10));//重新生成Key
mono1 = deviceInfoService.updateDeviceInfoById(entity);
}
return mono1.map(m ->{
return entity;
});
}).map(o -> {
DeviceInfoEntity deviceInfoEntity = (DeviceInfoEntity)o;
ReactiveValueOperations<String, String> operations = reactiveStringRedisTemplate.opsForValue();
operations.set(RedisConstans.DEVICE_INFO + deviceInfoEntity.getSn()
, JSONObject.toJSONString(deviceInfoEntity)
, RedisConstans.ONE_HOUR).subscribe();
DeviceInitResp resp = new DeviceInitResp();
resp.setKey(deviceInfoEntity.getKey());
resp.setSn(deviceInfoEntity.getSn());

View File

@ -1,12 +1,12 @@
spring:
cloud:
config:
# 如果本地配置优先级高,那么 override-none 设置为 true包括系统环境变量、本地配置文件等配置
override-none: true
# 如果想要远程配置优先级高,那么 allow-override 设置为 false如果想要本地配置优先级高那么 allow-override 设置为 true
allow-override: true
# 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
override-system-properties: false
# config:
# # 如果本地配置优先级高,那么 override-none 设置为 true包括系统环境变量、本地配置文件等配置
# override-none: true
# # 如果想要远程配置优先级高,那么 allow-override 设置为 false如果想要本地配置优先级高那么 allow-override 设置为 true
# allow-override: true
# # 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
# override-system-properties: false
nacos:
discovery:
# 服务注册地址

View File

@ -67,7 +67,7 @@ public class BoxWebSocketHandler implements WebSocketHandler {
request.setSn(sn);
return deviceInfoService.selectDeviceInfoByRequest(request).defaultIfEmpty(new DeviceInfoEntity()).map(dv -> {
if(dv.getId() != null){
operations.set(RedisConstans.DEVICE_INFO + dv.getSn(), JSONObject.toJSONString(dv)).subscribe();//直接提交订阅
operations.set(RedisConstans.DEVICE_INFO + dv.getSn(), JSONObject.toJSONString(dv), RedisConstans.ONE_HOUR).subscribe();//直接提交订阅
}
return dv;

View File

@ -1,12 +1,12 @@
spring:
cloud:
config:
# 如果本地配置优先级高,那么 override-none 设置为 true包括系统环境变量、本地配置文件等配置
override-none: true
# 如果想要远程配置优先级高,那么 allow-override 设置为 false如果想要本地配置优先级高那么 allow-override 设置为 true
allow-override: true
# 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
override-system-properties: false
# config:
# # 如果本地配置优先级高,那么 override-none 设置为 true包括系统环境变量、本地配置文件等配置
# override-none: true
# # 如果想要远程配置优先级高,那么 allow-override 设置为 false如果想要本地配置优先级高那么 allow-override 设置为 true
# allow-override: true
# # 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
# override-system-properties: false
nacos:
discovery:
# 服务注册地址

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff