package com.ruoyi.common.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;

/**
 * 注入SpringBean RestTemplate
 */
@Configuration
@Slf4j
public class RestTemplateConfig {
/*

    @Bean(name = "restTemplate")
    public RestTemplate httpsRestTemplate() {
        RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder()
                .setConnectTimeout(Duration.ofSeconds(60 * 3)) //连接超时时间秒
                .setReadTimeout(Duration.ofSeconds(60 * 3)); //读取超时时间秒
        return restTemplateBuilder.build();
    }
*/

    @Bean
    public RestTemplate restTemplate() {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(1000 * 60 * 5);
        requestFactory.setReadTimeout(1000 * 60 * 5);
        RestTemplate restTemplate = new RestTemplate(requestFactory);
        return restTemplate;
    }


    public static void main(String[] args) {
        Duration duration = Duration.ofSeconds(60 * 3);
        System.out.println("duration = " + duration);
    }
}
