Commit cc7b9fa8 by 汪志阳

fix:bug修改

parent 58bbfd5d
......@@ -49,6 +49,8 @@ public class AnalysisVO {
private int hrSlow; // 当前心率
private String hrSlowTime; // 发生时间
private String createdTime;
// private Integer sleepDeepMinuteCount; // 深睡每分钟体动和翻身次数
......
......@@ -17,6 +17,10 @@ public class SleepTimeAnalysisVO {
*/
private String endTime;
private String getUpTime;
private String remark;
/**
* 间隔时间(分钟)
*/
......
package com.makeit.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.time.LocalDateTime;
/**
* @author wangzy
* @description
* @createDate 2024-01-24-16:42
*/
@Data
public class SaveLogDTO {
@JsonProperty("messageType")
private String messageType;
@JsonProperty("deviceId")
private String deviceId;
@JsonProperty("reportTime")
private LocalDateTime reportTime;
@JsonProperty("createdTime")
private LocalDateTime createdTime;
@JsonProperty("br")
private Integer br;
@JsonProperty("bodyMove")
private Integer bodyMove;
@JsonProperty("personState")
private Integer personState;
@JsonProperty("person")
private Integer person;
@JsonProperty("hr")
private Integer hr;
}
......@@ -2,7 +2,10 @@ package com.makeit.mapper.platform.auth;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.makeit.dto.SaveLogDTO;
import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.module.iot.vo.analysis.AnalysisVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -15,4 +18,10 @@ import java.util.List;
public interface PlatOrgMapper extends BaseMapper<PlatOrg> {
List<PlatOrg> getSelfAndParents(String id);
void insertBatch(@Param("list") List<SaveLogDTO> saveList);
void saveBatch(@Param("list")List<AnalysisVO> list);
List<AnalysisVO> getData();
}
package com.makeit.service.platform.elder;
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;
/**
* @author wangzy
* @description
* @createDate 2024-01-24-16:38
*/
public interface TestLogService {
void save(Map<String, List<DeviceInfoContentBreathe>> minuteMap);
void saveEntity(TreeMap<String, AnalysisVO> statisticsMap);
TreeMap<String, AnalysisVO> getData();
void fillDefaultData(TreeMap<String, AnalysisVO> statisticsMap);
}
package com.makeit.service.platform.elder.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.google.common.collect.Lists;
import com.makeit.dto.SaveLogDTO;
import com.makeit.mapper.platform.auth.PlatOrgMapper;
import com.makeit.module.iot.vo.analysis.AnalysisVO;
import com.makeit.module.iot.vo.breathe.DeviceInfoContentBreathe;
import com.makeit.service.platform.elder.TestLogService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author wangzy
* @description
* @createDate 2024-01-24-16:38
*/
@Service
public class TestLogServiceImpl implements TestLogService {
@Resource
private PlatOrgMapper platOrgMapper;
@Override
public void save(Map<String, List<DeviceInfoContentBreathe>> minuteMap) {
if (CollUtil.isEmpty(minuteMap)) {
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);
});
});
platOrgMapper.insertBatch(saveList);
}
@Override
public void saveEntity(TreeMap<String, AnalysisVO> statisticsMap) {
List<AnalysisVO> list = new ArrayList<>();
statisticsMap.forEach((k,v) -> {
v.setCreatedTime(k);
list.add(v);
});
platOrgMapper.saveBatch(list);
}
@Override
public TreeMap<String, AnalysisVO> getData() {
List<AnalysisVO> data = platOrgMapper.getData();
LinkedHashMap<String, AnalysisVO> collect1 = data.stream().collect(Collectors.toMap(AnalysisVO::getCreatedTime, a -> a, (u, v) -> {
throw new IllegalStateException(String.format("Duplicate key %s", u));
}, LinkedHashMap::new));
TreeMap<String, AnalysisVO> result = new TreeMap<>();
collect1.forEach(result::put);
getDayMinute().forEach(minute -> {
boolean key = result.containsKey(minute);
if (!key) {
AnalysisVO analysisVO = buildDefaultData(minute);
result.put(minute, analysisVO);
}
});
return result;
}
public static List<String> getDayMinute() {
List<String> list = Lists.newArrayList();
LocalDateTime now = LocalDateTime.of(2024, 1, 9, 8, 0);
for (int i = 0; i < 24; i++) {
int hour = now.getHour();
for (int j = 0; j < 60; j++) {
LocalDateTime of = LocalDateTime.of(2024, 1, now.getDayOfMonth(), hour, j);
list.add(DateUtil.format(of, DatePattern.NORM_DATETIME_MINUTE_PATTERN));
}
now = now.plusHours(1);
}
return list;
}
@Override
public void fillDefaultData(TreeMap<String, AnalysisVO> statisticsMap) {
List<String> dayMinute = getDayMinute();
dayMinute.forEach(minute -> {
boolean key = statisticsMap.containsKey(minute);
if (!key) {
AnalysisVO analysisVO = buildDefaultData(minute);
statisticsMap.put(minute, analysisVO);
}
});
}
private AnalysisVO buildDefaultData(String minute) {
AnalysisVO analysisVO = new AnalysisVO();
analysisVO.setCreatedTime(minute);
analysisVO.setActionCount(0);
analysisVO.setAvgBr(0);
analysisVO.setAvgHr(0);
analysisVO.setIsAction(false);
analysisVO.setIsMinuteActionFlag(false);
analysisVO.setIsMoveBed(true);
analysisVO.setAwakeMinuteActionFlag(false);
return analysisVO;
}
}
......@@ -19,4 +19,46 @@
ON T1._id COLLATE utf8mb4_general_ci = T2.id COLLATE utf8mb4_general_ci
</select>
<!-- 批量插入数据 查询主键ID注入到是实体中-->
<insert id="insertBatch" parameterType="java.util.List" useGeneratedKeys="true">
<selectKey resultType="long" keyProperty="id" order="AFTER">
SELECT
LAST_INSERT_ID()
</selectKey>
insert into device_info_log
(message_type,device_id,report_time,br,body_move,person_state,person,hr,created_time)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.messageType},#{item.deviceId},#{item.reportTime},#{item.br},#{item.bodyMove},
#{item.personState},#{item.person},#{item.hr},#{item.createdTime})
</foreach>
</insert>
<insert id="saveBatch" parameterType="java.util.List" useGeneratedKeys="true">
<selectKey resultType="long" keyProperty="id" order="AFTER">
SELECT
LAST_INSERT_ID()
</selectKey>
insert into device_minute_info(total_hr, avg_hr, max_hr, min_hr, total_br, avg_br, max_br, min_br, hr_br_count,
action_count, turned_count, is_action, is_move_bed, is_minute_action_flag,
awake_minute_action_flag, br_stop_threshold, br_stop, br_stop_time, br_fast_threshold,
br_fast, br_fast_time, br_slow_threshold, br_slow, br_slow_time, hr_fast_threshold,
hr_fast, hr_fast_time, hr_slow_threshold, hr_slow, hr_slow_time, created_time)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.totalHr},#{item.avgHr},#{item.maxHr},#{item.minHr},#{item.totalBr},#{item.avgBr},#{item.maxBr},#{item.minBr},#{item.hrBrCount},
#{item.actionCount},#{item.turnedCount},#{item.isAction},#{item.isMoveBed},#{item.isMinuteActionFlag},
#{item.awakeMinuteActionFlag},#{item.brStopThreshold},#{item.brStop},#{item.brStopTime},#{item.brFastThreshold},
#{item.brFast},#{item.brFastTime},#{item.brSlowThreshold},#{item.brSlow},#{item.brSlowTime},#{item.hrFastThreshold},
#{item.hrFast},#{item.hrFastTime},#{item.hrSlowThreshold},#{item.hrSlow},#{item.hrSlowTime},#{item.createdTime})
</foreach>
</insert>
<select id="getData" resultType="com.makeit.module.iot.vo.analysis.AnalysisVO">
select * from device_minute_info group by created_time order by created_time
</select>
</mapper>
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