|
@@ -3,12 +3,15 @@ package com.ynfy.buss.exam.paperquestionanswer.service.impl;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ynfy.buss.exam.exam.service.IExamService;
|
|
|
import com.ynfy.buss.exam.paperquestionanswer.entity.PaperQuestionAnswer;
|
|
|
import com.ynfy.buss.exam.paperquestionanswer.mapper.PaperQuestionAnswerMapper;
|
|
|
import com.ynfy.buss.exam.paperquestionanswer.service.IPaperQuestionAnswerService;
|
|
|
import com.ynfy.buss.exam.question.entity.Question;
|
|
|
import com.ynfy.buss.exam.question.enums.QuestionType;
|
|
|
import com.ynfy.buss.exam.questionanswer.entity.QuestionAnswer;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
@@ -26,6 +29,10 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class PaperQuestionAnswerServiceImpl extends ServiceImpl<PaperQuestionAnswerMapper, PaperQuestionAnswer> implements IPaperQuestionAnswerService {
|
|
|
|
|
|
+ @Lazy
|
|
|
+ @Autowired
|
|
|
+ private IExamService examService;
|
|
|
+
|
|
|
@Override
|
|
|
public List<PaperQuestionAnswer> listByPaperId(String paperId) {
|
|
|
LambdaQueryWrapper<PaperQuestionAnswer> wrapper = new LambdaQueryWrapper<>();
|
|
@@ -46,13 +53,19 @@ public class PaperQuestionAnswerServiceImpl extends ServiceImpl<PaperQuestionAns
|
|
|
if (!CollectionUtils.isEmpty(answerList)) {
|
|
|
List<PaperQuestionAnswer> paperQuestionAnswerList = new ArrayList<>();
|
|
|
if (QuestionType.COMBINATION.getCode().equals(groupQuestionType)) {//组合题
|
|
|
- answerList.stream().forEach(answer -> {
|
|
|
- //计算每个答案得分
|
|
|
+ if (QuestionType.MULTI.getCode().equals(question.getType())) {
|
|
|
+ //找出正确答案
|
|
|
+ answerList = examService.findRightList(answerList);
|
|
|
+ double pathScore = NumberUtil.div(question.getScore().intValue(), answerList.size(), 2);
|
|
|
+ answerList.stream().forEach(answer ->
|
|
|
+ //生成试卷试题答案
|
|
|
+ paperQuestionAnswerList.add(generatePaperQuestionAnswer(paperId, question.getId(), answer.getId(), pathScore)));
|
|
|
+ } else if (QuestionType.BLANK.getCode().equals(question.getType())) {
|
|
|
double pathScore = NumberUtil.div(question.getScore().intValue(), answerList.size(), 2);
|
|
|
- //生成试卷试题答案
|
|
|
- PaperQuestionAnswer pqa = generatePaperQuestionAnswer(paperId, question.getId(), answer.getId(), pathScore);
|
|
|
- paperQuestionAnswerList.add(pqa);
|
|
|
- });
|
|
|
+ answerList.stream().forEach(answer ->
|
|
|
+ paperQuestionAnswerList.add(generatePaperQuestionAnswer(paperId, question.getId(), answer.getId(), pathScore)));
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
List<QuestionAnswer> pathScoreList = answerList.stream().filter(o ->
|
|
|
!Objects.isNull(o.getPathScore()) && o.getPathScore() > 0).collect(Collectors.toList());
|