
package cn.orionsec.ops.runner;

import cn.orionsec.ops.constant.command.ExecStatus;
import cn.orionsec.ops.dao.CommandExecDAO;
import cn.orionsec.ops.entity.domain.CommandExecDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

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

@Component
@Order(2200)
@Slf4j
public class CommandExecStatusCleanRunner implements CommandLineRunner {

    @Resource
    private CommandExecDAO commandExecDAO;

    @Override
    public void run(String... args) {
        log.info("重置命令执行状态-开始");
        LambdaQueryWrapper<CommandExecDO> wrapper = new LambdaQueryWrapper<CommandExecDO>()
                .in(CommandExecDO::getExecStatus, ExecStatus.WAITING.getStatus(), ExecStatus.RUNNABLE.getStatus());
        // 更新执行状态
        CommandExecDO update = new CommandExecDO();
        update.setExecStatus(ExecStatus.TERMINATED.getStatus());
        update.setUpdateTime(new Date());
        commandExecDAO.update(update, wrapper);
        log.info("重置命令执行状态-结束");
    }

}
