| 
					
				 | 
			
			
				@ -0,0 +1,153 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.service.channel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.ObjectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.doctor.dao.BaseDoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.hospital.message.SystemMessageDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.message.dao.SystemMessageDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.prescription.dao.OutpatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.prescription.service.PrescriptionService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.RemindDoctorJob; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.common.IdCardUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.utils.YkyySMSService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.enterprise.EnterpriseService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import net.sf.json.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class RemindDoctorService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final Logger logger = LoggerFactory.getLogger(RemindDoctorService.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private SystemMessageDao systemMessageDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private OutpatientDao outpatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseDoctorDao baseDoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private EnterpriseService enterpriseService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${wechat.id}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String wechatId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionService prescriptionService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void sendSystemMessage() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<WlyyOutpatientDO> list = outpatientDao.findDoctorRemindMessage(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            WlyyHospitalSysDictDO wlyyHospitalSysDictDO = wlyyHospitalSysDictDao.findById("isCirculation");//是否重复提醒 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<WlyyHospitalSysDictDO> dictDOS =wlyyHospitalSysDictDao.findByDictNameAndDictCode("RECEPTION_REMINDER","time"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Long doctorRemindTime =0l; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (dictDOS!=null&&dictDOS.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                doctorRemindTime = Long.parseLong(dictDOS.get(0).getDictValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String baseUrl = prescriptionService.findDomainUrlInDict(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String msg = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sex = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String age=""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String date = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String title = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (WlyyOutpatientDO wlyyOutpatientDO : list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Long lastRemindTime=wlyyOutpatientDO.getLastRemindTime()==null?wlyyOutpatientDO.getCreateTime().getTime():wlyyOutpatientDO.getLastRemindTime().getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Long nowTime = new Date().getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (StringUtils.isNoneBlank(wlyyOutpatientDO.getDoctor())&&!StringUtils.isNoneBlank(wlyyOutpatientDO.getRemindDoctor())&&(nowTime-lastRemindTime)>doctorRemindTime*1000*60) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logger.info("条件满足开始发送提醒"+wlyyOutpatientDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    sex= IdCardUtil.getSexForIdcard(wlyyOutpatientDO.getIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    age = IdCardUtil.getAgeForIdcard(wlyyOutpatientDO.getIdcard())+""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Long createTime = wlyyOutpatientDO.getCreateTime().getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Long minusts = TimeUnit.MILLISECONDS.toMinutes(nowTime - createTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    SystemMessageDO systemMessageDO = new SystemMessageDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if ("2".equals(wlyyOutpatientDO.getOutpatientType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        systemMessageDO.setTitle("协同门诊消息提醒"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        systemMessageDO.setType("3"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } else if ("3".equals(wlyyOutpatientDO.getOutpatientType())) {//专家咨询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        //1.图文 2.视频 3家医 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if ("1".equals(wlyyOutpatientDO.getType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            systemMessageDO.setTitle("图文咨询消息提醒"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            systemMessageDO.setType("18"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            title = "图文咨询消息提醒"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            msg = wlyyOutpatientDO.getPatientName()+"("+sex+" "+age+"岁)向您发起了图文咨询,已等待"+minusts+"分钟。点击接诊"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } else if ("3".equals(wlyyOutpatientDO.getType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            systemMessageDO.setTitle("家医咨询消息提醒"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            systemMessageDO.setType("15"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            systemMessageDO.setTitle("视频咨询消息提醒"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            systemMessageDO.setType("17"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            title = "视频咨询消息提醒"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            date = DateUtil.dateToStrLong(wlyyOutpatientDO.getRegisterDate()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            msg = wlyyOutpatientDO.getPatientName()+"("+sex+" "+age+"岁)预约了"+date+"的视频咨询,点击查看"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } else if ("1".equals(wlyyOutpatientDO.getOutpatientType())) {//在线复诊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        //1.图文 2.视频 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if ("1".equals(wlyyOutpatientDO.getType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            systemMessageDO.setTitle("图文复诊消息提醒"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            systemMessageDO.setType("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            title = "图文复诊消息提醒"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            msg = wlyyOutpatientDO.getPatientName()+"("+sex+" "+age+"岁)向您发起了图文复诊,已等待"+minusts+"分钟。点击接诊"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            systemMessageDO.setTitle("视频复诊消息提醒"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            systemMessageDO.setType("2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            title = "视频复诊消息提醒"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            date = DateUtil.dateToStrLong(wlyyOutpatientDO.getRegisterDate()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            msg = wlyyOutpatientDO.getPatientName()+"("+sex+" "+age+"岁)预约了"+date+"的视频复诊,点击查看"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSONObject data = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    data.put("name", wlyyOutpatientDO.getPatientName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    data.put("age", IdCardUtil.getAgeForIdcard(wlyyOutpatientDO.getIdcard())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    data.put("gender", IdCardUtil.getSexForIdcard_new(wlyyOutpatientDO.getIdcard())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    data.put("question", wlyyOutpatientDO.getDescription()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    data.put("msg", systemMessageDO.getTitle()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    data.put("waitTime",minusts); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDO.setData(data.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDO.setReceiver(wlyyOutpatientDO.getDoctor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDO.setReceiverName(wlyyOutpatientDO.getDoctorName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDO.setRelationCode(wlyyOutpatientDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDO.setSender(wlyyOutpatientDO.getPatient()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDO.setSenderName(wlyyOutpatientDO.getPatientName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDO.setRelationCode(wlyyOutpatientDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDO.setIsRead("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDO.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDO.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDao.save(systemMessageDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //系统消息结束===开始发送企业模板消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (wechatId.equalsIgnoreCase("xm_zsyy_wx")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        String url=baseUrl+"/hlwyy/ims-app-web/#/onlineChat/detail?_rs_title="+wlyyOutpatientDO.getDescription()+"&type=3&id="+wlyyOutpatientDO.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        enterpriseService.sendTWMesByDoctor("zsyy",wlyyOutpatientDO.getDoctor(),title,msg,url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    }else if(wechatId.equalsIgnoreCase("xm_ykyy_wx")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        String url=baseUrl+"/ims-app-web/#/onlineChat/detail?_rs_title="+wlyyOutpatientDO.getDescription()+"&type=3&id="+wlyyOutpatientDO.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        enterpriseService.sendTWMesByDoctor("xm_ykyy_wx",wlyyOutpatientDO.getDoctor(),title,msg,url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    }else if (wechatId.equalsIgnoreCase("xm_xzzx_wx")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        String url=baseUrl+"/hlwyy/ims-app-web/#/onlineChat/detail?_rs_title="+wlyyOutpatientDO.getDescription()+"&type=3&id="+wlyyOutpatientDO.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        enterpriseService.sendTWMesByDoctor("xm_xzzx_wx",wlyyOutpatientDO.getDoctor(),title,msg,url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (wlyyHospitalSysDictDO!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if ("1".equalsIgnoreCase(wlyyHospitalSysDictDO.getDictValue())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            wlyyOutpatientDO.setRemindDoctor("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    wlyyOutpatientDO.setLastRemindTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    outpatientDao.save(wlyyOutpatientDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |