Commit 0ebd05c3 by huangjy

fix:长者月报问题

parent 8cdf2ef8
ALTER TABLE `plat_device_other`
ALTER TABLE `plat_device_other`
......@@ -4,4 +4,14 @@ ADD COLUMN `secure_key` varchar(255) COMMENT '密钥key' AFTER `secure_id`;
ALTER TABLE `plat_alarm_record`
ADD COLUMN `misinformation_flag` char(1) DEFAULT 0 COMMENT '是否误报 1 误报 0 没有误报' AFTER `read_flag`;
\ No newline at end of file
ADD COLUMN `misinformation_flag` char(1) DEFAULT 0 COMMENT '是否误报 1 误报 0 没有误报' AFTER `read_flag`;
ALTER TABLE `plat_elder_report_month`
MODIFY COLUMN `sleep_result` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '睡眠结果' AFTER `day`,
MODIFY COLUMN `heart_rate` int(11) COMMENT '心率' AFTER `sleep_result`,
MODIFY COLUMN `respiratory_rate` int(11) COMMENT '呼吸率' AFTER `heart_rate`,
MODIFY COLUMN `fail_count` int(11) COMMENT '跌倒次数' AFTER `respiratory_rate`,
MODIFY COLUMN `heart_exception_count` int(11) COMMENT '心率异常次数' AFTER `fail_count`,
MODIFY COLUMN `respiratory_exception_count` int(11) COMMENT '呼吸异常次数' AFTER `heart_exception_count`,
MODIFY COLUMN `behavior_exception_count` int(11) COMMENT '行为异常次数' AFTER `respiratory_exception_count`;
\ No newline at end of file
......@@ -7,6 +7,7 @@ import com.makeit.dto.wechat.device.PlatDeviceAttrWechatDTO;
import com.makeit.global.annotation.AuthIgnore;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.platform.elder.PlatElderReportMonthService;
import com.makeit.service.platform.elder.PlatElderSleepService;
import com.makeit.task.IotSyncTask;
import io.swagger.annotations.Api;
......@@ -36,6 +37,9 @@ public class PlatElderSleepController {
private PlatElderSleepService platElderSleepService;
@Autowired
private PlatDeviceService platDeviceService;
@Autowired
private PlatElderReportMonthService platElderReportMonthService;
@ApiOperation("测试")
@PostMapping("test")
@AuthIgnore
......@@ -54,6 +58,13 @@ public class PlatElderSleepController {
return ApiResponseUtils.success();
}
@ApiOperation("测试")
@PostMapping("test2")
@AuthIgnore
public ApiResponseEntity<Void> reportMonthJob() {
platElderReportMonthService.reportMonthJob();
return ApiResponseUtils.success();
}
@ApiOperation("编辑设备属性")
@PostMapping("editDeviceProperties")
......
......@@ -9,6 +9,7 @@ import com.makeit.entity.platform.elder.PlatElder;
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.module.iot.service.IotProductDeviceService;
import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe;
......@@ -140,8 +141,9 @@ public class PlatElderReportMonthServiceImpl extends ServiceImpl<PlatElderReport
}
@Override
@TenantIdIgnore
public void reportMonthJob() {
LocalDate nowDate = LocalDate.now();
LocalDate nowDate = LocalDate.now().minusDays(6);
LocalDate yesDate = nowDate.minusDays(1);
LocalDateTime yesStart = LocalDateTimeUtils.getDayStart(yesDate);
......@@ -151,59 +153,56 @@ public class PlatElderReportMonthServiceImpl extends ServiceImpl<PlatElderReport
List<PlatElderReportMonth> reportMonthList = new ArrayList<>(10);
platTenantService.executeTenantList(() -> {
List<PlatElder> elderList = platElderService.list(new QueryWrapper<PlatElder>().lambda()
.isNotNull(PlatElder::getBedId));
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()
.in(PlatAlarmRecord::getElderIds, StreamUtil.mapId(elderList, PlatElder::getId)));
Map<String, List<PlatAlarmRecord>> recordMap = StreamUtil.groupBy(recordList, PlatAlarmRecord::getElderIds);
elderList.forEach(e -> {
PlatElderReportMonth reportMonth = new PlatElderReportMonth();
reportMonth.setElderId(e.getBedId());
reportMonth.setDay(yesDate);
MapUtil.setIfPresent(sleepAnalysisMap, e.getId(), sa -> {
reportMonth.setSleepResult(sa.getSleepResult());
});
List<PlatElderSleepAnalysis> sleepAnalysesList = platElderSleepAnalysisService.list(new QueryWrapper<PlatElderSleepAnalysis>().lambda()
.in(PlatElderSleepAnalysis::getElderId, StreamUtil.mapId(elderList, PlatElder::getId))
.eq(PlatElderSleepAnalysis::getHappenDate, dateTimeFormatter.format(yesDate))
);
PlatDevice platDevice = platElderRealTimeService.getBreathDevice(e.getId(), null);
Map<String, PlatElderSleepAnalysis> sleepAnalysisMap = StreamUtil.toMap(sleepAnalysesList, PlatElderSleepAnalysis::getElderId);
List<DeviceInfoContentBreathe> breatheList = iotProductDeviceService.getDeviceLogByTimeRangeBreathe(platDevice.getOriDeviceId(), 2 * 24 * 3600, yesStart, yesEnd);
List<PlatAlarmRecord> recordList = platAlarmRecordService.list(new QueryWrapper<PlatAlarmRecord>().lambda()
.in(PlatAlarmRecord::getElderIds, StreamUtil.mapId(elderList, PlatElder::getId)));
if (CollectionUtils.isNotEmpty(breatheList)) {
Map<String, List<PlatAlarmRecord>> recordMap = StreamUtil.groupBy(recordList, PlatAlarmRecord::getElderIds);
reportMonth.setBreatheDeviceId(platDevice.getId());
reportMonth.setBreatheOriDeviceId(platDevice.getOriDeviceId());
for (PlatElder e : elderList) {
PlatElderReportMonth reportMonth = new PlatElderReportMonth();
reportMonth.setElderId(e.getId());
reportMonth.setDay(yesDate);
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()));
}
MapUtil.setIfPresent(sleepAnalysisMap, e.getId(), sa -> {
reportMonth.setSleepResult(sa.getSleepResult());
});
List<PlatAlarmRecord> rList = Optional.ofNullable(recordMap.get(e.getId())).orElse(new ArrayList<>(10));
PlatDevice platDevice = platElderRealTimeService.getBreathDevice(e.getId(), null);
if (platDevice == null) {
continue;
}
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())));
List<DeviceInfoContentBreathe> breatheList = iotProductDeviceService.getDeviceLogByTimeRangeBreathe(platDevice.getOriDeviceId(), 2 * 24 * 3600, yesStart, yesEnd);
reportMonthList.add(reportMonth);
if (CollectionUtils.isNotEmpty(breatheList)) {
});
reportMonth.setBreatheDeviceId(platDevice.getId());
reportMonth.setBreatheOriDeviceId(platDevice.getOriDeviceId());
saveBatch(reportMonthList);
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);
}
}
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