package com.ruoyi;

import cn.hutool.core.net.NetUtil;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.framework.config.ApplicationConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.InetAddress;
import java.util.Arrays;


/**
 * 启动程序
 *
 * @author ruoyi
 */

@SpringBootApplication
@Slf4j
@EnableScheduling
public class RuoYiApplication {


    public static void main(String[] args)throws Exception {
//        System.setProperty("spring.devtools.restart.enabled", "false");
        SpringApplication application = new SpringApplication(RuoYiApplication.class);
        application.setApplicationStartup(new BufferingApplicationStartup(2048));
        ApplicationContext act =application.run(args);
        RuoYiConfig config = act.getBean(RuoYiConfig.class);
        Environment environment = act.getEnvironment();
//        System.out.println("(♥◠‿◠)ﾉﾞ  RuoYi-Vue-Plus启动成功   ლ(´ڡ`ლ)ﾞ");
        System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
        StringBuffer sb = new StringBuffer("\n\n");
        sb.append("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
        sb.append("┃ 项目名称：").append(config.getName()).append("\n");
        sb.append("┃ 项目版本：").append(config.getVersion()).append("\n");
        sb.append("┃ 运行环境：").append(environment.getProperty("spring.profiles.active", "main")).append("\n");
        sb.append("┃ 运行模式：").append(config.getDev() ? "开发模式" : "生产模式").append("\n");
        String port = ":"+environment.getProperty("server.port","8080");
        if(":80".equals(port)){
            port="";
        }
        try {
//            for(String s : NetUtil.localIps()) {
            for(String s : NetUtil.localIpv4s()) {
                sb.append("┃ 访问地址：http://").append(s).append(port).append("\n");
            };

        } catch (Exception e) {
            sb.append("┃ 访问地址：http://127.0.0.1").append(port).append("\n");
        }
        sb.append("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
        sb.append("\n\n\n");
        log.info(sb.toString());
    }

}
