From 4e04f5e967b14c6f2881d867438653f968027b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Tue, 28 Dec 2021 14:32:53 +0800 Subject: [PATCH] =?UTF-8?q?remove=20=E7=A7=BB=E9=99=A4=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=20=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/annotation/DataScope.java | 32 ---- .../framework/aspectj/DataScopeAspect.java | 142 ------------------ .../resources/mapper/system/SysDeptMapper.xml | 4 - .../resources/mapper/system/SysRoleMapper.xml | 8 - .../resources/mapper/system/SysUserMapper.xml | 16 -- 5 files changed, 202 deletions(-) delete mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataScope.java delete mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataScope.java b/ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataScope.java deleted file mode 100644 index f1a4f9f34..000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataScope.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.ruoyi.common.annotation; - -import java.lang.annotation.*; - -/** - * 数据权限过滤注解 - * - * @author ruoyi - * @deprecated 3.6.0 移除 {@link com.ruoyi.common.annotation.DataPermission} - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Deprecated -public @interface DataScope { - - /** - * 部门表的别名 - */ - String deptAlias() default ""; - - /** - * 用户表的别名 - */ - String userAlias() default ""; - - /** - * 是否过滤用户权限 - */ - boolean isUser() default false; - -} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java deleted file mode 100644 index 1a0d8e042..000000000 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.ruoyi.framework.aspectj; - -import com.ruoyi.common.annotation.DataScope; -import com.ruoyi.common.core.domain.BaseEntity; -import com.ruoyi.common.core.domain.entity.SysRole; -import com.ruoyi.common.core.domain.entity.SysUser; -import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.common.core.service.UserService; -import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.utils.spring.SpringUtils; -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.springframework.stereotype.Component; - -/** - * 数据过滤处理 - * - * @author Lion Li - * @deprecated 3.6.0 移除 {@link com.ruoyi.framework.handler.PlusDataPermissionHandler} - */ -@Aspect -@Component -@Deprecated -public class DataScopeAspect { - - /** - * 全部数据权限 - */ - public static final String DATA_SCOPE_ALL = "1"; - - /** - * 自定数据权限 - */ - public static final String DATA_SCOPE_CUSTOM = "2"; - - /** - * 部门数据权限 - */ - public static final String DATA_SCOPE_DEPT = "3"; - - /** - * 部门及以下数据权限 - */ - public static final String DATA_SCOPE_DEPT_AND_CHILD = "4"; - - /** - * 仅本人数据权限 - */ - public static final String DATA_SCOPE_SELF = "5"; - - /** - * 数据权限过滤关键字 - */ - public static final String DATA_SCOPE = "dataScope"; - - @Before("@annotation(controllerDataScope)") - public void doBefore(JoinPoint point, DataScope controllerDataScope) throws Throwable { - clearDataScope(point); - handleDataScope(point, controllerDataScope); - } - - protected void handleDataScope(final JoinPoint joinPoint, DataScope controllerDataScope) { - // 获取当前的用户 - LoginUser loginUser = SecurityUtils.getLoginUser(); - if (StringUtils.isNotNull(loginUser)) { - SysUser currentUser = SpringUtils.getBean(UserService.class).selectUserById(loginUser.getUserId()); - // 如果是超级管理员,则不过滤数据 - if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) { - dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), - controllerDataScope.userAlias(), controllerDataScope.isUser()); - } - } - } - - /** - * 数据范围过滤 - * - * @param joinPoint 切点 - * @param user 用户 - * @param userAlias 别名 - */ - public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, boolean isUser) { - StringBuilder sqlString = new StringBuilder(); - - // 将 "." 提取出,不写别名为单表查询,写别名为多表查询 - deptAlias = StringUtils.isNotBlank(deptAlias) ? deptAlias + "." : ""; - userAlias = StringUtils.isNotBlank(userAlias) ? userAlias + "." : ""; - - for (SysRole role : user.getRoles()) { - String dataScope = role.getDataScope(); - if (DATA_SCOPE_ALL.equals(dataScope)) { - sqlString = new StringBuilder(); - break; - } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) { - sqlString.append(StringUtils.format( - " OR {}dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", - deptAlias, role.getRoleId())); - } else if (DATA_SCOPE_DEPT.equals(dataScope)) { - sqlString.append(StringUtils.format(" OR {}dept_id = {} ", - deptAlias, user.getDeptId())); - } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) { - sqlString.append(StringUtils.format( - " OR {}dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", - deptAlias, user.getDeptId(), user.getDeptId())); - } else if (DATA_SCOPE_SELF.equals(dataScope)) { - if (isUser) { - sqlString.append(StringUtils.format(" OR {}user_id = {} ", - userAlias, user.getUserId())); - } else { - // 数据权限为仅本人且没有userAlias别名不查询任何数据 - sqlString.append(" OR 1=0 "); - } - } - } - - if (StringUtils.isNotBlank(sqlString.toString())) { - putDataScope(joinPoint, sqlString.substring(4)); - } - } - - /** - * 拼接权限sql前先清空params.dataScope参数防止注入 - */ - private void clearDataScope(final JoinPoint joinPoint) { - Object params = joinPoint.getArgs()[0]; - if (StringUtils.isNotNull(params)) { - putDataScope(joinPoint, ""); - } - } - - private static void putDataScope(JoinPoint joinPoint, String sql) { - Object params = joinPoint.getArgs()[0]; - if (StringUtils.isNotNull(params)) { - if (params instanceof BaseEntity) { - BaseEntity baseEntity = (BaseEntity) params; - baseEntity.getParams().put(DATA_SCOPE, sql); - } - } - } -} diff --git a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml index 8e9d1d758..c9b525279 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -42,10 +42,6 @@ AND status = #{status} - - - - order by d.parent_id, d.order_num diff --git a/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml index c13bd68bb..15f94f312 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml @@ -60,10 +60,6 @@ and date_format(r.create_time,'%y%m%d') <= date_format(#{role.params.endTime},'%y%m%d') - - - - order by r.role_sort @@ -88,10 +84,6 @@ and date_format(r.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') - - - - order by r.role_sort diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index c430cbb20..62ee4e187 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -108,10 +108,6 @@ AND (u.dept_id = #{user.deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{user.deptId}, ancestors) )) - - - -