修改:私聊消息存库
This commit is contained in:
parent
3696b666f4
commit
2d052ea752
|
@ -60,6 +60,11 @@
|
|||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -6,11 +6,11 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.InboxPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.InboxRespVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.InboxSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.ImInboxPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.ImInboxRespVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.ImInboxSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.inbox.ImInboxDO;
|
||||
import cn.iocoder.yudao.module.im.service.inbox.InboxService;
|
||||
import cn.iocoder.yudao.module.im.service.inbox.ImInboxService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
@ -31,23 +31,23 @@ import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.E
|
|||
@RestController
|
||||
@RequestMapping("/im/inbox")
|
||||
@Validated
|
||||
public class InboxController {
|
||||
public class ImInboxController {
|
||||
|
||||
@Resource
|
||||
private InboxService inboxService;
|
||||
private ImInboxService imInboxService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建收件箱")
|
||||
@PreAuthorize("@ss.hasPermission('im:inbox:create')")
|
||||
public CommonResult<Long> createInbox(@Valid @RequestBody InboxSaveReqVO createReqVO) {
|
||||
return success(inboxService.createInbox(createReqVO));
|
||||
public CommonResult<Long> createInbox(@Valid @RequestBody ImInboxSaveReqVO createReqVO) {
|
||||
return success(imInboxService.createInbox(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新收件箱")
|
||||
@PreAuthorize("@ss.hasPermission('im:inbox:update')")
|
||||
public CommonResult<Boolean> updateInbox(@Valid @RequestBody InboxSaveReqVO updateReqVO) {
|
||||
inboxService.updateInbox(updateReqVO);
|
||||
public CommonResult<Boolean> updateInbox(@Valid @RequestBody ImInboxSaveReqVO updateReqVO) {
|
||||
imInboxService.updateInbox(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class InboxController {
|
|||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('im:inbox:delete')")
|
||||
public CommonResult<Boolean> deleteInbox(@RequestParam("id") Long id) {
|
||||
inboxService.deleteInbox(id);
|
||||
imInboxService.deleteInbox(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -64,30 +64,30 @@ public class InboxController {
|
|||
@Operation(summary = "获得收件箱")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('im:inbox:query')")
|
||||
public CommonResult<InboxRespVO> getInbox(@RequestParam("id") Long id) {
|
||||
ImInboxDO inbox = inboxService.getInbox(id);
|
||||
return success(BeanUtils.toBean(inbox, InboxRespVO.class));
|
||||
public CommonResult<ImInboxRespVO> getInbox(@RequestParam("id") Long id) {
|
||||
ImInboxDO inbox = imInboxService.getInbox(id);
|
||||
return success(BeanUtils.toBean(inbox, ImInboxRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得收件箱分页")
|
||||
@PreAuthorize("@ss.hasPermission('im:inbox:query')")
|
||||
public CommonResult<PageResult<InboxRespVO>> getInboxPage(@Valid InboxPageReqVO pageReqVO) {
|
||||
PageResult<ImInboxDO> pageResult = inboxService.getInboxPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, InboxRespVO.class));
|
||||
public CommonResult<PageResult<ImInboxRespVO>> getInboxPage(@Valid ImInboxPageReqVO pageReqVO) {
|
||||
PageResult<ImInboxDO> pageResult = imInboxService.getInboxPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, ImInboxRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出收件箱 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('im:inbox:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportInboxExcel(@Valid InboxPageReqVO pageReqVO,
|
||||
public void exportInboxExcel(@Valid ImInboxPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<ImInboxDO> list = inboxService.getInboxPage(pageReqVO).getList();
|
||||
List<ImInboxDO> list = imInboxService.getInboxPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "收件箱.xls", "数据", InboxRespVO.class,
|
||||
BeanUtils.toBean(list, InboxRespVO.class));
|
||||
ExcelUtils.write(response, "收件箱.xls", "数据", ImInboxRespVO.class,
|
||||
BeanUtils.toBean(list, ImInboxRespVO.class));
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InboxPageReqVO extends PageParam {
|
||||
public class ImInboxPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "用户编号", example = "3979")
|
||||
private Long userId;
|
|
@ -10,7 +10,7 @@ import java.time.LocalDateTime;
|
|||
@Schema(description = "管理后台 - 收件箱 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class InboxRespVO {
|
||||
public class ImInboxRespVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18389")
|
||||
@ExcelProperty("编号")
|
|
@ -2,11 +2,15 @@ package cn.iocoder.yudao.module.im.controller.admin.inbox.vo;
|
|||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Schema(description = "管理后台 - 收件箱新增/修改 Request VO")
|
||||
@Data
|
||||
public class InboxSaveReqVO {
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ImInboxSaveReqVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18389")
|
||||
private Long id;
|
||||
|
@ -23,4 +27,10 @@ public class InboxSaveReqVO {
|
|||
@NotNull(message = "序号,按照 user 递增不能为空")
|
||||
private Long sequence;
|
||||
|
||||
public ImInboxSaveReqVO(Long userId, Long messageId, Long sequence) {
|
||||
this.userId = userId;
|
||||
this.messageId = messageId;
|
||||
this.sequence = sequence;
|
||||
}
|
||||
|
||||
}
|
|
@ -90,10 +90,4 @@ public class ImMessageController {
|
|||
BeanUtils.toBean(list, ImMessageRespVO.class));
|
||||
}
|
||||
|
||||
@PostMapping("/send")
|
||||
@Operation(summary = "发送私聊消息")
|
||||
public CommonResult<Long> sendMessage(@Valid @RequestBody ImMessageSaveReqVO imMessageSaveReqVO) {
|
||||
return success(imMessageService.sendPrivateMessage(imMessageSaveReqVO));
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.im.dal.mysql.inbox;
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.InboxPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.ImInboxPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.inbox.ImInboxDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
@ -15,7 +15,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
@Mapper
|
||||
public interface InboxMapper extends BaseMapperX<ImInboxDO> {
|
||||
|
||||
default PageResult<ImInboxDO> selectPage(InboxPageReqVO reqVO) {
|
||||
default PageResult<ImInboxDO> selectPage(ImInboxPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ImInboxDO>()
|
||||
.eqIfPresent(ImInboxDO::getUserId, reqVO.getUserId())
|
||||
.eqIfPresent(ImInboxDO::getMessageId, reqVO.getMessageId())
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package cn.iocoder.yudao.module.im.dal.redis;
|
||||
|
||||
|
||||
/**
|
||||
* im Redis Key 枚举类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface RedisKeyConstants {
|
||||
|
||||
/**
|
||||
* 收件箱序号生成器
|
||||
* KEY 格式: im:inbox:sequence:{userId}
|
||||
* VALUE 数据类型: String
|
||||
*/
|
||||
String INBOX_SEQUENCE = "im_inbox_sequence:%s";
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package cn.iocoder.yudao.module.im.dal.redis.inbox;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import static cn.iocoder.yudao.module.im.dal.redis.RedisKeyConstants.INBOX_SEQUENCE;
|
||||
|
||||
/**
|
||||
* 序号生成器 Redis DAO
|
||||
*
|
||||
* @author anhaohao
|
||||
*/
|
||||
@Repository
|
||||
public class SequenceGeneratorRedisDao {
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Long> redisTemplate;
|
||||
|
||||
private static String formatKey(Long userId) {
|
||||
return String.format(INBOX_SEQUENCE, userId);
|
||||
}
|
||||
|
||||
public Long generateSequence(Long userId) {
|
||||
return redisTemplate.opsForValue().increment(formatKey(userId), 1);
|
||||
}
|
||||
|
||||
}
|
|
@ -51,4 +51,5 @@ public interface ImConversationService {
|
|||
*/
|
||||
PageResult<ImConversationDO> getConversationPage(ImConversationPageReqVO pageReqVO);
|
||||
|
||||
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package cn.iocoder.yudao.module.im.service.inbox;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.InboxPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.InboxSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.ImInboxPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.ImInboxSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.inbox.ImInboxDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
|
@ -11,7 +11,7 @@ import jakarta.validation.Valid;
|
|||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InboxService {
|
||||
public interface ImInboxService {
|
||||
|
||||
/**
|
||||
* 创建收件箱
|
||||
|
@ -19,14 +19,14 @@ public interface InboxService {
|
|||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createInbox(@Valid InboxSaveReqVO createReqVO);
|
||||
Long createInbox(@Valid ImInboxSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新收件箱
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateInbox(@Valid InboxSaveReqVO updateReqVO);
|
||||
void updateInbox(@Valid ImInboxSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除收件箱
|
||||
|
@ -49,6 +49,6 @@ public interface InboxService {
|
|||
* @param pageReqVO 分页查询
|
||||
* @return 收件箱分页
|
||||
*/
|
||||
PageResult<ImInboxDO> getInboxPage(InboxPageReqVO pageReqVO);
|
||||
PageResult<ImInboxDO> getInboxPage(ImInboxPageReqVO pageReqVO);
|
||||
|
||||
}
|
|
@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.im.service.inbox;
|
|||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.InboxPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.InboxSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.ImInboxPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.ImInboxSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.inbox.ImInboxDO;
|
||||
import cn.iocoder.yudao.module.im.dal.mysql.inbox.InboxMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -20,13 +20,13 @@ import static cn.iocoder.yudao.module.im.enums.ErrorCodeConstants.INBOX_NOT_EXIS
|
|||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class InboxServiceImpl implements InboxService {
|
||||
public class ImInboxServiceImpl implements ImInboxService {
|
||||
|
||||
@Resource
|
||||
private InboxMapper inboxMapper;
|
||||
|
||||
@Override
|
||||
public Long createInbox(InboxSaveReqVO createReqVO) {
|
||||
public Long createInbox(ImInboxSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
ImInboxDO inbox = BeanUtils.toBean(createReqVO, ImInboxDO.class);
|
||||
inboxMapper.insert(inbox);
|
||||
|
@ -35,7 +35,7 @@ public class InboxServiceImpl implements InboxService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateInbox(InboxSaveReqVO updateReqVO) {
|
||||
public void updateInbox(ImInboxSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateInboxExists(updateReqVO.getId());
|
||||
// 更新
|
||||
|
@ -63,7 +63,7 @@ public class InboxServiceImpl implements InboxService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ImInboxDO> getInboxPage(InboxPageReqVO pageReqVO) {
|
||||
public PageResult<ImInboxDO> getInboxPage(ImInboxPageReqVO pageReqVO) {
|
||||
return inboxMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||
import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessagePageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.message.ImMessageDO;
|
||||
import cn.iocoder.yudao.module.im.websocket.message.ImSendMessage;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
|
@ -51,10 +52,13 @@ public interface ImMessageService {
|
|||
*/
|
||||
PageResult<ImMessageDO> getMessagePage(ImMessagePageReqVO pageReqVO);
|
||||
|
||||
|
||||
/**
|
||||
* 发送私聊消息
|
||||
* @param imMessageSaveReqVO 消息信息
|
||||
* @return 消息编号
|
||||
* 保存私聊消息
|
||||
*
|
||||
* @param imSendMessage 消息信息
|
||||
* @param fromUserId 发送人编号
|
||||
* @return id
|
||||
*/
|
||||
Long sendPrivateMessage(ImMessageSaveReqVO imMessageSaveReqVO);
|
||||
Long savePrivateMessage(ImSendMessage imSendMessage, Long fromUserId);
|
||||
}
|
|
@ -6,6 +6,9 @@ import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessagePageReqVO
|
|||
import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.message.ImMessageDO;
|
||||
import cn.iocoder.yudao.module.im.dal.mysql.message.ImMessageMapper;
|
||||
import cn.iocoder.yudao.module.im.websocket.message.ImSendMessage;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
@ -24,6 +27,8 @@ public class ImMessageServiceImpl implements ImMessageService {
|
|||
|
||||
@Resource
|
||||
private ImMessageMapper imMessageMapper;
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
|
||||
@Override
|
||||
public Long createMessage(ImMessageSaveReqVO createReqVO) {
|
||||
|
@ -67,9 +72,24 @@ public class ImMessageServiceImpl implements ImMessageService {
|
|||
return imMessageMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Long sendPrivateMessage(ImMessageSaveReqVO imMessageSaveReqVO) {
|
||||
return 0L;
|
||||
public Long savePrivateMessage(ImSendMessage message, Long fromUserId) {
|
||||
ImMessageSaveReqVO imMessageSaveReqVO = new ImMessageSaveReqVO();
|
||||
imMessageSaveReqVO.setClientMessageId(message.getClientMessageId());
|
||||
imMessageSaveReqVO.setSenderId(fromUserId);
|
||||
imMessageSaveReqVO.setReceiverId(message.getReceiverId());
|
||||
//查询发送人昵称和发送人头像
|
||||
AdminUserRespDTO user = adminUserApi.getUser(fromUserId);
|
||||
imMessageSaveReqVO.setSenderNickname(user.getNickname());
|
||||
imMessageSaveReqVO.setSenderAvatar(user.getAvatar());
|
||||
imMessageSaveReqVO.setConversationType(message.getConversationType());
|
||||
imMessageSaveReqVO.setContentType(message.getContentType());
|
||||
imMessageSaveReqVO.setConversationNo("1");
|
||||
imMessageSaveReqVO.setContent(message.getContent());
|
||||
//消息来源 100-用户发送;200-系统发送(一般是通知);不能为空
|
||||
imMessageSaveReqVO.setSendFrom(100);
|
||||
return createMessage(imMessageSaveReqVO);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,15 +4,14 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
|||
import cn.iocoder.yudao.framework.websocket.core.listener.WebSocketMessageListener;
|
||||
import cn.iocoder.yudao.framework.websocket.core.sender.WebSocketMessageSender;
|
||||
import cn.iocoder.yudao.framework.websocket.core.util.WebSocketFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.ImInboxSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.redis.inbox.SequenceGeneratorRedisDao;
|
||||
import cn.iocoder.yudao.module.im.enums.conversation.ImConversationTypeEnum;
|
||||
import cn.iocoder.yudao.module.im.service.conversation.ImConversationService;
|
||||
import cn.iocoder.yudao.module.im.service.inbox.ImInboxService;
|
||||
import cn.iocoder.yudao.module.im.service.message.ImMessageService;
|
||||
import cn.iocoder.yudao.module.im.websocket.message.ImReceiveMessage;
|
||||
import cn.iocoder.yudao.module.im.websocket.message.ImSendMessage;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
@ -30,54 +29,23 @@ public class ImWebSocketMessageListener implements WebSocketMessageListener<ImSe
|
|||
@Resource
|
||||
private ImMessageService imMessageService;
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
@Resource
|
||||
private ImConversationService imConversationService;
|
||||
@Resource
|
||||
private ImInboxService imInboxService;
|
||||
@Resource
|
||||
private SequenceGeneratorRedisDao sequenceGeneratorRedisDao;
|
||||
|
||||
@Override
|
||||
public void onMessage(WebSocketSession session, ImSendMessage message) {
|
||||
Long fromUserId = WebSocketFrameworkUtils.getLoginUserId(session);
|
||||
//1、插入消息表
|
||||
ImMessageSaveReqVO imMessageSaveReqVO = new ImMessageSaveReqVO();
|
||||
imMessageSaveReqVO.setClientMessageId(message.getClientMessageId());
|
||||
imMessageSaveReqVO.setSenderId(fromUserId);
|
||||
imMessageSaveReqVO.setReceiverId(message.getReceiverId());
|
||||
//查询发送人昵称和发送人头像
|
||||
AdminUserRespDTO user = adminUserApi.getUser(fromUserId);
|
||||
imMessageSaveReqVO.setSenderNickname(user.getNickname());
|
||||
imMessageSaveReqVO.setSenderAvatar(user.getAvatar());
|
||||
imMessageSaveReqVO.setConversationType(message.getConversationType());
|
||||
imMessageSaveReqVO.setContentType(message.getContentType());
|
||||
imMessageSaveReqVO.setConversationNo("1");
|
||||
imMessageSaveReqVO.setContent(message.getContent());
|
||||
//消息来源 100-用户发送;200-系统发送(一般是通知);不能为空
|
||||
imMessageSaveReqVO.setSendFrom(100);
|
||||
imMessageService.createMessage(imMessageSaveReqVO);
|
||||
|
||||
Long messageId = imMessageService.savePrivateMessage(message, fromUserId);
|
||||
|
||||
// 私聊
|
||||
if (message.getConversationType().equals(ImConversationTypeEnum.PRIVATE.getType())) {
|
||||
//2、插入收件箱表(私聊:两条,群聊:每个群有一条)
|
||||
ImConversationSaveReqVO imConversationSaveReqVO = new ImConversationSaveReqVO();
|
||||
imConversationSaveReqVO.setUserId(fromUserId);
|
||||
imConversationSaveReqVO.setConversationType(message.getConversationType());
|
||||
//单聊时,用户编号;群聊时,群编号
|
||||
imConversationSaveReqVO.setTargetId(message.getReceiverId()+"");
|
||||
//会话标志 单聊:s_{userId}_{targetId},需要排序 userId 和 targetId 群聊:g_groupId
|
||||
imConversationSaveReqVO.setNo("s_" + fromUserId + "_" + message.getReceiverId());
|
||||
imConversationSaveReqVO.setPinned(false);
|
||||
imConversationService.createConversation(imConversationSaveReqVO);
|
||||
|
||||
ImConversationSaveReqVO imConversationSaveReqVO1 = new ImConversationSaveReqVO();
|
||||
imConversationSaveReqVO1.setUserId(message.getReceiverId());
|
||||
imConversationSaveReqVO1.setConversationType(message.getConversationType());
|
||||
//单聊时,用户编号;群聊时,群编号
|
||||
imConversationSaveReqVO1.setTargetId(fromUserId+"");
|
||||
//会话标志 单聊:s_{userId}_{targetId},需要排序 userId 和 targetId 群聊:g_groupId
|
||||
imConversationSaveReqVO1.setNo("s_" + message.getReceiverId() + "_" + fromUserId);
|
||||
imConversationSaveReqVO1.setPinned(false);
|
||||
imConversationService.createConversation(imConversationSaveReqVO1);
|
||||
|
||||
imInboxService.createInbox(new ImInboxSaveReqVO(message.getReceiverId(), messageId, sequenceGeneratorRedisDao.generateSequence(message.getReceiverId())));
|
||||
imInboxService.createInbox(new ImInboxSaveReqVO(fromUserId, messageId, sequenceGeneratorRedisDao.generateSequence(fromUserId)));
|
||||
|
||||
//3、推送消息
|
||||
ImReceiveMessage toMessage = new ImReceiveMessage();
|
||||
|
|
|
@ -22,15 +22,15 @@ import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
|||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* {@link InboxServiceImpl} 的单元测试类
|
||||
* {@link ImInboxServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(InboxServiceImpl.class)
|
||||
public class InboxServiceImplTest extends BaseDbUnitTest {
|
||||
@Import(ImInboxServiceImpl.class)
|
||||
public class ImInboxServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private InboxServiceImpl inboxService;
|
||||
private ImInboxServiceImpl inboxService;
|
||||
|
||||
@Resource
|
||||
private InboxMapper inboxMapper;
|
||||
|
@ -38,7 +38,7 @@ public class InboxServiceImplTest extends BaseDbUnitTest {
|
|||
@Test
|
||||
public void testCreateInbox_success() {
|
||||
// 准备参数
|
||||
InboxSaveReqVO createReqVO = randomPojo(InboxSaveReqVO.class).setId(null);
|
||||
ImInboxSaveReqVO createReqVO = randomPojo(ImInboxSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long inboxId = inboxService.createInbox(createReqVO);
|
||||
|
@ -55,7 +55,7 @@ public class InboxServiceImplTest extends BaseDbUnitTest {
|
|||
ImInboxDO dbInbox = randomPojo(ImInboxDO.class);
|
||||
inboxMapper.insert(dbInbox);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
InboxSaveReqVO updateReqVO = randomPojo(InboxSaveReqVO.class, o -> {
|
||||
ImInboxSaveReqVO updateReqVO = randomPojo(ImInboxSaveReqVO.class, o -> {
|
||||
o.setId(dbInbox.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class InboxServiceImplTest extends BaseDbUnitTest {
|
|||
@Test
|
||||
public void testUpdateInbox_notExists() {
|
||||
// 准备参数
|
||||
InboxSaveReqVO updateReqVO = randomPojo(InboxSaveReqVO.class);
|
||||
ImInboxSaveReqVO updateReqVO = randomPojo(ImInboxSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> inboxService.updateInbox(updateReqVO), INBOX_NOT_EXISTS);
|
||||
|
@ -118,7 +118,7 @@ public class InboxServiceImplTest extends BaseDbUnitTest {
|
|||
// 测试 createTime 不匹配
|
||||
inboxMapper.insert(cloneIgnoreId(dbInbox, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
InboxPageReqVO reqVO = new InboxPageReqVO();
|
||||
ImInboxPageReqVO reqVO = new ImInboxPageReqVO();
|
||||
reqVO.setUserId(null);
|
||||
reqVO.setMessageId(null);
|
||||
reqVO.setSequence(null);
|
Loading…
Reference in New Issue