Commit b45d6e38 by huangjy

fix: 状态bug

parent c65440f9
...@@ -123,12 +123,14 @@ public class PushCallback implements MqttCallback { ...@@ -123,12 +123,14 @@ public class PushCallback implements MqttCallback {
if (REPORT_PROPERTY.equals(device.getMessageType()) && headers.getProductName().contains("呼吸")) { if (REPORT_PROPERTY.equals(device.getMessageType()) && headers.getProductName().contains("呼吸")) {
// 缓存呼吸设备某段时间的数据,hash 最大长度 duration // 缓存呼吸设备某段时间的数据,hash 最大长度 duration
long duration = getSleepTimeActionDuration(); long duration = getSleepTimeActionDuration();
Long size = redisTemplate.opsForHash().size(DEVICE_BR_ANALYSIS + device.getDeviceId()); long size = redisTemplate.opsForHash().size(DEVICE_BR_ANALYSIS + device.getDeviceId());
redisTemplate.opsForHash().put(DEVICE_BR_ANALYSIS + device.getDeviceId(), currentSecond,JSON.toJSONString(device.getProperties())); redisTemplate.opsForHash().put(DEVICE_BR_ANALYSIS + device.getDeviceId(), currentSecond,JSON.toJSONString(device.getProperties()));
redisTemplate.expire(DEVICE_BR_ANALYSIS + device.getDeviceId(),duration + 3,TimeUnit.MINUTES); redisTemplate.expire(DEVICE_BR_ANALYSIS + device.getDeviceId(),duration + 3,TimeUnit.MINUTES);
if (size >= duration) { if (size == duration) {
redisTemplate.opsForHash().delete(DEVICE_BR_ANALYSIS + device.getDeviceId(),currentSecond - duration); redisTemplate.opsForHash().delete(DEVICE_BR_ANALYSIS + device.getDeviceId(),currentSecond - duration);
}else if (size > duration) {
redisTemplate.delete(Objects.requireNonNull(redisTemplate.keys(DEVICE_BR_ANALYSIS + device.getDeviceId())));
} }
redisTemplate.opsForValue().set(DEVICE_BR_DATA + device.getDeviceId(),JSON.toJSONString(device.getProperties()), redisTemplate.opsForValue().set(DEVICE_BR_DATA + device.getDeviceId(),JSON.toJSONString(device.getProperties()),
5000, TimeUnit.MILLISECONDS); 5000, TimeUnit.MILLISECONDS);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment