wangliang 2 éve
szülő
commit
c57a33f446

+ 25 - 19
themis-task/src/main/java/com/qmth/themis/task/quartz/MqActivityJob.java

@@ -7,12 +7,12 @@ import com.qmth.themis.business.entity.TEExamActivity;
 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.enums.InvigilateMonitorStatusEnum;
 import com.qmth.themis.business.service.*;
 import org.quartz.JobExecutionContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.scheduling.quartz.QuartzJobBean;
+import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.util.List;
@@ -70,25 +70,31 @@ public class MqActivityJob extends QuartzJobBean {
                     QueryWrapper<TOeExamRecord> tOeExamRecordQueryWrapper = new QueryWrapper<>();
                     tOeExamRecordQueryWrapper.lambda().in(TOeExamRecord::getExamActivityId, examActivityIdSet);
                     List<TOeExamRecord> examRecordList = tOeExamRecordService.list(tOeExamRecordQueryWrapper);
-                    examRecordList.forEach(s -> {
-                        ExamRecordStatusEnum examRecordStatusEnum = s.getStatus();
-                        //获取该考试批次下所有未交卷的考生的考试记录
-                        if (Objects.nonNull(examRecordStatusEnum)
-                                && !Objects.equals(ExamRecordStatusEnum.FINISHED, examRecordStatusEnum)
-                                && !Objects.equals(ExamRecordStatusEnum.PERSISTED, examRecordStatusEnum)
-                                && !Objects.equals(ExamRecordStatusEnum.ANSWERING, examRecordStatusEnum)) {
-                            Integer durationSeconds = s.getDurationSeconds();
-                            Long examStudentId = s.getExamStudentId();
-                            ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
-                            //候考阶段且没有进入考试则不交卷
-                            if (examRecordStatusEnum == ExamRecordStatusEnum.FIRST_PREPARE && Objects.isNull(s.getFirstStartTime())) {
-                                commonService.deleteExamStudentCache(s.getId(), examStudentCacheBean.getStudentId());
-                                commonService.DismissRoomByStrRoomId(s.getId());
-                            } else {//交卷
-                                teExamService.finish(examStudentCacheBean.getStudentId(), s.getId(), FinishTypeEnum.AUTO.name(), durationSeconds);
+                    if (!CollectionUtils.isEmpty(examRecordList)) {
+                        examRecordList.forEach(s -> {
+                            ExamRecordStatusEnum examRecordStatusEnum = s.getStatus();
+                            //获取该考试批次下所有未交卷的考生的考试记录
+                            if (Objects.nonNull(examRecordStatusEnum)
+                                    && !Objects.equals(ExamRecordStatusEnum.FINISHED, examRecordStatusEnum)
+                                    && !Objects.equals(ExamRecordStatusEnum.PERSISTED, examRecordStatusEnum)
+                                    && !Objects.equals(ExamRecordStatusEnum.ANSWERING, examRecordStatusEnum)) {
+                                Integer durationSeconds = s.getDurationSeconds();
+                                Long examStudentId = s.getExamStudentId();
+                                ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
+                                //候考阶段且没有进入考试则不交卷
+                                if (examRecordStatusEnum == ExamRecordStatusEnum.FIRST_PREPARE && Objects.isNull(s.getFirstStartTime())) {
+                                    if (Objects.nonNull(examStudentCacheBean)) {
+                                        commonService.deleteExamStudentCache(s.getId(), examStudentCacheBean.getStudentId());
+                                        commonService.DismissRoomByStrRoomId(s.getId());
+                                    }
+                                } else {//交卷
+                                    if (Objects.nonNull(examStudentCacheBean)) {
+                                        teExamService.finish(examStudentCacheBean.getStudentId(), s.getId(), FinishTypeEnum.AUTO.name(), durationSeconds);
+                                    }
+                                }
                             }
-                        }
-                    });
+                        });
+                    }
                 }
             }
         }

+ 21 - 9
themis-task/src/main/java/com/qmth/themis/task/quartz/service/impl/QuartzLogicServiceImpl.java

