SysRoleController.java 3.5 KB
Newer Older
1
package com.youlai.system.controller;
H
hxrui 已提交
2 3

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
4
import com.youlai.common.result.PageResult;
H
hxrui 已提交
5
import com.youlai.common.result.Result;
H
horizons 已提交
6
import com.youlai.common.web.model.Option;
7 8 9 10 11
import com.youlai.system.pojo.entity.SysRole;
import com.youlai.system.pojo.form.RoleForm;
import com.youlai.system.pojo.query.RolePageQuery;
import com.youlai.system.pojo.service.SysRoleService;
import com.youlai.system.pojo.vo.role.RolePageVO;
12 13 14
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
15
import lombok.RequiredArgsConstructor;
H
hxrui 已提交
16
import org.springframework.web.bind.annotation.*;
17

郝先瑞 已提交
18
import javax.validation.Valid;
H
hxrui 已提交
19 20 21 22
import java.util.List;

@Api(tags = "角色接口")
@RestController
H
haoxr 已提交
23
@RequestMapping("/api/v1/roles")
24
@RequiredArgsConstructor
25
public class SysRoleController {
H
hxrui 已提交
26

27
    private final SysRoleService roleService;
H
haoxr 已提交
28

郝先瑞 已提交
29
    @ApiOperation(value = "角色分页列表")
30 31
    @GetMapping("/pages")
    public PageResult<RolePageVO> listRolePages(RolePageQuery queryParams) {
32
        Page<RolePageVO> result = roleService.listRolePages(queryParams);
33
        return PageResult.success(result);
34
    }
H
hxrui 已提交
35

郝先瑞 已提交
36
    @ApiOperation(value = "角色下拉列表")
37 38
    @GetMapping("/options")
    public Result<List<Option>> listRoleOptions() {
39
        List<Option> list = roleService.listRoleOptions();
40
        return Result.success(list);
H
hxrui 已提交
41 42
    }

43 44 45 46 47
    @ApiOperation(value = "角色详情")
    @GetMapping("/{roleId}")
    public Result getRoleDetail(
            @ApiParam("角色ID") @PathVariable Long roleId
    ) {
48
        SysRole role = roleService.getById(roleId);
49 50 51
        return Result.success(role);
    }

H
haoxr 已提交
52
    @ApiOperation(value = "新增角色")
H
hxrui 已提交
53
    @PostMapping
郝先瑞 已提交
54
    public Result addRole(@Valid @RequestBody RoleForm roleForm) {
55
        boolean result = roleService.saveRole(roleForm);
H
hxrui 已提交
56 57 58
        return Result.judge(result);
    }

H
haoxr 已提交
59
    @ApiOperation(value = "修改角色")
H
hxrui 已提交
60
    @PutMapping(value = "/{id}")
郝先瑞 已提交
61
    public Result updateRole(@Valid @RequestBody RoleForm roleForm) {
62
        boolean result = roleService.saveRole(roleForm);
H
hxrui 已提交
63 64 65
        return Result.judge(result);
    }

H
haoxr 已提交
66
    @ApiOperation(value = "删除角色")
H
hxrui 已提交
67
    @DeleteMapping("/{ids}")
68 69 70
    public Result deleteRoles(
            @ApiParam("删除角色,多个以英文逗号(,)分割") @PathVariable String ids
    ) {
71
        boolean result = roleService.deleteRoles(ids);
H
hxrui 已提交
72 73 74
        return Result.judge(result);
    }

郝先瑞 已提交
75 76 77
    @ApiOperation(value = "修改角色状态")
    @PutMapping(value = "/{roleId}/status")
    public Result updateRoleStatus(
有来技术 已提交
78
            @ApiParam("角色ID") @PathVariable Long roleId,
79
            @ApiParam("角色状态:1-启用;0-禁用") @RequestParam Integer status
有来技术 已提交
80
    ) {
81
        boolean result = roleService.updateRoleStatus(roleId, status);
H
hxrui 已提交
82 83 84
        return Result.judge(result);
    }

85 86 87
    @ApiOperation(value = "获取角色的菜单ID集合")
    @GetMapping("/{roleId}/menuIds")
    public Result<List<Long>> getRoleMenuIds(
有来技术 已提交
88 89
            @ApiParam("角色ID") @PathVariable Long roleId
    ) {
90
        List<Long> resourceIds = roleService.getRoleMenuIds(roleId);
郝先瑞 已提交
91
        return Result.success(resourceIds);
H
hxrui 已提交
92 93
    }

94
    @ApiOperation(value = "分配角色的资源权限")
95 96
    @PutMapping("/{roleId}/menus")
    public Result updateRoleMenus(
97
            @PathVariable Long roleId,
98
            @RequestBody List<Long> menuIds
有来技术 已提交
99
    ) {
100
        boolean result = roleService.updateRoleMenus(roleId,menuIds);
H
hxrui 已提交
101 102 103
        return Result.judge(result);
    }
}