|  | @ -173,9 +173,15 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
	
		
			
				|  |  |      * 燃气浓度
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> gasConcentration(String patient,String date){
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> gasConcentration(String patient,String date,String deviceSn){
 | 
	
		
			
				|  |  |         String sql = "SELECT r.value,r.create_time from wlyy_patient_device pd,base_device_health_index r " +
 | 
	
		
			
				|  |  |                 "WHERE pd.device_sn = r.device_sn and pd.`user` = '"+patient+"' ";
 | 
	
		
			
				|  |  |                 "WHERE pd.device_sn = r.device_sn  ";
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(patient)){
 | 
	
		
			
				|  |  |             sql +=" and pd.`user` = '"+patient+"' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(deviceSn)){
 | 
	
		
			
				|  |  |             sql +=" and r.device_sn = '"+deviceSn+"' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         sql += " and pd.category_code='14' and r.create_time>'"+date+" 00:00:00' and r.create_time<'"+date+" 23:59:59'  ORDER BY r.create_time desc ";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
	
		
			
				|  | @ -210,6 +216,11 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
	
		
			
				|  |  |         String userType = devicePatientDevice.getUserType();
 | 
	
		
			
				|  |  |         String sosAddress = null;
 | 
	
		
			
				|  |  |         String url ="";
 | 
	
		
			
				|  |  |         String sql = " select count(id) from wlyy_patient_device where user='"+devicePatientDevice.getUser()+"' and  device_sn='sn' and del=0 ";
 | 
	
		
			
				|  |  |         if (jdbcTemplate.queryForObject(sql,Integer.class)>0){
 | 
	
		
			
				|  |  |             return -5;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (userType == null) {
 | 
	
		
			
				|  |  |             userType = "-1";
 | 
	
		
			
				|  |  |             devicePatientDevice.setUserType("-1");
 | 
	
	
		
			
				|  | @ -919,9 +930,13 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
	
		
			
				|  |  |                     case "2"://血糖设备
 | 
	
		
			
				|  |  |                         break;
 | 
	
		
			
				|  |  |                     case "4"://手表 围栏与轨迹
 | 
	
		
			
				|  |  |                         if (StringUtils.isBlank(day)){
 | 
	
		
			
				|  |  |                             day = DateUtil.getStringDateShort();
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         devInfoObj =  securityMonitoringOrderService.patientSignTopicInfo(devInfoObj,patient,"preventLost");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         //轨迹动态
 | 
	
		
			
				|  |  |                         JSONArray locations = getX1Locations(deviceSn,day.replace("-",""));
 | 
	
		
			
				|  |  |                         devInfoObj.put("routes",locations);
 | 
	
		
			
				|  |  |                         break;
 | 
	
		
			
				|  |  |                     case "7"://报警器 紧急工单
 | 
	
		
			
				|  |  |                         break;
 | 
	
	
		
			
				|  | @ -942,13 +957,13 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
	
		
			
				|  |  |                         if (StringUtils.isBlank(day)){
 | 
	
		
			
				|  |  |                             day = DateUtil.getStringDateShort();
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         List<Map<String,Object>> listTmp = gasConcentration(patient,day);
 | 
	
		
			
				|  |  |                         List<Map<String,Object>> listTmp = gasConcentration(patient,day,deviceSn);
 | 
	
		
			
				|  |  |                         devInfoObj.put("monitorInfo",listTmp);
 | 
	
		
			
				|  |  |                         devInfoObj.put("day",day);
 | 
	
		
			
				|  |  |                         securityMonitoringOrderService.preventGasLeakage(devInfoObj,patient,false);
 | 
	
		
			
				|  |  |                         break;
 | 
	
		
			
				|  |  |                     case "15"://烟感报警器 获取最新浓度
 | 
	
		
			
				|  |  |                         securityMonitoringOrderService.preventFire(devInfoObj,patient,false);
 | 
	
		
			
				|  |  |                         securityMonitoringOrderService.preventFire(devInfoObj,patient,deviceSn,false);
 | 
	
		
			
				|  |  |                         devInfoObj.put("day",DateUtil.getStringDateShort());
 | 
	
		
			
				|  |  |                         break;
 | 
	
		
			
				|  |  |                 }
 | 
	
	
		
			
				|  | @ -975,10 +990,10 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 switch (device.getCategoryCode()){
 | 
	
		
			
				|  |  |                     case "1"://血压设备
 | 
	
		
			
				|  |  |                         result = getHealthIndex(result,deviceSn,null,page,pageSize);
 | 
	
		
			
				|  |  |                         result = getHealthIndex(result,1,deviceSn,null,page,pageSize);
 | 
	
		
			
				|  |  |                         break;
 | 
	
		
			
				|  |  |                     case "2"://血糖设备
 | 
	
		
			
				|  |  |                         result = getHealthIndex(result,deviceSn,null,page,pageSize);
 | 
	
		
			
				|  |  |                         result = getHealthIndex(result,2,deviceSn,null,page,pageSize);
 | 
	
		
			
				|  |  |                         break;
 | 
	
		
			
				|  |  |                     default://安防设备
 | 
	
		
			
				|  |  |                         result  = getEmeWarn(result,deviceSn,null,page,pageSize);
 | 
	
	
		
			
				|  | @ -991,29 +1006,105 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject getHealthIndex(JSONObject result,String deviceSn,String patient,Integer page,Integer pageSize){
 | 
	
		
			
				|  |  |         String sqlCount = "select count(id) from wlyy_patient_health_index where user ='"+patient+"' and device_sn='"+deviceSn+"' " +
 | 
	
		
			
				|  |  |                 " and del=1 ";
 | 
	
		
			
				|  |  |         String sql = "select *,CAST(DATE_FORMAT(record_date,'%Y-%m-%d %H:%i:%S') as char) record_date from wlyy_patient_health_index where user ='"+patient+"' and device_sn='"+deviceSn+"' " +
 | 
	
		
			
				|  |  |                 " and del=1 order by record_date desc limit "+page*pageSize+","+pageSize;
 | 
	
		
			
				|  |  |         long count = jdbcTemplate.queryForObject(sqlCount,long.class);
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         for (Map<String,Object> tmp:list){
 | 
	
		
			
				|  |  |             Integer type =Integer.parseInt(tmp.get("type").toString());
 | 
	
		
			
				|  |  |             String value1 = tmp.get("value1")==null?null:tmp.get("value1").toString();
 | 
	
		
			
				|  |  |             String value2 = tmp.get("value2")==null?null:tmp.get("value2").toString();
 | 
	
		
			
				|  |  |             String value3 = tmp.get("value3")==null?null:tmp.get("value3").toString();
 | 
	
		
			
				|  |  |             String value4 = tmp.get("value4")==null?null:tmp.get("value4").toString();
 | 
	
		
			
				|  |  |             String value5 = tmp.get("value5")==null?null:tmp.get("value5").toString();
 | 
	
		
			
				|  |  |             String value6 = tmp.get("value6")==null?null:tmp.get("value6").toString();
 | 
	
		
			
				|  |  |             String value7 = tmp.get("value7")==null?null:tmp.get("value7").toString();
 | 
	
		
			
				|  |  |             com.alibaba.fastjson.JSONArray errorInfo = healthIndexUtil.verifyHealthIndex(type,value1,value2,value3,value4,value5,value6,value7);
 | 
	
		
			
				|  |  |             tmp.put("errorInfo",errorInfo);
 | 
	
		
			
				|  |  |     public JSONObject getHealthIndex(JSONObject result,Integer type,String deviceSn,String patient,Integer page,Integer pageSize){
 | 
	
		
			
				|  |  |         page = page>0?page-1:0;
 | 
	
		
			
				|  |  |         Long count =0l;
 | 
	
		
			
				|  |  |         PageRequest pageRequest = new PageRequest(page, pageSize);
 | 
	
		
			
				|  |  |         result.put("dataList",new ArrayList<>());
 | 
	
		
			
				|  |  |         if (type == 1) {
 | 
	
		
			
				|  |  |             List<Object> re = new ArrayList<>();
 | 
	
		
			
				|  |  |             String countSql =" select count(*) from wlyy_patient_health_index a where a.user = '"+patient+"' " +
 | 
	
		
			
				|  |  |                     " and a.type=1 and a.device_sn='"+deviceSn+"' and a.del = '1' group by DATE_FORMAT(a.record_date,'%Y-%m-%d') ";
 | 
	
		
			
				|  |  |             count = jdbcTemplate.queryForObject(countSql,Long.class);
 | 
	
		
			
				|  |  |             String sql =" select DATE_FORMAT(a.record_date,'%Y-%m-%d') from wlyy_patient_health_index a where a.user = '"+patient+"' " +
 | 
	
		
			
				|  |  |                     " and a.type=1 and a.device_sn='"+deviceSn+"' and a.del = '1' group by DATE_FORMAT(a.record_date,'%Y-%m-%d') order by DATE_FORMAT(a.record_date,'%Y-%m-%d') desc limit "+pageRequest.getOffset()+" ,"+pageRequest.getPageSize();
 | 
	
		
			
				|  |  |             List<String> dateList = jdbcTemplate.queryForList(sql,String.class);
 | 
	
		
			
				|  |  |             if (dateList != null && dateList.size() > 0) {
 | 
	
		
			
				|  |  |                 for (String dateString : dateList) {
 | 
	
		
			
				|  |  |                     com.alibaba.fastjson.JSONObject obj = healthIndexService.getPatientXT_Json(patient, dateString);
 | 
	
		
			
				|  |  |                     if (obj != null) {
 | 
	
		
			
				|  |  |                         re.add(obj);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             result.put("dataList",re);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         else if (type == 2){
 | 
	
		
			
				|  |  |             JSONArray re = new JSONArray();
 | 
	
		
			
				|  |  |             // 排序
 | 
	
		
			
				|  |  |             String countSql =" select count(*) from wlyy_patient_health_index a where a.user = '"+patient+"' " +
 | 
	
		
			
				|  |  |                     " and a.type=2 and a.device_sn='"+deviceSn+"' and a.del = '1' GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date ";
 | 
	
		
			
				|  |  |             count = jdbcTemplate.queryForObject(countSql,Long.class);
 | 
	
		
			
				|  |  |             String sql = "SELECT " +
 | 
	
		
			
				|  |  |                     "MIN(id) id" +
 | 
	
		
			
				|  |  |                     ", user" +
 | 
	
		
			
				|  |  |                     ",value1" +
 | 
	
		
			
				|  |  |                     ",value2" +
 | 
	
		
			
				|  |  |                     ",value3" +
 | 
	
		
			
				|  |  |                     ",value4" +
 | 
	
		
			
				|  |  |                     ",value5" +
 | 
	
		
			
				|  |  |                     ",value6" +
 | 
	
		
			
				|  |  |                     ",value7" +
 | 
	
		
			
				|  |  |                     ",device_sn" +
 | 
	
		
			
				|  |  |                     ",type" +
 | 
	
		
			
				|  |  |                     ",record_date" +
 | 
	
		
			
				|  |  |                     ",sort_date" +
 | 
	
		
			
				|  |  |                     ",czrq as createDate" +
 | 
	
		
			
				|  |  |                     ",min(czrq) czrq " +
 | 
	
		
			
				|  |  |                     " from wlyy_patient_health_index " +
 | 
	
		
			
				|  |  |                     " WHERE `user` = '" + patient + "' " +
 | 
	
		
			
				|  |  |                     " and type =" + type +" "+
 | 
	
		
			
				|  |  |                     " and device_sn='"+deviceSn+"' "+
 | 
	
		
			
				|  |  |                     " and del = '1' " +
 | 
	
		
			
				|  |  |                     " GROUP BY user,value1,value2,value3,value4,value5,value6,value7,type,record_date,sort_date " +
 | 
	
		
			
				|  |  |                     " order by record_date desc ,sort_date desc limit " + pageRequest.getOffset() + " ," + pageRequest.getPageSize() + " ";
 | 
	
		
			
				|  |  |             List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |             for (Map<String, Object> map : list) {
 | 
	
		
			
				|  |  |                 JSONObject json = new JSONObject();
 | 
	
		
			
				|  |  |                 json.put("id", map.get("id"));
 | 
	
		
			
				|  |  |                 json.put("healthindexid", 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"));
 | 
	
		
			
				|  |  |                 //是否为补传数据(设备上传且测量时间和创建时间不匹配)
 | 
	
		
			
				|  |  |                 Date recordDate = (Date)map.get("record_date");
 | 
	
		
			
				|  |  |                 Date createDate = (Date) map.get("createDate");
 | 
	
		
			
				|  |  |                 String recordTime = DateUtil.dateToStr(recordDate,DateUtil.YYYY_MM_DD);
 | 
	
		
			
				|  |  |                 String createTime = DateUtil.dateToStr(createDate,DateUtil.YYYY_MM_DD);
 | 
	
		
			
				|  |  |                 if (map.get("device_sn") == null){
 | 
	
		
			
				|  |  |                     json.put("isSupplement",0);
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     if (recordTime.compareToIgnoreCase(createTime)==0){
 | 
	
		
			
				|  |  |                         json.put("isSupplement",0);
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         json.put("isSupplement",1);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 re.put(json);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             result.put("dataList",re);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         result.put("total",count);
 | 
	
		
			
				|  |  |         result.put("page",page+1);
 | 
	
		
			
				|  |  |         result.put("pageSize",pageSize);
 | 
	
		
			
				|  |  |         result.put("dataList",list);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -1225,14 +1316,17 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
	
		
			
				|  |  |         com.alibaba.fastjson.JSONObject resObj = JSON.parseObject(responseStr);
 | 
	
		
			
				|  |  |         if (resObj.getBooleanValue("success")){
 | 
	
		
			
				|  |  |             com.alibaba.fastjson.JSONArray arr = resObj.getJSONArray("objs");
 | 
	
		
			
				|  |  |             arr.sort(Comparator.comparing(obj -> ((JSONObject) obj).getLong("created_at")));
 | 
	
		
			
				|  |  |             arr.sort(Comparator.comparing(obj -> ((com.alibaba.fastjson.JSONObject) obj).getJSONObject("created_at").getLong("$date")));
 | 
	
		
			
				|  |  |             for (int i=0;i<arr.size();i++){
 | 
	
		
			
				|  |  |                 com.alibaba.fastjson.JSONObject obj = arr.getJSONObject(i);
 | 
	
		
			
				|  |  |                 com.alibaba.fastjson.JSONArray pointArr = obj.getJSONObject("point").getJSONArray("coordinates");
 | 
	
		
			
				|  |  |                 Double lon = pointArr.getDouble(0);
 | 
	
		
			
				|  |  |                 Double lat = pointArr.getDouble(1);
 | 
	
		
			
				|  |  |                 com.alibaba.fastjson.JSONObject pointJson = gpsUtil.gcj02_To_Bd09(lat,lon);
 | 
	
		
			
				|  |  |                 result.put(pointJson);
 | 
	
		
			
				|  |  |                 try {
 | 
	
		
			
				|  |  |                     com.alibaba.fastjson.JSONObject obj = arr.getJSONObject(i);
 | 
	
		
			
				|  |  |                     com.alibaba.fastjson.JSONArray pointArr = obj.getJSONObject("point").getJSONArray("coordinates");
 | 
	
		
			
				|  |  |                     Double lon = pointArr.getDouble(0);
 | 
	
		
			
				|  |  |                     Double lat = pointArr.getDouble(1);
 | 
	
		
			
				|  |  |                     com.alibaba.fastjson.JSONObject pointJson = gpsUtil.gcj02_To_Bd09(lat,lon);
 | 
	
		
			
				|  |  |                     result.put(pointJson);
 | 
	
		
			
				|  |  |                 }catch (Exception e){
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 |