青羊经侦大队-数据平台
baizonghao
2023-03-21 94c89cf9f870027a290ea1c1c768d9901346acbf
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.example.jz.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.example.jz.modle.R;
import com.example.jz.modle.entity.Announcement;
import com.example.jz.modle.entity.Group;
import com.example.jz.modle.entity.GroupUser;
import com.example.jz.modle.vo.GroupMessageVo;
import com.example.jz.modle.vo.GroupUserVo;
import com.example.jz.service.GroupService;
import com.example.jz.service.GroupUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * 群表
 * (Group)表控制层
 *
 * @author makejava
 * @since 2022-07-11 16:35:57
 */
@RestController
@RequestMapping("group")
@Api(tags = "群组接口")
public class GroupController extends ApiController {
    private GroupService groupService;
 
    @Autowired
    public void setGroupService(GroupService groupService) {
        this.groupService = groupService;
    }
 
    @Autowired
    GroupUserService groupUserService;
 
    /**
     * 根据群组id获取当前群组所有的消息 修改
     *
     * @param id 群组id
     * @return 当前群组所有的消息
     */
    @GetMapping("getAllMessage")
    @ApiOperation(value = "获取当前群组所有的消息")
    @ApiImplicitParam(name = "id", value = "群组id", required = true, dataType = "Integer")
    public R<List<GroupMessageVo>> getAllMessage(@RequestParam("id") Integer id) {
        return R.ok(groupService.getAllMessage(id));
    }
 
 
    @GetMapping("getGroupMessage")
    @ApiOperation(value = "获取当前群组消息通过成员或者内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "report", value = "群组id", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "context", value = "群组id", required = true, dataType = "String")
    })
    public R<List<GroupMessageVo>> get(@RequestParam(value = "report", required = false) String reporter, @RequestParam(value = "context", required = false) String context, Integer groupId) {
        return R.ok(groupService.getByCondition(reporter, context, groupId));
    }
 
    @PutMapping("banSpeech")
    @ApiOperation(value = "禁言")
    @ApiImplicitParam(name = "id", value = "群组id", required = true, dataType = "Integer")
    public R setBanSpeech(@RequestParam("id") Integer id, @RequestParam("groupId") Integer groupId) {
        return R.ok(groupUserService.update(new UpdateWrapper<GroupUser>().set("ban_speech", 1).eq("user_id", id).eq("group_id", groupId)));
    }
 
    @PutMapping("allowSpeech")
    @ApiOperation(value = "允许发言")
    @ApiImplicitParam(name = "id", value = "群组id", required = true, dataType = "Integer")
    public R setAllowSpeech(@RequestParam("id") Integer id, @RequestParam("groupId") Integer groupId) {
        return R.ok(groupUserService.update(new UpdateWrapper<GroupUser>().set("ban_speech", 0).eq("user_id", id).eq("group_id", groupId)));
    }
 
    @PutMapping("banSpeechAll")
    @ApiOperation(value = "全部禁言")
    public R setBanSpeechAll(@RequestParam("id") Integer id) {
        return R.ok(groupUserService.update(new UpdateWrapper<GroupUser>().set("ban_speech", 1).eq("group_id", id)));
    }
 
    @PutMapping("banSpeechRemark")
    @ApiOperation(value = "全部允许发言")
    public R setBanSpeechRemark(@RequestParam("id") Integer id) {
        return R.ok(groupUserService.update(new UpdateWrapper<GroupUser>().set("ban_speech", 0).eq("group_id", id)));
    }
 
    /**
     * 根据群组id获取当前群组所有公告
     *
     * @param id 群组id
     * @return 当前群组所有的消息
     */
    @GetMapping("getAllNotice")
    @ApiOperation(value = "获取当前群组所有的公告")
    @ApiImplicitParam(name = "id", value = "群组id", required = true, dataType = "Integer")
    public R<List<Announcement>> getAllNotice(@RequestParam("id") Integer id) {
        return R.ok(groupService.getAllNotice(id));
    }
 
    /**
     * 发送信息
     *
     * @param id   群组id
     * @param text 消息内容
     * @return 发送结果
     */
    @GetMapping("sendMessage")
    @ApiOperation(value = "发送信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "text", value = "消息文本", required = true, dataType = "String"),
            @ApiImplicitParam(name = "id", value = "群组id", required = true, dataType = "Integer")
    })
    public R<Boolean> sendMessage(@RequestParam("id") Integer id, @RequestParam("text") String text) {
        if (StringUtils.isBlank(text)) {
            return R.failed("文本为空");
        }
        return R.ok(groupService.sendMessage(id, text));
    }
 
    /**
     * 获取群组所有人员列表 修改
     *
     * @param id 群组id
     * @return 群组所有人员列表
     */
    @GetMapping("getAllUser")
    @ApiOperation(value = "获取群组所有人员列表")
    @ApiImplicitParam(name = "id", value = "群组id", required = true, dataType = "Integer")
    public R<List<GroupUserVo>> getAllUser(@RequestParam("id") Integer id) {
        return R.ok(groupService.getAllUser(id));
    }
 
    @GetMapping("getAllGroupName")
    @ApiOperation(value = "获取群组名称")
    public R<List<Group>> getAllGroupName() {
        return R.ok(groupService.list());
    }
}