Commit 098dcc25 by huangjy

fix: 数据保存

parent 78d4dbe3
...@@ -112,16 +112,17 @@ public class PushCallback implements MqttCallback { ...@@ -112,16 +112,17 @@ public class PushCallback implements MqttCallback {
List<HeaderInfo.Bind> bindings = headers.getBindings(); List<HeaderInfo.Bind> bindings = headers.getBindings();
Long timestamp = device.getTimestamp(); Long timestamp = device.getTimestamp();
long currentSecond = timestamp / 1000;
// TODO 先这样判断 // TODO 先这样判断
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(), timestamp,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,TimeUnit.MINUTES); redisTemplate.expire(DEVICE_BR_ANALYSIS + device.getDeviceId(),duration,TimeUnit.MINUTES);
if (size > duration * 60) { if (size > duration * 60) {
redisTemplate.opsForHash().delete(DEVICE_BR_ANALYSIS + device.getDeviceId(),timestamp - duration * 60); redisTemplate.opsForHash().delete(DEVICE_BR_ANALYSIS + device.getDeviceId(),currentSecond - duration * 60);
} }
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);
...@@ -129,22 +130,22 @@ public class PushCallback implements MqttCallback { ...@@ -129,22 +130,22 @@ public class PushCallback implements MqttCallback {
if (REPORT_PROPERTY.equals(device.getMessageType()) && headers.getProductName().contains("空间")) { if (REPORT_PROPERTY.equals(device.getMessageType()) && headers.getProductName().contains("空间")) {
long maxSize = 10L; long maxSize = 10L;
Long size = redisTemplate.opsForHash().size(DEVICE_SPACE_TEMP_DATA + device.getDeviceId()); Long size = redisTemplate.opsForHash().size(DEVICE_SPACE_TEMP_DATA + device.getDeviceId());
redisTemplate.opsForHash().put(DEVICE_SPACE_TEMP_DATA + device.getDeviceId(), timestamp,JSON.toJSONString(device.getProperties())); redisTemplate.opsForHash().put(DEVICE_SPACE_TEMP_DATA + device.getDeviceId(), currentSecond,JSON.toJSONString(device.getProperties()));
redisTemplate.expire(DEVICE_SPACE_TEMP_DATA + device.getDeviceId(),maxSize + 1,TimeUnit.SECONDS); redisTemplate.expire(DEVICE_SPACE_TEMP_DATA + device.getDeviceId(),maxSize + 1,TimeUnit.SECONDS);
if (size > maxSize) { if (size > maxSize) {
redisTemplate.opsForHash().delete(DEVICE_SPACE_TEMP_DATA + device.getDeviceId(),timestamp - maxSize); redisTemplate.opsForHash().delete(DEVICE_SPACE_TEMP_DATA + device.getDeviceId(),currentSecond - maxSize);
} }
redisTemplate.opsForValue().set(DEVICE_SPACE_DATA + device.getDeviceId(),JSON.toJSONString(device.getProperties()), redisTemplate.opsForValue().set(DEVICE_SPACE_DATA + device.getDeviceId(),JSON.toJSONString(device.getProperties()),
5000, TimeUnit.MILLISECONDS); 5000, TimeUnit.MILLISECONDS);
} }
if (REPORT_PROPERTY.equals(device.getMessageType()) && headers.getProductName().contains("跌倒")) { if (REPORT_PROPERTY.equals(device.getMessageType()) && headers.getProductName().contains("跌倒")) {
Long maxSize = 10L; long maxSize = 10L;
Long size = redisTemplate.opsForHash().size(DEVICE_FALL_TEMP_DATA + device.getDeviceId()); Long size = redisTemplate.opsForHash().size(DEVICE_FALL_TEMP_DATA + device.getDeviceId());
redisTemplate.opsForHash().put(DEVICE_FALL_TEMP_DATA + device.getDeviceId(), timestamp,JSON.toJSONString(device.getProperties())); redisTemplate.opsForHash().put(DEVICE_FALL_TEMP_DATA + device.getDeviceId(), currentSecond,JSON.toJSONString(device.getProperties()));
redisTemplate.expire(DEVICE_FALL_TEMP_DATA + device.getDeviceId(),maxSize + 1,TimeUnit.SECONDS); redisTemplate.expire(DEVICE_FALL_TEMP_DATA + device.getDeviceId(),maxSize + 1,TimeUnit.SECONDS);
if (size > maxSize) { if (size > maxSize) {
redisTemplate.opsForHash().delete(DEVICE_FALL_TEMP_DATA + device.getDeviceId(),timestamp - maxSize); redisTemplate.opsForHash().delete(DEVICE_FALL_TEMP_DATA + device.getDeviceId(),currentSecond - maxSize);
} }
redisTemplate.opsForValue().set(DEVICE_FALL_DATA + device.getDeviceId(),JSON.toJSONString(device.getProperties()), redisTemplate.opsForValue().set(DEVICE_FALL_DATA + device.getDeviceId(),JSON.toJSONString(device.getProperties()),
......
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