|  | @ -44,6 +44,7 @@ import org.springframework.http.HttpEntity;
 | 
	
		
			
				|  |  | import org.springframework.http.HttpHeaders;
 | 
	
		
			
				|  |  | import org.springframework.http.HttpMethod;
 | 
	
		
			
				|  |  | import org.springframework.http.MediaType;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Component;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
	
		
			
				|  | @ -949,11 +950,52 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
	
		
			
				|  |  |             devInfo.put("patient", patient);
 | 
	
		
			
				|  |  |             devInfo.put("sosContactsDOS", new ArrayList<>());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //v1.4获取设备在线状态、数据采集量、异常指标量、 、
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //v1.4获取其绑定设备的居民列表 //todo 各平台全部对接后外层无用字段删除(患者相关,如patientName,orgCode等)
 | 
	
		
			
				|  |  |             //v1.4获取设备在线状态、数据采集量、异常指标量、
 | 
	
		
			
				|  |  |             sql =" select contact_status  from wlyy_devices where device_code='"+deviceSn+"' ";
 | 
	
		
			
				|  |  |             List<String> onLineStatus = jdbcTemplate.queryForList(sql,String.class);
 | 
	
		
			
				|  |  |             if (onLineStatus.size()>0){
 | 
	
		
			
				|  |  |                 devInfo.put("contactStatus",onLineStatus.get(0));
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 devInfo.put("contactStatus",0);//在线状态
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //数据采集量
 | 
	
		
			
				|  |  |             if(1==device.getDeviceType()){//安防设备
 | 
	
		
			
				|  |  |                 sql = " select count(id) from device_data_push_log where device_sn='"+deviceSn+"' ";
 | 
	
		
			
				|  |  |                 Long dataCount = jdbcTemplate.queryForObject(sql,Long.class);
 | 
	
		
			
				|  |  |                 devInfo.put("dataCount",dataCount);//
 | 
	
		
			
				|  |  |                 sql = " select sum(total) from (\n" +
 | 
	
		
			
				|  |  |                         "select count(id) total from base_emergency_assistance_order where device_sn='"+deviceSn+"'\n" +
 | 
	
		
			
				|  |  |                         "UNION ALL\n" +
 | 
	
		
			
				|  |  |                         "select count(id) total from base_security_monitoring_order where device_sn='"+deviceSn+"'" +
 | 
	
		
			
				|  |  |                         ")A ";
 | 
	
		
			
				|  |  |                 Long orderCount = jdbcTemplate.queryForObject(sql,Long.class);
 | 
	
		
			
				|  |  |                 devInfo.put("errorCount",orderCount);//         //异常量
 | 
	
		
			
				|  |  |             }else if (2==device.getDeviceType()){//健康设备
 | 
	
		
			
				|  |  |                 sql = " select count(id) from wlyy_patient_health_index where device_sn ='"+deviceSn+"' ";
 | 
	
		
			
				|  |  |                 Long dataCount = jdbcTemplate.queryForObject(sql,Long.class);
 | 
	
		
			
				|  |  |                 devInfo.put("dataCount",dataCount);//异常量
 | 
	
		
			
				|  |  |                 sql += " and status =1 ";
 | 
	
		
			
				|  |  |                 dataCount = jdbcTemplate.queryForObject(sql,Long.class);
 | 
	
		
			
				|  |  |                 devInfo.put("errorCount",dataCount);//异常量
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //v1.4获取其绑定设备的居民列表 //todo 各平台全部对接后外层无用字段删除(患者相关,如patientName,orgCode等)
 | 
	
		
			
				|  |  |             sql =" select  p.id patient,p.photo,p.name,case p.sex when 1 then '男' when 2 then '女' else sex end as sex,TIMESTAMPDIFF(year,p.birthday,now()) as age, \n" +
 | 
	
		
			
				|  |  |                     "p.residential_area residentialArea,p.mobile,p.idcard,p.address from base_patient p INNER JOIN wlyy_patient_device pd on p.id = pd.user and pd.del=0  " +
 | 
	
		
			
				|  |  |                     "where 1=1 and pd.device_sn='"+deviceSn+"' ";
 | 
	
		
			
				|  |  |             List<Map<String,Object>> patientList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |             for (Map<String,Object>map :patientList){
 | 
	
		
			
				|  |  |                 String patientStr = map.get("patient").toString();
 | 
	
		
			
				|  |  |                 sql ="SELECT GROUP_CONCAT(Distinct sp.org_name) orgName FROM base_service_package_record spr INNER JOIN base_service_package sp on " +
 | 
	
		
			
				|  |  |                         " spr.service_package_id = sp.id AND spr.patient = '"+patientStr+"' where sp.org_code " +
 | 
	
		
			
				|  |  |                         " IS NOT NULL GROUP BY spr.patient ";
 | 
	
		
			
				|  |  |                 List<String> orgs = jdbcTemplate.queryForList(sql,String.class);
 | 
	
		
			
				|  |  |                 if (orgs.size()>0){
 | 
	
		
			
				|  |  |                     map.put("orgName", orgs.get(0));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             devInfo.put("patientList",patientList);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String dataSql = "";
 | 
	
		
			
				|  |  |             String recordSql = "";
 | 
	
	
		
			
				|  | @ -1098,6 +1140,93 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取睡眠带 睡眠报告
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @param deviceSn
 | 
	
		
			
				|  |  |      * @param day
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject getSleepReport(String patient,String deviceSn,String day){
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         String sql = " select * from base_sleep_device where 1=1 ";
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(patient)){
 | 
	
		
			
				|  |  |             sql +=" and patient='"+patient+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(deviceSn)){
 | 
	
		
			
				|  |  |             sql += " and device_sn='"+deviceSn+"' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(day)){
 | 
	
		
			
				|  |  |             sql +=" and create_time>="+day+" 00:00:00 and create_time<'"+day+"' 23:59:59 ";
 | 
	
		
			
				|  |  |         }else   {
 | 
	
		
			
				|  |  |             sql +=" order by create_time desc ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql +=" limit 1 ";
 | 
	
		
			
				|  |  |         List<BaseSleepDeviceReport> list = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BaseSleepDeviceReport.class));
 | 
	
		
			
				|  |  |         if (list.size()>0){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag,ResponseContant.success);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg,list.get(0));
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag,ResponseContant.fail);
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg,"无睡眠记录");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> getSmokeOrGasList(String deviceSn,String day){
 | 
	
		
			
				|  |  |         List<Map<String,Object>> result = new ArrayList<>();
 | 
	
		
			
				|  |  |         Date now = new Date();
 | 
	
		
			
				|  |  |         String nowDay =  DateUtil.getStringDateShort();
 | 
	
		
			
				|  |  |         if (StringUtils.isBlank(day)){
 | 
	
		
			
				|  |  |             day = nowDay;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String timeBeginStr = day+" 00:00:00";
 | 
	
		
			
				|  |  |         String timeEndStr = "";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (nowDay.equals(day)){//同一天
 | 
	
		
			
				|  |  |             timeEndStr = DateUtil.dateToStr(now,DateUtil.yyyy_MM_dd_HH_mm_ss);
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             timeEndStr = day+ " 23:59:59";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         Date timeBegin = DateUtil.strToDate(timeBeginStr,DateUtil.yyyy_MM_dd_HH_mm_ss);
 | 
	
		
			
				|  |  |         Date timeEnd = DateUtil.strToDate(timeEndStr,DateUtil.yyyy_MM_dd_HH_mm_ss);
 | 
	
		
			
				|  |  |         String sql = " SELECT r.value,CAST(DATE_FORMAT(r.create_time,'%Y-%m-%d %H:%i:%S') as char) create_time " +
 | 
	
		
			
				|  |  |                 " from wlyy_patient_device pd,base_device_health_index r WHERE pd.device_sn = r.device_sn " +
 | 
	
		
			
				|  |  |                 " and r.device_sn='"+deviceSn+"' order by r.create_time asc";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //遍历时间区间,无数据时间点产生数据
 | 
	
		
			
				|  |  |         int i=0; //list遍历索引
 | 
	
		
			
				|  |  |         int length = list.size();
 | 
	
		
			
				|  |  |         Date prTimeBegin = timeBegin;
 | 
	
		
			
				|  |  |         Date listIndexTime = null;
 | 
	
		
			
				|  |  |         if (length>0){
 | 
	
		
			
				|  |  |             listIndexTime = DateUtil.strToDate(list.get(0).get("create_time").toString(),DateUtil.yyyy_MM_dd_HH_mm_ss);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         for (;timeEnd.after(timeBegin);){
 | 
	
		
			
				|  |  |             timeBegin =  DateUtil.getNextMin(timeBegin,15);
 | 
	
		
			
				|  |  |             Map<String,Object> map = new HashMap<>();
 | 
	
		
			
				|  |  |             if (length>0&&i<length){
 | 
	
		
			
				|  |  |                 if ((prTimeBegin.before(listIndexTime)||prTimeBegin.equals(listIndexTime))&&(timeBegin.after(listIndexTime)||timeBegin.equals(listIndexTime))){
 | 
	
		
			
				|  |  |                     map.put("value",Double.parseDouble( list.get(i).get("value").toString()));
 | 
	
		
			
				|  |  |                     map.put("createTime",list.get(i).get("create_time").toString());
 | 
	
		
			
				|  |  |                     i++;
 | 
	
		
			
				|  |  |                     if (i<length){
 | 
	
		
			
				|  |  |                         listIndexTime = DateUtil.strToDate(list.get(i).get("create_time").toString(),DateUtil.yyyy_MM_dd_HH_mm_ss);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     map.put("value",0.00);
 | 
	
		
			
				|  |  |                     map.put("createTime",DateUtil.dateToStr(timeBegin,DateUtil.yyyy_MM_dd_HH_mm_ss));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 map.put("value",0.00);
 | 
	
		
			
				|  |  |                 map.put("createTime",DateUtil.dateToStr(timeBegin,DateUtil.yyyy_MM_dd_HH_mm_ss));
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             result.add(map);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 根据设备sn及居民code获取居民有效的设备绑定数据
 | 
	
		
			
				|  |  |      * @param deviceSn 设备sn码
 | 
	
	
		
			
				|  | @ -1260,6 +1389,10 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
	
		
			
				|  |  |             long count = jdbcTemplate.queryForObject(sqlCount,long.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |             for (Map<String,Object> map:list){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String str = JSON.toJSONString(list,SerializerFeature.WriteMapNullValue);
 | 
	
		
			
				|  |  |             com.alibaba.fastjson.JSONArray arr = com.alibaba.fastjson.JSONArray.parseArray(str);
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -1316,7 +1449,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
	
		
			
				|  |  |             Date dateNow = new Date();
 | 
	
		
			
				|  |  |             Date dateNow1 = DateUtil.strToDate(DateUtil.getStringDateShort()+" 08:00:00");
 | 
	
		
			
				|  |  |             Date dateNow2 = DateUtil.strToDate(DateUtil.getStringDateShort()+" 20:00:00");
 | 
	
		
			
				|  |  |             List<String> noWarnDays = new ArrayList<>();
 | 
	
		
			
				|  |  |             List<String> noWarnDays = new ArrayList<>();//无预警记录
 | 
	
		
			
				|  |  |             String dateTmp = "";
 | 
	
		
			
				|  |  |             if (dateNow.after(dateNow1)){
 | 
	
		
			
				|  |  |                 dateTmp = DateUtil.dateToStr(dateNow1,DateUtil.yyyy_MM_dd_HH_mm_ss);
 |