package com.ruoyi.common.orm.config;

//import cn.hutool.core.net.NetUtil;
//import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
//import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
//import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
//import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
//import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
//import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
//import org.dromara.common.mybatis.handler.InjectionMetaObjectHandler;
//import org.dromara.common.mybatis.interceptor.PlusDataPermissionInterceptor;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.datasource.DataSourceDecipher;
import com.ruoyi.common.orm.decipher.Decipher;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * mybatis-flex配置
 *
 * @author dataprince数据小王子
 */
//@EnableTransactionManagement(proxyTargetClass = true)
@Configuration
@MapperScan("${mybatis-flex.mapperPackage}")
public class MyBatisFlexConfig {

    private static final Logger logger = LoggerFactory.getLogger("mybatis-flex-sql");

    /**
     * SQL 打印
     */
    public MyBatisFlexConfig() {
        //开启审计功能
        AuditManager.setAuditEnable(true);

        //设置 SQL 审计收集器
        AuditManager.setMessageCollector(auditMessage ->
            logger.info("{},{}ms", auditMessage.getFullSql()
                , auditMessage.getElapsedTime())
        );
    }

    /**
     * 数据源解密
     */
    @Bean
    public DataSourceDecipher decipher(){
        DataSourceDecipher decipher = new Decipher();
        return decipher;
    }

    //TODO:动态表名

    //TODO:多租户配置

}
