package com.dxhy;

import com.alibaba.fastjson.parser.ParserConfig;
import com.dxhy.common.auth.AuthCheck;
import com.dxhy.common.auth.AuthUtils;
import com.dxhy.common.auth.Result;
import com.dxhy.common.datasource.config.DynamicDataSourceConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author jiaohongyang
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableScheduling
@EnableTransactionManagement(proxyTargetClass = true)
@EnableAspectJAutoProxy(exposeProxy = true)
@Import({DynamicDataSourceConfig.class})
@ComponentScan(basePackages = {"com.dxhy.*"})
@Slf4j
public class DxhyOperationFlowApplication {
    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(DxhyOperationFlowApplication.class);
        springApplication.setAllowCircularReferences(Boolean.TRUE);
        springApplication.setAllowBeanDefinitionOverriding(Boolean.TRUE);
        ParserConfig.getGlobalInstance().setSafeMode(true);
        ConfigurableApplicationContext context = springApplication.run(args);
        afterStart(context);

    }

    private static void afterStart(ConfigurableApplicationContext context) {
        AuthUtils authCheck = context.getBean(AuthUtils.class);
        if (!authCheck.auth()) {
            log.error("系统禁止启动...");
            SpringApplication.exit(context, ()-> 1);
            System.exit(1);
        }
    }
}
