|
|
@@ -8,26 +8,32 @@ import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconn;
|
|
|
import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Set;
|
|
|
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class DeviceconnCacheService {
|
|
|
@Resource
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
public void setCache(IotDeviceconn iotDeviceconn){
|
|
|
+ log.error("【设备连接缓存】保存设备连接信息缓存,设备链接信息标识:{}",iotDeviceconn.getDevconnBid());
|
|
|
redisTemplate.opsForValue().set(getKey(RedisCacheKey.IOT_DEVICE_CONN)+iotDeviceconn.getDevconnBid(),iotDeviceconn);
|
|
|
}
|
|
|
public void deleteCache(IotDeviceconn iotDeviceconn){
|
|
|
+ log.error("【设备连接缓存】删除设备连接信息缓存,设备链接信息标识:{}",iotDeviceconn.getDevconnBid());
|
|
|
redisTemplate.delete(getKey(RedisCacheKey.IOT_DEVICE_CONN)+iotDeviceconn.getDevconnBid());
|
|
|
}
|
|
|
public IotDeviceconn getIotDeviceConnByDevconnBid(String devconnBid){
|
|
|
+ log.error("【设备连接缓存】查询设备连接信息,设备连接标识为:{}",devconnBid);
|
|
|
// 首先查询出当前设备的连接信息
|
|
|
IotDeviceconn iotDeviceconn = (IotDeviceconn) redisTemplate.opsForValue().get(getKey(RedisCacheKey.IOT_DEVICE_CONN)+devconnBid);
|
|
|
if(null == iotDeviceconn){
|
|
|
+ log.error("【设备连接缓存】查询设备连接信息失败,设备连接标识为:{}",devconnBid);
|
|
|
throw new IotBizException(IotErrorCode.INVALID_DEVICE_CONN_BID);
|
|
|
}
|
|
|
return iotDeviceconn;
|
|
|
@@ -41,8 +47,10 @@ public class DeviceconnCacheService {
|
|
|
}
|
|
|
|
|
|
public String getMqttConnectIdByDeviceConnBid(String devconnBid){
|
|
|
+ log.error("【设备连接缓存】查询mqtt链接标识,设备连接标识为:{}",devconnBid);
|
|
|
String connectId = (String) redisTemplate.opsForValue().get(getKey(RedisCacheKey.IOT_DEVICE_CONN_MQTT_ID)+devconnBid);
|
|
|
if(null == connectId){
|
|
|
+ log.error("【设备连接缓存】查询mqtt链接标识失败,设备连接标识为:{}",devconnBid);
|
|
|
throw new IotBizException(IotErrorCode.INVALID_DEVICE_CONN_BID);
|
|
|
}
|
|
|
return connectId;
|