|
|
@@ -0,0 +1,36 @@
|
|
|
+package com.yunfeiyun.agmp.iot.common.service;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.yunfeiyun.agmp.common.enums.RedisCacheKey;
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
|
|
|
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictEnum;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconn;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconn;
|
|
|
+import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class DeviceconnCacheService {
|
|
|
+ @Resource
|
|
|
+ private RedisTemplate redisTemplate;
|
|
|
+
|
|
|
+ public void setCache(IotDeviceconn iotDeviceconn){
|
|
|
+ redisTemplate.opsForValue().set(getKey(RedisCacheKey.IOT_DEVICE_CONN)+iotDeviceconn.getDevconnBid(),iotDeviceconn);
|
|
|
+ }
|
|
|
+ public void deleteCache(IotDeviceconn iotDeviceconn){
|
|
|
+ redisTemplate.delete(getKey(RedisCacheKey.IOT_DEVICE_CONN)+iotDeviceconn.getDevconnBid());
|
|
|
+ }
|
|
|
+ public IotDeviceconn getIotDeviceConnByDevconnBid(String devconnBid){
|
|
|
+ IotDeviceconn iotDeviceconn = (IotDeviceconn) redisTemplate.opsForValue().get(getKey(RedisCacheKey.IOT_DEVICE_CONN)+devconnBid);
|
|
|
+ if(null == iotDeviceconn){
|
|
|
+ throw new IotBizException(IotErrorCode.INVALID_DEVICE_CONN_BID);
|
|
|
+ }
|
|
|
+ return iotDeviceconn;
|
|
|
+ }
|
|
|
+ private String getKey(RedisCacheKey redisCacheKey){
|
|
|
+ return redisCacheKey.getPrefix() + ":" + redisCacheKey.getModuleType() + ":" + redisCacheKey.getName()+":";
|
|
|
+ }
|
|
|
+}
|