package thyyxxk.webserver;

import com.dtflys.forest.springboot.annotation.ForestScan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.core.env.Environment;
import thyyxxk.webserver.utils.ZipUtil;

import java.net.InetAddress;

/**
 * @author dj
 */
@SpringBootApplication
@EnableTransactionManagement
@EnableScheduling
@EnableConfigurationProperties
@ForestScan(basePackages = {"thyyxxk.webserver.service.externalhttp"})
@Slf4j
public class WebServerApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext application = SpringApplication.run(WebServerApplication.class, args);
        String OS = System.getProperty("os.name");
        boolean isWindow = OS.startsWith("Windows");
        ZipUtil.setDirectory(isWindow ? "D:\\his\\catagory" : "/home/web-server/temp/");
        try {
            log.info("Done-CY");
            Environment env = application.getEnvironment();
            String ip = InetAddress.getLocalHost().getHostAddress();
            String port = env.getProperty("server.port");
            String property = env.getProperty("server.servlet.context-path");
            String path = property == null ? "" : property;
            log.info("\n\t" +
                     "----------------------------------------------------------\n\t" +
                     "Application Sailrui-Boot is running on {} \n\t" +
                     "Access URLs:\n\t" +
                     "Local: \t\t" +
                     "http://localhost:{}{}/\n\t" +
                     "External: \t" +
                     "http://{}:{}{}/\n\t" +
                     "------------------------------------------------------------", OS, port, path, ip, port, path);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

}
