|
@ -1,6 +1,8 @@
|
|
|
package com.yihu.wlyy.task;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.es.entity.AssistantMsgPushLog;
|
|
|
import com.yihu.wlyy.config.es.ElastricSearchSave;
|
|
|
import com.yihu.wlyy.entity.wechat.WechatTemplate;
|
|
|
import com.yihu.wlyy.entity.wechat.WechatTemplateData;
|
|
|
import com.yihu.wlyy.util.HttpUtil;
|
|
@ -15,6 +17,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
@ -64,6 +67,12 @@ public class PushMsgTask {
|
|
|
private String putMesType;
|
|
|
@Autowired
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
@Autowired
|
|
|
private ElastricSearchSave elastricSearchSave;
|
|
|
@Value("${es.type.AssistantMsgPushLog}")
|
|
|
private String esType;
|
|
|
@Value("${es.index.AssistantMsgPushLog}")
|
|
|
private String esIndex;
|
|
|
|
|
|
|
|
|
/**
|
|
@ -118,6 +127,8 @@ public class PushMsgTask {
|
|
|
mes.put("title", putMesType);
|
|
|
mes.put("value", json.toString());
|
|
|
redisTemplate.opsForList().leftPush(redisQueue, mes.toString());
|
|
|
saveAssistantMsgPushLog(access_token,1,type+"",openid,
|
|
|
url,data.toString(),null,null,null,null);
|
|
|
} else {
|
|
|
queue.put(json);
|
|
|
}
|
|
@ -187,6 +198,8 @@ public class PushMsgTask {
|
|
|
String url = json.has("url") ? json.getString("url") : "";
|
|
|
// 发送消息到微信端
|
|
|
sendWeixinMessage(access_token, type, openid, url, data);
|
|
|
saveAssistantMsgPushLog(access_token,1,type+"",openid,
|
|
|
url,data.toString(),null,null,null,null);
|
|
|
} else {
|
|
|
// 推送平台消息
|
|
|
String receiver = json.has("receiver") ? json.getString("receiver") : "";
|
|
@ -197,8 +210,12 @@ public class PushMsgTask {
|
|
|
boolean res = httpUtil.pushMessage(receiver, type, title, msg, data);
|
|
|
if (res) {
|
|
|
logger.info("消息推送成功!");
|
|
|
saveAssistantMsgPushLog(null,2,type,null,
|
|
|
null,data,receiver,title,msg,1);
|
|
|
} else {
|
|
|
logger.error("消息推送失败!");
|
|
|
saveAssistantMsgPushLog(null,2,type,null,
|
|
|
null,data,receiver,title,msg,-1);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception ex) {
|
|
@ -359,4 +376,35 @@ public class PushMsgTask {
|
|
|
return templateId;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 推送记录保存到ES
|
|
|
* @param accessToken 微信AccessToken(微信平台)
|
|
|
* @param pushPlatform 推送的平台 1、微信平台,2、平台消息
|
|
|
* @param type 消息类型
|
|
|
* @param openid 微信的openid
|
|
|
* @param url 微信跳转url
|
|
|
* @param data 数据(微信平台、平台消息)
|
|
|
* @param receiver 接受人(平台消息)
|
|
|
* @param title 标题(平台消息)
|
|
|
* @param msg 消息(平台消息)
|
|
|
* @param success 是否推送成功(1、成功,-1、失败)
|
|
|
*/
|
|
|
public void saveAssistantMsgPushLog(String accessToken,Integer pushPlatform,String type,String openid,
|
|
|
String url,String data,String receiver,String title,String msg,Integer success){
|
|
|
|
|
|
AssistantMsgPushLog assistantMsgPushLog = new AssistantMsgPushLog();
|
|
|
assistantMsgPushLog.setAccessToken(accessToken);
|
|
|
assistantMsgPushLog.setCreateTime(new Date());
|
|
|
assistantMsgPushLog.setPushPlatform(pushPlatform);
|
|
|
assistantMsgPushLog.setType(type);
|
|
|
assistantMsgPushLog.setOpenid(openid);
|
|
|
assistantMsgPushLog.setUrl(url);
|
|
|
assistantMsgPushLog.setData(data);
|
|
|
assistantMsgPushLog.setReceiver(receiver);
|
|
|
assistantMsgPushLog.setTitle(title);
|
|
|
assistantMsgPushLog.setMsg(msg);
|
|
|
assistantMsgPushLog.setSuccess(success);
|
|
|
elastricSearchSave.save(assistantMsgPushLog, esIndex, esType);
|
|
|
}
|
|
|
|
|
|
}
|