TaskInitRunner.java 1.65 KB
package com.viontech.fanxing.task.runner;

import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.commons.model.TaskExample;
import com.viontech.fanxing.task.mapper.TaskMapper;
import com.viontech.fanxing.task.model.TaskData;
import com.viontech.fanxing.task.service.TaskDataService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * .
 *
 * @author 谢明辉
 * @date 2021/9/2
 */

@Component
@Slf4j
public class TaskInitRunner implements CommandLineRunner {

    @Resource
    private TaskMapper taskMapper;
    @Resource
    private TaskDataService taskDataService;

    @Override

    public void run(String... args) throws Exception {
        log.info("===================任务初始化开始===================");

        List<Task> tasks = taskMapper.selectByExampleWithBLOBs(new TaskExample());
        for (Task task : tasks) {
            if (StringUtils.isNotBlank(task.getScene()) && task.getStoreConfigId() != null) {
                try {
                    TaskData taskData = taskDataService.getRepository().getTaskDataByUnid(task.getUnid());
                    if (taskData == null) {
                        taskDataService.addTask(task);
                    }
                } catch (Exception e) {
                    log.info("初始化任务失败,任务unid:{},失败信息:{}", task.getUnid(), e.getMessage());
                }
            }
        }

        log.info("===================任务初始化结束===================");
    }
}