Browse Source

代码修改

yeshijie 7 years ago
parent
commit
3eeda030a0

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java

@ -593,7 +593,7 @@ public class PatientHealthIndexService extends BaseService {
    public void updateStatus(DevicePatientHealthIndex data){
        if(iotDeviceService.isUploadIot()){
            //物联网更新
            iotDeviceService.updateStatus(data.getId());
            iotDeviceService.updateStatus(data.getId(),"1");
        }else {
            data.setStatus(1);
            patientHealthIndexDao.save(data);

+ 179 - 88
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/iot/IotDeviceService.java

@ -40,7 +40,7 @@ public class IotDeviceService {
    private Logger logger = LoggerFactory.getLogger(IotDeviceService.class);
//    @Value("${}")
    private String baseUrl = "http://192.168.131.24:8080/svr-iot-ysj/";
    private String baseUrl = "http://192.168.131.24:8088/svr-iot/";
    private String grantType = "client_credentials";
    private String clientId = "Va5yQRHlA4Fq4eR3LT0vuXV4";
    private String clientSecret = "0rDSjzQ20XUj5itV7WRtznPQSzr5pVw2";
@ -75,7 +75,7 @@ public class IotDeviceService {
        return "1".equals(value)?true:false;
    }
    public JSONObject test(){
    public JSONObject testUpload(){
//        String sql = "select response from wlyy_http_log_detail where id = 1";
//        List<String> list = jdbcTemplate.queryForList(sql,String.class);
        String sql = "SELECT i.id,i.user,i.value1,i.value2,i.value3,i.value4,i.type,i.record_date,i.device_sn,i.status,i.del,d.device_name,d.user_type,p.name,p.idcard " +
@ -108,6 +108,17 @@ public class IotDeviceService {
        if(list.size()>0){
            JSONObject one = list.get(0);
            String response = initUpload(one);
            JSONObject re = JSONObject.parseObject(response);
            if(re.getInteger("status")!=200){
                logger.error("id:"+one.getInteger("id")+" "+re.getString("errorMsg"));
            }else {
                //保存映射关系
                DeviceHealthyInfoMapping info = new DeviceHealthyInfoMapping();
                info.setCreateTime(new Date());
                info.setIndexId(one.getLong("id"));
                info.setRid(re.getJSONObject("obj").getJSONArray("rid").getString(0));
                deviceHealthyInfoMappingDao.save(info);
            }
            return JSONObject.parseObject(response);
        }
        return null;
@ -158,13 +169,13 @@ public class IotDeviceService {
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonUser = new JSONObject();
        jsonUser.put("andOr","and");
        jsonUser.put("filed","usercode");
        jsonUser.put("field","usercode");
        jsonUser.put("condition","=");
        jsonUser.put("value",user);
        jsonArray.add(jsonUser);
        JSONObject jsonSn = new JSONObject();
        jsonSn.put("andOr","and");
        jsonSn.put("filed","sn");
        jsonSn.put("field","sn");
        jsonSn.put("condition","=");
        jsonSn.put("value",deviceSn);
        jsonArray.add(jsonSn);
@ -172,7 +183,7 @@ public class IotDeviceService {
            //血糖
            JSONObject jsonValue1 = new JSONObject();
            jsonValue1.put("andOr","and");
            jsonValue1.put("filed","blood_sugar");
            jsonValue1.put("field","blood_sugar");
            jsonValue1.put("condition","=");
            jsonValue1.put("value",value1);
            jsonArray.add(jsonValue1);
@ -180,12 +191,12 @@ public class IotDeviceService {
            //血压
            JSONObject jsonValue1 = new JSONObject();
            jsonValue1.put("andOr","and");
            jsonValue1.put("filed","systolic");
            jsonValue1.put("field","systolic");
            jsonValue1.put("condition","=");
            jsonValue1.put("value",value1);
            JSONObject jsonValue2 = new JSONObject();
            jsonValue2.put("andOr","and");
            jsonValue2.put("filed","diastolic");
            jsonValue2.put("field","diastolic");
            jsonValue2.put("condition","=");
            jsonValue2.put("value",value2);
            jsonArray.add(jsonValue1);
@ -193,10 +204,11 @@ public class IotDeviceService {
        }
        JSONObject jsonTime = new JSONObject();
        jsonTime.put("andOr","and");
        jsonTime.put("filed","measure_time");
        jsonTime.put("field","measure_time");
        jsonTime.put("condition","=");
        jsonTime.put("value",time);
        String url = baseUrl+"/findById";
        jsonArray.add(jsonTime);
        String url = baseUrl+"/dataSearch/findById";
        String response = httpClientUtil.iotPostBody(url, jsonArray.toString());
        return response;
    }
@ -209,11 +221,15 @@ public class IotDeviceService {
     */
    public String getById(String rid){
        JSONObject json = new JSONObject();
        json.put("andOr","and");
        json.put("filed","rid");
        json.put("condition","=");
        json.put("value",rid);
        String url = baseUrl+"/getById";
        JSONArray filters = new JSONArray();
        JSONObject filter = new JSONObject();
        filter.put("andOr","and");
        filter.put("field","rid");
        filter.put("condition","=");
        filter.put("value",rid);
        filters.add(filter);
        json.put("filter",filters);
        String url = baseUrl+"/dataSearch/getById";
        String response = httpClientUtil.iotPostBody(url, json.toString());
        return response;
    }
@ -221,15 +237,17 @@ public class IotDeviceService {
    /**
     * 查询
     * filter
     * - 参数格式:[{"andOr":"and|or","condition":">|=|<|>=|<=|?","field":"<filed>","value":"<value>"},<{...}>]
     * - 参数格式:[{"andOr":"and|or","condition":">|=|<|>=|<=|?","field":"<field>","value":"<value>"},<{...}>]
     * - 参数说明:andOr跟数据库的中的AND和OR相似;condition指条件匹配程度,?相当于数据库中的like;filed指检索的字段;value为检索的值
     * page - 参数说明:页码
     * size - 参数说明:分页大小
     * sort - 参数格式:排序,key要排序的字段,order固定,取值asc或desc,不需要排序,传""
     *  排序[{"key1":{"order":"asc|desc"}},{"key2":{"order":"asc|desc"}}]
     * @param json
     * @return
     */
    public String searchList(JSONObject json){
        String url = baseUrl+"/searchList";
        String url = baseUrl+"/dataSearch/searchList";
        String response = httpClientUtil.iotPostBody(url, json.toString());
        return response;
    }
@ -240,7 +258,7 @@ public class IotDeviceService {
     * @return
     */
    public String listPage(JSONObject json){
        String url = baseUrl+"/listPage";
        String url = baseUrl+"/dataSearch/listPage";
        String response = httpClientUtil.iotPostBody(url, json.toString());
        return response;
    }
@ -254,7 +272,7 @@ public class IotDeviceService {
    public String recent5(JSONObject json,JSONObject sort){
        json.put("access_token",accessToken);
        String url = baseUrl+"/recent5";
        String url = baseUrl+"/dataSearch/recent5";
        String response = httpClientUtil.iotPostBody(url, json.toString());
        return response;
    }
@ -268,7 +286,7 @@ public class IotDeviceService {
    public String recent1(JSONObject json,JSONObject sort){
        json.put("access_token",accessToken);
        String url = baseUrl+"/recent1";
        String url = baseUrl+"/dataSearch/recent1";
        String response = httpClientUtil.iotPostBody(url, json.toString());
        return response;
    }
@ -313,14 +331,14 @@ public class IotDeviceService {
            list.stream().forEach(one->{
                String response = initUpload(one);
                JSONObject re = JSONObject.parseObject(response);
                String errorMsg = re.getString("errorMsg");//错误信息(请求失败才有错误消息)
                if(StringUtils.isNotBlank(errorMsg)){
                    logger.error("id:"+one.getInteger("id")+" "+errorMsg);
                if(re.getInteger("status")!=200){
                    logger.error("id:"+one.getInteger("id")+" "+re.getString("errorMsg"));
                }else {
                    //保存映射关系
                    DeviceHealthyInfoMapping info = new DeviceHealthyInfoMapping();
                    info.setCreateTime(new Date());
                    info.setIndexId(one.getLong("id"));
                    info.setRid(one.getJSONObject("obj").getJSONArray("rid").getString(0));
                    infos.add(info);
                }
            });
@ -356,7 +374,7 @@ public class IotDeviceService {
//        js.put("id",String.valueOf(jsonObject.getInteger("id")));
        js.put("measure_time",subStringTime(jsonObject.getString("record_date")));
        js.put("del",StringUtils.trimToEmpty(jsonObject.getString("del")));
        js.put("status",StringUtils.trimToEmpty(jsonObject.getString("status")));
        js.put("status",getStatus(jsonObject.getString("status")));
        switch (type){
            case 1:
                //血糖
@ -405,14 +423,17 @@ public class IotDeviceService {
     * 更新状态
     * @param id
     */
    public void updateStatus(Long id){
    public void updateStatus(Long id,String status){
        DeviceHealthyInfoMapping mapping = deviceHealthyInfoMappingDao.findByIndexId(id,id);
        if(mapping == null){
            logger.info("未找到映射关系,id:"+id);
            logger.error("未找到映射关系,id:"+id);
        }else {
            JSONObject json = new JSONObject();
            String url = baseUrl+"/dataInput/updateRecord";
            json.put("rid",mapping.getRid());
            json.put("status",status);
            String url = baseUrl+"/dataSearch/update";
            String response = httpClientUtil.iotPostBody(url, json.toString());
            JSONObject res = JSONObject.parseObject(response);
        }
    }
@ -424,13 +445,61 @@ public class IotDeviceService {
    public DevicePatientHealthIndex getById(Long id){
        DeviceHealthyInfoMapping mapping = deviceHealthyInfoMappingDao.findByIndexId(id,id);
        if(mapping == null){
            logger.info("未找到映射关系,id:"+id);
            logger.error("未找到映射关系,id:"+id);
            return null;
        }else {
            return transforOne(getById(mapping.getRid()),id);
        }
    }
    /**
     * 更新
     * @param obj
     * @return
     */
    public DevicePatientHealthIndex update(DevicePatientHealthIndex obj){
        DeviceHealthyInfoMapping mapping = deviceHealthyInfoMappingDao.findByIndexId(obj.getId(),obj.getId());
        if(mapping == null){
            logger.error("未找到映射关系,id:"+obj.getId());
        }else {
            JSONObject json = new JSONObject();
            json.put("rid",mapping.getRid());
            transforIot(obj,json);
            String url = baseUrl+"/dataSearch/update";
            String response = httpClientUtil.iotPostBody(url, json.toString());
            JSONObject res = JSONObject.parseObject(response);
        }
        return obj;
    }
    /**
     * 删除
     * @param id
     */
    public void delete(Long id){
        DeviceHealthyInfoMapping mapping = deviceHealthyInfoMappingDao.findByIndexId(id,id);
        if(mapping == null){
            logger.error("未找到映射关系,id:"+id);
        }else {
            JSONObject json = new JSONObject();
            json.put("rid",mapping.getRid());
            json.put("del","0");
            String url = baseUrl+"/dataSearch/delete";
            String response = httpClientUtil.iotPostBody(url, json.toString());
            JSONObject res = JSONObject.parseObject(response);
            if("true".equals(res.getString("obj"))){
                logger.info("删除成功!");
            }else {
                logger.error("删除失败,id="+id+",rid="+mapping.getRid()+",msg="+res.getString("errorMsg"));
            }
        }
    }
    /**
     * 体征上传
     * @param obj
@ -457,43 +526,9 @@ public class IotDeviceService {
        JSONArray jsonArray = new JSONArray();
        JSONObject js = new JSONObject();
        js.put("measure_time",obj.getRecordDate());
        switch (obj.getType()){
            case 1:
                //血糖
                js.put("blood_sugar",obj.getValue1());
                js.put("blood_sugar_unit",bloodSugarUnit);
                js.put("blood_sugar_result",obj.getValue2());
                break;
            case 2:
                //血压
                js.put("systolic",obj.getValue1());
                js.put("systolic_unit",bloodPressureUnit);
                js.put("diastolic",obj.getValue2());
                js.put("diastolic_unit",bloodPressureUnit);
                if(StringUtils.isNotBlank(obj.getValue3())){
                    js.put("pulse",obj.getValue3());
                    js.put("pulse_unit",pulseUnit);
                }
                break;
            case 3:
                //体重/身高/BMI
                js.put("height",obj.getValue1());
                js.put("height_unit",heightUnit);
                js.put("weight",obj.getValue2());
                js.put("weight_unit",weightUnit);
                if(StringUtils.isNotBlank(obj.getValue3())){
                    js.put("bmi",obj.getValue3());
                    js.put("bmi_unit",bmiUnit);
                }
                break;
            case 4:
                //腰围
                js.put("waist",obj.getValue1());
                js.put("waist_unit",waistUnit);
                break;
            default:
                break;
        }
        transforIot(obj,js);
        js.put("status","0");
        jsonArray.add(js);
        json.put("data",jsonArray);
        //上传
@ -514,15 +549,6 @@ public class IotDeviceService {
        return obj;
    }
    /**
     * 更新
     * @param obj
     * @return
     */
    public DevicePatientHealthIndex update(DevicePatientHealthIndex obj){
        return obj;
    }
    /************************************i健康业务相关 end  ************************************************************/
@ -537,7 +563,7 @@ public class IotDeviceService {
            return null;
        }
        JSONObject jsonObject = JSONObject.parseObject(res);
        if(jsonObject.getString("errorMsg")!=null){
        if(jsonObject.getInteger("status")!=200||jsonObject.getJSONArray("obj").size()==0){
            logger.error(jsonObject.getString("errorMsg"));
            return null;
        }
@ -547,25 +573,34 @@ public class IotDeviceService {
        index.setDeviceSn(obj.getString("sn"));
        index.setUser(obj.getString("usercode"));
        index.setIdcard(obj.getString("idcard"));
        index.setRecordDate(DateUtil.strToDate(obj.getString("measure_time")));
        //{"errorCode":null,"errorMsg":null,"successMsg":"search success","status":200,"pageSize":10,"currPage":0,"totalPage":0,"totalCount":0,"detailModelList":null,
        // "obj":[{"access_token":"test","data_source":"iHealth","sn":"867967022337804","ext_code":"","device_name":"","device_model":"",
        // "data":[{"rid":"lwKBG349zj/XBIJOP8CpyoFxFKl0xyxLLzxpN/l9+1U=","del":1,"measure_time":"2016-08-26 12:32:04","systolic":"115.00","systolic_unit":"mmHg","diastolic":"105.00","pulse":"105.00","pulse_unit":"bpm"}],
        // "idCard":"350122198601145513","username":"谢挺盛","usercode":"443a196ef8744536a531260eb26c05d7"}]}
        JSONObject data = obj.getJSONArray("data").getJSONObject(0);
        index.setRecordDate(DateUtil.strToDate(data.getString("measure_time")));
        index.setSortDate(index.getRecordDate());
        if(obj.getString("blood_sugar")==null){
        index.setDel(data.getString("del"));
        index.setStatus(data.getInteger("status"));
        if(data.getString("blood_sugar")!=null){
            index.setType(1);
            index.setValue1(obj.getString("blood_sugar"));
            index.setValue2(obj.getString("blood_sugar_result"));
        }else if(obj.getString("systolic")==null){
            index.setValue1(data.getString("blood_sugar"));
            index.setValue2(data.getString("blood_sugar_result"));
        }else if(data.getString("systolic")!=null){
            index.setType(2);
            index.setValue1(obj.getString("systolic"));
            index.setValue2(obj.getString("diastolic"));
            index.setValue3(obj.getString("pulse"));
        }else if(obj.getString("height")==null){
            index.setValue1(data.getString("systolic"));
            index.setValue2(data.getString("diastolic"));
            index.setValue3(data.getString("pulse"));
        }else if(data.getString("height")!=null){
            index.setType(3);
            index.setValue1(obj.getString("height"));
            index.setValue2(obj.getString("weight"));
            index.setValue3(obj.getString("bmi"));
        }else if(obj.getString("waist")==null){
            index.setValue1(data.getString("height"));
            index.setValue2(data.getString("weight"));
            index.setValue3(data.getString("bmi"));
        }else if(data.getString("waist")!=null){
            index.setType(4);
            index.setValue1(obj.getString("waist"));
            index.setValue1(data.getString("waist"));
        }
        return index;
    }
@ -605,6 +640,62 @@ public class IotDeviceService {
        return StringUtils.isBlank(time)? "":time.substring(0,19);
    }
    /**
     * 状态默认值
     * @param status
     * @return
     */
    private String getStatus(String status){
        return StringUtils.isBlank(status)?"0":status;
    }
    /**
     * 转化成物联网格式
     * @param obj
     * @param json
     * @return
     */
    public JSONObject transforIot(DevicePatientHealthIndex obj,JSONObject json){
        switch (obj.getType()){
            case 1:
                //血糖
                json.put("blood_sugar",obj.getValue1());
                json.put("blood_sugar_unit",bloodSugarUnit);
                json.put("blood_sugar_result",obj.getValue2());
                break;
            case 2:
                //血压
                json.put("systolic",obj.getValue1());
                json.put("systolic_unit",bloodPressureUnit);
                json.put("diastolic",obj.getValue2());
                json.put("diastolic_unit",bloodPressureUnit);
                if(StringUtils.isNotBlank(obj.getValue3())){
                    json.put("pulse",obj.getValue3());
                    json.put("pulse_unit",pulseUnit);
                }
                break;
            case 3:
                //体重/身高/BMI
                json.put("height",obj.getValue1());
                json.put("height_unit",heightUnit);
                json.put("weight",obj.getValue2());
                json.put("weight_unit",weightUnit);
                if(StringUtils.isNotBlank(obj.getValue3())){
                    json.put("bmi",obj.getValue3());
                    json.put("bmi_unit",bmiUnit);
                }
                break;
            case 4:
                //腰围
                json.put("waist",obj.getValue1());
                json.put("waist_unit",waistUnit);
                break;
            default:
                break;
        }
        return json;
    }
    /*****************************************工具方法 end  ************************************************************/
}

+ 53 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/iot/IotDeviceController.java

@ -4,11 +4,13 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.device.entity.DevicePatientHealthIndex;
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
import com.yihu.wlyy.service.third.iot.IotDeviceService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
@ -27,6 +29,8 @@ public class IotDeviceController extends BaseController{
    @Autowired
    private IotDeviceService iotDeviceService;
    private ObjectMapper objectMapper = new ObjectMapper();
    @Autowired
    private PatientHealthIndexService indexService;
    @RequestMapping(value = "/registedevice",method = RequestMethod.POST)
    @ApiOperation("注册设备")
@ -73,11 +77,11 @@ public class IotDeviceController extends BaseController{
        }
    }
    @RequestMapping(value = "/test",method = RequestMethod.GET)
    @ApiOperation("test")
    @RequestMapping(value = "/testUpload",method = RequestMethod.GET)
    @ApiOperation("testUpload")
    public String upload(){
        try {
            return write(200, "test成功!", "data", iotDeviceService.test());
            return write(200, "test成功!", "data", iotDeviceService.testUpload());
        }catch (Exception e){
            error(e);
            return error(-1, e.getMessage());
@ -110,7 +114,7 @@ public class IotDeviceController extends BaseController{
    @RequestMapping(value = "/getById",method = RequestMethod.GET)
    @ApiOperation("按id查询")
    public String getById(@ApiParam(name = "id",value = "id",defaultValue = "123")
    public String getById(@ApiParam(name = "id",value = "id",defaultValue = "100000")
                           @RequestParam(name="id",required = true) Long id){
        try {
            return write(200,"查询成功","data",iotDeviceService.getById(id));
@ -120,6 +124,51 @@ public class IotDeviceController extends BaseController{
        }
    }
    @RequestMapping(value = "/delHealthIndex",method = RequestMethod.POST)
    @ApiOperation("删除体征数据")
    public String delHealthIndex(@ApiParam(name = "id",value = "id",defaultValue = "100000")
                          @RequestParam(name="id",required = true) Long id){
        try {
            iotDeviceService.delete(id);
            return success("删除成功");
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    @RequestMapping(value = "/updateHealthIndex",method = RequestMethod.POST)
    @ApiOperation("更新体征数据")
    public String updateHealthIndex(@ApiParam(name = "id",value = "id",defaultValue = "1")
                                 @RequestParam(name="id",required = true) Long id){
        try {
            DevicePatientHealthIndex index = indexService.findOne(id);
            DevicePatientHealthIndex newIndex = new DevicePatientHealthIndex();
            BeanUtils.copyProperties(index,newIndex);
            newIndex.setId(100000L);
            iotDeviceService.update(newIndex);
            return success("更新成功");
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    @RequestMapping(value = "/updateStatus",method = RequestMethod.POST)
    @ApiOperation("更新成功")
    public String getById(@ApiParam(name = "id",value = "id",defaultValue = "100000")
                          @RequestParam(name="id",required = true) Long id,
                          @ApiParam(name = "status",value = "status",defaultValue = "1")
                          @RequestParam(name="status",required = true) String status){
        try {
            iotDeviceService.updateStatus(id,status);
            return success("更新成功");
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    @RequestMapping(value = "/findRepeat",method = RequestMethod.GET)
    @ApiOperation("查找重复数据")
    public String findRepeat(@ApiParam(name = "user",value = "user",defaultValue = "aduiojdajkdlsd")