package com.qmth.themis.admin.start;

import com.qmth.themis.business.constant.SystemConstant;
import com.qmth.themis.business.service.AuthInfoService;
import com.qmth.themis.business.service.SysConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.File;

/**
 * @Description: 服务启动时初始化运行，哪个微服务模块需要则拿此模版去用
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2020/7/3
 */
@Component
public class StartRunning implements CommandLineRunner {
    private final static Logger log = LoggerFactory.getLogger(StartRunning.class);

    @Value("${spring.application.name}")
    String applicationName;

    @Resource
    AuthInfoService authInfoService;

    @Resource
    SysConfigService sysConfigService;

    @Override
    public void run(String... args) throws Exception {
        log.info("服务器启动时执行 start");
        SystemConstant.initTempFiles();
        SystemConstant.getSearcher(SystemConstant.TEMP_FILES_DIR + File.separator + applicationName);
        sysConfigService.selectAll();
        authInfoService.appInfoInit();
        log.info("服务器启动时执行 end");
    }
}
