소스 검색

修改保存角色修改

gao.qiang 1 년 전
부모
커밋
d48082ea6d
1개의 변경된 파일29개의 추가작업 그리고 50개의 파일을 삭제
  1. 29 50
      hazard-admin/src/main/java/com/ozs/web/controller/system/SysRoleController.java

+ 29 - 50
hazard-admin/src/main/java/com/ozs/web/controller/system/SysRoleController.java

@@ -59,8 +59,7 @@ import com.ozs.system.service.ISysUserService;
  */
 @RestController
 @RequestMapping("/system/role")
-public class SysRoleController extends BaseController
-{
+public class SysRoleController extends BaseController {
     @Autowired
     private ISysRoleService roleService;
 
@@ -97,7 +96,7 @@ public class SysRoleController extends BaseController
     @Log(title = "角色管理", businessType = BusinessType.SELECT)
     public AjaxResult page(@NotEmpty(message = "数据为空")
                            @RequestBody SysRoleRequestVo vo) {
-        vo= (SysRoleRequestVo) dataScoreUtil.setDataScore(getUserId(),vo);
+        vo = (SysRoleRequestVo) dataScoreUtil.setDataScore(getUserId(), vo);
         IPage<SysRole> page = roleService.queryPage(vo);
         page.setTotal(page.getTotal());
         page.setCurrent(page.getCurrent());
@@ -109,8 +108,7 @@ public class SysRoleController extends BaseController
     @Log(title = "角色管理", businessType = BusinessType.EXPORT)
     @PreAuthorize("@ss.hasPermi('system:role:export')")
     @PostMapping("/export")
-    public void export(HttpServletResponse response, SysRole role)
-    {
+    public void export(HttpServletResponse response, SysRole role) {
         List<SysRole> list = roleService.selectRoleList(role);
         ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
         util.exportExcel(response, list, "角色数据");
@@ -122,16 +120,15 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:query')")
     @GetMapping(value = "/{roleId}")
     @Log(title = "角色管理", businessType = BusinessType.MESSAGE)
-    public AjaxResult getInfo(@PathVariable Long roleId)
-    {
+    public AjaxResult getInfo(@PathVariable Long roleId) {
 //        roleService.checkRoleDataScope(roleId);
         SysRole sysRole = roleService.selectRoleById(roleId);
-        if (sysRole.getRoleKey().equals(("admin"))){
+        if (sysRole.getRoleKey().equals(("admin"))) {
             List<SysMenu> list = menuService.list();
             List<Long> collect = list.stream().map(SysMenu::getMenuId).collect(Collectors.toList());
             Long[] strArr = collect.toArray(new Long[collect.size()]);
             sysRole.setMenuIds(strArr);
-        }else {
+        } else {
             List<Long> rolePerms = menuService.selectMenu(sysRole.getRoleId());
             Long[] strArr = rolePerms.toArray(new Long[rolePerms.size()]);
             sysRole.setMenuIds(strArr);
@@ -145,14 +142,10 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:add')")
     @Log(title = "角色管理", businessType = BusinessType.INSERT)
     @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 error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
-        }
-        else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
-        {
+        } else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) {
             return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
         }
         role.setCreateBy(getUserId());
@@ -167,35 +160,31 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@Validated @RequestBody SysRole role)
-    {
+    public AjaxResult edit(@Validated @RequestBody SysRole role) {
 //        roleService.checkRoleAllowed(role);
 //        roleService.checkRoleDataScope(role.getRoleId());
-        BaseUser baseUser = baseUserService.getUser(getUserId());
-        if ("admin".equals(baseUser.getUserName())) {
+        String roleKey = roleService.getRoleKey(role.getRoleId());
+        if ("admin".equals(roleKey)) {
             if (!ObjectUtils.isEmpty(role.getRoleKey())) {
                 role.setRoleKey("admin");
             }
             if (!ObjectUtils.isEmpty(role.getStatus())) {
                 role.setStatus("1");
             }
+        } else {
+            if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role))) {
+                return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
+            }
         }
-        if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
-        {
+        if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) {
             return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
         }
-        else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
-        {
-            return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
-        }
         role.setUpdateBy(getUserId());
 
-        if (roleService.updateRole(role) > 0)
-        {
+        if (roleService.updateRole(role) > 0) {
             // 更新缓存用户权限
             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.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
                 tokenService.setLoginUser(loginUser);
@@ -211,8 +200,7 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.UPDATE)
     @PutMapping("/dataScope")
-    public AjaxResult dataScope(@RequestBody SysRole role)
-    {
+    public AjaxResult dataScope(@RequestBody SysRole role) {
         roleService.checkRoleAllowed(role);
         roleService.checkRoleDataScope(role.getRoleId());
         return toAjax(roleService.authDataScope(role));
@@ -224,8 +212,7 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.UPDATE)
     @PutMapping("/changeStatus")
-    public AjaxResult changeStatus(@RequestBody SysRole role)
-    {
+    public AjaxResult changeStatus(@RequestBody SysRole role) {
         roleService.checkRoleAllowed(role);
         roleService.checkRoleDataScope(role.getRoleId());
         role.setUpdateBy(getUsername());
@@ -238,8 +225,7 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:remove')")
     @Log(title = "角色管理", businessType = BusinessType.DELETE)
     @DeleteMapping("/{roleIds}")
-    public AjaxResult remove(@PathVariable Long[] roleIds)
-    {
+    public AjaxResult remove(@PathVariable Long[] roleIds) {
         return toAjax(roleService.deleteRoleByIds(roleIds));
     }
 
@@ -249,8 +235,7 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:query')")
     @GetMapping("/optionselect")
     @Log(title = "角色管理", businessType = BusinessType.OTHER)
-    public AjaxResult optionselect()
-    {
+    public AjaxResult optionselect() {
         return success(roleService.selectRoleAll());
     }
 
@@ -260,8 +245,7 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:list')")
     @GetMapping("/authUser/allocatedList")
     @Log(title = "角色管理", businessType = BusinessType.SELECT)
-    public TableDataInfo allocatedList(SysUser user)
-    {
+    public TableDataInfo allocatedList(SysUser user) {
         startPage();
         List<SysUser> list = userService.selectAllocatedList(user);
         return getDataTable(list);
@@ -273,8 +257,7 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:list')")
     @GetMapping("/authUser/unallocatedList")
     @Log(title = "角色管理", businessType = BusinessType.SELECT)
-    public TableDataInfo unallocatedList(SysUser user)
-    {
+    public TableDataInfo unallocatedList(SysUser user) {
         startPage();
         List<SysUser> list = userService.selectUnallocatedList(user);
         return getDataTable(list);
@@ -286,8 +269,7 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.GRANT)
     @PutMapping("/authUser/cancel")
-    public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole)
-    {
+    public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) {
         return toAjax(roleService.deleteAuthUser(userRole));
     }
 
@@ -297,8 +279,7 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.GRANT)
     @PutMapping("/authUser/cancelAll")
-    public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
-    {
+    public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) {
         return toAjax(roleService.deleteAuthUsers(roleId, userIds));
     }
 
@@ -308,8 +289,7 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.GRANT)
     @PutMapping("/authUser/selectAll")
-    public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
-    {
+    public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) {
         roleService.checkRoleDataScope(roleId);
         return toAjax(roleService.insertAuthUsers(roleId, userIds));
     }
@@ -320,8 +300,7 @@ public class SysRoleController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:role:query')")
     @GetMapping(value = "/deptTree/{roleId}")
     @Log(title = "角色管理", businessType = BusinessType.OTHER)
-    public AjaxResult deptTree(@PathVariable("roleId") Long roleId)
-    {
+    public AjaxResult deptTree(@PathVariable("roleId") Long roleId) {
         AjaxResult ajax = AjaxResult.success();
         ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
         ajax.put("depts", deptService.selectDeptTreeList(new SysDept()));