Commit aa3f63ea by huangjy

Merge remote-tracking branch 'origin/dev' into dev

parents 19fe1429 55e10402
......@@ -8,7 +8,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.makeit.common.entity.BaseEntity;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder;
......@@ -21,8 +20,6 @@ import com.makeit.enums.report.ConditionTypeEnum;
import com.makeit.mapper.platform.elder.PlatElderBreatheAnalysisMapper;
import com.makeit.module.iot.service.IotProductDeviceService;
import com.makeit.module.iot.vo.DeviceOperationLogEntity;
import com.makeit.module.iot.vo.analysis.AnalysisVO;
import com.makeit.module.iot.vo.analysis.BreatheAbnormalVO;
import com.makeit.module.iot.vo.analysis.DiseaseReportVO;
import com.makeit.module.iot.vo.analysis.EvaluateReportVO;
import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe;
......@@ -37,21 +34,22 @@ import com.makeit.service.saas.SaasSleepAnalysisModelService;
import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.time.LocalDateTimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
/**
......@@ -63,6 +61,7 @@ import java.util.stream.Collectors;
* @since 2023-09-15
*/
@Service
@Slf4j
public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBreatheAnalysisMapper, PlatElderBreatheAnalysis> implements PlatElderBreatheAnalysisService {
private static final Logger logger = LoggerFactory.getLogger(PlatElderBreatheAnalysisServiceImpl.class);
......@@ -88,45 +87,15 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
private static final DateTimeFormatter DEFAULT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
@Override
@Transactional(rollbackFor = Exception.class)
public List<PlatElderBreatheAnalysis> elderHeartRespiratoryAnalysisTask(Integer month,Integer day) {
// 12-06,12-18 12-07、 12-12(70分)
LocalDate nowDate = LocalDate.now();
if (month != null && day != null) {
nowDate = LocalDate.of(2023, month, day);
}
LocalDate yesDate = nowDate.minusDays(1);
LocalDateTime yesStart = LocalDateTimeUtils.getDayStart(yesDate);
LocalDateTime yesEnd = LocalDateTimeUtils.getDayEnd(yesDate);
List<PlatElder> elderList = platElderService.list(new QueryWrapper<PlatElder>().lambda()
.isNotNull(PlatElder::getBedId));
List<PlatElderBreatheAnalysis> result = new ArrayList<>();
if (CollectionUtils.isEmpty(elderList)) {
return result;
private LocalDateTime longToTime(Long longTime) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(longTime), ZoneOffset.of("+8"));
}
List<String> elderIdList = StreamUtil.map(elderList, BaseEntity::getId);
List<PlatElderBreatheDayStat> elderBreatheDayStatList = platElderBreatheDayStatService.list(new QueryWrapper<PlatElderBreatheDayStat>().lambda()
.in(PlatElderBreatheDayStat::getElderId, elderIdList)
.eq(PlatElderBreatheDayStat::getDay, yesDate));
Map<String, PlatElderBreatheDayStat> breatheDayStatMap = StreamUtil.toMapDep(elderBreatheDayStatList, PlatElderBreatheDayStat::getElderId);
SaasSleepAnalysisModel analysisModel = saasSleepAnalysisModelService.getOne(new QueryWrapper<SaasSleepAnalysisModel>().lambda()
.orderByDesc(BaseEntity::getCreateBy)
.last("limit 1"));
SaasDiseaseModel saasDiseaseModel = saasDiseaseModelService.getOne(new QueryWrapper<SaasDiseaseModel>().lambda()
.orderByDesc(BaseEntity::getCreateBy)
.last("limit 1"));
Map<String, PlatElderBreatheAnalysis> analysisMap = StreamUtil.toMapDep(platElderBreatheAnalysisService.list(Wrappers.<PlatElderBreatheAnalysis>lambdaQuery()
.in(PlatElderBreatheAnalysis::getElderId, elderIdList)
.eq(PlatElderBreatheAnalysis::getHappenDate, yesDate)), PlatElderBreatheAnalysis::getElderId);
private PlatElderBreatheAnalysis elderHeartAnalysis(PlatElder platElder, Map<String, PlatElderBreatheDayStat> breatheDayStatMap,
LocalDateTime yesStart, SaasSleepAnalysisModel analysisModel,
SaasDiseaseModel saasDiseaseModel,
LocalDate yesDate, Map<String, PlatElderBreatheAnalysis> analysisMap,
SaasDiseaseEvaluateReport saasDiseaseEvaluateReport) {
// 呼吸率
int breatheThresholdMin = Integer.parseInt(analysisModel.getBreatheThresholdMin());
int breatheThresholdMax = Integer.parseInt(analysisModel.getBreatheThresholdMax());
......@@ -136,23 +105,36 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
int heartThresholdMin = Integer.parseInt(analysisModel.getHeartThresholdMin());
int heartThresholdMax = Integer.parseInt(analysisModel.getHeartThresholdMax());
int heartDuration = Integer.parseInt(analysisModel.getHeartDuration());
for (PlatElder platElder : elderList) {
PlatElderBreatheDayStat elderBreatheDayStat = breatheDayStatMap.get(platElder.getId());
if (elderBreatheDayStat == null) {
continue;
return new PlatElderBreatheAnalysis();
}
PlatDevice platDevice = platElderRealTimeService.getBreathDevice(platElder.getId(), null);
if (platDevice == null) {
continue;
return new PlatElderBreatheAnalysis();
}
List<String> dayHourRange = getLastDayHourRange(yesStart);
TreeMap<String, AnalysisVO> totalMap = new TreeMap<>();
String reportStartTime = "";
String reportEndTime = "";
// 呼吸暂停
AtomicInteger brStopCount = new AtomicInteger(0);
AtomicLong brStopSecond = new AtomicLong(0);
// 呼吸过速
AtomicInteger brFastCount = new AtomicInteger(0);
;
AtomicLong brFastSecond = new AtomicLong();
// 呼吸过缓
AtomicInteger brSlowCount = new AtomicInteger(0);
AtomicLong brSlowSecond = new AtomicLong();
// 心率过速
AtomicInteger hrFastCount = new AtomicInteger(0);
AtomicLong hrFastSecond = new AtomicLong();
// 心率过缓
AtomicInteger hrSlowCount = new AtomicInteger(0);
AtomicLong hrSlowSecond = new AtomicLong();
for (String hourRange : dayHourRange) {
String[] hourRangeArray = hourRange.split("~");
List<DeviceOperationLogEntity> deviceOperationLogEntities = productDeviceService.getDeviceLogByTimeRange(platDevice.getOriDeviceId(), "reportProperty", 5000, hourRangeArray[0], hourRangeArray[1]);
List<DeviceOperationLogEntity> deviceOperationLogEntities = productDeviceService.getDeviceLogByTimeRange(
platDevice.getOriDeviceId(), "reportProperty", 5000, hourRangeArray[0], hourRangeArray[1]);
if (CollectionUtils.isEmpty(deviceOperationLogEntities)) {
continue;
}
......@@ -160,217 +142,160 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
.filter(deviceOperationLogEntity -> deviceOperationLogEntity.getType().contains("reportProperty"))
.map(deviceOperationLogEntity -> {
DeviceInfoContentBreathe deviceInfoContentBreathe = JsonUtil.toObj((String) deviceOperationLogEntity.getContent(), DeviceInfoContentBreathe.class);
assert deviceInfoContentBreathe != null;
deviceInfoContentBreathe.setReportTime(formatLongTime(deviceInfoContentBreathe.getTimestamp()));
return deviceInfoContentBreathe;
})
.collect(Collectors.toList());
Map<String, List<DeviceInfoContentBreathe>> minuteMap = StreamUtil.groupBy(deviceInfoContentBreatheList, DeviceInfoContentBreathe::getReportTime);
deviceOperationLogEntities.clear();
// 统计每小时的体动和翻身
Map<String, AnalysisVO> statisticsMap = Maps.newHashMap();
List<DeviceInfoContentBreathe> deviceInfoContentBreathes;
for (Map.Entry<String, List<DeviceInfoContentBreathe>> entry : minuteMap.entrySet()) {
if (StringUtils.isEmpty(reportStartTime)) {
reportStartTime = entry.getKey();
}
reportEndTime = entry.getKey();
deviceInfoContentBreathes = entry.getValue();
DeviceInfoContentBreathe.Properties breatheProperties;
// 呼吸暂停
int brStopCount = 0;
int brStopSecond = 0;
// 呼吸过速
int brFastCount = 0;
int brFastSecond = 0;
int brFast = 0;
// 呼吸过缓
int brSlowCount = 0;
int brSlowSecond = 0;
int brSlow = 0;
// 心率过速
int hrFastCount = 0;
int hrFast = 0;
int hrFastSecond = 0;
// 心率过缓
int hrSlowCount = 0;
int hrSlowSecond = 0;
int hrSlow = 0;
AnalysisVO analysisVO = new AnalysisVO();
for (DeviceInfoContentBreathe infoContentBreathe : deviceInfoContentBreathes) {
// 体动指数
breatheProperties = infoContentBreathe.getProperties();
int br = breatheProperties.getBr();
int hr = breatheProperties.getHr();
Integer hasPerson = breatheProperties.getPerson(); // 0无人,1有人
if (hasPerson == 0) {
continue;
}
AtomicBoolean existHrFast = new AtomicBoolean(false);
AtomicBoolean existHrSlow = new AtomicBoolean(false);
AtomicBoolean existBrFast = new AtomicBoolean(false);
AtomicBoolean existBrSlow = new AtomicBoolean(false);
AtomicBoolean existBrStop = new AtomicBoolean(false);
deviceInfoContentBreatheList.forEach(deviceInfo -> {
DeviceInfoContentBreathe.Properties deviceProperties = deviceInfo.getProperties();
int br = deviceProperties.getBr();
int hr = deviceProperties.getHr();
Integer hasPerson = deviceProperties.getPerson(); // 0无人,1有人
// 0和255设备误报直接跳过
if (hr == 255 || br == 255) {
continue;
}
if (hasPerson == 0 || hr == 255 || br == 255) {
brStopSecond.set(0);
brFastSecond.set(0);
brSlowSecond.set(0);
hrFastSecond.set(0);
hrSlowSecond.set(0);
existHrFast.set(false);
existHrSlow.set(false);
existBrFast.set(false);
existBrSlow.set(false);
existBrStop.set(false);
return;
}
Long timestamp = deviceInfo.getTimestamp();
// 判断呼吸暂停
if (br == 0) {
brStopSecond++;
if (brStopSecond == breatheDuration) {
brStopCount++;
brStopSecond = 0;
}
} else {
brStopSecond = 0;
}
// 判断呼吸率阈值,记录发生时间和当前呼吸率
if (breatheThresholdMax < br) {
if (brFast == 0) {
brFast = br;
}
brFastSecond++;
if (brFastSecond == breatheDuration) {
brFastCount++;
brFastSecond = 0;
}
} else {
brFastSecond = 0;
}
if (br < breatheThresholdMin) {
if (brSlow == 0) {
brSlow = br;
}
brSlowSecond++;
if (brSlowSecond == breatheDuration) {
brSlowCount++;
brSlowSecond = 0;
}
long firstStopSecond = brStopSecond.get();
if (firstStopSecond == 0) {
log.info("第一次呼吸暂停的时间:{}", longToTime(timestamp));
brStopSecond.set(timestamp);
}
if (firstStopSecond != 0 && (timestamp - firstStopSecond) / 1000 >= breatheDuration) {
// 避免每10s生成一次统计的方式,切换状态后重新计算
if(!existBrStop.get()) {
log.info("第一次呼吸暂停持续时间满足:{}:now:{}", breatheDuration, longToTime(timestamp));
brStopCount.getAndIncrement();
existBrStop.set(true);
}
}
brFastSecond.set(0);
brSlowSecond.set(0);
existBrFast.set(false);
existBrSlow.set(false);
} else if (breatheThresholdMax < br) {
//呼吸过快
long firstFastBr = brFastSecond.get();
if (firstFastBr == 0) {
log.info("第一次呼吸:{},fast大于阈值:{},的时间:{}", br, breatheThresholdMax, longToTime(timestamp));
brFastSecond.set(timestamp);
}
if (firstFastBr != 0 && (timestamp - firstFastBr) / 1000 >= breatheDuration) {
if (!existBrFast.get()) {
log.info("第一次呼吸:{},fast持续时间满足:{}:now:{}", br, breatheDuration, longToTime(timestamp));
brFastCount.getAndIncrement();
existBrFast.set(true);
}
}
brSlowSecond.set(0);
brStopSecond.set(0);
existBrSlow.set(false);
existBrStop.set(false);
} else if (br < breatheThresholdMin) {
// 呼吸过慢
long firstSlowBr = brSlowSecond.get();
if (firstSlowBr == 0) {
log.info("第一次呼吸:{},slow小于阈值:{},的时间:{}", br, breatheThresholdMin, longToTime(timestamp));
brSlowSecond.set(timestamp);
}
if (firstSlowBr != 0 && (timestamp - firstSlowBr) / 1000 >= breatheDuration) {
if (!existBrSlow.get()) {
log.info("第一次呼吸:{},slow持续时间满足:{}:now:{}", br, breatheDuration, longToTime(timestamp));
brSlowCount.getAndIncrement();
}
}
brFastSecond.set(0);
brStopSecond.set(0);
existBrFast.set(false);
existBrStop.set(false);
} else {
brSlowSecond = 0;
brSlowSecond.set(0);
brFastSecond.set(0);
brStopSecond.set(0);
existBrFast.set(false);
existBrStop.set(false);
existBrSlow.set(false);
log.info("呼吸正常:{},min:{},max:{},的时间:{}", br, breatheThresholdMin, breatheThresholdMax, longToTime(timestamp));
}
// 心率过快
if (heartThresholdMax < hr) {
if (hrFast == 0) {
hrFast = br;
}
hrFastSecond++;
if (hrFastSecond == heartDuration) {
hrFastCount++;
hrFastSecond = 0;
}
} else {
hrFastSecond = 0;
}
if (heartThresholdMin > hr) {
if (hrSlow == 0) {
hrSlow = br;
}
hrSlowSecond++;
if (hrSlowSecond == heartDuration) {
hrSlowCount++;
hrSlowSecond = 0;
long firstHrMax = hrFastSecond.get();
if (firstHrMax == 0) {
log.info("第一次心率:{},max大于阈值:{},的时间:{}", hr, heartThresholdMax, longToTime(timestamp));
hrFastSecond.set(timestamp);
}
if (firstHrMax != 0 && (timestamp - firstHrMax) / 1000 >= heartDuration) {
if (!existHrFast.get()) {
log.info("第一次心率:{},max持续时间满足:{}:now:{}", hr, heartDuration, longToTime(timestamp));
hrFastCount.getAndIncrement();
existHrFast.set(true);
}
}
hrSlowSecond.set(0);
existHrSlow.set(false);
} else if (heartThresholdMin > hr) {
// 心率过慢
long firstHrMin = hrSlowSecond.get();
if (firstHrMin == 0) {
log.info("第一次心率:{},min小于阈值:{},的时间:{}", hr, heartThresholdMin, longToTime(timestamp));
hrSlowSecond.set(timestamp);
}
if (firstHrMin != 0 && (timestamp - firstHrMin) / 1000 >= heartDuration) {
if (!existHrSlow.get()) {
log.info("第一次心率:{},min持续时间满足:{}:now:{}", hr, heartDuration, longToTime(timestamp));
hrSlowCount.getAndIncrement();
existHrSlow.set(true);
}
}
hrFastSecond.set(0);
existHrFast.set(false);
}else {
hrSlowSecond.set(0);
existHrSlow.set(false);
hrFastSecond.set(0);
existHrFast.set(false);
log.info("心率正常:{},min:{},max:{},的时间:{}", hr, heartThresholdMin,heartThresholdMax, longToTime(timestamp));
}
});
}
} else {
hrSlowSecond = 0;
}
}
analysisVO.setBrStopThreshold(brStopCount);
analysisVO.setBrFastThreshold(brFastCount);
analysisVO.setBrSlowThreshold(brSlowCount);
analysisVO.setHrFastThreshold(hrFastCount);
analysisVO.setHrSlowThreshold(hrSlowCount);
statisticsMap.put(entry.getKey(), analysisVO);
}
TreeMap<String, AnalysisVO> treeMap = new TreeMap<>(statisticsMap);
totalMap.putAll(treeMap);
statisticsMap.clear();
treeMap.clear();
}
if (totalMap.isEmpty()) {
continue;
}
// 呼吸暂停
int apneaTime = Integer.parseInt(saasDiseaseModel.getApneaTime());
int apneaThreshold = Integer.parseInt(saasDiseaseModel.getApneaThreshold());
BigDecimal apneaRate = new BigDecimal(apneaThreshold);
// 呼吸过速
int tachypneaTime = Integer.parseInt(saasDiseaseModel.getTachypneaTime());
int tachypneaThreshold = Integer.parseInt(saasDiseaseModel.getTachypneaThreshold());
BigDecimal tachypneaRate = new BigDecimal(tachypneaThreshold);
// 呼吸过缓
int bradypneaTime = Integer.parseInt(saasDiseaseModel.getBradypneaTime());
int bradypneaThreshold = Integer.parseInt(saasDiseaseModel.getBradypneaThreshold());
BigDecimal bradypneaRate = new BigDecimal(bradypneaThreshold);
// 心率过缓
int bradycardiaTime = Integer.parseInt(saasDiseaseModel.getBradycardiaTime());
int bradycardiaThreshold = Integer.parseInt(saasDiseaseModel.getBradycardiaThreshold());
BigDecimal bradycardiaRate = new BigDecimal(bradycardiaThreshold);
// 心率过速
int tachycardiaTime = Integer.parseInt(saasDiseaseModel.getTachycardiaTime());
int tachycardiaComparison = Integer.parseInt(saasDiseaseModel.getTachycardiaThreshold());
BigDecimal tachycardiaRate = new BigDecimal(tachycardiaComparison);
// 呼吸疾病报告
int brStopCount = 0;
int brFastCount = 0;
int brSlowCount = 0;
int hrFastCount = 0;
int hrSlowCount = 0;
// 计算异常的信息,并且统计异常的次数
List<BreatheAbnormalVO> breatheAbnormalVOList = Lists.newArrayList();
for (Map.Entry<String, AnalysisVO> entry : totalMap.entrySet()) {
AnalysisVO analysisVO = entry.getValue();
if (analysisVO.getBrStopThreshold() > 0) {
brStopCount += analysisVO.getBrStopThreshold();
}
if (analysisVO.getBrSlowThreshold() > 0) {
brSlowCount += analysisVO.getBrSlowThreshold();
}
if (analysisVO.getBrFastThreshold() > 0) {
brFastCount += analysisVO.getBrFastThreshold();
}
if (analysisVO.getHrFastThreshold() > 0) {
hrFastCount += analysisVO.getHrFastThreshold();
}
if (analysisVO.getHrSlowThreshold() > 0) {
hrSlowCount += analysisVO.getHrSlowThreshold();
}
}
int timeHourRange = 24;
if (StringUtils.isNotEmpty(reportStartTime) && StringUtils.isNotEmpty(reportEndTime)) {
timeHourRange = Math.toIntExact(getDurationRange(reportStartTime, reportEndTime));
}
// 判断是否满足配置的呼吸心率异常类型
BigDecimal dayBrStopRate = new BigDecimal(brStopCount);
BigDecimal dayBrSlowRate = new BigDecimal(brSlowCount);
BigDecimal dayBrFastRate = new BigDecimal(brFastCount);
BigDecimal dayHrFastRate = new BigDecimal(hrFastCount);
BigDecimal dayHrSlowRate = new BigDecimal(hrSlowCount);
boolean brStopFlag = false;
boolean brFastFlag = false;
boolean brSlowFlag = false;
......@@ -378,36 +303,30 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
boolean hrSlowFlag = false;
boolean normalFlag;
if (dayBrStopRate.compareTo(apneaRate) > 0) {
if (brStopCount.get() > apneaThreshold) {
brStopFlag = true;
}
if (dayBrFastRate.compareTo(tachypneaRate) > 0) {
if (brFastCount.get() > tachypneaThreshold) {
brFastFlag = true;
}
if (dayBrSlowRate.compareTo(bradypneaRate) > 0) {
if (brSlowCount.get() > bradypneaThreshold) {
brSlowFlag = true;
}
if (dayHrFastRate.compareTo(tachycardiaRate) > 0) {
if (hrFastCount.get() > tachycardiaComparison) {
hrFastFlag = true;
}
if (dayHrSlowRate.compareTo(bradycardiaRate) > 0) {
if (hrSlowCount.get() > bradycardiaThreshold) {
hrSlowFlag = true;
}
normalFlag = !(hrFastFlag || brStopFlag || brFastFlag || brSlowFlag || hrSlowFlag);
SaasDiseaseEvaluateReport saasDiseaseEvaluateReport = saasDiseaseEvaluateReportService.getOne(new QueryWrapper<SaasDiseaseEvaluateReport>().lambda()
.orderByDesc(BaseEntity::getCreateBy)
.last("limit 1"));
String resultContent = saasDiseaseEvaluateReport.getResultContent();
List<DiseaseReportVO> evaluateReportList = JSON.parseArray(resultContent, DiseaseReportVO.class);
List<DiseaseReportVO> evaluateReportList = JSON.parseArray(saasDiseaseEvaluateReport.getResultContent(), DiseaseReportVO.class);
DiseaseReportVO finalReport = new DiseaseReportVO();
// 根据疾病标准配置的规则判断满足哪个区间范围
for (DiseaseReportVO diseaseReportVO : evaluateReportList) {
List<DiseaseReportVO.Condition> conditionList = diseaseReportVO.getCondition();
if (CollUtil.isEmpty(conditionList)) {
return result;
continue;
}
boolean conditionFlag = true;
......@@ -443,8 +362,13 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
finalReport = diseaseReportVO;
}
}
long scoreLong = Long.parseLong(finalReport.getScore());
if (scoreLong > 100) {
scoreLong = 100;
finalReport.setScore("100");
}
EvaluateReportVO diseaseReport = saasDiseaseReportService.getByScore(Long.parseLong(finalReport.getScore()));
EvaluateReportVO diseaseReport = saasDiseaseReportService.getByScore(scoreLong);
PlatElderBreatheAnalysis platElderBreatheAnalysis = new PlatElderBreatheAnalysis();
platElderBreatheAnalysis.setElderId(platElder.getId());
......@@ -464,11 +388,58 @@ public class PlatElderBreatheAnalysisServiceImpl extends ServiceImpl<PlatElderBr
} else {
platElderBreatheAnalysisService.save(platElderBreatheAnalysis);
}
result.add(platElderBreatheAnalysis);
return platElderBreatheAnalysis;
}
@Override
@Transactional(rollbackFor = Exception.class)
public List<PlatElderBreatheAnalysis> elderHeartRespiratoryAnalysisTask(Integer month,Integer day) {
// 12-06,12-18 12-07、 12-12(70分)
LocalDate nowDate = LocalDate.now();
if (month != null && day != null) {
nowDate = LocalDate.of(2023, month, day);
}
LocalDate yesDate = nowDate.minusDays(1);
LocalDateTime yesStart = LocalDateTimeUtils.getDayStart(yesDate);
LocalDateTime yesEnd = LocalDateTimeUtils.getDayEnd(yesDate);
List<PlatElder> elderList = platElderService.list(new QueryWrapper<PlatElder>().lambda()
.isNotNull(PlatElder::getBedId));
List<PlatElderBreatheAnalysis> result = new ArrayList<>();
if (CollectionUtils.isEmpty(elderList)) {
return result;
}
List<String> elderIdList = StreamUtil.map(elderList, BaseEntity::getId);
List<PlatElderBreatheDayStat> elderBreatheDayStatList = platElderBreatheDayStatService.list(new QueryWrapper<PlatElderBreatheDayStat>().lambda()
.in(PlatElderBreatheDayStat::getElderId, elderIdList)
.eq(PlatElderBreatheDayStat::getDay, yesDate));
Map<String, PlatElderBreatheDayStat> breatheDayStatMap = StreamUtil.toMapDep(elderBreatheDayStatList, PlatElderBreatheDayStat::getElderId);
SaasSleepAnalysisModel analysisModel = saasSleepAnalysisModelService.getOne(new QueryWrapper<SaasSleepAnalysisModel>().lambda()
.orderByDesc(BaseEntity::getCreateBy)
.last("limit 1"));
SaasDiseaseModel saasDiseaseModel = saasDiseaseModelService.getOne(new QueryWrapper<SaasDiseaseModel>().lambda()
.orderByDesc(BaseEntity::getCreateBy)
.last("limit 1"));
Map<String, PlatElderBreatheAnalysis> analysisMap = StreamUtil.toMapDep(platElderBreatheAnalysisService.list(Wrappers.<PlatElderBreatheAnalysis>lambdaQuery()
.in(PlatElderBreatheAnalysis::getElderId, elderIdList)
.eq(PlatElderBreatheAnalysis::getHappenDate, yesDate)), PlatElderBreatheAnalysis::getElderId);
SaasDiseaseEvaluateReport saasDiseaseEvaluateReport = saasDiseaseEvaluateReportService.getOne(
new QueryWrapper<SaasDiseaseEvaluateReport>().lambda().orderByDesc(BaseEntity::getCreateBy)
.last("limit 1"));
for (PlatElder platElder : elderList) {
PlatElderBreatheAnalysis platAnalysis = elderHeartAnalysis(platElder, breatheDayStatMap, yesStart, analysisModel,
saasDiseaseModel, yesDate, analysisMap, saasDiseaseEvaluateReport);
result.add(platAnalysis);
}
return result;
}
public Long getDurationRange(String startTime, String endTime) {
......
......@@ -185,7 +185,8 @@ public class PlatElderDayReportDayServiceImpl implements PlatElderDayReportDaySe
score.updateAndGet(v -> v + Long.parseLong(finalSleepScore));
});
});
return Long.parseLong(baseScore) + score.get();
Long result = Long.parseLong(baseScore) + score.get();
return result.compareTo(100L) > 0 ? 100L : result;
}
......
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