From 553c29ab8a46c9a07e3657fdd36a81a6bfde1afe Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期四, 23 九月 2021 19:13:58 +0800
Subject: [PATCH] update 整合 satoken 权限、鉴权一体化框架

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java |  119 +++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 86 insertions(+), 33 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 dfe7a2a..80a4621 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
@@ -1,31 +1,28 @@
 package com.ruoyi.web.controller.system;
 
-import java.util.List;
-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 cn.dev33.satoken.annotation.SaCheckPermission;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysRole;
+import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.enums.BusinessType;
-import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.system.domain.SysUserRole;
 import com.ruoyi.system.service.ISysRoleService;
+import com.ruoyi.system.service.ISysUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
 
 /**
  * 瑙掕壊淇℃伅
- * 
+ *
  * @author ruoyi
  */
 @RestController
@@ -35,39 +32,40 @@
     @Autowired
     private ISysRoleService roleService;
 
-    @PreAuthorize("@ss.hasPermi('system:role:list')")
+    @Autowired
+    private ISysUserService userService;
+
+    @SaCheckPermission("system:role:list")
     @GetMapping("/list")
     public TableDataInfo list(SysRole role)
     {
-        startPage();
-        List<SysRole> list = roleService.selectRoleList(role);
-        return getDataTable(list);
+        return roleService.selectPageRoleList(role);
     }
 
     @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.EXPORT)
-    @PreAuthorize("@ss.hasPermi('system:role:export')")
+    @SaCheckPermission("system:role:export")
     @GetMapping("/export")
-    public AjaxResult export(SysRole role)
+    public void export(SysRole role, HttpServletResponse response)
     {
         List<SysRole> list = roleService.selectRoleList(role);
-        ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
-        return util.exportExcel(list, "瑙掕壊鏁版嵁");
+		ExcelUtil.exportExcel(list, "瑙掕壊鏁版嵁", SysRole.class, response);
     }
 
     /**
      * 鏍规嵁瑙掕壊缂栧彿鑾峰彇璇︾粏淇℃伅
      */
-    @PreAuthorize("@ss.hasPermi('system:role:query')")
+    @SaCheckPermission("system:role:query")
     @GetMapping(value = "/{roleId}")
     public AjaxResult getInfo(@PathVariable Long roleId)
     {
+        roleService.checkRoleDataScope(roleId);
         return AjaxResult.success(roleService.selectRoleById(roleId));
     }
 
     /**
      * 鏂板瑙掕壊
      */
-    @PreAuthorize("@ss.hasPermi('system:role:add')")
+    @SaCheckPermission("system:role:add")
     @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@Validated @RequestBody SysRole role)
@@ -80,7 +78,6 @@
         {
             return AjaxResult.error("鏂板瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹叉潈闄愬凡瀛樺湪");
         }
-        role.setCreateBy(SecurityUtils.getUsername());
         return toAjax(roleService.insertRole(role));
 
     }
@@ -88,7 +85,7 @@
     /**
      * 淇敼淇濆瓨瑙掕壊
      */
-    @PreAuthorize("@ss.hasPermi('system:role:edit')")
+    @SaCheckPermission("system:role:edit")
     @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE)
     @PutMapping
     public AjaxResult edit(@Validated @RequestBody SysRole role)
@@ -102,14 +99,18 @@
         {
             return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑹叉潈闄愬凡瀛樺湪");
         }
-        role.setUpdateBy(SecurityUtils.getUsername());
-        return toAjax(roleService.updateRole(role));
+
+        if (roleService.updateRole(role) > 0)
+        {
+            return AjaxResult.success();
+        }
+        return AjaxResult.error("淇敼瑙掕壊'" + role.getRoleName() + "'澶辫触锛岃鑱旂郴绠$悊鍛�");
     }
 
     /**
      * 淇敼淇濆瓨鏁版嵁鏉冮檺
      */
-    @PreAuthorize("@ss.hasPermi('system:role:edit')")
+    @SaCheckPermission("system:role:edit")
     @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE)
     @PutMapping("/dataScope")
     public AjaxResult dataScope(@RequestBody SysRole role)
@@ -121,20 +122,19 @@
     /**
      * 鐘舵�佷慨鏀�
      */
-    @PreAuthorize("@ss.hasPermi('system:role:edit')")
+    @SaCheckPermission("system:role:edit")
     @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.UPDATE)
     @PutMapping("/changeStatus")
     public AjaxResult changeStatus(@RequestBody SysRole role)
     {
         roleService.checkRoleAllowed(role);
-        role.setUpdateBy(SecurityUtils.getUsername());
         return toAjax(roleService.updateRoleStatus(role));
     }
 
     /**
      * 鍒犻櫎瑙掕壊
      */
-    @PreAuthorize("@ss.hasPermi('system:role:remove')")
+    @SaCheckPermission("system:role:remove")
     @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.DELETE)
     @DeleteMapping("/{roleIds}")
     public AjaxResult remove(@PathVariable Long[] roleIds)
@@ -145,10 +145,63 @@
     /**
      * 鑾峰彇瑙掕壊閫夋嫨妗嗗垪琛�
      */
-    @PreAuthorize("@ss.hasPermi('system:role:query')")
+    @SaCheckPermission("system:role:query")
     @GetMapping("/optionselect")
     public AjaxResult optionselect()
     {
         return AjaxResult.success(roleService.selectRoleAll());
     }
+
+    /**
+     * 鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛�
+     */
+    @SaCheckPermission("system:role:list")
+    @GetMapping("/authUser/allocatedList")
+    public TableDataInfo allocatedList(SysUser user)
+    {
+		return userService.selectAllocatedList(user);
+    }
+
+    /**
+     * 鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛�
+     */
+    @SaCheckPermission("system:role:list")
+    @GetMapping("/authUser/unallocatedList")
+    public TableDataInfo unallocatedList(SysUser user)
+    {
+        return userService.selectUnallocatedList(user);
+    }
+
+    /**
+     * 鍙栨秷鎺堟潈鐢ㄦ埛
+     */
+    @SaCheckPermission("system:role:edit")
+    @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT)
+    @PutMapping("/authUser/cancel")
+    public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole)
+    {
+        return toAjax(roleService.deleteAuthUser(userRole));
+    }
+
+    /**
+     * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛
+     */
+    @SaCheckPermission("system:role:edit")
+    @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT)
+    @PutMapping("/authUser/cancelAll")
+    public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
+    {
+        return toAjax(roleService.deleteAuthUsers(roleId, userIds));
+    }
+
+    /**
+     * 鎵归噺閫夋嫨鐢ㄦ埛鎺堟潈
+     */
+    @SaCheckPermission("system:role:edit")
+    @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT)
+    @PutMapping("/authUser/selectAll")
+    public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
+    {
+        return toAjax(roleService.insertAuthUsers(roleId, userIds));
+    }
 }

--
Gitblit v1.9.3