|  | @ -910,88 +910,103 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
												
													
														
															|  |             result.put(ResponseContant.resultMsg,"未查询到该设备");
 |  |             result.put(ResponseContant.resultMsg,"未查询到该设备");
 | 
												
													
														
															|  |         }else {
 |  |         }else {
 | 
												
													
														
															|  |             DevicePatientDevice device = devices.get(0);
 |  |             DevicePatientDevice device = devices.get(0);
 | 
												
													
														
															|  |             if (!patient.equals(device.getUser())){
 |  | 
 | 
												
													
														
															|  |                 result.put(ResponseContant.resultFlag,ResponseContant.fail);
 |  | 
 | 
												
													
														
															|  |                 result.put(ResponseContant.resultMsg,"居民未绑定该设备");
 |  | 
 | 
												
													
														
															|  |             }else {
 |  | 
 | 
												
													
														
															|  |                 String sql = "select dd.photo,GROUP_CONCAT( p.name) as patientName,pd.device_sn,dd.brands,dd.category_code,dd.model,pd.device_name,date_format(pd.czrq,'%Y-%m-%d %H:%i:%S' ) deviceTime,wd.manufacturer,p.mobile,p.address,p.idcard,wd.device_type  " +
 |  | 
 | 
												
													
														
															|  |                         "from dm_device dd INNER JOIN wlyy_patient_device pd on dd.category_code = pd.category_code INNER JOIN base_patient p on p.id = pd.user " +
 |  | 
 | 
												
													
														
															|  |                         " INNER JOIN wlyy_devices wd on dd.model = wd.device_model and pd.device_sn = wd.device_code " +
 |  | 
 | 
												
													
														
															|  |                         "where 1=1 and  pd.del=0 and pd.device_sn ='"+deviceSn+"' group by pd.device_sn";
 |  | 
 | 
												
													
														
															|  |                 Map<String,Object> devInfo = jdbcTemplate.queryForMap(sql);
 |  | 
 | 
												
													
														
															|  |                 devInfo.put("patient",patient);
 |  | 
 | 
												
													
														
															|  |                 devInfo.put("sosContactsDOS",new ArrayList<>());
 |  | 
 | 
												
													
														
															|  |                 String dataSql= "";
 |  | 
 | 
												
													
														
															|  |                 String recordSql = "";
 |  | 
 | 
												
													
														
															|  |                 List<Map<String , Object>> dataList = new ArrayList<>();
 |  | 
 | 
												
													
														
															|  |                 List<Map<String , Object>> recordList = new ArrayList<>();
 |  | 
 | 
												
													
														
															|  |                 String addresSql = "SELECT sp.org_code orgCode,sp.org_name orgName FROM base_service_package_record spr , base_service_package sp\n" +
 |  | 
 | 
												
													
														
															|  |                         "WHERE spr.service_package_id = sp.id AND spr.patient = '"+patient+"' AND sp.org_code IS NOT NULL GROUP BY sp.org_code,sp.org_name";
 |  | 
 | 
												
													
														
															|  |                 List<Map<String, Object>> addressList = jdbcTemplate.queryForList(addresSql);
 |  | 
 | 
												
													
														
															|  |                 if (addressList.size() > 0) {
 |  | 
 | 
												
													
														
															|  |                     devInfo.put("orgName",addressList.get(0).get("orgName"));
 |  | 
 | 
												
													
														
															|  |                     devInfo.put("orgCode",addressList.get(0).get("orgCode"));
 |  | 
 | 
												
													
														
															|  |                 } else {
 |  | 
 | 
												
													
														
															|  |                     devInfo.put("orgName","");
 |  | 
 | 
												
													
														
															|  |                     devInfo.put("orgCode","");
 |  | 
 | 
												
													
														
															|  |                 }
 |  | 
 | 
												
													
														
															|  | 
 |  | //            if (!patient.equals(device.getUser())){
 | 
												
													
														
															|  | 
 |  | //                result.put(ResponseContant.resultFlag,ResponseContant.fail);
 | 
												
													
														
															|  | 
 |  | //                result.put(ResponseContant.resultMsg,"居民未绑定该设备");
 | 
												
													
														
															|  | 
 |  | //            }else {
 | 
												
													
														
															|  | 
 |  |             String sql = "select dd.photo,GROUP_CONCAT(DISTINCT p.name) as patientName,pd.device_sn,dd.brands,dd.category_code,dd.model,pd.device_name,date_format(pd.czrq,'%Y-%m-%d %H:%i:%S' ) deviceTime,wd.manufacturer,p.mobile,p.address,p.idcard,wd.device_type  " +
 | 
												
													
														
															|  | 
 |  |                     "from dm_device dd INNER JOIN wlyy_patient_device pd on dd.category_code = pd.category_code INNER JOIN base_patient p on p.id = pd.user " +
 | 
												
													
														
															|  | 
 |  |                     " INNER JOIN wlyy_devices wd on dd.model = wd.device_model and pd.device_sn = wd.device_code " +
 | 
												
													
														
															|  | 
 |  |                     "where 1=1 and  pd.del=0 and pd.device_sn ='" + deviceSn + "' group by pd.device_sn";
 | 
												
													
														
															|  | 
 |  |             Map<String, Object> devInfo = jdbcTemplate.queryForMap(sql);
 | 
												
													
														
															|  | 
 |  |             devInfo.put("patient", patient);
 | 
												
													
														
															|  | 
 |  |             devInfo.put("sosContactsDOS", new ArrayList<>());
 | 
												
													
														
															|  | 
 |  |             String dataSql = "";
 | 
												
													
														
															|  | 
 |  |             String recordSql = "";
 | 
												
													
														
															|  | 
 |  |             List<Map<String, Object>> dataList = new ArrayList<>();
 | 
												
													
														
															|  | 
 |  |             List<Map<String, Object>> recordList = new ArrayList<>();
 | 
												
													
														
															|  | 
 |  |             String addresSql = "SELECT sp.org_code orgCode,sp.org_name orgName FROM base_service_package_record spr , base_service_package sp\n" +
 | 
												
													
														
															|  | 
 |  |                     "WHERE spr.service_package_id = sp.id AND spr.patient = '" + patient + "' AND sp.org_code IS NOT NULL GROUP BY sp.org_code,sp.org_name";
 | 
												
													
														
															|  | 
 |  |             List<Map<String, Object>> addressList = jdbcTemplate.queryForList(addresSql);
 | 
												
													
														
															|  | 
 |  |             if (addressList.size() > 0) {
 | 
												
													
														
															|  | 
 |  |                 devInfo.put("orgName", addressList.get(0).get("orgName"));
 | 
												
													
														
															|  | 
 |  |                 devInfo.put("orgCode", addressList.get(0).get("orgCode"));
 | 
												
													
														
															|  | 
 |  |             } else {
 | 
												
													
														
															|  | 
 |  |                 devInfo.put("orgName", "");
 | 
												
													
														
															|  | 
 |  |                 devInfo.put("orgCode", "");
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |                 if ("4".equals(device.getCategoryCode())||"7".equals(device.getCategoryCode())){
 |  | 
 | 
												
													
														
															|  |                     devInfo.put("sosContactsDOS",contactsService.getPatientSosContacts(patient));
 |  | 
 | 
												
													
														
															|  |                 }
 |  | 
 | 
												
													
														
															|  |                 com.alibaba.fastjson.JSONObject devInfoObj = JSON.parseObject(JSON.toJSONString(devInfo, SerializerFeature.WriteMapNullValue));
 |  | 
 | 
												
													
														
															|  |                 switch (device.getCategoryCode()){
 |  | 
 | 
												
													
														
															|  |                     case "1"://血压设备
 |  | 
 | 
												
													
														
															|  |                         dataSql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '"+deviceSn+"' AND del = 1 ORDER BY sort_date DESC LIMIT 10";
 |  | 
 | 
												
													
														
															|  |                         dataList = jdbcTemplate.queryForList(dataSql);
 |  | 
 | 
												
													
														
															|  |                         devInfoObj.put("data",dataList);
 |  | 
 | 
												
													
														
															|  |                         break;
 |  | 
 | 
												
													
														
															|  |                     case "2"://血糖设备
 |  | 
 | 
												
													
														
															|  |                         dataSql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '"+deviceSn+"' AND del = 1 ORDER BY sort_date DESC LIMIT 10";
 |  | 
 | 
												
													
														
															|  |                         dataList = jdbcTemplate.queryForList(dataSql);
 |  | 
 | 
												
													
														
															|  |                         devInfoObj.put("data",dataList);
 |  | 
 | 
												
													
														
															|  |                         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;
 |  | 
 | 
												
													
														
															|  |                     case "12"://监控 视频地址
 |  | 
 | 
												
													
														
															|  |                         com.alibaba.fastjson.JSONObject tmp =ysDeviceService.getDeviceLiveAddress(patient,deviceSn,1,null);
 |  | 
 | 
												
													
														
															|  |                         devInfoObj.put("monitorInfoStatus",tmp.getIntValue(ResponseContant.resultFlag));
 |  | 
 | 
												
													
														
															|  |                         if (tmp.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
 |  | 
 | 
												
													
														
															|  |                             devInfoObj.put("monitorInfo",tmp.getString(ResponseContant.resultMsg));
 |  | 
 | 
												
													
														
															|  |                         }
 |  | 
 | 
												
													
														
															|  |                         else {
 |  | 
 | 
												
													
														
															|  |                             devInfoObj.put("monitorInfo",tmp.getJSONObject(ResponseContant.resultMsg));
 |  | 
 | 
												
													
														
															|  |                         }
 |  | 
 | 
												
													
														
															|  |                         break;
 |  | 
 | 
												
													
														
															|  |                     case "13"://睡眠带 获取当天睡眠详情
 |  | 
 | 
												
													
														
															|  |                         securityMonitoringOrderService.preventOutOfBed(devInfoObj,patient,false,day);
 |  | 
 | 
												
													
														
															|  |                         break;
 |  | 
 | 
												
													
														
															|  |                     case "14"://气感报警器 当天监测记录以及最新浓度
 |  | 
 | 
												
													
														
															|  |                         if (StringUtils.isBlank(day)){
 |  | 
 | 
												
													
														
															|  |                             day = DateUtil.getStringDateShort();
 |  | 
 | 
												
													
														
															|  |                         }
 |  | 
 | 
												
													
														
															|  |                         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,deviceSn,false);
 |  | 
 | 
												
													
														
															|  |                         devInfoObj.put("day",DateUtil.getStringDateShort());
 |  | 
 | 
												
													
														
															|  |                         break;
 |  | 
 | 
												
													
														
															|  |                 }
 |  | 
 | 
												
													
														
															|  | 
 |  |             if ("4".equals(device.getCategoryCode()) || "7".equals(device.getCategoryCode())) {
 | 
												
													
														
															|  | 
 |  |                 devInfo.put("sosContactsDOS", contactsService.getPatientSosContacts(patient));
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             com.alibaba.fastjson.JSONObject devInfoObj = JSON.parseObject(JSON.toJSONString(devInfo, SerializerFeature.WriteMapNullValue));
 | 
												
													
														
															|  | 
 |  |             switch (device.getCategoryCode()) {
 | 
												
													
														
															|  | 
 |  |                 case "1"://血压设备
 | 
												
													
														
															|  | 
 |  |                     dataSql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '" + deviceSn + "' AND del = 1 ORDER BY sort_date DESC LIMIT 10";
 | 
												
													
														
															|  | 
 |  |                     dataList = jdbcTemplate.queryForList(dataSql);
 | 
												
													
														
															|  | 
 |  |                     devInfoObj.put("data", dataList);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |                     String ssql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '" + deviceSn + "' AND del = 1 AND status = 1 ";
 | 
												
													
														
															|  | 
 |  |                     String bloodPressureSql = ssql + " AND type = 1 ORDER BY sort_date DESC LIMIT 10";
 | 
												
													
														
															|  | 
 |  |                     dataList = jdbcTemplate.queryForList(bloodPressureSql);
 | 
												
													
														
															|  | 
 |  |                     devInfoObj.put("bloodPressure",dataList); //血压
 | 
												
													
														
															|  | 
 |  |                     break;
 | 
												
													
														
															|  | 
 |  |                 case "2"://血糖设备
 | 
												
													
														
															|  | 
 |  |                     dataSql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '" + deviceSn + "' AND del = 1 ";
 | 
												
													
														
															|  | 
 |  |                     dataSql += " ORDER BY sort_date DESC LIMIT 10";
 | 
												
													
														
															|  | 
 |  |                     dataList = jdbcTemplate.queryForList(dataSql);
 | 
												
													
														
															|  | 
 |  |                     devInfoObj.put("data", dataList);    //血糖数据
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |                     recordSql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '" + deviceSn + "' AND del = 1  AND status = 1 ORDER BY sort_date DESC LIMIT 10";
 | 
												
													
														
															|  | 
 |  |                     dataList = jdbcTemplate.queryForList(recordSql);
 | 
												
													
														
															|  | 
 |  |                     devInfoObj.put("bloodSugar", dataList);          //血糖异常数据
 | 
												
													
														
															|  | 
 |  |                     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;
 | 
												
													
														
															|  | 
 |  |                 case "12"://监控 视频地址
 | 
												
													
														
															|  | 
 |  |                     com.alibaba.fastjson.JSONObject tmp = ysDeviceService.getDeviceLiveAddress(patient, deviceSn, 1, null);
 | 
												
													
														
															|  | 
 |  |                     devInfoObj.put("monitorInfoStatus", tmp.getIntValue(ResponseContant.resultFlag));
 | 
												
													
														
															|  | 
 |  |                     if (tmp.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
 | 
												
													
														
															|  | 
 |  |                         devInfoObj.put("monitorInfo", tmp.getString(ResponseContant.resultMsg));
 | 
												
													
														
															|  | 
 |  |                     } else {
 | 
												
													
														
															|  | 
 |  |                         devInfoObj.put("monitorInfo", tmp.getJSONObject(ResponseContant.resultMsg));
 | 
												
													
														
															|  | 
 |  |                     }
 | 
												
													
														
															|  | 
 |  |                     break;
 | 
												
													
														
															|  | 
 |  |                 case "13"://睡眠带 获取当天睡眠详情
 | 
												
													
														
															|  | 
 |  |                     securityMonitoringOrderService.preventOutOfBed(devInfoObj, patient, false, day);
 | 
												
													
														
															|  | 
 |  |                     break;
 | 
												
													
														
															|  | 
 |  |                 case "14"://气感报警器 当天监测记录以及最新浓度
 | 
												
													
														
															|  | 
 |  |                     if (StringUtils.isBlank(day)) {
 | 
												
													
														
															|  | 
 |  |                         day = DateUtil.getStringDateShort();
 | 
												
													
														
															|  | 
 |  |                     }
 | 
												
													
														
															|  | 
 |  |                     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, deviceSn, false);
 | 
												
													
														
															|  | 
 |  |                     devInfoObj.put("day", DateUtil.getStringDateShort());
 | 
												
													
														
															|  | 
 |  |                     break;
 | 
												
													
														
															|  | 
 |  |                 case "16":
 | 
												
													
														
															|  | 
 |  |                     // 电子围栏
 | 
												
													
														
															|  | 
 |  |                     devInfoObj.put("safeAreaGz", securityMonitoringOrderService.getElectronicFence(deviceSn));
 | 
												
													
														
															|  | 
 |  |                     // 行动轨迹
 | 
												
													
														
															|  | 
 |  |                     devInfoObj.put("actionTrack", securityMonitoringOrderService.getActionTrack(deviceSn));
 | 
												
													
														
															|  | 
 |  |                     break;
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  | //        }
 | 
												
													
														
															|  |                 result.put(ResponseContant.resultFlag,ResponseContant.success);
 |  |                 result.put(ResponseContant.resultFlag,ResponseContant.success);
 | 
												
													
														
															|  |                 result.put(ResponseContant.resultMsg,JSON.toJSONString(devInfoObj,SerializerFeature.WriteMapNullValue));
 |  |                 result.put(ResponseContant.resultMsg,JSON.toJSONString(devInfoObj,SerializerFeature.WriteMapNullValue));
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         return result;
 |  |         return result;
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
											
												
													
														
															|  | @ -1007,9 +1022,9 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
												
													
														
															|  |         List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
 |  |         List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
 | 
												
													
														
															|  |         if (devices.size()>0){
 |  |         if (devices.size()>0){
 | 
												
													
														
															|  |             DevicePatientDevice device = devices.get(0);
 |  |             DevicePatientDevice device = devices.get(0);
 | 
												
													
														
															|  |             if (!patient.equals(device.getUser())){
 |  | 
 | 
												
													
														
															|  |                 throw new Exception("居民未绑定该设备");
 |  | 
 | 
												
													
														
															|  |             }else{
 |  | 
 | 
												
													
														
															|  | 
 |  | //            if (!patient.equals(device.getUser())){
 | 
												
													
														
															|  | 
 |  | //                throw new Exception("居民未绑定该设备");
 | 
												
													
														
															|  | 
 |  | //            }else{
 | 
												
													
														
															|  |                 switch (device.getCategoryCode()){
 |  |                 switch (device.getCategoryCode()){
 | 
												
													
														
															|  |                     case "1"://血压设备
 |  |                     case "1"://血压设备
 | 
												
													
														
															|  |                         result = getHealthIndex(result,1,deviceSn,patient,page,pageSize);
 |  |                         result = getHealthIndex(result,1,deviceSn,patient,page,pageSize);
 | 
												
											
												
													
														
															|  | @ -1021,10 +1036,12 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
												
													
														
															|  |                         result  = getEmeWarn(result,deviceSn,null,page,pageSize);
 |  |                         result  = getEmeWarn(result,deviceSn,null,page,pageSize);
 | 
												
													
														
															|  |                         break;
 |  |                         break;
 | 
												
													
														
															|  |                 }
 |  |                 }
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  | 
 |  | //            }
 | 
												
													
														
															|  |         }else {
 |  |         }else {
 | 
												
													
														
															|  |             throw new Exception("设备未被绑定");
 |  |             throw new Exception("设备未被绑定");
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  | 
 |  |         result.put(ResponseContant.resultFlag,ResponseContant.success);
 | 
												
													
														
															|  | 
 |  |         result.put(ResponseContant.resultMsg,JSON.toJSONString(result,SerializerFeature.WriteMapNullValue));
 | 
												
													
														
															|  |         return result;
 |  |         return result;
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 |