|
@@ -16,11 +16,13 @@ import cn.com.qmth.examcloud.question.commons.core.paper.DefaultPaper;
|
|
|
import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionGroup;
|
|
|
import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionStructureWrapper;
|
|
|
import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionUnitWrapper;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.question.DefaultQuestion;
|
|
|
import cn.com.qmth.examcloud.question.commons.core.question.DefaultQuestionStructure;
|
|
|
import cn.com.qmth.examcloud.question.commons.core.question.DefaultQuestionUnit;
|
|
|
import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.QuestionCacheBean;
|
|
|
import cn.com.qmth.examcloud.support.examing.*;
|
|
|
+import cn.com.qmth.examcloud.support.handler.QuestionBodyHandler;
|
|
|
import cn.com.qmth.examcloud.support.redis.RedisKeyHelper;
|
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
@@ -29,6 +31,7 @@ import com.google.common.cache.CacheBuilder;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -162,9 +165,51 @@ public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsServic
|
|
|
} else {// 如果本地缓存不存在,则从redis中获取, 并在本地缓存存在存储一份
|
|
|
QuestionCacheBean getQuestionResp = CacheHelper.getQuestion(examSessionInfo.getExamId(),
|
|
|
examSessionInfo.getCourseCode(), examSessionInfo.getPaperType(), questionId);
|
|
|
- DefaultQuestionStructure questionStructure = getQuestionResp.getDefaultQuestion().getMasterVersion();
|
|
|
+
|
|
|
+ DefaultQuestion defaultQuestion = getQuestionResp.getDefaultQuestion();
|
|
|
+ DefaultQuestionStructure questionStructure = defaultQuestion.getMasterVersion();
|
|
|
+ List<DefaultQuestionUnit> questionUnits = questionStructure.getQuestionUnitList();
|
|
|
+
|
|
|
+ // 在线考试,清除答案
|
|
|
+ if (ExamType.ONLINE.name().equals(examSessionInfo.getExamType())
|
|
|
+ || ExamType.ONLINE_HOMEWORK.name().equals(examSessionInfo.getExamType())) {
|
|
|
+ for (DefaultQuestionUnit questionUnit : questionUnits) {
|
|
|
+ questionUnit.setRightAnswer(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String resultJson = JsonUtil.toJson(questionStructure);
|
|
|
+ questionContentCache.put(cacheKey, resultJson);
|
|
|
+ return resultJson;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getQuestionContentForClient(Long studentId, String questionId) {
|
|
|
+ ExamingSession examSessionInfo = examingSessionService.getExamingSession(studentId);
|
|
|
+ if (examSessionInfo == null
|
|
|
+ || examSessionInfo.getExamingStatus().equals(ExamingStatus.INFORMAL)) {
|
|
|
+ throw new StatusException("2001", "考试已结束,不允许获取试题内容");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 本地缓存key规则:examId_courseCode_paperType_questionId
|
|
|
+ String cacheKey = examSessionInfo.getExamId() + "_" + examSessionInfo.getCourseCode() + "_"
|
|
|
+ + examSessionInfo.getPaperType() + "_" + questionId;
|
|
|
+ String contentJson = questionContentCache.getIfPresent(cacheKey);
|
|
|
+
|
|
|
+ // 如果本地缓存中存在,则从本地缓存中获取
|
|
|
+ if (StringUtils.isNotEmpty(contentJson)) {
|
|
|
+ return contentJson;
|
|
|
+ } else {// 如果本地缓存不存在,则从redis中获取, 并在本地缓存存在存储一份
|
|
|
+ QuestionCacheBean getQuestionResp = CacheHelper.getQuestion(examSessionInfo.getExamId(),
|
|
|
+ examSessionInfo.getCourseCode(), examSessionInfo.getPaperType(), questionId);
|
|
|
+
|
|
|
+ DefaultQuestion defaultQuestion = getQuestionResp.getDefaultQuestion();
|
|
|
+ DefaultQuestionStructure questionStructure = defaultQuestion.getMasterVersion();
|
|
|
List<DefaultQuestionUnit> questionUnits = questionStructure.getQuestionUnitList();
|
|
|
|
|
|
+ // 将题干、选项等 HTML结构转换为“富文本”JSON结构
|
|
|
+ QuestionBodyHandler.convertRichText(defaultQuestion);
|
|
|
+
|
|
|
// 在线考试,清除答案
|
|
|
if (ExamType.ONLINE.name().equals(examSessionInfo.getExamType())
|
|
|
|| ExamType.ONLINE_HOMEWORK.name().equals(examSessionInfo.getExamType())) {
|
|
@@ -187,8 +232,8 @@ public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsServic
|
|
|
}
|
|
|
long examRecordDataId = examSessionInfo.getExamRecordDataId();
|
|
|
|
|
|
- if(StringUtils.isEmpty(referer) || StringUtils.isEmpty(agent) || !agent.contains("electron-exam-shell")){
|
|
|
- redisClient.set("OE_SESSION_WARN_"+examSessionInfo.getExamRecordDataId(), true,12 * 60 * 60);
|
|
|
+ if (StringUtils.isEmpty(referer) || StringUtils.isEmpty(agent) || !agent.contains("electron-exam-shell")) {
|
|
|
+ redisClient.set("OE_SESSION_WARN_" + examSessionInfo.getExamRecordDataId(), true, 12 * 60 * 60);
|
|
|
}
|
|
|
|
|
|
for (ExamStudentQuestionInfo examQuestionInfo : examQuestionInfos) {
|
|
@@ -304,4 +349,5 @@ public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsServic
|
|
|
eq.setAudioPlayTimes(temp.getAudioPlayTimes());
|
|
|
eq.setAnswerType(temp.getAnswerType());
|
|
|
}
|
|
|
+
|
|
|
}
|