package com.supervision;

import cn.hutool.core.thread.ThreadUtil;
import com.supervision.service.MatchToolService;
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.context.ConfigurableApplicationContext;

@Slf4j
@SpringBootApplication
@MapperScan(basePackages = {"com.supervision.**.mapper"})
public class InterroRobotApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(InterroRobotApplication.class, args);

        refreshMatchToolLibraryDelay(applicationContext,5*60*1000);

    }

    public static void refreshMatchToolLibraryDelay(ConfigurableApplicationContext applicationContext,long delay) {
        ThreadUtil.newThread(() -> {
            try {
                log.info("=============等待{}ms刷新向量匹配库=================",delay);
                Thread.sleep(delay);
                log.info("=============刷新向量匹配库=================");
                applicationContext.getBean(MatchToolService.class).refreshMatchToolLibrary();
                log.info("=============刷新向量匹配库完成=================");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },"refreshMatchToolLibrary").start();
    }

}
