package com.xhkjedu.sexam.task;

import com.xhkjedu.sexam.mapper.exam.ESubjectMapper;
import com.xhkjedu.sexam.mapper.paper.EPaperCorrectTeacherMapper;
import com.xhkjedu.sexam.service.paperstudent.EPaperStudentService;
import com.xhkjedu.utils.N_Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author ywx
 * @classname PaperTask
 * @description 试卷状态定时任务
 * @date 2022/9/13 11:28
 **/
@Slf4j
@Component
public class PaperTask {

    @Resource
    private ESubjectMapper eSubjectMapper;
    @Resource
    private EPaperCorrectTeacherMapper ePaperCorrectTeacherMapper;
    @Resource
    EPaperStudentService ePaperStudentService;

    /**
     * 试卷开始考试
     * @Param []
     * @Author ywx
     * @Date 2022/9/13 11:29
     * @return void
     **/
    @Async("threadPoolTaskScheduler")
    @Scheduled(cron = "${cron.updatePaperState}")
    public void startPaper() {
        int timestamp = N_Utils.getSecondTimestamp();
        String strtime = N_Utils.getStrtimeTimestamp(timestamp, "yyyy-MM-dd HH:mm");
        eSubjectMapper.startPaper(strtime);
    }

    /**
     * 试卷结束考试
     * @Param []
     * @Author ywx
     * @Date 2022/9/13 11:30
     * @return void
     **/
    @Async("threadPoolTaskScheduler")
    @Scheduled(cron = "${cron.updatePaperState}")
    public void endPaper() {
        int timestamp = N_Utils.getSecondTimestamp();
        String strtime = N_Utils.getStrtimeTimestamp(timestamp, "yyyy-MM-dd HH:mm:ss");
        eSubjectMapper.endPaper(timestamp, strtime);
    }

    /*
     * 试题锁定状态超过10分钟后自动取消
     * @Param []
     * @Author ywx
     * @Date 2022/10/23 12:23
     * @return void
     **/
    @Async("threadPoolTaskScheduler")
    @Scheduled(cron = "${cron.questionCheckState}")
    public void unLockQuestion() {
        int timestamp = N_Utils.getSecondTimestamp();
        ePaperCorrectTeacherMapper.unLockQuestion(timestamp);
    }

    /*
     * 合并学生答案
     * @Param []
     * @Author ywx
     * @Date 2022/11/12 17:17
     * @return void
     **/
    @Async("threadPoolTaskScheduler")
    @Scheduled(cron = "${cron.imgMerge}")
    public void paperStuQuestionAnswerMerge() {
        ePaperStudentService.paperStuQuestionAnswerMerge();
    }

}
