diff --git a/im-platform/src/main/java/com/bx/implatform/controller/third/ThirdPrivateMsgController.java b/im-platform/src/main/java/com/bx/implatform/controller/third/ThirdPrivateMsgController.java index e3db810..893977c 100644 --- a/im-platform/src/main/java/com/bx/implatform/controller/third/ThirdPrivateMsgController.java +++ b/im-platform/src/main/java/com/bx/implatform/controller/third/ThirdPrivateMsgController.java @@ -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 sendMessage(@Valid @RequestBody ThirdPrivateMessageSendDTO vo) { + return ResultUtils.success(thirdPrivateMsgService.sendMessage(vo)); + } + @PostMapping("/page") @Operation(summary = "查询私聊消息列表", description = "查询私聊消息列表") public Result> page(@Valid @RequestBody ThirdPrivateMessageDTO dto) { diff --git a/im-platform/src/main/java/com/bx/implatform/dto/third/privatemsg/ThirdPrivateMessageSendDTO.java b/im-platform/src/main/java/com/bx/implatform/dto/third/privatemsg/ThirdPrivateMessageSendDTO.java new file mode 100644 index 0000000..7a93086 --- /dev/null +++ b/im-platform/src/main/java/com/bx/implatform/dto/third/privatemsg/ThirdPrivateMessageSendDTO.java @@ -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; + +} diff --git a/im-platform/src/main/java/com/bx/implatform/service/third/ThirdPrivateMsgService.java b/im-platform/src/main/java/com/bx/implatform/service/third/ThirdPrivateMsgService.java index d5d5bdb..00580d6 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/third/ThirdPrivateMsgService.java +++ b/im-platform/src/main/java/com/bx/implatform/service/third/ThirdPrivateMsgService.java @@ -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); + /** * 查询私聊消息列表 */ diff --git a/im-platform/src/main/java/com/bx/implatform/service/third/impl/ThirdPrivateMsgServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/third/impl/ThirdPrivateMsgServiceImpl.java index e1a1c89..e28c2e8 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/third/impl/ThirdPrivateMsgServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/third/impl/ThirdPrivateMsgServiceImpl.java @@ -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 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; + } + /** * 查询私聊消息列表 */