|
@@ -16,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -57,6 +58,8 @@ public class PaperResultService {
|
|
|
public Result parseResult(PaperCommit paperCommit, Paper paper) {
|
|
|
List<Question> questions = paper.getQuestions();
|
|
|
List<Answer> answers = convertAnswer(paperCommit.getJsonAns());
|
|
|
+ //map化
|
|
|
+ Map<Integer, Answer> mapAnswers = answers.stream().collect(Collectors.toMap(Answer::getNumber, Function.identity()));
|
|
|
List<Integer> collectQuestion = new ArrayList<>();
|
|
|
PaperResult result = new PaperResult();
|
|
|
result.setPid(paperCommit.getPid());
|
|
@@ -71,15 +74,20 @@ public class PaperResultService {
|
|
|
//清空value为0
|
|
|
pData.keySet().forEach(d -> pData.put(d, 0d));
|
|
|
double score = 0d;
|
|
|
+ //分析对比答案
|
|
|
+ List<AnswerContrast> contrasts = new ArrayList<>();
|
|
|
for (Question q : questions) {
|
|
|
String ans = q.getAnswer();
|
|
|
if (StringUtils.isBlank(ans)) {
|
|
|
continue;
|
|
|
}
|
|
|
//找到对应题目的答案
|
|
|
- Answer a = answers.stream().filter(answer -> answer.getNumber() == q.getNumber())
|
|
|
- .findFirst().orElse(null);
|
|
|
+// Answer a = answers.stream().filter(answer -> answer.getNumber() == q.getNumber())
|
|
|
+// .findFirst().orElse(null);
|
|
|
+ Answer a = mapAnswers.getOrDefault(q.getNumber(), null);
|
|
|
if (a == null || StringUtils.isBlank(a.getOptions())) {
|
|
|
+ AnswerContrast contrast = new AnswerContrast(q.getId(), q.getNumber(), a == null ? "" : a.getOptions(), ans);
|
|
|
+ contrasts.add(contrast);
|
|
|
continue;
|
|
|
}
|
|
|
//检测答案的对错,如果答案为空或者全部对上该题目正确
|
|
@@ -97,6 +105,7 @@ public class PaperResultService {
|
|
|
}
|
|
|
//对的选项进行升序排序
|
|
|
collectQuestion.sort(Integer::compareTo);
|
|
|
+ result.setWrongAnswerContrast(ObjectUtil.object2Json(contrasts));
|
|
|
result.setCollectQuestion(StringUtils.join(collectQuestion, ","));
|
|
|
//错误选项
|
|
|
List<Integer> wrongQuestions = generateWrongQuestion(paper, collectQuestion);
|
|
@@ -108,7 +117,8 @@ public class PaperResultService {
|
|
|
result.setScore(totalScore == 0 ? score : s);
|
|
|
result.setTotalScore(totalScore);
|
|
|
paperResultRepo.save(result);
|
|
|
- logger.info("答案分析保存成功");
|
|
|
+ logger.info("答案分析保存成功,pid={},uid={},name={},score={},collectQuestion={}", paper.getId(),
|
|
|
+ paperCommit.getUid(), paperCommit.getName(), result.getScore(), result.getCollectQuestion());
|
|
|
return Result.ok(result);
|
|
|
}
|
|
|
|