RemindExpensesTask.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package com.yihu.wlyy.task;
  2. import com.yihu.wlyy.entity.doctor.profile.Doctor;
  3. import com.yihu.wlyy.entity.organization.Hospital;
  4. import com.yihu.wlyy.entity.patient.Patient;
  5. import com.yihu.wlyy.service.app.consult.ConsultService;
  6. import com.yihu.wlyy.service.common.SMSService;
  7. import com.yihu.wlyy.util.DateUtil;
  8. import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
  9. import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.json.JSONArray;
  12. import org.json.JSONObject;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.context.support.SpringBeanAutowiringSupport;
  15. import java.util.Date;
  16. import java.util.List;
  17. /**
  18. * 缴费提醒任务
  19. * <p>
  20. * Created by lyr-pc on 2017/1/16.
  21. */
  22. public class RemindExpensesTask implements Runnable {
  23. List<Patient> patients;
  24. Doctor doctor;
  25. Hospital hospital;
  26. @Autowired
  27. WeiXinAccessTokenUtils tokenUtils;
  28. @Autowired
  29. WeiXinOpenIdUtils weiXinOpenIdUtils;
  30. @Autowired
  31. ConsultService consultService;
  32. private SMSService smsService;
  33. public RemindExpensesTask(List<Patient> patients, Doctor doctor, Hospital hospital,SMSService smsService) {
  34. this.patients = patients;
  35. this.doctor = doctor;
  36. this.hospital = hospital;
  37. SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
  38. this.smsService=smsService;
  39. }
  40. @Override
  41. public void run() {
  42. StringBuffer sb = new StringBuffer();
  43. for (Patient p : patients) {
  44. try {
  45. if (StringUtils.isNotEmpty(p.getMobile())) {
  46. if (sb.length() > 0) {
  47. sb.append(",");
  48. }
  49. sb.append(p.getMobile());
  50. }
  51. // 微信提醒
  52. JSONObject json = new JSONObject();
  53. json.put("first", "缴费提醒");
  54. json.put("toUser", p.getCode());
  55. json.put("represented",p.getCode());//被代理人
  56. json.put("name", p.getName());
  57. json.put("doctor", doctor.getCode());
  58. json.put("doctorName", doctor.getName());
  59. json.put("date", DateUtil.dateToStrShort(new Date()));
  60. json.put("content", p.getName() + ",您好!为完成家庭医生签约,尽早为您提供家庭医生服务,请尽快到" + hospital.getName() + "(地址:" + hospital.getAddress() + ")缴费");
  61. json.put("remark", "");
  62. if (StringUtils.isNotEmpty(p.getOpenid())) {
  63. // 添加到发送队列
  64. PushMsgTask.getInstance().putWxMsg(tokenUtils.getAccessToken(), 8, p.getOpenid(), p.getName(), json);
  65. }
  66. //发送代理人
  67. JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
  68. if(jsonArray!=null&&jsonArray.length()>0){
  69. String first = (String) json.get("doctorName");
  70. for (int i = 0;i<jsonArray.length();i++){
  71. JSONObject j = jsonArray.getJSONObject(i);
  72. Patient member = (Patient) j.get("member");
  73. JSONObject data = json;
  74. data.remove("toUser");
  75. data.put("toUser",member.getCode());
  76. data.remove("doctorName");
  77. data.put("doctorName", weiXinOpenIdUtils.getTitleMes(p, j.getInt("relation"), p.getName()) +"\n"+first);
  78. PushMsgTask.getInstance().putWxMsg(tokenUtils.getAccessToken(), 8, member.getOpenid(), p.getName(), data);
  79. }
  80. }
  81. //发送IM
  82. consultService.sendMucMessageBySingnType(doctor.getCode(), doctor.getName(), p.getCode(), doctor.getName() + "医生提醒您:为完成家庭医生签约," +
  83. "尽早为您提供家庭医生服务,请尽快到" + doctor.getName() + "(地址:" + hospital.getAddress() + ")缴费", "1", p.getName());
  84. } catch (Exception e) {
  85. e.printStackTrace();
  86. }
  87. }
  88. JSONObject result = smsService.sendMsg(sb.toString(), doctor.getName() + "医生提醒您:为完成家庭医生签约," +
  89. "尽早为您提供家庭医生服务,请尽快到" + hospital.getName() + "(地址:" + hospital.getAddress() + ")缴费");
  90. }
  91. }