青羊经侦大队-数据平台
安瑾然
2022-07-14 5b04d19edea32888efa9ee4881395a21da348e3f
src/main/java/com/example/jz/controller/GroupController.java
@@ -1,13 +1,20 @@
package com.example.jz.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.jz.modle.entity.Announcement;
import com.example.jz.modle.entity.Group;
import com.example.jz.modle.vo.GroupMessageVo;
import com.example.jz.modle.vo.GroupUserVo;
import com.example.jz.service.GroupService;
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 javax.annotation.Resource;
@@ -16,73 +23,74 @@
/**
 * 群表
(Group)表控制层
 * (Group)表控制层
 *
 * @author makejava
 * @since 2022-07-11 16:35:57
 */
@RestController
@RequestMapping("group")
@Api(tags = "群组接口")
public class GroupController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private GroupService groupService;
    @Autowired
    public void setGroupService(GroupService groupService) {
        this.groupService = groupService;
    }
    /**
     * 分页查询所有数据
     * 根据群组id获取当前群组所有的消息
     *
     * @param page 分页对象
     * @param group 查询实体
     * @return 所有数据
     * @param id 群组id
     * @return 当前群组所有的消息
     */
    @GetMapping
    public R selectAll(Page<Group> page, Group group) {
        return success(this.groupService.page(page, new QueryWrapper<>(group)));
    @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));
    }
    /**
     * 通过主键查询单条数据
     * 根据群组id获取当前群组所有公告
     *
     * @param id 主键
     * @return 单条数据
     * @param id 群组id
     * @return 当前群组所有的消息
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return success(this.groupService.getById(id));
    @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 group 实体对象
     * @return 新增结果
     * @param id   群组id
     * @param text 消息内容
     * @return 发送结果
     */
    @PostMapping
    public R insert(@RequestBody Group group) {
        return success(this.groupService.save(group));
    @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) {
        return R.ok(groupService.sendMessage(id, text));
    }
    /**
     * 修改数据
     * 获取群组所有人员列表
     *
     * @param group 实体对象
     * @return 修改结果
     * @param id 群组id
     * @return 群组所有人员列表
     */
    @PutMapping
    public R update(@RequestBody Group group) {
        return success(this.groupService.updateById(group));
    }
    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return success(this.groupService.removeByIds(idList));
    @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));
    }
}