package cn.com.qmth.examcloud.core.questions.starter;

import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.mongodb.config.EnableMongoAuditing;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

@EnableAsync
@Configuration
@EnableJpaAuditing
@EnableMongoAuditing
@EnableTransactionManagement
@EnableEurekaClient
@EnableDiscoveryClient
@ComponentScan(basePackages = {"cn.com.qmth"})
@EntityScan(basePackages = {"cn.com.qmth"})
@EnableJpaRepositories(basePackages = {"cn.com.qmth"})
@EnableMongoRepositories(basePackages = {"cn.com.qmth"})
@SpringBootApplication(exclude = {MultipartAutoConfiguration.class})
public class CoreQuestionApp {

    static {
        if (System.getProperty("log.commonLevel") == null) {
            System.setProperty("log.commonLevel", "INFO");
        }
        System.setProperty("hibernate.dialect.storage_engine", "innodb");
    }

    public static void main(String[] args) {
        // AppBootstrap.run(CoreQuestionApp.class, args);
        SpringApplication.run(CoreQuestionApp.class, args);

        FileStorageUtil.initYunSite();
        FileStorageUtil.initYunClient();
    }

    @Bean(name = "multipartResolver")
    public MultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setDefaultEncoding("UTF-8");
        resolver.setResolveLazily(true);
        resolver.setMaxInMemorySize(40960);
        resolver.setMaxUploadSize(200L * 1024L * 1024L);
        return resolver;
    }

}