liyong
4 小时以前 7a23c450f3ac85de7dca1b908de273ff636ce218
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package cn.iocoder.yudao.module.im.controller.admin.manager.message;
 
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.im.controller.admin.manager.message.vo.channel.ImChannelMessagePageReqVO;
import cn.iocoder.yudao.module.im.controller.admin.manager.message.vo.channel.ImChannelMessageRespVO;
import cn.iocoder.yudao.module.im.controller.admin.manager.message.vo.channel.ImChannelMessageSendReqVO;
import cn.iocoder.yudao.module.im.dal.dataobject.channel.ImChannelDO;
import cn.iocoder.yudao.module.im.dal.dataobject.channel.ImChannelMaterialDO;
import cn.iocoder.yudao.module.im.dal.dataobject.message.ImChannelMessageDO;
import cn.iocoder.yudao.module.im.service.channel.ImChannelMaterialService;
import cn.iocoder.yudao.module.im.service.message.ImChannelMessageService;
import cn.iocoder.yudao.module.im.service.channel.ImChannelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.Map;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 
@Tag(name = "管理后台 - IM 频道消息")
@RestController
@RequestMapping("/im/manager/channel-message")
@Validated
public class ImChannelMessageManagerController {
 
    @Resource
    private ImChannelMessageService channelMessageService;
    @Resource
    private ImChannelService channelService;
    @Resource
    private ImChannelMaterialService channelMaterialService;
 
    @PostMapping("/send")
    @Operation(summary = "立即推送频道消息")
    @PreAuthorize("@ss.hasPermission('im:manager:channel-message:send')")
    public CommonResult<Long> sendMessage(@Valid @RequestBody ImChannelMessageSendReqVO reqVO) {
        return success(channelMessageService.sendMessage(reqVO));
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除频道消息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('im:manager:channel-message:delete')")
    public CommonResult<Boolean> deleteMessage(@RequestParam("id") Long id) {
        channelMessageService.deleteMessage(id);
        return success(true);
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得频道消息分页;回填频道名 / 素材标题")
    @PreAuthorize("@ss.hasPermission('im:manager:channel-message:query')")
    public CommonResult<PageResult<ImChannelMessageRespVO>> getMessagePage(@Valid ImChannelMessagePageReqVO pageReqVO) {
        PageResult<ImChannelMessageDO> pageResult = channelMessageService.getMessagePage(pageReqVO);
        if (CollUtil.isEmpty(pageResult.getList())) {
            return success(PageResult.empty(pageResult.getTotal()));
        }
        // 批量查询频道和素材,并回填频道名 / 素材标题
        Map<Long, ImChannelDO> channelMap = channelService.getChannelMap(
                convertSet(pageResult.getList(), ImChannelMessageDO::getChannelId));
        Map<Long, ImChannelMaterialDO> materialMap = channelMaterialService.getMaterialMap(
                convertSet(pageResult.getList(), ImChannelMessageDO::getMaterialId));
        return success(BeanUtils.toBean(pageResult, ImChannelMessageRespVO.class, vo -> {
            MapUtils.findAndThen(channelMap, vo.getChannelId(), c -> vo.setChannelName(c.getName()));
            MapUtils.findAndThen(materialMap, vo.getMaterialId(),
                    material -> vo.setMaterialTitle(material.getTitle()).setMaterialCoverUrl(material.getCoverUrl()));
        }));
    }
 
}