OutPatientRemindJob.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.yihu.jw.job;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
  4. import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
  5. import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
  6. import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
  7. import com.yihu.jw.hospital.prescription.service.PrescriptionService;
  8. import com.yihu.jw.im.service.ImService;
  9. import com.yihu.jw.im.util.ImUtil;
  10. import com.yihu.jw.util.date.DateUtil;
  11. import org.quartz.Job;
  12. import org.quartz.JobExecutionContext;
  13. import org.quartz.JobExecutionException;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.beans.factory.annotation.Value;
  18. import java.util.Date;
  19. import java.util.List;
  20. /**
  21. * Created by Trick on 2020/3/11
  22. */
  23. public class OutPatientRemindJob implements Job {
  24. private static final Logger logger = LoggerFactory.getLogger(OutPatientRemindJob.class);
  25. @Autowired
  26. public ImUtil imUtil;
  27. @Autowired
  28. private OutpatientDao outpatientDao;
  29. @Autowired
  30. private PrescriptionService prescriptionService;
  31. @Autowired
  32. private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
  33. @Value("${wechat.id}")
  34. private String wxId;
  35. @Override
  36. public void execute(JobExecutionContext context) throws JobExecutionException {
  37. List<WlyyOutpatientDO> wlyyOutpatientDOS= outpatientDao.findWaitingOutpatient();
  38. String senderId ="";
  39. String reciverId = "";
  40. long timeCount = 0l;
  41. String content = "您邀请的医师暂无应答,您可以选择继续等待或者取消邀请。";
  42. JSONObject object = new JSONObject();
  43. object.put("socket_sms_type",14);
  44. object.put("msg",content);
  45. object.put("msg_time", DateUtil.dateToStrLong(new Date()));
  46. if (null!=wlyyOutpatientDOS){
  47. for (WlyyOutpatientDO wlyyOutpatientDO:wlyyOutpatientDOS){
  48. long patientTime = wlyyOutpatientDO.getCreateTime().getTime();
  49. logger.info("接诊创建时间="+patientTime);
  50. List<WlyyHospitalSysDictDO> wlyyHospitalSysDictDOS = wlyyHospitalSysDictDao.findByDictName("outpatient_timeout_remind");
  51. if (wlyyHospitalSysDictDOS.size()>0){
  52. timeCount = Long.valueOf(wlyyHospitalSysDictDOS.get(0).getDictValue());
  53. }
  54. long currentTime = new Date().getTime();
  55. logger.info("当前时间="+currentTime);
  56. logger.info("数据库配置时间=0"+timeCount);
  57. if (currentTime-patientTime>timeCount*60*1000){
  58. logger.info("--便利发送消息");
  59. reciverId = wlyyOutpatientDO.getPatient();
  60. logger.info("---发送人id"+senderId);
  61. senderId= wlyyOutpatientDO.getDoctor();
  62. logger.info("---接受人Id"+reciverId);
  63. imUtil.sendMessage(senderId,reciverId,"1",object.toString());
  64. logger.info("--发送结束");
  65. logger.info("--模板发送开始");
  66. prescriptionService.sendWxTemplateMsg(wxId,wlyyOutpatientDO.getId(),null,null,"outPatientTimeOutRemind","");
  67. }
  68. }
  69. }
  70. }
  71. }