Shi Kejing il y a 4 ans
Parent
commit
fb6daf8461

+ 93 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/monitorPlatform/MonitorPlatformController.java

@ -911,4 +911,97 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
        }
        }
    }
    }
    @ApiOperation("获取运动记录")
    @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
    ){
        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);//心率
            }
            //健康分  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); //健康分值总分
            }
            // 实时数据
            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); //实时卡路里,累积卡路里
            }
            //运动数据
            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); //跑步消耗卡路里
            }
            //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); //总距离
            }
            //睡眠数据
            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设备为时间戳
            }
            return success("查询成功",json);
        }catch (Exception e){
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
}
}

+ 41 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/monitorPlatform/MonitorPlatformService.java

@ -1771,4 +1771,45 @@ public class MonitorPlatformService  {
        return null;
        return null;
    }
    }
    public List<Map<String, Object>> getHealthScoreByPatient(String patient){
        String sql = "SELECT chhs.* FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_health_score chhs,wlyy.hm_token t\n" +
                "WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chhs.device_sn ORDER BY export_time DESC ";
        List<Map<String, Object>> scoreDO = jdbcTemplate.queryForList(sql);
        return scoreDO;
    }
    public List<Map<String,Object>> getRealtimeDateByPatient(String patient){
        String sql = "SELECT chrd.* FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_realtime_date chrd,wlyy.hm_token t\n" +
                "WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chrd.device_sn ORDER BY chrd.`data` DESC";
        List<Map<String, Object>> realtimeDateDo = jdbcTemplate.queryForList(sql);
        return realtimeDateDo;
    }
    public List<Map<String,Object>> getRundatePatient(String patient){
        String sql = "SELECT chr.* FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_rundate chr,wlyy.hm_token t\n" +
                "WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chr.device_sn ORDER BY chr.`date` DESC";
        List<Map<String, Object>> rundataDo = jdbcTemplate.queryForList(sql);
        return rundataDo;
    }
    public List<Map<String,Object>> getPaiPatient(String patient){
        String sql = "SELECT chp.* FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_pai chp,wlyy.hm_token t\n" +
                "WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chp.device_sn ORDER BY chp.`timestamp` DESC";
        List<Map<String, Object>> paiDo = jdbcTemplate.queryForList(sql);
        return paiDo;
    }
    public List<Map<String,Object>> getSleepByPatient(String patient){
        String sql = "SELECT chs.* FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_sleep chs,wlyy.hm_token t\n" +
                "WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chs.device_sn ORDER BY chs.`last_sync_time` DESC";
        List<Map<String, Object>> paiDo = jdbcTemplate.queryForList(sql);
        return paiDo;
    }
    public List<Map<String , Object>> getHeartByPatient(String patient){
        String sql = "SELECT chh.* FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_heart chh,wlyy.hm_token t\n" +
                "WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chh.device_sn ORDER BY chh.`date` DESC limit 0,7";
        List<Map<String, Object>> heartDo = jdbcTemplate.queryForList(sql);
        return heartDo;
    }
}
}