package cn.reghao.tnb.search.app.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @author reghao
 * @date 2022-03-28 11:54:49
 */
@Slf4j
@Component
public class SpringLifecycle implements ApplicationRunner, DisposableBean {
    private final SiteProperties siteProperties;

    public SpringLifecycle(SiteProperties siteProperties) {
        this.siteProperties = siteProperties;
    }

    @Override
    public void run(ApplicationArguments args) {
        String indexDir = siteProperties.getIndexDir();
        File dir = new File(indexDir);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        log.info("SearchService 启动...");
    }

    @Override
    public void destroy() {
        log.info("SearchService 停止...");
    }
}
