mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-05-11 02:17:56 +08:00
消息通知功能
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.mdd.common.plugin.notice;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.common.entity.notice.NoticeSetting;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.notice.NoticeSettingMapper;
|
||||
import com.mdd.common.plugin.notice.engine.MpNotice;
|
||||
import com.mdd.common.plugin.notice.engine.OaNotice;
|
||||
import com.mdd.common.plugin.notice.engine.SmsNotice;
|
||||
import com.mdd.common.utils.SpringUtil;
|
||||
import com.mdd.common.utils.StringUtil;
|
||||
import com.mdd.common.utils.ToolsUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
public class NoticeDriver {
|
||||
|
||||
public void handle(Map<String, Object> params) {
|
||||
// 获取通知场景
|
||||
if (StringUtil.isNull(params.get("scene"))) {
|
||||
throw new OperateException("scene参数缺失!");
|
||||
}
|
||||
|
||||
// 获取场景模板
|
||||
NoticeSettingMapper noticeSettingMapper = SpringUtil.getBean(NoticeSettingMapper.class);
|
||||
NoticeSetting noticeSetting = noticeSettingMapper.selectOne(
|
||||
new QueryWrapper<NoticeSetting>()
|
||||
.eq("scene", Integer.parseInt(params.get("scene").toString()))
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtil.isNull(noticeSetting)) {
|
||||
throw new OperateException("消息场景不存在!");
|
||||
}
|
||||
|
||||
// 短信通知
|
||||
Map<String, String> smsTemplate = ToolsUtil.jsonToMap(noticeSetting.getSmsNotice());
|
||||
if (StringUtil.isNotEmpty(smsTemplate.get("status")) && Integer.parseInt(smsTemplate.get("status")) == 1) {
|
||||
(new SmsNotice()).send(params, smsTemplate);
|
||||
}
|
||||
|
||||
// 公众号订阅通知
|
||||
// Map<String, String> oaTemplate = ToolsUtil.jsonToMap(noticeSetting.getOaNotice());
|
||||
// if (StringUtil.isNotEmpty(oaTemplate.get("status")) && Integer.parseInt(oaTemplate.get("status")) == 1) {
|
||||
// (new OaNotice()).send(params, oaTemplate);
|
||||
// }
|
||||
//
|
||||
// // 小程序订阅通知
|
||||
// Map<String, String> mnpTemplate = ToolsUtil.jsonToMap(noticeSetting.getMnpNotice());
|
||||
// if (StringUtil.isNotEmpty(mnpTemplate.get("status")) && Integer.parseInt(mnpTemplate.get("status")) == 1) {
|
||||
// (new MpNotice()).send(params, mnpTemplate);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.mdd.common.plugin.notice.engine;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MpNotice {
|
||||
|
||||
public void send(Map<String, String> params, Map<String, String> smsTemplate) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.mdd.common.plugin.notice.engine;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class OaNotice {
|
||||
|
||||
public void send(Map<String, String> params, Map<String, String> smsTemplate) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.mdd.common.plugin.notice.engine;
|
||||
|
||||
import com.mdd.common.plugin.sms.SmsDriver;
|
||||
import com.mdd.common.utils.ConfigUtil;
|
||||
import com.mdd.common.utils.StringUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class SmsNotice {
|
||||
|
||||
public Boolean send(Map<String, Object> params, Map<String, String> smsTemplate) {
|
||||
String mobile = params.getOrDefault("mobile", "").toString();
|
||||
String scene = params.getOrDefault("scene", "").toString();
|
||||
if (!StringUtil.isNotEmpty(mobile) || !StringUtil.isNotEmpty(scene)) {
|
||||
return false;
|
||||
}
|
||||
// System.out.println(this.getContent(params, smsTemplate));
|
||||
// 发送短信
|
||||
// (new SmsDriver())
|
||||
// .setMobile(mobile)
|
||||
// .setTemplateCode(smsTemplate.getOrDefault("templateId", ""))
|
||||
// .setTemplateParam(null)
|
||||
// .setSmsContent(this.getContent(params, smsTemplate));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取短信内容
|
||||
*
|
||||
* @author fzr
|
||||
* @param params 短信参数
|
||||
* @param smsTemplate 短信模板
|
||||
* @return String 短信内容
|
||||
*/
|
||||
private String getContent(Map<String, String> params, Map<String, String> smsTemplate) {
|
||||
String content = smsTemplate.getOrDefault("content", "");
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
String searchReplace = "\\$\\{" + entry.getKey() + "}";
|
||||
content = content.replaceAll(searchReplace, entry.getValue());
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 腾讯云参数处理
|
||||
*
|
||||
* @author fzr
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
private Map<String, String> getSmsParams(Map<String, String> params) {
|
||||
String engine = ConfigUtil.get("sms", "default", "");
|
||||
if (!engine.equals("tencent")) {
|
||||
return params;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user