package com.zjty.autotest.runner;

import com.zjty.autotest.pojo.sjq.AutoResultSet;
import com.zjty.autotest.service.AutoResultSetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * <p>Description : autotest
 * <p>Date : 2020/5/28 14:49
 * <p>@author : C
 */

@SuppressWarnings("SpringAutowiredFieldsWarningInspection")
@Slf4j
@Component
public class InitRunner implements CommandLineRunner {

    @Autowired
    AutoResultSetService autoResultSetService;

    @Override
    public void run(String... args) throws Exception {
        log.info("初始化报告状态...");
        List<AutoResultSet> resultsForReset = autoResultSetService.findAll().stream()
                .filter(autoResultSet -> Objects.equals(autoResultSet.getStatus(), 0))
                .collect(Collectors.toList());
        for (AutoResultSet resultSet : resultsForReset) {
            autoResultSetService.updateByid(resultSet.getId(),2);
        }
        log.info("初始化完毕...");

    }

}