@@ -76,12 +76,16 @@ public class QuartzLogicServiceImpl implements QuartzLogicService {
                             ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
                             //候考阶段且没有进入考试则不交卷
                             if (examRecordStatusEnum == ExamRecordStatusEnum.FIRST_PREPARE && Objects.isNull(s.getFirstStartTime())) {
-                                commonService.deleteExamStudentCache(s.getId(), examStudentCacheBean.getStudentId());
-                                commonService.DismissRoomByStrRoomId(s.getId());
+                                if (Objects.nonNull(examStudentCacheBean)) {
+                                    commonService.deleteExamStudentCache(s.getId(), examStudentCacheBean.getStudentId());
+                                    commonService.DismissRoomByStrRoomId(s.getId());
+                                }
                             } else {//交卷
                                 Long recordEndTime = s.getEndTime();
                                 if (Objects.nonNull(examActivityCacheBean.getFinishTime()) && Objects.nonNull(recordEndTime) && examActivityCacheBean.getFinishTime().longValue() == recordEndTime.longValue()) {
-                                    teExamService.finish(examStudentCacheBean.getStudentId(), s.getId(), FinishTypeEnum.AUTO.name(), durationSeconds);
+                                    if (Objects.nonNull(examStudentCacheBean)) {
+                                        teExamService.finish(examStudentCacheBean.getStudentId(), s.getId(), FinishTypeEnum.AUTO.name(), durationSeconds);
+                                    }
                                 }
                             }
                         }
@@ -103,10 +107,14 @@ public class QuartzLogicServiceImpl implements QuartzLogicService {
                                 ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
                                 //候考阶段且没有进入考试则不交卷
                                 if (examRecordStatusEnum == ExamRecordStatusEnum.FIRST_PREPARE && Objects.isNull(s.getFirstStartTime())) {
-                                    commonService.deleteExamStudentCache(s.getId(), examStudentCacheBean.getStudentId());
-                                    commonService.DismissRoomByStrRoomId(s.getId());
+                                    if (Objects.nonNull(examStudentCacheBean)) {
+                                        commonService.deleteExamStudentCache(s.getId(), examStudentCacheBean.getStudentId());
+                                        commonService.DismissRoomByStrRoomId(s.getId());
+                                    }
                                 } else {//交卷
-                                    teExamService.finish(examStudentCacheBean.getStudentId(), s.getId(), FinishTypeEnum.AUTO.name(), durationSeconds);
+                                    if (Objects.nonNull(examStudentCacheBean)) {
+                                        teExamService.finish(examStudentCacheBean.getStudentId(), s.getId(), FinishTypeEnum.AUTO.name(), durationSeconds);
+                                    }
                                 }
                             }
                         }
@@ -142,13 +150,17 @@ public class QuartzLogicServiceImpl implements QuartzLogicService {
             }
             //候考阶段且没有进入考试则不交卷
             if (examRecordStatusEnum == ExamRecordStatusEnum.FIRST_PREPARE && Objects.isNull(firstStartTime)) {
-                commonService.deleteExamStudentCache(recordId, examStudentCacheBean.getStudentId());
-                commonService.DismissRoomByStrRoomId(recordId);
+                if (Objects.nonNull(examStudentCacheBean)) {
+                    commonService.deleteExamStudentCache(recordId, examStudentCacheBean.getStudentId());
+                    commonService.DismissRoomByStrRoomId(recordId);
+                }
             } else {//交卷
                 Long recordEndTime = ExamRecordCacheUtil.getEndTime(recordId);
                 if (examActivityCacheBean.getFinishTime().longValue() == recordEndTime.longValue()) {
                     Integer durationSeconds = ExamRecordCacheUtil.getDurationSeconds(recordId);
-                    teExamService.finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
+                    if (Objects.nonNull(examStudentCacheBean)) {
+                        teExamService.finish(examStudentCacheBean.getStudentId(), recordId, FinishTypeEnum.AUTO.name(), durationSeconds);
+                    }
                 }
             }
         }