瀏覽代碼

代码修改

yeshijie 7 年之前
父節點
當前提交
8bf95c95e8

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

@ -167,52 +167,115 @@ public class IotDeviceService {
     */
     */
    public String findRepeat(String user,String deviceSn,String value1,String value2,String type,String time){
    public String findRepeat(String user,String deviceSn,String value1,String value2,String type,String time){
        JSONArray jsonArray = new JSONArray();
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonUser = new JSONObject();
        jsonUser.put("andOr","and");
        jsonUser.put("field","usercode");
        jsonUser.put("condition","=");
        jsonUser.put("value",user);
        jsonArray.add(jsonUser);
        JSONObject jsonSn = new JSONObject();
        jsonSn.put("andOr","and");
        jsonSn.put("field","sn");
        jsonSn.put("condition","=");
        jsonSn.put("value",deviceSn);
        jsonArray.add(jsonSn);
        field("and","usercode","=",user,jsonArray);
        field("and","sn","=",deviceSn,jsonArray);
        if("1".equals(type)){
        if("1".equals(type)){
            //血糖
            //血糖
            JSONObject jsonValue1 = new JSONObject();
            jsonValue1.put("andOr","and");
            jsonValue1.put("field","blood_sugar");
            jsonValue1.put("condition","=");
            jsonValue1.put("value",value1);
            jsonArray.add(jsonValue1);
            field("and","blood_sugar","=",value1,jsonArray);
        }else {
        }else {
            //血压
            //血压
            JSONObject jsonValue1 = new JSONObject();
            jsonValue1.put("andOr","and");
            jsonValue1.put("field","systolic");
            jsonValue1.put("condition","=");
            jsonValue1.put("value",value1);
            JSONObject jsonValue2 = new JSONObject();
            jsonValue2.put("andOr","and");
            jsonValue2.put("field","diastolic");
            jsonValue2.put("condition","=");
            jsonValue2.put("value",value2);
            jsonArray.add(jsonValue1);
            jsonArray.add(jsonValue2);
            field("and","systolic","=",value1,jsonArray);
            field("and","diastolic","=",value2,jsonArray);
        }
        }
        JSONObject jsonTime = new JSONObject();
        jsonTime.put("andOr","and");
        jsonTime.put("field","measure_time");
        jsonTime.put("condition","=");
        jsonTime.put("value",time);
        jsonArray.add(jsonTime);
        field("and","measure_time","=",time,jsonArray);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("filter",jsonArray);
        String url = baseUrl+"/dataSearch/findById";
        String url = baseUrl+"/dataSearch/findById";
        String response = httpClientUtil.iotPostBody(url, jsonArray.toString());
        String response = httpClientUtil.iotPostBody(url, jsonObject.toString());
        return response;
        return response;
    }
    }
    /**
     * 按条件统计数量
     * @param start
     * @param end
     * @param status
     * @param patientCode
     * @return
     */
    public int getCountByTimeAndStatusAndPatient(String start,String end,Integer status,String patientCode){
        int re = 0;
        JSONArray jsonArray = new JSONArray();
        field("and","usercode","=",patientCode,jsonArray);
        field("and","status","=",String.valueOf(status),jsonArray);
        field("and","del","=","1",jsonArray);
        field("and","measure_time",">=",start,jsonArray);
        field("and","measure_time","<=",end,jsonArray);
        field("and","type",">=","1",jsonArray);
        field("and","type","<=","2",jsonArray);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("filter",jsonArray);
        String url = baseUrl+"/dataSearch/findById";
        String response = httpClientUtil.iotPostBody(url, jsonObject.toString());
        JSONObject json = JSONObject.parseObject(response);
        JSONArray ja = json.getJSONArray("obj");
        if(ja!=null){
            re = ja.size();
        }
        return re;
    }
    /**
     *
     * @param patient
     * @param type
     * @return
     */
    public List<DevicePatientHealthIndex> findByPatientAndType(String patient,Integer type){
        List<DevicePatientHealthIndex> list = new ArrayList<>();
        JSONArray jsonArray = new JSONArray();
        field("and","usercode","=",patient,jsonArray);
        field("and","del","=","1",jsonArray);
        field("and","type","=",String.valueOf(type),jsonArray);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("filter",jsonArray);
        jsonObject.put("page","1");
        jsonObject.put("size","5");
        JSONArray sort = new JSONArray();
        sort(sort,"measure_time","desc");
        jsonObject.put("sort",sort);
        String url = baseUrl+"/dataSearch/findById";
        String response = httpClientUtil.iotPostBody(url, jsonObject.toString());
        return list;
    }
    /**
     * 添加条件
     * 参数格式:[{"andOr":"and|or","condition":">|=|<|>=|<=|?","field":"<field>","value":"<value>"},<{...}>]
     * @param andOr
     * @param field
     * @param condition
     * @param value
     * @param jsonArray
     */
    private void field(String andOr,String field,String condition,String value,JSONArray jsonArray){
        JSONObject json = new JSONObject();
        json.put("andOr",andOr);
        json.put("field",field);
        json.put("condition",condition);
        json.put("value",value);
        jsonArray.add(json);
    }
    /**
     * 排序[{"key1":{"order":"asc|desc"}},{"key2":{"order":"asc|desc"}}]
     * @param jsonArray
     * @param key
     * @param order
     */
    private void sort(JSONArray jsonArray,String key,String order){
        JSONObject json = new JSONObject();
        json.put("order",order);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(key,json);
        jsonArray.add(json);
    }
    /**
    /**
     * 查询单条
     * 查询单条
@ -222,12 +285,7 @@ public class IotDeviceService {
    public String getById(String rid){
    public String getById(String rid){
        JSONObject json = new JSONObject();
        JSONObject json = new JSONObject();
        JSONArray filters = new JSONArray();
        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);
        field("and","rid","=",rid,filters);
        json.put("filter",filters);
        json.put("filter",filters);
        String url = baseUrl+"/dataSearch/getById";
        String url = baseUrl+"/dataSearch/getById";
        String response = httpClientUtil.iotPostBody(url, json.toString());
        String response = httpClientUtil.iotPostBody(url, json.toString());
@ -375,6 +433,7 @@ public class IotDeviceService {
        js.put("measure_time",subStringTime(jsonObject.getString("record_date")));
        js.put("measure_time",subStringTime(jsonObject.getString("record_date")));
        js.put("del",StringUtils.trimToEmpty(jsonObject.getString("del")));
        js.put("del",StringUtils.trimToEmpty(jsonObject.getString("del")));
        js.put("status",getStatus(jsonObject.getString("status")));
        js.put("status",getStatus(jsonObject.getString("status")));
        js.put("type",String.valueOf(type));
        switch (type){
        switch (type){
            case 1:
            case 1:
                //血糖
                //血糖
@ -466,6 +525,7 @@ public class IotDeviceService {
        }else {
        }else {
            JSONObject json = new JSONObject();
            JSONObject json = new JSONObject();
            json.put("rid",mapping.getRid());
            json.put("rid",mapping.getRid());
            json.put("del",obj.getDel());
            transforIot(obj,json);
            transforIot(obj,json);
            String url = baseUrl+"/dataSearch/update";
            String url = baseUrl+"/dataSearch/update";
            String response = httpClientUtil.iotPostBody(url, json.toString());
            String response = httpClientUtil.iotPostBody(url, json.toString());
@ -529,6 +589,8 @@ public class IotDeviceService {
        transforIot(obj,js);
        transforIot(obj,js);
        js.put("status","0");
        js.put("status","0");
        js.put("del","1");
        js.put("type",String.valueOf(obj.getType()));
        jsonArray.add(js);
        jsonArray.add(js);
        json.put("data",jsonArray);
        json.put("data",jsonArray);
        //上传
        //上传

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

@ -169,7 +169,7 @@ public class IotDeviceController extends BaseController{
        }
        }
    }
    }
    @RequestMapping(value = "/findRepeat",method = RequestMethod.GET)
    @RequestMapping(value = "/findRepeat",method = RequestMethod.POST)
    @ApiOperation("查找重复数据")
    @ApiOperation("查找重复数据")
    public String findRepeat(@ApiParam(name = "user",value = "user",defaultValue = "aduiojdajkdlsd")
    public String findRepeat(@ApiParam(name = "user",value = "user",defaultValue = "aduiojdajkdlsd")
                             @RequestParam(name="user",required = true) String user,
                             @RequestParam(name="user",required = true) String user,
@ -191,4 +191,36 @@ public class IotDeviceController extends BaseController{
        }
        }
    }
    }
    @RequestMapping(value = "getCountByTimeAndStatusAndPatient",method = RequestMethod.POST)
    @ApiOperation("按条件查找数量")
    public String getCountByTimeAndStatusAndPatient(@ApiParam(name="patientCode",value = "居民code")
                                                    @RequestParam(name="patientCode",required = true)String patientCode,
                                                    @ApiParam(name="status",value = "状态")
                                                    @RequestParam(name="status",required = true)Integer status,
                                                    @ApiParam(name="start",value = "开始时间")
                                                    @RequestParam(name="start",required = true)String start,
                                                    @ApiParam(name="end",value = "结束时间")
                                                    @RequestParam(name="end",required = true)String end){
        try {
            return write(200,"","data",iotDeviceService.getCountByTimeAndStatusAndPatient(start, end, status, patientCode));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    @RequestMapping(value = "findByPatientAndType",method = RequestMethod.POST)
    @ApiOperation("按类型查找最近5次的体征记录")
    public String findByPatientAndType(@ApiParam(name="patientCode",value = "居民code")
                                                    @RequestParam(name="patientCode",required = true)String patientCode,
                                                    @ApiParam(name="type",value = "类型")
                                                    @RequestParam(name="type",required = true)Integer type){
        try {
            return write(200,"","data",iotDeviceService.findByPatientAndType(patientCode,type));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
}
}