package cn.com.ty.lift.batch;

import cn.com.ty.lift.common.sql.SqlAnalysisInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

/**
 * @Author xwy
 * @create 2019/11/4
 */
@Slf4j
@EnableFeignClients
@MapperScan("cn.com.ty.**.dao.mapper")
@SpringBootApplication(scanBasePackages = {"cn.com.ty.lift", "cn.com.xwy.boot"})
@EnableRedisHttpSession
@EnableRedisRepositories
public class BatchApplication {

    public static void main(String[] args) {
        log.debug("BatchApplication startup main");
        SpringApplication.run(BatchApplication.class,args);
    }

    /**
     * mybatis-plus 执行sql性能监测
     * @return SqlAnalysisInterceptor
     */
    @Bean
    @ConditionalOnMissingBean(PerformanceInterceptor.class)
    public SqlAnalysisInterceptor sqlAnalysisInterceptor() {
        SqlAnalysisInterceptor sqlAnalysisInterceptor = new SqlAnalysisInterceptor();
        //格式化执行的sql
        sqlAnalysisInterceptor.setFormat(true);
        //sql写入日志文件
        sqlAnalysisInterceptor.setLogWrite(true);
        return sqlAnalysisInterceptor;
    }
}
