cheng
2023-12-12 c64c9f6fb38f65be99b827c1af8d3c3852f68ba4
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.config.datasource;
2
3 import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
4 import cn.stylefeng.guns.sys.core.mybatis.sqlfilter.DemoProfileSqlInterceptor;
5 import cn.stylefeng.roses.core.metadata.CustomMetaObjectHandler;
6 import org.mybatis.spring.annotation.MapperScan;
7 import org.springframework.context.annotation.Bean;
8 import org.springframework.context.annotation.Configuration;
9
10 /**
11  * mp的插件拓展和资源扫描
12  *
13  * @author fengshuonan
14  * @Date 2019/5/10 21:33
15  */
16 @Configuration
17 @MapperScan(basePackages = {"cn.stylefeng.**.mapper"})
18 public class PluginsConfig {
19
20     /**
21      * 拓展核心包中的字段包装器
22      *
23      * @author fengshuonan
24      * @Date 2019/5/10 21:35
25      */
26     @Bean
27     public CustomMetaObjectHandler gunsMpFieldHandler() {
28         return new CustomMetaObjectHandler() {
29
30             @Override
31             protected Long getUserUniqueId() {
32                 try {
33                     return LoginContextHolder.getContext().getUser().getId();
34                 } catch (Exception e) {
35
36                     //如果获取不到当前用户就存空id
37                     return -100L;
38                 }
39             }
40         };
41     }
42
43     /**
44      * 演示环境的sql拦截器
45      * <p>
46      * 演示环境只开放查询操作,其他都不允许
47      *
48      * @author stylefeng
49      * @date 2020/5/5 12:24
50      */
51     @Bean
52     public DemoProfileSqlInterceptor demoProfileSqlInterceptor() {
53         return new DemoProfileSqlInterceptor();
54     }
55
56 }