package com.uas.search.console;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import com.uas.search.console.core.util.ContextUtils;
import com.uas.search.console.schedule.service.TaskService;
import com.uas.search.console.service.RealTimeUpdateMonitorService;

@EnableTransactionManagement
@EnableWebMvc
@SpringBootApplication(scanBasePackages = "com.uas.search.console")
@ImportResource({ "classpath:spring/dubbo.xml" })
public class Application {

	public static void main(String[] args) {
		SpringApplication application = new SpringApplication(Application.class);
		application.addListeners(new ContextUtils());
		application.run(args);

		startTask();
	}

	/**
	 * 开启定时任务
	 */
	public static void startTask() {
		SystemProperties systemProperties = ContextUtils.getBean(SystemProperties.class);
		if (systemProperties.isTaskAutoStart()) {
			// 定时监控实时更新异常情况
			RealTimeUpdateMonitorService realTimeUpdateMonitorService = ContextUtils
					.getBean(RealTimeUpdateMonitorService.class);
			realTimeUpdateMonitorService.newTask();

			// 开启定时任务
			TaskService taskService = ContextUtils.getBean(TaskService.class);
			if (!taskService.isStopped()) {
				taskService.stop();
			}
			taskService.start();
		}
	}
}
