Commit 2558d8c8745f6e18b30957a6829d171d486df88d
1 parent
34d273a2
feat(im):增加渠道消息的 get 接口
Showing
3 changed files
with
46 additions
and
8 deletions
yudao-module-im/src/main/java/cn/iocoder/yudao/module/im/controller/admin/manager/message/ImChannelMessageManagerController.java
| @@ -23,6 +23,8 @@ import org.springframework.security.access.prepost.PreAuthorize; | @@ -23,6 +23,8 @@ import org.springframework.security.access.prepost.PreAuthorize; | ||
| 23 | import org.springframework.validation.annotation.Validated; | 23 | import org.springframework.validation.annotation.Validated; |
| 24 | import org.springframework.web.bind.annotation.*; | 24 | import org.springframework.web.bind.annotation.*; |
| 25 | 25 | ||
| 26 | +import java.util.Collections; | ||
| 27 | +import java.util.List; | ||
| 26 | import java.util.Map; | 28 | import java.util.Map; |
| 27 | 29 | ||
| 28 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 30 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| @@ -62,19 +64,42 @@ public class ImChannelMessageManagerController { | @@ -62,19 +64,42 @@ public class ImChannelMessageManagerController { | ||
| 62 | @PreAuthorize("@ss.hasPermission('im:manager:channel-message:query')") | 64 | @PreAuthorize("@ss.hasPermission('im:manager:channel-message:query')") |
| 63 | public CommonResult<PageResult<ImChannelMessageRespVO>> getMessagePage(@Valid ImChannelMessagePageReqVO pageReqVO) { | 65 | public CommonResult<PageResult<ImChannelMessageRespVO>> getMessagePage(@Valid ImChannelMessagePageReqVO pageReqVO) { |
| 64 | PageResult<ImChannelMessageDO> pageResult = channelMessageService.getMessagePage(pageReqVO); | 66 | PageResult<ImChannelMessageDO> pageResult = channelMessageService.getMessagePage(pageReqVO); |
| 65 | - if (CollUtil.isEmpty(pageResult.getList())) { | ||
| 66 | - return success(PageResult.empty(pageResult.getTotal())); | 67 | + return success(new PageResult<>(buildMessageRespVOList(pageResult.getList()), pageResult.getTotal())); |
| 68 | + } | ||
| 69 | + | ||
| 70 | + @GetMapping("/get") | ||
| 71 | + @Operation(summary = "获得频道消息详情") | ||
| 72 | + @Parameter(name = "id", description = "消息编号", required = true, example = "1024") | ||
| 73 | + @PreAuthorize("@ss.hasPermission('im:manager:channel-message:query')") | ||
| 74 | + public CommonResult<ImChannelMessageRespVO> getMessage(@RequestParam("id") Long id) { | ||
| 75 | + ImChannelMessageDO message = channelMessageService.getMessage(id); | ||
| 76 | + return success(buildMessageRespVO(message)); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + // ==================== 拼接 VO ==================== | ||
| 80 | + | ||
| 81 | + private ImChannelMessageRespVO buildMessageRespVO(ImChannelMessageDO message) { | ||
| 82 | + if (message == null) { | ||
| 83 | + return null; | ||
| 84 | + } | ||
| 85 | + return CollUtil.getFirst(buildMessageRespVOList(Collections.singletonList(message))); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + private List<ImChannelMessageRespVO> buildMessageRespVOList(List<ImChannelMessageDO> messages) { | ||
| 89 | + if (CollUtil.isEmpty(messages)) { | ||
| 90 | + return Collections.emptyList(); | ||
| 67 | } | 91 | } |
| 68 | - // 批量查询频道和素材,并回填频道名 / 素材标题 | 92 | + // 1. 查询关联数据 |
| 69 | Map<Long, ImChannelDO> channelMap = channelService.getChannelMap( | 93 | Map<Long, ImChannelDO> channelMap = channelService.getChannelMap( |
| 70 | - convertSet(pageResult.getList(), ImChannelMessageDO::getChannelId)); | 94 | + convertSet(messages, ImChannelMessageDO::getChannelId)); |
| 71 | Map<Long, ImChannelMaterialDO> materialMap = channelMaterialService.getMaterialMap( | 95 | Map<Long, ImChannelMaterialDO> materialMap = channelMaterialService.getMaterialMap( |
| 72 | - convertSet(pageResult.getList(), ImChannelMessageDO::getMaterialId)); | ||
| 73 | - return success(BeanUtils.toBean(pageResult, ImChannelMessageRespVO.class, vo -> { | ||
| 74 | - MapUtils.findAndThen(channelMap, vo.getChannelId(), c -> vo.setChannelName(c.getName())); | 96 | + convertSet(messages, ImChannelMessageDO::getMaterialId)); |
| 97 | + // 2. 拼接 VO | ||
| 98 | + return BeanUtils.toBean(messages, ImChannelMessageRespVO.class, vo -> { | ||
| 99 | + MapUtils.findAndThen(channelMap, vo.getChannelId(), channel -> vo.setChannelName(channel.getName())); | ||
| 75 | MapUtils.findAndThen(materialMap, vo.getMaterialId(), | 100 | MapUtils.findAndThen(materialMap, vo.getMaterialId(), |
| 76 | material -> vo.setMaterialTitle(material.getTitle()).setMaterialCoverUrl(material.getCoverUrl())); | 101 | material -> vo.setMaterialTitle(material.getTitle()).setMaterialCoverUrl(material.getCoverUrl())); |
| 77 | - })); | 102 | + }); |
| 78 | } | 103 | } |
| 79 | 104 | ||
| 80 | } | 105 | } |
yudao-module-im/src/main/java/cn/iocoder/yudao/module/im/service/message/ImChannelMessageService.java
| @@ -66,6 +66,14 @@ public interface ImChannelMessageService { | @@ -66,6 +66,14 @@ public interface ImChannelMessageService { | ||
| 66 | PageResult<ImChannelMessageDO> getMessagePage(ImChannelMessagePageReqVO reqVO); | 66 | PageResult<ImChannelMessageDO> getMessagePage(ImChannelMessagePageReqVO reqVO); |
| 67 | 67 | ||
| 68 | /** | 68 | /** |
| 69 | + * 获得频道消息 | ||
| 70 | + * | ||
| 71 | + * @param id 消息编号 | ||
| 72 | + * @return 频道消息 | ||
| 73 | + */ | ||
| 74 | + ImChannelMessageDO getMessage(Long id); | ||
| 75 | + | ||
| 76 | + /** | ||
| 69 | * 删除消息 | 77 | * 删除消息 |
| 70 | * | 78 | * |
| 71 | * @param id 消息编号 | 79 | * @param id 消息编号 |
yudao-module-im/src/main/java/cn/iocoder/yudao/module/im/service/message/ImChannelMessageServiceImpl.java
| @@ -138,6 +138,11 @@ public class ImChannelMessageServiceImpl implements ImChannelMessageService { | @@ -138,6 +138,11 @@ public class ImChannelMessageServiceImpl implements ImChannelMessageService { | ||
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | @Override | 140 | @Override |
| 141 | + public ImChannelMessageDO getMessage(Long id) { | ||
| 142 | + return channelMessageMapper.selectById(id); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + @Override | ||
| 141 | public void deleteMessage(Long id) { | 146 | public void deleteMessage(Long id) { |
| 142 | if (channelMessageMapper.selectById(id) == null) { | 147 | if (channelMessageMapper.selectById(id) == null) { |
| 143 | throw exception(IM_CHANNEL_MESSAGE_NOT_EXISTS); | 148 | throw exception(IM_CHANNEL_MESSAGE_NOT_EXISTS); |