| 
					
				 | 
			
			
				@ -0,0 +1,127 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.util; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.prescription.dao.OutpatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.prescription.service.PrescriptionService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.im.util.ImUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.bouncycastle.asn1.cmp.CertOrEncCert; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.context.annotation.Lazy; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.scheduling.Trigger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.scheduling.TriggerContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.scheduling.annotation.EnableScheduling; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.scheduling.annotation.Scheduled; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.scheduling.annotation.SchedulingConfigurer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.scheduling.config.ScheduledTaskRegistrar; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.scheduling.support.CronTrigger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Lazy(false) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Component 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@EnableScheduling 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class AutoTimeOutRemind implements SchedulingConfigurer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final Logger logger = LoggerFactory.getLogger(AutoTimeOutRemind.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static String cron; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static String dictName = "remind_patient_job"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ImUtil imUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private OutpatientDao outpatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionService prescriptionService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${wechat.ids}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String wxId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public AutoTimeOutRemind() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      cron = "0 /5 * * * ?"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        System.out.println("创建时的corn"+cron); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String change(String corIn){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isNotBlank(corIn)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            cron = corIn; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<WlyyHospitalSysDictDO> wlyyHospitalSysDictDO =wlyyHospitalSysDictDao.findByDictName(dictName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (wlyyHospitalSysDictDO.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                cron = wlyyHospitalSysDictDO.get(0).getDictValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                System.out.println("dict"+ cron); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        System.out.println(cron); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return "success"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        taskRegistrar.addTriggerTask(new Runnable() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            public void run() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logger.info("启动发送超时提示消息开始"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                System.out.println(wxId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                System.out.println("启动发送超时提示消息开始"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Integer remindCount = 5; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<WlyyHospitalSysDictDO> countList = wlyyHospitalSysDictDao.findByDictName("remind_count"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (countList.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    remindCount= null!=countList.get(0).getDictValue()?Integer.parseInt(countList.get(0).getDictValue()):5; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<WlyyOutpatientDO> wlyyOutpatientDOS= outpatientDao.findWaitingOutpatient(remindCount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String senderId =""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String reciverId = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                long timeCount = 0l; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String content = "您邀请的医师暂无应答,您可以选择继续等待或者取消邀请。"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject object = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                object.put("socket_sms_type",14); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                object.put("msg",content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                object.put("msg_time", DateUtil.dateToStrLong(new Date())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (null!=wlyyOutpatientDOS){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    for (WlyyOutpatientDO wlyyOutpatientDO:wlyyOutpatientDOS){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        long patientTime = wlyyOutpatientDO.getCreateTime().getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Integer currentRemindCount = wlyyOutpatientDO.getRemindCount(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        logger.info("接诊创建时间="+patientTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        List<WlyyHospitalSysDictDO> wlyyHospitalSysDictDOS = wlyyHospitalSysDictDao.findByDictName("outpatient_timeout_remind"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (wlyyHospitalSysDictDOS.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            timeCount = Long.valueOf(wlyyHospitalSysDictDOS.get(0).getDictValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        long currentTime = new Date().getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        logger.info("当前时间="+currentTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        logger.info("数据库配置时间=0"+timeCount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (currentTime-patientTime>timeCount*60*1000){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            logger.info("--便利发送消息"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            reciverId = wlyyOutpatientDO.getPatient(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            logger.info("---发送人id"+senderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            senderId= wlyyOutpatientDO.getDoctor(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            logger.info("---接受人Id"+reciverId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            imUtil.sendMessage(senderId,reciverId,"1",object.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            logger.info("--发送结束"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            logger.info("--模板发送开始"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            prescriptionService.sendWxTemplateMsg(wxId,wlyyOutpatientDO.getId(),null,null,"outPatientTimeOutRemind",""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            wlyyOutpatientDO.setRemindCount(currentRemindCount+1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            outpatientDao.save(wlyyOutpatientDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }, new Trigger() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            public Date nextExecutionTime(TriggerContext triggerContext) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                // 任务触发,可修改任务的执行周期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                CronTrigger trigger = new CronTrigger(cron); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                System.out.println("任务触发,可修改任务的执行周期"+cron); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Date nextExec = trigger.nextExecutionTime(triggerContext); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return nextExec; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |