package com.dgtly;

import org.apache.http.client.HttpClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.web.client.RestTemplate;

import javax.servlet.MultipartConfigElement;
import java.nio.charset.Charset;
import java.util.List;

/**
 * 启动程序
 * 
 * @author ruoyi
 */
@EnableRetry
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class DgtlyApplication
{
    public static void main(String[] args)
    {
        // System.setProperty("spring.devtools.restart.enabled", "false");
        SpringApplication.run(DgtlyApplication.class, args);
        System.out.println("(♥◠‿◠)ﾉﾞ  系统启动成功   ლ(´ڡ`ლ)ﾞ  \n" +
        " _____    _____  _______  _   __     __        ____   _   _  ______  _____    ____   _____  _______         _      \n" +
                "|  __ \\  / ____||__   __|| |  \\ \\   / /       / __ \\ | \\ | ||  ____||  __ \\  / __ \\ |  __ \\|__   __| /\\    | |     \n" +
                "| |  | || |  __    | |   | |   \\ \\_/ /______ | |  | ||  \\| || |__   | |__) || |  | || |__) |  | |   /  \\   | |     \n" +
                "| |  | || | |_ |   | |   | |    \\   /|______|| |  | || . ` ||  __|  |  ___/ | |  | ||  _  /   | |  / /\\ \\  | |     \n" +
                "| |__| || |__| |   | |   | |____ | |         | |__| || |\\  || |____ | |     | |__| || | \\ \\   | | / ____ \\ | |____ \n" +
                "|_____/  \\_____|   |_|   |______||_|          \\____/ |_| \\_||______||_|      \\____/ |_|  \\_\\  |_|/_/    \\_\\|______|\n "+
                "\n"+
                "(♥◠‿◠)ﾉﾞ 通誉企业云平台  ლ(´ڡ`ლ)ﾞ"
        );
    }

    @Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        List<HttpMessageConverter<?>> httpMessageConverters = restTemplate.getMessageConverters();
        httpMessageConverters.stream().forEach(httpMessageConverter -> {
            if(httpMessageConverter instanceof StringHttpMessageConverter){
                StringHttpMessageConverter messageConverter = (StringHttpMessageConverter) httpMessageConverter;
                messageConverter.setDefaultCharset(Charset.forName("UTF-8"));
            }
        });
         return restTemplate;
    }

    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setLocation("/tmp/tomcat");
        return factory.createMultipartConfig();
    }
}