puzhibing
2026-02-04 85bafa86f44fbe6646019fd8ecbab79f552ccd0a
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
package com.xiaopeng.account.controller;
 
 
import com.xiaopeng.account.model.dto.SysRoleAddDTO;
import com.xiaopeng.account.model.dto.SysRoleEditDTO;
import com.xiaopeng.account.model.query.SysRolePageQuery;
import com.xiaopeng.account.model.vo.SysRoleDetailVO;
import com.xiaopeng.account.model.vo.SysRolePageVO;
import com.xiaopeng.account.service.ISysRoleService;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.web.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
/**
 * <p>
 * 角色管理 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2026-02-03
 */
@Api(tags = "角色管理")
@RequiredArgsConstructor(onConstructor_ = @Lazy)
@RestController
public class SysRoleController {
    private final ISysRoleService sysRoleService;
 
    @ApiOperation("新增角色")
    @PostMapping("/api/v1/role/add")
    public R<?> add(@Validated @RequestBody SysRoleAddDTO dto) {
        sysRoleService.addRole(dto);
        return R.ok();
    }
 
    @ApiOperation("编辑角色")
    @PostMapping("/api/v1/role/edit")
    public R<?> edit(@Validated @RequestBody SysRoleEditDTO dto) {
        sysRoleService.editRole(dto);
        return R.ok();
    }
 
    @ApiOperation("角色详情")
    @GetMapping("/api/v1/role/queryById")
    public R<SysRoleDetailVO> queryById(@ApiParam(value = "角色id", required = true) @RequestParam Long id) {
        SysRoleDetailVO detail = sysRoleService.getRoleDetail(id);
        return R.ok(detail);
    }
 
    @ApiOperation("角色分页列表")
    @PostMapping("/api/v1/role/pageList")
    public R<PageInfo<SysRolePageVO>> pageList(@Validated @RequestBody SysRolePageQuery query) {
        PageInfo<SysRolePageVO> pageInfo = sysRoleService.pageList(query);
        return R.ok(pageInfo);
    }
 
    @ApiOperation("删除角色")
    @DeleteMapping("/api/v1/role/delete/{id}")
    public R<?> delete(@ApiParam(value = "角色id", required = true) @PathVariable Long id) {
        sysRoleService.deleteRole(id);
        return R.ok();
    }
}