浏览代码

在线练习在交卷时即算出客观分

lideyin 5 年之前
父节点
当前提交
a7148ff1b7

+ 35 - 18
examcloud-core-oe-task-service/src/main/java/cn/com/qmth/examcloud/core/oe/task/service/pipeline/HandInExamExecutor.java

@@ -1,20 +1,16 @@
 package cn.com.qmth.examcloud.core.oe.task.service.pipeline;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.helpers.ObjectHolder;
-import cn.com.qmth.examcloud.commons.helpers.pipeline.SimpleNode;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
 import cn.com.qmth.examcloud.commons.helpers.KeyValuePair;
+import cn.com.qmth.examcloud.commons.helpers.ObjectHolder;
 import cn.com.qmth.examcloud.commons.helpers.pipeline.NodeExecuter;
 import cn.com.qmth.examcloud.commons.helpers.pipeline.TaskContext;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
+import cn.com.qmth.examcloud.core.oe.student.api.ExamRecordDataCloudService;
+import cn.com.qmth.examcloud.core.oe.student.api.request.CalcExamScoreReq;
+import cn.com.qmth.examcloud.core.oe.student.api.response.CalcExamScoreResp;
 import cn.com.qmth.examcloud.core.oe.task.service.ExamRecordDataService;
 import cn.com.qmth.examcloud.core.oe.task.service.ExamingSessionService;
 import cn.com.qmth.examcloud.support.Constants;
@@ -26,6 +22,11 @@ import cn.com.qmth.examcloud.support.examing.ExamingSession;
 import cn.com.qmth.examcloud.support.redis.RedisKeyHelper;
 import cn.com.qmth.examcloud.web.helpers.SequenceLockHelper;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
 
 /**
  * @Description 自动交卷执行器
@@ -43,6 +44,8 @@ public class HandInExamExecutor implements NodeExecuter<Long, ExamRecordData, Lo
     @Autowired
     private RedisClient redisClient;
     @Autowired
+    private ExamRecordDataCloudService examRecordDataCloudService;
+    @Autowired
     private static final ExamCloudLog LOG = ExamCloudLogFactory.getLog(HandInExamExecutor.class);
 
     /**
@@ -75,6 +78,8 @@ public class HandInExamExecutor implements NodeExecuter<Long, ExamRecordData, Lo
             //获取最新的考试记录状态
             ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(uncertainExamRecordData.getId());
 
+            Long examRecordDataId = examRecordData.getId();
+
             //处理正在进行中的考试
             if (examRecordData.getExamRecordStatus() == ExamRecordStatus.EXAM_ING) {
 
@@ -85,13 +90,25 @@ public class HandInExamExecutor implements NodeExecuter<Long, ExamRecordData, Lo
 
                     try {
 
-                        this.debugLog("prepare to auto hand in...", examRecordData.getId());
+                        this.debugLog("prepare to auto hand in...", examRecordDataId);
 
                         //更改内存中的交卷状态
                         examRecordData.setExamRecordStatus(ExamRecordStatus.EXAM_AUTO_HAND_IN);
                         examRecordData.setCleanTime(new Date());
 
-                        examRecordDataService.saveExamRecordDataCache(examRecordData.getId(), examRecordData);
+                        //如果是在线练习,则交卷时立即算出客观分,并保存在考试记录表的缓存中
+                        if (ExamType.PRACTICE == examRecordData.getExamType()) {
+                            CalcExamScoreReq cesReq = new CalcExamScoreReq();
+                            cesReq.setExamRecordDataId(examRecordDataId);
+                            CalcExamScoreResp calcExamScoreResp = examRecordDataCloudService.calcExamScore(cesReq);
+                            examRecordData.setObjectiveScore(calcExamScoreResp.getObjectiveScore());
+                            examRecordData.setObjectiveAccuracy(calcExamScoreResp.getObjectiveAccuracy());
+                            examRecordData.setSuccPercent(calcExamScoreResp.getSuccPercent());
+                            examRecordData.setTotalScore(calcExamScoreResp.getTotalScore());
+                        }
+
+                        //更新考试记录缓存
+                        examRecordDataService.saveExamRecordDataCache(examRecordDataId, examRecordData);
 
                         // 删除考试会话
                         if (null != examingSession) {
@@ -100,7 +117,7 @@ public class HandInExamExecutor implements NodeExecuter<Long, ExamRecordData, Lo
 
                         outList.add(new KeyValuePair<>(key, examRecordData));
 
-                        this.debugLog("auto hand in success...", examRecordData.getId());
+                        this.debugLog("auto hand in success...", examRecordDataId);
 
                         return;
 
@@ -108,12 +125,12 @@ public class HandInExamExecutor implements NodeExecuter<Long, ExamRecordData, Lo
                         //回滚自动交卷操作
                         examRecordData.setExamRecordStatus(ExamRecordStatus.EXAM_ING);
                         examRecordData.setCleanTime(null);
-                        examRecordDataService.saveExamRecordDataCache(examRecordData.getId(), examRecordData);
+                        examRecordDataService.saveExamRecordDataCache(examRecordDataId, examRecordData);
 
                         outList.clear();
                         removable.set(false);
 
-                        this.errorLog("auto hand in occurs error,to be retry...", e, examRecordData.getId());
+                        this.errorLog("auto hand in occurs error,to be retry...", e, examRecordDataId);
 
                         throw new StatusException("300101", "自动交卷出现异常:" + e.getMessage());
                     }
@@ -123,7 +140,7 @@ public class HandInExamExecutor implements NodeExecuter<Long, ExamRecordData, Lo
                 removable.set(false);
                 outList.clear();
 
-                this.debugLog("don't need auto hand in.to be retry...", examRecordData.getId());
+                this.debugLog("don't need auto hand in.to be retry...", examRecordDataId);
 
                 return;
             }
@@ -132,7 +149,7 @@ public class HandInExamExecutor implements NodeExecuter<Long, ExamRecordData, Lo
             outList.add(new KeyValuePair<>(key, examRecordData));
 
             this.debugLog("current status is '" + examRecordData.getExamRecordStatus().name() +
-                    "'.do nothing and go to the next node...", examRecordData.getId());
+                    "'.do nothing and go to the next node...", examRecordDataId);
         } finally {
             SequenceLockHelper.releaseLockSimple(sequenceLockKey);
         }