package com.ruoyi.framework.config;


import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MybatisPlusConfig
 * MybatisPlus 插件配置
 * @author yangjian
 */
@Configuration
public class MybatisPlusConfig {

    /**
     * @return PaginationInterceptor
     * @Description MybatisPlus 分页插件配置
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {

        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        //分页单页最大条数，默认500
        paginationInterceptor.setLimit(-1);
        return paginationInterceptor;
    }


    /**
     * @return cn.hutool.core.lang.Snowflake
     * @Description 分布式id生成
     */
    @Bean
    public Snowflake snowflake() {
        return IdUtil.createSnowflake(1, 1);
    }

    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInterceptor();
    }


}