JudgedAnswersVO.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package cn.seecoder.judgement.vo;
  2. import cn.seecoder.judgement.dto.StudentAnswerDTO;
  3. import cn.seecoder.judgement.vo.question.BaseQuestionVO;
  4. import lombok.AllArgsConstructor;
  5. import lombok.Data;
  6. import lombok.NoArgsConstructor;
  7. import lombok.NonNull;
  8. import java.math.BigDecimal;
  9. import java.time.LocalDateTime;
  10. import java.util.List;
  11. import java.util.Map;
  12. import java.util.stream.Collectors;
  13. /**
  14. * @author cst
  15. */
  16. @Data
  17. @NoArgsConstructor
  18. public class JudgedAnswersVO {
  19. /**
  20. * 回答情况
  21. */
  22. private Map<String, QuestionStudentAnswerInfo> answers;
  23. /**
  24. * 提交时间
  25. */
  26. private LocalDateTime submitAt;
  27. /**
  28. * 已提交次数
  29. */
  30. private Integer submitNumber;
  31. /**
  32. * 自动化判分的分数
  33. */
  34. private BigDecimal score;
  35. public JudgedAnswersVO(Map<String, QuestionStudentAnswerInfo> answers){
  36. this.answers = answers;
  37. }
  38. public JudgedAnswersVO(@NonNull Map<String, StudentAnswerDTO.AnswerRecordDTO> records, List<BaseQuestionVO> baseQuestionVOList) {
  39. /* this.quizId = quizStudentAnswer.getQuiz().getId();
  40. this.quizName = quizStudentAnswer.getQuiz().getName();
  41. this.studentId = quizStudentAnswer.getStudent().getId();
  42. this.studentName = quizStudentAnswer.getStudent().getName();*/
  43. this.answers = baseQuestionVOList.parallelStream()
  44. .map(baseQuestionVO -> {
  45. String questionId = baseQuestionVO.getId();
  46. StudentAnswerDTO.AnswerRecordDTO questionRecord = records.get(questionId);
  47. Object questionStudentAnswer = questionRecord.getAnswer();
  48. return QuestionStudentAnswerInfo.of(questionId, questionStudentAnswer, baseQuestionVO.pass(questionStudentAnswer));
  49. })
  50. .collect(Collectors.toMap(QuestionStudentAnswerInfo::getQuestionId, questionStudentAnswerInfo -> questionStudentAnswerInfo));
  51. /* this.submitAt = quizStudentAnswer.getSubmitAt();
  52. this.submitNumber = quizStudentAnswer.getSubmitNumber();
  53. this.score = quizStudentAnswer.getScore();*/
  54. }
  55. @Data
  56. @NoArgsConstructor
  57. @AllArgsConstructor(staticName = "of")
  58. public static class QuestionStudentAnswerInfo {
  59. private String questionId;
  60. private Object answer;
  61. private Boolean correct;
  62. }
  63. }