|  | @ -37,10 +37,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.lang.reflect.Field;
 | 
	
		
			
				|  |  | import java.util.ArrayList;
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | import java.util.stream.Collectors;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
	
		
			
				|  | @ -664,4 +661,234 @@ public class PatientInfoPlatFormService {
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         return PageEnvelop.getSuccessListWithPage("查询成功",list,page,pageSize,count);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      *获取设备详情
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> getPatientDeviceInfoWithDetail(String patient){
 | 
	
		
			
				|  |  |         List<Map<String,Object>>  list = new ArrayList<>();
 | 
	
		
			
				|  |  |         list = patientDeviceService.patientDeviceListByTopic(patient,null);
 | 
	
		
			
				|  |  |         for (Map<String,Object> tmp :list){
 | 
	
		
			
				|  |  |             String category_code = tmp.get("category_code").toString();
 | 
	
		
			
				|  |  |             String deviceSN = tmp.get("device_sn").toString();
 | 
	
		
			
				|  |  |             Map<String,Object> detailInfo =  getDeviceIndexAndOrder(category_code,deviceSN,patient);
 | 
	
		
			
				|  |  |             tmp.put("detailInfo",detailInfo);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return list;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取设备关联数据
 | 
	
		
			
				|  |  |      * 手表4:电量、佩戴状态、是否预警、在线状态
 | 
	
		
			
				|  |  |      * 报警器7:电量  是否报警、在线状态
 | 
	
		
			
				|  |  |      * 床带13:是否压床、是否预警、心率和呼吸频率、在线状态
 | 
	
		
			
				|  |  |      * 监控12:是否预警、在线状态
 | 
	
		
			
				|  |  |      * 烟雾15:浓度、是否预警、在线状态
 | 
	
		
			
				|  |  |      * 燃气14 :浓度、是否预警、在线状态
 | 
	
		
			
				|  |  |      * 拐杖16:是否预警、在线状态
 | 
	
		
			
				|  |  |      * 血压2:最近一次收缩压,舒张压、在线状态
 | 
	
		
			
				|  |  |      * 血糖1:最近一次血糖、在线状态
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Map<String,Object> getDeviceIndexAndOrder(String category_code,String deviceSn,String patient){
 | 
	
		
			
				|  |  |         Map<String,Object> detailInfo = new HashMap<>();
 | 
	
		
			
				|  |  |         String sql = " select IFNULL(contact_status,0) contact_status from wlyy_devices where device_code='"+deviceSn+"' ";
 | 
	
		
			
				|  |  |         List<String> contact_status = jdbcTemplate.queryForList(sql,String.class);
 | 
	
		
			
				|  |  |         detailInfo.put("contact_status",0);
 | 
	
		
			
				|  |  |         if (contact_status.size()>0){
 | 
	
		
			
				|  |  |             detailInfo.put("contact_status",contact_status.get(0));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         switch (category_code){
 | 
	
		
			
				|  |  |             case "1"://血糖 最近一次血糖、在线状态
 | 
	
		
			
				|  |  |                 sql = " select *,CAST(DATE_FORMAT(record_date,'%Y-%m-%d %H:%i:%S') as char) record_date,  " +
 | 
	
		
			
				|  |  |                         " CAST(DATE_FORMAT(sort_date,'%Y-%m-%d %H:%i:%S') as char) sort_date,  " +
 | 
	
		
			
				|  |  |                         " CAST(DATE_FORMAT(czrq,'%Y-%m-%d %H:%i:%S') as char) czrq from wlyy_patient_health_index " +
 | 
	
		
			
				|  |  |                         " where device_sn='"+deviceSn+"' ORDER BY sort_date DESC LIMIT 1  ";
 | 
	
		
			
				|  |  |                 List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                     detailInfo.put("healthIndex",sqlResult.get(0));
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     detailInfo.put("healthIndex",null);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case "2"://血压 最近一次收缩压,舒张压、在线状态
 | 
	
		
			
				|  |  |                 sql = " select *,CAST(DATE_FORMAT(record_date,'%Y-%m-%d %H:%i:%S') as char) record_date,  " +
 | 
	
		
			
				|  |  |                         " CAST(DATE_FORMAT(sort_date,'%Y-%m-%d %H:%i:%S') as char) sort_date,  " +
 | 
	
		
			
				|  |  |                         " CAST(DATE_FORMAT(czrq,'%Y-%m-%d %H:%i:%S') as char) czrq from wlyy_patient_health_index " +
 | 
	
		
			
				|  |  |                         " where device_sn='"+deviceSn+"' ORDER BY sort_date DESC LIMIT 1  ";
 | 
	
		
			
				|  |  |                 sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                     detailInfo.put("healthIndex",sqlResult.get(0));
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     detailInfo.put("healthIndex",null);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case "4"://手表 电量、佩戴状态、是否预警、在线状态
 | 
	
		
			
				|  |  |                 sql = "  select o.id,p.id patient,p.name,p.idcard,p.residential_area,'20' orderType,'1' type,o.serve_address,'紧急呼叫' serve_desc,  " +
 | 
	
		
			
				|  |  |                         " o.status,DATE_FORMAT(o.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_emergency_assistance_order o " +
 | 
	
		
			
				|  |  |                         " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' " +
 | 
	
		
			
				|  |  |                         " UNION " +
 | 
	
		
			
				|  |  |                         " select o.id,p.id patient,p.name,p.idcard,p.residential_area,'22' orderType,'1' type,o.serve_address,o.serve_desc,  " +
 | 
	
		
			
				|  |  |                         " o.status,DATE_FORMAT(o.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_security_monitoring_order o " +
 | 
	
		
			
				|  |  |                         " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' " +
 | 
	
		
			
				|  |  |                         "ORDER BY create_time desc limit 1 ";
 | 
	
		
			
				|  |  |                 sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",true);
 | 
	
		
			
				|  |  |                     detailInfo.put("orderInfo",sqlResult.get(0));
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",false);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 JSONObject response = patientDeviceService.getAqgDeviceInfo2(deviceSn);
 | 
	
		
			
				|  |  |                 //手表佩戴状态
 | 
	
		
			
				|  |  |                 if (response.containsKey("wear_flag") && response.get("wear_flag") != null) {
 | 
	
		
			
				|  |  |                     detailInfo.put("wear_flag", response.get("wear_flag"));
 | 
	
		
			
				|  |  |                     detailInfo.put("wear_flagName", 1==response.getInteger("wear_flag")?"未佩戴":"已佩戴");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 //电量
 | 
	
		
			
				|  |  |                 if (response.containsKey("remaining_power") && response.get("remaining_power") != null) {
 | 
	
		
			
				|  |  |                     detailInfo.put("remaining_power", response.get("remaining_power"));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 //在线状态实时获取
 | 
	
		
			
				|  |  |                 if (!response.getBoolean("online")) {//设备在线状态
 | 
	
		
			
				|  |  |                     detailInfo.put("contact_status",0);
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     detailInfo.put("contact_status",1);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case "7"://报警器 电量  是否报警、在线状态
 | 
	
		
			
				|  |  |                 sql = "  select o.id,p.id patient,p.name,p.idcard,p.residential_area,'20' orderType,'1' type,o.serve_address,'紧急呼叫' serve_desc,  " +
 | 
	
		
			
				|  |  |                         " o.status,DATE_FORMAT(o.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_emergency_assistance_order o " +
 | 
	
		
			
				|  |  |                         " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' ORDER BY create_time desc limit 1 ";
 | 
	
		
			
				|  |  |                 sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",true);
 | 
	
		
			
				|  |  |                     detailInfo.put("orderInfo",sqlResult.get(0));
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",false);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 response = patientDeviceService.getAqgDeviceInfo2(deviceSn);
 | 
	
		
			
				|  |  |                 //电量
 | 
	
		
			
				|  |  |                 if (response.containsKey("remaining_power") && response.get("remaining_power") != null) {
 | 
	
		
			
				|  |  |                     detailInfo.put("remaining_power", response.get("remaining_power"));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 //在线状态实时获取
 | 
	
		
			
				|  |  |                 if (!response.getBoolean("online")) {//设备在线状态
 | 
	
		
			
				|  |  |                     detailInfo.put("contact_status",0);
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     detailInfo.put("contact_status",1);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case "12"://监控
 | 
	
		
			
				|  |  |                 sql = " select o.id,p.id patient,p.name,p.idcard,p.residential_area,'22' orderType,'1' type,o.serve_address,o.serve_desc,  " +
 | 
	
		
			
				|  |  |                      " o.status,DATE_FORMAT(o.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_security_monitoring_order o " +
 | 
	
		
			
				|  |  |                      " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' " +
 | 
	
		
			
				|  |  |                      "ORDER BY create_time desc limit 1 ";
 | 
	
		
			
				|  |  |                 sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",true);
 | 
	
		
			
				|  |  |                     detailInfo.put("orderInfo",sqlResult.get(0));
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",false);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case "13"://床带 是否压床、 心率和呼吸频率、在线状态
 | 
	
		
			
				|  |  |                 sql = " select o.id,p.id patient,p.name,p.idcard,p.residential_area,'22' orderType,'1' type,o.serve_address,o.serve_desc,  " +
 | 
	
		
			
				|  |  |                         " o.status,DATE_FORMAT(o.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_security_monitoring_order o " +
 | 
	
		
			
				|  |  |                         " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' " +
 | 
	
		
			
				|  |  |                         "ORDER BY create_time desc limit 1 ";
 | 
	
		
			
				|  |  |                 sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",true);
 | 
	
		
			
				|  |  |                     detailInfo.put("orderInfo",sqlResult.get(0));
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",false);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 JSONObject deviceInfo = patientDeviceService.getSleepDeviceInfo(deviceSn);
 | 
	
		
			
				|  |  |                 if (deviceInfo.getBooleanValue("success")) {
 | 
	
		
			
				|  |  |                     com.alibaba.fastjson.JSONArray objInfo = deviceInfo.getJSONArray("objs");
 | 
	
		
			
				|  |  |                     if (objInfo.size() > 0) {
 | 
	
		
			
				|  |  |                         response = objInfo.getJSONObject(0);
 | 
	
		
			
				|  |  |                         if (!response.getBoolean("online")) {//设备在线状态
 | 
	
		
			
				|  |  |                             detailInfo.put("contact_status",0);
 | 
	
		
			
				|  |  |                         } else {
 | 
	
		
			
				|  |  |                             detailInfo.put("contact_status",1);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         if (response.getBooleanValue("onbed")) {//当前在床状态
 | 
	
		
			
				|  |  |                             detailInfo.put("bedStatus", 1);
 | 
	
		
			
				|  |  |                             detailInfo.put("heartRate", response.getString("heartrate"));
 | 
	
		
			
				|  |  |                             detailInfo.put("breath", response.getString("breathrate"));
 | 
	
		
			
				|  |  |                         } else {
 | 
	
		
			
				|  |  |                             detailInfo.put("bedStatus", 0);
 | 
	
		
			
				|  |  |                             detailInfo.put("heartRate", null);
 | 
	
		
			
				|  |  |                             detailInfo.put("breath", null);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case "14"://燃气
 | 
	
		
			
				|  |  |                 sql = " select o.id,p.id patient,p.name,p.idcard,p.residential_area,'22' orderType,'1' type,o.serve_address,o.serve_desc,  " +
 | 
	
		
			
				|  |  |                         " o.status,DATE_FORMAT(o.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_security_monitoring_order o " +
 | 
	
		
			
				|  |  |                         " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' " +
 | 
	
		
			
				|  |  |                         "ORDER BY create_time desc limit 1 ";
 | 
	
		
			
				|  |  |                 sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",true);
 | 
	
		
			
				|  |  |                     detailInfo.put("orderInfo",sqlResult.get(0));
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",false);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 //获取最新一次燃气浓度
 | 
	
		
			
				|  |  |                 sql = "";
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case "15"://烟感
 | 
	
		
			
				|  |  |                 sql = " select o.id,p.id patient,p.name,p.idcard,p.residential_area,'22' orderType,'1' type,o.serve_address,o.serve_desc,  " +
 | 
	
		
			
				|  |  |                         " o.status,DATE_FORMAT(o.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_security_monitoring_order o " +
 | 
	
		
			
				|  |  |                         " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' " +
 | 
	
		
			
				|  |  |                         "ORDER BY create_time desc limit 1 ";
 | 
	
		
			
				|  |  |                 sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",true);
 | 
	
		
			
				|  |  |                     detailInfo.put("orderInfo",sqlResult.get(0));
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",false);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 //获取最新一次燃气浓度
 | 
	
		
			
				|  |  |                 sql = " select value,record_time from base_device_health_index where device_sn='"+deviceSn+"' ORDER BY record_time desc limit 1 ";
 | 
	
		
			
				|  |  |                 sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                     detailInfo.putAll(sqlResult.get(0));
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     detailInfo.put("value",null);
 | 
	
		
			
				|  |  |                     detailInfo.put("record_time",null);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case "16"://拐杖 是否预警
 | 
	
		
			
				|  |  |                 sql = "  select o.id,p.id patient,p.name,p.idcard,p.residential_area,'20' orderType,'1' type,o.serve_address,'紧急呼叫' serve_desc,  " +
 | 
	
		
			
				|  |  |                         " o.status,DATE_FORMAT(o.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_emergency_assistance_order o " +
 | 
	
		
			
				|  |  |                         " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' " +
 | 
	
		
			
				|  |  |                         " UNION " +
 | 
	
		
			
				|  |  |                         " select o.id,p.id patient,p.name,p.idcard,p.residential_area,'22' orderType,'1' type,o.serve_address,o.serve_desc,  " +
 | 
	
		
			
				|  |  |                         " o.status,DATE_FORMAT(o.create_time,'%Y-%m-%d %H:%i:%S') create_time from base_security_monitoring_order o " +
 | 
	
		
			
				|  |  |                         " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' " +
 | 
	
		
			
				|  |  |                         "ORDER BY create_time desc limit 1 ";
 | 
	
		
			
				|  |  |                 sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",true);
 | 
	
		
			
				|  |  |                     detailInfo.put("orderInfo",sqlResult.get(0));
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     detailInfo.put("warnStatus",false);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 sql = " select value,record_time from base_device_health_index where device_sn='"+deviceSn+"' ORDER BY record_time desc limit 1 ";
 | 
	
		
			
				|  |  |                 sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                     detailInfo.putAll(sqlResult.get(0));
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     detailInfo.put("value",null);
 | 
	
		
			
				|  |  |                     detailInfo.put("record_time",null);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return detailInfo;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |