重构监测首页接口
This commit is contained in:
+83
@@ -0,0 +1,83 @@
|
||||
package com.renkang.watch;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.renkang.watch.vo.WatchH5IndexItemVo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class WatchH5IndexItemNewVo {
|
||||
@Schema(title = "数据类型")
|
||||
private String wdType;
|
||||
@Schema(title = "数据类型名称")
|
||||
private String wdTypeName;
|
||||
@Schema(title = "最新数据日期")
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date dataDate;
|
||||
/**
|
||||
* 注意 当wdType=sleep时此字段返回长睡时长
|
||||
*/
|
||||
@Schema(title = "监测数据最大值(当wdType=sleep时此字段返回长睡时长)")
|
||||
private String dataMax;
|
||||
/**
|
||||
*注意 当wdType=sleep时此字段返回短睡时长
|
||||
*/
|
||||
@Schema(title = "监测数据最小值(当wdType=sleep时此字段返回短睡时长)")
|
||||
private String dataMin;
|
||||
@Schema(title = "监测数据平均值")
|
||||
private String dataAvg;
|
||||
@Schema(title = "最新数据值")
|
||||
private String dataValue;
|
||||
@Schema(title = "最低阈值")
|
||||
private String warnMin;
|
||||
@Schema(title = "最高阈值")
|
||||
private String warnMax;
|
||||
|
||||
public String getDataAvg() {
|
||||
if(StrUtil.isNotEmpty(dataAvg)){
|
||||
try {
|
||||
return BigDecimal.valueOf(Double.parseDouble(dataAvg)).setScale(1, RoundingMode.HALF_UP).toString();
|
||||
} catch (NumberFormatException e) {
|
||||
return dataAvg;
|
||||
}
|
||||
}
|
||||
return dataAvg;
|
||||
}
|
||||
|
||||
public String getWdTypeName() {
|
||||
if (!StringUtils.hasLength(wdType)) {
|
||||
return "";
|
||||
}
|
||||
switch (wdType) {
|
||||
case "sleep":
|
||||
return "睡眠";
|
||||
case "steps":
|
||||
return "步数";
|
||||
case "heart_rate":
|
||||
return "心率";
|
||||
case "spo2":
|
||||
return "血氧饱和度";
|
||||
case "stress":
|
||||
return "压力";
|
||||
case "temperature":
|
||||
return "体温";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public void fieldCopy(WatchH5IndexItemVo watchH5IndexItemVo){
|
||||
this.setWarnMax(watchH5IndexItemVo.getWarnMax());
|
||||
this.setWarnMin(watchH5IndexItemVo.getWarnMin());
|
||||
this.setWdType(watchH5IndexItemVo.getWdType());
|
||||
this.setWdTypeName(watchH5IndexItemVo.getWdTypeName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.renkang.watch.vo;
|
||||
|
||||
import com.renkang.watch.WatchH5IndexItemNewVo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(title = "手表监测首页数据V2版本")
|
||||
public class WatchIndexNewVo {
|
||||
@Schema(title = "手表使用天数")
|
||||
private Integer days = 0;
|
||||
@Schema(title = "步行距离")
|
||||
private Integer distance;
|
||||
@Schema(title = "平均睡眠(所有数据求出的平均睡眠)")
|
||||
private Double aveSleep;
|
||||
@Schema(title = "各项指标数据")
|
||||
private List<WatchH5IndexItemNewVo> indexItemVos;
|
||||
}
|
||||
+6
@@ -35,6 +35,12 @@ public class WatchController {
|
||||
return Result.OK("成功", vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "手表监测数据首页信息", description = "手表监测数据首页信息(v2版本20251218重构)")
|
||||
@GetMapping(value = "/indexDataNew/v2")
|
||||
public Result<WatchIndexNewVo> getIndexDataV2(@RequestParam("userId") String userId) {
|
||||
return Result.OK(watchService.getIndexDataV2(userId));
|
||||
}
|
||||
|
||||
//-------------------------------------bustiw---------------------------------------------------\\
|
||||
@Operation(summary = "获取日睡眠列表(新)", description = "获取日睡眠列表(新)")
|
||||
@GetMapping(value = "/sleepNewDayData")
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.renkang.watch.data.model.vo.WearCount;
|
||||
import com.renkang.watch.dto.WatchDeviceDTO;
|
||||
import com.renkang.watch.entity.WatchData;
|
||||
@@ -27,7 +28,7 @@ import java.util.Set;
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface WatchDeviceMapper extends BaseMapper<WatchDevice> {
|
||||
public interface WatchDeviceMapper extends MPJBaseMapper<WatchDevice> {
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package com.renkang.watch.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.renkang.watch.dto.BigScreenDTO;
|
||||
import com.renkang.watch.entity.WatchStatUserInfoDayHeartRate;
|
||||
import com.renkang.watch.vo.BigScreenSleepVo;
|
||||
@@ -20,7 +21,7 @@ import java.util.List;
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface WatchStatUserInfoDayHeartRateMapper extends BaseMapper<WatchStatUserInfoDayHeartRate> {
|
||||
public interface WatchStatUserInfoDayHeartRateMapper extends MPJBaseMapper<WatchStatUserInfoDayHeartRate> {
|
||||
|
||||
/**
|
||||
* 年收据
|
||||
|
||||
+2
-4
@@ -1,13 +1,11 @@
|
||||
package com.renkang.watch.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.renkang.watch.entity.WatchStatUserInfoDaySleep;
|
||||
import com.renkang.watch.vo.UserData.res.sleep.WatchDataSleepRes;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -18,7 +16,7 @@ import java.util.List;
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface WatchStatUserInfoDaySleepMapper extends BaseMapper<WatchStatUserInfoDaySleep> {
|
||||
public interface WatchStatUserInfoDaySleepMapper extends MPJBaseMapper<WatchStatUserInfoDaySleep> {
|
||||
|
||||
List<WatchDataSleepRes> selectSleepByYear(@Param("dateYear") Date dateYear, @Param("userId")String userId);
|
||||
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package com.renkang.watch.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.renkang.watch.entity.WatchStatUserInfoDaySpo2;
|
||||
import com.renkang.watch.vo.UserData.res.bloodOxygen.BloodOxygenRes;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -16,7 +17,7 @@ import java.util.List;
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface WatchStatUserInfoDaySpo2Mapper extends BaseMapper<WatchStatUserInfoDaySpo2> {
|
||||
public interface WatchStatUserInfoDaySpo2Mapper extends MPJBaseMapper<WatchStatUserInfoDaySpo2> {
|
||||
|
||||
List<BloodOxygenRes> selectHeartRateByYear(@Param("dateYear") Date dateYear, @Param("userId")String userId);
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.renkang.watch.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.renkang.watch.entity.WatchStatUserInfoDayStress;
|
||||
import com.renkang.watch.vo.UserData.res.Stress.WatchDataStressRes;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface WatchStatUserInfoDayStressMapper extends BaseMapper<WatchStatUserInfoDayStress> {
|
||||
public interface WatchStatUserInfoDayStressMapper extends MPJBaseMapper<WatchStatUserInfoDayStress> {
|
||||
|
||||
/**
|
||||
* 年数据
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package com.renkang.watch.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.renkang.watch.entity.WatchStatUserInfoDayTemp;
|
||||
import com.renkang.watch.vo.UserData.res.bodyTemperature.BodyTempStatRes;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -16,7 +17,7 @@ import java.util.List;
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface WatchStatUserInfoDayTempMapper extends BaseMapper<WatchStatUserInfoDayTemp> {
|
||||
public interface WatchStatUserInfoDayTempMapper extends MPJBaseMapper<WatchStatUserInfoDayTemp> {
|
||||
|
||||
|
||||
List<BodyTempStatRes> selectTempByYear(@Param("dateYear") Date dateYear, @Param("userId")String userId);
|
||||
|
||||
+6
@@ -77,4 +77,10 @@ public interface IWatchService {
|
||||
|
||||
Result<?> thresholdSetting(String userId, String eventType, Double warnMax, Double warnMin);
|
||||
|
||||
/**
|
||||
*手表监测数据首页信息
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
WatchIndexNewVo getIndexDataV2(String userId);
|
||||
}
|
||||
|
||||
+253
-26
@@ -4,22 +4,26 @@ import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.renkang.datacenter.api.DataCenterExecutor;
|
||||
import com.renkang.datacenter.bean.Period;
|
||||
import com.renkang.datacenter.bean.WatchNo;
|
||||
import com.renkang.datacenter.bean.WatchSdcItemData;
|
||||
import com.renkang.watch.WatchH5IndexItemNewVo;
|
||||
import com.renkang.watch.dto.WatchDataDTO;
|
||||
import com.renkang.watch.dto.WatchWarnDTO;
|
||||
import com.renkang.watch.entity.*;
|
||||
import com.renkang.watch.mapper.*;
|
||||
import com.renkang.watch.service.IWatchService;
|
||||
import com.renkang.watch.vo.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
@@ -31,8 +35,11 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.task.AsyncTaskExecutor;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.Duration;
|
||||
@@ -41,6 +48,8 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -48,35 +57,50 @@ import java.util.stream.Stream;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class WatchServiceImpl implements IWatchService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(WatchServiceImpl.class);
|
||||
@Autowired
|
||||
private WatchMapper watchMapper;
|
||||
@Autowired
|
||||
private WatchDataStepsMapper stepsMapper;
|
||||
@Autowired
|
||||
private WatchDataDistanceMapper distanceMapper;
|
||||
@Autowired
|
||||
private WatchDataCalorieMapper calorieMapper;
|
||||
@Autowired
|
||||
private WatchBindHisMapper bindHisMapper;
|
||||
@Autowired
|
||||
private DataCenterExecutor dataCenterExecutor;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private WatchDataTemperatureMapper tempMapper;
|
||||
@Autowired
|
||||
private WatchDataHeartRateMapper rateMapper;
|
||||
@Autowired
|
||||
private WatchDataStressMapper stressMapper;
|
||||
@Autowired
|
||||
private WatchDataSpo2Mapper spo2Mapper;
|
||||
@Autowired
|
||||
private WatchStatUserInfoDaySdcMapper statSdcMapper;
|
||||
@Autowired
|
||||
private WatchDataWorkoutMapper watchDataWorkoutMapper;
|
||||
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm");
|
||||
private final WatchMapper watchMapper;
|
||||
private final WatchBindHisMapper bindHisMapper;
|
||||
private final DataCenterExecutor dataCenterExecutor;
|
||||
private final RedisUtil redisUtil;
|
||||
private final WatchDataTemperatureMapper tempMapper;
|
||||
private final WatchDataHeartRateMapper rateMapper;
|
||||
private final WatchDataStressMapper stressMapper;
|
||||
private final WatchDataSpo2Mapper spo2Mapper;
|
||||
private final WatchStatUserInfoDaySdcMapper statSdcMapper;
|
||||
private final WatchDataWorkoutMapper watchDataWorkoutMapper;
|
||||
private final WatchDeviceMapper watchDeviceMapper;
|
||||
private final WatchStatUserInfoDaySleepMapper daySleepMapper;
|
||||
private final WatchStatUserInfoDayHeartRateMapper dayHeartRateMapper;
|
||||
private final WatchStatUserInfoDaySpo2Mapper daySpo2Mapper;
|
||||
private final WatchStatUserInfoDayStressMapper dayStressMapper;
|
||||
private final WatchStatUserInfoDayTempMapper dayTempMapper;
|
||||
private AsyncTaskExecutor asyncTaskExecutor;
|
||||
|
||||
public AsyncTaskExecutor getAsyncTaskExecutor() {
|
||||
if (asyncTaskExecutor == null) {
|
||||
initAsyncExecutor();
|
||||
}
|
||||
return asyncTaskExecutor;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
initAsyncExecutor();
|
||||
}
|
||||
|
||||
private void initAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
|
||||
taskExecutor.setCorePoolSize(150);
|
||||
taskExecutor.setMaxPoolSize(500);
|
||||
taskExecutor.setQueueCapacity(500);
|
||||
taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
taskExecutor.setThreadNamePrefix("watch-latest-pool1-");
|
||||
taskExecutor.initialize();
|
||||
asyncTaskExecutor = taskExecutor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较两个日期
|
||||
@@ -435,6 +459,209 @@ public class WatchServiceImpl implements IWatchService {
|
||||
return indexVo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 此方法是对同类中getIndex()方法的重构 ,主要重构方向如下
|
||||
* 1.APP调用该接口的业务较多,此类中需要返回监测数据的最新值, 最大值, 最小值,平均值,getIndex()中只返回了最新值其他的数据都没有返回
|
||||
* -----之前前端最大最小值取的是用户设置的阈值 (warnMin,warnMax), 完全是错的, 平均是用阈值相加后除2
|
||||
* 2.getIndex()方法中查询的都是原始数据表, 效率很多, 现将部分数据改查日汇总表
|
||||
* 3.优化之前的代码逻辑结构 如将串行查询改为异步并行查询等
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public WatchIndexNewVo getIndexDataV2(String userId) {
|
||||
WatchIndexNewVo indexVo = new WatchIndexNewVo();
|
||||
//查询用户最新佩戴的手表信息 ,只有曾经绑定过手表才走后续的查询逻辑
|
||||
WatchBindHis watchBindHis = queryUserLatestBindHis(userId);
|
||||
if(ObjectUtil.isNotEmpty(watchBindHis)){
|
||||
//计算使用天数,未解绑计算绑定日期到现在的天数,已解绑计算绑计算绑定日期与解绑日期的天数
|
||||
if(ObjectUtil.isEmpty(watchBindHis.getBindEndDate())){
|
||||
indexVo.setDays((int)DateUtil.betweenDay(watchBindHis.getBindDate(),new Date(),true));
|
||||
}else {
|
||||
indexVo.setDays((int)DateUtil.betweenDay(watchBindHis.getBindDate(),watchBindHis.getBindEndDate(),true));
|
||||
}
|
||||
//调用数据中心查询阈值设置
|
||||
Result<Object> periodResult = dataCenterExecutor.getPeriod(WatchNo.of(watchBindHis.getWatchNo()));
|
||||
Stream<WatchH5IndexItemVo> itemVoStream = periodResult.isSuccess()
|
||||
? convertItems(periodResult.getResult())
|
||||
: emptyItems();
|
||||
//查询几项指标的最新数据,平均数据等
|
||||
List<WatchH5IndexItemNewVo> list = selectUserLatestData(itemVoStream,userId);
|
||||
indexVo.setIndexItemVos(list);
|
||||
//平均睡眠 (20251218重构后改变了平均睡眠的计算方式,之前查的原始数据表, 后查day表,且当天没有睡眠时间的不参与计算, 使用day表中的长睡时长计算平均值)
|
||||
indexVo.setAveSleep(queryAverageSleep(userId));
|
||||
//总的步行距离
|
||||
indexVo.setDistance(queryTotalDistance(userId));
|
||||
}
|
||||
return indexVo;
|
||||
}
|
||||
|
||||
private List<WatchH5IndexItemNewVo> selectUserLatestData(Stream<WatchH5IndexItemVo> voStream,String userId) {
|
||||
List<WatchH5IndexItemNewVo> list = new ArrayList<>();
|
||||
//异步并行查询几种监测数据的最新结果
|
||||
CompletableFuture<WatchH5IndexItemNewVo> futureSleepData = CompletableFuture.supplyAsync(() ->
|
||||
latestSleepData(userId),getAsyncTaskExecutor());
|
||||
CompletableFuture<WatchH5IndexItemNewVo> futureStepsData = CompletableFuture.supplyAsync(() ->
|
||||
latestStepsData(userId),getAsyncTaskExecutor());
|
||||
CompletableFuture<WatchH5IndexItemNewVo> futureHeartRateData = CompletableFuture.supplyAsync(() ->
|
||||
latestHeartRateData(userId),getAsyncTaskExecutor());
|
||||
CompletableFuture<WatchH5IndexItemNewVo> futureSpo2Data = CompletableFuture.supplyAsync(() ->
|
||||
latestSpo2Data(userId),getAsyncTaskExecutor());
|
||||
CompletableFuture<WatchH5IndexItemNewVo> futureStressData = CompletableFuture.supplyAsync(() ->
|
||||
latestStressData(userId),getAsyncTaskExecutor());
|
||||
CompletableFuture<WatchH5IndexItemNewVo> futureTempData = CompletableFuture.supplyAsync(() ->
|
||||
latestTempData(userId),getAsyncTaskExecutor());
|
||||
CompletableFuture.allOf(futureSleepData,futureStepsData,futureHeartRateData, futureSpo2Data,futureStressData,futureTempData).join();
|
||||
//转换结果,填充数据
|
||||
voStream.forEach(watchH5IndexItemVo -> {
|
||||
try {
|
||||
switch (watchH5IndexItemVo.getWdType()) {
|
||||
case "sleep":
|
||||
WatchH5IndexItemNewVo sleepData = futureSleepData.get();
|
||||
sleepData.fieldCopy(watchH5IndexItemVo);
|
||||
list.add(sleepData);
|
||||
break;
|
||||
case "steps":
|
||||
WatchH5IndexItemNewVo stepsData = futureStepsData.get();
|
||||
stepsData.fieldCopy(watchH5IndexItemVo);
|
||||
list.add(stepsData);
|
||||
break;
|
||||
case "heart_rate":
|
||||
WatchH5IndexItemNewVo heartData = futureHeartRateData.get();
|
||||
heartData.fieldCopy(watchH5IndexItemVo);
|
||||
list.add(heartData);
|
||||
break;
|
||||
case "spo2":
|
||||
WatchH5IndexItemNewVo apo2Data = futureSpo2Data.get();
|
||||
apo2Data.fieldCopy(watchH5IndexItemVo);
|
||||
list.add(apo2Data);
|
||||
break;
|
||||
case "stress":
|
||||
WatchH5IndexItemNewVo stressData = futureStressData.get();
|
||||
stressData.fieldCopy(watchH5IndexItemVo);
|
||||
list.add(stressData);
|
||||
break;
|
||||
case "temperature":
|
||||
WatchH5IndexItemNewVo tempData = futureTempData.get();
|
||||
tempData.fieldCopy(watchH5IndexItemVo);
|
||||
list.add(tempData);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
private WatchH5IndexItemNewVo latestSleepData(String userId) {
|
||||
MPJLambdaWrapper<WatchStatUserInfoDaySleep> wrapper = new MPJLambdaWrapper<>();
|
||||
//因为睡眠详情页取的是长睡时长作为当天的睡眠时间 , 所以这里保持一致并没有取当天的睡眠总时长
|
||||
wrapper.selectAs(WatchStatUserInfoDaySleep::getLongDurationTotal,WatchH5IndexItemNewVo::getDataValue);
|
||||
wrapper.selectAs(WatchStatUserInfoDaySleep::getLongDurationTotal,WatchH5IndexItemNewVo::getDataMax);
|
||||
wrapper.selectAs(WatchStatUserInfoDaySleep::getShortDurationTotal,WatchH5IndexItemNewVo::getDataMin);
|
||||
wrapper.selectAs(WatchStatUserInfoDaySleep::getDataDate,WatchH5IndexItemNewVo::getDataDate);
|
||||
wrapper.eq(WatchStatUserInfoDaySleep::getUserId, userId);
|
||||
wrapper.orderByDesc(WatchStatUserInfoDaySleep::getDataDate);
|
||||
wrapper.last("limit 1");
|
||||
return daySleepMapper.selectJoinOne(WatchH5IndexItemNewVo.class,wrapper);
|
||||
}
|
||||
|
||||
private WatchH5IndexItemNewVo latestStepsData(String userId) {
|
||||
//当天的步数没有平均值 最大最小的概念, 只用查当天的步数即可
|
||||
MPJLambdaWrapper<WatchStatUserInfoDaySdc> wrapper = new MPJLambdaWrapper<>();
|
||||
wrapper.selectAs(WatchStatUserInfoDaySdc::getStepValue,WatchH5IndexItemNewVo::getDataValue);
|
||||
wrapper.selectAs(WatchStatUserInfoDaySdc::getDataDate,WatchH5IndexItemNewVo::getDataDate);
|
||||
wrapper.eq(WatchStatUserInfoDaySdc::getUserId, userId);
|
||||
wrapper.orderByDesc(WatchStatUserInfoDaySdc::getDataDate);
|
||||
wrapper.last("limit 1");
|
||||
return statSdcMapper.selectJoinOne(WatchH5IndexItemNewVo.class,wrapper);
|
||||
}
|
||||
|
||||
private WatchH5IndexItemNewVo latestHeartRateData(String userId) {
|
||||
MPJLambdaWrapper<WatchStatUserInfoDayHeartRate> wrapper = new MPJLambdaWrapper<>();
|
||||
// 必须是watch_stat_user_info_day_heart_rate表中new_data字段启用后才能这样查
|
||||
wrapper.selectAs(WatchStatUserInfoDayHeartRate::getNewValue,WatchH5IndexItemNewVo::getDataValue);
|
||||
wrapper.selectAs(WatchStatUserInfoDayHeartRate::getMaxValue,WatchH5IndexItemNewVo::getDataMax);
|
||||
wrapper.selectAs(WatchStatUserInfoDayHeartRate::getMinValue,WatchH5IndexItemNewVo::getDataMin);
|
||||
wrapper.selectAs(WatchStatUserInfoDayHeartRate::getAvgValue,WatchH5IndexItemNewVo::getDataAvg);
|
||||
wrapper.selectAs(WatchStatUserInfoDayHeartRate::getDataDate,WatchH5IndexItemNewVo::getDataDate);
|
||||
wrapper.eq(WatchStatUserInfoDayHeartRate::getUserId, userId);
|
||||
wrapper.orderByDesc(WatchStatUserInfoDayHeartRate::getDataDate);
|
||||
wrapper.last("limit 1");
|
||||
return dayHeartRateMapper.selectJoinOne(WatchH5IndexItemNewVo.class,wrapper);
|
||||
}
|
||||
|
||||
private WatchH5IndexItemNewVo latestSpo2Data(String userId) {
|
||||
MPJLambdaWrapper<WatchStatUserInfoDaySpo2> wrapper = new MPJLambdaWrapper<>();
|
||||
// 必须是watch_stat_user_info_day_spo2表中new_data字段启用后才能这样查
|
||||
wrapper.selectAs(WatchStatUserInfoDaySpo2::getNewValue,WatchH5IndexItemNewVo::getDataValue);
|
||||
wrapper.selectAs(WatchStatUserInfoDaySpo2::getMaxValue,WatchH5IndexItemNewVo::getDataMax);
|
||||
wrapper.selectAs(WatchStatUserInfoDaySpo2::getMinValue,WatchH5IndexItemNewVo::getDataMin);
|
||||
wrapper.selectAs(WatchStatUserInfoDaySpo2::getAvgValue,WatchH5IndexItemNewVo::getDataAvg);
|
||||
wrapper.selectAs(WatchStatUserInfoDaySpo2::getDataDate,WatchH5IndexItemNewVo::getDataDate);
|
||||
wrapper.eq(WatchStatUserInfoDaySpo2::getUserId, userId);
|
||||
wrapper.orderByDesc(WatchStatUserInfoDaySpo2::getDataDate);
|
||||
wrapper.last("limit 1");
|
||||
return daySpo2Mapper.selectJoinOne(WatchH5IndexItemNewVo.class,wrapper);
|
||||
}
|
||||
|
||||
private WatchH5IndexItemNewVo latestStressData(String userId) {
|
||||
MPJLambdaWrapper<WatchStatUserInfoDayStress> wrapper = new MPJLambdaWrapper<>();
|
||||
// 必须是watch_stat_user_info_day_stress表中new_data字段启用后才能这样查
|
||||
wrapper.selectAs(WatchStatUserInfoDayStress::getNewValue,WatchH5IndexItemNewVo::getDataValue);
|
||||
wrapper.selectAs(WatchStatUserInfoDayStress::getMaxValue,WatchH5IndexItemNewVo::getDataMax);
|
||||
wrapper.selectAs(WatchStatUserInfoDayStress::getMinValue,WatchH5IndexItemNewVo::getDataMin);
|
||||
wrapper.selectAs(WatchStatUserInfoDayStress::getAvgValue,WatchH5IndexItemNewVo::getDataAvg);
|
||||
wrapper.selectAs(WatchStatUserInfoDayStress::getDataDate,WatchH5IndexItemNewVo::getDataDate);
|
||||
wrapper.eq(WatchStatUserInfoDayStress::getUserId, userId);
|
||||
wrapper.orderByDesc(WatchStatUserInfoDayStress::getDataDate);
|
||||
wrapper.last("limit 1");
|
||||
return dayStressMapper.selectJoinOne(WatchH5IndexItemNewVo.class,wrapper);
|
||||
}
|
||||
|
||||
private WatchH5IndexItemNewVo latestTempData(String userId) {
|
||||
MPJLambdaWrapper<WatchStatUserInfoDayTemp> wrapper = new MPJLambdaWrapper<>();
|
||||
// 必须是watch_stat_user_info_day_temp表中new_data字段启用后才能这样查
|
||||
wrapper.selectAs(WatchStatUserInfoDayTemp::getNewValue,WatchH5IndexItemNewVo::getDataValue);
|
||||
wrapper.selectAs(WatchStatUserInfoDayTemp::getMaxValue,WatchH5IndexItemNewVo::getDataMax);
|
||||
wrapper.selectAs(WatchStatUserInfoDayTemp::getMinValue,WatchH5IndexItemNewVo::getDataMin);
|
||||
wrapper.selectAs(WatchStatUserInfoDayTemp::getAvgValue,WatchH5IndexItemNewVo::getDataAvg);
|
||||
wrapper.selectAs(WatchStatUserInfoDayTemp::getDataDate,WatchH5IndexItemNewVo::getDataDate);
|
||||
wrapper.eq(WatchStatUserInfoDayTemp::getUserId, userId);
|
||||
wrapper.orderByDesc(WatchStatUserInfoDayTemp::getDataDate);
|
||||
wrapper.last("limit 1");
|
||||
return dayTempMapper.selectJoinOne(WatchH5IndexItemNewVo.class,wrapper);
|
||||
}
|
||||
|
||||
|
||||
private WatchBindHis queryUserLatestBindHis(String userId) {
|
||||
LambdaQueryWrapper<WatchBindHis> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(WatchBindHis::getBindUserId, userId);
|
||||
wrapper.orderByDesc(WatchBindHis::getBindDate);
|
||||
wrapper.last("limit 1");
|
||||
return bindHisMapper.selectOne(wrapper);
|
||||
}
|
||||
|
||||
private Double queryAverageSleep(String userId) {
|
||||
MPJLambdaWrapper<WatchStatUserInfoDaySleep> wrapper = new MPJLambdaWrapper<>();
|
||||
wrapper.selectAvg(WatchStatUserInfoDaySleep::getLongDurationTotal,WatchIndexNewVo::getAveSleep);
|
||||
wrapper.eq(WatchStatUserInfoDaySleep::getUserId, userId);
|
||||
wrapper.isNotNull(WatchStatUserInfoDaySleep::getLongDurationTotal);
|
||||
WatchIndexVo vo = daySleepMapper.selectJoinOne(WatchIndexVo.class,wrapper);
|
||||
return vo.getAveSleep();
|
||||
}
|
||||
|
||||
private Integer queryTotalDistance(String userId) {
|
||||
MPJLambdaWrapper<WatchStatUserInfoDaySdc> wrapper = new MPJLambdaWrapper<>();
|
||||
wrapper.selectSum(WatchStatUserInfoDaySdc::getDistanceValue,WatchIndexVo::getDistance);
|
||||
wrapper.eq(WatchStatUserInfoDaySdc::getUserId, userId);
|
||||
WatchIndexVo vo = statSdcMapper.selectJoinOne(WatchIndexVo.class,wrapper);
|
||||
return vo.getDistance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WatchH5SleepNewDayVo getSleepNewDayVo(String userId, Date queryDate, List<Date> hasDayList) {
|
||||
WatchH5SleepNewDayVo watchH5SleepDayVo = new WatchH5SleepNewDayVo();
|
||||
|
||||
Reference in New Issue
Block a user