|  | @ -1,9 +1,12 @@
 | 
	
		
			
				|  |  | package com.yihu.wlyy.service.template;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.doctor.profile.Doctor;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.patient.Patient;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.doctor.DoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.patient.PatientDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.BaseService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.task.PushMsgTask;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.ImUtill;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
 | 
	
		
			
				|  |  | import org.json.JSONArray;
 | 
	
	
		
			
				|  | @ -29,7 +32,12 @@ public class DoctorFeldsherTemplateService extends BaseService {
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientDao patientDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DoctorDao doctorDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WeiXinOpenIdUtils weiXinOpenIdUtils;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ImUtill imUtill;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private static final Logger logger = LoggerFactory.getLogger(DoctorFeldsherTemplateService.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
	
		
			
				|  | @ -73,6 +81,195 @@ public class DoctorFeldsherTemplateService extends BaseService {
 | 
	
		
			
				|  |  |                 pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 10, member.getOpenid(), name, sendJson);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         logger.info("sendJson: "+sendJson);
 | 
	
		
			
				|  |  |         logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 发送给医生的模板消息提醒
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param patientCode 居民code
 | 
	
		
			
				|  |  |      * @param doctorCode  医生code
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void sendDoctorTemplate(String patientCode, String doctorCode, int type) throws Exception {
 | 
	
		
			
				|  |  |         int num = 0;
 | 
	
		
			
				|  |  |         int num1 = 0;
 | 
	
		
			
				|  |  |         int num2 = 0;
 | 
	
		
			
				|  |  |         int num3 = 0;
 | 
	
		
			
				|  |  |         int num4 = 0;
 | 
	
		
			
				|  |  |         int num5 = 0;
 | 
	
		
			
				|  |  |         int num6 = 0;
 | 
	
		
			
				|  |  |         Date date = new Date();
 | 
	
		
			
				|  |  |         Date date1 = new Date();
 | 
	
		
			
				|  |  |         String content1 = "";
 | 
	
		
			
				|  |  |         String contetn2 = "";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Patient people = patientDao.findByCode(patientCode);
 | 
	
		
			
				|  |  |         String patientOpenId = people.getOpenid();
 | 
	
		
			
				|  |  |         String patientName = people.getName();
 | 
	
		
			
				|  |  |         int patientSex = people.getSex();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Doctor doctor = doctorDao.findByCode(doctorCode);
 | 
	
		
			
				|  |  |         String doctorName = doctor.getName();
 | 
	
		
			
				|  |  |         String doctorOpenId = doctor.getOpenid();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //使用微信应用宝跳转APP的功能。点击后跳转APP消息页。
 | 
	
		
			
				|  |  |         String url = "";
 | 
	
		
			
				|  |  |         String first = "";
 | 
	
		
			
				|  |  |         String remark = "请进入手机APP查看,如尚未安装APP请点击详情下载安装";
 | 
	
		
			
				|  |  |         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
 | 
	
		
			
				|  |  |         JSONObject sendJson = new JSONObject();
 | 
	
		
			
				|  |  |         switch (type) {
 | 
	
		
			
				|  |  |             case 1:
 | 
	
		
			
				|  |  |                 first = doctorName + "医生您好,你有一条新的签约申请待处理";
 | 
	
		
			
				|  |  |                 sendJson.put("keyword1", patientName);
 | 
	
		
			
				|  |  |                 sendJson.put("keyword2", dateFormat.format(new Date()));
 | 
	
		
			
				|  |  |                 sendJson.put("first", first);
 | 
	
		
			
				|  |  |                 sendJson.put("remark", remark);
 | 
	
		
			
				|  |  |                 sendJson.put("url", url);//带参数的模板跳转链接
 | 
	
		
			
				|  |  |                 pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 0, doctorOpenId, doctorName, sendJson);
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 2:
 | 
	
		
			
				|  |  |                 first = doctorName + "医生,您的签约居民" + patientName + "有" + num + "条未读的体征异常消息";
 | 
	
		
			
				|  |  |                 sendJson.put("keyword1", patientName);
 | 
	
		
			
				|  |  |                 sendJson.put("keyword2", dateFormat.format(new Date()));
 | 
	
		
			
				|  |  |                 sendJson.put("first", first);
 | 
	
		
			
				|  |  |                 sendJson.put("remark", remark);
 | 
	
		
			
				|  |  |                 sendJson.put("url", url);//带参数的模板跳转链接
 | 
	
		
			
				|  |  |                 pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 0, doctorOpenId, doctorName, sendJson);
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 3:
 | 
	
		
			
				|  |  |                 first = doctorName + "医生您好。" + date + "新增1个签约居民待分配健管师,截至目前共有 " + num1 + " 人待处理";
 | 
	
		
			
				|  |  |                 sendJson.put("keyword1", "分配健管师");
 | 
	
		
			
				|  |  |                 sendJson.put("keyword2", dateFormat.format(new Date()));
 | 
	
		
			
				|  |  |                 sendJson.put("first", first);
 | 
	
		
			
				|  |  |                 sendJson.put("remark", remark);
 | 
	
		
			
				|  |  |                 sendJson.put("url", url);//带参数的模板跳转链接
 | 
	
		
			
				|  |  |                 pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 0, doctorOpenId, doctorName, sendJson);
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 4:
 | 
	
		
			
				|  |  |                 first = "您今日有" + num3 + "个随访计划待处理";
 | 
	
		
			
				|  |  |                 sendJson.put("keyword1", patientName);
 | 
	
		
			
				|  |  |                 sendJson.put("keyword2", dateFormat.format(new Date()));
 | 
	
		
			
				|  |  |                 sendJson.put("first", first);
 | 
	
		
			
				|  |  |                 sendJson.put("remark", remark);
 | 
	
		
			
				|  |  |                 sendJson.put("url", url);//带参数的模板跳转链接
 | 
	
		
			
				|  |  |                 pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 0, doctorOpenId, doctorName, sendJson);
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 5:
 | 
	
		
			
				|  |  |                 first = doctorName + "医生您好,有患者向您发起咨询";
 | 
	
		
			
				|  |  |                 sendJson.put("keyword1", patientName);
 | 
	
		
			
				|  |  |                 sendJson.put("keyword2", patientSex == 1 ? "男" : "女");
 | 
	
		
			
				|  |  |                 sendJson.put("first", first);
 | 
	
		
			
				|  |  |                 sendJson.put("remark", remark);
 | 
	
		
			
				|  |  |                 sendJson.put("url", url);//带参数的模板跳转链接
 | 
	
		
			
				|  |  |                 pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 0, doctorOpenId, doctorName, sendJson);
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 6:
 | 
	
		
			
				|  |  |                 first = "居民" + patientName + "的健康咨询有新的回复";
 | 
	
		
			
				|  |  |                 sendJson.put("keyword1", content1);
 | 
	
		
			
				|  |  |                 sendJson.put("keyword2", contetn2);
 | 
	
		
			
				|  |  |                 sendJson.put("keyword3", doctorName);
 | 
	
		
			
				|  |  |                 sendJson.put("first", first);
 | 
	
		
			
				|  |  |                 sendJson.put("remark", remark);
 | 
	
		
			
				|  |  |                 sendJson.put("url", url);//带参数的模板跳转链接
 | 
	
		
			
				|  |  |                 pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 0, doctorOpenId, doctorName, sendJson);
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 7:
 | 
	
		
			
				|  |  |                 first = doctorName + "医生您好。您的签约居民" + patientName + "申请线上续方,请尽快审核";
 | 
	
		
			
				|  |  |                 sendJson.put("keyword1", "续方审核");
 | 
	
		
			
				|  |  |                 sendJson.put("keyword2", dateFormat.format(new Date()));
 | 
	
		
			
				|  |  |                 sendJson.put("first", first);
 | 
	
		
			
				|  |  |                 sendJson.put("remark", remark);
 | 
	
		
			
				|  |  |                 sendJson.put("url", url);//带参数的模板跳转链接
 | 
	
		
			
				|  |  |                 pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 0, doctorOpenId, doctorName, sendJson);
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 8:
 | 
	
		
			
				|  |  |                 first = doctorName + "医生您好。" + date1 +
 | 
	
		
			
				|  |  |                         "新增1个续方订单待分配配送员,目前共" + num4 +
 | 
	
		
			
				|  |  |                         "人待分配,一个尽快分配";
 | 
	
		
			
				|  |  |                 sendJson.put("keyword1", "分配配送员");
 | 
	
		
			
				|  |  |                 sendJson.put("keyword2", dateFormat.format(new Date()));
 | 
	
		
			
				|  |  |                 sendJson.put("first", first);
 | 
	
		
			
				|  |  |                 sendJson.put("remark", remark);
 | 
	
		
			
				|  |  |                 sendJson.put("url", url);//带参数的模板跳转链接
 | 
	
		
			
				|  |  |                 pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 0, doctorOpenId, doctorName, sendJson);
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 9:
 | 
	
		
			
				|  |  |                 first = doctorName + "医生您好。您有一个您有1个续方申请处方开立失败";
 | 
	
		
			
				|  |  |                 sendJson.put("keyword1", doctorName);
 | 
	
		
			
				|  |  |                 sendJson.put("keyword2", patientName);
 | 
	
		
			
				|  |  |                 sendJson.put("first", first);
 | 
	
		
			
				|  |  |                 sendJson.put("remark", remark);
 | 
	
		
			
				|  |  |                 sendJson.put("url", url);//带参数的模板跳转链接
 | 
	
		
			
				|  |  |                 pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 0, doctorOpenId, doctorName, sendJson);
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 10:
 | 
	
		
			
				|  |  |                 first = doctorName + "医生您好。您有1个续方申请已在线下调整完成,请尽快进行CA认证";
 | 
	
		
			
				|  |  |                 sendJson.put("keyword1", "续方审核CA认证");
 | 
	
		
			
				|  |  |                 sendJson.put("keyword2", dateFormat.format(new Date()));
 | 
	
		
			
				|  |  |                 sendJson.put("first", first);
 | 
	
		
			
				|  |  |                 sendJson.put("remark", remark);
 | 
	
		
			
				|  |  |                 sendJson.put("url", url);//带参数的模板跳转链接
 | 
	
		
			
				|  |  |                 pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 0, doctorOpenId, doctorName, sendJson);
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 11:
 | 
	
		
			
				|  |  |                 first = doctorName + "医生您好,你有一条新的续签申请待处理";
 | 
	
		
			
				|  |  |                 sendJson.put("keyword1", patientName);
 | 
	
		
			
				|  |  |                 sendJson.put("keyword2", dateFormat.format(new Date()));
 | 
	
		
			
				|  |  |                 sendJson.put("first", first);
 | 
	
		
			
				|  |  |                 sendJson.put("remark", remark);
 | 
	
		
			
				|  |  |                 sendJson.put("url", url);//带参数的模板跳转链接
 | 
	
		
			
				|  |  |                 pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 0, doctorOpenId, doctorName, sendJson);
 | 
	
		
			
				|  |  |                 logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      *  拼装医生助手 医生类模板消息并发送
 | 
	
		
			
				|  |  |      * @param doctorCode 医生code
 | 
	
		
			
				|  |  |      * @param sessionId 会话Id
 | 
	
		
			
				|  |  |      * @param sessionType 会话类型
 | 
	
		
			
				|  |  |      * @param businessType 消息类型
 | 
	
		
			
				|  |  |      * @param from 发送者
 | 
	
		
			
				|  |  |      * @param content 消息内容
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Boolean sendDoctorTemplate(String doctorCode, String sessionId, String sessionType, String businessType, String from, String content) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             String remark = "请进入手机APP查看,如尚未安装APP请点击详情下载安装";
 | 
	
		
			
				|  |  |             String url = "www.baidu.com";
 | 
	
		
			
				|  |  |             SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
 | 
	
		
			
				|  |  |             JSONObject sendJson = new JSONObject();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             Doctor doctor = doctorDao.findByCode(doctorCode);
 | 
	
		
			
				|  |  |             String doctorName = doctor.getName();
 | 
	
		
			
				|  |  |             String doctorOpenId = doctor.getOpenid();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String first = businessType;
 | 
	
		
			
				|  |  |             sendJson.put("keyword1", content);
 | 
	
		
			
				|  |  |             sendJson.put("keyword2", dateFormat.format(new Date()));
 | 
	
		
			
				|  |  |             sendJson.put("first", first);
 | 
	
		
			
				|  |  |             sendJson.put("remark", remark);
 | 
	
		
			
				|  |  |             sendJson.put("url", url);//带参数的模板跳转链接
 | 
	
		
			
				|  |  |             pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 11, doctorOpenId, doctorName, sendJson);
 | 
	
		
			
				|  |  |             logger.info("sendJson: " + sendJson);
 | 
	
		
			
				|  |  |             return true;
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             return false;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |