|
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
@@ -38,8 +39,21 @@ public class HandInExamExecutor implements NodeExecuter<Long, ExamRecordData, Lo
|
|
|
@Autowired
|
|
|
private RedisClient redisClient;
|
|
|
|
|
|
+ /**
|
|
|
+ * 执行
|
|
|
+ *
|
|
|
+ * @param key
|
|
|
+ * @param examRecordData
|
|
|
+ * @param outList
|
|
|
+ * @param removable
|
|
|
+ * @param context
|
|
|
+ * @throws Exception
|
|
|
+ * @author WANGWEI
|
|
|
+ */
|
|
|
@Override
|
|
|
- public List<KeyValuePair<Long, ExamRecordData>> execute(Long key, ExamRecordData examRecordData, TaskContext context) throws Exception {
|
|
|
+ public void execute(Long key, ExamRecordData examRecordData,
|
|
|
+ List<KeyValuePair<Long, ExamRecordData>> outList,
|
|
|
+ Boolean removable, TaskContext context) throws Exception {
|
|
|
|
|
|
String sequenceLockKey = Constants.EXAM_CONTROL_LOCK_PREFIX + examRecordData.getStudentId();
|
|
|
|
|
@@ -47,34 +61,55 @@ public class HandInExamExecutor implements NodeExecuter<Long, ExamRecordData, Lo
|
|
|
//添加考试控制全局锁
|
|
|
SequenceLockHelper.getLockSimple(sequenceLockKey);
|
|
|
|
|
|
- List<KeyValuePair<Long, ExamRecordData>> resultList = new ArrayList<>();
|
|
|
- KeyValuePair<Long, ExamRecordData> keyValuePair = new KeyValuePair<>(key, examRecordData);
|
|
|
+ //获取最新的考试记录状态
|
|
|
+ ExamRecordData examRecordDataCache = examRecordDataService.getExamRecordDataCache(examRecordData.getId());
|
|
|
+
|
|
|
+ examRecordData.setExamRecordStatus(examRecordDataCache.getExamRecordStatus());
|
|
|
|
|
|
//处理正在进行中的考试
|
|
|
if (examRecordData.getExamRecordStatus() == ExamRecordStatus.EXAM_ING) {
|
|
|
+
|
|
|
ExamingSession examingSession = examingSessionService.getExamingSession(examRecordData.getStudentId());
|
|
|
|
|
|
// 如果考试会话不存在/超过考试时间/超过断点续考时间,自动交卷
|
|
|
if (null == examingSession || isOverExamTime(examingSession) || isOverBreakpointTime(examingSession)) {
|
|
|
- Date now = new Date();
|
|
|
|
|
|
- //更改内存中的交卷状态
|
|
|
- examRecordData.setExamRecordStatus(ExamRecordStatus.EXAM_AUTO_HAND_IN);
|
|
|
- examRecordData.setCleanTime(now);
|
|
|
+ try {
|
|
|
+ //更改内存中的交卷状态
|
|
|
+ examRecordData.setExamRecordStatus(ExamRecordStatus.EXAM_AUTO_HAND_IN);
|
|
|
+ examRecordData.setCleanTime(new Date());
|
|
|
+
|
|
|
+ examRecordDataService.saveExamRecordDataCache(examRecordData.getId(), examRecordData);
|
|
|
|
|
|
- examRecordDataService.saveExamRecordDataCache(examRecordData.getId(), examRecordData);
|
|
|
+ // 删除考试会话
|
|
|
+ if (null != examingSession) {
|
|
|
+ examingSessionService.deleteExamingSession(examRecordData.getStudentId());
|
|
|
+ }
|
|
|
|
|
|
- keyValuePair.setValue(examRecordData);
|
|
|
- resultList.add(keyValuePair);
|
|
|
+ outList.add(new KeyValuePair<>(key, examRecordData));
|
|
|
+ } catch (Exception e) {
|
|
|
+ //回滚自动交卷操作
|
|
|
+ examRecordData.setExamRecordStatus(ExamRecordStatus.EXAM_ING);
|
|
|
+ examRecordData.setCleanTime(null);
|
|
|
+ examRecordDataService.saveExamRecordDataCache(examRecordData.getId(), examRecordData);
|
|
|
|
|
|
- // 删除redis会话
|
|
|
- examingSessionService.deleteExamingSession(examRecordData.getStudentId());
|
|
|
- return resultList;
|
|
|
+ outList.clear();
|
|
|
+ removable = false;
|
|
|
+
|
|
|
+ throw new StatusException("300101", "自动交卷出现异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ //如果不需要自动交卷,则需要下次轮循,继续处理
|
|
|
+ removable = false;
|
|
|
+ outList.clear();
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- resultList.add(keyValuePair);
|
|
|
- return resultList;
|
|
|
+ //其它状态的数据,直接交给下一个节点处理
|
|
|
+ outList.add(new KeyValuePair<>(key, examRecordData));
|
|
|
} finally {
|
|
|
SequenceLockHelper.releaseLockSimple(sequenceLockKey);
|
|
|
}
|
|
@@ -87,13 +122,13 @@ public class HandInExamExecutor implements NodeExecuter<Long, ExamRecordData, Lo
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean isOverExamTime(ExamingSession examingSession) {
|
|
|
- String examingHeartbeatKey = RedisKeyHelper.getBuilder()
|
|
|
- .examingHeartbeatKey(examingSession.getExamRecordDataId());
|
|
|
- ExamingHeartbeat examingHeartbeat = redisClient.get(examingHeartbeatKey,
|
|
|
- ExamingHeartbeat.class);
|
|
|
+ String examingHeartbeatKey = RedisKeyHelper.getBuilder()
|
|
|
+ .examingHeartbeatKey(examingSession.getExamRecordDataId());
|
|
|
+ ExamingHeartbeat examingHeartbeat = redisClient.get(examingHeartbeatKey,
|
|
|
+ ExamingHeartbeat.class);
|
|
|
|
|
|
- //秒
|
|
|
- long cost = null == examingHeartbeat ? 0 : examingHeartbeat.getCost();
|
|
|
+ //秒
|
|
|
+ long cost = null == examingHeartbeat ? 0 : examingHeartbeat.getCost();
|
|
|
return examingSession.getExamDuration() <= cost * 1000;
|
|
|
}
|
|
|
|
|
@@ -105,16 +140,16 @@ public class HandInExamExecutor implements NodeExecuter<Long, ExamRecordData, Lo
|
|
|
*/
|
|
|
private boolean isOverBreakpointTime(ExamingSession examingSession) {
|
|
|
long now = System.currentTimeMillis();
|
|
|
-
|
|
|
- String examingActiveTimeKey = RedisKeyHelper.getBuilder()
|
|
|
- .examingActiveTimeKey(examingSession.getExamRecordDataId());
|
|
|
- ExamingActivityTime examingActiveTime = redisClient.get(examingActiveTimeKey,
|
|
|
- ExamingActivityTime.class);
|
|
|
-
|
|
|
- long activeTime = null == examingActiveTime
|
|
|
- ? System.currentTimeMillis()
|
|
|
- : examingActiveTime.getActiveTime();
|
|
|
- return now - activeTime>= examingSession.getExamReconnectTime().intValue() * 60 * 1000;
|
|
|
+
|
|
|
+ String examingActiveTimeKey = RedisKeyHelper.getBuilder()
|
|
|
+ .examingActiveTimeKey(examingSession.getExamRecordDataId());
|
|
|
+ ExamingActivityTime examingActiveTime = redisClient.get(examingActiveTimeKey,
|
|
|
+ ExamingActivityTime.class);
|
|
|
+
|
|
|
+ long activeTime = null == examingActiveTime
|
|
|
+ ? System.currentTimeMillis()
|
|
|
+ : examingActiveTime.getActiveTime();
|
|
|
+ return now - activeTime >= examingSession.getExamReconnectTime().intValue() * 60 * 1000;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|