clll
2023-11-27 c39cbcb00cbff39d50756a58e0e1c64dde160fc1
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
package com.example.springboot.controller;
 
import com.example.springboot.entity.Role;
import com.example.springboot.entity.vo.Result;
import com.example.springboot.entity.vo.RoleVo;
import com.example.springboot.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
@Slf4j
@Api(tags = "角色")
@RequestMapping("/api/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
 
    @ApiOperation(value = "添加或者更新角色")
    @PostMapping("/saveOrUpdate")
    @RequiresRoles({"admin"})
    @RequiresPermissions({"role:add", "role:update"})
    public Result saveOrUpdate(@RequestBody Role role) {
        Integer count = roleService.lambdaQuery().eq(Role::getName, role.getName())
                .ne(role.getId() != null, Role::getId, role.getId())
                .count();
        if (count > 0) return Result.fail("已存在该角色名称");
        roleService.saveOrUpdate(role);
        return Result.success();
    }
 
 
    @ApiOperation(value = "根据id删除角色")
    @PostMapping("/removeById")
    @RequiresRoles({"admin"})
    @RequiresPermissions({"role:delete"})
    public Result removeById(@RequestBody RoleVo roleVO) {
        roleService.removeById(roleVO.getId());
        return Result.success();
    }
 
    @ApiOperation(value = "根据id查询角色")
    @GetMapping("/getById")
    @RequiresRoles({"admin"})
    @RequiresPermissions({"role:select"})
    public Result getById(Role role) {
        return Result.success(roleService.getById(role.getId()));
    }
 
 
 
    @ApiOperation(value = "分页查询角色")
    @GetMapping("/selectPage")
    @RequiresRoles({"admin"})
    @RequiresPermissions({"role:select"})
    public Result selectPage(RoleVo roleVO) {
        return Result.success(roleService.selectPage(roleVO));
    }
 
    @ApiOperation(value = "查询角色列表")
    @GetMapping("/select")
    @RequiresRoles({"admin"})
    @RequiresPermissions({"role:select"})
    public Result select(RoleVo roleVO) {
        return Result.success(roleService.lambdaQuery().list());
    }
}