package cn.com.qmth.stmms.ms;

import cn.com.qmth.stmms.ms.commons.utils.RandomUtil;
import cn.com.qmth.stmms.ms.core.domain.Work;
import cn.com.qmth.stmms.ms.core.repository.WorkRepo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

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

    @Autowired
    WorkRepo workRepo;

    @Autowired
    RandomUtil randomUtil;


    @Override
    public void run(String... args) {
        LOGGER.info("服务器启动时执行 start");
        /*Work work = workRepo.findByActiveTrue();
        if (Objects.isNull(work)) {
            LOGGER.info("没有创建工作区");
        } else {
            randomUtil.getRandom(work.getId(), false);
        }*/
        //对所有当前工作都生成随机数
        List<Work> works = workRepo.findAllByActiveTrue();
        for (Work work : works) {
            randomUtil.getRandom(work.getId(), false);
        }
        LOGGER.info("服务器启动时执行 end");
    }
}
