|
@@ -1,7 +1,23 @@
|
|
|
package cn.com.qmth.examcloud.core.oe.admin.service.impl;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.bean.MarkResultScoreBean;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.request.ClearMarkResultReq;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.request.SaveSubjectiveQuestionScoreReq;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.utils.Check;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.utils.QuestionTypeUtil;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordDataRepo;
|
|
@@ -13,22 +29,12 @@ import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamRecordQuestionsEntity;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamScoreEntity;
|
|
|
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.bean.SubjectiveQuestionScoreInfo;
|
|
|
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.QuestionType;
|
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
@Service("examRecordQuestionsService")
|
|
|
public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsService {
|
|
@@ -47,9 +53,38 @@ public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsServic
|
|
|
@Autowired
|
|
|
private ExamStudentFinalScoreService examStudentFinalScoreService;
|
|
|
|
|
|
+ @Override
|
|
|
+ public void clearSubjectiveScore(ClearMarkResultReq req) {
|
|
|
+ ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo, req.getExamRecordDataId(),
|
|
|
+ ExamRecordDataEntity.class);
|
|
|
+ // MongoDB清除小题得分
|
|
|
+ if (ExamType.ONLINE == examRecordData.getExamType()
|
|
|
+ || ExamType.ONLINE_HOMEWORK == examRecordData.getExamType()) {
|
|
|
+ ExamRecordQuestionsEntity eqs = getExamRecordQuestionsAndFixExamRecordDataIfNecessary(examRecordData);
|
|
|
+ if (eqs != null && CollectionUtils.isNotEmpty(eqs.getExamQuestionEntities())) {
|
|
|
+ for (ExamQuestionEntity eq : eqs.getExamQuestionEntities()) {
|
|
|
+ if (!isObjecttive(eq.getQuestionType())) {
|
|
|
+ eq.setStudentScore(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ examRecordQuestionsRepo.save(eqs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Boolean isObjecttive(QuestionType type) {
|
|
|
+ if (QuestionType.SINGLE_CHOICE.equals(type) || QuestionType.MULTIPLE_CHOICE.equals(type)
|
|
|
+ || QuestionType.TRUE_OR_FALSE.equals(type)) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<ExamQuestionEntity> querySubjectiveAnswerList(Long examRecordDataId) {
|
|
|
- ExamRecordQuestionsEntity examRecordQuestionsEntity = getExamRecordQuestionsAndFixExamRecordDataIfNecessary(examRecordDataId);
|
|
|
+ ExamRecordQuestionsEntity examRecordQuestionsEntity = getExamRecordQuestionsAndFixExamRecordDataIfNecessary(
|
|
|
+ examRecordDataId);
|
|
|
List<ExamQuestionEntity> examRecordQuestionList = examRecordQuestionsEntity.getExamQuestionEntities();
|
|
|
return examRecordQuestionList.stream().filter((obj -> {
|
|
|
return !QuestionTypeUtil.isObjectiveQuestion(obj.getQuestionType());
|
|
@@ -57,48 +92,47 @@ public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsServic
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void saveSubjectiveQuestionScore(Long examRecordDataId, List<SubjectiveQuestionScoreInfo> subjectiveQuestionScoreInfoList) {
|
|
|
- ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo, examRecordDataId, ExamRecordDataEntity.class);
|
|
|
-
|
|
|
- if (ExamType.ONLINE == examRecordData.getExamType() || ExamType.ONLINE_HOMEWORK == examRecordData.getExamType()) {
|
|
|
- ExamRecordQuestionsEntity examRecordQuestionsEntity = getExamRecordQuestionsAndFixExamRecordDataIfNecessary(examRecordData);
|
|
|
-
|
|
|
- List<ExamQuestionEntity> examRecordQuestionList = examRecordQuestionsEntity.getExamQuestionEntities();
|
|
|
- for (SubjectiveQuestionScoreInfo scoreInfo : subjectiveQuestionScoreInfoList) {
|
|
|
- for (ExamQuestionEntity examQuestionEntity : examRecordQuestionList) {
|
|
|
- if (scoreInfo.getQuestionId().equals(examQuestionEntity.getQuestionId())
|
|
|
- && scoreInfo.getOrder().intValue() == examQuestionEntity.getOrder().intValue()) {
|
|
|
- examQuestionEntity.setStudentScore(scoreInfo.getScore());
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- examRecordQuestionsRepo.save(examRecordQuestionsEntity);
|
|
|
- }
|
|
|
+ public void saveSubjectiveQuestionScore(SaveSubjectiveQuestionScoreReq req) {
|
|
|
+ ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo, req.getExamRecordDataId(),
|
|
|
+ ExamRecordDataEntity.class);
|
|
|
|
|
|
- //计算主观题总得分
|
|
|
+ // 计算主观题总得分
|
|
|
double totalSubjectiveScore = 0D;
|
|
|
- for (SubjectiveQuestionScoreInfo scoreInfo : subjectiveQuestionScoreInfoList) {
|
|
|
+ for (MarkResultScoreBean scoreInfo : req.getScores()) {
|
|
|
totalSubjectiveScore += scoreInfo.getScore();
|
|
|
}
|
|
|
|
|
|
- //更新ec_oe_exam_score
|
|
|
- ExamScoreEntity examScoreEntity = examScoreRepo.findByExamRecordDataId(examRecordDataId);
|
|
|
+ // 更新ec_oe_exam_score
|
|
|
+ ExamScoreEntity examScoreEntity = examScoreRepo.findByExamRecordDataId(req.getExamRecordDataId());
|
|
|
examScoreEntity.setSubjectiveScore(totalSubjectiveScore);
|
|
|
double totalScore = totalSubjectiveScore + examScoreEntity.getObjectiveScore();
|
|
|
examScoreEntity.setTotalScore(totalScore);
|
|
|
examScoreRepo.save(examScoreEntity);
|
|
|
|
|
|
- //计算考生的最终分数
|
|
|
+ // 计算考生的最终分数
|
|
|
examStudentFinalScoreService.calcAndSaveFinalScore(examRecordData.getExamStudentId());
|
|
|
+
|
|
|
+ // MongoDB保存小题得分
|
|
|
+ if (ExamType.ONLINE == examRecordData.getExamType()
|
|
|
+ || ExamType.ONLINE_HOMEWORK == examRecordData.getExamType()) {
|
|
|
+ ExamRecordQuestionsEntity eqs = getExamRecordQuestionsAndFixExamRecordDataIfNecessary(examRecordData);
|
|
|
+ if (eqs != null && CollectionUtils.isNotEmpty(eqs.getExamQuestionEntities())) {
|
|
|
+ Map<Integer, Double> scoreMap = req.getScores().stream().collect(Collectors
|
|
|
+ .toMap(MarkResultScoreBean::getOrders, MarkResultScoreBean::getScore, (key1, key2) -> key2));
|
|
|
+ for (ExamQuestionEntity eq : eqs.getExamQuestionEntities()) {
|
|
|
+ eq.setStudentScore(scoreMap.get(eq.getOrder()));
|
|
|
+ }
|
|
|
+ examRecordQuestionsRepo.save(eqs);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Integer calculationSubjectiveAnswerLength(Long examRecordDataId) {
|
|
|
- ExamRecordQuestionsEntity examRecordQuesitonsEntity = getExamRecordQuestionsAndFixExamRecordDataIfNecessary(examRecordDataId);
|
|
|
- if (examRecordQuesitonsEntity == null || examRecordQuesitonsEntity.getExamQuestionEntities() == null ||
|
|
|
- examRecordQuesitonsEntity.getExamQuestionEntities().isEmpty()) {
|
|
|
+ ExamRecordQuestionsEntity examRecordQuesitonsEntity = getExamRecordQuestionsAndFixExamRecordDataIfNecessary(
|
|
|
+ examRecordDataId);
|
|
|
+ if (examRecordQuesitonsEntity == null || examRecordQuesitonsEntity.getExamQuestionEntities() == null
|
|
|
+ || examRecordQuesitonsEntity.getExamQuestionEntities().isEmpty()) {
|
|
|
return 0;
|
|
|
}
|
|
|
List<ExamQuestionEntity> examQuestionList = examRecordQuesitonsEntity.getExamQuestionEntities();
|
|
@@ -122,9 +156,11 @@ public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsServic
|
|
|
int order = 0;
|
|
|
for (int i = 0; i < defaultQuestionGroups.size(); i++) {
|
|
|
DefaultQuestionGroup defaultQuestionGroup = defaultQuestionGroups.get(i);
|
|
|
- List<DefaultQuestionStructureWrapper> defaultQuestionStructureWrappers = defaultQuestionGroup.getQuestionWrapperList();
|
|
|
+ List<DefaultQuestionStructureWrapper> defaultQuestionStructureWrappers = defaultQuestionGroup
|
|
|
+ .getQuestionWrapperList();
|
|
|
for (DefaultQuestionStructureWrapper defaultQuestionStructureWrapper : defaultQuestionStructureWrappers) {
|
|
|
- List<DefaultQuestionUnitWrapper> questionUnitWrapperList = defaultQuestionStructureWrapper.getQuestionUnitWrapperList();
|
|
|
+ List<DefaultQuestionUnitWrapper> questionUnitWrapperList = defaultQuestionStructureWrapper
|
|
|
+ .getQuestionUnitWrapperList();
|
|
|
for (DefaultQuestionUnitWrapper defaultQuestionUnitWrapper : questionUnitWrapperList) {
|
|
|
ExamQuestionEntity examQuestionEntity = new ExamQuestionEntity();
|
|
|
examQuestionEntity.setExamRecordDataId(examRecordDataId);
|
|
@@ -146,18 +182,20 @@ public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsServic
|
|
|
examRecordQuestionsEntity.setExamRecordDataId(examRecordDataId);
|
|
|
examRecordQuestionsEntity.setCreationTime(new Date());
|
|
|
ExamRecordQuestionsEntity saveResult = examRecordQuestionsRepo.save(examRecordQuestionsEntity);
|
|
|
- // redisTemplate.opsForList().leftPushAll(examQuestionKeyPrefix+examRecordDataId,examQuestionEntityList);
|
|
|
+ // redisTemplate.opsForList().leftPushAll(examQuestionKeyPrefix+examRecordDataId,examQuestionEntityList);
|
|
|
return saveResult;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取考试作答记录并修复考试记录数据(如有必要)
|
|
|
*
|
|
|
- * @param examRecordData 考试记录
|
|
|
+ * @param examRecordData
|
|
|
+ * 考试记录
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public ExamRecordQuestionsEntity getExamRecordQuestionsAndFixExamRecordDataIfNecessary(ExamRecordDataEntity examRecordData) {
|
|
|
+ public ExamRecordQuestionsEntity getExamRecordQuestionsAndFixExamRecordDataIfNecessary(
|
|
|
+ ExamRecordDataEntity examRecordData) {
|
|
|
if (examRecordData == null) {
|
|
|
throw new StatusException("201101", "examRecordData参数不允许为空");
|
|
|
}
|
|
@@ -167,30 +205,33 @@ public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsServic
|
|
|
|
|
|
ExamRecordQuestionsEntity examRecordQuestions;
|
|
|
if (StringUtils.isNotEmpty(examRecordQuestionId)) {
|
|
|
- //如果考试作答记录id不为空,则根据id查询考试作答记录
|
|
|
- examRecordQuestions = GlobalHelper.getEntity(examRecordQuestionsRepo, examRecordQuestionId, ExamRecordQuestionsEntity.class);
|
|
|
+ // 如果考试作答记录id不为空,则根据id查询考试作答记录
|
|
|
+ examRecordQuestions = GlobalHelper.getEntity(examRecordQuestionsRepo, examRecordQuestionId,
|
|
|
+ ExamRecordQuestionsEntity.class);
|
|
|
} else {
|
|
|
- //如果考试作答记录id为空,则根据考试记录id获取考试作答记录,并将考试作答记录id保存至examRecordData表中
|
|
|
+ // 如果考试作答记录id为空,则根据考试记录id获取考试作答记录,并将考试作答记录id保存至examRecordData表中
|
|
|
examRecordQuestions = examRecordQuestionsRepo.findByExamRecordDataId(examRecordDataId);
|
|
|
|
|
|
if (examRecordQuestions == null) {
|
|
|
- log.warn("examRecordQuestions is null, examRecordDataId = {} examType:{}", examRecordData.getId(), examRecordData.getExamType());
|
|
|
+ log.warn("examRecordQuestions is null, examRecordDataId = {} examType:{}", examRecordData.getId(),
|
|
|
+ examRecordData.getExamType());
|
|
|
throw new StatusException("201101", "examRecordQuestions为空");
|
|
|
}
|
|
|
|
|
|
- //将考试作答记录id保存至examRecordData表中,目的:纠正历史数据
|
|
|
+ // 将考试作答记录id保存至examRecordData表中,目的:纠正历史数据
|
|
|
examRecordData.setExamRecordQuestionsId(examRecordQuestions.getId());
|
|
|
examRecordDataRepo.updateExamRecordDataQuestionIdById(examRecordQuestions.getId(), examRecordData.getId());
|
|
|
}
|
|
|
|
|
|
- // List<ExamQuestionEntity> examQuestions = examRecordQuestions.getExamQuestionEntities();
|
|
|
+ // List<ExamQuestionEntity> examQuestions =
|
|
|
+ // examRecordQuestions.getExamQuestionEntities();
|
|
|
// for (ExamQuestionEntity examQuestion : examQuestions) {
|
|
|
- // if (QuestionType.SINGLE_CHOICE == examQuestion.getQuestionType() ||
|
|
|
- // QuestionType.MULTIPLE_CHOICE == examQuestion.getQuestionType()) {
|
|
|
- // // 选择题 - 转换为新答案格式(兼容旧格式)
|
|
|
- // examQuestion.setCorrectAnswer(QuestionOptionHelper.parseNumbers(examQuestion.getCorrectAnswer()));
|
|
|
- // examQuestion.setStudentAnswer(QuestionOptionHelper.parseNumbers(examQuestion.getStudentAnswer()));
|
|
|
- // }
|
|
|
+ // if (QuestionType.SINGLE_CHOICE == examQuestion.getQuestionType() ||
|
|
|
+ // QuestionType.MULTIPLE_CHOICE == examQuestion.getQuestionType()) {
|
|
|
+ // // 选择题 - 转换为新答案格式(兼容旧格式)
|
|
|
+ // examQuestion.setCorrectAnswer(QuestionOptionHelper.parseNumbers(examQuestion.getCorrectAnswer()));
|
|
|
+ // examQuestion.setStudentAnswer(QuestionOptionHelper.parseNumbers(examQuestion.getStudentAnswer()));
|
|
|
+ // }
|
|
|
// }
|
|
|
|
|
|
return examRecordQuestions;
|
|
@@ -200,7 +241,8 @@ public class ExamRecordQuestionsServiceImpl implements ExamRecordQuestionsServic
|
|
|
public ExamRecordQuestionsEntity getExamRecordQuestionsAndFixExamRecordDataIfNecessary(Long examRecordDataId) {
|
|
|
Check.isNull(examRecordDataId, "examRecordDataId不能为空");
|
|
|
|
|
|
- ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo, examRecordDataId, ExamRecordDataEntity.class);
|
|
|
+ ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo, examRecordDataId,
|
|
|
+ ExamRecordDataEntity.class);
|
|
|
return getExamRecordQuestionsAndFixExamRecordDataIfNecessary(examRecordData);
|
|
|
}
|
|
|
|