提交 bbac2671 编写于 作者: zhouweidong's avatar zhouweidong

钉钉、微信、阿里消息集成

上级 c2b17b89
...@@ -9,9 +9,6 @@ import java.util.Map; ...@@ -9,9 +9,6 @@ import java.util.Map;
@Data @Data
public class Msg { public class Msg {
@NotBlank(message="系统标识不能为空")
private String system;
@NotBlank(message="模板标识不能为空") @NotBlank(message="模板标识不能为空")
private String templateid; private String templateid;
......
...@@ -76,10 +76,10 @@ public class NotifyCoreService { ...@@ -76,10 +76,10 @@ public class NotifyCoreService {
* 平台消息类型代码表 * 平台消息类型代码表
*/ */
private static Map<Integer,String> msgTypes = new HashMap(){{ private static Map<Integer,String> msgTypes = new HashMap(){{
put(2,"email"); put(2,"aliyun-email");
put(4,"sms"); put(4,"aliyun-sms");
put(32,"wechat"); put(32,"wechat-msg");
put(64,"dingtalk"); put(64,"dingtalk-msg");
}}; }};
@Autowired @Autowired
...@@ -314,7 +314,7 @@ public class NotifyCoreService { ...@@ -314,7 +314,7 @@ public class NotifyCoreService {
* @return * @return
*/ */
public boolean createMsgTemplate(Template template){ public boolean createMsgTemplate(Template template){
String system=template.getSystem() ; String system=template.getSystem().toLowerCase();
JSONArray templates = template.getTemplate(); JSONArray templates = template.getTemplate();
for(int a=0;a<templates.size();a++){ for(int a=0;a<templates.size();a++){
List<MsgOpenAccess> openAccesses=new ArrayList<>(); List<MsgOpenAccess> openAccesses=new ArrayList<>();
...@@ -328,15 +328,15 @@ public class NotifyCoreService { ...@@ -328,15 +328,15 @@ public class NotifyCoreService {
openAccess.setId(system+templateType); openAccess.setId(system+templateType);
openAccess.setName(templateType); openAccess.setName(templateType);
openAccess.setDisabled(0); openAccess.setDisabled(0);
openAccess.setOpenType(templateType); openAccess.setOpenType(templateType.contains("-")?templateType.substring(0,templateType.indexOf("-")):templateType);
openAccesses.add(openAccess); openAccesses.add(openAccess);
} }
//创建消息模板 //创建消息模板
MsgTemplate msgTemplate =JSONObject.toJavaObject(templates.getJSONObject(a),MsgTemplate.class); MsgTemplate msgTemplate =JSONObject.toJavaObject(templates.getJSONObject(a),MsgTemplate.class);
msgTemplate.setAccessId(openAccess.getId()); msgTemplate.setAccessId(openAccess.getId());
msgTemplate.setOpenType(templateType); msgTemplate.setOpenType(templateType.contains("-")?templateType.substring(0,templateType.indexOf("-")):templateType);
msgTemplate.setTemplateType(templateType); msgTemplate.setTemplateType(templateType);
msgTemplate.setTid(system+msgTemplate.getTid()+templateType); msgTemplate.setTid(msgTemplate.getTid()+templateType);
msgTemplates.add(msgTemplate); msgTemplates.add(msgTemplate);
} }
if(openAccesses.size()>0) if(openAccesses.size()>0)
...@@ -353,27 +353,26 @@ public class NotifyCoreService { ...@@ -353,27 +353,26 @@ public class NotifyCoreService {
* @return * @return
*/ */
public boolean sendMsg(Msg msg){ public boolean sendMsg(Msg msg){
String system = msg.getSystem();
String templateId =msg.getTemplateid(); String templateId =msg.getTemplateid();
String userIds=msg.getUserids(); String userIds=msg.getUserids();
Map templParams=msg.getTemplparams(); Map templParams=msg.getTemplparams();
for(String msgType:getMsgType(msg.getMsgtypes())){ for(String msgType:getMsgType(msg.getMsgtypes())){
MsgTemplate msgTemplate=templateService.getById(system+templateId+msgType); MsgTemplate msgTemplate=templateService.getById(templateId+msgType);
if(msgTemplate==null){ if(msgTemplate==null){
throw new BadRequestAlertException(String.format("发送消息失败,无法获取到[%s]对应的rt模板",templateId),"",""); throw new BadRequestAlertException(String.format("发送消息失败,无法获取到[%s]对应的rt模板",templateId),"","");
} }
else{ else{
switch(msgType){ switch(msgType){
case "sms": case "aliyun-sms":
sendAliSms(msgTemplate.getTid(),userIds,templParams); sendAliSms(msgTemplate.getTid(),userIds,templParams);
break; break;
case "email": case "aliyun-email":
sendAliEMail(msgTemplate.getTid(),userIds); sendAliEMail(msgTemplate.getTid(),userIds);
break; break;
case "dingtalk": case "dingtalk-msg":
sendDingTalkMsg(msgTemplate.getTid(),userIds); sendDingTalkMsg(msgTemplate.getTid(),userIds);
break; break;
case "wechat": case "wechat-msg":
sendWeChatMsg(msgTemplate.getTid(),userIds,templParams); sendWeChatMsg(msgTemplate.getTid(),userIds,templParams);
break; break;
default: default:
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册