Ver Fonte

force_end_exam

deason há 2 anos atrás
pai
commit
22aaf5eb14

+ 18 - 10
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/impl/ExamControlServiceImpl.java

@@ -814,9 +814,12 @@ public class ExamControlServiceImpl implements ExamControlService {
         Long examId = examRecordData.getExamId();
         Long rootOrgId = examRecordData.getRootOrgId();
 
+        log.info("handInExam start! studentId:{}, examRecordDataId:{}, handInExamType:{}, ip:{}, force:{}",
+                studentId, examRecordDataId, handInExamType.name(), ip, force);
+
         if (handInExamType == HandInExamType.MANUAL) {
             // 得到考试时长,校验是否达到冻结时间
-            long usedExamTime = checkAndComputeExamDuration(studentId);
+            long usedExamTime = this.checkAndComputeExamDuration(studentId, force);
             examRecordData.setUsedExamTime(usedExamTime);
             examRecordData.setExamRecordStatus(ExamRecordStatus.EXAM_HAND_IN);
             examRecordData.setEndTime(new Date());
@@ -888,7 +891,8 @@ public class ExamControlServiceImpl implements ExamControlService {
         // 更新考试记录状态
         examRecordDataRepo.updateExamRecordStatusById(examRecordData.getExamRecordStatus(), new Date(), examRecordDataId);
 
-        log.warn("handInExam success! studentId:{}, examRecordDataId:{}, handInExamType:{}, ip:{}", studentId, examRecordDataId, handInExamType.name(), ip);
+        log.warn("handInExam success! studentId:{}, examRecordDataId:{}, handInExamType:{}, ip:{}, force:{}",
+                studentId, examRecordDataId, handInExamType.name(), ip, force);
 
         //考试过程记录(交卷)打点
         ReportsUtil.report(new ExamProcessRecordReport(examRecordDataId,
@@ -2014,8 +2018,7 @@ public class ExamControlServiceImpl implements ExamControlService {
      * @param studentId 学生id
      * @return
      */
-    private Long checkAndComputeExamDuration(Long studentId) {
-
+    private Long checkAndComputeExamDuration(Long studentId, Boolean forceEndExam) {
         // 获取考试会话,判断考生是否已结束考试(二次校验)
         ExamingSession examingSession = examingSessionService.getExamingSession(studentId);
         if (examingSession == null) {
@@ -2025,7 +2028,7 @@ public class ExamControlServiceImpl implements ExamControlService {
         //交卷时重新计算考试已用时间
         Long examUsedMilliSeconds = calcUsedExamSeconds(studentId) * 1000;
         //考试总时长
-        //        long examTotalMilliSeconds = calcExamTotalMilliSeconds(examingSession.getExamRecordDataId());
+        // long examTotalMilliSeconds = calcExamTotalMilliSeconds(examingSession.getExamRecordDataId());
         //如果开启场次,并且设置了定点交卷,且已到定点收卷时间,则不需要校验冻结时间,直接返回考试时长
         if (examingSession.getTimingEnd() && examingSession.getFixedSubmitTime().getTime() <= new Date().getTime()) {
             return examUsedMilliSeconds;
@@ -2034,17 +2037,22 @@ public class ExamControlServiceImpl implements ExamControlService {
         // 如果没有超过冻结时间,抛出异常
         if (ExamType.ONLINE.name().equals(examingSession.getExamType())
                 || ExamType.ONLINE_HOMEWORK.name().equals(examingSession.getExamType())) {
-            ExamRecordData examRecordData = examRecordDataService
-                    .getExamRecordDataCache(examingSession.getExamRecordDataId());
 
+            ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(examingSession.getExamRecordDataId());
             if ((examRecordData != null && examRecordData.getIsExceed() != null && examRecordData.getIsExceed())
-                    || examRecordData.getExceedMaxSwitchScreenCount()) {// 超过断点最大次数或超过切屏限制的不校验冻结时间
+                    || examRecordData.getExceedMaxSwitchScreenCount()) {
+                // 超过断点最大次数或超过切屏限制的不校验冻结时间
+                return examUsedMilliSeconds;
+            }
+
+            if (forceEndExam != null && forceEndExam) {
+                // 强制交卷,则不校验冻结时间
                 return examUsedMilliSeconds;
             }
+
             long freezeTime = examingSession.getFreezeTime() * 60 * 1000;
             if (examUsedMilliSeconds < freezeTime) {
-                throw new StatusException("ExamControlServiceImpl-checkAndComputeExamDuration-exception",
-                        "开考" + examingSession.getFreezeTime() + "分钟后才能交卷");
+                throw new StatusException("开考" + examingSession.getFreezeTime() + "分钟后才能交卷!");
             }
         }