Commit bb3ec1af by 汪志阳

fix:bug fix

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