潘志宝
2024-08-15 81c220fd9e0ea6c8ee84c9b766885b0322b4038c
提交 | 用户 | 时间
e7c126 1 package com.iailab.framework.datapermission.config;
H 2
d9f9ba 3 import com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor;
e7c126 4 import com.iailab.framework.datapermission.core.aop.DataPermissionAnnotationAdvisor;
d9f9ba 5 import com.iailab.framework.datapermission.core.db.DataPermissionRuleHandler;
e7c126 6 import com.iailab.framework.datapermission.core.rule.DataPermissionRule;
H 7 import com.iailab.framework.datapermission.core.rule.DataPermissionRuleFactory;
8 import com.iailab.framework.datapermission.core.rule.DataPermissionRuleFactoryImpl;
9 import com.iailab.framework.mybatis.core.util.MyBatisUtils;
10 import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
11 import org.springframework.boot.autoconfigure.AutoConfiguration;
12 import org.springframework.context.annotation.Bean;
13
14 import java.util.List;
15
16 /**
17  * 数据权限的自动配置类
18  *
19  * @author iailab
20  */
21 @AutoConfiguration
22 public class IailabDataPermissionAutoConfiguration {
23
24     @Bean
25     public DataPermissionRuleFactory dataPermissionRuleFactory(List<DataPermissionRule> rules) {
26         return new DataPermissionRuleFactoryImpl(rules);
27     }
28
29     @Bean
d9f9ba 30     public DataPermissionRuleHandler dataPermissionRuleHandler(MybatisPlusInterceptor interceptor,
H 31                                                                DataPermissionRuleFactory ruleFactory) {
32         // 创建 DataPermissionInterceptor 拦截器
33         DataPermissionRuleHandler handler = new DataPermissionRuleHandler(ruleFactory);
34         DataPermissionInterceptor inner = new DataPermissionInterceptor(handler);
e7c126 35         // 添加到 interceptor 中
H 36         // 需要加在首个,主要是为了在分页插件前面。这个是 MyBatis Plus 的规定
37         MyBatisUtils.addInterceptor(interceptor, inner, 0);
d9f9ba 38         return handler;
e7c126 39     }
H 40
d9f9ba 41
e7c126 42     @Bean
H 43     public DataPermissionAnnotationAdvisor dataPermissionAnnotationAdvisor() {
44         return new DataPermissionAnnotationAdvisor();
45     }
46
47 }