package com.qmth.themis.task.quartz;

import com.qmth.themis.business.constant.SystemConstant;
import com.qmth.themis.business.service.TEExamActivityService;
import com.qmth.themis.business.service.TEExamPaperService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

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

/**
 * @Description: 客观题缓存加载
 * @Author: xiatian
 * @Date: 2020-12-30
 */
@Component
public class ObjectiveAnswerCacheLoadJob extends QuartzJobBean {
    private final static Logger log = LoggerFactory.getLogger(ObjectiveAnswerCacheLoadJob.class);

    @Resource
    TEExamActivityService examActivityService;

    @Resource
    TEExamPaperService examPaperService;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        log.info("ObjectiveAnswerCacheLoadJob进来了,context:{}", context);
        List<Long> examids = examActivityService.findExamIdToday();
        if (examids != null && examids.size() > 0) {
            for (Long examId : examids) {
                try {
                    examPaperService.disposeObjectiveAnswer(examId);
                } catch (Exception e) {
                    log.error(SystemConstant.LOG_ERROR, e);
                }
            }
        }
    }
}
