| 
					
				 | 
			
			
				@ -863,7 +863,82 @@ public class PatientHealthIndexService extends BaseJpaService<DevicePatientHealt 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return re; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject findChartByPatientWithAvg(String patient, int type, int gi_type, String begin, String end,String deviceSn) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray re = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "MIN(id) id" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ", user" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",value1" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",value2" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",value3" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",value4" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",value5" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",value6" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",value7" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",device_sn" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",type" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",record_date" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",sort_date" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",min(czrq) czrq " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " from wlyy_patient_health_index " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " WHERE 1=1 "+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " and type =" + type + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " and record_date >= '" + begin + "'" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " and record_date <= '" + end + "' " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " and del = '1' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isNotBlank(patient)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql+=" and user = '" + patient + "' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isNotBlank(deviceSn)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += " and device_sn='"+deviceSn+"' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String conditionApp = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (gi_type != 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            conditionApp = " and value2 = '" + gi_type + "' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql = sql + conditionApp + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " order by record_date desc ,sort_date desc limit " + 0 + " ," + 1000 + " "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> list = findByPatientAndTime(sql,patient,type,1000,gi_type,begin,end); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (Map<String, Object> map : list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject json = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("id", map.get("id")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("patient", map.get("user")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("value1", map.get("value1")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("value2", map.get("value2")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("value3", map.get("value3")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("value4", map.get("value4")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("value5", map.get("value5")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("value6", map.get("value6")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("value7", map.get("value7")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("deviceSn", map.get("device_sn") == null ? "" : map.get("device_sn")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("type", map.get("type")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Date date = (Date) map.get("record_date"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (type == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("date", DateUtil.dateToStr(date, DateUtil.YYYY_MM_DD_HH_MM_SS)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("date", DateUtil.dateToStr(date, DateUtil.YYYY_MM_DD)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("sortDate", map.get("sort_date")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            json.put("czrq", map.get("czrq")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            re.put(json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("list",re); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        OptionalDouble avg =  list.stream().mapToDouble(t -> t.get("value1") == null ? 0.0 :Double.parseDouble(t.get("value1").toString())).average(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("avg",0.0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("avg",avg.getAsDouble()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (Exception e){} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 按时间段查询患者健康指标 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 |