Commit d44d7a1f by huangjy

fix:长者报告定时器

parent 93f00def
Showing with 220 additions and 263 deletions
...@@ -265,27 +265,6 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -265,27 +265,6 @@ public class IotProductDeviceService extends IotCommonService {
return tempList; return tempList;
} }
return Lists.newArrayList(); return Lists.newArrayList();
/* 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.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
deviceInfoContentBreathe.setTimestamp(timeStamp);
DeviceInfoContentBreathe.Properties properties = new DeviceInfoContentBreathe.Properties();
properties.setBr(brRandomLong);
properties.setHr(hrRandomLong);
properties.setBodymove(movebodyRandomLong);
deviceInfoContentBreathe.setProperties(properties);
breatheList.add(deviceInfoContentBreathe);
}
return breatheList;*/
} }
public static String formatLongTime(long time) { public static String formatLongTime(long time) {
......
...@@ -74,5 +74,12 @@ public class DeviceInfoContentBreathe { ...@@ -74,5 +74,12 @@ public class DeviceInfoContentBreathe {
@JsonProperty("point") @JsonProperty("point")
// 呼吸波形 // 呼吸波形
private List<Integer> point; private List<Integer> point;
private int brStopThreshold; // 发生次数阈值
private int brFastThreshold; // 发生次数阈值
private int brSlowThreshold; // 发生次数阈值
private int hrFastThreshold; // 发生次数阈值
private int hrSlowThreshold; // 发生次数阈值
} }
} }
...@@ -4,7 +4,6 @@ package com.makeit.module.controller.children.elder; ...@@ -4,7 +4,6 @@ package com.makeit.module.controller.children.elder;
import com.makeit.common.response.ApiResponseEntity; import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils; import com.makeit.common.response.ApiResponseUtils;
import com.makeit.dto.platform.elder.PlatElderReportDTO; import com.makeit.dto.platform.elder.PlatElderReportDTO;
import com.makeit.global.annotation.AuthIgnore;
import com.makeit.service.platform.elder.PlatElderDayReportWeekService; import com.makeit.service.platform.elder.PlatElderDayReportWeekService;
import com.makeit.vo.platform.elder.realtime.PlatElderCoordinateVO; import com.makeit.vo.platform.elder.realtime.PlatElderCoordinateVO;
import com.makeit.vo.platform.elder.report.day.*; import com.makeit.vo.platform.elder.report.day.*;
...@@ -104,13 +103,5 @@ public class PlatElderReportWeekChildrenController { ...@@ -104,13 +103,5 @@ public class PlatElderReportWeekChildrenController {
} }
@ApiOperation("定时任务")
@PostMapping("heartRespiratoryJob")
@AuthIgnore
public ApiResponseEntity<String> heartRespiratoryJob() {
platElderDayReportWeekService.heartRespiratoryJob();
return ApiResponseUtils.success();
}
} }
...@@ -9,7 +9,7 @@ import com.makeit.global.aspect.tenant.TenantIdIgnore; ...@@ -9,7 +9,7 @@ import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.platform.elder.PlatElderReportMonthService; import com.makeit.service.platform.elder.PlatElderReportMonthService;
import com.makeit.service.platform.elder.PlatElderSleepService; import com.makeit.service.platform.elder.PlatElderSleepService;
import com.makeit.task.IotSyncTask; import com.makeit.task.PlatElderReportTask;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.RestController;
public class PlatElderSleepController { public class PlatElderSleepController {
@Autowired @Autowired
private IotSyncTask iotSyncTask; private PlatElderReportTask platElderReportTask;
@Autowired @Autowired
private PlatElderSleepService platElderSleepService; private PlatElderSleepService platElderSleepService;
@Autowired @Autowired
...@@ -40,14 +40,7 @@ public class PlatElderSleepController { ...@@ -40,14 +40,7 @@ public class PlatElderSleepController {
@Autowired @Autowired
private PlatElderReportMonthService platElderReportMonthService; private PlatElderReportMonthService platElderReportMonthService;
@ApiOperation("测试")
@PostMapping("test")
@AuthIgnore
@TenantIdIgnore
public ApiResponseEntity<Void> test() {
iotSyncTask.elderSleepSleepAnalysisTask();
return ApiResponseUtils.success();
}
@ApiOperation("测试") @ApiOperation("测试")
@PostMapping("test1") @PostMapping("test1")
...@@ -61,8 +54,24 @@ public class PlatElderSleepController { ...@@ -61,8 +54,24 @@ public class PlatElderSleepController {
@ApiOperation("测试") @ApiOperation("测试")
@PostMapping("test2") @PostMapping("test2")
@AuthIgnore @AuthIgnore
public ApiResponseEntity<Void> reportMonthJob() { public ApiResponseEntity<Void> heartRespiratoryTask() {
platElderReportMonthService.reportMonthJob(); platElderReportTask.heartRespiratoryTask();
return ApiResponseUtils.success();
}
@ApiOperation("测试")
@PostMapping("test3")
@AuthIgnore
public ApiResponseEntity<Void> elderHeartRespiratoryAnalysisTask() {
platElderReportTask.elderHeartRespiratoryAnalysisTask();
return ApiResponseUtils.success();
}
@ApiOperation("测试")
@PostMapping("test4")
@AuthIgnore
public ApiResponseEntity<Void> elderSleepSleepAnalysisTask() {
platElderReportTask.elderSleepSleepAnalysisTask();
return ApiResponseUtils.success(); return ApiResponseUtils.success();
} }
......
...@@ -13,4 +13,5 @@ import com.makeit.entity.platform.elder.PlatElderBreatheAnalysis; ...@@ -13,4 +13,5 @@ import com.makeit.entity.platform.elder.PlatElderBreatheAnalysis;
*/ */
public interface PlatElderBreatheAnalysisService extends IService<PlatElderBreatheAnalysis> { public interface PlatElderBreatheAnalysisService extends IService<PlatElderBreatheAnalysis> {
void elderHeartRespiratoryAnalysisTask();
} }
...@@ -13,4 +13,5 @@ import com.makeit.entity.platform.elder.PlatElderBreatheDayStat; ...@@ -13,4 +13,5 @@ import com.makeit.entity.platform.elder.PlatElderBreatheDayStat;
*/ */
public interface PlatElderBreatheDayStatService extends IService<PlatElderBreatheDayStat> { public interface PlatElderBreatheDayStatService extends IService<PlatElderBreatheDayStat> {
void heartRespiratoryTask();
} }
...@@ -48,6 +48,4 @@ public interface PlatElderDayReportWeekService { ...@@ -48,6 +48,4 @@ public interface PlatElderDayReportWeekService {
List<PlatElderBehaviorDistributionVO> behaviorDistribution(PlatElderReportDTO platElderIdDTO); List<PlatElderBehaviorDistributionVO> behaviorDistribution(PlatElderReportDTO platElderIdDTO);
void heartRespiratoryJob();
} }
...@@ -28,7 +28,6 @@ public interface PlatElderReportMonthService extends IService<PlatElderReportMon ...@@ -28,7 +28,6 @@ public interface PlatElderReportMonthService extends IService<PlatElderReportMon
List<PlatElderReportMonthVO> reportMonth(PlatElderReportDTO platElderIdDTO); List<PlatElderReportMonthVO> reportMonth(PlatElderReportDTO platElderIdDTO);
void reportMonthJob();
} }
package com.makeit.service.platform.elder.impl; package com.makeit.service.platform.elder.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.entity.platform.elder.PlatElderBreatheDayStat; import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.*;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.report.BreatheTypeEnum;
import com.makeit.enums.report.HeartRateTypeEnum;
import com.makeit.mapper.platform.elder.PlatElderBreatheDayStatMapper; import com.makeit.mapper.platform.elder.PlatElderBreatheDayStatMapper;
import com.makeit.service.platform.elder.PlatElderBreatheDayStatService; import com.makeit.module.iot.service.IotProductDeviceService;
import com.makeit.module.iot.vo.analysis.DiseaseReportVO;
import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.service.platform.elder.*;
import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.data.validate.CollectionUtils;
import com.makeit.utils.data.validate.MapUtil;
import com.makeit.utils.time.LocalDateTimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/** /**
* <p> * <p>
...@@ -17,4 +41,108 @@ import org.springframework.stereotype.Service; ...@@ -17,4 +41,108 @@ import org.springframework.stereotype.Service;
@Service @Service
public class PlatElderBreatheDayStatServiceImpl extends ServiceImpl<PlatElderBreatheDayStatMapper, PlatElderBreatheDayStat> implements PlatElderBreatheDayStatService { public class PlatElderBreatheDayStatServiceImpl extends ServiceImpl<PlatElderBreatheDayStatMapper, PlatElderBreatheDayStat> implements PlatElderBreatheDayStatService {
@Autowired
private PlatAlarmRecordService platAlarmRecordService;
@Autowired
private PlatElderService platElderService;
@Autowired
private PlatElderSleepAnalysisService platElderSleepAnalysisService;
@Autowired
private IotProductDeviceService iotProductDeviceService;
@Autowired
private PlatElderRealTimeService platElderRealTimeService;
@Autowired
private PlatElderReportMonthService platElderReportMonthService;
@Transactional(rollbackFor = Exception.class)
@Override
public void heartRespiratoryTask() {
LocalDate nowDate = LocalDate.now();
LocalDate yesDate = nowDate.minusDays(1);
LocalDateTime yesStart = LocalDateTimeUtils.getDayStart(yesDate);
LocalDateTime yesEnd = LocalDateTimeUtils.getDayEnd(yesDate);
List<PlatElderBreatheDayStat> breatheDayStatList = new ArrayList<>(10);
List<PlatElder> elderList = platElderService.list(new QueryWrapper<PlatElder>().lambda()
.isNotNull(PlatElder::getBedId));
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
List<PlatElderReportMonth> reportMonthList = new ArrayList<>(10);
List<PlatElderSleepAnalysis> sleepAnalysesList = platElderSleepAnalysisService.list(new QueryWrapper<PlatElderSleepAnalysis>().lambda()
.in(PlatElderSleepAnalysis::getElderId, StreamUtil.mapId(elderList, PlatElder::getId))
.eq(PlatElderSleepAnalysis::getHappenDate, dateTimeFormatter.format(yesDate))
);
Map<String, PlatElderSleepAnalysis> sleepAnalysisMap = StreamUtil.toMap(sleepAnalysesList, PlatElderSleepAnalysis::getElderId);
List<PlatAlarmRecord> recordList = platAlarmRecordService.list(new QueryWrapper<PlatAlarmRecord>().lambda()
.ge(PlatAlarmRecord::getAlarmDate, yesStart)
.le(PlatAlarmRecord::getAlarmDate, yesEnd)
.eq(PlatAlarmRecord::getMisinformationFlag,0)
.in(PlatAlarmRecord::getElderIds, StreamUtil.mapId(elderList, PlatElder::getId)));
Map<String, List<PlatAlarmRecord>> recordMap = StreamUtil.groupBy(recordList, PlatAlarmRecord::getElderIds);
for (PlatElder e : elderList) {
PlatDevice platDevice = platElderRealTimeService.getBreathDevice(e.getId(), null);
if (platDevice != null) {
PlatElderBreatheDayStat platElderBreatheDayStat = new PlatElderBreatheDayStat();
platElderBreatheDayStat.setElderId(e.getId());
platElderBreatheDayStat.setDeviceId(platDevice.getId());
platElderBreatheDayStat.setOriDeviceId(platDevice.getOriDeviceId());
platElderBreatheDayStat.setDay(yesDate);
List<DeviceInfoContentBreathe> breatheList = iotProductDeviceService.getDeviceLogByTimeRangeBreathe(platDevice.getOriDeviceId(), 2 * 24 * 3600, yesStart, yesEnd);
if (CollectionUtils.isEmpty(breatheList)) {
continue;
}
long hrAvg = StreamUtil.reduce(breatheList, i -> (long) i.getProperties().getHr(), 0L, Long::sum) / breatheList.size();
long brAvg = StreamUtil.reduce(breatheList, i -> (long) i.getProperties().getBr(), 0L, Long::sum) / breatheList.size();
platElderBreatheDayStat.setHeartRateMax(breatheList.stream().map(i -> i.getProperties().getHr()).max(Integer::compareTo).orElse(null));
platElderBreatheDayStat.setHeartRateMin(breatheList.stream().map(i -> i.getProperties().getHr()).min(Integer::compareTo).orElse(null));
platElderBreatheDayStat.setHeartRateAvg((int) (hrAvg));
platElderBreatheDayStat.setRespiratoryRateMax(breatheList.stream().map(i -> i.getProperties().getBr()).max(Integer::compareTo).orElse(null));
platElderBreatheDayStat.setRespiratoryRateMin(breatheList.stream().map(i -> i.getProperties().getBr()).min(Integer::compareTo).orElse(null));
platElderBreatheDayStat.setRespiratoryRateAvg((int) (brAvg));
platElderBreatheDayStat.setTenantId(e.getTenantId());
breatheDayStatList.add(platElderBreatheDayStat);
PlatElderReportMonth reportMonth = new PlatElderReportMonth();
reportMonth.setElderId(e.getId());
reportMonth.setDay(yesDate);
MapUtil.setIfPresent(sleepAnalysisMap, e.getId(), sa -> {
reportMonth.setSleepResult(sa.getSleepResult());
});
reportMonth.setBreatheDeviceId(platDevice.getId());
reportMonth.setBreatheOriDeviceId(platDevice.getOriDeviceId());
reportMonth.setHeartRate((int) (hrAvg));
reportMonth.setRespiratoryRate((int) (brAvg));
List<PlatAlarmRecord> rList = Optional.ofNullable(recordMap.get(e.getId())).orElse(new ArrayList<>(10));
reportMonth.setFailCount((int) StreamUtil.count(rList, i -> PlatAlarmConfigEnum.AlarmTypeEnum.FALL.getValue().equals(i.getAlarmType())));
reportMonth.setHeartExceptionCount((int) StreamUtil.count(rList, i -> PlatAlarmConfigEnum.AlarmTypeEnum.HEART.getValue().equals(i.getAlarmType())));
reportMonth.setRespiratoryExceptionCount((int) StreamUtil.count(rList, i -> PlatAlarmConfigEnum.AlarmTypeEnum.BREATHE.getValue().equals(i.getAlarmType())));
reportMonth.setBehaviorExceptionCount((int) StreamUtil.count(rList, i -> PlatAlarmConfigEnum.AlarmTypeEnum.BEHAVIOR.getValue().equals(i.getAlarmType())));
reportMonth.setTenantId(e.getTenantId());
reportMonthList.add(reportMonth);
}
}
platElderReportMonthService.saveBatch(reportMonthList);
saveBatch(breatheDayStatList);
}
} }
...@@ -4,13 +4,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,13 +4,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.makeit.common.entity.BaseBusEntity; import com.makeit.common.entity.BaseBusEntity;
import com.makeit.dto.platform.elder.PlatElderReportDTO; import com.makeit.dto.platform.elder.PlatElderReportDTO;
import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.*; import com.makeit.entity.platform.elder.*;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum; import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.enums.report.SleepTypeEnum; import com.makeit.enums.report.SleepTypeEnum;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.iot.service.IotProductDeviceService; import com.makeit.module.iot.service.IotProductDeviceService;
import com.makeit.module.iot.vo.analysis.EvaluateReportVO; import com.makeit.module.iot.vo.analysis.EvaluateReportVO;
import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe; import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe;
import com.makeit.service.platform.alarm.PlatAlarmRecordService;
import com.makeit.service.platform.elder.*; import com.makeit.service.platform.elder.*;
import com.makeit.service.saas.PlatTenantService; import com.makeit.service.saas.PlatTenantService;
import com.makeit.service.saas.SaasDiseaseReportService; import com.makeit.service.saas.SaasDiseaseReportService;
...@@ -19,6 +22,7 @@ import com.makeit.service.saas.SaasSleepEvaluateReportService; ...@@ -19,6 +22,7 @@ import com.makeit.service.saas.SaasSleepEvaluateReportService;
import com.makeit.utils.data.convert.BeanDtoVoUtils; import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.convert.StreamUtil; import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.data.validate.CollectionUtils; import com.makeit.utils.data.validate.CollectionUtils;
import com.makeit.utils.data.validate.MapUtil;
import com.makeit.utils.old.StringUtils; import com.makeit.utils.old.StringUtils;
import com.makeit.utils.time.LocalDateTimeUtils; import com.makeit.utils.time.LocalDateTimeUtils;
import com.makeit.vo.platform.elder.realtime.PlatElderCoordinateVO; import com.makeit.vo.platform.elder.realtime.PlatElderCoordinateVO;
...@@ -47,20 +51,10 @@ import java.util.stream.Collectors; ...@@ -47,20 +51,10 @@ import java.util.stream.Collectors;
public class PlatElderDayReportWeekServiceImpl implements PlatElderDayReportWeekService { public class PlatElderDayReportWeekServiceImpl implements PlatElderDayReportWeekService {
@Autowired @Autowired
private PlatElderService platElderService;
@Autowired
private PlatTenantService platTenantService;
@Autowired
private PlatElderRealTimeService platElderRealTimeService; private PlatElderRealTimeService platElderRealTimeService;
@Autowired @Autowired
private PlatElderDayReportDayService platElderDayReportDayService; private PlatElderDayReportDayService platElderDayReportDayService;
@Autowired
private PlatElderSleepAnalysisService platElderSleepAnalysisService;
@Autowired @Autowired
private PlatElderSleepService platElderSleepService; private PlatElderSleepService platElderSleepService;
...@@ -80,7 +74,7 @@ public class PlatElderDayReportWeekServiceImpl implements PlatElderDayReportWeek ...@@ -80,7 +74,7 @@ public class PlatElderDayReportWeekServiceImpl implements PlatElderDayReportWeek
private PlatElderBreatheDayStatService platElderBreatheDayStatService; private PlatElderBreatheDayStatService platElderBreatheDayStatService;
@Autowired @Autowired
private IotProductDeviceService iotProductDeviceService; private PlatElderSleepAnalysisService platElderSleepAnalysisService;
private LocalDateTime weekStartDateTime(LocalDateTime defaultTime) { private LocalDateTime weekStartDateTime(LocalDateTime defaultTime) {
return weekStartDateTime(LocalDate.now().minusDays(1), defaultTime); return weekStartDateTime(LocalDate.now().minusDays(1), defaultTime);
...@@ -471,58 +465,4 @@ public class PlatElderDayReportWeekServiceImpl implements PlatElderDayReportWeek ...@@ -471,58 +465,4 @@ public class PlatElderDayReportWeekServiceImpl implements PlatElderDayReportWeek
return platElderDayReportDayService.behaviorDistributionInternal(platElderIdDTO, dateList); return platElderDayReportDayService.behaviorDistributionInternal(platElderIdDTO, dateList);
} }
@Override
public void heartRespiratoryJob() {
LocalDate nowDate = LocalDate.now();
LocalDate yesDate = nowDate.minusDays(1);
LocalDateTime yesStart = LocalDateTimeUtils.getDayStart(yesDate);
LocalDateTime yesEnd = LocalDateTimeUtils.getDayEnd(yesDate);
List<PlatElderBreatheDayStat> breatheDayStatList = new ArrayList<>(10);
platTenantService.executeTenantList(() -> {
List<PlatElder> elderList = platElderService.list(new QueryWrapper<PlatElder>().lambda()
.isNotNull(PlatElder::getBedId));
elderList.forEach(e -> {
PlatDevice platDevice = platElderRealTimeService.getBreathDevice(e.getId(), null);
if (platDevice != null) {
PlatElderBreatheDayStat platElderBreatheDayStat = new PlatElderBreatheDayStat();
platElderBreatheDayStat.setElderId(e.getId());
platElderBreatheDayStat.setDeviceId(platDevice.getId());
platElderBreatheDayStat.setOriDeviceId(platDevice.getOriDeviceId());
platElderBreatheDayStat.setDay(yesDate);
List<DeviceInfoContentBreathe> breatheList = iotProductDeviceService.getDeviceLogByTimeRangeBreathe(platDevice.getOriDeviceId(), 2 * 24 * 3600, yesStart, yesEnd);
platElderBreatheDayStat.setHeartRateMax(breatheList.stream().map(i -> i.getProperties().getHr()).max(Integer::compareTo).orElse(null));
platElderBreatheDayStat.setHeartRateMin(breatheList.stream().map(i -> i.getProperties().getHr()).min(Integer::compareTo).orElse(null));
if (CollectionUtils.isNotEmpty(breatheList)) {
platElderBreatheDayStat.setHeartRateAvg((int) (StreamUtil.reduce(breatheList, i -> (long) i.getProperties().getHr(), 0L, Long::sum) / breatheList.size()));
}
platElderBreatheDayStat.setRespiratoryRateMax(breatheList.stream().map(i -> i.getProperties().getBr()).max(Integer::compareTo).orElse(null));
platElderBreatheDayStat.setRespiratoryRateMin(breatheList.stream().map(i -> i.getProperties().getBr()).min(Integer::compareTo).orElse(null));
if (CollectionUtils.isNotEmpty(breatheList)) {
platElderBreatheDayStat.setRespiratoryRateAvg((int) (StreamUtil.reduce(breatheList, i -> (long) i.getProperties().getBr(), 0L, Long::sum) / breatheList.size()));
}
breatheDayStatList.add(platElderBreatheDayStat);
}
});
});
platElderBreatheDayStatService.saveBatch(breatheDayStatList);
}
} }
...@@ -3,23 +3,13 @@ package com.makeit.service.platform.elder.impl; ...@@ -3,23 +3,13 @@ package com.makeit.service.platform.elder.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.dto.platform.elder.PlatElderReportDTO; import com.makeit.dto.platform.elder.PlatElderReportDTO;
import com.makeit.entity.platform.alarm.PlatAlarmRecord;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.platform.elder.PlatElder;
import com.makeit.entity.platform.elder.PlatElderReportMonth; import com.makeit.entity.platform.elder.PlatElderReportMonth;
import com.makeit.entity.platform.elder.PlatElderSleepAnalysis;
import com.makeit.enums.platform.alarm.PlatAlarmConfigEnum;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.mapper.platform.elder.PlatElderReportMonthMapper; import com.makeit.mapper.platform.elder.PlatElderReportMonthMapper;
import com.makeit.module.iot.service.IotProductDeviceService; 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.alarm.PlatAlarmRecordService;
import com.makeit.service.platform.elder.*; import com.makeit.service.platform.elder.*;
import com.makeit.service.saas.PlatTenantService; import com.makeit.service.saas.PlatTenantService;
import com.makeit.utils.data.convert.BeanDtoVoUtils; import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.data.validate.CollectionUtils;
import com.makeit.utils.data.validate.MapUtil;
import com.makeit.utils.old.StringUtils; import com.makeit.utils.old.StringUtils;
import com.makeit.utils.time.LocalDateTimeUtils; import com.makeit.utils.time.LocalDateTimeUtils;
import com.makeit.vo.platform.elder.report.day.PlatElderHeartRespiratoryEvaluationVO; import com.makeit.vo.platform.elder.report.day.PlatElderHeartRespiratoryEvaluationVO;
...@@ -30,12 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -30,12 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
/** /**
* <p> * <p>
...@@ -140,72 +125,4 @@ public class PlatElderReportMonthServiceImpl extends ServiceImpl<PlatElderReport ...@@ -140,72 +125,4 @@ public class PlatElderReportMonthServiceImpl extends ServiceImpl<PlatElderReport
return voList; return voList;
} }
@Override
@TenantIdIgnore
public void reportMonthJob() {
LocalDate nowDate = LocalDate.now();
LocalDate yesDate = nowDate.minusDays(1);
LocalDateTime yesStart = LocalDateTimeUtils.getDayStart(yesDate);
LocalDateTime yesEnd = LocalDateTimeUtils.getDayEnd(yesDate);
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
List<PlatElderReportMonth> reportMonthList = new ArrayList<>(10);
List<PlatElder> elderList = platElderService.list(new QueryWrapper<PlatElder>().lambda()
.isNotNull(PlatElder::getBedId));
List<PlatElderSleepAnalysis> sleepAnalysesList = platElderSleepAnalysisService.list(new QueryWrapper<PlatElderSleepAnalysis>().lambda()
.in(PlatElderSleepAnalysis::getElderId, StreamUtil.mapId(elderList, PlatElder::getId))
.eq(PlatElderSleepAnalysis::getHappenDate, dateTimeFormatter.format(yesDate))
);
Map<String, PlatElderSleepAnalysis> sleepAnalysisMap = StreamUtil.toMap(sleepAnalysesList, PlatElderSleepAnalysis::getElderId);
List<PlatAlarmRecord> recordList = platAlarmRecordService.list(new QueryWrapper<PlatAlarmRecord>().lambda()
.ge(PlatAlarmRecord::getAlarmDate, yesStart)
.le(PlatAlarmRecord::getAlarmDate, yesEnd)
.eq(PlatAlarmRecord::getMisinformationFlag,0)
.in(PlatAlarmRecord::getElderIds, StreamUtil.mapId(elderList, PlatElder::getId)));
Map<String, List<PlatAlarmRecord>> recordMap = StreamUtil.groupBy(recordList, PlatAlarmRecord::getElderIds);
for (PlatElder e : elderList) {
PlatElderReportMonth reportMonth = new PlatElderReportMonth();
reportMonth.setElderId(e.getId());
reportMonth.setDay(yesDate);
MapUtil.setIfPresent(sleepAnalysisMap, e.getId(), sa -> {
reportMonth.setSleepResult(sa.getSleepResult());
});
PlatDevice platDevice = platElderRealTimeService.getBreathDevice(e.getId(), null);
if (platDevice == null) {
continue;
}
List<DeviceInfoContentBreathe> breatheList = iotProductDeviceService.getDeviceLogByTimeRangeBreathe(platDevice.getOriDeviceId(), 2 * 24 * 3600, yesStart, yesEnd);
if (CollectionUtils.isNotEmpty(breatheList)) {
reportMonth.setBreatheDeviceId(platDevice.getId());
reportMonth.setBreatheOriDeviceId(platDevice.getOriDeviceId());
reportMonth.setHeartRate((int) (StreamUtil.reduce(breatheList, i -> (long) i.getProperties().getHr(), 0L, Long::sum) / breatheList.size()));
reportMonth.setRespiratoryRate((int) (StreamUtil.reduce(breatheList, i -> (long) i.getProperties().getBr(), 0L, Long::sum) / breatheList.size()));
}
List<PlatAlarmRecord> rList = Optional.ofNullable(recordMap.get(e.getId())).orElse(new ArrayList<>(10));
reportMonth.setFailCount((int) StreamUtil.count(rList, i -> PlatAlarmConfigEnum.AlarmTypeEnum.FALL.getValue().equals(i.getAlarmType())));
reportMonth.setHeartExceptionCount((int) StreamUtil.count(rList, i -> PlatAlarmConfigEnum.AlarmTypeEnum.HEART.getValue().equals(i.getAlarmType())));
reportMonth.setRespiratoryExceptionCount((int) StreamUtil.count(rList, i -> PlatAlarmConfigEnum.AlarmTypeEnum.BREATHE.getValue().equals(i.getAlarmType())));
reportMonth.setBehaviorExceptionCount((int) StreamUtil.count(rList, i -> PlatAlarmConfigEnum.AlarmTypeEnum.BEHAVIOR.getValue().equals(i.getAlarmType())));
reportMonth.setTenantId(e.getTenantId());
reportMonthList.add(reportMonth);
}
saveBatch(reportMonthList);
}
} }
package com.makeit.task;
import com.makeit.service.platform.elder.PlatElderDayReportWeekService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class HeartRespiratoryTask {
@Autowired
private PlatElderDayReportWeekService platElderDayReportWeekService;
@Scheduled(cron = "0 0 2 * * ? ")
public void job(){
platElderDayReportWeekService.heartRespiratoryJob();
}
}
package com.makeit.task; package com.makeit.task;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.device.PlatDeviceService; import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.platform.elder.PlatElderSleepService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
...@@ -15,9 +13,6 @@ public class IotSyncTask { ...@@ -15,9 +13,6 @@ public class IotSyncTask {
@Autowired @Autowired
private PlatDeviceService platDeviceService; private PlatDeviceService platDeviceService;
@Autowired
private PlatElderSleepService platElderSleepService;
/** /**
* 一小时同步一次 * 一小时同步一次
...@@ -30,30 +25,4 @@ public class IotSyncTask { ...@@ -30,30 +25,4 @@ public class IotSyncTask {
} }
/**
* 床位id 绑定的所有设备
* 房间id 绑定的所有设备
*
*/
/**
* 长者睡眠分析
*/
@Scheduled(cron = "0 0 1 * * ?")
@TenantIdIgnore
public void elderSleepSleepAnalysisTask() {
log.info("开始定时分析长者睡眠质量");
platElderSleepService.elderSleepSleepAnalysisTask();
log.info("定时分析长者睡眠质量结束");
}
/* @Scheduled(cron = "0 0 1 * * ?")
@TenantIdIgnore
public void elderCoordinateListAnalysisTask() {
log.info("开始定时分析24小时热力图");
platElderDayReportDayService.elderCoordinateListAnalysisTask();
log.info("定时分析长者24小时热力图");
}*/
} }
package com.makeit.task;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.elder.PlatElderBreatheAnalysisService;
import com.makeit.service.platform.elder.PlatElderBreatheDayStatService;
import com.makeit.service.platform.elder.PlatElderSleepService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class PlatElderReportTask {
@Autowired
private PlatElderSleepService platElderSleepService;
@Autowired
private PlatElderBreatheDayStatService platElderBreatheDayStatService;
@Autowired
private PlatElderBreatheAnalysisService platElderBreatheAnalysisService;
@Scheduled(cron = "0 0 1 * * ?")
@TenantIdIgnore
public void heartRespiratoryTask() {
log.info("开始生成长者每日呼吸,异常情况");
platElderBreatheDayStatService.heartRespiratoryTask();
log.info("生成长者每日呼吸,异常情况结束");
}
/**
* 长者呼吸心率分析
*/
@Scheduled(cron = "0 0 2 * * ?")
@TenantIdIgnore
public void elderHeartRespiratoryAnalysisTask() {
log.info("开始定时分析长者呼吸心率");
platElderBreatheAnalysisService.elderHeartRespiratoryAnalysisTask();
log.info("定时分析长者呼吸心率结束");
}
/**
* 长者睡眠分析
*/
@Scheduled(cron = "0 0 3 * * ?")
@TenantIdIgnore
public void elderSleepSleepAnalysisTask() {
log.info("开始定时分析长者睡眠质量");
platElderSleepService.elderSleepSleepAnalysisTask();
log.info("定时分析长者睡眠质量结束");
}
}
package com.makeit.task;
import com.makeit.service.platform.elder.PlatElderReportMonthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class ReportMonthTask {
@Autowired
private PlatElderReportMonthService platElderReportMonthService;
@Scheduled(cron = "0 0 2 * * ? ")
public void job(){
platElderReportMonthService.reportMonthJob();
}
}
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