|
@@ -1,18 +1,5 @@
|
|
package com.ruoyi.web.controller.system;
|
|
package com.ruoyi.web.controller.system;
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
import com.ruoyi.common.annotation.Log;
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
@@ -29,32 +16,44 @@ import com.ruoyi.framework.web.service.TokenService;
|
|
import com.ruoyi.system.domain.SysUserRole;
|
|
import com.ruoyi.system.domain.SysUserRole;
|
|
import com.ruoyi.system.service.ISysRoleService;
|
|
import com.ruoyi.system.service.ISysRoleService;
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 角色信息
|
|
* 角色信息
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @author ruoyi
|
|
* @author ruoyi
|
|
*/
|
|
*/
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/system/role")
|
|
@RequestMapping("/system/role")
|
|
-public class SysRoleController extends BaseController
|
|
|
|
-{
|
|
|
|
|
|
+public class SysRoleController extends BaseController {
|
|
@Autowired
|
|
@Autowired
|
|
private ISysRoleService roleService;
|
|
private ISysRoleService roleService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private TokenService tokenService;
|
|
private TokenService tokenService;
|
|
-
|
|
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private SysPermissionService permissionService;
|
|
private SysPermissionService permissionService;
|
|
-
|
|
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private ISysUserService userService;
|
|
private ISysUserService userService;
|
|
|
|
|
|
@PreAuthorize("@ss.hasPermi('system:role:list')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:list')")
|
|
@GetMapping("/list")
|
|
@GetMapping("/list")
|
|
- public TableDataInfo list(SysRole role)
|
|
|
|
- {
|
|
|
|
|
|
+ public TableDataInfo list(SysRole role) {
|
|
startPage();
|
|
startPage();
|
|
List<SysRole> list = roleService.selectRoleList(role);
|
|
List<SysRole> list = roleService.selectRoleList(role);
|
|
return getDataTable(list);
|
|
return getDataTable(list);
|
|
@@ -63,8 +62,7 @@ public class SysRoleController extends BaseController
|
|
@Log(title = "角色管理", businessType = BusinessType.EXPORT)
|
|
@Log(title = "角色管理", businessType = BusinessType.EXPORT)
|
|
@PreAuthorize("@ss.hasPermi('system:role:export')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:export')")
|
|
@PostMapping("/export")
|
|
@PostMapping("/export")
|
|
- public void export(HttpServletResponse response, SysRole role)
|
|
|
|
- {
|
|
|
|
|
|
+ public void export(HttpServletResponse response, SysRole role) {
|
|
List<SysRole> list = roleService.selectRoleList(role);
|
|
List<SysRole> list = roleService.selectRoleList(role);
|
|
ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
|
|
ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
|
|
util.exportExcel(response, list, "角色数据");
|
|
util.exportExcel(response, list, "角色数据");
|
|
@@ -75,8 +73,7 @@ public class SysRoleController extends BaseController
|
|
*/
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:role:query')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:query')")
|
|
@GetMapping(value = "/{roleId}")
|
|
@GetMapping(value = "/{roleId}")
|
|
- public AjaxResult getInfo(@PathVariable Long roleId)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult getInfo(@PathVariable Long roleId) {
|
|
roleService.checkRoleDataScope(roleId);
|
|
roleService.checkRoleDataScope(roleId);
|
|
return AjaxResult.success(roleService.selectRoleById(roleId));
|
|
return AjaxResult.success(roleService.selectRoleById(roleId));
|
|
}
|
|
}
|
|
@@ -87,14 +84,10 @@ public class SysRoleController extends BaseController
|
|
@PreAuthorize("@ss.hasPermi('system:role:add')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:add')")
|
|
@Log(title = "角色管理", businessType = BusinessType.INSERT)
|
|
@Log(title = "角色管理", businessType = BusinessType.INSERT)
|
|
@PostMapping
|
|
@PostMapping
|
|
- public AjaxResult add(@Validated @RequestBody SysRole role)
|
|
|
|
- {
|
|
|
|
- if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult add(@Validated @RequestBody SysRole role) {
|
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) {
|
|
return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
|
return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
|
- }
|
|
|
|
- else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
|
|
|
|
- {
|
|
|
|
|
|
+ } else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) {
|
|
return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
|
return AjaxResult.error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
|
}
|
|
}
|
|
role.setCreateBy(getUsername());
|
|
role.setCreateBy(getUsername());
|
|
@@ -108,26 +101,20 @@ public class SysRoleController extends BaseController
|
|
@PreAuthorize("@ss.hasPermi('system:role:edit')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:edit')")
|
|
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
|
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
|
@PutMapping
|
|
@PutMapping
|
|
- public AjaxResult edit(@Validated @RequestBody SysRole role)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult edit(@Validated @RequestBody SysRole role) {
|
|
roleService.checkRoleAllowed(role);
|
|
roleService.checkRoleAllowed(role);
|
|
roleService.checkRoleDataScope(role.getRoleId());
|
|
roleService.checkRoleDataScope(role.getRoleId());
|
|
- if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
|
|
|
|
- {
|
|
|
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) {
|
|
return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
|
return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
|
- }
|
|
|
|
- else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
|
|
|
|
- {
|
|
|
|
|
|
+ } else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) {
|
|
return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
|
return AjaxResult.error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
|
}
|
|
}
|
|
role.setUpdateBy(getUsername());
|
|
role.setUpdateBy(getUsername());
|
|
-
|
|
|
|
- if (roleService.updateRole(role) > 0)
|
|
|
|
- {
|
|
|
|
|
|
+
|
|
|
|
+ if (roleService.updateRole(role) > 0) {
|
|
// 更新缓存用户权限
|
|
// 更新缓存用户权限
|
|
LoginUser loginUser = getLoginUser();
|
|
LoginUser loginUser = getLoginUser();
|
|
- if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin())
|
|
|
|
- {
|
|
|
|
|
|
+ if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) {
|
|
loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
|
|
loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
|
|
loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
|
|
loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
|
|
tokenService.setLoginUser(loginUser);
|
|
tokenService.setLoginUser(loginUser);
|
|
@@ -143,8 +130,7 @@ public class SysRoleController extends BaseController
|
|
@PreAuthorize("@ss.hasPermi('system:role:edit')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:edit')")
|
|
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
|
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
|
@PutMapping("/dataScope")
|
|
@PutMapping("/dataScope")
|
|
- public AjaxResult dataScope(@RequestBody SysRole role)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult dataScope(@RequestBody SysRole role) {
|
|
roleService.checkRoleAllowed(role);
|
|
roleService.checkRoleAllowed(role);
|
|
roleService.checkRoleDataScope(role.getRoleId());
|
|
roleService.checkRoleDataScope(role.getRoleId());
|
|
return toAjax(roleService.authDataScope(role));
|
|
return toAjax(roleService.authDataScope(role));
|
|
@@ -156,8 +142,7 @@ public class SysRoleController extends BaseController
|
|
@PreAuthorize("@ss.hasPermi('system:role:edit')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:edit')")
|
|
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
|
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
|
@PutMapping("/changeStatus")
|
|
@PutMapping("/changeStatus")
|
|
- public AjaxResult changeStatus(@RequestBody SysRole role)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult changeStatus(@RequestBody SysRole role) {
|
|
roleService.checkRoleAllowed(role);
|
|
roleService.checkRoleAllowed(role);
|
|
roleService.checkRoleDataScope(role.getRoleId());
|
|
roleService.checkRoleDataScope(role.getRoleId());
|
|
role.setUpdateBy(getUsername());
|
|
role.setUpdateBy(getUsername());
|
|
@@ -170,8 +155,7 @@ public class SysRoleController extends BaseController
|
|
@PreAuthorize("@ss.hasPermi('system:role:remove')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:remove')")
|
|
@Log(title = "角色管理", businessType = BusinessType.DELETE)
|
|
@Log(title = "角色管理", businessType = BusinessType.DELETE)
|
|
@DeleteMapping("/{roleIds}")
|
|
@DeleteMapping("/{roleIds}")
|
|
- public AjaxResult remove(@PathVariable Long[] roleIds)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult remove(@PathVariable Long[] roleIds) {
|
|
return toAjax(roleService.deleteRoleByIds(roleIds));
|
|
return toAjax(roleService.deleteRoleByIds(roleIds));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -180,18 +164,16 @@ public class SysRoleController extends BaseController
|
|
*/
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:role:query')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:query')")
|
|
@GetMapping("/optionselect")
|
|
@GetMapping("/optionselect")
|
|
- public AjaxResult optionselect()
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult optionselect() {
|
|
return AjaxResult.success(roleService.selectRoleAll());
|
|
return AjaxResult.success(roleService.selectRoleAll());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询已分配用户角色列表
|
|
* 查询已分配用户角色列表
|
|
*/
|
|
*/
|
|
- @PreAuthorize("@ss.hasPermi('system:role:list')")
|
|
|
|
|
|
+// @PreAuthorize("@ss.hasPermi('system:role:list')")
|
|
@GetMapping("/authUser/allocatedList")
|
|
@GetMapping("/authUser/allocatedList")
|
|
- public TableDataInfo allocatedList(SysUser user)
|
|
|
|
- {
|
|
|
|
|
|
+ public TableDataInfo allocatedList(SysUser user) {
|
|
startPage();
|
|
startPage();
|
|
List<SysUser> list = userService.selectAllocatedList(user);
|
|
List<SysUser> list = userService.selectAllocatedList(user);
|
|
return getDataTable(list);
|
|
return getDataTable(list);
|
|
@@ -202,8 +184,7 @@ public class SysRoleController extends BaseController
|
|
*/
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:role:list')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:list')")
|
|
@GetMapping("/authUser/unallocatedList")
|
|
@GetMapping("/authUser/unallocatedList")
|
|
- public TableDataInfo unallocatedList(SysUser user)
|
|
|
|
- {
|
|
|
|
|
|
+ public TableDataInfo unallocatedList(SysUser user) {
|
|
startPage();
|
|
startPage();
|
|
List<SysUser> list = userService.selectUnallocatedList(user);
|
|
List<SysUser> list = userService.selectUnallocatedList(user);
|
|
return getDataTable(list);
|
|
return getDataTable(list);
|
|
@@ -215,8 +196,7 @@ public class SysRoleController extends BaseController
|
|
@PreAuthorize("@ss.hasPermi('system:role:edit')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:edit')")
|
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
|
@PutMapping("/authUser/cancel")
|
|
@PutMapping("/authUser/cancel")
|
|
- public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) {
|
|
return toAjax(roleService.deleteAuthUser(userRole));
|
|
return toAjax(roleService.deleteAuthUser(userRole));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -226,8 +206,7 @@ public class SysRoleController extends BaseController
|
|
@PreAuthorize("@ss.hasPermi('system:role:edit')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:edit')")
|
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
|
@PutMapping("/authUser/cancelAll")
|
|
@PutMapping("/authUser/cancelAll")
|
|
- public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) {
|
|
return toAjax(roleService.deleteAuthUsers(roleId, userIds));
|
|
return toAjax(roleService.deleteAuthUsers(roleId, userIds));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -237,8 +216,7 @@ public class SysRoleController extends BaseController
|
|
@PreAuthorize("@ss.hasPermi('system:role:edit')")
|
|
@PreAuthorize("@ss.hasPermi('system:role:edit')")
|
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
|
@PutMapping("/authUser/selectAll")
|
|
@PutMapping("/authUser/selectAll")
|
|
- public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) {
|
|
roleService.checkRoleDataScope(roleId);
|
|
roleService.checkRoleDataScope(roleId);
|
|
return toAjax(roleService.insertAuthUsers(roleId, userIds));
|
|
return toAjax(roleService.insertAuthUsers(roleId, userIds));
|
|
}
|
|
}
|