publish 2.0.0.rc13

This commit is contained in:
曾文豪
2024-08-05 14:18:50 +08:00
parent 333d283e24
commit be08001f3f
12 changed files with 67 additions and 82 deletions

View File

@@ -14,7 +14,6 @@ import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.pojos.TokenBean;
import com.tiesheng.util.service.TsServiceBase;
import com.tiesheng.web.mapper.CoreLogLoginMapper;
import com.tiesheng.web.mapper.CoreLogMessageMapper;
import com.tiesheng.web.mapper.CoreLogOperationMapper;
import com.tiesheng.web.mapper.CoreLogProcessMapper;
import com.tiesheng.web.pojos.RequestUserInfo;

View File

@@ -1,99 +0,0 @@
package com.tiesheng.web.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.tiesheng.web.mapper.CoreLogMessageMapper;
import com.tiesheng.web.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;
import java.util.List;
import java.util.Objects;
/**
* @author hao
*/
@Service
public class CoreMessageService {
@Autowired
List<TieshengMessageSender> messageSenderList;
@Autowired
CoreLogMessageMapper coreLogMessageMapper;
/**
* 插入数据
*
* @param reqResp
*/
private void insertMessageLog(MessageReqResp reqResp) {
if (reqResp == null) {
return;
}
coreLogMessageMapper.insert(BeanUtil.copyProperties(reqResp, CoreLogMessage.class));
}
/**
* 发送所有消息
*
* @param userIds
* @param body
*/
public void all(List<String> userIds, JSONObject body) {
messageSenderList.stream().filter(TieshengMessageSender::support)
.forEach(sender -> {
for (String user : userIds) {
insertMessageLog(sender.send(user, body));
}
});
}
/**
* 发送消息
*
* @param channels
* @param body
* @param channels 消息通道如果为all时表示发送全部通道
*/
public void multiple(List<UserChannel> channels, JSONObject body) {
if (ArrayUtil.isEmpty(channels)) {
return;
}
messageSenderList.stream().filter(TieshengMessageSender::support)
.forEach(sender -> channels.stream().filter(it -> Objects.equals(it.getChannel(), sender.getChannel()))
.forEach(it -> insertMessageLog(sender.send(it.getUser(), body))));
}
/**
* 发送消息
*
* @param userChannel
* @param body
*/
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(), userChannel.getChannel()) && sender.support());
if (messageSender != null) {
MessageReqResp reqResp = messageSender.send(userChannel.getUser(), body);
insertMessageLog(reqResp);
return reqResp;
}
return null;
}
}