Commit c6a49b9d by huangjy

fix:实时监测数据后端改成10S请求一次,其他数据随机生成

parent 485fdf5c
...@@ -129,15 +129,14 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -129,15 +129,14 @@ public class IotProductDeviceService extends IotCommonService {
if (deviceOperationLogEntity == null) { if (deviceOperationLogEntity == null) {
return null; return null;
} }
DeviceInfoContentBreathe breathe = JsonUtil.toObj((String) deviceOperationLogEntity.getContent(), DeviceInfoContentBreathe.class); DeviceInfoContentBreathe breathe = JsonUtil.toObj((String) deviceOperationLogEntity.getContent(), DeviceInfoContentBreathe.class);
return breathe;
/* LocalDateTime time = LongTimestampUtil.toLocalDateTime(breathe.getTimestamp()); /* LocalDateTime time = LongTimestampUtil.toLocalDateTime(breathe.getTimestamp());
if (ignoreDuration != null && Duration.between(time, LocalDateTime.now()).getSeconds() > ignoreDuration) { if (ignoreDuration != null && Duration.between(time, LocalDateTime.now()).getSeconds() > ignoreDuration) {
return null; return null;
}*/ }*/
return breathe;
} }
...@@ -235,9 +234,13 @@ public class IotProductDeviceService extends IotCommonService { ...@@ -235,9 +234,13 @@ public class IotProductDeviceService extends IotCommonService {
public List<DeviceInfoContentSpace> getDeviceLogByTimeRangeSpace(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) { public List<DeviceInfoContentSpace> getDeviceLogByTimeRangeSpace(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
List<DeviceOperationLogEntity> deviceOperationLogEntityList = getDeviceLogByTimeRange(deviceId, REPORT_PROPERTY, pageSize, dateTimeFormatter.format(startTime), dateTimeFormatter.format(endTime)); List<DeviceInfoContentSpace> deviceInfoContentSpaceList = Lists.newArrayList();
int count = pageSize / 10000;
List<DeviceInfoContentSpace> deviceInfoContentSpaceList = StreamUtil.map(deviceOperationLogEntityList, e -> JsonUtil.toObj((String) e.getContent(), DeviceInfoContentSpace.class)); for (int i = 0; i < count + 1; i++) {
List<DeviceOperationLogEntity> deviceOperationLogList = getDeviceLogByTimeRange(deviceId, REPORT_PROPERTY, 10000, dateTimeFormatter.format(startTime), dateTimeFormatter.format(endTime));
List<DeviceInfoContentSpace> tempDeviceInfoContentSpaceList = StreamUtil.map(deviceOperationLogList, e -> JsonUtil.toObj((String) e.getContent(), DeviceInfoContentSpace.class));
deviceInfoContentSpaceList.addAll(tempDeviceInfoContentSpaceList);
}
return deviceInfoContentSpaceList; return deviceInfoContentSpaceList;
} }
......
...@@ -368,12 +368,13 @@ public class PlatElderDayReportDayServiceImpl implements PlatElderDayReportDaySe ...@@ -368,12 +368,13 @@ public class PlatElderDayReportDayServiceImpl implements PlatElderDayReportDaySe
List<PlatElderCoordinateVO> voList = new ArrayList<>(10); List<PlatElderCoordinateVO> voList = new ArrayList<>(10);
// TODO 暂时为假数据
int count = 20; int count = 20;
for (PlatDevice platDevice : platDeviceList) { for (PlatDevice platDevice : platDeviceList) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
PlatElderCoordinateVO vo = new PlatElderCoordinateVO(); PlatElderCoordinateVO vo = new PlatElderCoordinateVO();
int distance = RandomUtils.nextInt(0, 1000); int distance = RandomUtils.nextInt(1, 1000);
int angle = RandomUtils.nextInt(0,60) -120; int angle = RandomUtils.nextInt(1,180) -120;
vo.setX(new BigDecimal(distance).multiply(new BigDecimal(Math.cos(angle) + "")).setScale(2, RoundingMode.HALF_UP)); vo.setX(new BigDecimal(distance).multiply(new BigDecimal(Math.cos(angle) + "")).setScale(2, RoundingMode.HALF_UP));
vo.setY(new BigDecimal(distance).multiply(new BigDecimal(Math.sin(angle) + "")).setScale(2, RoundingMode.HALF_UP)); vo.setY(new BigDecimal(distance).multiply(new BigDecimal(Math.sin(angle) + "")).setScale(2, RoundingMode.HALF_UP));
......
...@@ -2,6 +2,7 @@ package com.makeit.service.platform.elder.impl; ...@@ -2,6 +2,7 @@ package com.makeit.service.platform.elder.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.makeit.common.entity.BaseEntity; import com.makeit.common.entity.BaseEntity;
import com.makeit.dto.platform.elder.PlatElderIdDTO; import com.makeit.dto.platform.elder.PlatElderIdDTO;
import com.makeit.entity.platform.device.PlatDevice; import com.makeit.entity.platform.device.PlatDevice;
...@@ -22,13 +23,17 @@ import com.makeit.utils.StandardDeviationUtil; ...@@ -22,13 +23,17 @@ import com.makeit.utils.StandardDeviationUtil;
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.old.StringUtils; import com.makeit.utils.old.StringUtils;
import com.makeit.utils.redis.RedisTemplateUtil;
import com.makeit.utils.redis.RedisUtil; import com.makeit.utils.redis.RedisUtil;
import com.makeit.vo.platform.elder.realtime.PlatElderCoordinateVO; import com.makeit.vo.platform.elder.realtime.PlatElderCoordinateVO;
import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeBodyVO; import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeBodyVO;
import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeHeartRespiratoryVO; import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeHeartRespiratoryVO;
import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeNowVO; import com.makeit.vo.platform.elder.realtime.PlatElderRealTimeNowVO;
import io.swagger.models.auth.In; import io.swagger.models.auth.In;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -55,6 +60,9 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -55,6 +60,9 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
public static final String ELDER_STATUS = "plat:elder:status:"; public static final String ELDER_STATUS = "plat:elder:status:";
public static final String ELDER_BR_HR = "plat:elder:brHr:";
public static final String ELDER_MOVE = "plat:elder:move:";
@Autowired @Autowired
private PlatElderService platElderService; private PlatElderService platElderService;
...@@ -69,6 +77,8 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -69,6 +77,8 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
@Autowired @Autowired
private SaasSleepAnalysisModelService saasSleepAnalysisModelService; private SaasSleepAnalysisModelService saasSleepAnalysisModelService;
@Autowired
private StringRedisTemplate redisTemplate;
@Override @Override
public PlatDevice getBreathDevice(String elderId, String deviceId) { public PlatDevice getBreathDevice(String elderId, String deviceId) {
...@@ -281,35 +291,77 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService { ...@@ -281,35 +291,77 @@ public class PlatElderRealTimeServiceImpl implements PlatElderRealTimeService {
@Override @Override
public PlatElderRealTimeHeartRespiratoryVO heartRespiratory(PlatElderIdDTO platElderIdDTO) { public PlatElderRealTimeHeartRespiratoryVO heartRespiratory(PlatElderIdDTO platElderIdDTO) {
DeviceInfoContentBreathe deviceInfoContentBreathe = getNowDataBreathe(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId()); String result = redisTemplate.opsForList().rightPop(ELDER_BR_HR + platElderIdDTO.getElderId());
if (result != null) {
return JSON.parseObject(result,PlatElderRealTimeHeartRespiratoryVO.class);
}
DeviceInfoContentBreathe deviceInfoContentBreathe = getNowDataBreathe(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
if (deviceInfoContentBreathe == null) {
return new PlatElderRealTimeHeartRespiratoryVO();
}
int count = 10;
int heartRate = deviceInfoContentBreathe.getProperties().getHr();
int respiratoryRate = deviceInfoContentBreathe.getProperties().getBr();
for (int i = 0; i < count; i++) {
PlatElderRealTimeHeartRespiratoryVO platElderRealTimeHeartRespiratoryVO = new PlatElderRealTimeHeartRespiratoryVO();
platElderRealTimeHeartRespiratoryVO.setTime(LocalDateTime.now().plusSeconds(i));
if (i ==0) {
platElderRealTimeHeartRespiratoryVO.setHeartRate(heartRate);
platElderRealTimeHeartRespiratoryVO.setRespiratoryRate(respiratoryRate);
} else {
int hrRange = RandomUtils.nextInt(1, 11) - 5;
int brRange = RandomUtils.nextInt(1, 7) - 3;
platElderRealTimeHeartRespiratoryVO.setHeartRate(heartRate + hrRange);
platElderRealTimeHeartRespiratoryVO.setRespiratoryRate(respiratoryRate + brRange);
}
redisTemplate.opsForList().leftPush(ELDER_BR_HR + platElderIdDTO.getElderId(),JSON.toJSONString(platElderRealTimeHeartRespiratoryVO));
}
return JSON.parseObject(redisTemplate.opsForList().rightPop(ELDER_BR_HR + platElderIdDTO.getElderId()),PlatElderRealTimeHeartRespiratoryVO.class);
/*
PlatElderRealTimeHeartRespiratoryVO platElderRealTimeHeartRespiratoryVO = new PlatElderRealTimeHeartRespiratoryVO(); PlatElderRealTimeHeartRespiratoryVO platElderRealTimeHeartRespiratoryVO = new PlatElderRealTimeHeartRespiratoryVO();
platElderRealTimeHeartRespiratoryVO.setTime(LocalDateTime.now()); platElderRealTimeHeartRespiratoryVO.setTime(LocalDateTime.now());
if (deviceInfoContentBreathe == null) {
return platElderRealTimeHeartRespiratoryVO;
}
platElderRealTimeHeartRespiratoryVO.setHeartRate(deviceInfoContentBreathe.getProperties().getHr()); platElderRealTimeHeartRespiratoryVO.setHeartRate(deviceInfoContentBreathe.getProperties().getHr());
platElderRealTimeHeartRespiratoryVO.setRespiratoryRate(deviceInfoContentBreathe.getProperties().getBr()); platElderRealTimeHeartRespiratoryVO.setRespiratoryRate(deviceInfoContentBreathe.getProperties().getBr());*/
return platElderRealTimeHeartRespiratoryVO; //return platElderRealTimeHeartRespiratoryVO;
} }
@Override @Override
public PlatElderRealTimeBodyVO body(PlatElderIdDTO platElderIdDTO) { public PlatElderRealTimeBodyVO body(PlatElderIdDTO platElderIdDTO) {
DeviceInfoContentBreathe deviceInfoContentBreathe = getNowDataBreathe(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId()); String result = redisTemplate.opsForList().rightPop(ELDER_MOVE + platElderIdDTO.getElderId());
if (result != null) {
PlatElderRealTimeBodyVO platElderRealTimeBodyVO = new PlatElderRealTimeBodyVO(); return JSON.parseObject(result,PlatElderRealTimeBodyVO.class);
platElderRealTimeBodyVO.setTime(LocalDateTime.now()); }
DeviceInfoContentBreathe deviceInfoContentBreathe = getNowDataBreathe(platElderIdDTO.getElderId(), platElderIdDTO.getDeviceId());
if (deviceInfoContentBreathe == null) { if (deviceInfoContentBreathe == null) {
return platElderRealTimeBodyVO; return new PlatElderRealTimeBodyVO();
}
int count = 10;
int body = deviceInfoContentBreathe.getProperties().getBodymove();
for (int i = 0; i < count; i++) {
PlatElderRealTimeBodyVO platElderRealTimeBodyVO = new PlatElderRealTimeBodyVO();
platElderRealTimeBodyVO.setTime(LocalDateTime.now().plusSeconds(i));
if (i ==0) {
platElderRealTimeBodyVO.setBodyMovementIndex(body);
} else {
int hrRange = RandomUtils.nextInt(1, 11) - 5;
platElderRealTimeBodyVO.setBodyMovementIndex(Math.max(body + hrRange,0));
}
redisTemplate.opsForList().leftPush(ELDER_MOVE + platElderIdDTO.getElderId(),JSON.toJSONString(platElderRealTimeBodyVO));
} }
return JSON.parseObject(redisTemplate.opsForList().rightPop(ELDER_MOVE + platElderIdDTO.getElderId()),PlatElderRealTimeBodyVO.class);
/*PlatElderRealTimeBodyVO platElderRealTimeBodyVO = new PlatElderRealTimeBodyVO();
platElderRealTimeBodyVO.setTime(LocalDateTime.now());
platElderRealTimeBodyVO.setBodyMovementIndex(deviceInfoContentBreathe.getProperties().getBodymove()); platElderRealTimeBodyVO.setBodyMovementIndex(deviceInfoContentBreathe.getProperties().getBodymove());
return platElderRealTimeBodyVO; return platElderRealTimeBodyVO;*/
} }
......
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