Commit bb3ec1af by 汪志阳

fix:bug fix

parent 068b485f
package com.makeit.service.platform.elder; package com.makeit.service.platform.elder;
import com.makeit.module.iot.vo.DeviceOperationLogEntity;
import com.makeit.module.iot.vo.analysis.AnalysisVO; import com.makeit.module.iot.vo.analysis.AnalysisVO;
import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
/** /**
...@@ -14,7 +13,7 @@ import java.util.TreeMap; ...@@ -14,7 +13,7 @@ import java.util.TreeMap;
*/ */
public interface DeviceLogService { public interface DeviceLogService {
void save(Map<String, List<DeviceInfoContentBreathe>> minuteMap); void save(List<DeviceOperationLogEntity> list);
void saveEntity(TreeMap<String, AnalysisVO> statisticsMap, String id); void saveEntity(TreeMap<String, AnalysisVO> statisticsMap, String id);
......
...@@ -7,17 +7,23 @@ import com.google.common.collect.Lists; ...@@ -7,17 +7,23 @@ import com.google.common.collect.Lists;
import com.makeit.dto.SaveLogDTO; import com.makeit.dto.SaveLogDTO;
import com.makeit.exception.BusinessException; import com.makeit.exception.BusinessException;
import com.makeit.mapper.platform.auth.PlatOrgMapper; import com.makeit.mapper.platform.auth.PlatOrgMapper;
import com.makeit.module.iot.vo.DeviceOperationLogEntity;
import com.makeit.module.iot.vo.analysis.AnalysisVO; import com.makeit.module.iot.vo.analysis.AnalysisVO;
import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe; import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe;
import com.makeit.service.platform.elder.DeviceLogService; import com.makeit.service.platform.elder.DeviceLogService;
import com.makeit.utils.data.convert.JsonUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.TreeMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -33,32 +39,45 @@ public class DeviceLogServiceImpl implements DeviceLogService { ...@@ -33,32 +39,45 @@ public class DeviceLogServiceImpl implements DeviceLogService {
@Override @Override
public void save(Map<String, List<DeviceInfoContentBreathe>> minuteMap) { public void save(List<DeviceOperationLogEntity> list) {
if (CollUtil.isEmpty(minuteMap)) { if (CollUtil.isEmpty(list)) {
return; return;
} }
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
List<SaveLogDTO> saveList = new ArrayList<>(); List<SaveLogDTO> saveList = new ArrayList<>();
minuteMap.forEach((k, v) -> {
list.forEach(l -> {
v.forEach(value -> { SaveLogDTO saveLogDTO = new SaveLogDTO();
SaveLogDTO saveLogDTO = new SaveLogDTO(); long timestamp = l.getTimestamp();
saveLogDTO.setReportTime(LocalDateTime.parse(k, fmt)); String time = formatLongTime(timestamp);
saveLogDTO.setCreatedTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(value.getTimestamp()), ZoneId.systemDefault())); saveLogDTO.setReportTime(LocalDateTime.parse(time, fmt));
DeviceInfoContentBreathe.Properties properties = value.getProperties(); saveLogDTO.setCreatedTime(longToTime(timestamp));
saveLogDTO.setBodyMove(properties.getBodymove()); DeviceInfoContentBreathe deviceInfoContentBreathe = JsonUtil.toObj((String) l.getContent(), DeviceInfoContentBreathe.class);
saveLogDTO.setBr(properties.getBr()); DeviceInfoContentBreathe.Properties properties = deviceInfoContentBreathe.getProperties();
saveLogDTO.setDeviceId(value.getDeviceId()); saveLogDTO.setBodyMove(properties.getBodymove());
saveLogDTO.setHr(properties.getHr()); saveLogDTO.setBr(properties.getBr());
saveLogDTO.setPerson(properties.getPerson()); saveLogDTO.setDeviceId(deviceInfoContentBreathe.getDeviceId());
saveLogDTO.setMessageType(value.getMessageType()); saveLogDTO.setHr(properties.getHr());
saveLogDTO.setPersonState(properties.getPersonState()); saveLogDTO.setPerson(properties.getPerson());
saveList.add(saveLogDTO); saveLogDTO.setMessageType(deviceInfoContentBreathe.getMessageType());
}); saveLogDTO.setPersonState(properties.getPersonState());
saveList.add(saveLogDTO);
}); });
platOrgMapper.insertBatch(saveList); platOrgMapper.insertBatch(saveList);
} }
private static final DateTimeFormatter DEFAULT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
public static String formatLongTime(long time) {
return DEFAULT_FORMATTER.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()));
}
private LocalDateTime longToTime(Long longTime) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(longTime), ZoneOffset.of("+8"));
}
@Override @Override
public void saveEntity(TreeMap<String, AnalysisVO> statisticsMap, String id) { public void saveEntity(TreeMap<String, AnalysisVO> statisticsMap, String id) {
List<AnalysisVO> list = new ArrayList<>(); List<AnalysisVO> list = new ArrayList<>();
......
...@@ -47,7 +47,10 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -47,7 +47,10 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.*; import java.time.*;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -117,6 +120,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -117,6 +120,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
// 清醒每分钟体动是否满足要求 (每分钟体动值大于60或无人) // 清醒每分钟体动是否满足要求 (每分钟体动值大于60或无人)
boolean awakeMinuteActionFlag = false; boolean awakeMinuteActionFlag = false;
int noPersonCount = 0; // 无人跳过计数 int noPersonCount = 0; // 无人跳过计数
boolean isLive = false;
for (DeviceInfoContentBreathe infoContentBreathe : deviceInfoContentBreathes) { for (DeviceInfoContentBreathe infoContentBreathe : deviceInfoContentBreathes) {
// 体动指数 // 体动指数
breatheProperties = infoContentBreathe.getProperties(); breatheProperties = infoContentBreathe.getProperties();
...@@ -124,12 +128,19 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -124,12 +128,19 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
int br = breatheProperties.getBr(); int br = breatheProperties.getBr();
int hr = breatheProperties.getHr(); int hr = breatheProperties.getHr();
Integer hasPerson = breatheProperties.getPerson(); // 0无人,1有人 Integer hasPerson = breatheProperties.getPerson(); // 0无人,1有人
if (hasPerson == 0) { if (hasPerson == 0 && !isLive) {
noPersonCount++; noPersonCount++;
isMoveBed = true; isMoveBed = true;
awakeMinuteActionFlag = true; awakeMinuteActionFlag = true;
// continue; // continue;
} }
if (hasPerson == 1) {
totalBr += br;
totalHr += hr;
hrBrCount++;
isMoveBed = false;
isLive = true;
}
// 0和255直接跳过 // 0和255直接跳过
if (breatheProperties.getHr() == 255 || breatheProperties.getHr() == 0) { if (breatheProperties.getHr() == 255 || breatheProperties.getHr() == 0) {
noPersonCount++; noPersonCount++;
...@@ -173,11 +184,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -173,11 +184,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
} else if (hr < minHr) { } else if (hr < minHr) {
minHr = hr; minHr = hr;
} }
if (hasPerson == 1) {
totalBr += br;
totalHr += hr;
hrBrCount++;
}
} }
// if (reportSize == noPersonCount) { // if (reportSize == noPersonCount) {
// // continue; // // continue;
...@@ -879,15 +886,17 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -879,15 +886,17 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
PlatElder elder = platElderService.getOne(new QueryWrapper<PlatElder>().lambda() PlatElder elder = platElderService.getOne(new QueryWrapper<PlatElder>().lambda()
.eq(PlatElder::getBedId, bedId)); .eq(PlatElder::getBedId, bedId));
// || !"1712648603580764161".equals(elder.getId()) // || !"1712648603580764161".equals(elder.getId())
if (elder == null ) { if (elder == null || !"1712648603580764161".equals(elder.getId()) ) {
continue; continue;
} }
PlatDevice platDevice = platDeviceService.getById(platRoomBedDevice.getDeviceId()); PlatDevice platDevice = platDeviceService.getById(platRoomBedDevice.getDeviceId());
// || !"218A00XE2669104".equals(platDevice.getOriDeviceId()) // || !"218A00XE2669104".equals(platDevice.getOriDeviceId())
if (platDevice == null ) { if (platDevice == null || !"218A00XE2669104".equals(platDevice.getOriDeviceId())) {
continue; continue;
} }
String tenantId = elder.getTenantId(); String tenantId = elder.getTenantId();
// dayHourRangeList = Lists.newArrayList("2024-01-30 09:45:00~2024-01-30 09:45:10");
for (String hourRange : dayHourRangeList) { for (String hourRange : dayHourRangeList) {
String[] hourRangeArray = hourRange.split("~"); 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]);
...@@ -903,6 +912,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -903,6 +912,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
return deviceInfoContentBreathe; return deviceInfoContentBreathe;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
Map<String, List<DeviceInfoContentBreathe>> minuteMap = StreamUtil.groupBy(deviceInfoContentBreatheList, DeviceInfoContentBreathe::getReportTime); Map<String, List<DeviceInfoContentBreathe>> minuteMap = StreamUtil.groupBy(deviceInfoContentBreatheList, DeviceInfoContentBreathe::getReportTime);
deviceLogService.save(deviceOperationLogEntities);
deviceOperationLogEntities.clear(); deviceOperationLogEntities.clear();
TreeMap<String, AnalysisVO> statisticsMap = getPerMinuteData(minuteMap, analysisModel); TreeMap<String, AnalysisVO> statisticsMap = getPerMinuteData(minuteMap, analysisModel);
if (CollUtil.isNotEmpty(statisticsMap)) { if (CollUtil.isNotEmpty(statisticsMap)) {
...@@ -1002,7 +1012,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper, ...@@ -1002,7 +1012,7 @@ public class PlatElderSleepServiceImpl extends ServiceImpl<PlatElderSleepMapper,
return DEFAULT_FORMATTER.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault())); return DEFAULT_FORMATTER.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()));
} }
public List<String> getLastDayHourRange(Integer month, Integer day) { public static List<String> getLastDayHourRange(Integer month, Integer day) {
int count = 24; int count = 24;
LocalDateTime localDateTime = LocalDateTime.now(); LocalDateTime localDateTime = LocalDateTime.now();
if (month != null && day != null) { if (month != null && day != null) {
......
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