peng
2025-06-13 30b41cc526165b70e04a1fe1438cb79bb035a7bf
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
81
82
83
84
85
86
87
88
89
90
package cn.lili.controller.im;
 
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.im.entity.dos.ImMessage;
import cn.lili.modules.im.entity.dto.MessageQueryParams;
import cn.lili.modules.im.service.ImMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
 
/**
 * @author Chopper
 */
@RestController
@Api(tags = "Im消息接口")
@RequestMapping("/im/message")
@Transactional(rollbackFor = Exception.class)
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ImMessageController {
 
    private final ImMessageService imMessageService;
 
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "查看Im消息详情")
    public ResultMessage<ImMessage> get(@PathVariable String id) {
        ImMessage imMessage = imMessageService.getById(id);
        return ResultUtil.data(imMessage);
    }
 
    @GetMapping
    @ApiOperation(value = "分页获取Im消息")
    public ResultMessage<List<ImMessage>> historyMessage(MessageQueryParams messageQueryParams) {
        List<ImMessage> data = imMessageService.getList(messageQueryParams);
        return ResultUtil.data(data);
    }
 
    @PostMapping
    @ApiOperation(value = "新增Im消息")
    public ResultMessage<ImMessage> save(ImMessage imMessage) {
        if (imMessageService.save(imMessage)) {
            return ResultUtil.data(imMessage);
        }
        throw new ServiceException(ResultCode.IM_MESSAGE_ADD_ERROR);
    }
 
    @PutMapping("/{id}")
    @ApiOperation(value = "更新Im消息")
    public ResultMessage<ImMessage> update(@PathVariable String id, ImMessage imMessage) {
        if (imMessageService.updateById(imMessage)) {
            return ResultUtil.data(imMessage);
        }
        throw new ServiceException(ResultCode.IM_MESSAGE_EDIT_ERROR);
    }
 
    @DeleteMapping(value = "/{ids}")
    @ApiOperation(value = "删除Im消息")
    public ResultMessage<Object> delAllByIds(@PathVariable List ids) {
        imMessageService.removeByIds(ids);
        return ResultUtil.success();
    }
 
 
    @GetMapping(value = "/newMessage")
    @ApiOperation(value = "查看是否有新消息")
    public ResultMessage<Boolean> hasNewMessage(String accessToken) {
        return ResultUtil.data(imMessageService.hasNewMessage(accessToken));
    }
 
    @GetMapping(value = "/unreadMessage")
    @ApiOperation(value = "获取所有未读消息")
    public ResultMessage<Long> getUnreadMessageCount() {
        return ResultUtil.data(imMessageService.unreadMessageCount());
    }
 
    @PutMapping(value = "/clean/unred")
    @ApiOperation(value = "清除所有未读消息")
    public ResultMessage<Object> cleanUnreadMessage() {
        imMessageService.cleanUnreadMessage();
        return ResultUtil.success();
    }
}