package com.njcn.db.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.njcn.db.handler.AutoFillValueHandler;
import com.njcn.db.handler.BatchInjector;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2021年12月14日 16:43
 */
@Configuration
public class MybatisConfig {

    /**
     * 分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }


    /**
     * 自定义公共字段自动填充
     */
    @Bean
    public AutoFillValueHandler autoFillValueHandler() {
        return new AutoFillValueHandler();
    }


    /***
     * 自定义注册器，处理批量插入
     * @author hongawen
     * @date 2023/5/30 14:53
     * @return BatchInjector
     */
    @Bean
    public BatchInjector BatchInjector() {
        return new BatchInjector();
    }


}
