perf:调整消息发送接口和方法
This commit is contained in:
@@ -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