This commit is contained in:
Jason 2022-09-06 14:17:27 +08:00
commit 7c666c7bd6
10 changed files with 105 additions and 69 deletions

View File

@ -34,7 +34,7 @@ public class DecoratePageServiceImpl implements IDecoratePageService {
Map<String, Object> map = new LinkedHashMap<>(); Map<String, Object> map = new LinkedHashMap<>();
map.put("id", decoratePage.getId()); map.put("id", decoratePage.getId());
map.put("pageType", decoratePage.getPageType()); map.put("pageType", decoratePage.getPageType());
map.put("pageData", ToolsUtil.jsonToMap(decoratePage.getPageData())); map.put("pageData", decoratePage.getPageData());
return map; return map;
} }
@ -49,7 +49,7 @@ public class DecoratePageServiceImpl implements IDecoratePageService {
DecoratePage decoratePage = decoratePageMapper.selectById(decoratePageParam.getId()); DecoratePage decoratePage = decoratePageMapper.selectById(decoratePageParam.getId());
Assert.notNull(decoratePage, "数据不存在!"); Assert.notNull(decoratePage, "数据不存在!");
decoratePage.setPageData(JSON.toJSONString(decoratePageParam.getPageData())); decoratePage.setPageData(decoratePageParam.getPageData());
decoratePage.setUpdateTime(System.currentTimeMillis() / 1000); decoratePage.setUpdateTime(System.currentTimeMillis() / 1000);
decoratePageMapper.updateById(decoratePage); decoratePageMapper.updateById(decoratePage);
} }

View File

@ -15,6 +15,6 @@ public class DecoratePageParam {
private Integer id; private Integer id;
@NotNull(message = "pageData参数缺失") @NotNull(message = "pageData参数缺失")
private Object pageData; private String pageData;
} }

View File

@ -14,6 +14,18 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>like-common</artifactId> <artifactId>like-common</artifactId>
<name>like-common</name> <name>like-common</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<!-- 依赖管理 --> <!-- 依赖管理 -->
<dependencies> <dependencies>

View File

