|
@@ -1,28 +1,16 @@
|
|
package com.qmth.themis.task.quartz;
|
|
package com.qmth.themis.task.quartz;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
-import com.qmth.themis.business.entity.TEExamActivity;
|
|
|
|
-import com.qmth.themis.business.entity.TEExamStudent;
|
|
|
|
-import com.qmth.themis.business.entity.TOeExamRecord;
|
|
|
|
-import com.qmth.themis.business.enums.ExamRecordStatusEnum;
|
|
|
|
-import com.qmth.themis.business.enums.FinishTypeEnum;
|
|
|
|
-import com.qmth.themis.business.service.TEExamActivityService;
|
|
|
|
-import com.qmth.themis.business.service.TEExamStudentService;
|
|
|
|
-import com.qmth.themis.business.service.TOeExamRecordService;
|
|
|
|
-import com.qmth.themis.common.exception.BusinessException;
|
|
|
|
|
|
+import com.qmth.themis.task.quartz.service.QuartzLogicService;
|
|
import org.quartz.JobDetail;
|
|
import org.quartz.JobDetail;
|
|
import org.quartz.JobExecutionContext;
|
|
import org.quartz.JobExecutionContext;
|
|
import org.quartz.JobExecutionException;
|
|
import org.quartz.JobExecutionException;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.scheduling.quartz.QuartzJobBean;
|
|
import org.springframework.scheduling.quartz.QuartzJobBean;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -32,76 +20,20 @@ import java.util.Objects;
|
|
* @Author: wangliang
|
|
* @Author: wangliang
|
|
* @Date: 2020/7/27
|
|
* @Date: 2020/7/27
|
|
*/
|
|
*/
|
|
-@Service
|
|
|
|
|
|
+@Component
|
|
public class ExamActivityJob extends QuartzJobBean {
|
|
public class ExamActivityJob extends QuartzJobBean {
|
|
private final static Logger log = LoggerFactory.getLogger(ExamActivityJob.class);
|
|
private final static Logger log = LoggerFactory.getLogger(ExamActivityJob.class);
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
- TEExamActivityService teExamActivityService;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- TEExamStudentService teExamStudentService;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- TOeExamRecordService tOeExamRecordService;
|
|
|
|
|
|
+ QuartzLogicService quartzLogicService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @Transactional
|
|
|
|
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
|
|
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
|
|
log.info("exam_acvitity_job进来了,context:{}", context);
|
|
log.info("exam_acvitity_job进来了,context:{}", context);
|
|
- try {
|
|
|
|
- JobDetail jobDetail = context.getJobDetail();
|
|
|
|
- String key = String.valueOf(jobDetail.getKey());
|
|
|
|
- if (Objects.nonNull(key)) {
|
|
|
|
- String[] strings = key.split("\\.");
|
|
|
|
- QueryWrapper<TEExamActivity> teExamActivityQueryWrapper = new QueryWrapper<>();
|
|
|
|
- teExamActivityQueryWrapper.lambda().eq(TEExamActivity::getCode, strings[1]);
|
|
|
|
- TEExamActivity teExamActivity = teExamActivityService.getOne(teExamActivityQueryWrapper);
|
|
|
|
- if (Objects.nonNull(teExamActivity)) {
|
|
|
|
- log.info("key:{}", key);
|
|
|
|
-
|
|
|
|
- //获取该考试批次下所有未交卷的考生的考试记录
|
|
|
|
- QueryWrapper<TOeExamRecord> tOeExamRecordQueryWrapper = new QueryWrapper<>();
|
|
|
|
- tOeExamRecordQueryWrapper.lambda().eq(TOeExamRecord::getExamActivityId, teExamActivity.getId()).ne(TOeExamRecord::getStatus, ExamRecordStatusEnum.finished.ordinal());
|
|
|
|
- List<TOeExamRecord> tOeExamRecordList = tOeExamRecordService.list(tOeExamRecordQueryWrapper);
|
|
|
|
- List<Long> examStudentIdList = null;
|
|
|
|
- if (Objects.nonNull(tOeExamRecordList) && tOeExamRecordList.size() > 0) {
|
|
|
|
- examStudentIdList = new ArrayList<>();
|
|
|
|
- }
|
|
|
|
- List<Long> finalExamStudentIdList = examStudentIdList;
|
|
|
|
- tOeExamRecordList.forEach(s -> {
|
|
|
|
- s.setStatus(ExamRecordStatusEnum.finished);
|
|
|
|
- s.setFinishTime(new Date());
|
|
|
|
- s.setFinishType(FinishTypeEnum.interrupt);
|
|
|
|
- finalExamStudentIdList.add(s.getExamStudentId());
|
|
|
|
- });
|
|
|
|
- tOeExamRecordService.updateBatchById(tOeExamRecordList);
|
|
|
|
-
|
|
|
|
- if (Objects.nonNull(examStudentIdList) && examStudentIdList.size() > 0) {
|
|
|
|
- //获取该考试批次下所有考生,考试次数减1
|
|
|
|
- QueryWrapper<TEExamStudent> teExamStudentQueryWrapper = new QueryWrapper<>();
|
|
|
|
- teExamStudentQueryWrapper.lambda().in(TEExamStudent::getId, examStudentIdList);
|
|
|
|
- List<TEExamStudent> teExamStudentList = teExamStudentService.list(teExamStudentQueryWrapper);
|
|
|
|
- teExamStudentList.forEach(s -> {
|
|
|
|
- int count = Objects.isNull(s.getLeftExamCount()) ? 0 : s.getLeftExamCount();
|
|
|
|
- count--;
|
|
|
|
- s.setLeftExamCount(count < 0 ? 0 : count);
|
|
|
|
- //加入踢下线mq
|
|
|
|
- });
|
|
|
|
- teExamStudentService.updateBatchById(teExamStudentList);
|
|
|
|
- }
|
|
|
|
- //todo 未完待续,需要加入交卷逻辑
|
|
|
|
- } else {
|
|
|
|
- log.info("考试场次:{}已删除", key);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- if (e instanceof BusinessException) {
|
|
|
|
- throw new BusinessException(e.getMessage());
|
|
|
|
- } else {
|
|
|
|
- throw new RuntimeException(e);
|
|
|
|
- }
|
|
|
|
|
|
+ JobDetail jobDetail = context.getJobDetail();
|
|
|
|
+ String key = String.valueOf(jobDetail.getKey());
|
|
|
|
+ if (Objects.nonNull(key)) {
|
|
|
|
+ quartzLogicService.execExamActivityJobLogic(key);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|