|
@ -167,52 +167,115 @@ public class IotDeviceService {
|
|
|
*/
|
|
|
public String findRepeat(String user,String deviceSn,String value1,String value2,String type,String time){
|
|
|
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)){
|
|
|
//血糖
|
|
|
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 {
|
|
|
//血压
|
|
|
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 response = httpClientUtil.iotPostBody(url, jsonArray.toString());
|
|
|
String response = httpClientUtil.iotPostBody(url, jsonObject.toString());
|
|
|
|
|
|
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){
|
|
|
JSONObject json = new JSONObject();
|
|
|
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);
|
|
|
String url = baseUrl+"/dataSearch/getById";
|
|
|
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("del",StringUtils.trimToEmpty(jsonObject.getString("del")));
|
|
|
js.put("status",getStatus(jsonObject.getString("status")));
|
|
|
js.put("type",String.valueOf(type));
|
|
|
switch (type){
|
|
|
case 1:
|
|
|
//血糖
|
|
@ -466,6 +525,7 @@ public class IotDeviceService {
|
|
|
}else {
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("rid",mapping.getRid());
|
|
|
json.put("del",obj.getDel());
|
|
|
transforIot(obj,json);
|
|
|
String url = baseUrl+"/dataSearch/update";
|
|
|
String response = httpClientUtil.iotPostBody(url, json.toString());
|
|
@ -529,6 +589,8 @@ public class IotDeviceService {
|
|
|
|
|
|
transforIot(obj,js);
|
|
|
js.put("status","0");
|
|
|
js.put("del","1");
|
|
|
js.put("type",String.valueOf(obj.getType()));
|
|
|
jsonArray.add(js);
|
|
|
json.put("data",jsonArray);
|
|
|
//上传
|