Commit 85f584d0 by huangjy

fix:呼吸心率接口

parent a8424457
...@@ -83,9 +83,20 @@ public class IotCommonService { ...@@ -83,9 +83,20 @@ public class IotCommonService {
* ] * ]
* @return * @return
*/ */
public static IotQueryParam buildQueryParam(int pageSize) { public static IotQueryParam buildQueryParam(int pageIndex,int pageSize) {
IotQueryParam iotQueryParam = new IotQueryParam(); IotQueryParam iotQueryParam = new IotQueryParam();
iotQueryParam.setPageIndex(0); iotQueryParam.setPageIndex(pageIndex);
iotQueryParam.setPageSize(pageSize);
iotQueryParam.setSorts(buildSort("timestamp"));
iotQueryParam.setTerms(Lists.newArrayList());
return iotQueryParam;
}
public static IotQueryParam buildQueryParamByPageIndex(int pageIndex,int pageSize) {
IotQueryParam iotQueryParam = new IotQueryParam();
iotQueryParam.setPageIndex(pageIndex);
iotQueryParam.setPageSize(pageSize); iotQueryParam.setPageSize(pageSize);
iotQueryParam.setSorts(buildSort("timestamp")); iotQueryParam.setSorts(buildSort("timestamp"));
......
package com.makeit.module.iot.service; package com.makeit.module.iot.service;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
...@@ -20,14 +22,13 @@ import com.makeit.utils.data.convert.StreamUtil; ...@@ -20,14 +22,13 @@ import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.old.StringUtils; import com.makeit.utils.old.StringUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.time.Duration; import java.time.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* iot产品设备相关接口 * iot产品设备相关接口
...@@ -40,6 +41,7 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -40,6 +41,7 @@ public class IotProductDeviceService extends IotCommonService {
public static final String REPORT_PROPERTY = "reportProperty"; public static final String REPORT_PROPERTY = "reportProperty";
private static final DateTimeFormatter DEFAULT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
/** /**
* 获取设备信息 * 获取设备信息
*/ */
...@@ -47,7 +49,7 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -47,7 +49,7 @@ public class IotProductDeviceService extends IotCommonService {
String url = iotUrl + DEVICE_PREFIX_URL + "_query"; String url = iotUrl + DEVICE_PREFIX_URL + "_query";
// 条件可以自己改 // 条件可以自己改
IotQueryParam iotQueryParam = buildQueryParam(10); IotQueryParam iotQueryParam = buildQueryParam(0,10);
String body = JsonUtil.toJson(iotQueryParam); String body = JsonUtil.toJson(iotQueryParam);
...@@ -129,14 +131,68 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -129,14 +131,68 @@ public class IotProductDeviceService extends IotCommonService {
} }
public List<String> getLastDayHourRange(LocalDateTime startDateTime) {
int count = 24;
List<String> list = Lists.newArrayList();
String startTime;
String endTime;
for (int i = count; i > 0; i--) {
startTime = DateUtil.format(startDateTime.minusHours(i), DatePattern.NORM_DATETIME_PATTERN);
endTime = DateUtil.format(startDateTime.minusHours(i - 1), DatePattern.NORM_DATETIME_PATTERN);
list.add(startTime + "~" + endTime);
}
return list;
}
public List<DeviceInfoContentBreathe> getDeviceLogByTimeRangeBreathe(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) { public List<DeviceInfoContentBreathe> getDeviceLogByTimeRangeBreathe(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); List<String> lastDayHourRange = getLastDayHourRange(startTime);
for (String hour : lastDayHourRange) {
String[] hourRangeArray = hour.split("~");
List<DeviceOperationLogEntity> deviceOperationLogEntities = getDeviceLogByTimeRange(deviceId, REPORT_PROPERTY, 5000, hourRangeArray[0], hourRangeArray[1]);
List<DeviceInfoContentBreathe> deviceInfoContentBreatheList = StreamUtil.map(deviceOperationLogEntities, e -> JsonUtil.toObj((String) e.getContent(), DeviceInfoContentBreathe.class));
}
long minute = 1440;
List<DeviceInfoContentBreathe> breatheList = Lists.newArrayList();
DeviceInfoContentBreathe deviceInfoContentBreathe;
for (long i = 1; i <= minute; i++) {
int brRandomLong = RandomUtils.nextInt(11,28);
int hrRandomLong = RandomUtils.nextInt(55,125);
int movebodyRandomLong = RandomUtils.nextInt(40,90);
deviceInfoContentBreathe = new DeviceInfoContentBreathe();
LocalDateTime localDateTime = startTime.plusMinutes(i);
long timeStamp = localDateTime.toEpochSecond(ZoneOffset.ofHours(8));
deviceInfoContentBreathe.setTimestamp(timeStamp);
DeviceInfoContentBreathe.Properties properties = new DeviceInfoContentBreathe.Properties();
properties.setBr(brRandomLong);
properties.setHr(hrRandomLong);
properties.setBodymove(movebodyRandomLong);
deviceInfoContentBreathe.setProperties(properties);
breatheList.add(deviceInfoContentBreathe);
}
/*
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
List<DeviceOperationLogEntity> deviceOperationLogEntityList = getDeviceLogByTimeRange(deviceId, REPORT_PROPERTY, pageSize, dateTimeFormatter.format(startTime), dateTimeFormatter.format(endTime)); List<DeviceOperationLogEntity> deviceOperationLogEntityList = getDeviceLogByTimeRange(deviceId, REPORT_PROPERTY, pageSize, dateTimeFormatter.format(startTime), dateTimeFormatter.format(endTime));
List<DeviceInfoContentBreathe> deviceInfoContentBreatheList = StreamUtil.map(deviceOperationLogEntityList, e -> JsonUtil.toObj((String) e.getContent(), DeviceInfoContentBreathe.class)); List<DeviceInfoContentBreathe> deviceInfoContentBreatheList = deviceOperationLogEntityList.stream()
.filter(deviceOperationLogEntity -> deviceOperationLogEntity.getType().contains(REPORT_PROPERTY))
.map(deviceOperationLogEntity -> {
DeviceInfoContentBreathe deviceInfoContentBreathe = JsonUtil.toObj((String) deviceOperationLogEntity.getContent(), DeviceInfoContentBreathe.class);
deviceInfoContentBreathe.setReportTime(formatLongTime(deviceInfoContentBreathe.getTimestamp()));
return deviceInfoContentBreathe;
})
.collect(Collectors.toList());
Map<String, List<DeviceInfoContentBreathe>> minuteMap = StreamUtil.groupBy(deviceInfoContentBreatheList, DeviceInfoContentBreathe::getReportTime);
for (Map.Entry<String, List<DeviceInfoContentBreathe>> entry : minuteMap.entrySet()) {
}*/
return breatheList;
}
return deviceInfoContentBreatheList; public static String formatLongTime(long time) {
return DEFAULT_FORMATTER.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()));
} }
public List<DeviceInfoContentSpace> getDeviceLogByTimeRangeSpace(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) { public List<DeviceInfoContentSpace> getDeviceLogByTimeRangeSpace(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) {
...@@ -217,7 +273,7 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -217,7 +273,7 @@ public class IotProductDeviceService extends IotCommonService {
* @return * @return
*/ */
public List<DeviceOperationLogEntity> getDeviceLogByTimeRange(String deviceId, String typeValue, int pageSize, String startTime, String endTime) { public List<DeviceOperationLogEntity> getDeviceLogByTimeRange(String deviceId, String typeValue, int pageSize, String startTime, String endTime) {
IotQueryParam iotQueryParam = buildQueryParam(pageSize); IotQueryParam iotQueryParam = buildQueryParam(0,pageSize);
List<Term> terms = Lists.newArrayList(); List<Term> terms = Lists.newArrayList();
Term term1 = Term.builder() Term term1 = Term.builder()
...@@ -283,7 +339,7 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -283,7 +339,7 @@ public class IotProductDeviceService extends IotCommonService {
*/ */
public List<DeviceOperationLogEntity> getDeviceLog(String deviceId, int pageSize, String typeValue) { public List<DeviceOperationLogEntity> getDeviceLog(String deviceId, int pageSize, String typeValue) {
String url = iotUrl + DEVICE_PREFIX_URL + deviceId + "/logs"; String url = iotUrl + DEVICE_PREFIX_URL + deviceId + "/logs";
IotQueryParam iotQueryParam = buildQueryParam(pageSize); IotQueryParam iotQueryParam = buildQueryParam(0,pageSize);
if (StringUtils.isNotEmpty(typeValue)) { if (StringUtils.isNotEmpty(typeValue)) {
List<Term> terms = Lists.newArrayList(); List<Term> terms = Lists.newArrayList();
Term term = Term.builder() Term term = Term.builder()
......
...@@ -7,8 +7,12 @@ public class AnalysisVO { ...@@ -7,8 +7,12 @@ public class AnalysisVO {
private Integer totalHr; private Integer totalHr;
private Integer avgHr; private Integer avgHr;
private Integer maxHr;
private Integer minHr;
private Integer totalBr; private Integer totalBr;
private Integer avgBr; private Integer avgBr;
private Integer maxBr;
private Integer minBr;
private Integer actionCount = 0; // 体动次数 private Integer actionCount = 0; // 体动次数
private Integer turnedCount = 0; // 翻身次数 private Integer turnedCount = 0; // 翻身次数
......
...@@ -5,6 +5,7 @@ import com.makeit.common.response.ApiResponseEntity; ...@@ -5,6 +5,7 @@ import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils; import com.makeit.common.response.ApiResponseUtils;
import com.makeit.global.annotation.AuthIgnore; import com.makeit.global.annotation.AuthIgnore;
import com.makeit.global.aspect.tenant.TenantIdIgnore; import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.elder.PlatElderSleepService;
import com.makeit.task.IotSyncTask; import com.makeit.task.IotSyncTask;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -28,6 +29,8 @@ public class PlatElderSleepController { ...@@ -28,6 +29,8 @@ public class PlatElderSleepController {
@Autowired @Autowired
private IotSyncTask iotSyncTask; private IotSyncTask iotSyncTask;
@Autowired
private PlatElderSleepService platElderSleepService;
@ApiOperation("测试") @ApiOperation("测试")
@PostMapping("test") @PostMapping("test")
...@@ -38,6 +41,15 @@ public class PlatElderSleepController { ...@@ -38,6 +41,15 @@ public class PlatElderSleepController {
return ApiResponseUtils.success(); return ApiResponseUtils.success();
} }
@ApiOperation("测试")
@PostMapping("test1")
@AuthIgnore
@TenantIdIgnore
public ApiResponseEntity<Void> test1() {
platElderSleepService.test1();
return ApiResponseUtils.success();
}
} }
......
...@@ -14,4 +14,6 @@ import com.makeit.entity.platform.elder.PlatElderSleep; ...@@ -14,4 +14,6 @@ import com.makeit.entity.platform.elder.PlatElderSleep;
public interface PlatElderSleepService extends IService<PlatElderSleep> { public interface PlatElderSleepService extends IService<PlatElderSleep> {
void elderSleepSleepAnalysisTask(); void elderSleepSleepAnalysisTask();
void test1();
} }
...@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.makeit.common.entity.BaseEntity; import com.makeit.common.entity.BaseEntity;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.*; import com.makeit.entity.platform.elder.*;
import com.makeit.entity.platform.space.PlatRoomBedDevice; import com.makeit.entity.platform.space.PlatRoomBedDevice;
import com.makeit.entity.saas.analysis.*; import com.makeit.entity.saas.analysis.*;
...@@ -20,6 +21,7 @@ import com.makeit.module.iot.service.IotProductDeviceService; ...@@ -20,6 +21,7 @@ import com.makeit.module.iot.service.IotProductDeviceService;
import com.makeit.module.iot.vo.DeviceOperationLogEntity; import com.makeit.module.iot.vo.DeviceOperationLogEntity;
import com.makeit.module.iot.vo.analysis.*; import com.makeit.module.iot.vo.analysis.*;
import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe; import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe;
import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.platform.elder.*; import com.makeit.service.platform.elder.*;
import com.makeit.service.platform.space.PlatRoomBedDeviceService; import com.makeit.service.platform.space.PlatRoomBedDeviceService;
import com.makeit.service.saas.*; import com.makeit.service.saas.*;
...@@ -27,6 +29,7 @@ import com.makeit.utils.data.convert.JsonUtil; ...@@ -27,6 +29,7 @@ import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.data.convert.StreamUtil; import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.vo.platform.elder.report.day.PlatSleepRangeVO; import com.makeit.vo.platform.elder.report.day.PlatSleepRangeVO;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -75,14 +78,20 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -75,14 +78,20 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
@Autowired @Autowired
private PlatElderService platElderService; private PlatElderService platElderService;
@Autowired @Autowired
private PlatDeviceService platDeviceService;
@Autowired
private PlatElderSleepAnalysisService platElderSleepAnalysisService; private PlatElderSleepAnalysisService platElderSleepAnalysisService;
@Autowired @Autowired
private PlatElderBreatheDayStatService platElderBreatheDayStatService;
@Autowired
private PlatElderSleepService platElderSleepService; private PlatElderSleepService platElderSleepService;
@Autowired @Autowired
private PlatElderBreatheAbnormalService platElderBreatheAbnormalService; private PlatElderBreatheAbnormalService platElderBreatheAbnormalService;
@Autowired @Autowired
private PlatElderBreatheAnalysisService platElderBreatheAnalysisService; private PlatElderBreatheAnalysisService platElderBreatheAnalysisService;
@Autowired
private PlatElderReportMonthService platElderReportMonthService;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
...@@ -143,12 +152,16 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -143,12 +152,16 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
if (elder == null) { if (elder == null) {
continue; continue;
} }
PlatDevice platDevice = platDeviceService.getById(platRoomBedDevice.getDeviceId());
if (platDevice == null) {
continue;
}
String tenantId = elder.getTenantId(); String tenantId = elder.getTenantId();
String reportStartTime = ""; /* String reportStartTime = "";
String reportEndTime = ""; String reportEndTime = "";*/
for (String hourRange : dayHourRangeList) { for (String hourRange : dayHourRangeList) {
String[] hourRangeArray = hourRange.split("~"); String[] hourRangeArray = hourRange.split("~");
List<DeviceOperationLogEntity> deviceOperationLogEntities = productDeviceService.getDeviceLogByTimeRange(platRoomBedDevice.getDeviceId(), "reportProperty", 5000, hourRangeArray[0], hourRangeArray[1]); List<DeviceOperationLogEntity> deviceOperationLogEntities = productDeviceService.getDeviceLogByTimeRange(platDevice.getOriDeviceId(), "reportProperty", 5000, hourRangeArray[0], hourRangeArray[1]);
if (CollectionUtils.isEmpty(deviceOperationLogEntities)) { if (CollectionUtils.isEmpty(deviceOperationLogEntities)) {
continue; continue;
} }
...@@ -163,15 +176,14 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -163,15 +176,14 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
Map<String, List<DeviceInfoContentBreathe>> minuteMap = StreamUtil.groupBy(deviceInfoContentBreatheList, DeviceInfoContentBreathe::getReportTime); Map<String, List<DeviceInfoContentBreathe>> minuteMap = StreamUtil.groupBy(deviceInfoContentBreatheList, DeviceInfoContentBreathe::getReportTime);
deviceOperationLogEntities.clear(); deviceOperationLogEntities.clear();
List<DeviceInfoContentBreathe> deviceInfoContentBreathes;
// 统计每小时的体动和翻身 // 统计每小时的体动和翻身
Map<String, AnalysisVO> statisticsMap = Maps.newHashMap(); Map<String, AnalysisVO> statisticsMap = Maps.newHashMap();
List<DeviceInfoContentBreathe> deviceInfoContentBreathes;
for (Map.Entry<String, List<DeviceInfoContentBreathe>> entry : minuteMap.entrySet()) { for (Map.Entry<String, List<DeviceInfoContentBreathe>> entry : minuteMap.entrySet()) {
if (StringUtils.isEmpty(reportStartTime)) { /* if (StringUtils.isEmpty(reportStartTime)) {
reportStartTime = entry.getKey(); reportStartTime = entry.getKey();
} }
reportEndTime = entry.getKey(); reportEndTime = entry.getKey();*/
deviceInfoContentBreathes = entry.getValue(); deviceInfoContentBreathes = entry.getValue();
DeviceInfoContentBreathe.Properties breatheProperties; DeviceInfoContentBreathe.Properties breatheProperties;
...@@ -179,6 +191,11 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -179,6 +191,11 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
// 记录总呼吸率和总心率 // 记录总呼吸率和总心率
int totalBr = 0; int totalBr = 0;
int maxBr = 0;
int minBr = 0;
int maxHr = 0;
int minHr = 0;
int totalHr = 0; int totalHr = 0;
// 呼吸暂停 // 呼吸暂停
...@@ -329,6 +346,20 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -329,6 +346,20 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
hrSlowSecond = 0; hrSlowSecond = 0;
} }
if (br > maxBr) {
maxBr = br;
}
if (br < minBr) {
minBr = br;
}
if (hr > maxHr) {
maxHr = hr;
}
if (hr < minHr) {
minHr = hr;
}
totalBr += br; totalBr += br;
totalHr += hr; totalHr += hr;
} }
...@@ -359,8 +390,13 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -359,8 +390,13 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
analysisVO.setTotalBr(totalBr); analysisVO.setTotalBr(totalBr);
analysisVO.setAvgBr(totalBr / 60); analysisVO.setAvgBr(totalBr / 60);
analysisVO.setMaxBr(maxBr);
analysisVO.setMinBr(minBr);
analysisVO.setTotalHr(totalHr); analysisVO.setTotalHr(totalHr);
analysisVO.setAvgHr(totalHr / 60); analysisVO.setAvgHr(totalHr / 60);
analysisVO.setMaxHr(maxHr);
analysisVO.setMinHr(minHr);
analysisVO.setActionCount(bodymoveCount); analysisVO.setActionCount(bodymoveCount);
...@@ -464,10 +500,10 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -464,10 +500,10 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
int timeHourRange = 24; int timeHourRange = 24;
if (StringUtils.isNotEmpty(reportStartTime) && StringUtils.isNotEmpty(reportEndTime)) { /* if (StringUtils.isNotEmpty(reportStartTime) && StringUtils.isNotEmpty(reportEndTime)) {
Long durationRange = getDurationRange(reportStartTime, reportEndTime); Long durationRange = getDurationRange(reportStartTime, reportEndTime);
timeHourRange = (int) (durationRange / 60); timeHourRange = (int) (durationRange / 60);
} }*/
// 判断是否满足配置的呼吸心率异常类型 // 判断是否满足配置的呼吸心率异常类型
BigDecimal dayBrStopRate = brStopCount == 0 ? BigDecimal.ZERO : new BigDecimal(timeHourRange).divide(new BigDecimal(brStopCount), 2, RoundingMode.HALF_UP); BigDecimal dayBrStopRate = brStopCount == 0 ? BigDecimal.ZERO : new BigDecimal(timeHourRange).divide(new BigDecimal(brStopCount), 2, RoundingMode.HALF_UP);
...@@ -559,9 +595,10 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -559,9 +595,10 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
platElderBreatheAnalysis.setHappenDate(currentDate); platElderBreatheAnalysis.setHappenDate(currentDate);
platElderBreatheAnalysis.setTenantId(tenantId); platElderBreatheAnalysis.setTenantId(tenantId);
platElderBreatheAnalysis.setBreatheEvaluate(diseaseReport == null ? "" : diseaseReport.getEvaluate()); platElderBreatheAnalysis.setBreatheEvaluate(diseaseReport == null ? "" : diseaseReport.getEvaluate());
platElderBreatheAnalysisService.save(platElderBreatheAnalysis); //platElderBreatheAnalysisService.save(platElderBreatheAnalysis);
// 记录长者呼吸心率的异常事件 // 记录长者呼吸心率的异常事件
List<PlatElderBreatheAbnormal> platElderBreatheAbnormalList = Lists.newArrayList();
PlatElderBreatheAbnormal platElderBreatheAbnormal; PlatElderBreatheAbnormal platElderBreatheAbnormal;
for (BreatheAbnormalVO breatheAbnormalVO : breatheAbnormalVOList) { for (BreatheAbnormalVO breatheAbnormalVO : breatheAbnormalVOList) {
platElderBreatheAbnormal = new PlatElderBreatheAbnormal(); platElderBreatheAbnormal = new PlatElderBreatheAbnormal();
...@@ -571,9 +608,9 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -571,9 +608,9 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
platElderBreatheAbnormal.setHappenTime(breatheAbnormalVO.getHappenTime()); platElderBreatheAbnormal.setHappenTime(breatheAbnormalVO.getHappenTime());
platElderBreatheAbnormal.setValue(breatheAbnormalVO.getValue()); platElderBreatheAbnormal.setValue(breatheAbnormalVO.getValue());
platElderBreatheAbnormal.setTenantId(tenantId); platElderBreatheAbnormal.setTenantId(tenantId);
platElderBreatheAbnormalService.save(platElderBreatheAbnormal); platElderBreatheAbnormalList.add(platElderBreatheAbnormal);
} }
// platElderBreatheAbnormalService.saveBatch(platElderBreatheAbnormalList);
int totalActionCount = 0; int totalActionCount = 0;
...@@ -585,10 +622,9 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -585,10 +622,9 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
// 判断睡觉时间 // 判断睡觉时间
String startSleepTime = null; // 入睡时间开始 String startSleepTime = null; // 入睡时间开始
int sleepMinute = 0; int sleepMinute = 0;
int currentSleepTimeDuration = 0;
for (Map.Entry<String, AnalysisVO> entry : totalMap.entrySet()) { for (Map.Entry<String, AnalysisVO> entry : totalMap.entrySet()) {
AnalysisVO analysisVO = entry.getValue(); AnalysisVO analysisVO = entry.getValue();
if (!analysisVO.getIsAction()) { if (!analysisVO.getIsAction()) {
if (StringUtils.isEmpty(startSleepTime)) { if (StringUtils.isEmpty(startSleepTime)) {
startSleepTime = entry.getKey(); startSleepTime = entry.getKey();
...@@ -610,6 +646,25 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -610,6 +646,25 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
sleepMinute = 0; sleepMinute = 0;
} }
TreeMap<String, TreeMap<String, AnalysisVO>> sleepTypeMap = new TreeMap<>();
for (SleepTimeAnalysisVO timeAnalysisVO : sleepTimeAnalysisVOList) {
boolean startTimeFlag = false;
TreeMap<String, AnalysisVO> sleepTotalMap = new TreeMap<>();
for (Map.Entry<String, AnalysisVO> entry : totalMap.entrySet()) {
if (entry.getKey().equals(timeAnalysisVO.getStartTime())) {
startTimeFlag = true;
sleepTotalMap.put(entry.getKey(),entry.getValue());
}
if (entry.getKey().equals(timeAnalysisVO.getEndTime())) {
sleepTotalMap.put(entry.getKey(),entry.getValue());
startTimeFlag = false;
}
if (startTimeFlag) {
sleepTotalMap.put(entry.getKey(),entry.getValue());
}
sleepTypeMap.put(timeAnalysisVO.getType(),sleepTotalMap);
}
}
// 判断起床时间 // 判断起床时间
String startGetupTime = null; // 起床时间开始 String startGetupTime = null; // 起床时间开始
...@@ -666,8 +721,10 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -666,8 +721,10 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
int sleepDeepMinute = 0; int sleepDeepMinute = 0;
String startSleepDeepTime = null; // 入睡时间开始 String startSleepDeepTime = null; // 入睡时间开始
// 判断深度睡眠时间 // 判断深度睡眠时间
for (Map.Entry<String, AnalysisVO> entry : totalMap.entrySet()) { for (Map.Entry<String, TreeMap<String, AnalysisVO>> entry : sleepTypeMap.entrySet()) {
AnalysisVO analysisVO = entry.getValue(); TreeMap<String, AnalysisVO> sleepMap = entry.getValue();
for (Map.Entry<String, AnalysisVO> voEntry : sleepMap.entrySet()) {
AnalysisVO analysisVO = voEntry.getValue();
totalActionCount += analysisVO.getActionCount(); totalActionCount += analysisVO.getActionCount();
totalTurnedCount += analysisVO.getTurnedCount(); totalTurnedCount += analysisVO.getTurnedCount();
if (analysisVO.getActionCount() == sleepDeepActionThreshold && analysisVO.getTurnedCount() == sleepDeepActionThreshold if (analysisVO.getActionCount() == sleepDeepActionThreshold && analysisVO.getTurnedCount() == sleepDeepActionThreshold
...@@ -692,11 +749,16 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -692,11 +749,16 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
sleepDeepMinute = 0; sleepDeepMinute = 0;
} }
}
// 中度睡眠 // 中度睡眠
int sleepMidMinute = 0; int sleepMidMinute = 0;
String startSleepMidTime = null; // 入睡时间开始 String startSleepMidTime = null; // 入睡时间开始
for (Map.Entry<String, AnalysisVO> entry : totalMap.entrySet()) { for (Map.Entry<String, TreeMap<String, AnalysisVO>> entry : sleepTypeMap.entrySet()) {
AnalysisVO analysisVO = entry.getValue(); TreeMap<String, AnalysisVO> sleepMap = entry.getValue();
for (Map.Entry<String, AnalysisVO> voEntry : sleepMap.entrySet()) {
AnalysisVO analysisVO = voEntry.getValue();
if (analysisVO.getActionCount() < sleepModerateActionThreshold && analysisVO.getTurnedCount() < sleepModerateActionThreshold) { if (analysisVO.getActionCount() < sleepModerateActionThreshold && analysisVO.getTurnedCount() < sleepModerateActionThreshold) {
if (StringUtils.isEmpty(startSleepMidTime)) { if (StringUtils.isEmpty(startSleepMidTime)) {
startSleepMidTime = entry.getKey(); startSleepMidTime = entry.getKey();
...@@ -717,12 +779,15 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -717,12 +779,15 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
startSleepMidTime = null; startSleepMidTime = null;
sleepMidMinute = 0; sleepMidMinute = 0;
} }
}
// 清醒 // 清醒
int awakeMinute = 0; int awakeMinute = 0;
String startAwakeTime = null; // 入睡时间开始 String startAwakeTime = null; // 入睡时间开始
for (Map.Entry<String, AnalysisVO> entry : totalMap.entrySet()) { for (Map.Entry<String, TreeMap<String, AnalysisVO>> entry : sleepTypeMap.entrySet()) {
AnalysisVO analysisVO = entry.getValue(); TreeMap<String, AnalysisVO> sleepMap = entry.getValue();
for (Map.Entry<String, AnalysisVO> voEntry : sleepMap.entrySet()) {
AnalysisVO analysisVO = voEntry.getValue();
if (analysisVO.getAwakeMinuteActionFlag()) { if (analysisVO.getAwakeMinuteActionFlag()) {
if (StringUtils.isEmpty(startAwakeTime)) { if (StringUtils.isEmpty(startAwakeTime)) {
startAwakeTime = entry.getKey(); startAwakeTime = entry.getKey();
...@@ -743,6 +808,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -743,6 +808,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
startAwakeTime = null; startAwakeTime = null;
awakeMinute = 0; awakeMinute = 0;
} }
}
Map<String, List<SleepTimeAnalysisVO>> sleepMap = StreamUtil.groupBy(sleepTimeAnalysisVOList, SleepTimeAnalysisVO::getType); Map<String, List<SleepTimeAnalysisVO>> sleepMap = StreamUtil.groupBy(sleepTimeAnalysisVOList, SleepTimeAnalysisVO::getType);
List<SleepTimeAnalysisVO> sleepList = sleepMap.get(SleepTypeEnum.SLEEP.getCode()); List<SleepTimeAnalysisVO> sleepList = sleepMap.get(SleepTypeEnum.SLEEP.getCode());
...@@ -775,6 +841,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -775,6 +841,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
timeAnalysisVO.setInterval(durationRange); timeAnalysisVO.setInterval(durationRange);
LocalDateTime startDateTime = LocalDateTime.parse(startTime, DEFAULT_FORMATTER); LocalDateTime startDateTime = LocalDateTime.parse(startTime, DEFAULT_FORMATTER);
LocalDateTime endDateTime = LocalDateTime.parse(endTime, DEFAULT_FORMATTER); LocalDateTime endDateTime = LocalDateTime.parse(endTime, DEFAULT_FORMATTER);
boolean lightSleepFlag = true; // 如果不满足下面条件,就默认都是浅睡
for (SleepTimeAnalysisVO otherSleepTime : sleepTimeAnalysisVOList) { for (SleepTimeAnalysisVO otherSleepTime : sleepTimeAnalysisVOList) {
if (otherSleepTime.getType().equals(SleepTypeEnum.SLEEP.getCode()) || otherSleepTime.getType().equals(SleepTypeEnum.GETUP.getCode())) { if (otherSleepTime.getType().equals(SleepTypeEnum.SLEEP.getCode()) || otherSleepTime.getType().equals(SleepTypeEnum.GETUP.getCode())) {
continue; continue;
...@@ -787,17 +854,23 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -787,17 +854,23 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
(endDateTime.isAfter(endDeepDateTime) || endDateTime.equals(endDeepDateTime))) { (endDateTime.isAfter(endDeepDateTime) || endDateTime.equals(endDeepDateTime))) {
if (otherSleepTime.getType().equals(SleepTypeEnum.SLEEP_DEEP.getCode())) { if (otherSleepTime.getType().equals(SleepTypeEnum.SLEEP_DEEP.getCode())) {
deepList.add(otherSleepTime); deepList.add(otherSleepTime);
} } else if (otherSleepTime.getType().equals(SleepTypeEnum.SLEEP_MODERATE.getCode())) {
if (otherSleepTime.getType().equals(SleepTypeEnum.SLEEP_MODERATE.getCode())) {
midList.add(otherSleepTime); midList.add(otherSleepTime);
} } else if (timeAnalysisVO.getType().equals(SleepTypeEnum.SOBER.getCode())) {
if (timeAnalysisVO.getType().equals(SleepTypeEnum.SLEEP_LIGHTNESS.getCode())) { soberList.add(otherSleepTime);
} else {
otherSleepTime.setType(SleepTypeEnum.SLEEP_LIGHTNESS.getCode());
lightList.add(otherSleepTime); lightList.add(otherSleepTime);
} }
if (timeAnalysisVO.getType().equals(SleepTypeEnum.SOBER.getCode())) { lightSleepFlag = false;
soberList.add(otherSleepTime);
} }
} }
if (lightSleepFlag) {
SleepTimeAnalysisVO lightSleepTime = new SleepTimeAnalysisVO();
lightSleepTime.setType(SleepTypeEnum.SLEEP_LIGHTNESS.getCode());
lightSleepTime.setStartTime(startTime);
lightSleepTime.setEndTime(endTime);
lightList.add(lightSleepTime);
} }
sleepTimeAnalysis.setDeepList(deepList); sleepTimeAnalysis.setDeepList(deepList);
sleepTimeAnalysis.setInterval(durationRange); sleepTimeAnalysis.setInterval(durationRange);
...@@ -957,7 +1030,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -957,7 +1030,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
elderSleep.setTenantId(tenantId); elderSleep.setTenantId(tenantId);
} }
// TODO 起床时间和入睡时间 // TODO 起床时间和入睡时间
platElderSleepService.saveBatch(elderSleepList); //platElderSleepService.saveBatch(elderSleepList);
EvaluateReportVO elderReport = saasElderReportConfigService.getByScore(totalScore); EvaluateReportVO elderReport = saasElderReportConfigService.getByScore(totalScore);
...@@ -975,7 +1048,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -975,7 +1048,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
elderSleepAnalysis.setSleepResult(sleepReport.getResult()); elderSleepAnalysis.setSleepResult(sleepReport.getResult());
elderSleepAnalysis.setTenantId(tenantId); elderSleepAnalysis.setTenantId(tenantId);
elderSleepAnalysis.setSleepEvaluate(elderReport == null ? "" : elderReport.getEvaluate()); elderSleepAnalysis.setSleepEvaluate(elderReport == null ? "" : elderReport.getEvaluate());
platElderSleepAnalysisService.save(elderSleepAnalysis); // platElderSleepAnalysisService.save(elderSleepAnalysis);
} }
} }
...@@ -1008,4 +1081,126 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -1008,4 +1081,126 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
return list; return list;
} }
public static void main(String[] args) {
int days = 30;
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDateTime localDateTime = LocalDateTime.now().minusDays(28);
for (int i = 0; i < days; i++) {
int i1 = RandomUtils.nextInt(0,4);
System.out.println(i1);
localDateTime = localDateTime.plusDays(1);
String currentDate = localDateTime.format(timeFormatter);
System.out.println(currentDate);
}
}
@Override
public void test1() {
int days = 30;
LocalDateTime localDateTime = LocalDateTime.now().minusDays(28);
List<String> timeRangeList = Lists.newArrayList();
PlatElder elder = platElderService.getById("1704706233484742658");
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
int sleepNumber = 6;
SleepTypeEnum[] values = SleepTypeEnum.values();
for (int i = 0; i < days; i++) {
String lastDate = localDateTime.format(timeFormatter);
localDateTime = localDateTime.plusDays(1);
String currentDate = localDateTime.format(timeFormatter);
PlatElderSleep platElderSleep = new PlatElderSleep();
String sleepStartTime = lastDate + " 22:00";
String sleepEndTime = currentDate + " 08:00";
LocalDateTime startTime = LocalDateTime.parse(sleepStartTime, DEFAULT_FORMATTER);
LocalDateTime endTime = LocalDateTime.parse(sleepEndTime, DEFAULT_FORMATTER);
platElderSleep.setStartSleep(startTime);
platElderSleep.setEndSleep(endTime);
platElderSleep.setElderSleepType(1);
platElderSleep.setElderId(elder.getId());
platElderSleep.setHappenDate(currentDate);
platElderSleep.setTenantId(elder.getTenantId());
List<PlatSleepRangeVO> rangeVOList = Lists.newArrayList();
String start = "";
String end = "";
for (int i1 = 0; i1 < sleepNumber; i1++) {
PlatSleepRangeVO rangeVO = new PlatSleepRangeVO();
int random = RandomUtils.nextInt(0,4);
long randomLong = RandomUtils.nextLong(1,3);
SleepTypeEnum sleepTypeEnum = values[random];
rangeVO.setSleepType(sleepTypeEnum.getCode());
start = startTime.format(DEFAULT_FORMATTER);
LocalDateTime dateTime = startTime.plusHours(randomLong);
end = dateTime.format(DEFAULT_FORMATTER);
rangeVO.setStartTime(start);
rangeVO.setEndTime(end);
startTime = LocalDateTime.parse(end, DEFAULT_FORMATTER);
rangeVOList.add(rangeVO);
}
platElderSleep.setSleepRecord(rangeVOList);
//platElderSleepService.save(platElderSleep);
PlatElderSleepAnalysis elderSleepAnalysis = new PlatElderSleepAnalysis();
elderSleepAnalysis.setElderId(elder.getId());
elderSleepAnalysis.setActionCount(700);
elderSleepAnalysis.setTurnedCount(500);
elderSleepAnalysis.setHappenDate(currentDate);
elderSleepAnalysis.setSleepScore("80");
elderSleepAnalysis.setSleepTime("600");
elderSleepAnalysis.setRestTime("840");
elderSleepAnalysis.setSleepResult("良好");
elderSleepAnalysis.setTenantId(elder.getTenantId());
elderSleepAnalysis.setSleepEvaluate("不错");
//platElderSleepAnalysisService.save(elderSleepAnalysis);
PlatElderBreatheDayStat elderBreatheDayStat = new PlatElderBreatheDayStat();
elderBreatheDayStat.setElderId(elder.getId());
elderBreatheDayStat.setDeviceId("1704705639248334849");
elderBreatheDayStat.setOriDeviceId("218A00XE26691FC");
elderBreatheDayStat.setDay(localDateTime.toLocalDate());
elderBreatheDayStat.setHeartRateMax(72);
elderBreatheDayStat.setHeartRateMax(60);
elderBreatheDayStat.setHeartRateMax(65);
elderBreatheDayStat.setRespiratoryRateAvg(14);
elderBreatheDayStat.setRespiratoryRateMax(18);
elderBreatheDayStat.setRespiratoryRateMin(12);
elderBreatheDayStat.setTenantId(elder.getTenantId());
//platElderBreatheDayStatService.save(elderBreatheDayStat);
PlatElderReportMonth platElderReportMonth = new PlatElderReportMonth();
platElderReportMonth.setElderId(elder.getId());
platElderReportMonth.setDay(localDateTime.toLocalDate());
platElderReportMonth.setTenantId(elder.getTenantId());
platElderReportMonth.setSleepResult("良好");
platElderReportMonth.setRespiratoryExceptionCount(0);
platElderReportMonth.setHeartExceptionCount(0);
platElderReportMonth.setBehaviorExceptionCount(0);
platElderReportMonth.setHeartRate(80);
platElderReportMonth.setRespiratoryRate(20);
platElderReportMonth.setFailCount(0);
platElderReportMonthService.save(platElderReportMonth);
PlatElderBreatheAnalysis platElderBreatheAnalysis = new PlatElderBreatheAnalysis();
platElderBreatheAnalysis.setElderId(elder.getId());
platElderBreatheAnalysis.setAvgBreatheRate("65");
platElderBreatheAnalysis.setAvgHeartRate("14");
platElderBreatheAnalysis.setBreatheScore("60");
platElderBreatheAnalysis.setBreatheResult("良好");
platElderBreatheAnalysis.setHappenDate(currentDate);
platElderBreatheAnalysis.setTenantId(elder.getTenantId());
platElderBreatheAnalysis.setBreatheEvaluate("还不错");
//platElderBreatheAnalysisService.save(platElderBreatheAnalysis);
}
}
} }
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