From 695cb6d76b838b1e4cb161bae335faa948dca12a Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期三, 27 十月 2021 13:16:19 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into satoken

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java |   73 +++++++++++++++++++++++-------------
 1 files changed, 46 insertions(+), 27 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
index 70a33ee..7dd14af 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
@@ -1,14 +1,16 @@
 package com.ruoyi.system.service.impl;
 
-import cn.hutool.core.lang.Validator;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.ruoyi.common.annotation.DataScope;
 import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.domain.entity.SysRole;
+import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
 import com.ruoyi.common.core.page.TableDataInfo;
-import com.ruoyi.common.exception.CustomException;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.PageUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.spring.SpringUtils;
 import com.ruoyi.system.domain.SysRoleDept;
 import com.ruoyi.system.domain.SysRoleMenu;
@@ -27,7 +29,7 @@
 /**
  * 瑙掕壊 涓氬姟灞傚鐞�
  *
- * @author ruoyi
+ * @author Lion Li
  */
 @Service
 public class SysRoleServiceImpl extends ServicePlusImpl<SysRoleMapper, SysRole, SysRole> implements ISysRoleService {
@@ -91,7 +93,7 @@
         List<SysRole> perms = baseMapper.selectRolePermissionByUserId(userId);
         Set<String> permsSet = new HashSet<>();
         for (SysRole perm : perms) {
-            if (Validator.isNotNull(perm)) {
+            if (StringUtils.isNotNull(perm)) {
                 permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
             }
         }
@@ -115,7 +117,7 @@
      * @return 閫変腑瑙掕壊ID鍒楄〃
      */
     @Override
-    public List<Integer> selectRoleListByUserId(Long userId) {
+    public List<Long> selectRoleListByUserId(Long userId) {
         return baseMapper.selectRoleListByUserId(userId);
     }
 
@@ -138,10 +140,10 @@
      */
     @Override
     public String checkRoleNameUnique(SysRole role) {
-        Long roleId = Validator.isNull(role.getRoleId()) ? -1L : role.getRoleId();
+        Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
         SysRole info = getOne(new LambdaQueryWrapper<SysRole>()
                 .eq(SysRole::getRoleName, role.getRoleName()).last("limit 1"));
-        if (Validator.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
+        if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
             return UserConstants.NOT_UNIQUE;
         }
         return UserConstants.UNIQUE;
@@ -155,10 +157,10 @@
      */
     @Override
     public String checkRoleKeyUnique(SysRole role) {
-        Long roleId = Validator.isNull(role.getRoleId()) ? -1L : role.getRoleId();
+        Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
         SysRole info = getOne(new LambdaQueryWrapper<SysRole>()
                 .eq(SysRole::getRoleKey, role.getRoleKey()).last("limit 1"));
-        if (Validator.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
+        if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
             return UserConstants.NOT_UNIQUE;
         }
         return UserConstants.UNIQUE;
@@ -171,8 +173,25 @@
      */
     @Override
     public void checkRoleAllowed(SysRole role) {
-        if (Validator.isNotNull(role.getRoleId()) && role.isAdmin()) {
-            throw new CustomException("涓嶅厑璁告搷浣滆秴绾х鐞嗗憳瑙掕壊");
+        if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) {
+            throw new ServiceException("涓嶅厑璁告搷浣滆秴绾х鐞嗗憳瑙掕壊");
+        }
+    }
+
+    /**
+     * 鏍¢獙瑙掕壊鏄惁鏈夋暟鎹潈闄�
+     *
+     * @param roleId 瑙掕壊id
+     */
+    @Override
+    public void checkRoleDataScope(Long roleId) {
+        if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
+            SysRole role = new SysRole();
+            role.setRoleId(roleId);
+            List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
+            if (StringUtils.isEmpty(roles)) {
+                throw new ServiceException("娌℃湁鏉冮檺璁块棶瑙掕壊鏁版嵁锛�");
+            }
         }
     }
 
@@ -183,7 +202,7 @@
      * @return 缁撴灉
      */
     @Override
-    public int countUserRoleByRoleId(Long roleId) {
+    public long countUserRoleByRoleId(Long roleId) {
         return userRoleMapper.selectCount(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getRoleId, roleId));
     }
 
@@ -261,7 +280,7 @@
             list.add(rm);
         }
         if (list.size() > 0) {
-			rows = roleMenuMapper.insertAll(list);
+            rows = roleMenuMapper.insertAll(list);
         }
         return rows;
     }
@@ -282,7 +301,7 @@
             list.add(rd);
         }
         if (list.size() > 0) {
-			rows = roleDeptMapper.insertAll(list);
+            rows = roleDeptMapper.insertAll(list);
         }
         return rows;
     }
@@ -316,7 +335,7 @@
             checkRoleAllowed(new SysRole(roleId));
             SysRole role = selectRoleById(roleId);
             if (countUserRoleByRoleId(roleId) > 0) {
-                throw new CustomException(String.format("%1$s宸插垎閰�,涓嶈兘鍒犻櫎", role.getRoleName()));
+                throw new ServiceException(String.format("%1$s宸插垎閰�,涓嶈兘鍒犻櫎", role.getRoleName()));
             }
         }
         List<Long> ids = Arrays.asList(roleIds);
@@ -336,45 +355,45 @@
     @Override
     public int deleteAuthUser(SysUserRole userRole) {
         return userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
-			.eq(SysUserRole::getRoleId, userRole.getRoleId())
-			.eq(SysUserRole::getUserId, userRole.getUserId()));
+                .eq(SysUserRole::getRoleId, userRole.getRoleId())
+                .eq(SysUserRole::getUserId, userRole.getUserId()));
     }
 
     /**
      * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛瑙掕壊
      *
-     * @param roleId 瑙掕壊ID
+     * @param roleId  瑙掕壊ID
      * @param userIds 闇�瑕佸彇娑堟巿鏉冪殑鐢ㄦ埛鏁版嵁ID
      * @return 缁撴灉
      */
     @Override
     public int deleteAuthUsers(Long roleId, Long[] userIds) {
-		return userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
-			.eq(SysUserRole::getRoleId, roleId)
-			.in(SysUserRole::getUserId, Arrays.asList(userIds)));
+        return userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
+                .eq(SysUserRole::getRoleId, roleId)
+                .in(SysUserRole::getUserId, Arrays.asList(userIds)));
     }
 
     /**
      * 鎵归噺閫夋嫨鎺堟潈鐢ㄦ埛瑙掕壊
      *
-     * @param roleId 瑙掕壊ID
+     * @param roleId  瑙掕壊ID
      * @param userIds 闇�瑕佸垹闄ょ殑鐢ㄦ埛鏁版嵁ID
      * @return 缁撴灉
      */
     @Override
     public int insertAuthUsers(Long roleId, Long[] userIds) {
         // 鏂板鐢ㄦ埛涓庤鑹茬鐞�
-		int rows = 1;
-		List<SysUserRole> list = new ArrayList<SysUserRole>();
+        int rows = 1;
+        List<SysUserRole> list = new ArrayList<SysUserRole>();
         for (Long userId : userIds) {
             SysUserRole ur = new SysUserRole();
             ur.setUserId(userId);
             ur.setRoleId(roleId);
             list.add(ur);
         }
-		if (list.size() > 0) {
-			rows = userRoleMapper.insertAll(list);
-		}
+        if (list.size() > 0) {
+            rows = userRoleMapper.insertAll(list);
+        }
         return rows;
     }
 }

--
Gitblit v1.9.3