|  | @ -2,16 +2,14 @@ package com.yihu.jw.door.util;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.WxAccessTokenDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.WxWechatDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.door.WlyyDoorServiceOrderDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.message.SystemMessageDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.exception.ApiException;
 | 
	
		
			
				|  |  | import com.yihu.jw.exception.code.ExceptionCode;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.message.dao.SystemMessageDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.base.WechatRequestMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.http.HttpClientUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.wechat.WeixinMessagePushUtils;
 | 
	
	
		
			
				|  | @ -19,11 +17,10 @@ import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.WxAccessTokenDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.WxTemplateConfigDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.service.WxAccessTokenService;
 | 
	
		
			
				|  |  | import com.yihu.utils.network.HttpUtils;
 | 
	
		
			
				|  |  | import org.apache.commons.collections.CollectionUtils;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
		
			
				|  |  | import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 | 
	
	
		
			
				|  | @ -56,13 +53,14 @@ public class MessageUtil {
 | 
	
		
			
				|  |  |     private SystemMessageDao systemMessageDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WxAccessTokenDao wxAccessTokenDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorDao baseDoctorDao;
 | 
	
		
			
				|  |  |     //发送微信模板消息
 | 
	
		
			
				|  |  |     public static String sendMessageUrl ="http://172.16.100.37:8090/hospitalPortal-sms/sms/sendMessage";
 | 
	
		
			
				|  |  |     public static String sendMessageUrl = "http://172.16.100.37:8090/hospitalPortal-sms/sms/sendMessage";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param wxId
 | 
	
		
			
				|  |  |      * @param patient 患者id
 | 
	
		
			
				|  |  |      * @param patient       患者id
 | 
	
		
			
				|  |  |      * @param cardNo
 | 
	
		
			
				|  |  |      * @param first
 | 
	
		
			
				|  |  |      * @param noticeContent
 | 
	
	
		
			
				|  | @ -70,52 +68,52 @@ public class MessageUtil {
 | 
	
		
			
				|  |  |      * @param redirectUrl
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String sendWXMes(String wxId,String patient,String cardNo,String first,String noticeContent,String remark,String redirectUrl){
 | 
	
		
			
				|  |  |         String msg="first:"+first+"contentMsg:"+noticeContent+"remark:"+remark;
 | 
	
		
			
				|  |  |         logger.info("发送的信息="+msg);
 | 
	
		
			
				|  |  |     public String sendWXMes(String wxId, String patient, String cardNo, String first, String noticeContent, String remark, String redirectUrl) {
 | 
	
		
			
				|  |  |         String msg = "first:" + first + "contentMsg:" + noticeContent + "remark:" + remark;
 | 
	
		
			
				|  |  |         logger.info("发送的信息=" + msg);
 | 
	
		
			
				|  |  |         JSONObject params = new JSONObject();
 | 
	
		
			
				|  |  |         params.put("transType","sms.hospital.notice");
 | 
	
		
			
				|  |  |         params.put("merchId","3501000014");
 | 
	
		
			
				|  |  |         params.put("transType", "sms.hospital.notice");
 | 
	
		
			
				|  |  |         params.put("merchId", "3501000014");
 | 
	
		
			
				|  |  |         JSONObject p = new JSONObject();
 | 
	
		
			
				|  |  |         String openId = "";
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(patient)){
 | 
	
		
			
				|  |  |             String sql = "select * from base.base_patient_wechat where wechat_id='"+wxId+"'and patient_id='"+patient+"' ";
 | 
	
		
			
				|  |  |             List<BasePatientWechatDo> paientWechatDos = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BasePatientWechatDo.class));
 | 
	
		
			
				|  |  |             if(paientWechatDos!=null&&paientWechatDos.size()>0){
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(patient)) {
 | 
	
		
			
				|  |  |             String sql = "select * from base.base_patient_wechat where wechat_id='" + wxId + "'and patient_id='" + patient + "' ";
 | 
	
		
			
				|  |  |             List<BasePatientWechatDo> paientWechatDos = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(BasePatientWechatDo.class));
 | 
	
		
			
				|  |  |             if (paientWechatDos != null && paientWechatDos.size() > 0) {
 | 
	
		
			
				|  |  |                 openId = paientWechatDos.get(0).getOpenid();
 | 
	
		
			
				|  |  |                 p.put("openId",openId);
 | 
	
		
			
				|  |  |                 p.put("openId", openId);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             p.put("cardNo",cardNo);
 | 
	
		
			
				|  |  |         } else {
 | 
	
		
			
				|  |  |             p.put("cardNo", cardNo);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         p.put("first",first);
 | 
	
		
			
				|  |  |         p.put("noticeTime", DateUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm:ss"));
 | 
	
		
			
				|  |  |         p.put("noticeContent",noticeContent);
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(redirectUrl)){
 | 
	
		
			
				|  |  |             p.put("redirectUrl",redirectUrl);
 | 
	
		
			
				|  |  |         p.put("first", first);
 | 
	
		
			
				|  |  |         p.put("noticeTime", DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss"));
 | 
	
		
			
				|  |  |         p.put("noticeContent", noticeContent);
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(redirectUrl)) {
 | 
	
		
			
				|  |  |             p.put("redirectUrl", redirectUrl);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         p.put("remark",remark);
 | 
	
		
			
				|  |  |         params.put("param",p);
 | 
	
		
			
				|  |  |         p.put("remark", remark);
 | 
	
		
			
				|  |  |         params.put("param", p);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         logger.info("params :"+params.toString());
 | 
	
		
			
				|  |  |         logger.info("params :" + params.toString());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(StringUtils.isNotBlank(openId)||StringUtils.isNotBlank(cardNo)){
 | 
	
		
			
				|  |  |             String rs = HttpUtil.sendPost(sendMessageUrl,params.toJSONString());
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(openId) || StringUtils.isNotBlank(cardNo)) {
 | 
	
		
			
				|  |  |             String rs = HttpUtil.sendPost(sendMessageUrl, params.toJSONString());
 | 
	
		
			
				|  |  |             JSONObject rsJson = JSON.parseObject(rs);
 | 
	
		
			
				|  |  |             String resCode = rsJson.getString("respCode");
 | 
	
		
			
				|  |  |             if("000000".equals(resCode)){
 | 
	
		
			
				|  |  |             if ("000000".equals(resCode)) {
 | 
	
		
			
				|  |  |                 return "1";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             return "0";
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |         } else {
 | 
	
		
			
				|  |  |             return "-1";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String ehospitalNotice(String userName, String idCard, String phone, String title, String content, String contentString,String url) {
 | 
	
		
			
				|  |  |         String msg="first:"+title+"contentMsg:"+content+"remark:"+contentString;
 | 
	
		
			
				|  |  |         logger.info("发送的信息="+msg);
 | 
	
		
			
				|  |  |     public String ehospitalNotice(String userName, String idCard, String phone, String title, String content, String contentString, String url) {
 | 
	
		
			
				|  |  |         String msg = "first:" + title + "contentMsg:" + content + "remark:" + contentString;
 | 
	
		
			
				|  |  |         logger.info("发送的信息=" + msg);
 | 
	
		
			
				|  |  |         JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |         jsonObject.put("userName", userName);
 | 
	
		
			
				|  |  |         jsonObject.put("idCard", idCard);
 | 
	
	
		
			
				|  | @ -130,132 +128,63 @@ public class MessageUtil {
 | 
	
		
			
				|  |  |         return responseMsg;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void putTemplateWxMessage(String wechatId,String templateName,String scene,String openId,String first,String remark,String url,String ...keywords){
 | 
	
		
			
				|  |  |     public void putTemplateWxMessage(String wechatId, String templateName, String scene, String openId, String first, String remark, String url, String... keywords) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             WxAccessTokenDO wxAccessTokenDO = getWxAccessTokenById(wechatId);
 | 
	
		
			
				|  |  |             if (wxAccessTokenDO==null){
 | 
	
		
			
				|  |  |                 logger.info("wx_access_token表获取为空,wechatId"+wechatId);
 | 
	
		
			
				|  |  |             WxAccessTokenDO wxAccessTokenDO = wxAccessTokenService.getWxAccessTokenById(wechatId);
 | 
	
		
			
				|  |  |             if (wxAccessTokenDO == null) {
 | 
	
		
			
				|  |  |                 logger.info("wx_access_token表获取为空,wechatId" + wechatId);
 | 
	
		
			
				|  |  |                 return;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             WxTemplateConfigDO newConfig = new WxTemplateConfigDO();
 | 
	
		
			
				|  |  |             String sql="select w.* from base.wx_template_config w where w.wechat_id='"+wechatId+"' and w.template_name='"+templateName+"' and w.scene='"+scene+"' and w.status=1";
 | 
	
		
			
				|  |  |             List<WxTemplateConfigDO> configList =  jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(WxTemplateConfigDO.class));
 | 
	
		
			
				|  |  |             WxTemplateConfigDO config =null;
 | 
	
		
			
				|  |  |             if (configList.size()>0){
 | 
	
		
			
				|  |  |                 config = configList.get(0);
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 logger.info("微信模板不存在!请确认wechatId:"+wechatId+",templateName:"+templateName+",scene:"+scene);
 | 
	
		
			
				|  |  |             WxTemplateConfigDO newConfig = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId, templateName, scene, 1);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (newConfig == null) {
 | 
	
		
			
				|  |  |                 logger.info("微信模板不存在!请确认wechatId:" + wechatId + ",templateName:" + templateName + ",scene:" + scene);
 | 
	
		
			
				|  |  |                 return;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             BeanUtils.copyProperties(config, newConfig);
 | 
	
		
			
				|  |  |             if (StringUtils.isNoneBlank(url)){
 | 
	
		
			
				|  |  |             if (StringUtils.isNoneBlank(url)) {
 | 
	
		
			
				|  |  |                 newConfig.setUrl(url);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (StringUtils.isNoneBlank(remark)){
 | 
	
		
			
				|  |  |             if (StringUtils.isNoneBlank(remark)) {
 | 
	
		
			
				|  |  |                 newConfig.setRemark(remark);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             newConfig.setFirst(first);
 | 
	
		
			
				|  |  |             int keyLength = keywords.length;
 | 
	
		
			
				|  |  |             if (keyLength>=1){
 | 
	
		
			
				|  |  |             if (keyLength >= 1) {
 | 
	
		
			
				|  |  |                 newConfig.setKeyword1(keywords[0]);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (keyLength>=2){
 | 
	
		
			
				|  |  |             if (keyLength >= 2) {
 | 
	
		
			
				|  |  |                 newConfig.setKeyword1(keywords[1]);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (keyLength>=3){
 | 
	
		
			
				|  |  |             if (keyLength >= 3) {
 | 
	
		
			
				|  |  |                 newConfig.setKeyword1(keywords[2]);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (keyLength>=4){
 | 
	
		
			
				|  |  |             if (keyLength >= 4) {
 | 
	
		
			
				|  |  |                 newConfig.setKeyword1(keywords[3]);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (keyLength>=5){
 | 
	
		
			
				|  |  |             if (keyLength >= 5) {
 | 
	
		
			
				|  |  |                 newConfig.setKeyword1(keywords[4]);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (keyLength>=6){
 | 
	
		
			
				|  |  |             if (keyLength >= 6) {
 | 
	
		
			
				|  |  |                 newConfig.setKeyword1(keywords[5]);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (keyLength>=7){
 | 
	
		
			
				|  |  |             if (keyLength >= 7) {
 | 
	
		
			
				|  |  |                 newConfig.setKeyword1(keywords[6]);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             //发起微信消息模板推送
 | 
	
		
			
				|  |  |             weixinMessagePushUtils.putWxMsg(wxAccessTokenDO.getAccessToken(), openId, newConfig);
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             logger.info("微信模板推送异常");
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public WxAccessTokenDO getWxAccessTokenById(String wechatId) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             //根据wechatCode查找出appid和appSecret
 | 
	
		
			
				|  |  |             String sql ="select * from base.wx_wechat w where w.id = '"+wechatId+"' and w.status!=-1";
 | 
	
		
			
				|  |  |             List<WxWechatDO> wxWechatList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(WxWechatDO.class));
 | 
	
		
			
				|  |  |             WxWechatDO wxWechat=null;
 | 
	
		
			
				|  |  |             if (wxWechatList.size()>0){
 | 
	
		
			
				|  |  |                 wxWechat = wxWechatList.get(0);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             sql="select * from base.wx_access_token w where w.wechat_id ='"+wechatId+"' order by w.add_timestamp desc ";
 | 
	
		
			
				|  |  |             List<WxAccessTokenDO> wxAccessTokens =  jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(WxAccessTokenDO.class));
 | 
	
		
			
				|  |  |             if(wxWechat==null){
 | 
	
		
			
				|  |  |                 throw new ApiException(WechatRequestMapping.WxConfig.message_fail_wxWechat_is_no_exist, ExceptionCode.common_error_params_code);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if(wxAccessTokens!=null&&wxAccessTokens.size()>0){
 | 
	
		
			
				|  |  |                 for (WxAccessTokenDO accessToken : wxAccessTokens) {
 | 
	
		
			
				|  |  |                     if ((System.currentTimeMillis() - accessToken.getAddTimestamp()) < (accessToken.getExpiresIn() * 500)) {
 | 
	
		
			
				|  |  |                         return accessToken;
 | 
	
		
			
				|  |  |                     } else {
 | 
	
		
			
				|  |  |                         sql="DELETE  from  base.wx_access_token where wechat_id='"+accessToken.getWechatId()+"' and access_token='"+accessToken.getAccessToken()+"'";
 | 
	
		
			
				|  |  |                         jdbcTemplate.execute(sql);
 | 
	
		
			
				|  |  |                         break;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             String token_url = "https://api.weixin.qq.com/cgi-bin/token";
 | 
	
		
			
				|  |  |             String appId="";
 | 
	
		
			
				|  |  |             String appSecret="";
 | 
	
		
			
				|  |  |             appId = wxWechat.getAppId();
 | 
	
		
			
				|  |  |             appSecret = wxWechat.getAppSecret();
 | 
	
		
			
				|  |  |             if (org.springframework.util.StringUtils.isEmpty(appId)){
 | 
	
		
			
				|  |  |                 throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appId_is_null, ExceptionCode.common_error_params_code);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (org.springframework.util.StringUtils.isEmpty(appSecret)){
 | 
	
		
			
				|  |  |                 throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appSecret_is_null, ExceptionCode.common_error_params_code);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             Map<String, Object> params = new HashMap<>();
 | 
	
		
			
				|  |  |             params.put("grant_type", "client_credential");
 | 
	
		
			
				|  |  |             params.put("appid", appId);
 | 
	
		
			
				|  |  |             params.put("secret", appSecret);
 | 
	
		
			
				|  |  |             String result = HttpUtils.doGet(token_url, params).getContent();
 | 
	
		
			
				|  |  |             logger.info("--------------wechat token return:"+result+"---------------");
 | 
	
		
			
				|  |  |             org.json.JSONObject json = new org.json.JSONObject(result);
 | 
	
		
			
				|  |  |             if (json.has("access_token")) {
 | 
	
		
			
				|  |  |                 String token = json.get("access_token").toString();
 | 
	
		
			
				|  |  |                 String expires_in = json.get("expires_in").toString();
 | 
	
		
			
				|  |  |                 WxAccessTokenDO newaccessToken = new WxAccessTokenDO();
 | 
	
		
			
				|  |  |                 newaccessToken.setAccessToken(token);
 | 
	
		
			
				|  |  |                 newaccessToken.setExpiresIn(Long.parseLong(expires_in));
 | 
	
		
			
				|  |  |                 newaccessToken.setAddTimestamp(System.currentTimeMillis());
 | 
	
		
			
				|  |  |                 newaccessToken.setCzrq(new Date());
 | 
	
		
			
				|  |  |                 newaccessToken.setCode(UUID.randomUUID().toString().replace("-",""));
 | 
	
		
			
				|  |  |                 newaccessToken.setWechatId(wechatId);
 | 
	
		
			
				|  |  |                 wxAccessTokenDao.save(newaccessToken);
 | 
	
		
			
				|  |  |                 return newaccessToken;
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 return null;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             logger.info("微信模板推送异常");
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public SystemMessageDO saveSystemMessage(String messageId,String relationCode,String title,String type,String sender,String senderName,String receiver,String receiverName,String idCard,String msg,String over) {
 | 
	
		
			
				|  |  |     public SystemMessageDO saveSystemMessage(String messageId, String relationCode, String title, String type, String sender, String senderName, String receiver, String receiverName, String idCard, String msg, String over) {
 | 
	
		
			
				|  |  |         SystemMessageDO messageDO = new SystemMessageDO();
 | 
	
		
			
				|  |  |         if (StringUtils.isBlank(messageId)){
 | 
	
		
			
				|  |  |             messageDO.setId(UUID.randomUUID().toString().replace("-",""));
 | 
	
		
			
				|  |  |         if (StringUtils.isBlank(messageId)) {
 | 
	
		
			
				|  |  |             messageDO.setId(UUID.randomUUID().toString().replace("-", ""));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         messageDO.setTitle(title);
 | 
	
		
			
				|  |  |         messageDO.setType(type);
 | 
	
	
		
			
				|  | @ -264,31 +193,103 @@ public class MessageUtil {
 | 
	
		
			
				|  |  |         messageDO.setRelationCode(relationCode);
 | 
	
		
			
				|  |  |         messageDO.setReceiver(receiver);
 | 
	
		
			
				|  |  |         messageDO.setReceiverName(receiverName);
 | 
	
		
			
				|  |  |         net.sf.json.JSONObject data = new net.sf.json.JSONObject();
 | 
	
		
			
				|  |  |         data.put("name", receiverName);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtils.isNoneBlank(idCard)){
 | 
	
		
			
				|  |  |                 data.put("age", IdCardUtil.getAgeForIdcard(idCard));
 | 
	
		
			
				|  |  |                 data.put("gender", IdCardUtil.getSexForIdcard(idCard));
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         data.put("msg", msg);
 | 
	
		
			
				|  |  |         messageDO.setData(data.toString());
 | 
	
		
			
				|  |  |         messageDO.setData(msg);
 | 
	
		
			
				|  |  |         messageDO.setOver(over);
 | 
	
		
			
				|  |  |         messageDO.setDel("1");
 | 
	
		
			
				|  |  |         messageDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         systemMessageDao.save(messageDO);
 | 
	
		
			
				|  |  |         return messageDO;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public  void test(){
 | 
	
		
			
				|  |  |         String sql="select w.* from base.wx_template_config w where w.wechat_id='xm_ykyy_wx' and w.template_name='template_evaluate_notice' and w.scene='fwqjtx' and w.status=1";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> config =  jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  | //        wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus("xm_ykyy_wx", "template_pay_notice_jz", "mzxxtx", 1)
 | 
	
		
			
				|  |  |         System.out.println("!");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void updateMessage(WlyyDoorServiceOrderDO doorServiceOrder,String[] type,String toType,String sender,String receiver){
 | 
	
		
			
				|  |  |         String orderId=doorServiceOrder.getId();
 | 
	
		
			
				|  |  |         List<SystemMessageDO> messages = systemMessageDao.queryByRelationCodeAndTypeIn(orderId,type);
 | 
	
		
			
				|  |  |         if (toType.equals("434")){//医生接单
 | 
	
		
			
				|  |  |             if (CollectionUtils.isEmpty(messages)){
 | 
	
		
			
				|  |  |                 logger.error("当前工单没有医生待接单消息!orderId:" + orderId);
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 messages.forEach(message->{
 | 
	
		
			
				|  |  |                     systemMessageDao.orderMessageDel(message.getReceiver(),message.getRelationCode());
 | 
	
		
			
				|  |  |                     if (message.getType().equals("403") ) {
 | 
	
		
			
				|  |  |                         BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doorServiceOrder.getDispatcher());//·
 | 
	
		
			
				|  |  |                         String msg=doorServiceOrder.getDispatcherName() + "接受了服务工单"+ doorServiceOrder.getNumber();
 | 
	
		
			
				|  |  |                         saveSystemMessage(message.getId(),message.getRelationCode(),"医生接单","434",doorServiceOrder.getDoctor(),doorServiceOrder.getDoctorName(),
 | 
	
		
			
				|  |  |                                 doorServiceOrder.getDispatcher(),doorServiceOrder.getDispatcherName(),null,msg,message.getOver());
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     else{
 | 
	
		
			
				|  |  |                         message.setOver("0");
 | 
	
		
			
				|  |  |                         systemMessageDao.save(message);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 });
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (toType.equals("435")) {//医生拒单
 | 
	
		
			
				|  |  |             if (CollectionUtils.isEmpty(messages)) {
 | 
	
		
			
				|  |  |                 logger.error("当前工单没有医生待接单消息!orderId:" + orderId);
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 SystemMessageDO message = messages.get(0);
 | 
	
		
			
				|  |  |                 BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doorServiceOrder.getDispatcher());
 | 
	
		
			
				|  |  |                 String msg=doorServiceOrder.getDoctorName() + "拒绝了服务工单" + doorServiceOrder.getNumber() + ", 请重新派单";
 | 
	
		
			
				|  |  |                 saveSystemMessage(message.getId(),message.getRelationCode(),"医生拒单","435",doorServiceOrder.getDoctor(),doorServiceOrder.getDoctorName(),
 | 
	
		
			
				|  |  |                         doorServiceOrder.getDispatcher(),doorServiceOrder.getDispatcherName(),null,msg,message.getOver());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (toType.equals("431")) {//调度员派单(派给本社区医生)
 | 
	
		
			
				|  |  |             if(CollectionUtils.isEmpty(messages)){
 | 
	
		
			
				|  |  |                 logger.error("当前工单没有 居民新增预约 消息!!orderId:" + orderId);
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 // 设置消息处理完毕
 | 
	
		
			
				|  |  |                 messages.forEach(
 | 
	
		
			
				|  |  |                         message -> {
 | 
	
		
			
				|  |  |                             String title = "调度员派单(派给本社区医生)";
 | 
	
		
			
				|  |  |                             if("system".equals(doorServiceOrder.getUpdateUser())){
 | 
	
		
			
				|  |  |                                 title = "系统派单(派给服务医生)";
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                             if (message.getType() .equals("430")) {
 | 
	
		
			
				|  |  |                                 message.setTitle(title);
 | 
	
		
			
				|  |  |                                 String msg = doorServiceOrder.getDispatcherName() + "已将服务工单" + doorServiceOrder.getNumber() + "指派给" + doorServiceOrder.getDoctorName() + "医生";
 | 
	
		
			
				|  |  |                                 saveSystemMessage(message.getId(),message.getRelationCode(),title,"431",doorServiceOrder.getUpdateUser(),doorServiceOrder.getUpdateUserName(),
 | 
	
		
			
				|  |  |                                         doorServiceOrder.getUpdateUser(),doorServiceOrder.getUpdateUserName(),null,msg,message.getOver());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                             }else{
 | 
	
		
			
				|  |  |                                 message.setOver("0");
 | 
	
		
			
				|  |  |                                 systemMessageDao.save(message);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                 );
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (toType.equals("432")){//调度员拒单
 | 
	
		
			
				|  |  |             if(CollectionUtils.isEmpty(messages)){
 | 
	
		
			
				|  |  |                 logger.error("当前工单没有系统消息!!orderId:" + orderId);
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 // 432 调度员拒单即取消工单-- 李四拒绝了张三的服务工单12345678
 | 
	
		
			
				|  |  |                 messages.forEach(
 | 
	
		
			
				|  |  |                         message -> {
 | 
	
		
			
				|  |  |                             if (message.getType() .equals("430")) {
 | 
	
		
			
				|  |  |                                 String msg=doorServiceOrder.getDispatcherName() + "拒绝了"+ doorServiceOrder.getPatientName() +"的服务工单" + doorServiceOrder.getNumber();
 | 
	
		
			
				|  |  |                                 saveSystemMessage(message.getId(),message.getRelationCode(),"调度员拒单","432",doorServiceOrder.getDispatcher(),doorServiceOrder.getDispatcherName(),
 | 
	
		
			
				|  |  |                                         doorServiceOrder.getDispatcher(),doorServiceOrder.getDispatcherName(),null,msg,message.getOver());
 | 
	
		
			
				|  |  |                             }else{
 | 
	
		
			
				|  |  |                                 message.setOver("0");
 | 
	
		
			
				|  |  |                                 systemMessageDao.save(message);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                 );
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (toType.equals("patientCancel")){//居民取消 消息列表也应该不显示
 | 
	
		
			
				|  |  |             if(CollectionUtils.isEmpty(messages)){
 | 
	
		
			
				|  |  |                 logger.error("当前工单没有系统消息!!orderId:" + orderId);
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 messages.forEach(
 | 
	
		
			
				|  |  |                         message -> {
 | 
	
		
			
				|  |  |                             message.setOver("0");
 | 
	
		
			
				|  |  |                             systemMessageDao.save(message);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                 );
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public static void main(String[] args){
 |