|  | @ -10,6 +10,8 @@ import com.yihu.jw.entity.log.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
		
			
				|  |  | import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 | 
	
	
		
			
				|  | @ -29,6 +31,9 @@ import java.util.Map;
 | 
	
		
			
				|  |  | @Component
 | 
	
		
			
				|  |  | public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private static Logger logger = LoggerFactory.getLogger(ZhaohuiDailyService.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private JdbcTemplate jdbcTemplate;
 | 
	
	
		
			
				|  | @ -75,7 +80,6 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |     private void getOldFamily(BasePatientDO old) {
 | 
	
		
			
				|  |  |         String sql = "select family_member from base_patient_family_member where patient ='" + old.getId() + "' and del = 1 ";
 | 
	
		
			
				|  |  |         List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         List result = new ArrayList<>();
 | 
	
		
			
				|  |  |         for (Map<String, Object> map : list) {
 | 
	
		
			
				|  |  |              getFamilyOldInfo(old,map.get("family_member").toString());
 | 
	
		
			
				|  |  |         }
 | 
	
	
		
			
				|  | @ -83,6 +87,8 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PadUseTimeDao padUseTimeDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |     public void getFamilyOldInfo(BasePatientDO old,String familyCode) {
 | 
	
	
		
			
				|  | @ -96,8 +102,8 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String oldId = old.getId();
 | 
	
		
			
				|  |  |         String date = DateUtil.getStringDateShort();
 | 
	
		
			
				|  |  |         String stateDate = "2022-01-01" + " 00:00:00";
 | 
	
		
			
				|  |  |         String endDate = "2022-11-15" + " 23:59:59";
 | 
	
		
			
				|  |  |         String stateDate = "2022-11-17" + " 00:00:00";
 | 
	
		
			
				|  |  |         String endDate = "2022-11-17" + " 23:59:59";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sex = old.getSex()==1?"爷爷":"奶奶";
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -111,13 +117,13 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |         String message = "";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String emeSql = "select count(id) from base_emergency_assistance_order where patient='"+oldId+"' and status in (0,1) 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+"'";
 | 
	
		
			
				|  |  |         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+"'and status in (0,1)";
 | 
	
		
			
				|  |  |         String secSql ="select count(id) total,serve_desc from  base_security_monitoring_order where patient= '"+oldId+"' and create_time>='"+stateDate+"' and create_time<='"+endDate+"' ";
 | 
	
		
			
				|  |  |         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)) {
 | 
	
	
		
			
				|  | @ -126,9 +132,9 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |                 message = "监护到"+old.getName()+sex+"今日存在安全预警:【"+list.get(0).get("serve_desc")+"】";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         zhaohuiDailyEntity.setEmeNum(emeTotal+list.size()>0?Integer.parseInt(list.get(0).get("total").toString()):0);
 | 
	
		
			
				|  |  |         zhaohuiDailyEntity.setEmeNum(emeTotal+(list.size()>0?Integer.parseInt(list.get(0).get("total").toString()):0));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (StringUtils.isBlank("")) {
 | 
	
		
			
				|  |  |         if (StringUtils.isBlank(message)) {
 | 
	
		
			
				|  |  |             message = old.getName()+sex+"今日状态正常,未发生异常情况";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -145,9 +151,26 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |             zhaohuiDailyEntity.setServiceTime(lifeList.get(0).get("create_time").toString());
 | 
	
		
			
				|  |  |             zhaohuiDailyEntity.setServiceName(lifeList.get(0).get("name").toString());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         zhaohuiDailyEntity.setPadTime("10");
 | 
	
		
			
				|  |  |         zhaohuiDailyEntity.setPadLastTime("15");
 | 
	
		
			
				|  |  |         zhaohuiDailyEntity.setPadLastTotalTime("2022-10-15 23:15:12");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String abcd = "select * from pad_use_time where patient = '"+oldId+"' and create_time>= '"+stateDate+"' and create_time<='"+endDate+"' ";
 | 
	
		
			
				|  |  |         List<Map<String, Object>> padUseTimeList = jdbcTemplate.queryForList(abcd);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Integer padNum = padUseTimeList.stream().mapToInt(padUserTime->Integer.parseInt(padUserTime.get("time").toString())).sum();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         /*List<PadUseTimeEntity> padTimeList = padUseTimeDao.findByPatient(oldId,stateDate,endDate);
 | 
	
		
			
				|  |  |         Integer padNum = padTimeList.stream().mapToInt(PadUseTimeEntity::getTime).sum();*/
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         zhaohuiDailyEntity.setPadTime(padNum.toString());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (padUseTimeList.size()>0) {
 | 
	
		
			
				|  |  |             padUseTimeList.get(padUseTimeList.size()-1).get("time");
 | 
	
		
			
				|  |  |             zhaohuiDailyEntity.setPadLastTime(padUseTimeList.get(padUseTimeList.size()-1).get("time").toString());
 | 
	
		
			
				|  |  |             zhaohuiDailyEntity.setPadLastTotalTime(padUseTimeList.get(padUseTimeList.size()-1).get("create_time").toString());
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             zhaohuiDailyEntity.setPadLastTime("0");
 | 
	
		
			
				|  |  |             zhaohuiDailyEntity.setPadLastTotalTime("无");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         zhaohuiDailyEntity = zhaohuiDailyDao.save(zhaohuiDailyEntity);
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -171,8 +194,10 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |                     if (jjbjqList.size()>0) {
 | 
	
		
			
				|  |  |                         zhaohuiDailyEmeEntity.setMessage("发出紧急呼叫");
 | 
	
		
			
				|  |  |                         zhaohuiDailyEmeEntity.setOrderId(jjbjqList.get(0).get("id").toString());
 | 
	
		
			
				|  |  |                         zhaohuiDailyEmeEntity.setMemStatus(1);
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         zhaohuiDailyEmeEntity.setMessage("未发出主动报警");
 | 
	
		
			
				|  |  |                         zhaohuiDailyEmeEntity.setMemStatus(0);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     JSONObject aqgDeviceInfo2 = patientDeviceService.getAqgDeviceInfo2(deviceSn);
 | 
	
	
		
			
				|  | @ -223,7 +248,7 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |                     if (sqlResult.size() > 0) {
 | 
	
		
			
				|  |  |                         Integer num = sqlResult.stream().mapToInt(obj -> Integer.parseInt(obj.get("value1").toString())).sum();
 | 
	
		
			
				|  |  |                         zhaohuiDailyWatchEntity.setHeart((num / sqlResult.size()) + "");
 | 
	
		
			
				|  |  |                         zhaohuiDailyWatchEntity.setHearts(JSONObject.toJSONString(sqlResult.get(0)));
 | 
	
		
			
				|  |  |                         zhaohuiDailyWatchEntity.setHearts(JSONObject.toJSONString(sqlResult));
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     //手表步数数据
 | 
	
	
		
			
				|  | @ -256,18 +281,22 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |                 case 12: //防跌倒视频监测
 | 
	
		
			
				|  |  |                     ZhaohuiDailyVideoEntity zhaohuiDailyVideoEntity = new ZhaohuiDailyVideoEntity();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     sql = " select o.serve_desc  " +
 | 
	
		
			
				|  |  |                     sql = " select o.serve_desc,o.id  " +
 | 
	
		
			
				|  |  |                             "  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 o.create_time desc  limit 1   ";
 | 
	
		
			
				|  |  |                             " 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+"' and topic_item = 'preventFall' ORDER BY o.create_time desc  limit 1   ";
 | 
	
		
			
				|  |  |                     sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                     if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                         zhaohuiDailyVideoEntity.setServeDesc(sqlResult.get(0).get("serve_desc").toString());
 | 
	
		
			
				|  |  |                         zhaohuiDailyVideoEntity.setOrderId(sqlResult.get(0).get("id").toString());
 | 
	
		
			
				|  |  |                         zhaohuiDailyVideoEntity.setEmeStatus(1);
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         zhaohuiDailyVideoEntity.setEmeStatus(0);
 | 
	
		
			
				|  |  |                         zhaohuiDailyVideoEntity.setServeDesc("无");
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     zhaohuiDailyVideoEntity.setDeviceSn(deviceSn);
 | 
	
		
			
				|  |  |                     zhaohuiDailyVideoEntity.setDailyId(zhaohuiDailyEntity.getId().toString());
 | 
	
		
			
				|  |  |                     zhaohuiDailyVideoEntity.setTime(stateDate + "," + endDate);
 | 
	
		
			
				|  |  |                     zhaohuiDailyVideoEntity.setServeDesc("无");
 | 
	
		
			
				|  |  |                     zhaohuiDailyVideoList.add(zhaohuiDailyVideoEntity);
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |                 case 13: //睡眠带
 | 
	
	
		
			
				|  | @ -325,6 +354,7 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         wxPush(old.getName(),familyCode, zhaohuiDailyEntity.getService(), emeTotal);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -345,6 +375,22 @@ public class ZhaohuiDailyService {
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private void wxPush(String name, String familyCode,Integer lift,Integer eme) {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql = "select openid from base_patient where id = '" + familyCode + "' and openid is not null ";
 | 
	
		
			
				|  |  |         List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         if (list.size() > 0) {
 | 
	
		
			
				|  |  |             if (name.equals("姜云")) {
 | 
	
		
			
				|  |  |                 String first = "您好,您的亲属【" + name + "】今日照护日报已生成";
 | 
	
		
			
				|  |  |                 String content = "紧急预警:" + eme + "\r\n生活照料:" + lift + "";
 | 
	
		
			
				|  |  |                 String url = "https://zhyzh.gongshu.gov.cn/medical-care-patient/healthRecords/index?active=1";
 | 
	
		
			
				|  |  |                 //o_DJs59V7MKJ5ea-YW__LoccEn50
 | 
	
		
			
				|  |  |                 messageUtil.putTemplateWxMessage(wxId, "template_system_family", "jsxtxx", list.get(0).get("openid").toString(), first, url, null, 1, null, content, "【推送完成】", com.yihu.jw.util.date.DateUtil.getStringDate());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public static void main(String[] args) {
 | 
	
		
			
				|  |  |         String abc = "[\"12:30-14:09\",\"22:00-04:06\",\"05:09-05:24\"]";
 | 
	
		
			
				|  |  |         String[] split = abc.split(",");
 |