/*
 * Copyright (c) 2023 codvision.com All Rights Reserved.
 */

package com.codvision.webcore.config;

import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
import com.baomidou.mybatisplus.extension.incrementer.H2KeyGenerator;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.codvision.webcore.interceptor.PlatformPaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * mybatis plus 统一配置
 *
 * @author lingee
 * @date 2023-7-13
 */
@Configuration
@MapperScan("com.codvision.**.mapper")
public class MybatisAutoConfiguration {

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

    /**
     * 主键策略插件
     */
    @Bean
    public IKeyGenerator keyGenerator() {
        return new H2KeyGenerator();
    }

}
