lyh
9 小时以前 78aeb8a8c97a884a640d46755e4be706bde48b7d
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
147
148
149
package com.lxzn.ucenter.controller;
 
import com.lxzn.api.ucenter.RoleControllerApi;
import com.lxzn.framework.domain.ucenter.*;
import com.lxzn.framework.domain.ucenter.request.RoleRequest;
import com.lxzn.framework.model.response.*;
import com.lxzn.ucenter.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.Collections;
import java.util.List;
 
@RestController
@RequestMapping("/ucenter/role")
public class RoleController implements RoleControllerApi {
    @Autowired
    private IRoleService roleService;
 
    @Override
    @PostMapping("/add")
    public ResponseResult addRole(@RequestBody Role role) {
        boolean b = roleService.addRole(role);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @Override
    @PutMapping("/edit/{id}")
    public ResponseResult editRole(@PathVariable("id") String id, @RequestBody Role role) {
        boolean b = roleService.editRole(id ,role);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @Override
    @PostMapping("/assign/menu/{roleId}")
    public ResponseResult assignMenus(@PathVariable("roleId") String roleId, @RequestBody String[] menuIds) {
        boolean b = roleService.assignMenus(roleId, menuIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @Override
    @PostMapping("/assign/button/{roleId}")
    public ResponseResult assignSysButton(@PathVariable("roleId") String roleId, @RequestBody String[] buttonIds) {
        boolean b = roleService.assignSysButton(roleId, buttonIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @Override
    @PostMapping("/assign/menu/button/{roleId}")
    public ResponseResult assignMenuButton(@PathVariable("roleId") String roleId, @RequestBody String[] menuButtonIds) {
        boolean b = roleService.assignMenuButton(roleId, menuButtonIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @Override
    @PostMapping("/assign/obj/button/{roleId}")
    public ResponseResult assignObjectButton(@PathVariable("roleId") String roleId, @RequestBody String[] objectButtonIds) {
        boolean b = roleService.assignObjectButton(roleId, objectButtonIds);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
 
    @Override
    @GetMapping("/perm/select/non/{userId}")
    public QueryListResponseResult<Role> getUserNonPermRole(@PathVariable("userId") String userId) {
        List<Role> list = roleService.getUserNonPermRole(userId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @Override
    @GetMapping("/perm/select/{userId}")
    public QueryListResponseResult<Role> getUserPermRole(@PathVariable("userId") String userId) {
        List<Role> list = roleService.getUserPermRole(userId);
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @Override
    @GetMapping("/find/page/{page}/{size}")
    public QueryPageResponseResult<Role> findPageList(@PathVariable("page") int page, @PathVariable("size") int size, RoleRequest roleRequest) {
        return roleService.findPageList(page, size, roleRequest);
    }
 
    @Override
    @GetMapping("/get/menu/button/{roleId}")
    public QueryListResponseResult<CommonJsonTree> getMenuButtonTree(@PathVariable("roleId") String roleId) {
        List<CommonJsonTree> commonJsonTree = roleService.getMenuButtonTree(roleId);
        if(commonJsonTree == null)
            commonJsonTree = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, commonJsonTree);
    }
 
    @Override
    @GetMapping("/get/object/button/{roleId}")
    public QueryListResponseResult<CommonJsonTree> getObjectButtonTree(@PathVariable("roleId") String roleId) {
        List<CommonJsonTree> commonJsonTree = roleService.getObjectButtonTree(roleId);
        if(commonJsonTree == null)
            commonJsonTree = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, commonJsonTree);
    }
 
    @Override
    @GetMapping("/get/menu/{roleId}")
    public QueryListResponseResult<CommonJsonTree> getMenuTree(@PathVariable("roleId") String roleId) {
        List<CommonJsonTree> commonJsonTree = roleService.getMenuTree(roleId);
        if(commonJsonTree == null)
            commonJsonTree = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, commonJsonTree);
    }
 
    @Override
    @GetMapping("/list/all")
    public QueryListResponseResult<Role> getRoleList() {
        List<Role> list = roleService.list();
        if(list == null)
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
 
    @Override
    @DeleteMapping("/delete")
    public ResponseResult deleteRole(@RequestParam("id") String id) {
        boolean b = roleService.deleteRole(id);
        if(b) {
            return new ResponseResult(CommonCode.SUCCESS);
        }
        return new ResponseResult(CommonCode.FAIL);
    }
}