refactor(DataPermission.java): 数据权限注解重命名

This commit is contained in:
郝先瑞 2022-01-18 00:00:38 +08:00
parent 4991ea573f
commit 7edac309ab
5 changed files with 9 additions and 21 deletions

View File

@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.youlai.admin.pojo.entity.SysDept; 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.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -14,7 +14,7 @@ import java.util.List;
@Mapper @Mapper
public interface SysDeptMapper extends BaseMapper<SysDept> { public interface SysDeptMapper extends BaseMapper<SysDept> {
@InterceptorIgnore @DataPermission
@Override @Override
List<SysDept> selectList(@Param(Constants.WRAPPER) Wrapper<SysDept> queryWrapper); List<SysDept> selectList(@Param(Constants.WRAPPER) Wrapper<SysDept> queryWrapper);
} }

View File

@ -7,7 +7,7 @@ import com.youlai.admin.pojo.entity.SysUser;
import com.youlai.admin.pojo.query.UserPageQuery; import com.youlai.admin.pojo.query.UserPageQuery;
import com.youlai.admin.pojo.vo.user.UserFormVO; import com.youlai.admin.pojo.vo.user.UserFormVO;
import com.youlai.admin.pojo.vo.user.UserPageVO; 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 org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
@ -28,7 +28,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
* @param queryParam * @param queryParam
* @return * @return
*/ */
@InterceptorIgnore(deptAlias = "d") @DataPermission(deptAlias = "d")
List<UserPageVO> listUsersWithPage(Page<UserPageVO> pageParam, UserPageQuery queryParam); List<UserPageVO> listUsersWithPage(Page<UserPageVO> pageParam, UserPageQuery queryParam);
/** /**

View File

@ -1,9 +1,9 @@
package com.youlai.common.mybatis.handler; package com.youlai.common.mybatis.annotation;
import java.lang.annotation.*; import java.lang.annotation.*;
/** /**
* 是否需要数据权限 * 数据权限注解
* *
* @author <a href="mailto:2256222053@qq.com">zc</a> * @author <a href="mailto:2256222053@qq.com">zc</a>
* @Date 2021-12-10 15:48 * @Date 2021-12-10 15:48
@ -11,14 +11,11 @@ import java.lang.annotation.*;
@Documented @Documented
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD}) @Target({ElementType.TYPE, ElementType.METHOD})
public @interface InterceptorIgnore { public @interface DataPermission {
/** /**
* 数据权限 {@link com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor} * 数据权限 {@link com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor}
* <p>
* 默认打开需要注解关闭
*/ */
String deptAlias() default ""; String deptAlias() default "";
} }

View File

@ -1,10 +0,0 @@
package com.youlai.common.mybatis.generator;
/**
* MP自定义主键生成器
*
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
* @date 2021/11/1 23:53
*/
public class CustomKeyGenerator {
}

View File

@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.handler.DataPermissionHandler; import com.baomidou.mybatisplus.extension.plugins.handler.DataPermissionHandler;
import com.youlai.common.constant.GlobalConstants; import com.youlai.common.constant.GlobalConstants;
import com.youlai.common.mybatis.annotation.DataPermission;
import com.youlai.common.web.util.JwtUtils; import com.youlai.common.web.util.JwtUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.*; import net.sf.jsqlparser.expression.*;
@ -34,7 +35,7 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
clazz.getAnnotatedSuperclass(); clazz.getAnnotatedSuperclass();
Method[] methods = clazz.getDeclaredMethods(); Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) { 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))) { if (ObjectUtils.isNotEmpty(annotation) && (method.getName().equals(methodName) || (method.getName() + "_COUNT").equals(methodName))) {
// 获取当前的用户角色 // 获取当前的用户角色
List<String> roles = JwtUtils.getRoles(); List<String> roles = JwtUtils.getRoles();