package com.seer.teach.openapi;

import cn.hutool.core.net.NetUtil;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;


/**
 * SeerOpenApiApplicationBootStrap 是Spring Boot应用程序的启动类
 * 该类负责启动整个Seer开放API应用，并配置相关的组件扫描和功能启用
 */
@SpringBootApplication(scanBasePackages = "com.seer.teach")
@EnableFeignClients("com.seer.teach")
@MapperScan(value = {"com.seer.teach.**.mapper"})
@EnableScheduling
@EnableDiscoveryClient
@EnableAsync
@Slf4j
public class SeerOpenApiApplicationBootStrap {

    /**
     * 应用程序的主入口方法
     * 启动Spring Boot应用并打印应用运行信息
     * 包括应用名称、访问地址、Swagger文档地址等
     *
     * @param args 命令行参数数组
     */
    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(SeerOpenApiApplicationBootStrap.class);
        Environment env = app.run(args).getEnvironment();
        String port = env.getProperty("server.port", "8087");
        String contextPath = env.getProperty("server.servlet.context-path", "/");

        // 打印应用启动信息
        log.info("----------------------------------------------------------");
        log.info("---------Application '{}' is running-------------------",env.getProperty("spring.application.name"));
        log.info("-----------Local : http://localhost:{}{} --------------",port,contextPath);
        log.info("--------------Ip : http://{}:{}{}  --------------------", NetUtil.getLocalhostStr(),port,contextPath);
        log.info("---------Swagger : http://{}:{}{}/swagger-ui/index.html",NetUtil.getLocalhostStr(),port,contextPath);
        log.info("----------------------------------------------------------");
    }
}

