Selaa lähdekoodia

考试中间读取 15min执行一次。

tom 1 kuukausi sitten
vanhempi
commit
6424be3c33

+ 9 - 0
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/CommSendService.java

@@ -297,11 +297,20 @@ public class CommSendService {
      * 每天06:00/12:00/18:00/00:00执行
      */
     public void scheduledCloseAllSocket() {
+        l.info("scheduledCloseAllSocket");
         AjaxResult ar = socketService.closeAll();
         l.info("AjaxResult = {}", ar);
     }
 
     /**
+     * 每15min运行一次。
+     */
+    public void scheduledExamMiddleRead() {
+        l.info("scheduledExamMiddleRead");
+        realExamService.studentMiddleReadRealExam();
+    }
+
+    /**
      * 主动更新模拟器状态。
      * <p>
      * <p>

+ 12 - 2
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/RealExamCollectionService.java

@@ -7,7 +7,7 @@ import cn.ele6.catalyzer.ruoyi.vue.custom.Ele6RYBaseService;
 import cn.ele6.catalyzer.ruoyi.vue.enhance.TableDataInfo;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.DateUtils;
-import com.ruoyi.sim.controller.RealExamCollectionController;
+import com.ruoyi.sim.domain.RealExam;
 import com.ruoyi.sim.domain.vo.RealExamCollectionVo;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -40,6 +40,8 @@ public class RealExamCollectionService extends Ele6RYBaseService {
     private CommSendService commSendService;
     @Autowired
     private SocketService socketService;
+    @Autowired
+    private RealExamService realExamService;
 
     /**
      * 查询考试集合
@@ -390,6 +392,14 @@ public class RealExamCollectionService extends Ele6RYBaseService {
                 return AjaxResult.error("已经关闭!");
             }
         }
+        // 处理没有点击交卷,后续没有任何处理的情况。
+        if (false) {
+            RealExam reQ = new RealExam();
+            reQ.setExamCollectionId(examCollectionId);
+            realExamService.selectRealExamList(reQ).forEach(re -> {
+                realExamService.systemSubmitTimeoutRealExam(re.getExamId());
+            });
+        }
         // todo:是否还有正在进行的考试
         // 修改为socket常开,直接返回成功结果。
         // Step:修改考试集合状态。
@@ -399,7 +409,7 @@ public class RealExamCollectionService extends Ele6RYBaseService {
         }
         return AjaxResult.success("关闭成功!");
     }
-
+    
     public AjaxResult close() {
         closeAllByType(RealExamCollection.Type.EXERCISE);
         closeAllByType(RealExamCollection.Type.SELF_EXERCISE);

+ 28 - 6
ruoyi-sim/src/main/java/com/ruoyi/sim/service/impl/RealExamService.java

@@ -571,11 +571,8 @@ public class RealExamService {
         if (StringUtils.equals(re.getExamStatus(), RealExam.State.SUBMITTED)) {
             return AjaxResult.error("已经交卷,禁止重复交卷,<br/>请刷新自动结束考试!");
         }
-        RealExamCollection rec = realExamCollectionService.selectRealExamCollectionByExamCollectionId(re.getExamCollectionId());
-        // 允许考试时长,毫秒
-        Long millisecondsAllowed = rec.getLimitDuration() * 60 * 1000 + DURATION_10_MIN;
         // Check:已经超时的交卷。
-        if (DateUtils.getNowDate().getTime() > re.getStartTime().getTime() + millisecondsAllowed) {
+        if (checkRealExamIsTimeout(re.getExamId())) {
             // 修改考试状态
             re.setExamStatus(RealExam.State.SUBMITTED);
             // 修改真实考试结束时间。
@@ -583,7 +580,6 @@ public class RealExamService {
             updateRealExam(re);
             return AjaxResult.success("考试时间已经超时,自动结束考试!");
         }
-
         // Check:检查参数studentBindIp有效性
         if (StringUtils.isBlank(studentBindIp)) {
             return AjaxResult.error("IP地址无效!");
@@ -599,7 +595,7 @@ public class RealExamService {
         if (!Objects.equals(seatStart.getSeatId(), seatNow.getSeatId())) {
             return AjaxResult.error("没有在原始座次上交卷,请回到原座次[" + seatStart.getSeatNum() + "]上进行交卷!");
         }
-
+        RealExamCollection rec = realExamCollectionService.selectRealExamCollectionByExamCollectionId(re.getExamCollectionId());
         // Check:检查参数examCollectionType有效性
         if (!StringUtils.equals(examCollectionType, rec.getExamCollectionType())) {
             return AjaxResult.error("考试集合类型不对应!");
@@ -679,6 +675,32 @@ public class RealExamService {
         }
     }
 
+    public void systemSubmitTimeoutRealExam(Long examId) {
+        RealExam re = selectRealExamByExamId(examId);
+        if (re != null &&
+                re.getExamId() != 0L &&
+                RealExam.State.ANSWERING.equals(re.getExamStatus()) &&
+                checkRealExamIsTimeout(re.getExamId())) {
+            re.setExamStatus(RealExam.State.SUBMITTED);
+            updateRealExam(re);
+        }
+    }
+
+    /**
+     * @param examId
+     * @return true 已经超时
+     */
+    public boolean checkRealExamIsTimeout(Long examId) {
+        RealExam re = selectRealExamByExamId(examId);
+        if (re == null || re.getExamId() == 0L) {
+            return false;
+        }
+        RealExamCollection rec = realExamCollectionService.selectRealExamCollectionByExamCollectionId(re.getExamCollectionId());
+        // 允许考试时长,毫秒
+        Long millisecondsAllowed = rec.getLimitDuration() * 60 * 1000 + DURATION_10_MIN;
+        return DateUtils.getNowDate().getTime() > (re.getStartTime().getTime() + millisecondsAllowed);
+    }
+
     /**
      * [轮询][学生]结束考试界面。
      *