package com.gyee;


import lombok.extern.log4j.Log4j2;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.InetAddress;
import java.net.UnknownHostException;


@Log4j2
@SpringBootApplication
@EnableScheduling
@EnableFeignClients
@MapperScan("com.gyee.runeconomy.mapper")
public class RunEconomyApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(RunEconomyApplication.class, args);


        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        ApplicationHome home = new ApplicationHome(RunEconomyApplication.class);
        String filePath = home.getSource().getParentFile().getAbsolutePath();

        //        createFolder();

        log.info("\n-------------------------------------------------------------------\n\t" +
                "经济运行系统启动成功，访问路径如下:\n\t" +
                "本地路径: \t\thttp://localhost:" + port + path + "\n\t" +
                "网络地址: \t\thttp://" + ip + ":" + port + path + "\n\t" +
                "API文档: \t\thttp://" + ip + ":" + port + path + "/swagger-ui.html\n" +
                "-----------------------------------------------------------------------");
        log.info(filePath);


    }


    /**
     * 功率曲线拟合的数据文件保存路径
     */
    //    private static void createFolder() {
    //        GyeeConfig bean = SpringUtils.getBean(GyeeConfig.class);
    //        File f1 = new File(bean.getFilePathPrepare());
    //        File f2 = new File(bean.getFilePathProcess());
    //        File f3 = new File(bean.getFilePathFitting());
    //        File f4 = new File(bean.getFilePathDownload());
    //        if (!f1.exists())
    //            f1.mkdirs();
    //        if (!f2.exists())
    //            f2.mkdirs();
    //        if (!f3.exists())
    //            f3.mkdirs();
    //        if (!f4.exists())
    //            f4.mkdirs();
    //    }

}
