package com.dgtly.apiframework.config;

import com.dgtly.apiframework.interceptor.SwitchEnSqlInterceptor;
import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;


//@Configuration
//@AutoConfigureAfter({PageHelperAutoConfiguration.class})
public class SwitchEnSqlInterceptorConfig {

        @Autowired
        private List<SqlSessionFactory> sqlSessionFactoryList;

        public SwitchEnSqlInterceptorConfig() {
        }



        @PostConstruct
        public void addPageInterceptor() {
            SwitchEnSqlInterceptor interceptor = new SwitchEnSqlInterceptor();
            Iterator var3 = this.sqlSessionFactoryList.iterator();
            Properties properties = new Properties();
            interceptor.setProperties( properties);
            while(var3.hasNext()) {
                SqlSessionFactory sqlSessionFactory = (SqlSessionFactory)var3.next();
                sqlSessionFactory.getConfiguration().addInterceptor(interceptor);
            }

        }
}
