package com.uas.search;

import com.uas.search.jms.JmsListener;
import com.uas.search.util.ContextUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

@EnableTransactionManagement
@EnableWebMvc
@SpringBootApplication
public class Application {

	public static void main(String[] args) throws FileNotFoundException {
		File logFile = new File("logs/log.log");
		if (!logFile.getParentFile().exists()) {
			logFile.getParentFile().mkdir();
		}
		System.setErr(new PrintStream(new FileOutputStream(logFile, true)));
		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()) {
			JmsListener jmsListener = ContextUtils.getBean(JmsListener.class);
			jmsListener.start(null);
		}
	}
}
