|  | @ -1,6 +1,5 @@
 | 
	
		
			
				|  |  | package com.yihu.wlyy.service.app.sign;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.consult.Consult;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.doctor.profile.Doctor;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.organization.Hospital;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.Patient;
 | 
	
	
		
			
				|  | @ -12,7 +11,10 @@ import com.yihu.wlyy.service.BaseService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.app.consult.ConsultService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.common.SMSService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.task.PushMsgTask;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.task.RemindExpensesTask;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.task.RemindFocusWechatTask;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.DateUtil;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.json.JSONObject;
 | 
	
	
		
			
				|  | @ -53,13 +55,13 @@ public class PatientRemindService extends BaseService {
 | 
	
		
			
				|  |  |     JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     ConsultService consultService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 缴费提醒
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param doctor 医生
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Async
 | 
	
		
			
				|  |  |     public void remindPatientExpensesAll(String doctor) throws Exception {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             Doctor doc = doctorDao.findByCode(doctor);
 | 
	
	
		
			
				|  | @ -89,38 +91,53 @@ public class PatientRemindService extends BaseService {
 | 
	
		
			
				|  |  |      * @param hos
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void RemindAll(Doctor doc, Hospital hos) throws Exception {
 | 
	
		
			
				|  |  |             boolean flag = true;
 | 
	
		
			
				|  |  |             int page = 0;
 | 
	
		
			
				|  |  |             int start = 0;
 | 
	
		
			
				|  |  |             String sql = "select p.* " +
 | 
	
		
			
				|  |  |                     "     from " +
 | 
	
		
			
				|  |  |                     "        wlyy_sign_family f join wlyy_patient p on f.patient = p.code " +
 | 
	
		
			
				|  |  |                     "     where " +
 | 
	
		
			
				|  |  |                     "        (f.doctor = ? or f.doctor_health = ?) " +
 | 
	
		
			
				|  |  |                     "        and f.status > 0 " +
 | 
	
		
			
				|  |  |                     "        and f.type = 2 " +
 | 
	
		
			
				|  |  |                     "        and (f.expenses_status = '0' or LENGTH(trim(ifnull(f.expenses_status,''))) < 1) " +
 | 
	
		
			
				|  |  |                     "     limit ?,3000";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             while (flag) {
 | 
	
		
			
				|  |  |                 List<Patient> result = jdbcTemplate.query(sql, new Object[]{doc.getCode(), doc.getCode(), start}, new BeanPropertyRowMapper(Patient.class));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (result != null && result.size() > 0) {
 | 
	
		
			
				|  |  |                     for (Patient p : result) {
 | 
	
		
			
				|  |  |                         if (p != null) {
 | 
	
		
			
				|  |  |                             Boolean epTime = redisTemplate.opsForSet().isMember("expenses:remind:set", p.getCode());
 | 
	
		
			
				|  |  |                             if (epTime) {
 | 
	
		
			
				|  |  |                                 continue;
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                             remindPatientExpenses(p, doc, hos, true);
 | 
	
		
			
				|  |  |         Calendar today = Calendar.getInstance();
 | 
	
		
			
				|  |  |         today.set(Calendar.HOUR, 23);
 | 
	
		
			
				|  |  |         today.set(Calendar.MINUTE, 59);
 | 
	
		
			
				|  |  |         today.set(Calendar.SECOND, 59);
 | 
	
		
			
				|  |  |         today.set(Calendar.MILLISECOND, 59);
 | 
	
		
			
				|  |  |         boolean flag = true;
 | 
	
		
			
				|  |  |         int page = 0;
 | 
	
		
			
				|  |  |         int start = 0;
 | 
	
		
			
				|  |  |         String sql = "select p.* " +
 | 
	
		
			
				|  |  |                 "     from " +
 | 
	
		
			
				|  |  |                 "        wlyy_sign_family f join wlyy_patient p on f.patient = p.code " +
 | 
	
		
			
				|  |  |                 "     where " +
 | 
	
		
			
				|  |  |                 "        (f.doctor = ? or f.doctor_health = ?) " +
 | 
	
		
			
				|  |  |                 "        and f.status > 0 " +
 | 
	
		
			
				|  |  |                 "        and f.type = 2 " +
 | 
	
		
			
				|  |  |                 "        and (f.expenses_status = '0' or LENGTH(trim(ifnull(f.expenses_status,''))) < 1) " +
 | 
	
		
			
				|  |  |                 "     limit ?,3000";
 | 
	
		
			
				|  |  |         List<Patient> patients = new ArrayList<>();
 | 
	
		
			
				|  |  |         List<String> redisPatients = new ArrayList<>();
 | 
	
		
			
				|  |  |         Set<String> exists = redisTemplate.opsForSet().members("expenses:remind:set");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         while (flag) {
 | 
	
		
			
				|  |  |             List<Patient> result = jdbcTemplate.query(sql, new Object[]{doc.getCode(), doc.getCode(), start}, new BeanPropertyRowMapper(Patient.class));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (result != null && result.size() > 0) {
 | 
	
		
			
				|  |  |                 patients.addAll(result);
 | 
	
		
			
				|  |  |                 for (Patient p : result) {
 | 
	
		
			
				|  |  |                     if (p != null) {
 | 
	
		
			
				|  |  |                         if (exists != null && exists.contains(p.getCode())) {
 | 
	
		
			
				|  |  |                             continue;
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         redisPatients.add(p.getCode());
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     page = page + 1;
 | 
	
		
			
				|  |  |                     start = page * 3000;
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     flag = false;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 page = page + 1;
 | 
	
		
			
				|  |  |                 start = page * 3000;
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 flag = false;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (patients.size() > 0) {
 | 
	
		
			
				|  |  |             RemindExpensesTask task = new RemindExpensesTask(patients, doc, hos);
 | 
	
		
			
				|  |  |             new Thread(task).run();
 | 
	
		
			
				|  |  |             redisTemplate.opsForSet().add("expenses:remind:set", redisPatients.toArray(new String[]{}));
 | 
	
		
			
				|  |  |             redisTemplate.expireAt("expenses:remind:set", today.getTime());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
	
		
			
				|  | @ -148,7 +165,7 @@ public class PatientRemindService extends BaseService {
 | 
	
		
			
				|  |  |                 throw new Exception("patient info can not find");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             return remindPatientExpenses(p, doc, hos, false);
 | 
	
		
			
				|  |  |             return remindPatientExpenses(p, doc, hos);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             JSONObject reObj = new JSONObject();
 | 
	
	
		
			
				|  | @ -166,14 +183,13 @@ public class PatientRemindService extends BaseService {
 | 
	
		
			
				|  |  |      * @param hos 医院
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject remindPatientExpenses(Patient p, Doctor doc, Hospital hos, boolean ignore) throws Exception {
 | 
	
		
			
				|  |  |     public JSONObject remindPatientExpenses(Patient p, Doctor doc, Hospital hos) throws Exception {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             Calendar today = Calendar.getInstance();
 | 
	
		
			
				|  |  |             today.set(Calendar.HOUR,23);
 | 
	
		
			
				|  |  |             today.set(Calendar.MINUTE,59);
 | 
	
		
			
				|  |  |             today.set(Calendar.SECOND,59);
 | 
	
		
			
				|  |  |             today.set(Calendar.MILLISECOND,59);
 | 
	
		
			
				|  |  |             SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
 | 
	
		
			
				|  |  |             today.set(Calendar.HOUR, 23);
 | 
	
		
			
				|  |  |             today.set(Calendar.MINUTE, 59);
 | 
	
		
			
				|  |  |             today.set(Calendar.SECOND, 59);
 | 
	
		
			
				|  |  |             today.set(Calendar.MILLISECOND, 59);
 | 
	
		
			
				|  |  |             JSONObject reObj = new JSONObject();
 | 
	
		
			
				|  |  |             String mDesc = "";
 | 
	
		
			
				|  |  |             boolean mFlag = false;
 | 
	
	
		
			
				|  | @ -209,16 +225,12 @@ public class PatientRemindService extends BaseService {
 | 
	
		
			
				|  |  |                 wFlag = true;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             //发送IM
 | 
	
		
			
				|  |  |             consultService.sendMucMessageBySingnType(doc.getCode(),doc.getName(),p.getCode(),doc.getName() + "医生提醒您:为完成家庭医生签约," +
 | 
	
		
			
				|  |  |                   "尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费", "1","医生:"+doc.getName()+"给患者:"+p.getName()+"发送了缴费提醒!");
 | 
	
		
			
				|  |  |             if (ignore) {
 | 
	
		
			
				|  |  |                 redisTemplate.opsForSet().add("expenses:remind:set",p.getCode());
 | 
	
		
			
				|  |  |                 redisTemplate.expireAt("expenses:remind:set", today.getTime());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             consultService.sendMucMessageBySingnType(doc.getCode(), doc.getName(), p.getCode(), doc.getName() + "医生提醒您:为完成家庭医生签约," +
 | 
	
		
			
				|  |  |                     "尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费", "1", "医生:" + doc.getName() + "给患者:" + p.getName() + "发送了缴费提醒!");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (wFlag || mFlag) {
 | 
	
		
			
				|  |  |                 reObj.put("status", 200);
 | 
	
		
			
				|  |  |                 redisTemplate.opsForSet().add("expenses:remind:set",p.getCode());
 | 
	
		
			
				|  |  |                 redisTemplate.opsForSet().add("expenses:remind:set", p.getCode());
 | 
	
		
			
				|  |  |                 redisTemplate.expireAt("expenses:remind:set", today.getTime());
 | 
	
		
			
				|  |  |                 if (wFlag && mFlag) {
 | 
	
		
			
				|  |  |                     reObj.put("msg", "提醒成功");
 | 
	
	
		
			
				|  | @ -253,7 +265,6 @@ public class PatientRemindService extends BaseService {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 提醒患者关注微信
 | 
	
		
			
				|  |  |      *
 | 
	
	
		
			
				|  | @ -293,9 +304,13 @@ public class PatientRemindService extends BaseService {
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param doctor
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Async
 | 
	
		
			
				|  |  |     public void remindPatientWechatFocusAll(String doctor) throws Exception {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             Calendar today = Calendar.getInstance();
 | 
	
		
			
				|  |  |             today.set(Calendar.HOUR, 23);
 | 
	
		
			
				|  |  |             today.set(Calendar.MINUTE, 59);
 | 
	
		
			
				|  |  |             today.set(Calendar.SECOND, 59);
 | 
	
		
			
				|  |  |             today.set(Calendar.MILLISECOND, 59);
 | 
	
		
			
				|  |  |             int page = 0;
 | 
	
		
			
				|  |  |             int start = 0;
 | 
	
		
			
				|  |  |             boolean flag = true;
 | 
	
	
		
			
				|  | @ -311,17 +326,19 @@ public class PatientRemindService extends BaseService {
 | 
	
		
			
				|  |  |                     "        and f.status > 0 " +
 | 
	
		
			
				|  |  |                     "        and f.expenses_status = '1' " +
 | 
	
		
			
				|  |  |                     "        and LENGTH(trim(ifnull(p.openid,''))) < 1 limit ?,3000";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             List<Map<String, Object>> patients = new ArrayList<>();
 | 
	
		
			
				|  |  |             List<String> redisPatients = new ArrayList<>();
 | 
	
		
			
				|  |  |             Set<String> exist = redisTemplate.opsForSet().members("wechat:focus:remind:set");
 | 
	
		
			
				|  |  |             while (flag) {
 | 
	
		
			
				|  |  |                 List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{doctor, doctor, start});
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (result != null && result.size() > 0) {
 | 
	
		
			
				|  |  |                     patients.addAll(result);
 | 
	
		
			
				|  |  |                     for (Map<String, Object> map : result) {
 | 
	
		
			
				|  |  |                         boolean epTime = redisTemplate.opsForSet().isMember("wechat:focus:remind:set", map.get("code").toString());
 | 
	
		
			
				|  |  |                         if (epTime) {
 | 
	
		
			
				|  |  |                         if (exist != null && exist.contains(map.get("code").toString())) {
 | 
	
		
			
				|  |  |                             continue;
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         remindWechatFocus(map, doc);
 | 
	
		
			
				|  |  |                         redisPatients.add(map.get("code").toString());
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     page = page + 1;
 | 
	
		
			
				|  |  |                     start = page * 3000;
 | 
	
	
		
			
				|  | @ -330,6 +347,13 @@ public class PatientRemindService extends BaseService {
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (patients.size() > 0) {
 | 
	
		
			
				|  |  |                 RemindFocusWechatTask task = new RemindFocusWechatTask(patients, doc);
 | 
	
		
			
				|  |  |                 new Thread(task).run();
 | 
	
		
			
				|  |  |                 redisTemplate.opsForSet().add("wechat:focus:remind:set", redisPatients.toArray(new String[]{}));
 | 
	
		
			
				|  |  |                 redisTemplate.expireAt("wechat:focus:remind:set", today.getTime());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             redisTemplate.opsForValue().set("wechat:focus:remind:doctor:" + doctor, "0");
 | 
	
		
			
				|  |  |             redisTemplate.expire("wechat:focus:remind:doctor:" + doctor, 10, TimeUnit.MINUTES);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
	
		
			
				|  | @ -339,7 +363,6 @@ public class PatientRemindService extends BaseService {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 微信关注提醒
 | 
	
		
			
				|  |  |      *
 | 
	
	
		
			
				|  | @ -349,13 +372,12 @@ public class PatientRemindService extends BaseService {
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject remindWechatFocus(Map<String, Object> p, Doctor doctor) {
 | 
	
		
			
				|  |  |         Calendar today = Calendar.getInstance();
 | 
	
		
			
				|  |  |         today.set(Calendar.HOUR,23);
 | 
	
		
			
				|  |  |         today.set(Calendar.MINUTE,59);
 | 
	
		
			
				|  |  |         today.set(Calendar.SECOND,59);
 | 
	
		
			
				|  |  |         today.set(Calendar.MILLISECOND,59);
 | 
	
		
			
				|  |  |         today.set(Calendar.HOUR, 23);
 | 
	
		
			
				|  |  |         today.set(Calendar.MINUTE, 59);
 | 
	
		
			
				|  |  |         today.set(Calendar.SECOND, 59);
 | 
	
		
			
				|  |  |         today.set(Calendar.MILLISECOND, 59);
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
 | 
	
		
			
				|  |  |         redisTemplate.opsForSet().add("wechat:focus:remind:set",p.get("code").toString());
 | 
	
		
			
				|  |  |         redisTemplate.opsForSet().add("wechat:focus:remind:set", p.get("code").toString());
 | 
	
		
			
				|  |  |         redisTemplate.expireAt("wechat:focus:remind:set", today.getTime());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (p.get("mobile") == null || StringUtils.isEmpty(p.get("mobile").toString())) {
 |