You've already forked FrameTour-BE
1、清理功能修复;2、device在线状态放redis;3、viid传入时重查redis缓存,避免关闭的设备传入素材
This commit is contained in:
@@ -19,6 +19,7 @@ public class DeviceRepository {
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
public static final String DEVICE_ONLINE_CACHE_KEY = "device:online_status:%s";
|
||||
public static final String DEVICE_CACHE_KEY = "device:%s";
|
||||
public static final String DEVICE_CONFIG_CACHE_KEY = "device:%s:config";
|
||||
|
||||
@@ -29,9 +30,6 @@ public class DeviceRepository {
|
||||
DeviceEntity device = deviceMapper.getByDeviceId(deviceId);
|
||||
if (null != device) {
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceId), JSONObject.toJSONString(device));
|
||||
if (!Integer.valueOf(1).equals(device.getStatus())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return device;
|
||||
}
|
||||
@@ -46,9 +44,7 @@ public class DeviceRepository {
|
||||
}
|
||||
if (null != device) {
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), JSONObject.toJSONString(device));
|
||||
if (!Integer.valueOf(1).equals(device.getStatus())) {
|
||||
return null;
|
||||
}
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JSONObject.toJSONString(device));
|
||||
} else {
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, deviceNo), "null", 60L, TimeUnit.SECONDS);
|
||||
}
|
||||
@@ -112,10 +108,20 @@ public class DeviceRepository {
|
||||
}
|
||||
device.setOnline(online);
|
||||
device.setKeepaliveAt(keepaliveAt);
|
||||
deviceMapper.updateOnlineStatus(deviceId, ipAddr, online, keepaliveAt);
|
||||
device.setIpAddr(ipAddr);
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId), JSONObject.toJSONString(device), 60L, TimeUnit.SECONDS);
|
||||
// deviceMapper.updateOnlineStatus(deviceId, ipAddr, online, keepaliveAt);
|
||||
updateDeviceCache(device);
|
||||
}
|
||||
|
||||
public DeviceEntity getOnlineStatus(Long deviceId) {
|
||||
if (redisTemplate.hasKey(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId))) {
|
||||
return JSONObject.parseObject(redisTemplate.opsForValue().get(String.format(DEVICE_ONLINE_CACHE_KEY, deviceId)), DeviceEntity.class);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDeviceCache(DeviceEntity device) {
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getId()), JSONObject.toJSONString(device));
|
||||
redisTemplate.opsForValue().set(String.format(DEVICE_CACHE_KEY, device.getNo()), JSONObject.toJSONString(device));
|
||||
|
Reference in New Issue
Block a user