消息通知功能
This commit is contained in:
parent
252ff34bc5
commit
458b675ddb
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.mdd.front.controller;
|
package com.mdd.front.controller;
|
||||||
|
|
||||||
import com.mdd.common.core.AjaxResult;
|
import com.mdd.common.core.AjaxResult;
|
||||||
|
import com.mdd.common.plugin.notice.NoticeDriver;
|
||||||
import com.mdd.common.validator.annotation.IDMust;
|
import com.mdd.common.validator.annotation.IDMust;
|
||||||
import com.mdd.front.service.IIndexService;
|
import com.mdd.front.service.IIndexService;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
|
@ -27,6 +29,20 @@ public class IndexController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("/index")
|
@GetMapping("/index")
|
||||||
public Object index() {
|
public Object index() {
|
||||||
|
Map<String, Object> params = new LinkedHashMap<>();
|
||||||
|
params.put("scene", "101");
|
||||||
|
params.put("mobile", "12323");
|
||||||
|
params.put("params", new String[]{
|
||||||
|
"code:203",
|
||||||
|
"张三丰",
|
||||||
|
"张无忌",
|
||||||
|
"王二麻子",
|
||||||
|
"张富贵"
|
||||||
|
});
|
||||||
|
|
||||||
|
(new NoticeDriver()).handle(params);
|
||||||
|
|
||||||
|
|
||||||
Map<String, Object> detail = IIndexService.index();
|
Map<String, Object> detail = IIndexService.index();
|
||||||
return AjaxResult.success(detail);
|
return AjaxResult.success(detail);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue