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