package com.ruoyi.framework.config;

import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.DialectFactory;
import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.IDialect;
import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils;
import org.apache.ibatis.executor.Executor;

/**
 * wanghao
 * mybatisplus多数据源中关于不同类型的（mysql，oracle）数据库分页
 * 配置动态方言
 */
public class AutoPaginationInnerInterceptor extends PaginationInnerInterceptor {

    @Override
    protected IDialect findIDialect(Executor executor) {
        // 首先尝试获取已经设置的方言
        IDialect dialect = super.findIDialect(executor);
        // 如果方言未设置，则根据数据库连接类型动态获取
        if (dialect == null) {
            return DialectFactory.getDialect(JdbcUtils.getDbType(executor));
        }
        return dialect;
    }
}
