|
@ -26,9 +26,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created by yeshijie on 2020/5/11.
|
|
@ -915,87 +915,101 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
|
|
|
@RequestMapping(value = "getSportRecord",method = {RequestMethod.POST,RequestMethod.GET})
|
|
|
public Envelop getSportRecord(
|
|
|
@ApiParam(name="patient",value="i健康居民code",defaultValue = "0fab4dd67e074e16ac86db6b6c15233e") @RequestParam(value = "patient", required = false)String patient,
|
|
|
@ApiParam(name="startDate",value="开始日期,如2020-05-09",defaultValue = "2020-05-09") @RequestParam(value = "startDate", required = false)String startDate,
|
|
|
@ApiParam(name="endDate",value="结束日期,如2020-05-10",defaultValue = "2020-05-10") @RequestParam(value = "endDate", required = false)String endDate
|
|
|
@ApiParam(name="date",value="开始日期,如2020-05-09",defaultValue = "2020-05-09") @RequestParam(value = "date", required = false)String date,
|
|
|
@ApiParam(name="type",value="大屏选择项",defaultValue = "hear") @RequestParam(value = "type", required = false)String type,
|
|
|
@ApiParam(name="day",value="周期",defaultValue = "7") @RequestParam(value = "day", required = false)Integer day
|
|
|
){
|
|
|
try {
|
|
|
JSONObject json = new JSONObject();
|
|
|
//心率
|
|
|
List<Map<String,Object>> hearDo = monitorPlatformService.getHeartByPatient(patient);
|
|
|
if (hearDo.size() > 0){
|
|
|
json.put("hear",hearDo);//心率
|
|
|
}else {
|
|
|
json.put("hear",0);//心率
|
|
|
String endDate = getNewDate(date,day);
|
|
|
if (type.equals("hear")){
|
|
|
//心率
|
|
|
List<Map<String,Object>> hearDo = monitorPlatformService.getHeartByPatient(patient,date,endDate);
|
|
|
if (hearDo.size() > 0){
|
|
|
json.put("hear",hearDo);//心率
|
|
|
}else {
|
|
|
json.put("hear",0);//心率
|
|
|
}
|
|
|
}
|
|
|
//健康分 retWeekTime("week"); 周的健康分
|
|
|
List<Map<String, Object>> scoreDO = monitorPlatformService.getHealthScoreByPatient(patient);
|
|
|
if (scoreDO.size() > 0){
|
|
|
Map<String,Object> healthScoreDO = scoreDO.get(0);
|
|
|
json.put("score",healthScoreDO.get("score")); //健康分值
|
|
|
json.put("total",healthScoreDO.get("total")); //健康分值总分
|
|
|
}else {
|
|
|
json.put("score",0); //健康分值
|
|
|
json.put("total",0); //健康分值总分
|
|
|
if (type.equals("score")){
|
|
|
//健康分 retWeekTime("week"); 周的健康分
|
|
|
List<Map<String, Object>> scoreDO = monitorPlatformService.getHealthScoreByPatient(patient,date,endDate);
|
|
|
if (scoreDO.size() > 0){
|
|
|
Map<String,Object> healthScoreDO = scoreDO.get(0);
|
|
|
json.put("score",healthScoreDO.get("score")); //健康分值
|
|
|
json.put("total",healthScoreDO.get("total")); //健康分值总分
|
|
|
}else {
|
|
|
json.put("score",0); //健康分值
|
|
|
json.put("total",0); //健康分值总分
|
|
|
}
|
|
|
}
|
|
|
// 实时数据
|
|
|
List<Map<String, Object>> realtimeDateDo = monitorPlatformService.getRealtimeDateByPatient(patient);
|
|
|
if (realtimeDateDo.size() > 0){
|
|
|
Map<String,Object> map = realtimeDateDo.get(0);
|
|
|
json.put("realtimehr",map.get("hr")); //实时心率
|
|
|
json.put("realtimest",map.get("st")); //实时步数,采集开始后的累积步数
|
|
|
json.put("realtimecal",map.get("cal")); //实时卡路里,累积卡路里
|
|
|
}else {
|
|
|
json.put("realtimehr",0); //实时心率
|
|
|
json.put("realtimest",0); //实时步数,采集开始后的累积步数
|
|
|
json.put("realtimecal",0); //实时卡路里,累积卡路里
|
|
|
if (type.equals("realtime")){
|
|
|
// 实时数据
|
|
|
List<Map<String, Object>> realtimeDateDo = monitorPlatformService.getRealtimeDateByPatient(patient,date);
|
|
|
if (realtimeDateDo.size() > 0){
|
|
|
Map<String,Object> map = realtimeDateDo.get(0);
|
|
|
json.put("realtimehr",map.get("hr")); //实时心率
|
|
|
json.put("realtimest",map.get("st")); //实时步数,采集开始后的累积步数
|
|
|
json.put("realtimecal",map.get("cal")); //实时卡路里,累积卡路里
|
|
|
}else {
|
|
|
json.put("realtimehr",0); //实时心率
|
|
|
json.put("realtimest",0); //实时步数,采集开始后的累积步数
|
|
|
json.put("realtimecal",0); //实时卡路里,累积卡路里
|
|
|
}
|
|
|
}
|
|
|
//运动数据
|
|
|
List<Map<String , Object>> rundateDo = monitorPlatformService.getRundatePatient(patient);
|
|
|
if (rundateDo.size() > 0){
|
|
|
Map<String,Object> map = rundateDo.get(0);
|
|
|
json.put("steps",map.get("steps")); //总步数
|
|
|
json.put("distance",map.get("distance")); //总距离
|
|
|
json.put("walkTime",map.get("walk_time")); //步行时长
|
|
|
json.put("runDistance",map.get("run_distance")); //跑步距离
|
|
|
json.put("runTime",map.get("run_time")); //跑步时长
|
|
|
json.put("calories",map.get("calories")); //总燃烧卡路里
|
|
|
json.put("runCalories",map.get("run_calories")); //跑步消耗卡路里
|
|
|
}else {
|
|
|
json.put("steps",0); //总步数
|
|
|
json.put("distance",0); //总距离
|
|
|
json.put("walkTime",0); //步行时长
|
|
|
json.put("runDistance",0); //跑步距离
|
|
|
json.put("runTime",0); //跑步时长
|
|
|
json.put("calories",0); //总燃烧卡路里
|
|
|
json.put("runCalories",0); //跑步消耗卡路里
|
|
|
if (type.equals("runData")){
|
|
|
//运动数据 runDate
|
|
|
List<Map<String , Object>> rundateDo = monitorPlatformService.getRundatePatient(patient,date);
|
|
|
if (rundateDo.size() > 0){
|
|
|
Map<String,Object> map = rundateDo.get(0);
|
|
|
json.put("steps",map.get("steps")); //总步数
|
|
|
json.put("distance",map.get("distance")); //总距离
|
|
|
json.put("walkTime",map.get("walk_time")); //步行时长
|
|
|
json.put("runDistance",map.get("run_distance")); //跑步距离
|
|
|
json.put("runTime",map.get("run_time")); //跑步时长
|
|
|
json.put("calories",map.get("calories")); //总燃烧卡路里
|
|
|
json.put("runCalories",map.get("run_calories")); //跑步消耗卡路里
|
|
|
}else {
|
|
|
json.put("steps",0); //总步数
|
|
|
json.put("distance",0); //总距离
|
|
|
json.put("walkTime",0); //步行时长
|
|
|
json.put("runDistance",0); //跑步距离
|
|
|
json.put("runTime",0); //跑步时长
|
|
|
json.put("calories",0); //总燃烧卡路里
|
|
|
json.put("runCalories",0); //跑步消耗卡路里
|
|
|
}
|
|
|
}
|
|
|
//PAI数据
|
|
|
List<Map<String,Object>> paiDo = monitorPlatformService.getPaiPatient(patient);
|
|
|
if (paiDo.size() > 0){
|
|
|
Map<String,Object> map = paiDo.get(0);
|
|
|
json.put("totalPai",map.get("total_pai")); //总
|
|
|
json.put("dailyPai",map.get("daily_pai")); //总距离
|
|
|
}else {
|
|
|
json.put("totalPai",0); //总
|
|
|
json.put("dailyPai",0); //总距离
|
|
|
if (type.equals("pai")){
|
|
|
//PAI数据
|
|
|
List<Map<String,Object>> paiDo = monitorPlatformService.getPaiPatient(patient,date);
|
|
|
if (paiDo.size() > 0){
|
|
|
Map<String,Object> map = paiDo.get(0);
|
|
|
json.put("totalPai",map.get("total_pai")); //用户本周运动前获得的所有PAI
|
|
|
json.put("dailyPai",map.get("daily_pai")); //用户在当天获得的PAI
|
|
|
}else {
|
|
|
json.put("totalPai",0); //总
|
|
|
json.put("dailyPai",0); //总距离
|
|
|
}
|
|
|
}
|
|
|
//睡眠数据
|
|
|
List<Map<String , Object>> sleepDo = monitorPlatformService.getSleepByPatient(patient);
|
|
|
if (sleepDo.size() > 0){
|
|
|
Map<String,Object> map = sleepDo.get(0);
|
|
|
json.put("deepSleepTime",map.get("deep_sleep_time")); //深度睡眠时长,单位为分钟
|
|
|
json.put("shallowSleepTime",map.get("shallow_sleep_time")); //浅度睡眠时长,单位为分钟
|
|
|
json.put("wakeTime",map.get("wake_time")); //睡眠期间清醒时长,单位为分钟
|
|
|
json.put("sleepScore",map.get("sleep_score")); //睡眠评分
|
|
|
json.put("start",map.get("start")); //睡眠开始时间。Amazfit设备为分钟序号(0-1439),mifit设备为时间戳
|
|
|
json.put("stop",map.get("stop")); //睡眠结束时间。Amazfit设备为分钟序号(0-1439),mifit设备为时间戳
|
|
|
}else {
|
|
|
json.put("deepSleepTime",0); //深度睡眠时长,单位为分钟
|
|
|
json.put("shallowSleepTime",0); //浅度睡眠时长,单位为分钟
|
|
|
json.put("wakeTime",0); //睡眠期间清醒时长,单位为分钟
|
|
|
json.put("sleepScore",0); //睡眠评分
|
|
|
json.put("start",0); //睡眠开始时间。Amazfit设备为分钟序号(0-1439),mifit设备为时间戳
|
|
|
json.put("stop",0); //睡眠结束时间。Amazfit设备为分钟序号(0-1439),mifit设备为时间戳
|
|
|
if (type.equals("sleepData")){
|
|
|
//睡眠数据
|
|
|
List<Map<String , Object>> sleepDo = monitorPlatformService.getSleepByPatient(patient,date);
|
|
|
if (sleepDo.size() > 0){
|
|
|
Map<String,Object> map = sleepDo.get(0);
|
|
|
json.put("deepSleepTime",map.get("deep_sleep_time")); //深度睡眠时长,单位为分钟
|
|
|
json.put("shallowSleepTime",map.get("shallow_sleep_time")); //浅度睡眠时长,单位为分钟
|
|
|
json.put("wakeTime",map.get("wake_time")); //睡眠期间清醒时长,单位为分钟
|
|
|
json.put("sleepScore",map.get("sleep_score")); //睡眠评分
|
|
|
json.put("start",map.get("start")); //睡眠开始时间。Amazfit设备为分钟序号(0-1439),mifit设备为时间戳
|
|
|
json.put("stop",map.get("stop")); //睡眠结束时间。Amazfit设备为分钟序号(0-1439),mifit设备为时间戳
|
|
|
}else {
|
|
|
json.put("deepSleepTime",0); //深度睡眠时长,单位为分钟
|
|
|
json.put("shallowSleepTime",0); //浅度睡眠时长,单位为分钟
|
|
|
json.put("wakeTime",0); //睡眠期间清醒时长,单位为分钟
|
|
|
json.put("sleepScore",0); //睡眠评分
|
|
|
json.put("start",0); //睡眠开始时间。Amazfit设备为分钟序号(0-1439),mifit设备为时间戳
|
|
|
json.put("stop",0); //睡眠结束时间。Amazfit设备为分钟序号(0-1439),mifit设备为时间戳
|
|
|
}
|
|
|
}
|
|
|
return success("查询成功",json);
|
|
|
}catch (Exception e){
|
|
@ -1004,4 +1018,14 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private String getNewDate(String date,Integer day) throws ParseException {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Date newDate = sdf.parse(date);
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(newDate);
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, -day);
|
|
|
System.out.println(sdf.format(calendar.getTime()));
|
|
|
return sdf.format(calendar.getTime());
|
|
|
}
|
|
|
|
|
|
}
|