|
@@ -179,8 +179,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
*/
|
|
|
public List<PaperQuestion> questionShuffle(List<PaperQuestion> paperQuestionList) {
|
|
|
List<PaperQuestion> shuffleList = new ArrayList<>();
|
|
|
- Map<Integer, List<PaperQuestion>> map = paperQuestionList.stream()
|
|
|
- .collect(Collectors.groupingBy(PaperQuestion::getQuestionType, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ Map<Integer, List<PaperQuestion>> map = paperQuestionList.stream().collect(Collectors.groupingBy(PaperQuestion::getQuestionType, LinkedHashMap::new, Collectors.toList()));
|
|
|
for (Map.Entry<Integer, List<PaperQuestion>> item : map.entrySet()) {
|
|
|
//题目洗牌
|
|
|
Collections.shuffle(item.getValue());
|
|
@@ -247,8 +246,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
List<QuestionAnswer> answerList = question.getAnswerList();
|
|
|
if (!CollectionUtils.isEmpty(answerList)) {
|
|
|
//答案乱序(支持单选题,多选题)
|
|
|
- if (!Objects.isNull(exam.getAnswerDisorder()) && exam.getAnswerDisorder()
|
|
|
- && (QuestionType.RADIO.getCode().equals(question.getType()) || QuestionType.MULTI.getCode().equals(question.getType()))) {
|
|
|
+ if (!Objects.isNull(exam.getAnswerDisorder()) && exam.getAnswerDisorder() && (QuestionType.RADIO.getCode().equals(question.getType()) || QuestionType.MULTI.getCode().equals(question.getType()))) {
|
|
|
//答案洗牌
|
|
|
Collections.shuffle(answerList);
|
|
|
}
|
|
@@ -311,8 +309,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
* 保存试卷试题列表
|
|
|
*/
|
|
|
private void savePaperQuestion(String userExamId, List<PaperQuestion> paperQuestionList) {
|
|
|
- paperQuestionList = paperQuestionList.stream().sorted(Comparator.comparing(PaperQuestion::getQuestionType)
|
|
|
- .thenComparing(PaperQuestion::getSort)).collect(Collectors.toList());
|
|
|
+ paperQuestionList = paperQuestionList.stream().sorted(Comparator.comparing(PaperQuestion::getQuestionType).thenComparing(PaperQuestion::getSort)).collect(Collectors.toList());
|
|
|
//获取规则组map
|
|
|
Map<String, PaperRuleGroup> groupMap = getGroupMap(paperQuestionList);
|
|
|
|
|
@@ -352,8 +349,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
return examDetail(userExamId, false, false, true, false);
|
|
|
}
|
|
|
|
|
|
- public UserExamDTO examDetail(String userExamId, boolean needAnswerFlag, boolean needAnalysis,
|
|
|
- boolean needClearBlankContent, boolean needRenderBlank) {
|
|
|
+ public UserExamDTO examDetail(String userExamId, boolean needAnswerFlag, boolean needAnalysis, boolean needClearBlankContent, boolean needRenderBlank) {
|
|
|
UserExamDTO dto = new UserExamDTO();
|
|
|
UserExam userExam = userExamService.listUserExam(userExamId);
|
|
|
if (Objects.isNull(userExam)) {
|
|
@@ -364,8 +360,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
List<Map<String, AnswerCardDTO>> answerCardList = new ArrayList<>();
|
|
|
if (!CollectionUtils.isEmpty(userExamQuestionList)) {
|
|
|
//获取题目和答案
|
|
|
- Map<String, Question> questionMap = getUserExamQuestionMap(userExamId, userExamQuestionList, needAnswerFlag,
|
|
|
- needAnalysis, false, true, needClearBlankContent);
|
|
|
+ Map<String, Question> questionMap = getUserExamQuestionMap(userExamId, userExamQuestionList, needAnswerFlag, needAnalysis, false, true, needClearBlankContent);
|
|
|
|
|
|
//设置题目
|
|
|
setUserExamQuestion(questionMap, userExamQuestionList, needRenderBlank);
|
|
@@ -399,23 +394,34 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
public void setAnswerTag(UserExamDTO userExamDTO) {
|
|
|
List<UserExamQuestion> userExamQuestionList = userExamDTO.getUserExamQuestionList();
|
|
|
if (!CollectionUtils.isEmpty(userExamQuestionList)) {
|
|
|
- userExamQuestionList.stream().forEach(userExamQuestion -> {
|
|
|
- if (QuestionType.RADIO.getCode().equals(userExamQuestion.getQuestionType())
|
|
|
- || QuestionType.MULTI.getCode().equals(userExamQuestion.getQuestionType())
|
|
|
- || QuestionType.JUDGE.getCode().equals(userExamQuestion.getQuestionType())) {
|
|
|
- String answer = userExamQuestion.getAnswer();
|
|
|
- if (!Objects.isNull(userExamQuestion.getQuestion())) {
|
|
|
- List<QuestionAnswer> answerList = userExamQuestion.getQuestion().getAnswerList();
|
|
|
- if (StringUtils.isNotBlank(answer) && !CollectionUtils.isEmpty(answerList)) {
|
|
|
- List<String> answers = Arrays.asList(answer.split(","));
|
|
|
- List<QuestionAnswer> resultAnswerList = answerList.stream().filter(item -> answers.contains(item.getId())).collect(Collectors.toList());
|
|
|
- List<String> tagList = resultAnswerList.stream().map(QuestionAnswer::getTag).collect(Collectors.toList());
|
|
|
- userExamQuestion.setAnswer(String.join(",", tagList.stream().sorted().collect(Collectors.toList())));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ userExamQuestionList.stream().forEach(userExamQuestion -> userExamQuestion
|
|
|
+ .setAnswer(generateQuestionAnswerTag(userExamQuestion.getAnswer(), userExamQuestion.getQuestion())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成单选,单选,填空答案tag
|
|
|
+ *
|
|
|
+ * @param userAnswer
|
|
|
+ * @param question
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String generateQuestionAnswerTag(String userAnswer, Question question) {
|
|
|
+ if (Objects.isNull(question)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (QuestionType.RADIO.getCode().equals(question.getType()) || QuestionType.MULTI.getCode().equals(question.getType())
|
|
|
+ || QuestionType.JUDGE.getCode().equals(question.getType())) {
|
|
|
+ List<QuestionAnswer> answerList = question.getAnswerList();
|
|
|
+ if (StringUtils.isNotBlank(userAnswer) && !CollectionUtils.isEmpty(answerList)) {
|
|
|
+ List<String> answers = Arrays.asList(userAnswer.split(","));
|
|
|
+ List<QuestionAnswer> resultAnswerList = answerList.stream().filter(item -> answers.contains(item.getId())).collect(Collectors.toList());
|
|
|
+ List<String> tagList = resultAnswerList.stream().map(QuestionAnswer::getTag).collect(Collectors.toList());
|
|
|
+ return tagList.stream().sorted().collect(Collectors.joining(","));
|
|
|
+ }
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -452,8 +458,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
Map<String, QuestionAnswer> answerMap = answerList.stream().collect(Collectors.toMap(QuestionAnswer::getTag, a -> a, (k1, k2) -> k1));
|
|
|
for (QuestionAnswer a : answerList) {
|
|
|
String fontColor = !Objects.isNull(a.getIsRight()) && a.getIsRight() ? "#00bb00" : "red";
|
|
|
- content = content.replaceAll("\\>" + a.getTag() + "\\<\\/span\\>", " style=\"color:"
|
|
|
- + fontColor + ";font-weight:bold\">" + answerMap.get(a.getTag()).getContent() + "</span>");
|
|
|
+ content = content.replaceAll("\\>" + a.getTag() + "\\<\\/span\\>", " style=\"color:" + fontColor + ";font-weight:bold\">" + answerMap.get(a.getTag()).getContent() + "</span>");
|
|
|
}
|
|
|
}
|
|
|
question.setContent(content);
|
|
@@ -466,8 +471,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
* @param answerCardList
|
|
|
*/
|
|
|
public void setAnswerCard(List<UserExamQuestion> userExamQuestionList, List<Map<String, AnswerCardDTO>> answerCardList) {
|
|
|
- Map<Integer, List<UserExamQuestion>> map = userExamQuestionList.stream()
|
|
|
- .collect(Collectors.groupingBy(UserExamQuestion::getQuestionType, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ Map<Integer, List<UserExamQuestion>> map = userExamQuestionList.stream().collect(Collectors.groupingBy(UserExamQuestion::getQuestionType, LinkedHashMap::new, Collectors.toList()));
|
|
|
for (Map.Entry<Integer, List<UserExamQuestion>> item : map.entrySet()) {
|
|
|
AnswerCardDTO answerCard = new AnswerCardDTO();
|
|
|
List<UserExamQuestion> questions = item.getValue();
|
|
@@ -513,12 +517,10 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
updateObjectiveQuestion(userExamQuestionList);
|
|
|
} else {
|
|
|
//有作答
|
|
|
- Map<Integer, UserExamQuestion> userExamQuestionMap = userExamQuestionList.stream().collect(Collectors
|
|
|
- .toMap(UserExamQuestion::getQuestionIndex, a -> a, (k1, k2) -> k1));
|
|
|
+ Map<Integer, UserExamQuestion> userExamQuestionMap = userExamQuestionList.stream().collect(Collectors.toMap(UserExamQuestion::getQuestionIndex, a -> a, (k1, k2) -> k1));
|
|
|
|
|
|
//获取题目和答案
|
|
|
- Map<String, Question> questionMap = getUserExamQuestionMap(dto.getUserExamId(), userExamQuestionList, true,
|
|
|
- false, true, false, false);
|
|
|
+ Map<String, Question> questionMap = getUserExamQuestionMap(dto.getUserExamId(), userExamQuestionList, true, false, true, false, false);
|
|
|
|
|
|
//计算客观题得分
|
|
|
int score = calcObjectiveScore(examAnswers, userExamQuestionMap, questionMap, userExamQuestionList);
|
|
@@ -539,8 +541,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
* @param userExamQuestionList
|
|
|
*/
|
|
|
public void updateObjectiveQuestion(List<UserExamQuestion> userExamQuestionList) {
|
|
|
- List<UserExamQuestion> objectiveList = userExamQuestionList.stream().filter(o ->
|
|
|
- !o.getQuestionType().equals(QuestionType.SIMPLE.getCode())).collect(Collectors.toList());
|
|
|
+ List<UserExamQuestion> objectiveList = userExamQuestionList.stream().filter(o -> !o.getQuestionType().equals(QuestionType.SIMPLE.getCode())).collect(Collectors.toList());
|
|
|
if (!CollectionUtils.isEmpty(objectiveList)) {
|
|
|
objectiveList.stream().forEach(o -> {
|
|
|
o.setAnswered(false);
|
|
@@ -551,20 +552,15 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
}
|
|
|
|
|
|
//获取题目和答案
|
|
|
- public Map<String, Question> getUserExamQuestionMap(String userExamId, List<UserExamQuestion> userExamQuestionList,
|
|
|
- boolean needAnswerFlag, boolean needAnalysis,
|
|
|
- boolean needPathScore, boolean needSubjective, boolean needClearBlankContent) {
|
|
|
+ public Map<String, Question> getUserExamQuestionMap(String userExamId, List<UserExamQuestion> userExamQuestionList, boolean needAnswerFlag, boolean needAnalysis, boolean needPathScore, boolean needSubjective, boolean needClearBlankContent) {
|
|
|
List<String> subjectiveList = null;
|
|
|
if (needSubjective) {//是否需要主观题
|
|
|
- subjectiveList = userExamQuestionList.stream().filter(o -> o.getQuestionType()
|
|
|
- .equals(QuestionType.SIMPLE.getCode())).map(UserExamQuestion::getQuestionId).collect(Collectors.toList());
|
|
|
+ subjectiveList = userExamQuestionList.stream().filter(o -> o.getQuestionType().equals(QuestionType.SIMPLE.getCode())).map(UserExamQuestion::getQuestionId).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
//客观题
|
|
|
- List<String> objectiveList = userExamQuestionList.stream().filter(o ->
|
|
|
- !o.getQuestionType().equals(QuestionType.SIMPLE.getCode())).map(UserExamQuestion::getQuestionId).collect(Collectors.toList());
|
|
|
- List<Question> questionList = questionService.listUserExamQuestionAnswer(userExamId, objectiveList,
|
|
|
- subjectiveList, needAnswerFlag, needAnalysis, needPathScore, needSubjective);
|
|
|
+ List<String> objectiveList = userExamQuestionList.stream().filter(o -> !o.getQuestionType().equals(QuestionType.SIMPLE.getCode())).map(UserExamQuestion::getQuestionId).collect(Collectors.toList());
|
|
|
+ List<Question> questionList = questionService.listUserExamQuestionAnswer(userExamId, objectiveList, subjectiveList, needAnswerFlag, needAnalysis, needPathScore, needSubjective);
|
|
|
//题目答案重新排序
|
|
|
if (!CollectionUtils.isEmpty(questionList)) {
|
|
|
questionList.stream().forEach(question -> {
|
|
@@ -595,8 +591,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
* @param questionMap
|
|
|
* @return
|
|
|
*/
|
|
|
- public int calcObjectiveScore(List<ExamAnswerDTO> examAnswers, Map<Integer, UserExamQuestion> userExamQuestionMap,
|
|
|
- Map<String, Question> questionMap, List<UserExamQuestion> userExamQuestionList) {
|
|
|
+ public int calcObjectiveScore(List<ExamAnswerDTO> examAnswers, Map<Integer, UserExamQuestion> userExamQuestionMap, Map<String, Question> questionMap, List<UserExamQuestion> userExamQuestionList) {
|
|
|
//最终得分
|
|
|
int score = 0;
|
|
|
if (!CollectionUtils.isEmpty(examAnswers)) {
|
|
@@ -645,8 +640,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
//获取回答过的题目
|
|
|
List<Integer> indexList = examAnswers.stream().map(ExamAnswerDTO::getIndex).collect(toList());
|
|
|
//获取没回答的客观题题目
|
|
|
- List<UserExamQuestion> objectiveNoAnswerList = userExamQuestionList.stream().filter(o -> !indexList.contains(o.getQuestionIndex())).filter(o ->
|
|
|
- !o.getQuestionType().equals(QuestionType.SIMPLE.getCode())).collect(Collectors.toList());
|
|
|
+ List<UserExamQuestion> objectiveNoAnswerList = userExamQuestionList.stream().filter(o -> !indexList.contains(o.getQuestionIndex())).filter(o -> !o.getQuestionType().equals(QuestionType.SIMPLE.getCode())).collect(Collectors.toList());
|
|
|
objectiveNoAnswerList.stream().forEach(o -> o.setIsRight(false));
|
|
|
|
|
|
userExamQuestionService.updateBatchById(userExamQuestionList);
|
|
@@ -732,8 +726,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
* @return
|
|
|
*/
|
|
|
public int sumRightAnswerScore(List<BlankAnswerResultDTO> dtoList) {
|
|
|
- return dtoList.stream().filter(d -> !Objects.isNull(d.getIsRight()) && d.getIsRight() && !Objects.isNull(d.getScore()))
|
|
|
- .mapToInt(BlankAnswerResultDTO::getScore).sum();
|
|
|
+ return dtoList.stream().filter(d -> !Objects.isNull(d.getIsRight()) && d.getIsRight() && !Objects.isNull(d.getScore())).mapToInt(BlankAnswerResultDTO::getScore).sum();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -769,8 +762,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
if (!Objects.isNull(answerArray) && answerArray.length > 0) {
|
|
|
List<String> asList = Arrays.asList(answerArray);
|
|
|
if (asList.contains(userAnswer.getContent().trim())) {
|
|
|
- dtoList.add(new BlankAnswerResultDTO(userAnswer.getTag(), userAnswer.getContent().trim(), true,
|
|
|
- !Objects.isNull(tmp.getPathScore()) ? tmp.getPathScore().intValue() : null));
|
|
|
+ dtoList.add(new BlankAnswerResultDTO(userAnswer.getTag(), userAnswer.getContent().trim(), true, !Objects.isNull(tmp.getPathScore()) ? tmp.getPathScore().intValue() : null));
|
|
|
} else {
|
|
|
dtoList.add(new BlankAnswerResultDTO(userAnswer.getTag(), userAnswer.getContent().trim(), false, null));
|
|
|
}
|
|
@@ -794,8 +786,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
|
|
|
if (!Objects.isNull(answerArray) && answerArray.length > 0) {
|
|
|
List<String> asList = Arrays.asList(answerArray);
|
|
|
if (asList.contains(userAnswer.getContent().trim())) {
|
|
|
- dtoList.add(new BlankAnswerResultDTO(userAnswer.getTag(), userAnswer.getContent().trim(), true,
|
|
|
- !Objects.isNull(qa.getPathScore()) ? qa.getPathScore().intValue() : null));
|
|
|
+ dtoList.add(new BlankAnswerResultDTO(userAnswer.getTag(), userAnswer.getContent().trim(), true, !Objects.isNull(qa.getPathScore()) ? qa.getPathScore().intValue() : null));
|
|
|
isTrue = true;
|
|
|
iterator.remove();
|
|
|
break;
|