package com.dayou;

import com.dayou.utils.SpringContextHolder;
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.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * 类说明：启动类
 *
 * @author: wucl
 * @since: 2022/11/28
 * created with IntelliJ IDEA.
 */
@SpringBootApplication
@MapperScan("com.dayou.mapper")
@EnableScheduling
@EnableCaching
@Slf4j
@ServletComponentScan
public class BaseApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext app = SpringApplication.run(BaseApplication.class, args);
        printInfo(app, args);

    }

    private static void printInfo(ConfigurableApplicationContext app, String[] args) {
        if (app != null) {
            try {
                String msg = "\r\n##################################################################";
                msg += String.format(
                        "\t\r\n系统[%s] 版本[%s],环境[%s] context-path[%s]于端口[%s]启动应用[%s] 成功! ",
                        System.getProperty("os.name"),
                        System.getProperty("os.version"),
                        SpringContextHolder.getActiveProfile(),
                        app.getEnvironment().getProperty("server.servlet.context-path"),
                        app.getEnvironment().getProperty("server.port"),
                        app.getEnvironment().getProperty("spring.application.name"));
                msg += "\r\n##################################################################";
                log.info("args ", args);
                log.info(msg);
            } catch (Exception e) {
            }
        }
    }

}
