From 925219ebfda2a480df99ca06a13033c78ae8d81f Mon Sep 17 00:00:00 2001
From: huliguo <2023611923@qq.com>
Date: 星期五, 30 五月 2025 18:08:16 +0800
Subject: [PATCH] 权限管理+用户管理

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java |  159 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 122 insertions(+), 37 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java
index 42d9e8f..4b00660 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java
@@ -2,17 +2,23 @@
 
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
+import javax.validation.Valid;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.system.pojo.dto.AddSysRoleDTO;
+import com.ruoyi.system.pojo.dto.EditSysRoleDTO;
+import com.ruoyi.system.pojo.vo.MenuTreeVO;
+import com.ruoyi.system.pojo.vo.SysRolePageVO;
+import com.ruoyi.system.pojo.vo.SysRoleVO;
+import com.ruoyi.system.service.ISysMenuService;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.security.core.context.SecurityContextHolder;
 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 org.springframework.web.bind.annotation.*;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -55,16 +61,16 @@
     @Autowired
     private ISysDeptService deptService;
 
-    @PreAuthorize("@ss.hasPermi('system:role:list')")
+  /*  @PreAuthorize("@ss.hasPermi('system:role:list')")
     @GetMapping("/list")
     public TableDataInfo list(SysRole role)
     {
         startPage();
         List<SysRole> list = roleService.selectRoleList(role);
         return getDataTable(list);
-    }
+    }*/
 
-    @Log(title = "角色管理", businessType = BusinessType.EXPORT)
+   /* @Log(title = "角色管理", businessType = BusinessType.EXPORT)
     @PreAuthorize("@ss.hasPermi('system:role:export')")
     @PostMapping("/export")
     public void export(HttpServletResponse response, SysRole role)
@@ -72,23 +78,23 @@
         List<SysRole> list = roleService.selectRoleList(role);
         ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
         util.exportExcel(response, list, "角色数据");
-    }
+    }*/
 
     /**
      * 根据角色编号获取详细信息
      */
-    @PreAuthorize("@ss.hasPermi('system:role:query')")
+  /*  @PreAuthorize("@ss.hasPermi('system:role:query')")
     @GetMapping(value = "/{roleId}")
     public AjaxResult getInfo(@PathVariable Long roleId)
     {
         roleService.checkRoleDataScope(roleId);
         return success(roleService.selectRoleById(roleId));
     }
-
+*/
     /**
      * 新增角色
      */
-    @PreAuthorize("@ss.hasPermi('system:role:add')")
+   /* @PreAuthorize("@ss.hasPermi('system:role:add')")
     @Log(title = "角色管理", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@Validated @RequestBody SysRole role)
@@ -104,12 +110,12 @@
         role.setCreateBy(getUsername());
         return toAjax(roleService.insertRole(role));
 
-    }
+    }*/
 
     /**
      * 修改保存角色
      */
-    @PreAuthorize("@ss.hasPermi('system:role:edit')")
+   /* @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.UPDATE)
     @PutMapping
     public AjaxResult edit(@Validated @RequestBody SysRole role)
@@ -139,12 +145,12 @@
             return success();
         }
         return error("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
-    }
+    }*/
 
     /**
      * 修改保存数据权限
      */
-    @PreAuthorize("@ss.hasPermi('system:role:edit')")
+    /*@PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.UPDATE)
     @PutMapping("/dataScope")
     public AjaxResult dataScope(@RequestBody SysRole role)
@@ -152,12 +158,12 @@
         roleService.checkRoleAllowed(role);
         roleService.checkRoleDataScope(role.getRoleId());
         return toAjax(roleService.authDataScope(role));
-    }
+    }*/
 
     /**
      * 状态修改
      */
-    @PreAuthorize("@ss.hasPermi('system:role:edit')")
+    /*@PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.UPDATE)
     @PutMapping("/changeStatus")
     public AjaxResult changeStatus(@RequestBody SysRole role)
@@ -166,45 +172,45 @@
         roleService.checkRoleDataScope(role.getRoleId());
         role.setUpdateBy(getUsername());
         return toAjax(roleService.updateRoleStatus(role));
-    }
+    }*/
 
     /**
      * 删除角色
      */
-    @PreAuthorize("@ss.hasPermi('system:role:remove')")
+ /*   @PreAuthorize("@ss.hasPermi('system:role:remove')")
     @Log(title = "角色管理", businessType = BusinessType.DELETE)
     @DeleteMapping("/{roleIds}")
     public AjaxResult remove(@PathVariable Long[] roleIds)
     {
         return toAjax(roleService.deleteRoleByIds(roleIds));
-    }
+    }*/
 
     /**
      * 获取角色选择框列表
      */
-    @PreAuthorize("@ss.hasPermi('system:role:query')")
+   /* @PreAuthorize("@ss.hasPermi('system:role:query')")
     @GetMapping("/optionselect")
     public AjaxResult optionselect()
     {
         return success(roleService.selectRoleAll());
-    }
+    }*/
 
     /**
      * 查询已分配用户角色列表
      */
-    @PreAuthorize("@ss.hasPermi('system:role:list')")
+   /* @PreAuthorize("@ss.hasPermi('system:role:list')")
     @GetMapping("/authUser/allocatedList")
     public TableDataInfo allocatedList(SysUser user)
     {
         startPage();
         List<SysUser> list = userService.selectAllocatedList(user);
         return getDataTable(list);
-    }
+    }*/
 
     /**
      * 查询未分配用户角色列表
      */
