package com.ruoyi.job;

import com.ruoyi.model.domain.AppletUsersTeacher;
import com.ruoyi.model.service.IAppletOrderService;
import com.ruoyi.model.service.IAppletUsersTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

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

@Component
@Slf4j
public class AppletUserExaminationJob {



    @Autowired
    private IAppletUsersTeacherService appletUsersTeacherService;

    /**
     * 检查伴宠师是否可以重新考试
     */

    @Async
    @Scheduled(cron = "0 0 3 * * ?")
    public void check(){

        LocalDateTime localDateTime = LocalDateTime.now().minusYears(1);

        boolean update = appletUsersTeacherService
                .lambdaUpdate()
                .le(AppletUsersTeacher::getExamTime, localDateTime)
                .gt(AppletUsersTeacher::getExamNumber, 0)
                .set(AppletUsersTeacher::getExamNumber, 0)
                .update();

        log.info("定时任务[检查伴宠师是否可以重新考试]， 重新考试人数 {}", update);
    }

}
