|  | @ -1,11 +1,14 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.care.service.message;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.serializer.SerializerFeature;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.pushLog.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.device.PatientDeviceService;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.util.MessageUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.device.DevicePatientDevice;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.log.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
	
		
			
				|  | @ -55,6 +58,8 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |     private ZhaohuiDailySleepDao zhaohuiDailySleepDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ZhaohuiDailyEmeDao zhaohuiDailyEmeDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ZhaohuifireGasSecDao zhaohuifireGasSecDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void allRound() {
 | 
	
	
		
			
				|  | @ -86,6 +91,12 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String messageDict(String dictCode){
 | 
	
		
			
				|  |  |         String sql = "select * from base_yujing_dict where dict_name = 'zhaohui' ";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PadUseTimeDao padUseTimeDao;
 | 
	
	
		
			
				|  | @ -97,6 +108,7 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |         List<ZhaohuiDailySleepEntity> zhaohuiDailySleepList = new ArrayList<>();
 | 
	
		
			
				|  |  |         List<ZhaohuiDailyVideoEntity> zhaohuiDailyVideoList = new ArrayList<>();
 | 
	
		
			
				|  |  |         List<ZhaohuiDailyEmeEntity> zhaohuiDailyEmeList = new ArrayList<>();
 | 
	
		
			
				|  |  |         List<ZhaohuifireGasSecEntity> zhaohuifireGasSecEntityList = new ArrayList<>();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -114,16 +126,22 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |         zhaohuiDailyEntity.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         zhaohuiDailyEntity.setFamilyCode(familyCode);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String orgCodeSql = "SELECT d.org_code as orgCode FROM base_patient p INNER JOIN base_service_package_sign_record r ON p.id = r.patient INNER JOIN base_doctor_hospital d ON r.sign_doctor = d.doctor_code WHERE d.del =1 and = p.id = '"+oldId+"' ";
 | 
	
		
			
				|  |  |         List<Map<String, Object>> orgCodeList = jdbcTemplate.queryForList(orgCodeSql);
 | 
	
		
			
				|  |  |         if (orgCodeList.size()>0) {
 | 
	
		
			
				|  |  |             zhaohuiDailyEntity.setOrgCode(orgCodeList.get(0).get("orgCode").toString());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String message = "";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String emeSql = "select count(id) from base_emergency_assistance_order where patient='"+oldId+"'  and create_time>='"+stateDate+"' and create_time<='"+endDate+"'";
 | 
	
		
			
				|  |  |         String emeSql = "select count(id) from base_emergency_assistance_order where patient='"+oldId+"'  and create_time>='"+stateDate+"' and create_time<='"+endDate+"' and status <> -1";
 | 
	
		
			
				|  |  |         Integer emeTotal = jdbcTemplate.queryForObject(emeSql, Integer.class);
 | 
	
		
			
				|  |  |         if (emeTotal>0){
 | 
	
		
			
				|  |  |             message += old.getName()+sex+"今日发起"+emeTotal+"次紧急呼叫";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String secSql ="select count(id) total,serve_desc from  base_security_monitoring_order where patient= '"+oldId+"' and create_time>='"+stateDate+"' and create_time<='"+endDate+"' ";
 | 
	
		
			
				|  |  |         String secSql ="select count(id) total,serve_desc from  base_security_monitoring_order where patient= '"+oldId+"' and create_time>='"+stateDate+"' and create_time<='"+endDate+"' and status <> -1 ";
 | 
	
		
			
				|  |  |         List<Map<String, Object>> list = jdbcTemplate.queryForList(secSql);
 | 
	
		
			
				|  |  |         if (list.size()>0&&0>Integer.parseInt(list.get(0).get("total").toString())) {
 | 
	
		
			
				|  |  |             if (StringUtils.isNotBlank(message)) {
 | 
	
	
		
			
				|  | @ -135,14 +153,14 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |         zhaohuiDailyEntity.setEmeNum(emeTotal+(list.size()>0?Integer.parseInt(list.get(0).get("total").toString()):0));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (StringUtils.isBlank(message)) {
 | 
	
		
			
				|  |  |             message = old.getName()+sex+"今日状态正常,未发生异常情况";
 | 
	
		
			
				|  |  |             message = old.getName()+sex+"今日状态正常,未发生异常情况,今日家中设备工作正常";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         zhaohuiDailyEntity.setMessage(message);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String lifeSql = "select count(id) from base_life_care_order where patient = '" + oldId + "' and status = 1 and create_time>= '" + stateDate + "' and create_time<= '" + endDate + "'";
 | 
	
		
			
				|  |  |         String lifeSql = "select count(id) from base_life_care_order where patient = '" + oldId + "' and status = 1 and create_time>= '" + stateDate + "' and create_time<= '" + endDate + "' and status <> -1";
 | 
	
		
			
				|  |  |         String lifeInfoSql = "select d.name,d.create_time create_time from base_life_care_order o INNER JOIN base_life_care_fee_detail d ON o.id=d.order_id where o.patient = '" + oldId + "' and o.status = 1 and o.create_time>= '" + stateDate + "' and o.create_time<= '" + endDate + "' order by o.create_time DESC limit 1";
 | 
	
		
			
				|  |  |         List<Map<String, Object>> lifeList = jdbcTemplate.queryForList(lifeInfoSql);
 | 
	
		
			
				|  |  |         Integer lifeTotal = jdbcTemplate.queryForObject(lifeSql, Integer.class);
 | 
	
	
		
			
				|  | @ -178,7 +196,7 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql = "SELECT pd.device_sn,pd.category_code FROM base.wlyy_patient_device pd  where pd.del=0 AND  category_code in ('7','12','4','13') AND user = '" + oldId + "'  ";
 | 
	
		
			
				|  |  |         List<Map<String, Object>> oldDeviceList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String zhaohuiID = zhaohuiDailyEntity.getId().toString();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         for (Map<String, Object> device : oldDeviceList) {
 | 
	
		
			
				|  |  |             String deviceSn = device.get("device_sn").toString();
 | 
	
	
		
			
				|  | @ -187,7 +205,7 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |                 case 7: //居家报警器
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     ZhaohuiDailyEmeEntity zhaohuiDailyEmeEntity = new ZhaohuiDailyEmeEntity();
 | 
	
		
			
				|  |  |                     zhaohuiDailyEmeEntity.setDailyId(zhaohuiDailyEntity.getId().toString());
 | 
	
		
			
				|  |  |                     zhaohuiDailyEmeEntity.setDailyId(zhaohuiID);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     sql = "  select o.id,o.create_time from base_emergency_assistance_order o " +
 | 
	
		
			
				|  |  |                             " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' and o.status=1  and o.create_time >= '"+stateDate+"' and o.create_time <= '"+endDate+"'  ORDER BY create_time desc  limit 1 ";
 | 
	
	
		
			
				|  | @ -218,7 +236,7 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |                 case 4: //智能手表
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     ZhaohuiDailyWatchEntity zhaohuiDailyWatchEntity = new ZhaohuiDailyWatchEntity();
 | 
	
		
			
				|  |  |                     zhaohuiDailyWatchEntity.setDailyId(zhaohuiDailyEntity.getId().toString());
 | 
	
		
			
				|  |  |                     zhaohuiDailyWatchEntity.setDailyId(zhaohuiID);
 | 
	
		
			
				|  |  |                     JSONObject response = patientDeviceService.getAqgDeviceInfo2(deviceSn);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     if (null != response) {
 | 
	
	
		
			
				|  | @ -277,6 +295,11 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |                         zhaohuiDailyWatchEntity.setServeDesc("无");
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     JSONArray x1Locations = getX1Locations(oldId, stateDate);
 | 
	
		
			
				|  |  |                     if (null!=x1Locations&&x1Locations.size()>0) {
 | 
	
		
			
				|  |  |                         zhaohuiDailyWatchEntity.setLocations(x1Locations.toJSONString());
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     zhaohuiDailyWatchList.add(zhaohuiDailyWatchEntity);
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case 12: //防跌倒视频监测
 | 
	
	
		
			
				|  | @ -296,13 +319,13 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     zhaohuiDailyVideoEntity.setDeviceSn(deviceSn);
 | 
	
		
			
				|  |  |                     zhaohuiDailyVideoEntity.setDailyId(zhaohuiDailyEntity.getId().toString());
 | 
	
		
			
				|  |  |                     zhaohuiDailyVideoEntity.setDailyId(zhaohuiID);
 | 
	
		
			
				|  |  |                     zhaohuiDailyVideoEntity.setTime(stateDate + "," + endDate);
 | 
	
		
			
				|  |  |                     zhaohuiDailyVideoList.add(zhaohuiDailyVideoEntity);
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case 13: //睡眠带
 | 
	
		
			
				|  |  |                     ZhaohuiDailySleepEntity zhaohuiDailySleep = new ZhaohuiDailySleepEntity();
 | 
	
		
			
				|  |  |                     zhaohuiDailySleep.setDailyId(zhaohuiDailyEntity.getId().toString());
 | 
	
		
			
				|  |  |                     zhaohuiDailySleep.setDailyId(zhaohuiID);
 | 
	
		
			
				|  |  |                     JSONObject sleepDeviceInfo = patientDeviceService.getSleepDeviceInfo(deviceSn);
 | 
	
		
			
				|  |  |                     if (sleepDeviceInfo.getBooleanValue("success")) {
 | 
	
		
			
				|  |  |                         JSONArray objs = sleepDeviceInfo.getJSONArray("objs");
 | 
	
	
		
			
				|  | @ -351,6 +374,48 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     zhaohuiDailySleepList.add(zhaohuiDailySleep);
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case 14: //烟感
 | 
	
		
			
				|  |  |                     ZhaohuifireGasSecEntity yg = new ZhaohuifireGasSecEntity();
 | 
	
		
			
				|  |  |                     sql = " select count(o.id) as total from base_security_monitoring_order o " +
 | 
	
		
			
				|  |  |                             " INNER JOIN base_patient p on p.id = o.patient where device_sn='" + deviceSn + "' and o.status=1 and o.create_time >= '" + stateDate + "' and o.create_time <= '" + endDate + "' ORDER BY create_time desc    ";
 | 
	
		
			
				|  |  |                     Integer ygTotal = jdbcTemplate.queryForObject(sql, Integer.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     sql = " select value, DATE_FORMAT( record_time, '%H:%i:%S' ) as record_time  from base_device_health_index where device_sn='" + deviceSn + "' and record_time >= '" + stateDate + "' and record_time <= '" + endDate + "' ORDER BY record_time desc";
 | 
	
		
			
				|  |  |                     List<Map<String, Object>> ygList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                     JSONArray ygJsonArray = JSONArray.parseArray(ygList.toString());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     yg.setDailyId(zhaohuiID);
 | 
	
		
			
				|  |  |                     yg.setOnline(1);
 | 
	
		
			
				|  |  |                     yg.setType(1);
 | 
	
		
			
				|  |  |                     if (ygTotal>0) {
 | 
	
		
			
				|  |  |                         yg.setSecStatus(1);
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         yg.setSecStatus(0);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     yg.setFireCurve(ygJsonArray.toJSONString());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     zhaohuifireGasSecEntityList.add(yg);
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case 15: //气感
 | 
	
		
			
				|  |  |                     sql = " select count(o.id) as total from base_security_monitoring_order o " +
 | 
	
		
			
				|  |  |                             " INNER JOIN base_patient p on p.id = o.patient where device_sn='"+deviceSn+"' and o.status=1 and o.create_time >= '"+stateDate+"' and o.create_time <= '"+endDate+"' ORDER BY create_time desc  limit 1 ";
 | 
	
		
			
				|  |  |                     Integer qgTotal = jdbcTemplate.queryForObject(sql, Integer.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     ZhaohuifireGasSecEntity qg = new ZhaohuifireGasSecEntity();
 | 
	
		
			
				|  |  |                     qg.setDailyId(zhaohuiID);
 | 
	
		
			
				|  |  |                     qg.setOnline(1);
 | 
	
		
			
				|  |  |                     qg.setType(2);
 | 
	
		
			
				|  |  |                     if (qgTotal>0) {
 | 
	
		
			
				|  |  |                         qg.setSecStatus(1);
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         qg.setSecStatus(0);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     sql = " select value,DATE_FORMAT( record_time, '%H:%i:%S' ) as record_time  from base_device_health_index where device_sn='"+deviceSn+"' and record_time >='"+stateDate+"' and record_time <= '"+endDate+"'  ORDER BY record_time desc limit 1 ";
 | 
	
		
			
				|  |  |                     List<Map<String, Object>> qgList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                     JSONArray qgJsonArray = JSONArray.parseArray(qgList.toString());
 | 
	
		
			
				|  |  |                     qg.setFireCurve(qgJsonArray.toJSONString());
 | 
	
		
			
				|  |  |                     zhaohuifireGasSecEntityList.add(qg);
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -373,6 +438,7 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |         zhaohuiDailyWatchDao.save(zhaohuiDailyWatchList);
 | 
	
		
			
				|  |  |         zhaohuiDailyVideoDao.save(zhaohuiDailyVideoList);
 | 
	
		
			
				|  |  |         zhaohuiDailyEmeDao.save(zhaohuiDailyEmeList);
 | 
	
		
			
				|  |  |         zhaohuifireGasSecDao.save(zhaohuifireGasSecEntityList);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -390,6 +456,18 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //行动轨迹
 | 
	
		
			
				|  |  |     public JSONArray getX1Locations(String patient, String date){
 | 
	
		
			
				|  |  |         String sql = "select * from wlyy_patient_device where user = '"+patient+"' and category_code = '4' and del = 0";
 | 
	
		
			
				|  |  |         List<DevicePatientDevice> byUserAndCategoryCode = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DevicePatientDevice.class));
 | 
	
		
			
				|  |  |         if (byUserAndCategoryCode.size()==0){
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         JSONArray x1Locations = JSON.parseArray(JSON.toJSONString(patientDeviceService.getX1Locations(byUserAndCategoryCode.get(0).getDeviceSn(), date), SerializerFeature.WriteMapNullValue));
 | 
	
		
			
				|  |  |         return x1Locations;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public static void main(String[] args) {
 | 
	
		
			
				|  |  |         String abc = "[\"12:30-14:09\",\"22:00-04:06\",\"05:09-05:24\"]";
 | 
	
		
			
				|  |  |         String[] split = abc.split(",");
 | 
	
	
		
			
				|  | @ -401,4 +479,6 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |