package com.jiayue.ipp.common.mybatis;

import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
//import com.jiayuep.ipp.common.mybatis.interceptor.DataPermissionsInterceptorPlus;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.annotation.MapperScans;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScans({
        @MapperScan("com.jiayue.ipp.common.security.user"),
        @MapperScan("com.jiayue.ipp.idp.mapper")
})
public class MybatisConfig {


    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor1() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        // 添加数据权限插件
//        DataPermissionsInterceptorPlus dataPermissionInterceptor = new DataPermissionsInterceptorPlus();
        // 添加自定义的数据权限处理器
//        interceptor.addInnerInterceptor(dataPermissionInterceptor);

        return interceptor;
    }

    @Bean
    @ConfigurationProperties(prefix = "mybatis-plus.global-config")
    public GlobalConfig globalConfig() {
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setMetaObjectHandler(new MpMetaObjectHandler());
        return globalConfig;
    }
}
