Commit 8e1c37cb by huangjy

fix: 实时监测状态问题

parent 212cf08f
...@@ -67,6 +67,8 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -67,6 +67,8 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
public static final String DEVICE_BR_DATA = "device:brhr:data:"; public static final String DEVICE_BR_DATA = "device:brhr:data:";
public static final String SLEEP_ANALYSIS_KEY = "saas:sleep:analysis";
public static final String DEVICE_SPACE_DATA = "device:space:data:"; public static final String DEVICE_SPACE_DATA = "device:space:data:";
public static final String DEVICE_FALL_DATA = "device:fall:data:"; public static final String DEVICE_FALL_DATA = "device:fall:data:";
...@@ -76,6 +78,8 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -76,6 +78,8 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
public static final String DEVICE_SPACE_TEMP_DATA = "device:space:tempData:"; public static final String DEVICE_SPACE_TEMP_DATA = "device:space:tempData:";
public static final String DEVICE_FALL_TEMP_DATA = "device:fall:tempData:";
@Autowired @Autowired
private PlatElderService platElderService; private PlatElderService platElderService;
...@@ -326,6 +330,24 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -326,6 +330,24 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
String person = jsonObject.getString("person"); String person = jsonObject.getString("person");
String personState = jsonObject.getString("personState"); String personState = jsonObject.getString("personState");
if (StringUtils.equals(person,"1")) { if (StringUtils.equals(person,"1")) {
// 判断是否在床睡觉
Integer sleepTimeActionThreshold = getSleepTimeActionThreshold();
Long sleepTimeActionDuration = getSleepTimeActionDuration();
Map<Object, Object> entries = redisTemplate.opsForHash().entries(DEVICE_BR_ANALYSIS + platDevice.getOriDeviceId());
Collection<Object> values = entries.values();
if (values.size() >= sleepTimeActionDuration * 60) {
Predicate<Object> predicate = entity -> {
JSONObject result = JSON.parseObject(entity.toString());
Integer bodymove = Integer.valueOf(result.getString("bodymove"));
return bodymove.compareTo(sleepTimeActionThreshold) <= 0;
};
boolean sleepFlag = values.stream().allMatch(predicate);
if (sleepFlag) {
log.info("当前属于在床睡眠:" + platElderIdDTO.getElderId());
platElderRealTimeNowVO.setStatus(PlatElderRealtimeReportEnum.NowStatus.SLEEP.getValue());
return platElderRealTimeNowVO;
}
}
// 在床运动 // 在床运动
if (StringUtils.equals(personState,"1")) { if (StringUtils.equals(personState,"1")) {
log.info("当前属于在床运动:" + platElderIdDTO.getElderId()); log.info("当前属于在床运动:" + platElderIdDTO.getElderId());
...@@ -338,21 +360,6 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -338,21 +360,6 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
platElderRealTimeNowVO.setStatus(PlatElderRealtimeReportEnum.NowStatus.BED.getValue()); platElderRealTimeNowVO.setStatus(PlatElderRealtimeReportEnum.NowStatus.BED.getValue());
return platElderRealTimeNowVO; return platElderRealTimeNowVO;
} }
// 判断是否在床睡觉
Integer sleepTimeActionThreshold = getSleepTimeActionThreshold();
Map<Object, Object> entries = redisTemplate.opsForHash().entries(DEVICE_BR_ANALYSIS + platDevice.getOriDeviceId());
Collection<Object> values = entries.values();
Predicate<Object> predicate = entity -> {
JSONObject result = JSON.parseObject(entity.toString());
Integer bodymove = Integer.valueOf(result.getString("bodymove"));
return bodymove.compareTo(sleepTimeActionThreshold) <= 0;
};
boolean sleepFlag = values.stream().allMatch(predicate);
if (sleepFlag) {
log.info("当前属于在床睡眠:" + platElderIdDTO.getElderId());
platElderRealTimeNowVO.setStatus(PlatElderRealtimeReportEnum.NowStatus.SLEEP.getValue());
return platElderRealTimeNowVO;
}
} }
} }
List<PlatDevice> spaceDeviceList = getSpaceDevice(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId()); List<PlatDevice> spaceDeviceList = getSpaceDevice(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
...@@ -405,7 +412,7 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -405,7 +412,7 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
} }
for (PlatDevice device : fallDeviceList) { for (PlatDevice device : fallDeviceList) {
// 无人 // 无人
Map<Object, Object> entries = redisTemplate.opsForHash().entries(DEVICE_FALL_DATA + device.getOriDeviceId()); Map<Object, Object> entries = redisTemplate.opsForHash().entries(DEVICE_FALL_TEMP_DATA + device.getOriDeviceId());
if (entries.isEmpty()) { if (entries.isEmpty()) {
continue; continue;
} }
...@@ -455,6 +462,22 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -455,6 +462,22 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
return platElderRealTimeNowVO; return platElderRealTimeNowVO;
} }
private Long getSleepTimeActionDuration() {
String sleepTimeActionDuration = "";
String result = redisTemplate.opsForValue().get(SLEEP_ANALYSIS_KEY);
if (result != null) {
sleepTimeActionDuration = result;
} else {
SaasSleepAnalysisModel analysisModel = saasSleepAnalysisModelService.getOne(new QueryWrapper<SaasSleepAnalysisModel>().lambda()
.orderByDesc(BaseEntity::getCreateBy)
.last("limit 1"));
redisTemplate.opsForValue().set(SLEEP_ANALYSIS_KEY,analysisModel.getSleepTimeActionDuration(),1,TimeUnit.DAYS);
sleepTimeActionDuration = analysisModel.getSleepTimeActionDuration();
}
BigDecimal s = new BigDecimal(sleepTimeActionDuration).multiply(new BigDecimal(60));
return s.longValue();
}
private Integer getSleepTimeActionThreshold() { private Integer getSleepTimeActionThreshold() {
Integer sleepTimeActionThreshold; Integer sleepTimeActionThreshold;
String result = redisTemplate.opsForValue().get(SLEEP_ANALYSIS_THRESHOLD_KEY); String result = redisTemplate.opsForValue().get(SLEEP_ANALYSIS_THRESHOLD_KEY);
......
...@@ -118,8 +118,8 @@ public class PushCallback implements MqttCallback { ...@@ -118,8 +118,8 @@ public class PushCallback implements MqttCallback {
// 缓存呼吸设备某段时间的数据,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());
if (size.equals(duration)) { if (size.equals(duration * 60)) {
redisTemplate.opsForHash().delete(DEVICE_BR_ANALYSIS + device.getDeviceId(),timestamp - duration); redisTemplate.opsForHash().delete(DEVICE_BR_ANALYSIS + device.getDeviceId(),timestamp - duration * 60);
} }
redisTemplate.opsForHash().put(DEVICE_BR_ANALYSIS + device.getDeviceId(), timestamp,JSON.toJSONString(device.getProperties())); redisTemplate.opsForHash().put(DEVICE_BR_ANALYSIS + device.getDeviceId(), timestamp,JSON.toJSONString(device.getProperties()));
redisTemplate.expire(DEVICE_BR_ANALYSIS + device.getDeviceId(),duration,TimeUnit.MINUTES); redisTemplate.expire(DEVICE_BR_ANALYSIS + device.getDeviceId(),duration,TimeUnit.MINUTES);
......
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