perf:调整消息发送接口和方法
This commit is contained in:
@@ -2,7 +2,6 @@ package com.tiesheng.demo.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
@@ -17,15 +16,14 @@ import com.tiesheng.database.config.DbBackupConfig;
|
||||
import com.tiesheng.demo.pojos.PoiBean;
|
||||
import com.tiesheng.demo.pojos.TestFile;
|
||||
import com.tiesheng.login.config.token.TsTokenConfig;
|
||||
import com.tiesheng.login.config.token.bean.TokenBean;
|
||||
import com.tiesheng.message.pojos.MessageReqResp;
|
||||
import com.tiesheng.message.pojos.UserChannel;
|
||||
import com.tiesheng.util.config.EncryptConfig;
|
||||
import com.tiesheng.util.config.GlobalConfig;
|
||||
import com.tiesheng.util.config.Ip2regionConfig;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import com.tiesheng.util.pojos.FileUploadPath;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -67,7 +65,7 @@ public class TestController {
|
||||
@TokenIgnore
|
||||
public void redirect(HttpServletResponse response) {
|
||||
|
||||
ArrayList<String> strings = CollUtil.newArrayList("11111","22222");
|
||||
ArrayList<String> strings = CollUtil.newArrayList("11111", "22222");
|
||||
coreLogService.addProcess("fdfd", strings, new ProcessImportConsumer<String>() {
|
||||
@Override
|
||||
public int accept(List<String> list) {
|
||||
@@ -94,8 +92,8 @@ public class TestController {
|
||||
@TokenIgnore
|
||||
public ApiResp<MessageReqResp> sendMessage() {
|
||||
|
||||
MessageReqResp reqResp = coreMessageService.send("13567116463", "SMS_154950909",
|
||||
JSONUtil.createObj().putOpt("code", "123456"), "sms");
|
||||
MessageReqResp reqResp = coreMessageService.send(new UserChannel("13567116463", "sms"),
|
||||
JSONUtil.createObj().putOpt("code", "123456").putOpt("template_code", "SMS_154950909"));
|
||||
|
||||
return ApiResp.respOK(reqResp);
|
||||
}
|
||||
|
||||
@@ -138,8 +138,8 @@ public class AliyunSmsSender implements TieshengMessageSender {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageReqResp send(String user, String title, JSONObject body) {
|
||||
return sendSms(user, title, (JSONObject) body);
|
||||
public MessageReqResp send(String user, JSONObject body) {
|
||||
return sendSms(user, body.getStr("template_code"), body);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,6 @@ public class MessageReqResp {
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
|
||||
/**
|
||||
* 提示的异常信息
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.tiesheng.message.pojos;
|
||||
|
||||
public class UserChannel {
|
||||
|
||||
private String user;
|
||||
private String channel;
|
||||
|
||||
public UserChannel(String user, String channel) {
|
||||
this.user = user;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void setChannel(String channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public interface TieshengMessageSender {
|
||||
* @param channel 消息通道,如果为空表示所有通道
|
||||
* @return 返回的内容,如果为空表示发送成功
|
||||
*/
|
||||
MessageReqResp send(String user, String title, JSONObject body);
|
||||
MessageReqResp send(String user, JSONObject body);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@ import cn.hutool.json.JSONObject;
|
||||
import com.tiesheng.core.mapper.CoreLogMessageMapper;
|
||||
import com.tiesheng.core.pojos.dao.CoreLogMessage;
|
||||
import com.tiesheng.message.pojos.MessageReqResp;
|
||||
import com.tiesheng.message.pojos.UserChannel;
|
||||
import com.tiesheng.message.service.TieshengMessageSender;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -30,42 +31,42 @@ public class CoreMessageService {
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param user
|
||||
* @param title
|
||||
* @param body
|
||||
* @param channels 消息通道,如果为all时,表示发送全部通道
|
||||
*/
|
||||
public void multiple(String user, String title, JSONObject body, String... channels) {
|
||||
if (StrUtil.isEmpty(user) || ArrayUtil.isEmpty(channels)) {
|
||||
public void multiple(List<UserChannel> channels, JSONObject body) {
|
||||
if (ArrayUtil.isEmpty(channels)) {
|
||||
return;
|
||||
}
|
||||
|
||||
messageSenderList.forEach(sender -> {
|
||||
boolean isChannel = ArrayUtil.contains(channels, sender.getChannel()) || ArrayUtil.contains(channels, "all");
|
||||
if (sender.support() && isChannel) {
|
||||
MessageReqResp reqResp = sender.send(user, title, body);
|
||||
coreLogMessageMapper.insert(BeanUtil.copyProperties(reqResp, CoreLogMessage.class));
|
||||
}
|
||||
});
|
||||
messageSenderList.stream().filter(TieshengMessageSender::support)
|
||||
.forEach(sender -> {
|
||||
channels.stream().filter(it -> Objects.equals(it.getChannel(), sender.getChannel())).forEach(it -> {
|
||||
MessageReqResp reqResp = sender.send(it.getUser(), body);
|
||||
coreLogMessageMapper.insert(BeanUtil.copyProperties(reqResp, CoreLogMessage.class));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param user
|
||||
* @param userChannel
|
||||
* @param title
|
||||
* @param body
|
||||
*/
|
||||
public MessageReqResp send(String user, String title, JSONObject body, String channel) {
|
||||
if (StrUtil.isEmpty(user) || StrUtil.isEmpty(channel)) {
|
||||
public MessageReqResp send(UserChannel userChannel, JSONObject body) {
|
||||
|
||||
if (StrUtil.isEmpty(userChannel.getUser()) || StrUtil.isEmpty(userChannel.getChannel())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TieshengMessageSender messageSender = CollUtil.findOne(messageSenderList,
|
||||
sender -> Objects.equals(sender.getChannel(), channel) && sender.support());
|
||||
sender -> Objects.equals(sender.getChannel(), userChannel.getChannel()) && sender.support());
|
||||
if (messageSender != null) {
|
||||
MessageReqResp reqResp = messageSender.send(user, title, body);
|
||||
MessageReqResp reqResp = messageSender.send(userChannel.getUser(), body);
|
||||
coreLogMessageMapper.insert(BeanUtil.copyProperties(reqResp, CoreLogMessage.class));
|
||||
return reqResp;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user