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