-    @PreAuthorize("@ss.hasPermi('system:role:list')")
+  /*  @PreAuthorize("@ss.hasPermi('system:role:list')")
     @GetMapping("/authUser/unallocatedList")
     public TableDataInfo unallocatedList(SysUser user)
     {
@@ -212,45 +218,45 @@
         List<SysUser> list = userService.selectUnallocatedList(user);
         return getDataTable(list);
     }
-
+*/
     /**
      * 取消授权用户
      */
-    @PreAuthorize("@ss.hasPermi('system:role:edit')")
+    /*@PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.GRANT)
     @PutMapping("/authUser/cancel")
     public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole)
     {
         return toAjax(roleService.deleteAuthUser(userRole));
     }
-
+*/
     /**
      * 批量取消授权用户
      */
-    @PreAuthorize("@ss.hasPermi('system:role:edit')")
+   /* @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.GRANT)
     @PutMapping("/authUser/cancelAll")
     public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
     {
         return toAjax(roleService.deleteAuthUsers(roleId, userIds));
-    }
+    }*/
 
     /**
      * 批量选择用户授权
      */
-    @PreAuthorize("@ss.hasPermi('system:role:edit')")
+  /*  @PreAuthorize("@ss.hasPermi('system:role:edit')")
     @Log(title = "角色管理", businessType = BusinessType.GRANT)
     @PutMapping("/authUser/selectAll")
     public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
     {
         roleService.checkRoleDataScope(roleId);
         return toAjax(roleService.insertAuthUsers(roleId, userIds));
-    }
+    }*/
 
     /**
      * 获取对应角色部门树列表
      */
-    @PreAuthorize("@ss.hasPermi('system:role:query')")
+   /* @PreAuthorize("@ss.hasPermi('system:role:query')")
     @GetMapping(value = "/deptTree/{roleId}")
     public AjaxResult deptTree(@PathVariable("roleId") Long roleId)
     {
@@ -258,5 +264,84 @@
         ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
         ajax.put("depts", deptService.selectDeptTreeList(new SysDept()));
         return ajax;
+    }*/
+
+    /**
+     * 分页查询
+     */
+
+    @GetMapping("/page")
+    @PreAuthorize("@ss.hasPermi('permission:role')")
+    @ApiOperation(value = "角色管理-分页列表", tags = "系统后台-权限管理")
+    public R<IPage<SysRolePageVO>> page(@RequestParam(value = "pageNum",defaultValue = "0")Integer pageNum,
+                                        @RequestParam(value = "pageSize",defaultValue="10")Integer pageSize,
+                                        @RequestParam(value = "name",required = false)String name) {
+        IPage<SysRolePageVO> iPage = new Page<>(pageNum, pageSize);
+        return R.ok(roleService.page(iPage,name));
+    }
+
+    @Autowired
+    private ISysMenuService menuService;
+    /**
+     * 菜单项结构(下拉框)
+     */
+    @GetMapping("/tree")
+    @ApiOperation(value = "角色管理-菜单列表树", tags = {"系统后台-权限管理","系统后台-首页"})
+    public R<List<MenuTreeVO>> tree() {
+        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+        return R.ok(menuService.tree(loginUser.getUserId()));
+    }
+    /**
+     * 新增
+     */
+    @ApiOperation(value = "新增角色", tags = "系统后台-权限管理")
+    @PreAuthorize("@ss.hasPermi('permission:role')")
+    @Log(title = "角色管理", businessType = BusinessType.INSERT)
+    @PostMapping("/add")
+    public R<Void> add(@Valid @RequestBody AddSysRoleDTO dto) {
+        roleService.add(dto);
+        return R.ok();
+
+    }
+
+    /**
+     * 查看详情
+     */
+    @ApiOperation(value = "查看详情", tags = "系统后台-权限管理")
+    @PreAuthorize("@ss.hasPermi('permission:role')")
+    @Log(title = "角色管理", businessType = BusinessType.DELETE)
+    @GetMapping("/{roleId}")
+    public R<SysRoleVO> getById(@PathVariable Long roleId) {
+
+        return R.ok(roleService.getById(roleId));
+    }
+    /**
+     * 修改
+     */
+    @ApiOperation(value = "修改角色", tags = "系统后台-权限管理")
+    @PreAuthorize("@ss.hasPermi('permission:role')")
+    @Log(title = "角色管理", businessType = BusinessType.INSERT)
+    @PutMapping("/edit")
+    public R<Void> edit(@Valid @RequestBody EditSysRoleDTO dto) {
+        roleService.edit(dto);
+        // 更新缓存用户权限
+        LoginUser loginUser = getLoginUser();
+        if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin()) {
+            loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
+            loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
+            tokenService.setLoginUser(loginUser);
+        }
+        return R.ok();
+    }
+    /**
+     * 删除角色
+     */
+    @ApiOperation(value = "删除角色", tags = "系统后台-权限管理")
+    @PreAuthorize("@ss.hasPermi('permission:role')")
+    @Log(title = "角色管理", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{roleId}")
+    public R<Void> remove(@PathVariable Long roleId) {
+        roleService.deleteRoleById(roleId);
+        return R.ok();
     }
 }

--
Gitblit v1.7.1