Commit 8e1c37cb by huangjy

fix: 实时监测状态问题

parent 212cf08f
......@@ -67,6 +67,8 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
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_FALL_DATA = "device:fall:data:";
......@@ -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_FALL_TEMP_DATA = "device:fall:tempData:";
@Autowired
private PlatElderService platElderService;
......@@ -326,22 +330,12 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
String person = jsonObject.getString("person");
String personState = jsonObject.getString("personState");
if (StringUtils.equals(person,"1")) {
// 在床运动
if (StringUtils.equals(personState,"1")) {
log.info("当前属于在床运动:" + platElderIdDTO.getElderId());
platElderRealTimeNowVO.setStatus(PlatElderRealtimeReportEnum.NowStatus.SPORT.getValue());
return platElderRealTimeNowVO;
}
// 在床静息
if (StringUtils.equals(personState,"2") || StringUtils.equals(personState,"3")) {
log.info("当前属于在床静息:" + platElderIdDTO.getElderId());
platElderRealTimeNowVO.setStatus(PlatElderRealtimeReportEnum.NowStatus.BED.getValue());
return platElderRealTimeNowVO;
}
// 判断是否在床睡觉
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"));
......@@ -354,6 +348,19 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
return platElderRealTimeNowVO;
}
}
// 在床运动
if (StringUtils.equals(personState,"1")) {
log.info("当前属于在床运动:" + platElderIdDTO.getElderId());
platElderRealTimeNowVO.setStatus(PlatElderRealtimeReportEnum.NowStatus.SPORT.getValue());
return platElderRealTimeNowVO;
}
// 在床静息
if (StringUtils.equals(personState,"2") || StringUtils.equals(personState,"3")) {
log.info("当前属于在床静息:" + platElderIdDTO.getElderId());
platElderRealTimeNowVO.setStatus(PlatElderRealtimeReportEnum.NowStatus.BED.getValue());
return platElderRealTimeNowVO;
}
}
}
List<PlatDevice> spaceDeviceList = getSpaceDevice(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
List<PlatDevice> fallDeviceList = getFallDevice(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
......@@ -405,7 +412,7 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
}
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()) {
continue;
}
......@@ -455,6 +462,22 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
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() {
Integer sleepTimeActionThreshold;
String result = redisTemplate.opsForValue().get(SLEEP_ANALYSIS_THRESHOLD_KEY);
......
......@@ -118,8 +118,8 @@ public class PushCallback implements MqttCallback {
// 缓存呼吸设备某段时间的数据,hash 最大长度 duration
Long duration = getSleepTimeActionDuration();
Long size = redisTemplate.opsForHash().size(DEVICE_BR_ANALYSIS + device.getDeviceId());
if (size.equals(duration)) {
redisTemplate.opsForHash().delete(DEVICE_BR_ANALYSIS + device.getDeviceId(),timestamp - duration);
if (size.equals(duration * 60)) {
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.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