|
@@ -1,5 +1,6 @@
|
|
package cn.com.qmth.examcloud.core.oe.admin.service.impl;
|
|
package cn.com.qmth.examcloud.core.oe.admin.service.impl;
|
|
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.utils.QuestionTypeUtil;
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.utils.QuestionTypeUtil;
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordDataRepo;
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordDataRepo;
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordQuestionsRepo;
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordQuestionsRepo;
|
|
@@ -12,11 +13,23 @@ import cn.com.qmth.examcloud.core.oe.admin.dao.enums.ExamType;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.ExamRecordQuestionsService;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.ExamRecordQuestionsService;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.ExamStudentFinalScoreService;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.ExamStudentFinalScoreService;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.SubjectiveQuestionScoreInfo;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.SubjectiveQuestionScoreInfo;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.api.ExtractConfigCloudService;
|
|
|
|
+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.web.helpers.GlobalHelper;
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
|
+import com.google.common.cache.Cache;
|
|
|
|
+import com.google.common.cache.CacheBuilder;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service("examRecordQuestionsService")
|
|
@Service("examRecordQuestionsService")
|
|
@@ -31,6 +44,17 @@ public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsServic
|
|
@Autowired
|
|
@Autowired
|
|
private ExamScoreRepo examScoreRepo;
|
|
private ExamScoreRepo examScoreRepo;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExtractConfigCloudService extractConfigCloudService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //本地题干缓存,最大200道题,默认缓存120秒
|
|
|
|
+ private Cache<String, String> questionContentCache = CacheBuilder.newBuilder().maximumSize(200)
|
|
|
|
+ .expireAfterWrite(120, TimeUnit.SECONDS).build();
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private ExamStudentFinalScoreService examStudentFinalScoreService;
|
|
private ExamStudentFinalScoreService examStudentFinalScoreService;
|
|
|
|
|
|
@@ -79,4 +103,96 @@ public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsServic
|
|
examStudentFinalScoreService.calculateFinalScore(examRecordData.getExamStudentId());
|
|
examStudentFinalScoreService.calculateFinalScore(examRecordData.getExamStudentId());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Integer calculationSubjectiveAnswerLength(Long examRecordDataId) {
|
|
|
|
+ ExamRecordQuestionsEntity examRecordQuesitonsEntity = getExamRecordQuestionsAndFixExamRecordDataIfNecessary(examRecordDataId);
|
|
|
|
+ if (examRecordQuesitonsEntity == null || examRecordQuesitonsEntity.getExamQuestionEntities() == null ||
|
|
|
|
+ examRecordQuesitonsEntity.getExamQuestionEntities().isEmpty()) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ List<ExamQuestionEntity> examQuestionList = examRecordQuesitonsEntity.getExamQuestionEntities();
|
|
|
|
+
|
|
|
|
+ int answerLength = 0;
|
|
|
|
+ for (ExamQuestionEntity examQuestionEntity : examQuestionList) {
|
|
|
|
+ if (!QuestionTypeUtil.isObjectiveQuestion(examQuestionEntity.getQuestionType())
|
|
|
|
+ && examQuestionEntity.getStudentAnswer() != null) {
|
|
|
|
+ answerLength += examQuestionEntity.getStudentAnswer().length();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return answerLength;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ExamRecordQuestionsEntity createExamRecordQuestions(Long examRecordDataId, DefaultPaper defaultPaper) {
|
|
|
|
+ ExamRecordQuestionsEntity examRecordQuestionsEntity = new ExamRecordQuestionsEntity();
|
|
|
|
+
|
|
|
|
+ List<ExamQuestionEntity> examQuestionEntityList = new ArrayList<ExamQuestionEntity>();
|
|
|
|
+ List<DefaultQuestionGroup> defaultQuestionGroups = defaultPaper.getQuestionGroupList();
|
|
|
|
+ int order = 0;
|
|
|
|
+ for (int i = 0; i < defaultQuestionGroups.size(); i++) {
|
|
|
|
+ DefaultQuestionGroup defaultQuestionGroup = defaultQuestionGroups.get(i);
|
|
|
|
+ List<DefaultQuestionStructureWrapper> defaultQuestionStructureWrappers = defaultQuestionGroup.getQuestionWrapperList();
|
|
|
|
+ for (DefaultQuestionStructureWrapper defaultQuestionStructureWrapper : defaultQuestionStructureWrappers) {
|
|
|
|
+ List<DefaultQuestionUnitWrapper> questionUnitWrapperList = defaultQuestionStructureWrapper.getQuestionUnitWrapperList();
|
|
|
|
+ for (DefaultQuestionUnitWrapper defaultQuestionUnitWrapper : questionUnitWrapperList) {
|
|
|
|
+ ExamQuestionEntity examQuestionEntity = new ExamQuestionEntity();
|
|
|
|
+ examQuestionEntity.setExamRecordDataId(examRecordDataId);
|
|
|
|
+ examQuestionEntity.setMainNumber(i + 1);
|
|
|
|
+ examQuestionEntity.setOrder(++order);
|
|
|
|
+ examQuestionEntity.setQuestionId(defaultQuestionStructureWrapper.getQuestionId());
|
|
|
|
+ examQuestionEntity.setQuestionScore(defaultQuestionUnitWrapper.getQuestionScore());
|
|
|
|
+ examQuestionEntity.setQuestionType(defaultQuestionUnitWrapper.getQuestionType());
|
|
|
|
+ examQuestionEntity.setOptionPermutation(defaultQuestionUnitWrapper.getOptionPermutation());
|
|
|
|
+ examQuestionEntity.setAudioPlayTimes(null);
|
|
|
|
+ examQuestionEntity.setAnswerType(defaultQuestionUnitWrapper.getAnswerType());
|
|
|
|
+
|
|
|
|
+ examQuestionEntityList.add(examQuestionEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ examRecordQuestionsEntity.setExamQuestionEntities(examQuestionEntityList);
|
|
|
|
+ examRecordQuestionsEntity.setExamRecordDataId(examRecordDataId);
|
|
|
|
+ examRecordQuestionsEntity.setCreationTime(new Date());
|
|
|
|
+ ExamRecordQuestionsEntity saveResult = examRecordQuestionsRepo.save(examRecordQuestionsEntity);
|
|
|
|
+// redisTemplate.opsForList().leftPushAll(examQuestionKeyPrefix+examRecordDataId,examQuestionEntityList);
|
|
|
|
+ return saveResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取考试作答记录并修复考试记录数据(如有必要)
|
|
|
|
+ *
|
|
|
|
+ * @param examRecordData 考试记录
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ExamRecordQuestionsEntity getExamRecordQuestionsAndFixExamRecordDataIfNecessary(ExamRecordDataEntity examRecordData) {
|
|
|
|
+ if (examRecordData == null) {
|
|
|
|
+ throw new StatusException("201101", "examRecordData参数不允许为空");
|
|
|
|
+ }
|
|
|
|
+ Long examRecordDataId = examRecordData.getId();
|
|
|
|
+ String examRecordQuestionId = examRecordData.getExamRecordQuestionsId();
|
|
|
|
+
|
|
|
|
+ //如果考试作答记录id不为空,则根据id查询考试作答记录
|
|
|
|
+ if (StringUtils.isNotEmpty(examRecordQuestionId)) {
|
|
|
|
+ return GlobalHelper.getEntity(examRecordQuestionsRepo, examRecordQuestionId,
|
|
|
|
+ ExamRecordQuestionsEntity.class);
|
|
|
|
+ }
|
|
|
|
+ //如果考试作答记录id为空,则根据考试记录id获取考试作答记录,并将考试作答记录id保存至examRecordData表中
|
|
|
|
+ else {
|
|
|
|
+ ExamRecordQuestionsEntity examRecordQuestionsEntity = examRecordQuestionsRepo.findByExamRecordDataId(examRecordDataId);
|
|
|
|
+
|
|
|
|
+ //将考试作答记录id保存至examRecordData表中,目的:纠正历史数据
|
|
|
|
+ examRecordDataRepo.updateExamRecordDataQuestionIdById(examRecordQuestionsEntity.getId(), examRecordData.getId());
|
|
|
|
+ return examRecordQuestionsEntity;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ExamRecordQuestionsEntity getExamRecordQuestionsAndFixExamRecordDataIfNecessary(Long examRecordDataId) {
|
|
|
|
+ ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo,
|
|
|
|
+ examRecordDataId, ExamRecordDataEntity.class);
|
|
|
|
+ return getExamRecordQuestionsAndFixExamRecordDataIfNecessary(examRecordData);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|