yeshijie преди 7 години
родител
ревизия
46aaf77c11

+ 3 - 3
common/common-entity/src/main/java/com/yihu/device/entity/DevicePatientHealthIndex.java

@ -37,7 +37,7 @@ public class DevicePatientHealthIndex extends IdEntity {
	private String value7;
	// 健康指标类型(1血糖,2血压,3体重/身高/BMI,4腰围)
	private int type;
	private Integer type;
	// 记录时间
	private Date recordDate;
	// 排序日期
@ -135,11 +135,11 @@ public class DevicePatientHealthIndex extends IdEntity {
		this.recordDate = recordDate;
	}
	public int getType() {
	public Integer getType() {
		return type;
	}
	public void setType(int type) {
	public void setType(Integer type) {
		this.type = type;
	}

+ 3 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/deviece/DeviceHealthyInfoMappingDao.java

@ -12,4 +12,7 @@ public interface DeviceHealthyInfoMappingDao extends PagingAndSortingRepository<
    @Query("select a from DeviceHealthyInfoMapping a where a.id = ?1 or a.indexId=?2 ")
    DeviceHealthyInfoMapping findByIndexId(Long id,Long indexId);
    @Query("select a from DeviceHealthyInfoMapping a where a.rid = ?1 ")
    DeviceHealthyInfoMapping findByRid(String rid);
}

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

@ -169,18 +169,21 @@ public class IotDeviceService {
        JSONArray jsonArray = new JSONArray();
        field("and","usercode","=",user,jsonArray);
        field("and","sn","=",deviceSn,jsonArray);
        field("and","del","=","1",jsonArray);
        if("1".equals(type)){
            //血糖
            field("and","blood_sugar","=",value1,jsonArray);
        }else {
            //血压
            field("and","systolic","=",value1,jsonArray);
            field("and","diastolic","=",value2,jsonArray);
            if(StringUtils.isNotBlank(value2)){
                field("and","diastolic","=",value2,jsonArray);
            }
        }
        field("and","measure_time","=",time,jsonArray);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("filter",jsonArray);
        String url = baseUrl+"/dataSearch/findById";
        String url = baseUrl+"/dataSearch/getById";
        String response = httpClientUtil.iotPostBody(url, jsonObject.toString());
        return response;
@ -207,7 +210,9 @@ public class IotDeviceService {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("filter",jsonArray);
        String url = baseUrl+"/dataSearch/findById";
        jsonObject.put("page","1");
        jsonObject.put("size","50");
        String url = baseUrl+"/dataSearch/getById";
        String response = httpClientUtil.iotPostBody(url, jsonObject.toString());
        JSONObject json = JSONObject.parseObject(response);
        JSONArray ja = json.getJSONArray("obj");
@ -219,7 +224,7 @@ public class IotDeviceService {
    }
    /**
     *
     * 按居民code和类型查找
     * @param patient
     * @param type
     * @return
@ -239,9 +244,23 @@ public class IotDeviceService {
        JSONArray sort = new JSONArray();
        sort(sort,"measure_time","desc");
        jsonObject.put("sort",sort);
        String url = baseUrl+"/dataSearch/findById";
        String url = baseUrl+"/dataSearch/getById";
        String response = httpClientUtil.iotPostBody(url, jsonObject.toString());
        try {
            JSONObject json = JSONObject.parseObject(response);
            JSONArray obj = json.getJSONArray("obj");
            if(obj!=null&&obj.size()>0){
                for (int i=0;i<obj.size();i++){
                    DevicePatientHealthIndex index = transforHealthIndex(obj.getJSONObject(i),null);
                    list.add(index);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }
@ -274,7 +293,7 @@ public class IotDeviceService {
        json.put("order",order);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(key,json);
        jsonArray.add(json);
        jsonArray.add(jsonObject);
    }
    /**
@ -298,7 +317,7 @@ public class IotDeviceService {
     * - 参数格式:[{"andOr":"and|or","condition":">|=|<|>=|<=|?","field":"<field>","value":"<value>"},<{...}>]
     * - 参数说明:andOr跟数据库的中的AND和OR相似;condition指条件匹配程度,?相当于数据库中的like;filed指检索的字段;value为检索的值
     * page - 参数说明:页码
     * size - 参数说明:分页大小
     * size - 参数说明:分页大小 默认1
     * sort - 参数格式:排序,key要排序的字段,order固定,取值asc或desc,不需要排序,传""
     *  排序[{"key1":{"order":"asc|desc"}},{"key2":{"order":"asc|desc"}}]
     * @param json
@ -630,8 +649,18 @@ public class IotDeviceService {
            return null;
        }
        JSONObject obj = jsonObject.getJSONArray("obj").getJSONObject(0);
        return transforHealthIndex(obj,id);
    }
    /**
     * 转化成数据库对象
     * @param obj
     * @param id
     * @return
     */
    private DevicePatientHealthIndex transforHealthIndex(JSONObject obj,Long id){
        DevicePatientHealthIndex index = new DevicePatientHealthIndex();
        index.setId(id);
        index.setDeviceSn(obj.getString("sn"));
        index.setUser(obj.getString("usercode"));
        index.setIdcard(obj.getString("idcard"));
@ -642,8 +671,17 @@ public class IotDeviceService {
        // "idCard":"350122198601145513","username":"谢挺盛","usercode":"443a196ef8744536a531260eb26c05d7"}]}
        JSONObject data = obj.getJSONArray("data").getJSONObject(0);
        if(id==null){
            //从数据库中取id
            DeviceHealthyInfoMapping mapping = deviceHealthyInfoMappingDao.findByRid(data.getString("rid"));
            if(mapping!=null){
                id = mapping.getIndexId()==null?mapping.getId():mapping.getIndexId();
            }
        }
        index.setId(id);
        index.setRecordDate(DateUtil.strToDate(data.getString("measure_time")));
        index.setSortDate(index.getRecordDate());
        index.setType(data.getInteger("type"));
        index.setDel(data.getString("del"));
        index.setStatus(data.getInteger("status"));
        if(data.getString("blood_sugar")!=null){

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

@ -202,7 +202,7 @@ public class IotDeviceController extends BaseController{
                                                    @ApiParam(name="end",value = "结束时间")
                                                    @RequestParam(name="end",required = true)String end){
        try {
            return write(200,"","data",iotDeviceService.getCountByTimeAndStatusAndPatient(start, end, status, patientCode));
            return write(200,"查询成功","data",iotDeviceService.getCountByTimeAndStatusAndPatient(start, end, status, patientCode));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
@ -216,7 +216,7 @@ public class IotDeviceController extends BaseController{
                                                    @ApiParam(name="type",value = "类型")
                                                    @RequestParam(name="type",required = true)Integer type){
        try {
            return write(200,"","data",iotDeviceService.findByPatientAndType(patientCode,type));
            return write(200,"查询成功","data",iotDeviceService.findByPatientAndType(patientCode,type));
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());