|
|
@@ -11,6 +11,7 @@ import com.fs.live.param.LiveCompletionCouponAnswerItem;
|
|
|
import com.fs.live.param.LiveCompletionCouponAnswerParam;
|
|
|
import com.fs.live.param.LiveCompletionCouponClaimParam;
|
|
|
import com.fs.live.service.*;
|
|
|
+import com.fs.live.vo.LiveCompletionAnswerDetailVO;
|
|
|
import com.fs.live.vo.LiveCompletionCouponAnswerResult;
|
|
|
import com.fs.live.vo.LiveCompletionCouponConfigVO;
|
|
|
import com.fs.live.vo.LiveCompletionCouponInfoVO;
|
|
|
@@ -72,6 +73,9 @@ public class LiveCompletionCouponServiceImpl implements ILiveCompletionCouponSer
|
|
|
@Autowired
|
|
|
private ILiveConsoleOpLogService liveConsoleOpLogService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ILiveCompletionAnswerRecordService liveCompletionAnswerRecordService;
|
|
|
+
|
|
|
@Override
|
|
|
public LiveCompletionCouponConfigVO parseCompletionCouponConfig(Live live) {
|
|
|
LiveCompletionCouponConfigVO vo = new LiveCompletionCouponConfigVO();
|
|
|
@@ -213,11 +217,14 @@ public class LiveCompletionCouponServiceImpl implements ILiveCompletionCouponSer
|
|
|
}
|
|
|
|
|
|
List<LiveCompletionCouponAnswerItem> normalizedAnswers = normalizeUserAnswers(param.getAnswers());
|
|
|
- boolean allCorrect = evaluateAnswers(normalizedAnswers, configuredQuestionIds);
|
|
|
- saveAnswerRecordToday(liveId, userId, allCorrect);
|
|
|
+ AnswerEvaluation evaluation = evaluateAnswersWithDetails(normalizedAnswers, configuredQuestionIds);
|
|
|
+ saveAnswerRecordToday(liveId, userId, evaluation.isAllCorrect());
|
|
|
+ Long recordId = liveCompletionAnswerRecordService.saveAnswerRecord(
|
|
|
+ liveId, userId, evaluation.isAllCorrect(), normalizedAnswers, evaluation.getDetails());
|
|
|
|
|
|
LiveCompletionCouponAnswerResult result = new LiveCompletionCouponAnswerResult();
|
|
|
- result.setAllCorrect(allCorrect);
|
|
|
+ result.setAllCorrect(evaluation.isAllCorrect());
|
|
|
+ result.setRecordId(recordId);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -332,9 +339,10 @@ public class LiveCompletionCouponServiceImpl implements ILiveCompletionCouponSer
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 校验是否答完全部题目,并返回是否全部答对(答错不阻断记录)
|
|
|
+ * 校验是否答完全部题目,并返回是否全部答对及每题明细(答错不阻断记录)
|
|
|
*/
|
|
|
- private boolean evaluateAnswers(List<LiveCompletionCouponAnswerItem> userAnswers, List<Long> configuredQuestionIds) {
|
|
|
+ private AnswerEvaluation evaluateAnswersWithDetails(List<LiveCompletionCouponAnswerItem> userAnswers,
|
|
|
+ List<Long> configuredQuestionIds) {
|
|
|
Set<Long> submittedIds = userAnswers.stream()
|
|
|
.map(LiveCompletionCouponAnswerItem::getQuestionId)
|
|
|
.filter(Objects::nonNull)
|
|
|
@@ -350,16 +358,27 @@ public class LiveCompletionCouponServiceImpl implements ILiveCompletionCouponSer
|
|
|
.collect(Collectors.toMap(LiveQuestionBank::getId, q -> q));
|
|
|
|
|
|
boolean allCorrect = true;
|
|
|
+ List<LiveCompletionAnswerDetailVO> details = new ArrayList<>();
|
|
|
for (LiveCompletionCouponAnswerItem userAnswer : userAnswers) {
|
|
|
LiveQuestionBank correctAnswer = correctAnswersMap.get(userAnswer.getQuestionId());
|
|
|
if (correctAnswer == null || correctAnswer.getStatus() == null || correctAnswer.getStatus() == 0) {
|
|
|
throw new BaseException("题目不存在或已停用");
|
|
|
}
|
|
|
- if (!isAnswerCorrect(userAnswer.getAnswer(), correctAnswer)) {
|
|
|
+ boolean questionCorrect = isAnswerCorrect(userAnswer.getAnswer(), correctAnswer);
|
|
|
+ if (!questionCorrect) {
|
|
|
allCorrect = false;
|
|
|
}
|
|
|
+
|
|
|
+ LiveCompletionAnswerDetailVO detail = new LiveCompletionAnswerDetailVO();
|
|
|
+ detail.setQuestionId(userAnswer.getQuestionId());
|
|
|
+ detail.setTitle(correctAnswer.getTitle());
|
|
|
+ detail.setType(correctAnswer.getType());
|
|
|
+ detail.setUserAnswer(userAnswer.getAnswer());
|
|
|
+ detail.setCorrectAnswer(correctAnswer.getAnswer());
|
|
|
+ detail.setIsRight(questionCorrect ? 1 : 0);
|
|
|
+ details.add(detail);
|
|
|
}
|
|
|
- return allCorrect;
|
|
|
+ return new AnswerEvaluation(allCorrect, details);
|
|
|
}
|
|
|
|
|
|
private boolean isAnswerCorrect(String userAnswerValue, LiveQuestionBank correctAnswer) {
|
|
|
@@ -698,4 +717,22 @@ public class LiveCompletionCouponServiceImpl implements ILiveCompletionCouponSer
|
|
|
this.allCorrect = allCorrect;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private static class AnswerEvaluation {
|
|
|
+ private final boolean allCorrect;
|
|
|
+ private final List<LiveCompletionAnswerDetailVO> details;
|
|
|
+
|
|
|
+ private AnswerEvaluation(boolean allCorrect, List<LiveCompletionAnswerDetailVO> details) {
|
|
|
+ this.allCorrect = allCorrect;
|
|
|
+ this.details = details;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isAllCorrect() {
|
|
|
+ return allCorrect;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<LiveCompletionAnswerDetailVO> getDetails() {
|
|
|
+ return details;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|