@ -1,32 +1,23 @@
package com.mdd.common.plugin.notice; package com.mdd.common.plugin.notice;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.reflect.TypeToken;
import com.mdd.common.entity.notice.NoticeSetting; import com.mdd.common.entity.notice.NoticeSetting;
import com.mdd.common.exception.OperateException; import com.mdd.common.exception.OperateException;
import com.mdd.common.mapper.notice.NoticeSettingMapper; import com.mdd.common.mapper.notice.NoticeSettingMapper;
import com.mdd.common.plugin.notice.engine.MpNotice; import com.mdd.common.plugin.notice.engine.MpNotice;
import com.mdd.common.plugin.notice.engine.OaNotice; import com.mdd.common.plugin.notice.engine.OaNotice;
import com.mdd.common.plugin.notice.engine.SmsNotice; import com.mdd.common.plugin.notice.engine.SmsNotice;
import com.mdd.common.utils.ArrayUtil;
import com.mdd.common.utils.SpringUtil; import com.mdd.common.utils.SpringUtil;
import com.mdd.common.utils.StringUtil; import com.mdd.common.utils.StringUtil;
import com.mdd.common.utils.ToolsUtil; import com.mdd.common.utils.ToolsUtil;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map; import java.util.Map;
public class NoticeDriver { public class NoticeDriver {
public void handle(Map<String, Object> params) { public void handle(Map<String, String> config, Map<String, String> params) {
// 获取通知场景 // 获取通知场景
if (StringUtil.isNull(params.get("scene"))) { if (StringUtil.isNull(config.get("scene"))) {
throw new OperateException("scene参数缺失!"); throw new OperateException("scene参数缺失!");
} }
@ -34,7 +25,7 @@ public class NoticeDriver {
NoticeSettingMapper noticeSettingMapper = SpringUtil.getBean(NoticeSettingMapper.class); NoticeSettingMapper noticeSettingMapper = SpringUtil.getBean(NoticeSettingMapper.class);
NoticeSetting noticeSetting = noticeSettingMapper.selectOne( NoticeSetting noticeSetting = noticeSettingMapper.selectOne(
new QueryWrapper<NoticeSetting>() new QueryWrapper<NoticeSetting>()
.eq("scene", Integer.parseInt(params.get("scene").toString())) .eq("scene", Integer.parseInt(config.get("scene")))
.eq("is_delete", 0) .eq("is_delete", 0)
.last("limit 1")); .last("limit 1"));
@ -45,20 +36,21 @@ public class NoticeDriver {
// 短信通知 // 短信通知
Map<String, String> smsTemplate = ToolsUtil.jsonToMap(noticeSetting.getSmsNotice()); Map<String, String> smsTemplate = ToolsUtil.jsonToMap(noticeSetting.getSmsNotice());
if (StringUtil.isNotEmpty(smsTemplate.get("status")) && Integer.parseInt(smsTemplate.get("status")) == 1) { if (StringUtil.isNotEmpty(smsTemplate.get("status")) && Integer.parseInt(smsTemplate.get("status")) == 1) {
(new SmsNotice()).send(params, smsTemplate); (new SmsNotice()).send(config, params, smsTemplate);
}
// 小程序订阅通知
Map<String, String> mnpTemplate = ToolsUtil.jsonToMap(noticeSetting.getMnpNotice());
if (StringUtil.isNotEmpty(mnpTemplate.get("status")) && Integer.parseInt(mnpTemplate.get("status")) == 1) {
(new MpNotice()).send(config, params, mnpTemplate);
} }
// 公众号订阅通知 // 公众号订阅通知
// Map<String, String> oaTemplate = ToolsUtil.jsonToMap(noticeSetting.getOaNotice()); // Map<String, String> oaTemplate = ToolsUtil.jsonToMap(noticeSetting.getOaNotice());
// if (StringUtil.isNotEmpty(oaTemplate.get("status")) && Integer.parseInt(oaTemplate.get("status")) == 1) { // if (StringUtil.isNotEmpty(oaTemplate.get("status")) && Integer.parseInt(oaTemplate.get("status")) == 1) {
// (new OaNotice()).send(params, oaTemplate); // (new OaNotice()).send(config, 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);
// } // }
} }
} }

View File

@ -4,7 +4,7 @@ import java.util.Map;
public class MpNotice { public class MpNotice {
public void send(Map<String, String> params, Map<String, String> smsTemplate) { public void send(Map<String, String> config, Map<String, String> params, Map<String, String> smsTemplate) {
} }

View File

@ -4,7 +4,7 @@ import java.util.Map;
public class OaNotice { public class OaNotice {
public void send(Map<String, String> params, Map<String, String> smsTemplate) { public void send(Map<String, String> config, Map<String, String> params, Map<String, String> smsTemplate) {
} }

View File

@ -1,35 +1,32 @@
package com.mdd.common.plugin.notice.engine; package com.mdd.common.plugin.notice.engine;
import com.alibaba.fastjson.JSON;
import com.mdd.common.plugin.sms.SmsDriver; import com.mdd.common.plugin.sms.SmsDriver;
import com.mdd.common.utils.ConfigUtil; import com.mdd.common.utils.ConfigUtil;
import com.mdd.common.utils.StringUtil; import com.mdd.common.utils.StringUtil;
import com.mdd.common.utils.ToolsUtil;
import java.util.Map; import java.util.*;
public class SmsNotice { 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)) { * @author fzr
return false; * @param config 基础配置
* @param params 短信参数
* @param smsTemplate 短信模板
*/
public void send(Map<String, String> config, Map<String, String> params, Map<String, String> smsTemplate) {
String mobile = config.getOrDefault("mobile", "");
String scene = config.getOrDefault("scene", "");
if (StringUtil.isNotEmpty(mobile) && StringUtil.isNotEmpty(scene)) {
(new SmsDriver())
.setMobile(mobile)
.setTemplateCode(smsTemplate.getOrDefault("templateId", ""))
.setTemplateParam(this.getSmsParams(params, smsTemplate))
.setSmsContent(this.getContent(params, smsTemplate))
.sendSms();
} }
// if (StringUtil.isNotNull(params.get("params"))) {
// ToolsUtil.objectToMap(params.get("params"));
// }
// System.out.println(this.getContent(params, smsTemplate));
// 发送短信
// (new SmsDriver())
// .setMobile(mobile)
// .setTemplateCode(smsTemplate.getOrDefault("templateId", ""))
// .setTemplateParam(null)
// .setSmsContent(this.getContent(params, smsTemplate));
return true;
} }
/** /**
@ -56,12 +53,49 @@ public class SmsNotice {
* @author fzr * @author fzr
* @return Map<String, String> * @return Map<String, String>
*/ */
private Map<String, String> getSmsParams(Map<String, String> params) { private Map<String, String> getSmsParams(Map<String, String> params, Map<String, String> smsTemplate) {
String engine = ConfigUtil.get("sms", "default", ""); String engine = ConfigUtil.get("sms", "default", "");
if (!engine.equals("tencent")) { if (!engine.equals("tencent")) {
return params; return params;
} }
return null;
// 获取内容变量
List<String> arr = new LinkedList<>();
String content = smsTemplate.getOrDefault("content", "");
for (Map.Entry<String, String> entry : params.entrySet()) {
String search = "\\$\\{" + entry.getKey() + "}";
if (content.indexOf(search) != 1 && !arr.contains(entry.getKey())) {
arr.add(entry.getKey());
}
}
// 获取变量名称
List<Integer> arrIndex = new LinkedList<>();
Map<Integer, String> arr2 = new LinkedHashMap<>();
if (arr.size() > 0) {
for (String v: arr) {
int k = content.indexOf(v);
arrIndex.add(k);
arr2.put(k, v);
}
}
// 从小到大排序
List<String> arr3 = new LinkedList<>();
Collections.sort(arrIndex);
for (Integer i : arrIndex) {
arr3.add(arr2.get(i));
}
// 取变量对应值
Map<String, String> arr4 = new LinkedHashMap<>();
for (String v : arr3) {
if (StringUtil.isNotNull(params.get(v))) {
arr4.put(params.get(v), "");
}
}
return arr4;
} }
} }

View File

@ -106,15 +106,10 @@ public class SmsDriver {
sendResult = aliSms.getSendResult(); sendResult = aliSms.getSendResult();
break; break;
case "tencent": case "tencent":
List<String> params = new LinkedList<>();
for (Map.Entry<String, String> MapString : this.templateParam.entrySet()) {
params.add(MapString.getValue());
}
TencentSms tencentSms = new TencentSms(this.config); TencentSms tencentSms = new TencentSms(this.config);
results = tencentSms.setMobile(this.mobile) results = tencentSms.setMobile(this.mobile)
.setTemplateId(this.templateCode) .setTemplateId(this.templateCode)
.setTemplateParams(params.toArray(new String[0])) .setTemplateParams(this.templateParam)
.send(); .send();
sendResult = tencentSms.getSendResult(); sendResult = tencentSms.getSendResult();
break; break;

View File

@ -1,6 +1,5 @@
package com.mdd.common.plugin.sms.engine; package com.mdd.common.plugin.sms.engine;
import com.mdd.common.exception.OperateException;
import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile; import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile; import com.tencentcloudapi.common.profile.HttpProfile;
@ -8,6 +7,9 @@ import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest; import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse; import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -53,8 +55,13 @@ public class TencentSms {
* @param templateParams 模板参数 * @param templateParams 模板参数
* @return AliSms * @return AliSms
*/ */
public TencentSms setTemplateParams(String[] templateParams) { public TencentSms setTemplateParams(Map<String, String> templateParams) {
this.templateParams = templateParams; List<String> params = new LinkedList<>();
for (Map.Entry<String, String> entry : templateParams.entrySet()) {
params.add(entry.getKey());
}
this.templateParams = params.toArray(String[]::new);
return this; return this;
} }

View File

@ -29,18 +29,14 @@ public class IndexController {
*/ */
@GetMapping("/index") @GetMapping("/index")
public Object index() { public Object index() {
Map<String, Object> params = new LinkedHashMap<>(); Map<String, String> config = new LinkedHashMap<>();
params.put("scene", "101"); config.put("scene", "100");
params.put("mobile", "12323"); config.put("mobile", "1222");
params.put("params", new String[]{
"code:203",
"张三丰",
"张无忌",
"王二麻子",
"张富贵"
});
(new NoticeDriver()).handle(params); Map<String, String> params = new LinkedHashMap<>();
params.put("code", "5522");
// params.put("order_sn", "27552210565677");
(new NoticeDriver()).handle(config, params);
Map<String, Object> detail = IIndexService.index(); Map<String, Object> detail = IIndexService.index();