From 7edac309ab91b9e7e9fca4a76053aea3b86ebbf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Tue, 18 Jan 2022 00:00:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor(DataPermission.java):=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9D=83=E9=99=90=E6=B3=A8=E8=A7=A3=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/youlai/admin/mapper/SysDeptMapper.java | 4 ++-- .../java/com/youlai/admin/mapper/SysUserMapper.java | 4 ++-- .../DataPermission.java} | 9 +++------ .../common/mybatis/generator/CustomKeyGenerator.java | 10 ---------- .../mybatis/handler/DataPermissionHandlerImpl.java | 3 ++- 5 files changed, 9 insertions(+), 21 deletions(-) rename youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/{handler/InterceptorIgnore.java => annotation/DataPermission.java} (69%) delete mode 100644 youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/generator/CustomKeyGenerator.java diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysDeptMapper.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysDeptMapper.java index 9ac12c2eb..6d23b86ba 100644 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysDeptMapper.java +++ b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysDeptMapper.java @@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.toolkit.Constants; import com.youlai.admin.pojo.entity.SysDept; -import com.youlai.common.mybatis.handler.InterceptorIgnore; +import com.youlai.common.mybatis.annotation.DataPermission; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -14,7 +14,7 @@ import java.util.List; @Mapper public interface SysDeptMapper extends BaseMapper { - @InterceptorIgnore + @DataPermission @Override List selectList(@Param(Constants.WRAPPER) Wrapper queryWrapper); } diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysUserMapper.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysUserMapper.java index d749c4b12..7309c8082 100644 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysUserMapper.java +++ b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/mapper/SysUserMapper.java @@ -7,7 +7,7 @@ import com.youlai.admin.pojo.entity.SysUser; import com.youlai.admin.pojo.query.UserPageQuery; import com.youlai.admin.pojo.vo.user.UserFormVO; import com.youlai.admin.pojo.vo.user.UserPageVO; -import com.youlai.common.mybatis.handler.InterceptorIgnore; +import com.youlai.common.mybatis.annotation.DataPermission; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -28,7 +28,7 @@ public interface SysUserMapper extends BaseMapper { * @param queryParam * @return */ - @InterceptorIgnore(deptAlias = "d") + @DataPermission(deptAlias = "d") List listUsersWithPage(Page pageParam, UserPageQuery queryParam); /** diff --git a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/InterceptorIgnore.java b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/annotation/DataPermission.java similarity index 69% rename from youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/InterceptorIgnore.java rename to youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/annotation/DataPermission.java index 64eabeac9..7b6146322 100644 --- a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/InterceptorIgnore.java +++ b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/annotation/DataPermission.java @@ -1,9 +1,9 @@ -package com.youlai.common.mybatis.handler; +package com.youlai.common.mybatis.annotation; import java.lang.annotation.*; /** - * 是否需要数据权限 + * 数据权限注解 * * @author zc * @Date 2021-12-10 15:48 @@ -11,14 +11,11 @@ import java.lang.annotation.*; @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) -public @interface InterceptorIgnore { +public @interface DataPermission { /** * 数据权限 {@link com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor} - *

- * 默认打开,需要注解关闭 */ - String deptAlias() default ""; } diff --git a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/generator/CustomKeyGenerator.java b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/generator/CustomKeyGenerator.java deleted file mode 100644 index 10da7676c..000000000 --- a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/generator/CustomKeyGenerator.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.youlai.common.mybatis.generator; - -/** - * MP自定义主键生成器 - * - * @author haoxr - * @date 2021/11/1 23:53 - */ -public class CustomKeyGenerator { -} diff --git a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/DataPermissionHandlerImpl.java b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/DataPermissionHandlerImpl.java index c4a35432f..070089947 100644 --- a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/DataPermissionHandlerImpl.java +++ b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/DataPermissionHandlerImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.extension.plugins.handler.DataPermissionHandler; import com.youlai.common.constant.GlobalConstants; +import com.youlai.common.mybatis.annotation.DataPermission; import com.youlai.common.web.util.JwtUtils; import lombok.extern.slf4j.Slf4j; import net.sf.jsqlparser.expression.*; @@ -34,7 +35,7 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler { clazz.getAnnotatedSuperclass(); Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { - InterceptorIgnore annotation = method.getAnnotation(InterceptorIgnore.class); + DataPermission annotation = method.getAnnotation(DataPermission.class); if (ObjectUtils.isNotEmpty(annotation) && (method.getName().equals(methodName) || (method.getName() + "_COUNT").equals(methodName))) { // 获取当前的用户角色 List roles = JwtUtils.getRoles();