package com.zd.exam.util;

import com.zd.exam.domain.ElCourse;
import com.zd.exam.mapper.ElCourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @Author: cyl
 * @Date: 2022/02/10/19:44
 * @Description:
 */
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class IncourseScheduleTask {

    @Autowired
    private ElCourseMapper elCourseMapper;

    /**
     * 每10分钟执行一次
     */
//    @Scheduled(cron = "0 */10 * * * ?")
    @Scheduled(cron = "0 0 1 ? * *")
    private void configureTasks() {
        System.err.println("执行课题定时任务时间: " + LocalDateTime.now());
        ElCourse elCourse = new ElCourse();
        List <ElCourse> elCourseList = elCourseMapper.selectElCourseOverdueList(elCourse);
        for(ElCourse course:elCourseList){
            ElCourse courseNew = new ElCourse();
            courseNew.setId(course.getId());
            courseNew.setStatus(0);
            courseNew.setUpdateTime(new Date());
            elCourseMapper.updateElCourse(courseNew);
        }
    }

}
