feat:发送消息限制
This commit is contained in:
1 parent
7a7dc73ce8
commit
41aea55ec3
4 files changed
+105
No files matched your search
+8
@@ -3,9 +3,11 @@ package com.bx.implatform.controller.third;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageCountDTO;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageDTO;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageInfoDTO;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageSendDTO;
|
||||
import com.bx.implatform.result.Result;
|
||||
import com.bx.implatform.result.ResultUtils;
|
||||
import com.bx.implatform.service.third.ThirdPrivateMsgService;
|
||||
import com.bx.implatform.vo.PrivateMessageVO;
|
||||
import com.bx.implatform.vo.third.ThirdTableVO;
|
||||
import com.bx.implatform.vo.third.privatemsg.ThirdPrivateMessageVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -30,6 +32,12 @@ public class ThirdPrivateMsgController {
|
||||
|
||||
private final ThirdPrivateMsgService thirdPrivateMsgService;
|
||||
|
||||
@PostMapping("/send")
|
||||
@Operation(summary = "发送私聊消息", description = "发送私聊消息")
|
||||
public Result<PrivateMessageVO> sendMessage(@Valid @RequestBody ThirdPrivateMessageSendDTO vo) {
|
||||
return ResultUtils.success(thirdPrivateMsgService.sendMessage(vo));
|
||||
}
|
||||
|
||||
@PostMapping("/page")
|
||||
@Operation(summary = "查询私聊消息列表", description = "查询私聊消息列表")
|
||||
public Result<ThirdTableVO<ThirdPrivateMessageVO>> page(@Valid @RequestBody ThirdPrivateMessageDTO dto) {
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.bx.implatform.dto.third.privatemsg;
|
||||
|
||||
import com.bx.imcommon.enums.IMTerminalType;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
@Data
|
||||
@Schema(description = "私聊消息DTO")
|
||||
public class ThirdPrivateMessageSendDTO {
|
||||
|
||||
@NotNull(message = "发送用户id不能为空")
|
||||
@Schema(description = "发送用户id")
|
||||
private Long sendId;
|
||||
|
||||
/**
|
||||
* @see IMTerminalType
|
||||
*/
|
||||
@NotNull(message = "发送终端类型不可为空")
|
||||
@Schema(description = "发送终端类型")
|
||||
private Integer terminal;
|
||||
|
||||
@Schema(description = "临时id")
|
||||
private String tmpId;
|
||||
|
||||
@NotNull(message = "接收用户id不可为空")
|
||||
@Schema(description = "接收用户id")
|
||||
private Long recvId;
|
||||
|
||||
@Length(max = 1024, message = "内容长度不得大于1024")
|
||||
@NotEmpty(message = "发送内容不可为空")
|
||||
@Schema(description = "发送内容")
|
||||
private String content;
|
||||
|
||||
@NotNull(message = "消息类型不可为空")
|
||||
@Schema(description = "消息类型 0:文字 1:图片 2:文件 3:语音 4:视频")
|
||||
private Integer type;
|
||||
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package com.bx.implatform.service.third;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageCountDTO;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageDTO;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageInfoDTO;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageSendDTO;
|
||||
import com.bx.implatform.vo.PrivateMessageVO;
|
||||
import com.bx.implatform.vo.third.ThirdTableVO;
|
||||
import com.bx.implatform.vo.third.privatemsg.ThirdPrivateMessageVO;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -12,6 +14,11 @@ import java.util.Map;
|
||||
|
||||
public interface ThirdPrivateMsgService {
|
||||
|
||||
/**
|
||||
* 发送私聊消息
|
||||
*/
|
||||
PrivateMessageVO sendMessage(@Valid ThirdPrivateMessageSendDTO vo);
|
||||
|
||||
/**
|
||||
* 查询私聊消息列表
|
||||
*/
|
||||
|
||||
+49
@@ -9,14 +9,27 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bx.imclient.IMClient;
|
||||
import com.bx.imcommon.model.IMPrivateMessage;
|
||||
import com.bx.imcommon.model.IMUserInfo;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageCountDTO;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageDTO;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageInfoDTO;
|
||||
import com.bx.implatform.dto.third.privatemsg.ThirdPrivateMessageSendDTO;
|
||||
import com.bx.implatform.entity.PrivateMessage;
|
||||
import com.bx.implatform.entity.User;
|
||||
import com.bx.implatform.enums.MessageStatus;
|
||||
import com.bx.implatform.enums.MessageType;
|
||||
import com.bx.implatform.exception.GlobalException;
|
||||
import com.bx.implatform.mapper.PrivateMessageMapper;
|
||||
import com.bx.implatform.mapper.UserMapper;
|
||||
import com.bx.implatform.service.FriendService;
|
||||
import com.bx.implatform.service.third.ThirdPrivateMsgService;
|
||||
import com.bx.implatform.session.SessionContext;
|
||||
import com.bx.implatform.session.UserSession;
|
||||
import com.bx.implatform.util.BeanUtils;
|
||||
import com.bx.implatform.util.SensitiveFilterUtil;
|
||||
import com.bx.implatform.vo.PrivateMessageVO;
|
||||
import com.bx.implatform.vo.third.ThirdTableVO;
|
||||
import com.bx.implatform.vo.third.privatemsg.ThirdPrivateMessageVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -35,6 +48,42 @@ public class ThirdPrivateMsgServiceImpl extends ServiceImpl<PrivateMessageMapper
|
||||
|
||||
private final UserMapper userMapper;
|
||||
|
||||
private final IMClient imClient;
|
||||
private final FriendService friendService;
|
||||
private final SensitiveFilterUtil sensitiveFilterUtil;
|
||||
|
||||
/**
|
||||
* 发送私聊消息
|
||||
*/
|
||||
@Override
|
||||
public PrivateMessageVO sendMessage(ThirdPrivateMessageSendDTO dto) {
|
||||
Boolean isFriends = friendService.isFriend(dto.getSendId(), dto.getRecvId());
|
||||
if (Boolean.FALSE.equals(isFriends)) {
|
||||
throw new GlobalException("您已不是对方好友,无法发送消息");
|
||||
}
|
||||
// 保存消息
|
||||
PrivateMessage msg = BeanUtils.copyProperties(dto, PrivateMessage.class);
|
||||
msg.setSendId(dto.getSendId());
|
||||
msg.setStatus(MessageStatus.PENDING.code());
|
||||
msg.setSendTime(new Date());
|
||||
// 过滤内容中的敏感词
|
||||
if (MessageType.TEXT.code().equals(dto.getType())) {
|
||||
msg.setContent(sensitiveFilterUtil.filter(dto.getContent()));
|
||||
}
|
||||
this.save(msg);
|
||||
// 推送消息
|
||||
PrivateMessageVO msgInfo = BeanUtils.copyProperties(msg, PrivateMessageVO.class);
|
||||
IMPrivateMessage<PrivateMessageVO> sendMessage = new IMPrivateMessage<>();
|
||||
sendMessage.setSender(new IMUserInfo(dto.getSendId(), dto.getTerminal()));
|
||||
sendMessage.setRecvId(msgInfo.getRecvId());
|
||||
sendMessage.setSendToSelf(true);
|
||||
sendMessage.setData(msgInfo);
|
||||
sendMessage.setSendResult(true);
|
||||
imClient.sendPrivateMessage(sendMessage);
|
||||
log.info("发送私聊消息,发送id:{},接收id:{},内容:{}", dto.getSendId(), dto.getRecvId(), dto.getContent());
|
||||
return msgInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询私聊消息列表
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user