package com.prolog.upcloud.base.wh.operate;

import com.prolog.framework.authority.annotation.EnablePrologResourceServer;
import com.prolog.framework.bz.common.search.EnableSearchApi;
import com.prolog.framework.bz.common.integration.EnableIntegrationApi;
import com.prolog.framework.log.aop.annotation.EnableUserLog;
import com.prolog.framework.microservice.annotation.EnablePrologService;
import com.prolog.framework.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;

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

@Slf4j
@EnablePrologService
@EnableUserLog
@MapperScan("com.prolog.upcloud.base.wh.operate.dao")
@EnablePrologResourceServer
@EnableSearchApi
@EnableIntegrationApi
public class WhOperateApplication {

    private static Logger logger = LoggerFactory.getLogger(WhOperateApplication.class);

    public static void main(String[] args) {
        ConfigurableApplicationContext application = SpringApplication.run(WhOperateApplication.class, args);
        logger.info("============= SpringBoot Start Success =============");
        Environment env = application.getEnvironment();
        String ip = "";
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            logger.error(e.getMessage());
        }
        String port = env.getProperty("server.port");
        String property = env.getProperty("server.servlet.context-path");
        if (StringUtils.isBlank(property) || "null".equals(property)) {
            property = "";
        }
        String applicationName = env.getProperty("spring.application.name");
        if (StringUtils.isBlank(applicationName) || "null".equals(applicationName)) {
            applicationName = "";
        }
        String path = property.trim();
        String format = String.format(
                "\n----------------------------------------------------------\n\t"
                        + "Application SpringBoot Start Success  %s is running! Access URLs:\n\t"
                        + "Local : \thttp://localhost:%s%s/\n\t" + "plg本地文档 : \thttp://localhost:%s%s/apidoc.html#/\n\t"
                        + "remote : \thttp://%s:%s%s/\n\t" + "plg远程文档 : \thttp://%s:%s%s/apidoc.html#/" + "\n\t"
                        + "----------------------------------------------------------",
                applicationName, port, path, port, path, ip, port, path, ip, port, path);

        logger.info(format);
    }
}
