Commit 4d005df2 by 朱淼

工作台老人状态

parent e4b83cf0
package com.makeit.enums.platform.workstation;
import com.makeit.enums.BaseEnum;
import com.makeit.utils.sys.SysDictUtil;
public class WorkStationStatusEnum {
public enum NowStatus implements BaseEnum {
OUT("work.station.now.status.out"),
TURNED("work.station.now.status.turned"),
REST("work.station.now.status.rest"),
SLEEP("work.station.now.status.sleep");
private String code;
NowStatus(String code) {
this.code = code;
}
public String getValue() {
return SysDictUtil.getValue(code);
}
}
}
......@@ -2,6 +2,7 @@ package com.makeit.service.platform.workstation.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.makeit.common.entity.BaseEntity;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.dto.platform.auth.PlatOrgDTO;
......@@ -10,6 +11,7 @@ import com.makeit.dto.platform.space.PlatSpaceVO;
import com.makeit.dto.platform.workstation.WorkStationQueryDTO;
import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.space.PlatBed;
import com.makeit.entity.platform.space.PlatRoom;
......@@ -19,10 +21,16 @@ import com.makeit.entity.saas.analysis.SaasSleepAnalysisModel;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.platform.alarm.PlatAlarmRecordEnum;
import com.makeit.enums.platform.auth.PlatOrgEnum;
import com.makeit.enums.platform.elder.PlatElderRealtimeReportEnum;
import com.makeit.enums.platform.space.PlatBedStatusEnum;
import com.makeit.enums.platform.workstation.WorkStationStatusEnum;
import com.makeit.enums.saas.ModelManageTypeEnum;
import com.makeit.module.iot.enums.DeviceInfoContentBreatheEnum;
import com.makeit.module.iot.service.IotProductDeviceService;
import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.service.platform.auth.PlatOrgService;
import com.makeit.service.platform.elder.PlatElderDayReportDayService;
import com.makeit.service.platform.elder.PlatElderRealTimeService;
import com.makeit.service.platform.elder.PlatElderService;
import com.makeit.service.platform.space.PlatBedService;
......@@ -31,9 +39,12 @@ import com.makeit.service.platform.space.PlatSpaceService;
import com.makeit.service.platform.workstation.WorkStationService;
import com.makeit.service.saas.SaasModelManageService;
import com.makeit.service.saas.SaasSleepAnalysisModelService;
import com.makeit.utils.StandardDeviationUtil;
import com.makeit.utils.data.convert.PageUtil;
import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.data.validate.CollectionUtils;
import com.makeit.utils.sql.join.JoinUtil;
import com.makeit.vo.platform.elder.realtime.PlatElderCoordinateVO;
import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeNowVO;
import com.makeit.vo.platform.space.PlatBedVo;
import com.makeit.vo.platform.workstation.*;
......@@ -41,6 +52,7 @@ import jodd.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
......@@ -72,6 +84,10 @@ public class WorkStationServiceImpl implements WorkStationService {
private SaasModelManageService saasModelManageService;
@Autowired
private SaasSleepAnalysisModelService saasSleepAnalysisModelService;
@Autowired
private PlatElderDayReportDayService platElderDayReportDayService;
@Autowired
private IotProductDeviceService iotProductDeviceService;
@Override
public WorkStationInstitutionStatisticsVO institutionStatistics(WorkStationQueryDTO dto) {
......@@ -218,16 +234,17 @@ public class WorkStationServiceImpl implements WorkStationService {
});
//查询睡眠质量分析模型
// SaasModelManage modelManage = saasModelManageService.getOne(new QueryWrapper<SaasModelManage>().lambda()
// .eq(SaasModelManage::getModelType, ModelManageTypeEnum.SLEEP.getCode());
// Integer turnedComparison = 0;
// if(modelManage != null){
// SaasSleepAnalysisModel model = saasSleepAnalysisModelService.view(modelManage.getModelId());
// if(model != null && model.getTurnedComparison() != null){
// turnedComparison = Integer.valueOf(model.getTurnedComparison());
// }
// }
SaasModelManage modelManage = saasModelManageService.getOne(new QueryWrapper<SaasModelManage>().lambda()
.eq(SaasModelManage::getModelType, ModelManageTypeEnum.SLEEP.getCode()));
Integer turnedThreshold = 0;
if(modelManage != null){
SaasSleepAnalysisModel model = saasSleepAnalysisModelService.view(modelManage.getModelId());
if(model != null && model.getTurnedThreshold() != null){
turnedThreshold = Integer.valueOf(model.getTurnedThreshold());
}
}
LocalDateTime now = LocalDateTime.now();
LocalDateTime start = now.minusSeconds(10);
for (WorkStationInstitutionRoomVO vo : roomVOList) {
vo.setPathName(vo.getPathName() + "-" + vo.getRoomName());
if (bedMap.get(vo.getRoomId()) != null) {
......@@ -239,21 +256,26 @@ public class WorkStationServiceImpl implements WorkStationService {
r.setAlarmTypeMap(elderAlarmTypeMap.get(r.getElderId()));
}
if(StringUtil.isNotEmpty(r.getDeviceId())){
if(StringUtil.isNotEmpty(r.getOriDeviceId())){
PlatElderIdDTO platElderIdDTO = new PlatElderIdDTO();
platElderIdDTO.setElderId(r.getElderId());
platElderIdDTO.setDeviceId(r.getDeviceId());
platElderIdDTO.setDeviceId(r.getOriDeviceId());
PlatElderRealTimeNowVO nowStatus = platElderRealTimeService.nowStatus(platElderIdDTO);
DeviceInfoContentBreathe deviceInfoContentBreathe = getNowDataBreathe(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
//离床:雷达状态上报无人
//翻身:雷达上报的数据符合IOT平台睡眠质量分析模型中配置的翻身规则
//睡眠:雷达上报的数据符合IOT平台睡眠质量分析模型中的入睡时间,状态变更为睡眠
//静息:雷达上报有人,且非睡眠
// if("0".equals(nowStatus.getStatus())){
// r.setElderStatus(nowStatus.getStatus());
// }else if(nowStatus.getBodyMove()!=null && nowStatus.getBodyMove() > turnedComparison){
//
// }
r.setElderStatus(nowStatus.getStatus());
if(DeviceInfoContentBreatheEnum.PersonStateEnum.NOBODY.getValue().equals(nowStatus.getStatus())){
r.setElderStatus(WorkStationStatusEnum.NowStatus.OUT.getValue());
}else if(nowStatus.getBodyMove()!=null && nowStatus.getBodyMove() > turnedThreshold){
r.setElderStatus(WorkStationStatusEnum.NowStatus.TURNED.getValue());
}else {
List<PlatElderCoordinateVO> coordinateList = platElderDayReportDayService.coordinateList(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId(), start, now);
nowStatusRest(r, platElderIdDTO, deviceInfoContentBreathe, coordinateList);
nowStatusSleep(r, platElderIdDTO, deviceInfoContentBreathe);
}
}
}
}
......@@ -264,6 +286,78 @@ public class WorkStationServiceImpl implements WorkStationService {
return PageUtil.toPageVO(pages);
}
private void nowStatusRest(WorkStationInstitutionBedVO vo , PlatElderIdDTO platElderIdDTO, DeviceInfoContentBreathe nowDataBreathe, List<PlatElderCoordinateVO> coordinateList) {
if (nowDataBreathe == null) {
return;
}
boolean flag = DeviceInfoContentBreatheEnum.PersonStateEnum.NOBODY.getValue().equals(nowDataBreathe.getProperties().getPersonState());
if (!flag) {
return;
}
if (CollectionUtils.isNotEmpty(coordinateList)) {
double v = StandardDeviationUtil.average(StreamUtil.map(coordinateList, e -> e.getDistance().doubleValue()));
if (new BigDecimal(v + "").compareTo(new BigDecimal(2)) <= 0) {
vo.setStatus((WorkStationStatusEnum.NowStatus.REST.getValue()));
}
}
}
private void nowStatusSleep(WorkStationInstitutionBedVO vo, PlatElderIdDTO platElderIdDTO, DeviceInfoContentBreathe nowDataBreathe) {
if (nowDataBreathe == null) {
return;
}
boolean flag = !DeviceInfoContentBreatheEnum.PersonStateEnum.NOBODY.getValue().equals(nowDataBreathe.getProperties().getPersonState());
if (!flag) {
return;
}
SaasSleepAnalysisModel analysisModel = saasSleepAnalysisModelService.getOne(new QueryWrapper<SaasSleepAnalysisModel>().lambda()
.orderByDesc(BaseEntity::getCreateBy)
.last("limit 1"));
if (analysisModel == null) {
return;
}
Integer sleepTimeActionDuration = Integer.valueOf(analysisModel.getSleepTimeActionDuration() + "");
Integer sleepTimeActionThreshold = Integer.valueOf(analysisModel.getSleepTimeActionThreshold() + "");
LocalDateTime now = LocalDateTime.now();
LocalDateTime start = now.minusHours(sleepTimeActionDuration);
PlatDevice platDevice = platElderRealTimeService.getBreathDevice(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
List<DeviceInfoContentBreathe> breatheList = iotProductDeviceService.getDeviceLogByTimeRangeBreathe(platDevice.getOriDeviceId(), 2 * 24 * 3600, start, now);
if (CollectionUtils.isNotEmpty(breatheList)) {
if (StreamUtil.allMatch(breatheList, e -> e.getProperties().getBodymove() < sleepTimeActionThreshold)) {
vo.setStatus(WorkStationStatusEnum.NowStatus.SLEEP.getValue());
}
}
}
private DeviceInfoContentBreathe getNowDataBreathe(String elderId, String deviceId) {
PlatDevice platDevice = platElderRealTimeService.getBreathDevice(elderId, deviceId);
if (platDevice == null) {
return null;
}
DeviceInfoContentBreathe deviceInfoContentBreathe = iotProductDeviceService.getLastDeviceLogBreathe(platDevice.getOriDeviceId(), 10);
return deviceInfoContentBreathe;
}
@Override
public Map<String, Map<String,String>> mapElderAlarmType(List<PlatAlarmRecord> alarmRecords) {
Map<String, Map<String,String>> map = new HashMap<>();
......@@ -281,17 +375,6 @@ public class WorkStationServiceImpl implements WorkStationService {
typeMap.put(a.getAlarmType(),a.getRemark());
}
}
// if(typeMap.containsKey(a.getAlarmType())){
// if(StringUtil.isNotEmpty(a.getRemark())){
// String remark = typeMap.get(a.getAlarmType())+","+a.getRemark();
// typeMap.put(a.getAlarmType(),remark);
// }
//
// }else {
// if(StringUtil.isNotEmpty(a.getRemark())){
// typeMap.put(a.getAlarmType(),a.getRemark());
// }
// }
} else {
typeMap.put(a.getAlarmType(),"");
}
......@@ -440,10 +523,10 @@ public class WorkStationServiceImpl implements WorkStationService {
vo.setAlarmTypeMap(elderAlarmTypeMap.get(vo.getElderId()));
}
if(StringUtil.isNotEmpty(vo.getDeviceId())){
if(StringUtil.isNotEmpty(vo.getOriDeviceId())){
PlatElderIdDTO platElderIdDTO = new PlatElderIdDTO();
platElderIdDTO.setElderId(vo.getElderId());
platElderIdDTO.setDeviceId(vo.getDeviceId());
platElderIdDTO.setDeviceId(vo.getOriDeviceId());
PlatElderRealTimeNowVO nowStatus = platElderRealTimeService.nowStatus(platElderIdDTO);
vo.setElderStatus(nowStatus.getStatus());
vo.setHeartRate(nowStatus.getHeartRate());
......
......@@ -53,6 +53,9 @@ public class WorkStationHomeBedVO {
@ApiModelProperty(value = "设备id")
private String deviceId;
@ApiModelProperty(value = "原始设备id")
private String oriDeviceId;
@ApiModelProperty(value = "长者状态")
private String elderStatus;
......
......@@ -38,6 +38,9 @@ public class WorkStationInstitutionBedVO {
@ApiModelProperty(value = "设备id")
private String deviceId;
@ApiModelProperty(value = "设备id")
private String oriDeviceId;
@ApiModelProperty(value = "长者状态")
private String elderStatus;
......
......@@ -50,10 +50,11 @@
</select>
<select id="selectByRoomIds" resultType="com.makeit.vo.platform.workstation.WorkStationInstitutionBedVO">
SELECT pb.`name` as bedName, pb.id as bedId, pb.room_id as roomId , pe.id as elderId, pe.name as elderName, prbd.device_id as deviceId,pb.status
SELECT pb.`name` as bedName, pb.id as bedId, pb.room_id as roomId , pe.id as elderId, pe.name as elderName, prbd.device_id as deviceId,pb.status,pd.ori_device_id as oriDeviceId
FROM plat_bed pb
LEFT JOIN plat_elder pe ON pe.bed_id = pb.id and pe.del_flag = 0
LEFT JOIN plat_room_bed_device prbd ON prbd.bed_id = pb.id and prbd.del_flag = 0
LEFT JOIN plat_device pd ON prbd.device_id = pd.id and pd.del_flag = 0
<where>
pb.del_flag = 0
<if test="roomIds != null and roomIds.size() > 0 ">
......@@ -123,13 +124,14 @@
</select>
<select id="selectByConditionPage" resultType="com.makeit.vo.platform.workstation.WorkStationHomeBedVO">
SELECT pb.`name` as bedName, pb.id as bedId, pb.room_id , pe.id as elderId, pe.name as elderName, prbd.device_id,pm.id as roomId,pm.name as roomName ,pm.space_path,pb.status,pe.avatar,sf.url as avatarPath
SELECT pb.`name` as bedName, pb.id as bedId, pb.room_id , pe.id as elderId, pe.name as elderName, prbd.device_id,pm.id as roomId,pm.name as roomName ,pm.space_path,pb.status,pe.avatar,sf.url as avatarPath,pd.ori_device_id as oriDeviceId
FROM plat_bed pb
LEFT JOIN plat_room pm ON pm.id = pb.room_id
LEFT JOIN plat_space ps ON ps.id = pm.space_id
LEFT JOIN plat_elder pe ON pe.bed_id = pb.id
LEFT JOIN plat_room_bed_device prbd ON prbd.bed_id = pb.id and prbd.del_flag = 0
LEFT JOIN sys_file sf ON sf.id = pe.avatar
LEFT JOIN plat_device pd ON pd.id = prbd.device_id and pd..del_flag = 0
<where>
pb.del_flag = 0 and pb.status = 0
<if test="dto.elderName != null and dto.elderName != ''">
......
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