package com.iformall.config;

import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.iformall.plugin.MultiTenancy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.Properties;

@EnableTransactionManagement
@Configuration
public class MyBatisConfiguration {


    @Bean
    public MultiTenancy multiTenancy() {
        MultiTenancy multiTenancy = new MultiTenancy();
        Properties properties = new Properties();
        properties.setProperty("tenantIdColumn", "tenant_id");
        properties.setProperty("dialect", "mysql");
        properties.setProperty("tenantInfo", "com.iformall.tenant.TenantInfoImpl");
        multiTenancy.setProperties(properties);
        return multiTenancy;
    }

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor page = new PaginationInterceptor();
        page.setDialectType("mysql");
        return page;
    }

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