提交 | 用户 | 时间
|
722af2
|
1 |
package com.dl.web.controller.system; |
X |
2 |
|
|
3 |
import cn.dev33.satoken.annotation.SaCheckPermission; |
|
4 |
import com.dl.common.annotation.Log; |
|
5 |
import com.dl.common.core.controller.BaseController; |
|
6 |
import com.dl.common.core.domain.PageQuery; |
|
7 |
import com.dl.common.core.domain.R; |
|
8 |
import com.dl.common.core.domain.entity.SysDept; |
|
9 |
import com.dl.common.core.domain.entity.SysRole; |
|
10 |
import com.dl.common.core.domain.entity.SysUser; |
|
11 |
import com.dl.common.core.page.TableDataInfo; |
|
12 |
import com.dl.common.enums.BusinessType; |
|
13 |
import com.dl.common.utils.poi.ExcelUtil; |
|
14 |
import com.dl.system.domain.SysUserRole; |
|
15 |
import com.dl.system.service.ISysDeptService; |
|
16 |
import com.dl.system.service.ISysRoleService; |
|
17 |
import com.dl.system.service.ISysUserService; |
|
18 |
import com.dl.system.service.SysPermissionService; |
|
19 |
import lombok.RequiredArgsConstructor; |
|
20 |
import org.springframework.validation.annotation.Validated; |
|
21 |
import org.springframework.web.bind.annotation.*; |
|
22 |
|
|
23 |
import javax.servlet.http.HttpServletResponse; |
|
24 |
import java.util.HashMap; |
|
25 |
import java.util.List; |
|
26 |
import java.util.Map; |
|
27 |
|
|
28 |
/** |
|
29 |
* 角色信息 |
|
30 |
* |
|
31 |
* @author Lion Li |
|
32 |
*/ |
|
33 |
@Validated |
|
34 |
@RequiredArgsConstructor |
|
35 |
@RestController |
|
36 |
@RequestMapping("/system/role") |
|
37 |
public class SysRoleController extends BaseController { |
|
38 |
|
|
39 |
private final ISysRoleService roleService; |
|
40 |
private final ISysUserService userService; |
|
41 |
private final ISysDeptService deptService; |
|
42 |
private final SysPermissionService permissionService; |
|
43 |
|
|
44 |
/** |
|
45 |
* 获取角色信息列表 |
|
46 |
*/ |
|
47 |
@SaCheckPermission("system:role:list") |
|
48 |
@GetMapping("/list") |
|
49 |
public TableDataInfo<SysRole> list(SysRole role, PageQuery pageQuery) { |
|
50 |
return roleService.selectPageRoleList(role, pageQuery); |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* 导出角色信息列表 |
|
55 |
*/ |
|
56 |
@Log(title = "角色管理", businessType = BusinessType.EXPORT) |
|
57 |
@SaCheckPermission("system:role:export") |
|
58 |
@PostMapping("/export") |
|
59 |
public void export(SysRole role, HttpServletResponse response) { |
|
60 |
List<SysRole> list = roleService.selectRoleList(role); |
|
61 |
ExcelUtil.exportExcel(list, "角色数据", SysRole.class, response); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* 根据角色编号获取详细信息 |
|
66 |
* |
|
67 |
* @param roleId 角色ID |
|
68 |
*/ |
|
69 |
@SaCheckPermission("system:role:query") |
|
70 |
@GetMapping(value = "/{roleId}") |
|
71 |
public R<SysRole> getInfo(@PathVariable String roleId) { |
|
72 |
roleService.checkRoleDataScope(roleId); |
|
73 |
return R.ok(roleService.selectRoleById(roleId)); |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* 新增角色 |
|
78 |
*/ |
|
79 |
@SaCheckPermission("system:role:add") |
|
80 |
@Log(title = "角色管理", businessType = BusinessType.INSERT) |
|
81 |
@PostMapping |
|
82 |
public R<Void> add(@Validated @RequestBody SysRole role) { |
|
83 |
if (!roleService.checkRoleNameUnique(role)) { |
|
84 |
return R.fail("新增角色'" + role.getRoleName() + "'失败,角色名称已存在"); |
|
85 |
} else if (!roleService.checkRoleKeyUnique(role)) { |
|
86 |
return R.fail("新增角色'" + role.getRoleName() + "'失败,角色权限已存在"); |
|
87 |
} |
|
88 |
return toAjax(roleService.insertRole(role)); |
|
89 |
|
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* 修改保存角色 |
|
94 |
*/ |
|
95 |
@SaCheckPermission("system:role:edit") |
|
96 |
@Log(title = "角色管理", businessType = BusinessType.UPDATE) |
|
97 |
@PutMapping |
|
98 |
public R<Void> edit(@Validated @RequestBody SysRole role) { |
|
99 |
roleService.checkRoleAllowed(role); |
|
100 |
roleService.checkRoleDataScope(role.getRoleId()); |
|
101 |
if (!roleService.checkRoleNameUnique(role)) { |
|
102 |
return R.fail("修改角色'" + role.getRoleName() + "'失败,角色名称已存在"); |
|
103 |
} else if (!roleService.checkRoleKeyUnique(role)) { |
|
104 |
return R.fail("修改角色'" + role.getRoleName() + "'失败,角色权限已存在"); |
|
105 |
} |
|
106 |
|
|
107 |
if (roleService.updateRole(role) > 0) { |
|
108 |
roleService.cleanOnlineUserByRole(role.getRoleId()); |
|
109 |
return R.ok(); |
|
110 |
} |
|
111 |
return R.fail("修改角色'" + role.getRoleName() + "'失败,请联系管理员"); |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* 修改保存数据权限 |
|
116 |
*/ |
|
117 |
@SaCheckPermission("system:role:edit") |
|
118 |
@Log(title = "角色管理", businessType = BusinessType.UPDATE) |
|
119 |
@PutMapping("/dataScope") |
|
120 |
public R<Void> dataScope(@RequestBody SysRole role) { |
|
121 |
roleService.checkRoleAllowed(role); |
|
122 |
roleService.checkRoleDataScope(role.getRoleId()); |
|
123 |
return toAjax(roleService.authDataScope(role)); |
|
124 |
} |
|
125 |
|
|
126 |
/** |
|
127 |
* 状态修改 |
|
128 |
*/ |
|
129 |
@SaCheckPermission("system:role:edit") |
|
130 |
@Log(title = "角色管理", businessType = BusinessType.UPDATE) |
|
131 |
@PutMapping("/changeStatus") |
|
132 |
public R<Void> changeStatus(@RequestBody SysRole role) { |
|
133 |
roleService.checkRoleAllowed(role); |
|
134 |
roleService.checkRoleDataScope(role.getRoleId()); |
|
135 |
return toAjax(roleService.updateRoleStatus(role)); |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* 删除角色 |
|
140 |
* |
|
141 |
* @param roleIds 角色ID串 |
|
142 |
*/ |
|
143 |
@SaCheckPermission("system:role:remove") |
|
144 |
@Log(title = "角色管理", businessType = BusinessType.DELETE) |
|
145 |
@DeleteMapping("/{roleIds}") |
|
146 |
public R<Void> remove(@PathVariable String[] roleIds) { |
|
147 |
return toAjax(roleService.deleteRoleByIds(roleIds)); |
|
148 |
} |
|
149 |
|
|
150 |
/** |
|
151 |
* 获取角色选择框列表 |
|
152 |
*/ |
|
153 |
@SaCheckPermission("system:role:query") |
|
154 |
@GetMapping("/optionselect") |
|
155 |
public R<List<SysRole>> optionselect() { |
|
156 |
return R.ok(roleService.selectRoleAll()); |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* 查询已分配用户角色列表 |
|
161 |
*/ |
|
162 |
@SaCheckPermission("system:role:list") |
|
163 |
@GetMapping("/authUser/allocatedList") |
|
164 |
public TableDataInfo<SysUser> allocatedList(SysUser user, PageQuery pageQuery) { |
|
165 |
return userService.selectAllocatedList(user, pageQuery); |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* 查询未分配用户角色列表 |
|
170 |
*/ |
|
171 |
@SaCheckPermission("system:role:list") |
|
172 |
@GetMapping("/authUser/unallocatedList") |
|
173 |
public TableDataInfo<SysUser> unallocatedList(SysUser user, PageQuery pageQuery) { |
|
174 |
return userService.selectUnallocatedList(user, pageQuery); |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* 取消授权用户 |
|
179 |
*/ |
|
180 |
@SaCheckPermission("system:role:edit") |
|
181 |
@Log(title = "角色管理", businessType = BusinessType.GRANT) |
|
182 |
@PutMapping("/authUser/cancel") |
|
183 |
public R<Void> cancelAuthUser(@RequestBody SysUserRole userRole) { |
|
184 |
return toAjax(roleService.deleteAuthUser(userRole)); |
|
185 |
} |
|
186 |
|
|
187 |
/** |
|
188 |
* 批量取消授权用户 |
|
189 |
* |
|
190 |
* @param roleId 角色ID |
|
191 |
* @param userIds 用户ID串 |
|
192 |
*/ |
|
193 |
@SaCheckPermission("system:role:edit") |
|
194 |
@Log(title = "角色管理", businessType = BusinessType.GRANT) |
|
195 |
@PutMapping("/authUser/cancelAll") |
|
196 |
public R<Void> cancelAuthUserAll(String roleId, String[] userIds) { |
|
197 |
return toAjax(roleService.deleteAuthUsers(roleId, userIds)); |
|
198 |
} |
|
199 |
|
|
200 |
/** |
|
201 |
* 批量选择用户授权 |
|
202 |
* |
|
203 |
* @param roleId 角色ID |
|
204 |
* @param userIds 用户ID串 |
|
205 |
*/ |
|
206 |
@SaCheckPermission("system:role:edit") |
|
207 |
@Log(title = "角色管理", businessType = BusinessType.GRANT) |
|
208 |
@PutMapping("/authUser/selectAll") |
|
209 |
public R<Void> selectAuthUserAll(String roleId, String[] userIds) { |
|
210 |
roleService.checkRoleDataScope(roleId); |
|
211 |
return toAjax(roleService.insertAuthUsers(roleId, userIds)); |
|
212 |
} |
|
213 |
|
|
214 |
/** |
|
215 |
* 获取对应角色部门树列表 |
|
216 |
* |
|
217 |
* @param roleId 角色ID |
|
218 |
*/ |
|
219 |
@SaCheckPermission("system:role:list") |
|
220 |
@GetMapping(value = "/deptTree/{roleId}") |
|
221 |
public R<Map<String, Object>> roleDeptTreeselect(@PathVariable("roleId") String roleId) { |
|
222 |
Map<String, Object> ajax = new HashMap<>(); |
|
223 |
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); |
|
224 |
ajax.put("depts", deptService.selectDeptTreeList(new SysDept())); |
|
225 |
return R.ok(ajax); |
|
226 |
} |
|
227 |
} |