package com.zjrs.ggfw.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@EnableTransactionManagement
@Configuration
// 注意：MapperScan 通常建议扫描 Mapper 接口所在的包，而不是 entity 实体类包
@MapperScan("com.zjrs.ggfw.**.entity")
public class MybatisPlusConfig {

    /**
     * 新版分页插件配置
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        // 1. 添加分页内部拦截器
        // 建议明确指定 DbType (如 MYSQL, ORACLE, POSTGRE_SQL)，这能显著提高插件解析 SQL 的效率
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);

        // 2. 设置单页分页限制 (可选，默认无限制)
        // paginationInnerInterceptor.setMaxLimit(500L);

        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        return interceptor;
    }
}