修改:im 模块简单实现
This commit is contained in:
parent
bb0b7056cf
commit
3696b666f4
2
pom.xml
2
pom.xml
|
@ -15,8 +15,6 @@
|
|||
<!-- 各种 module 拓展 -->
|
||||
<module>yudao-module-system</module>
|
||||
<module>yudao-module-infra</module>
|
||||
<module>yudao-module-im</module>
|
||||
<module>yudao-module-im/yudao-module-im-api</module>
|
||||
<!-- <module>yudao-module-member</module>-->
|
||||
<!-- <module>yudao-module-bpm</module>-->
|
||||
<!-- <module>yudao-module-report</module>-->
|
||||
|
|
|
@ -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.conversation.vo.ConversationPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ConversationRespVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ConversationSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ConversationDO;
|
||||
import cn.iocoder.yudao.module.im.service.conversation.ConversationService;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationRespVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO;
|
||||
import cn.iocoder.yudao.module.im.service.conversation.ImConversationService;
|
||||
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/conversation")
|
||||
@Validated
|
||||
public class ConversationController {
|
||||
public class ImConversationController {
|
||||
|
||||
@Resource
|
||||
private ConversationService conversationService;
|
||||
private ImConversationService imConversationService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建会话")
|
||||
@PreAuthorize("@ss.hasPermission('im:conversation:create')")
|
||||
public CommonResult<Long> createConversation(@Valid @RequestBody ConversationSaveReqVO createReqVO) {
|
||||
return success(conversationService.createConversation(createReqVO));
|
||||
public CommonResult<Long> createConversation(@Valid @RequestBody ImConversationSaveReqVO createReqVO) {
|
||||
return success(imConversationService.createConversation(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新会话")
|
||||
@PreAuthorize("@ss.hasPermission('im:conversation:update')")
|
||||
public CommonResult<Boolean> updateConversation(@Valid @RequestBody ConversationSaveReqVO updateReqVO) {
|
||||
conversationService.updateConversation(updateReqVO);
|
||||
public CommonResult<Boolean> updateConversation(@Valid @RequestBody ImConversationSaveReqVO updateReqVO) {
|
||||
imConversationService.updateConversation(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class ConversationController {
|
|||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('im:conversation:delete')")
|
||||
public CommonResult<Boolean> deleteConversation(@RequestParam("id") Long id) {
|
||||
conversationService.deleteConversation(id);
|
||||
imConversationService.deleteConversation(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -64,30 +64,30 @@ public class ConversationController {
|
|||
@Operation(summary = "获得会话")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('im:conversation:query')")
|
||||
public CommonResult<ConversationRespVO> getConversation(@RequestParam("id") Long id) {
|
||||
ConversationDO conversation = conversationService.getConversation(id);
|
||||
return success(BeanUtils.toBean(conversation, ConversationRespVO.class));
|
||||
public CommonResult<ImConversationRespVO> getConversation(@RequestParam("id") Long id) {
|
||||
ImConversationDO conversation = imConversationService.getConversation(id);
|
||||
return success(BeanUtils.toBean(conversation, ImConversationRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得会话分页")
|
||||
@PreAuthorize("@ss.hasPermission('im:conversation:query')")
|
||||
public CommonResult<PageResult<ConversationRespVO>> getConversationPage(@Valid ConversationPageReqVO pageReqVO) {
|
||||
PageResult<ConversationDO> pageResult = conversationService.getConversationPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, ConversationRespVO.class));
|
||||
public CommonResult<PageResult<ImConversationRespVO>> getConversationPage(@Valid ImConversationPageReqVO pageReqVO) {
|
||||
PageResult<ImConversationDO> pageResult = imConversationService.getConversationPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, ImConversationRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出会话 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('im:conversation:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportConversationExcel(@Valid ConversationPageReqVO pageReqVO,
|
||||
public void exportConversationExcel(@Valid ImConversationPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<ConversationDO> list = conversationService.getConversationPage(pageReqVO).getList();
|
||||
List<ImConversationDO> list = imConversationService.getConversationPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "会话.xls", "数据", ConversationRespVO.class,
|
||||
BeanUtils.toBean(list, ConversationRespVO.class));
|
||||
ExcelUtils.write(response, "会话.xls", "数据", ImConversationRespVO.class,
|
||||
BeanUtils.toBean(list, ImConversationRespVO.class));
|
||||
}
|
||||
|
||||
}
|
|
@ -15,13 +15,13 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
|||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ConversationPageReqVO extends PageParam {
|
||||
public class ImConversationPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "所属用户", example = "11545")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "类型:1 单聊;2 群聊;4 通知会话(预留)", example = "1")
|
||||
private Boolean conversationType;
|
||||
private Integer conversationType;
|
||||
|
||||
@Schema(description = "单聊时,用户编号;群聊时,群编号", example = "21454")
|
||||
private String targetId;
|
|
@ -10,7 +10,7 @@ import java.time.LocalDateTime;
|
|||
@Schema(description = "管理后台 - 会话 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class ConversationRespVO {
|
||||
public class ImConversationRespVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13905")
|
||||
@ExcelProperty("编号")
|
||||
|
@ -22,7 +22,7 @@ public class ConversationRespVO {
|
|||
|
||||
@Schema(description = "类型:1 单聊;2 群聊;4 通知会话(预留)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty("类型:1 单聊;2 群聊;4 通知会话(预留)")
|
||||
private Boolean conversationType;
|
||||
private Integer conversationType;
|
||||
|
||||
@Schema(description = "单聊时,用户编号;群聊时,群编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21454")
|
||||
@ExcelProperty("单聊时,用户编号;群聊时,群编号")
|
|
@ -9,7 +9,7 @@ import java.time.LocalDateTime;
|
|||
|
||||
@Schema(description = "管理后台 - 会话新增/修改 Request VO")
|
||||
@Data
|
||||
public class ConversationSaveReqVO {
|
||||
public class ImConversationSaveReqVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13905")
|
||||
private Long id;
|
||||
|
@ -20,7 +20,7 @@ public class ConversationSaveReqVO {
|
|||
|
||||
@Schema(description = "类型:1 单聊;2 群聊;4 通知会话(预留)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "类型:1 单聊;2 群聊;4 通知会话(预留)不能为空")
|
||||
private Boolean conversationType;
|
||||
private Integer conversationType;
|
||||
|
||||
@Schema(description = "单聊时,用户编号;群聊时,群编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21454")
|
||||
@NotEmpty(message = "单聊时,用户编号;群聊时,群编号不能为空")
|
|
@ -9,7 +9,7 @@ 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.dal.dataobject.inbox.InboxDO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.inbox.ImInboxDO;
|
||||
import cn.iocoder.yudao.module.im.service.inbox.InboxService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
|
@ -65,7 +65,7 @@ public class InboxController {
|
|||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('im:inbox:query')")
|
||||
public CommonResult<InboxRespVO> getInbox(@RequestParam("id") Long id) {
|
||||
InboxDO inbox = inboxService.getInbox(id);
|
||||
ImInboxDO inbox = inboxService.getInbox(id);
|
||||
return success(BeanUtils.toBean(inbox, InboxRespVO.class));
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ public class InboxController {
|
|||
@Operation(summary = "获得收件箱分页")
|
||||
@PreAuthorize("@ss.hasPermission('im:inbox:query')")
|
||||
public CommonResult<PageResult<InboxRespVO>> getInboxPage(@Valid InboxPageReqVO pageReqVO) {
|
||||
PageResult<InboxDO> pageResult = inboxService.getInboxPage(pageReqVO);
|
||||
PageResult<ImInboxDO> pageResult = inboxService.getInboxPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, InboxRespVO.class));
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class InboxController {
|
|||
public void exportInboxExcel(@Valid InboxPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<InboxDO> list = inboxService.getInboxPage(pageReqVO).getList();
|
||||
List<ImInboxDO> list = inboxService.getInboxPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "收件箱.xls", "数据", InboxRespVO.class,
|
||||
BeanUtils.toBean(list, InboxRespVO.class));
|
||||
|
|
|
@ -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.message.vo.MessagePageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.message.vo.MessageRespVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.message.vo.MessageSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.message.MessageDO;
|
||||
import cn.iocoder.yudao.module.im.service.message.MessageService;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessagePageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageRespVO;
|
||||
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.service.message.ImMessageService;
|
||||
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/message")
|
||||
@Validated
|
||||
public class MessageController {
|
||||
public class ImMessageController {
|
||||
|
||||
@Resource
|
||||
private MessageService messageService;
|
||||
private ImMessageService imMessageService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建消息")
|
||||
@PreAuthorize("@ss.hasPermission('im:message:create')")
|
||||
public CommonResult<Long> createMessage(@Valid @RequestBody MessageSaveReqVO createReqVO) {
|
||||
return success(messageService.createMessage(createReqVO));
|
||||
public CommonResult<Long> createMessage(@Valid @RequestBody ImMessageSaveReqVO createReqVO) {
|
||||
return success(imMessageService.createMessage(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新消息")
|
||||
@PreAuthorize("@ss.hasPermission('im:message:update')")
|
||||
public CommonResult<Boolean> updateMessage(@Valid @RequestBody MessageSaveReqVO updateReqVO) {
|
||||
messageService.updateMessage(updateReqVO);
|
||||
public CommonResult<Boolean> updateMessage(@Valid @RequestBody ImMessageSaveReqVO updateReqVO) {
|
||||
imMessageService.updateMessage(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class MessageController {
|
|||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('im:message:delete')")
|
||||
public CommonResult<Boolean> deleteMessage(@RequestParam("id") Long id) {
|
||||
messageService.deleteMessage(id);
|
||||
imMessageService.deleteMessage(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -64,36 +64,36 @@ public class MessageController {
|
|||
@Operation(summary = "获得消息")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('im:message:query')")
|
||||
public CommonResult<MessageRespVO> getMessage(@RequestParam("id") Long id) {
|
||||
MessageDO message = messageService.getMessage(id);
|
||||
return success(BeanUtils.toBean(message, MessageRespVO.class));
|
||||
public CommonResult<ImMessageRespVO> getMessage(@RequestParam("id") Long id) {
|
||||
ImMessageDO message = imMessageService.getMessage(id);
|
||||
return success(BeanUtils.toBean(message, ImMessageRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得消息分页")
|
||||
@PreAuthorize("@ss.hasPermission('im:message:query')")
|
||||
public CommonResult<PageResult<MessageRespVO>> getMessagePage(@Valid MessagePageReqVO pageReqVO) {
|
||||
PageResult<MessageDO> pageResult = messageService.getMessagePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, MessageRespVO.class));
|
||||
public CommonResult<PageResult<ImMessageRespVO>> getMessagePage(@Valid ImMessagePageReqVO pageReqVO) {
|
||||
PageResult<ImMessageDO> pageResult = imMessageService.getMessagePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, ImMessageRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出消息 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('im:message:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportMessageExcel(@Valid MessagePageReqVO pageReqVO,
|
||||
public void exportMessageExcel(@Valid ImMessagePageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<MessageDO> list = messageService.getMessagePage(pageReqVO).getList();
|
||||
List<ImMessageDO> list = imMessageService.getMessagePage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "消息.xls", "数据", MessageRespVO.class,
|
||||
BeanUtils.toBean(list, MessageRespVO.class));
|
||||
ExcelUtils.write(response, "消息.xls", "数据", ImMessageRespVO.class,
|
||||
BeanUtils.toBean(list, ImMessageRespVO.class));
|
||||
}
|
||||
|
||||
@PostMapping("/send")
|
||||
@Operation(summary = "发送私聊消息")
|
||||
public CommonResult<Long> sendMessage(@Valid @RequestBody MessageSaveReqVO messageSaveReqVO) {
|
||||
return success(messageService.sendPrivateMessage(messageSaveReqVO));
|
||||
public CommonResult<Long> sendMessage(@Valid @RequestBody ImMessageSaveReqVO imMessageSaveReqVO) {
|
||||
return success(imMessageService.sendPrivateMessage(imMessageSaveReqVO));
|
||||
}
|
||||
|
||||
}
|
|
@ -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 MessagePageReqVO extends PageParam {
|
||||
public class ImMessagePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "客户端消息编号 uuid,用于排重", example = "3331")
|
||||
private String clientMessageId;
|
||||
|
@ -33,13 +33,13 @@ public class MessagePageReqVO extends PageParam {
|
|||
private String senderAvatar;
|
||||
|
||||
@Schema(description = "会话类型", example = "2")
|
||||
private Boolean conversationType;
|
||||
private Integer conversationType;
|
||||
|
||||
@Schema(description = "会话标志")
|
||||
private String conversationNo;
|
||||
|
||||
@Schema(description = "消息类型", example = "1")
|
||||
private Boolean contentType;
|
||||
private Integer contentType;
|
||||
|
||||
@Schema(description = "消息内容")
|
||||
private String content;
|
||||
|
@ -49,7 +49,7 @@ public class MessagePageReqVO extends PageParam {
|
|||
private LocalDateTime[] sendTime;
|
||||
|
||||
@Schema(description = "消息来源 100-用户发送;200-系统发送(一般是通知);")
|
||||
private Boolean sendFrom;
|
||||
private Integer sendFrom;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
|
@ -10,7 +10,7 @@ import java.time.LocalDateTime;
|
|||
@Schema(description = "管理后台 - 消息 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class MessageRespVO {
|
||||
public class ImMessageRespVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "30713")
|
||||
@ExcelProperty("编号")
|
||||
|
@ -38,7 +38,7 @@ public class MessageRespVO {
|
|||
|
||||
@Schema(description = "会话类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("会话类型")
|
||||
private Boolean conversationType;
|
||||
private Integer conversationType;
|
||||
|
||||
@Schema(description = "会话标志", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("会话标志")
|
||||
|
@ -46,7 +46,7 @@ public class MessageRespVO {
|
|||
|
||||
@Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty("消息类型")
|
||||
private Boolean contentType;
|
||||
private Integer contentType;
|
||||
|
||||
@Schema(description = "消息内容", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("消息内容")
|
||||
|
@ -58,7 +58,7 @@ public class MessageRespVO {
|
|||
|
||||
@Schema(description = "消息来源 100-用户发送;200-系统发送(一般是通知);", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("消息来源 100-用户发送;200-系统发送(一般是通知);")
|
||||
private Boolean sendFrom;
|
||||
private Integer sendFrom;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
|
@ -9,7 +9,7 @@ import java.time.LocalDateTime;
|
|||
|
||||
@Schema(description = "管理后台 - 消息新增/修改 Request VO")
|
||||
@Data
|
||||
public class MessageSaveReqVO {
|
||||
public class ImMessageSaveReqVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "30713")
|
||||
private Long id;
|
||||
|
@ -36,7 +36,7 @@ public class MessageSaveReqVO {
|
|||
|
||||
@Schema(description = "会话类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "会话类型不能为空")
|
||||
private Boolean conversationType;
|
||||
private Integer conversationType;
|
||||
|
||||
@Schema(description = "会话标志", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "会话标志不能为空")
|
||||
|
@ -44,18 +44,17 @@ public class MessageSaveReqVO {
|
|||
|
||||
@Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "消息类型不能为空")
|
||||
private Boolean contentType;
|
||||
private Integer contentType;
|
||||
|
||||
@Schema(description = "消息内容", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "消息内容不能为空")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "发送时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "发送时间不能为空")
|
||||
private LocalDateTime sendTime;
|
||||
|
||||
@Schema(description = "消息来源 100-用户发送;200-系统发送(一般是通知);", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "消息来源 100-用户发送;200-系统发送(一般是通知);不能为空")
|
||||
private Boolean sendFrom;
|
||||
private Integer sendFrom;
|
||||
|
||||
}
|
|
@ -21,7 +21,7 @@ import java.time.LocalDateTime;
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ConversationDO extends BaseDO {
|
||||
public class ImConversationDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
|
@ -35,7 +35,7 @@ public class ConversationDO extends BaseDO {
|
|||
/**
|
||||
* 类型:1 单聊;2 群聊;4 通知会话(预留)
|
||||
*/
|
||||
private Boolean conversationType;
|
||||
private Integer conversationType;
|
||||
/**
|
||||
* 单聊时,用户编号;群聊时,群编号
|
||||
*/
|
|
@ -19,7 +19,7 @@ import lombok.*;
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class InboxDO extends BaseDO {
|
||||
public class ImInboxDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
|
@ -21,7 +21,7 @@ import java.time.LocalDateTime;
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MessageDO extends BaseDO {
|
||||
public class ImMessageDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
|
@ -51,7 +51,7 @@ public class MessageDO extends BaseDO {
|
|||
/**
|
||||
* 会话类型
|
||||
*/
|
||||
private Boolean conversationType;
|
||||
private Integer conversationType;
|
||||
/**
|
||||
* 会话标志
|
||||
*/
|
||||
|
@ -59,7 +59,7 @@ public class MessageDO extends BaseDO {
|
|||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
private Boolean contentType;
|
||||
private Integer contentType;
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
|
@ -71,6 +71,6 @@ public class MessageDO extends BaseDO {
|
|||
/**
|
||||
* 消息来源 100-用户发送;200-系统发送(一般是通知);
|
||||
*/
|
||||
private Boolean sendFrom;
|
||||
private Integer sendFrom;
|
||||
|
||||
}
|
|
@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.im.dal.mysql.conversation;
|
|||
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.conversation.vo.ConversationPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ConversationDO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
|
@ -13,18 +13,18 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ConversationMapper extends BaseMapperX<ConversationDO> {
|
||||
public interface ConversationMapper extends BaseMapperX<ImConversationDO> {
|
||||
|
||||
default PageResult<ConversationDO> selectPage(ConversationPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ConversationDO>()
|
||||
.eqIfPresent(ConversationDO::getUserId, reqVO.getUserId())
|
||||
.eqIfPresent(ConversationDO::getConversationType, reqVO.getConversationType())
|
||||
.eqIfPresent(ConversationDO::getTargetId, reqVO.getTargetId())
|
||||
.eqIfPresent(ConversationDO::getNo, reqVO.getNo())
|
||||
.eqIfPresent(ConversationDO::getPinned, reqVO.getPinned())
|
||||
.betweenIfPresent(ConversationDO::getLastReadTime, reqVO.getLastReadTime())
|
||||
.betweenIfPresent(ConversationDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(ConversationDO::getId));
|
||||
default PageResult<ImConversationDO> selectPage(ImConversationPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ImConversationDO>()
|
||||
.eqIfPresent(ImConversationDO::getUserId, reqVO.getUserId())
|
||||
.eqIfPresent(ImConversationDO::getConversationType, reqVO.getConversationType())
|
||||
.eqIfPresent(ImConversationDO::getTargetId, reqVO.getTargetId())
|
||||
.eqIfPresent(ImConversationDO::getNo, reqVO.getNo())
|
||||
.eqIfPresent(ImConversationDO::getPinned, reqVO.getPinned())
|
||||
.betweenIfPresent(ImConversationDO::getLastReadTime, reqVO.getLastReadTime())
|
||||
.betweenIfPresent(ImConversationDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(ImConversationDO::getId));
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@ 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.dal.dataobject.inbox.InboxDO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.inbox.ImInboxDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
|
@ -13,15 +13,15 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InboxMapper extends BaseMapperX<InboxDO> {
|
||||
public interface InboxMapper extends BaseMapperX<ImInboxDO> {
|
||||
|
||||
default PageResult<InboxDO> selectPage(InboxPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<InboxDO>()
|
||||
.eqIfPresent(InboxDO::getUserId, reqVO.getUserId())
|
||||
.eqIfPresent(InboxDO::getMessageId, reqVO.getMessageId())
|
||||
.eqIfPresent(InboxDO::getSequence, reqVO.getSequence())
|
||||
.betweenIfPresent(InboxDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(InboxDO::getId));
|
||||
default PageResult<ImInboxDO> selectPage(InboxPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ImInboxDO>()
|
||||
.eqIfPresent(ImInboxDO::getUserId, reqVO.getUserId())
|
||||
.eqIfPresent(ImInboxDO::getMessageId, reqVO.getMessageId())
|
||||
.eqIfPresent(ImInboxDO::getSequence, reqVO.getSequence())
|
||||
.betweenIfPresent(ImInboxDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(ImInboxDO::getId));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package cn.iocoder.yudao.module.im.dal.mysql.message;
|
||||
|
||||
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.message.vo.ImMessagePageReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.message.ImMessageDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 消息 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ImMessageMapper extends BaseMapperX<ImMessageDO> {
|
||||
|
||||
default PageResult<ImMessageDO> selectPage(ImMessagePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ImMessageDO>()
|
||||
.eqIfPresent(ImMessageDO::getClientMessageId, reqVO.getClientMessageId())
|
||||
.eqIfPresent(ImMessageDO::getSenderId, reqVO.getSenderId())
|
||||
.eqIfPresent(ImMessageDO::getReceiverId, reqVO.getReceiverId())
|
||||
.likeIfPresent(ImMessageDO::getSenderNickname, reqVO.getSenderNickname())
|
||||
.eqIfPresent(ImMessageDO::getSenderAvatar, reqVO.getSenderAvatar())
|
||||
.eqIfPresent(ImMessageDO::getConversationType, reqVO.getConversationType())
|
||||
.eqIfPresent(ImMessageDO::getConversationNo, reqVO.getConversationNo())
|
||||
.eqIfPresent(ImMessageDO::getContentType, reqVO.getContentType())
|
||||
.eqIfPresent(ImMessageDO::getContent, reqVO.getContent())
|
||||
.betweenIfPresent(ImMessageDO::getSendTime, reqVO.getSendTime())
|
||||
.eqIfPresent(ImMessageDO::getSendFrom, reqVO.getSendFrom())
|
||||
.betweenIfPresent(ImMessageDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(ImMessageDO::getId));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package cn.iocoder.yudao.module.im.dal.mysql.message;
|
||||
|
||||
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.message.vo.MessagePageReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.message.MessageDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 消息 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface MessageMapper extends BaseMapperX<MessageDO> {
|
||||
|
||||
default PageResult<MessageDO> selectPage(MessagePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<MessageDO>()
|
||||
.eqIfPresent(MessageDO::getClientMessageId, reqVO.getClientMessageId())
|
||||
.eqIfPresent(MessageDO::getSenderId, reqVO.getSenderId())
|
||||
.eqIfPresent(MessageDO::getReceiverId, reqVO.getReceiverId())
|
||||
.likeIfPresent(MessageDO::getSenderNickname, reqVO.getSenderNickname())
|
||||
.eqIfPresent(MessageDO::getSenderAvatar, reqVO.getSenderAvatar())
|
||||
.eqIfPresent(MessageDO::getConversationType, reqVO.getConversationType())
|
||||
.eqIfPresent(MessageDO::getConversationNo, reqVO.getConversationNo())
|
||||
.eqIfPresent(MessageDO::getContentType, reqVO.getContentType())
|
||||
.eqIfPresent(MessageDO::getContent, reqVO.getContent())
|
||||
.betweenIfPresent(MessageDO::getSendTime, reqVO.getSendTime())
|
||||
.eqIfPresent(MessageDO::getSendFrom, reqVO.getSendFrom())
|
||||
.betweenIfPresent(MessageDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(MessageDO::getId));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package cn.iocoder.yudao.module.im.service.conversation;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ConversationPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ConversationSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ConversationDO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@ import jakarta.validation.Valid;
|
|||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface ConversationService {
|
||||
public interface ImConversationService {
|
||||
|
||||
/**
|
||||
* 创建会话
|
||||
|
@ -19,14 +19,14 @@ public interface ConversationService {
|
|||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createConversation(@Valid ConversationSaveReqVO createReqVO);
|
||||
Long createConversation(@Valid ImConversationSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新会话
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateConversation(@Valid ConversationSaveReqVO updateReqVO);
|
||||
void updateConversation(@Valid ImConversationSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除会话
|
||||
|
@ -41,7 +41,7 @@ public interface ConversationService {
|
|||
* @param id 编号
|
||||
* @return 会话
|
||||
*/
|
||||
ConversationDO getConversation(Long id);
|
||||
ImConversationDO getConversation(Long id);
|
||||
|
||||
/**
|
||||
* 获得会话分页
|
||||
|
@ -49,6 +49,6 @@ public interface ConversationService {
|
|||
* @param pageReqVO 分页查询
|
||||
* @return 会话分页
|
||||
*/
|
||||
PageResult<ConversationDO> getConversationPage(ConversationPageReqVO pageReqVO);
|
||||
PageResult<ImConversationDO> getConversationPage(ImConversationPageReqVO pageReqVO);
|
||||
|
||||
}
|
|
@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.im.service.conversation;
|
|||
|
||||
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.conversation.vo.ConversationPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ConversationSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ConversationDO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationPageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO;
|
||||
import cn.iocoder.yudao.module.im.dal.mysql.conversation.ConversationMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -20,26 +20,26 @@ import static cn.iocoder.yudao.module.im.enums.ErrorCodeConstants.CONVERSATION_N
|
|||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ConversationServiceImpl implements ConversationService {
|
||||
public class ImConversationServiceImpl implements ImConversationService {
|
||||
|
||||
@Resource
|
||||
private ConversationMapper conversationMapper;
|
||||
|
||||
@Override
|
||||
public Long createConversation(ConversationSaveReqVO createReqVO) {
|
||||
public Long createConversation(ImConversationSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
ConversationDO conversation = BeanUtils.toBean(createReqVO, ConversationDO.class);
|
||||
ImConversationDO conversation = BeanUtils.toBean(createReqVO, ImConversationDO.class);
|
||||
conversationMapper.insert(conversation);
|
||||
// 返回
|
||||
return conversation.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConversation(ConversationSaveReqVO updateReqVO) {
|
||||
public void updateConversation(ImConversationSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateConversationExists(updateReqVO.getId());
|
||||
// 更新
|
||||
ConversationDO updateObj = BeanUtils.toBean(updateReqVO, ConversationDO.class);
|
||||
ImConversationDO updateObj = BeanUtils.toBean(updateReqVO, ImConversationDO.class);
|
||||
conversationMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
|
@ -58,12 +58,12 @@ public class ConversationServiceImpl implements ConversationService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ConversationDO getConversation(Long id) {
|
||||
public ImConversationDO getConversation(Long id) {
|
||||
return conversationMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ConversationDO> getConversationPage(ConversationPageReqVO pageReqVO) {
|
||||
public PageResult<ImConversationDO> getConversationPage(ImConversationPageReqVO pageReqVO) {
|
||||
return conversationMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ 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.dal.dataobject.inbox.InboxDO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.inbox.ImInboxDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ public interface InboxService {
|
|||
* @param id 编号
|
||||
* @return 收件箱
|
||||
*/
|
||||
InboxDO getInbox(Long id);
|
||||
ImInboxDO getInbox(Long id);
|
||||
|
||||
/**
|
||||
* 获得收件箱分页
|
||||
|
@ -49,6 +49,6 @@ public interface InboxService {
|
|||
* @param pageReqVO 分页查询
|
||||
* @return 收件箱分页
|
||||
*/
|
||||
PageResult<InboxDO> getInboxPage(InboxPageReqVO pageReqVO);
|
||||
PageResult<ImInboxDO> getInboxPage(InboxPageReqVO pageReqVO);
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@ 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.dal.dataobject.inbox.InboxDO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.inbox.ImInboxDO;
|
||||
import cn.iocoder.yudao.module.im.dal.mysql.inbox.InboxMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -28,7 +28,7 @@ public class InboxServiceImpl implements InboxService {
|
|||
@Override
|
||||
public Long createInbox(InboxSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
InboxDO inbox = BeanUtils.toBean(createReqVO, InboxDO.class);
|
||||
ImInboxDO inbox = BeanUtils.toBean(createReqVO, ImInboxDO.class);
|
||||
inboxMapper.insert(inbox);
|
||||
// 返回
|
||||
return inbox.getId();
|
||||
|
@ -39,7 +39,7 @@ public class InboxServiceImpl implements InboxService {
|
|||
// 校验存在
|
||||
validateInboxExists(updateReqVO.getId());
|
||||
// 更新
|
||||
InboxDO updateObj = BeanUtils.toBean(updateReqVO, InboxDO.class);
|
||||
ImInboxDO updateObj = BeanUtils.toBean(updateReqVO, ImInboxDO.class);
|
||||
inboxMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
|
@ -58,12 +58,12 @@ public class InboxServiceImpl implements InboxService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InboxDO getInbox(Long id) {
|
||||
public ImInboxDO getInbox(Long id) {
|
||||
return inboxMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<InboxDO> getInboxPage(InboxPageReqVO pageReqVO) {
|
||||
public PageResult<ImInboxDO> getInboxPage(InboxPageReqVO pageReqVO) {
|
||||
return inboxMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package cn.iocoder.yudao.module.im.service.message;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.message.vo.MessagePageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.message.vo.MessageSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.message.MessageDO;
|
||||
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 jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@ import jakarta.validation.Valid;
|
|||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface MessageService {
|
||||
public interface ImMessageService {
|
||||
|
||||
/**
|
||||
* 创建消息
|
||||
|
@ -19,14 +19,14 @@ public interface MessageService {
|
|||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createMessage(@Valid MessageSaveReqVO createReqVO);
|
||||
Long createMessage(@Valid ImMessageSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新消息
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateMessage(@Valid MessageSaveReqVO updateReqVO);
|
||||
void updateMessage(@Valid ImMessageSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除消息
|
||||
|
@ -41,7 +41,7 @@ public interface MessageService {
|
|||
* @param id 编号
|
||||
* @return 消息
|
||||
*/
|
||||
MessageDO getMessage(Long id);
|
||||
ImMessageDO getMessage(Long id);
|
||||
|
||||
/**
|
||||
* 获得消息分页
|
||||
|
@ -49,12 +49,12 @@ public interface MessageService {
|
|||
* @param pageReqVO 分页查询
|
||||
* @return 消息分页
|
||||
*/
|
||||
PageResult<MessageDO> getMessagePage(MessagePageReqVO pageReqVO);
|
||||
PageResult<ImMessageDO> getMessagePage(ImMessagePageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 发送私聊消息
|
||||
* @param messageSaveReqVO 消息信息
|
||||
* @param imMessageSaveReqVO 消息信息
|
||||
* @return 消息编号
|
||||
*/
|
||||
Long sendPrivateMessage(MessageSaveReqVO messageSaveReqVO);
|
||||
Long sendPrivateMessage(ImMessageSaveReqVO imMessageSaveReqVO);
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package cn.iocoder.yudao.module.im.service.message;
|
||||
|
||||
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.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 jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.im.enums.ErrorCodeConstants.MESSAGE_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 消息 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ImMessageServiceImpl implements ImMessageService {
|
||||
|
||||
@Resource
|
||||
private ImMessageMapper imMessageMapper;
|
||||
|
||||
@Override
|
||||
public Long createMessage(ImMessageSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
ImMessageDO message = BeanUtils.toBean(createReqVO, ImMessageDO.class);
|
||||
imMessageMapper.insert(message);
|
||||
// 返回
|
||||
return message.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMessage(ImMessageSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateMessageExists(updateReqVO.getId());
|
||||
// 更新
|
||||
ImMessageDO updateObj = BeanUtils.toBean(updateReqVO, ImMessageDO.class);
|
||||
imMessageMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMessage(Long id) {
|
||||
// 校验存在
|
||||
validateMessageExists(id);
|
||||
// 删除
|
||||
imMessageMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateMessageExists(Long id) {
|
||||
if (imMessageMapper.selectById(id) == null) {
|
||||
throw exception(MESSAGE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImMessageDO getMessage(Long id) {
|
||||
return imMessageMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ImMessageDO> getMessagePage(ImMessagePageReqVO pageReqVO) {
|
||||
return imMessageMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sendPrivateMessage(ImMessageSaveReqVO imMessageSaveReqVO) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package cn.iocoder.yudao.module.im.service.message;
|
||||
|
||||
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.message.vo.MessagePageReqVO;
|
||||
import cn.iocoder.yudao.module.im.controller.admin.message.vo.MessageSaveReqVO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.message.MessageDO;
|
||||
import cn.iocoder.yudao.module.im.dal.mysql.message.MessageMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.im.enums.ErrorCodeConstants.MESSAGE_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 消息 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class MessageServiceImpl implements MessageService {
|
||||
|
||||
@Resource
|
||||
private MessageMapper messageMapper;
|
||||
|
||||
@Override
|
||||
public Long createMessage(MessageSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
MessageDO message = BeanUtils.toBean(createReqVO, MessageDO.class);
|
||||
messageMapper.insert(message);
|
||||
// 返回
|
||||
return message.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMessage(MessageSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateMessageExists(updateReqVO.getId());
|
||||
// 更新
|
||||
MessageDO updateObj = BeanUtils.toBean(updateReqVO, MessageDO.class);
|
||||
messageMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMessage(Long id) {
|
||||
// 校验存在
|
||||
validateMessageExists(id);
|
||||
// 删除
|
||||
messageMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateMessageExists(Long id) {
|
||||
if (messageMapper.selectById(id) == null) {
|
||||
throw exception(MESSAGE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageDO getMessage(Long id) {
|
||||
return messageMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<MessageDO> getMessagePage(MessagePageReqVO pageReqVO) {
|
||||
return messageMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sendPrivateMessage(MessageSaveReqVO messageSaveReqVO) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
}
|
|
@ -4,9 +4,15 @@ 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.enums.conversation.ImConversationTypeEnum;
|
||||
import cn.iocoder.yudao.module.im.service.conversation.ImConversationService;
|
||||
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;
|
||||
|
@ -21,19 +27,65 @@ public class ImWebSocketMessageListener implements WebSocketMessageListener<ImSe
|
|||
|
||||
@Resource
|
||||
private WebSocketMessageSender webSocketMessageSender;
|
||||
@Resource
|
||||
private ImMessageService imMessageService;
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
@Resource
|
||||
private ImConversationService imConversationService;
|
||||
|
||||
@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);
|
||||
|
||||
|
||||
// 私聊
|
||||
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);
|
||||
|
||||
|
||||
//3、推送消息
|
||||
ImReceiveMessage toMessage = new ImReceiveMessage();
|
||||
toMessage.setToId(fromUserId);
|
||||
toMessage.setFromId(fromUserId);
|
||||
toMessage.setConversationType(ImConversationTypeEnum.PRIVATE.getType());
|
||||
//消息类型
|
||||
toMessage.setType(message.getType());
|
||||
toMessage.setBody(message.getBody());
|
||||
webSocketMessageSender.sendObject(UserTypeEnum.ADMIN.getValue(), message.getToId(), // 给指定用户
|
||||
toMessage.setContentType(message.getContentType());
|
||||
toMessage.setContent(message.getContent());
|
||||
webSocketMessageSender.sendObject(UserTypeEnum.ADMIN.getValue(), message.getReceiverId(), // 给指定用户
|
||||
"im-message-receive", toMessage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,20 +4,20 @@ import cn.iocoder.yudao.module.im.dal.dataobject.message.body.ImMessageBody;
|
|||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 消息发送 send")
|
||||
@Schema(description = "管理后台 - 消息发送 receive")
|
||||
@Data
|
||||
public class ImReceiveMessage {
|
||||
|
||||
@Schema(description = "会话类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer conversationType; // 对应 ImConversationTypeEnum 枚举
|
||||
|
||||
@Schema(description = "聊天对象,用户编号或群编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long toId; // 根据 conversationType 区分
|
||||
@Schema(description = "发送人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long fromId; // 根据 conversationType 区分
|
||||
|
||||
@Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer type; // 参见 ImMessageTypeEnum 枚举
|
||||
@Schema(description = "内容类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer contentType; // 参见 ImMessageTypeEnum 枚举
|
||||
|
||||
@Schema(description = "消息内容", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private ImMessageBody body;
|
||||
private String content;
|
||||
|
||||
}
|
|
@ -2,22 +2,26 @@ package cn.iocoder.yudao.module.im.websocket.message;
|
|||
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.message.body.ImMessageBody;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 消息发送 send")
|
||||
@Data
|
||||
public class ImSendMessage {
|
||||
|
||||
@Schema(description = "客户端消息编号 uuid,用于排重", requiredMode = Schema.RequiredMode.REQUIRED, example = "3331")
|
||||
private String clientMessageId;
|
||||
|
||||
@Schema(description = "会话类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer conversationType; // 对应 ImConversationTypeEnum 枚举
|
||||
|
||||
@Schema(description = "聊天对象,用户编号或群编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long toId; // 根据 conversationType 区分
|
||||
@Schema(description = "接收人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long receiverId; // 根据 conversationType 区分
|
||||
|
||||
@Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer type; // 参见 ImMessageTypeEnum 枚举
|
||||
@Schema(description = "内容类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer contentType; // 参见 ImMessageTypeEnum 枚举
|
||||
|
||||
@Schema(description = "消息内容", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private ImMessageBody body;
|
||||
private String content;
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.im.dal.mysql.message.MessageMapper">
|
||||
<mapper namespace="cn.iocoder.yudao.module.im.dal.mysql.message.ImMessageMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
|
@ -2,42 +2,35 @@ package cn.iocoder.yudao.module.im.service.conversation;
|
|||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.*;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ConversationDO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO;
|
||||
import cn.iocoder.yudao.module.im.dal.mysql.conversation.ConversationMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.im.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link ConversationServiceImpl} 的单元测试类
|
||||
* {@link ImConversationServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(ConversationServiceImpl.class)
|
||||
public class ConversationServiceImplTest extends BaseDbUnitTest {
|
||||
@Import(ImConversationServiceImpl.class)
|
||||
public class ImConversationServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private ConversationServiceImpl conversationService;
|
||||
private ImConversationServiceImpl conversationService;
|
||||
|
||||
@Resource
|
||||
private ConversationMapper conversationMapper;
|
||||
|
@ -45,38 +38,38 @@ public class ConversationServiceImplTest extends BaseDbUnitTest {
|
|||
@Test
|
||||
public void testCreateConversation_success() {
|
||||
// 准备参数
|
||||
ConversationSaveReqVO createReqVO = randomPojo(ConversationSaveReqVO.class).setId(null);
|
||||
ImConversationSaveReqVO createReqVO = randomPojo(ImConversationSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long conversationId = conversationService.createConversation(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(conversationId);
|
||||
// 校验记录的属性是否正确
|
||||
ConversationDO conversation = conversationMapper.selectById(conversationId);
|
||||
ImConversationDO conversation = conversationMapper.selectById(conversationId);
|
||||
assertPojoEquals(createReqVO, conversation, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateConversation_success() {
|
||||
// mock 数据
|
||||
ConversationDO dbConversation = randomPojo(ConversationDO.class);
|
||||
ImConversationDO dbConversation = randomPojo(ImConversationDO.class);
|
||||
conversationMapper.insert(dbConversation);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
ConversationSaveReqVO updateReqVO = randomPojo(ConversationSaveReqVO.class, o -> {
|
||||
ImConversationSaveReqVO updateReqVO = randomPojo(ImConversationSaveReqVO.class, o -> {
|
||||
o.setId(dbConversation.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
conversationService.updateConversation(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
ConversationDO conversation = conversationMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
ImConversationDO conversation = conversationMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, conversation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateConversation_notExists() {
|
||||
// 准备参数
|
||||
ConversationSaveReqVO updateReqVO = randomPojo(ConversationSaveReqVO.class);
|
||||
ImConversationSaveReqVO updateReqVO = randomPojo(ImConversationSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> conversationService.updateConversation(updateReqVO), CONVERSATION_NOT_EXISTS);
|
||||
|
@ -85,7 +78,7 @@ public class ConversationServiceImplTest extends BaseDbUnitTest {
|
|||
@Test
|
||||
public void testDeleteConversation_success() {
|
||||
// mock 数据
|
||||
ConversationDO dbConversation = randomPojo(ConversationDO.class);
|
||||
ImConversationDO dbConversation = randomPojo(ImConversationDO.class);
|
||||
conversationMapper.insert(dbConversation);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbConversation.getId();
|
||||
|
@ -109,7 +102,7 @@ public class ConversationServiceImplTest extends BaseDbUnitTest {
|
|||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetConversationPage() {
|
||||
// mock 数据
|
||||
ConversationDO dbConversation = randomPojo(ConversationDO.class, o -> { // 等会查询到
|
||||
ImConversationDO dbConversation = randomPojo(ImConversationDO.class, o -> { // 等会查询到
|
||||
o.setUserId(null);
|
||||
o.setConversationType(null);
|
||||
o.setTargetId(null);
|
||||
|
@ -134,7 +127,7 @@ public class ConversationServiceImplTest extends BaseDbUnitTest {
|
|||
// 测试 createTime 不匹配
|
||||
conversationMapper.insert(cloneIgnoreId(dbConversation, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
ConversationPageReqVO reqVO = new ConversationPageReqVO();
|
||||
ImConversationPageReqVO reqVO = new ImConversationPageReqVO();
|
||||
reqVO.setUserId(null);
|
||||
reqVO.setConversationType(null);
|
||||
reqVO.setTargetId(null);
|
||||
|
@ -144,7 +137,7 @@ public class ConversationServiceImplTest extends BaseDbUnitTest {
|
|||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<ConversationDO> pageResult = conversationService.getConversationPage(reqVO);
|
||||
PageResult<ImConversationDO> pageResult = conversationService.getConversationPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
|
@ -2,31 +2,24 @@ package cn.iocoder.yudao.module.im.service.inbox;
|
|||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.im.controller.admin.inbox.vo.*;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.inbox.InboxDO;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.inbox.ImInboxDO;
|
||||
import cn.iocoder.yudao.module.im.dal.mysql.inbox.InboxMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.im.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link InboxServiceImpl} 的单元测试类
|
||||
|
@ -52,14 +45,14 @@ public class InboxServiceImplTest extends BaseDbUnitTest {
|
|||
// 断言
|
||||
assertNotNull(inboxId);
|
||||
// 校验记录的属性是否正确
|
||||
InboxDO inbox = inboxMapper.selectById(inboxId);
|
||||
ImInboxDO inbox = inboxMapper.selectById(inboxId);
|
||||
assertPojoEquals(createReqVO, inbox, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateInbox_success() {
|
||||
// mock 数据
|
||||
InboxDO dbInbox = randomPojo(InboxDO.class);
|
||||
ImInboxDO dbInbox = randomPojo(ImInboxDO.class);
|
||||
inboxMapper.insert(dbInbox);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
InboxSaveReqVO updateReqVO = randomPojo(InboxSaveReqVO.class, o -> {
|
||||
|
@ -69,7 +62,7 @@ public class InboxServiceImplTest extends BaseDbUnitTest {
|
|||
// 调用
|
||||
inboxService.updateInbox(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
InboxDO inbox = inboxMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
ImInboxDO inbox = inboxMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, inbox);
|
||||
}
|
||||
|
||||
|
@ -85,7 +78,7 @@ public class InboxServiceImplTest extends BaseDbUnitTest {
|
|||
@Test
|
||||
public void testDeleteInbox_success() {
|
||||
// mock 数据
|
||||
InboxDO dbInbox = randomPojo(InboxDO.class);
|
||||
ImInboxDO dbInbox = randomPojo(ImInboxDO.class);
|
||||
inboxMapper.insert(dbInbox);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbInbox.getId();
|
||||
|
@ -109,7 +102,7 @@ public class InboxServiceImplTest extends BaseDbUnitTest {
|
|||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetInboxPage() {
|
||||
// mock 数据
|
||||
InboxDO dbInbox = randomPojo(InboxDO.class, o -> { // 等会查询到
|
||||
ImInboxDO dbInbox = randomPojo(ImInboxDO.class, o -> { // 等会查询到
|
||||
o.setUserId(null);
|
||||
o.setMessageId(null);
|
||||
o.setSequence(null);
|
||||
|
@ -132,7 +125,7 @@ public class InboxServiceImplTest extends BaseDbUnitTest {
|
|||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<InboxDO> pageResult = inboxService.getInboxPage(reqVO);
|
||||
PageResult<ImInboxDO> pageResult = inboxService.getInboxPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
|
|
|
@ -2,81 +2,74 @@ package cn.iocoder.yudao.module.im.service.message;
|
|||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.im.controller.admin.message.vo.*;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.message.MessageDO;
|
||||
import cn.iocoder.yudao.module.im.dal.mysql.message.MessageMapper;
|
||||
import cn.iocoder.yudao.module.im.dal.dataobject.message.ImMessageDO;
|
||||
import cn.iocoder.yudao.module.im.dal.mysql.message.ImMessageMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.im.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link MessageServiceImpl} 的单元测试类
|
||||
* {@link ImMessageServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(MessageServiceImpl.class)
|
||||
public class MessageServiceImplTest extends BaseDbUnitTest {
|
||||
@Import(ImMessageServiceImpl.class)
|
||||
public class ImMessageServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private MessageServiceImpl messageService;
|
||||
private ImMessageServiceImpl messageService;
|
||||
|
||||
@Resource
|
||||
private MessageMapper messageMapper;
|
||||
private ImMessageMapper imMessageMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateMessage_success() {
|
||||
// 准备参数
|
||||
MessageSaveReqVO createReqVO = randomPojo(MessageSaveReqVO.class).setId(null);
|
||||
ImMessageSaveReqVO createReqVO = randomPojo(ImMessageSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long messageId = messageService.createMessage(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(messageId);
|
||||
// 校验记录的属性是否正确
|
||||
MessageDO message = messageMapper.selectById(messageId);
|
||||
ImMessageDO message = imMessageMapper.selectById(messageId);
|
||||
assertPojoEquals(createReqVO, message, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMessage_success() {
|
||||
// mock 数据
|
||||
MessageDO dbMessage = randomPojo(MessageDO.class);
|
||||
messageMapper.insert(dbMessage);// @Sql: 先插入出一条存在的数据
|
||||
ImMessageDO dbMessage = randomPojo(ImMessageDO.class);
|
||||
imMessageMapper.insert(dbMessage);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
MessageSaveReqVO updateReqVO = randomPojo(MessageSaveReqVO.class, o -> {
|
||||
ImMessageSaveReqVO updateReqVO = randomPojo(ImMessageSaveReqVO.class, o -> {
|
||||
o.setId(dbMessage.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
messageService.updateMessage(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
MessageDO message = messageMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
ImMessageDO message = imMessageMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMessage_notExists() {
|
||||
// 准备参数
|
||||
MessageSaveReqVO updateReqVO = randomPojo(MessageSaveReqVO.class);
|
||||
ImMessageSaveReqVO updateReqVO = randomPojo(ImMessageSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> messageService.updateMessage(updateReqVO), MESSAGE_NOT_EXISTS);
|
||||
|
@ -85,15 +78,15 @@ public class MessageServiceImplTest extends BaseDbUnitTest {
|
|||
@Test
|
||||
public void testDeleteMessage_success() {
|
||||
// mock 数据
|
||||
MessageDO dbMessage = randomPojo(MessageDO.class);
|
||||
messageMapper.insert(dbMessage);// @Sql: 先插入出一条存在的数据
|
||||
ImMessageDO dbMessage = randomPojo(ImMessageDO.class);
|
||||
imMessageMapper.insert(dbMessage);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbMessage.getId();
|
||||
|
||||
// 调用
|
||||
messageService.deleteMessage(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(messageMapper.selectById(id));
|
||||
assertNull(imMessageMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -109,7 +102,7 @@ public class MessageServiceImplTest extends BaseDbUnitTest {
|
|||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetMessagePage() {
|
||||
// mock 数据
|
||||
MessageDO dbMessage = randomPojo(MessageDO.class, o -> { // 等会查询到
|
||||
ImMessageDO dbMessage = randomPojo(ImMessageDO.class, o -> { // 等会查询到
|
||||
o.setClientMessageId(null);
|
||||
o.setSenderId(null);
|
||||
o.setReceiverId(null);
|
||||
|
@ -123,33 +116,33 @@ public class MessageServiceImplTest extends BaseDbUnitTest {
|
|||
o.setSendFrom(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
messageMapper.insert(dbMessage);
|
||||
imMessageMapper.insert(dbMessage);
|
||||
// 测试 clientMessageId 不匹配
|
||||
messageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setClientMessageId(null)));
|
||||
imMessageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setClientMessageId(null)));
|
||||
// 测试 senderId 不匹配
|
||||
messageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setSenderId(null)));
|
||||
imMessageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setSenderId(null)));
|
||||
// 测试 receiverId 不匹配
|
||||
messageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setReceiverId(null)));
|
||||
imMessageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setReceiverId(null)));
|
||||
// 测试 senderNickname 不匹配
|
||||
messageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setSenderNickname(null)));
|
||||
imMessageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setSenderNickname(null)));
|
||||
// 测试 senderAvatar 不匹配
|
||||
messageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setSenderAvatar(null)));
|
||||
imMessageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setSenderAvatar(null)));
|
||||
// 测试 conversationType 不匹配
|
||||
messageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setConversationType(null)));
|
||||
imMessageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setConversationType(null)));
|
||||
// 测试 conversationNo 不匹配
|
||||
messageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setConversationNo(null)));
|
||||
imMessageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setConversationNo(null)));
|
||||
// 测试 contentType 不匹配
|
||||
messageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setContentType(null)));
|
||||
imMessageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setContentType(null)));
|
||||
// 测试 content 不匹配
|
||||
messageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setContent(null)));
|
||||
imMessageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setContent(null)));
|
||||
// 测试 sendTime 不匹配
|
||||
messageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setSendTime(null)));
|
||||
imMessageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setSendTime(null)));
|
||||
// 测试 sendFrom 不匹配
|
||||
messageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setSendFrom(null)));
|
||||
imMessageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setSendFrom(null)));
|
||||
// 测试 createTime 不匹配
|
||||
messageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setCreateTime(null)));
|
||||
imMessageMapper.insert(cloneIgnoreId(dbMessage, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
MessagePageReqVO reqVO = new MessagePageReqVO();
|
||||
ImMessagePageReqVO reqVO = new ImMessagePageReqVO();
|
||||
reqVO.setClientMessageId(null);
|
||||
reqVO.setSenderId(null);
|
||||
reqVO.setReceiverId(null);
|
||||
|
@ -164,7 +157,7 @@ public class MessageServiceImplTest extends BaseDbUnitTest {
|
|||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<MessageDO> pageResult = messageService.getMessagePage(reqVO);
|
||||
PageResult<ImMessageDO> pageResult = messageService.getMessagePage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
|
@ -41,4 +41,9 @@ public class AdminUserRespDTO {
|
|||
*/
|
||||
private String mobile;
|
||||
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
}
|
||||
|
|
|
@ -47,14 +47,14 @@ spring:
|
|||
datasource:
|
||||
master:
|
||||
name: ruoyi-vue-pro
|
||||
url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
|
||||
url: jdbc:mysql://chaojiniu.top:23306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
|
||||
# url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例
|
||||
# url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.master.name} # PostgreSQL 连接的示例
|
||||
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
|
||||
# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例
|
||||
# url: jdbc:dm://10.211.55.4:5236?schema=RUOYI_VUE_PRO # DM 连接的示例
|
||||
username: root
|
||||
password: 123456
|
||||
username: ruoyi-vue-pro
|
||||
password: ruoyi-@h2ju02hebp
|
||||
# username: sa
|
||||
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
|
||||
# username: SYSDBA # DM 连接的示例
|
||||
|
@ -62,23 +62,23 @@ spring:
|
|||
slave: # 模拟从库,可根据自己需要修改
|
||||
name: ruoyi-vue-pro
|
||||
lazy: true # 开启懒加载,保证启动速度
|
||||
url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
|
||||
url: jdbc:mysql://chaojiniu.top:23306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
|
||||
# url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例
|
||||
# url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.slave.name} # PostgreSQL 连接的示例
|
||||
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
|
||||
# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例
|
||||
username: root
|
||||
password: 123456
|
||||
username: ruoyi-vue-pro
|
||||
password: ruoyi-@h2ju02hebp
|
||||
# username: sa
|
||||
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W
|
||||
|
||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||
data:
|
||||
redis:
|
||||
host: 127.0.0.1 # 地址
|
||||
host: chaojiniu.top # 地址
|
||||
port: 6379 # 端口
|
||||
database: 0 # 数据库索引
|
||||
# password: dev # 密码,建议生产环境开启
|
||||
password: fsknKD7UvQYZsyf2hXXn # 密码,建议生产环境开启
|
||||
|
||||
--- #################### 定时任务相关配置 ####################
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ yudao:
|
|||
- cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants
|
||||
- cn.iocoder.yudao.module.im.enums.ErrorCodeConstants
|
||||
tenant: # 多租户相关配置项
|
||||
enable: true
|
||||
enable: false
|
||||
ignore-urls:
|
||||
- /admin-api/system/tenant/get-id-by-name # 基于名字获取租户,不许带租户编号
|
||||
- /admin-api/system/tenant/get-by-website # 基于域名获取租户,不许带租户编号
|
||||
|
|
Loading…
Reference in New Issue