فهرست منبع

交卷后续处理添加全局锁

lideyin 5 سال پیش
والد
کامیت
4fbd271050

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

@@ -19,6 +19,7 @@ import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
 import cn.com.qmth.examcloud.support.enums.ExamRecordStatus;
 import cn.com.qmth.examcloud.support.enums.HandInExamType;
 import cn.com.qmth.examcloud.support.examing.ExamRecordData;
+import cn.com.qmth.examcloud.web.helpers.SequenceLockHelper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -41,42 +42,51 @@ public class AfterHandInExamExecutor implements NodeExecuter<Long, ExamRecordDat
     @Override
     public List<KeyValuePair<Long, ExamRecordData>> execute(Long key, ExamRecordData examRecordData, TaskContext context) throws Exception {
 
-        List<KeyValuePair<Long, ExamRecordData>> resultList = new ArrayList<>();
-        KeyValuePair<Long, ExamRecordData> keyValuePair = new KeyValuePair<>(key, examRecordData);
+        String sequenceLockKey = Constants.EXAM_CONTROL_LOCK_PREFIX + examRecordData.getStudentId();
 
-        //针对已交卷的数据进行交卷后续处理
-        if (examRecordData.getExamRecordStatus() == ExamRecordStatus.EXAM_HAND_IN ||
-                examRecordData.getExamRecordStatus() == ExamRecordStatus.EXAM_AUTO_HAND_IN) {
+        try {
+            //添加考试控制全局锁
+            SequenceLockHelper.getLock(sequenceLockKey);
 
-            SysPropertyCacheBean maxProcessSecondsProperty = CacheHelper.getSysProperty("oe.task.maxProcessSeconds");
-            //本节点最大处理时长
-            Long maxProcessSeconds;
-            if (maxProcessSecondsProperty.getHasValue()) {
-                maxProcessSeconds = Long.valueOf(maxProcessSecondsProperty.getValue().toString());
-            } else {
-                maxProcessSeconds = DEFAULT_MAX_PROCESS_SECONDS;
-            }
+            List<KeyValuePair<Long, ExamRecordData>> resultList = new ArrayList<>();
+            KeyValuePair<Long, ExamRecordData> keyValuePair = new KeyValuePair<>(key, examRecordData);
+
+            //针对已交卷的数据进行交卷后续处理
+            if (examRecordData.getExamRecordStatus() == ExamRecordStatus.EXAM_HAND_IN ||
+                    examRecordData.getExamRecordStatus() == ExamRecordStatus.EXAM_AUTO_HAND_IN) {
+
+                SysPropertyCacheBean maxProcessSecondsProperty = CacheHelper.getSysProperty("oe.task.maxProcessSeconds");
+                //本节点最大处理时长
+                Long maxProcessSeconds;
+                if (maxProcessSecondsProperty.getHasValue()) {
+                    maxProcessSeconds = Long.valueOf(maxProcessSecondsProperty.getValue().toString());
+                } else {
+                    maxProcessSeconds = DEFAULT_MAX_PROCESS_SECONDS;
+                }
+
+                //交卷时间戳
+                Long handInTime = (examRecordData.getEndTime() == null ? examRecordData.getCleanTime() : examRecordData.getEndTime()).getTime();
+                Long times = System.currentTimeMillis() - handInTime;
+
+                //如果交卷后超过指定时长内仍未处理完成,则交给下一节点进行处理
+                if (times > maxProcessSeconds * 1000) {
+                    resultList.add(keyValuePair);
+                    return resultList;
+                }
 
-            //交卷时间戳
-            Long handInTime = (examRecordData.getEndTime() == null ? examRecordData.getCleanTime() : examRecordData.getEndTime()).getTime();
-            Long times = System.currentTimeMillis() - handInTime;
+                examRecordData = examRecordDataService.processAfterHandInExam(examRecordData.getId());
 
-            //如果交卷后超过指定时长内仍未处理完成,则交给下一节点进行处理
-            if (times > maxProcessSeconds * 1000) {
+                keyValuePair.setValue(examRecordData);
                 resultList.add(keyValuePair);
+
                 return resultList;
             }
 
-            examRecordData = examRecordDataService.processAfterHandInExam(examRecordData.getId());
-
-            keyValuePair.setValue(examRecordData);
             resultList.add(keyValuePair);
-
             return resultList;
+        } finally {
+            SequenceLockHelper.releaseLock(sequenceLockKey);
         }
-
-        resultList.add(keyValuePair);
-        return resultList;
     }
 
 }