| | |
| | | package com.ycl.jxkg.listener; |
| | | |
| | | import com.ycl.jxkg.domain.*; |
| | | import com.ycl.jxkg.domain.enums.ExamPaperTypeEnum; |
| | | import com.ycl.jxkg.domain.enums.QuestionTypeEnum; |
| | | import com.ycl.jxkg.domain.entity.ExamPaper; |
| | | import com.ycl.jxkg.domain.entity.ExamPaperScore; |
| | | import com.ycl.jxkg.domain.entity.ExamPaperScoreDetail; |
| | | import com.ycl.jxkg.domain.entity.TextContent; |
| | | import com.ycl.jxkg.enums.ExamPaperTypeEnum; |
| | | import com.ycl.jxkg.enums.QuestionTypeEnum; |
| | | import com.ycl.jxkg.event.CalculateExamPaperAnswerCompleteEvent; |
| | | import com.ycl.jxkg.service.ExamPaperAnswerService; |
| | | import com.ycl.jxkg.service.ExamPaperQuestionCustomerAnswerService; |
| | | import com.ycl.jxkg.service.ExamPaperScoreService; |
| | | import com.ycl.jxkg.service.ExamPaperScoreDetailService; |
| | | import com.ycl.jxkg.service.TaskExamCustomerAnswerService; |
| | | import com.ycl.jxkg.service.TextContentService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Component |
| | | public class CalculateExamPaperAnswerListener implements ApplicationListener<CalculateExamPaperAnswerCompleteEvent> { |
| | | |
| | | private final ExamPaperAnswerService examPaperAnswerService; |
| | | private final ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService; |
| | | private final ExamPaperScoreService examPaperScoreService; |
| | | private final ExamPaperScoreDetailService examPaperScoreDetailService; |
| | | private final TextContentService textContentService; |
| | | private final TaskExamCustomerAnswerService examCustomerAnswerService; |
| | | |
| | | /** |
| | | * Instantiates a new Calculate exam paper answer listener. |
| | | * |
| | | * @param examPaperAnswerService the exam paper answer service |
| | | * @param examPaperQuestionCustomerAnswerService the exam paper question customer answer service |
| | | * @param examPaperScoreService the exam paper answer service |
| | | * @param examPaperScoreDetailService the exam paper question customer answer service |
| | | * @param textContentService the text content service |
| | | * @param examCustomerAnswerService the exam customer answer service |
| | | */ |
| | | @Autowired |
| | | public CalculateExamPaperAnswerListener(ExamPaperAnswerService examPaperAnswerService, ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService, TextContentService textContentService, TaskExamCustomerAnswerService examCustomerAnswerService) { |
| | | this.examPaperAnswerService = examPaperAnswerService; |
| | | this.examPaperQuestionCustomerAnswerService = examPaperQuestionCustomerAnswerService; |
| | | public CalculateExamPaperAnswerListener(ExamPaperScoreService examPaperScoreService, ExamPaperScoreDetailService examPaperScoreDetailService, TextContentService textContentService, TaskExamCustomerAnswerService examCustomerAnswerService) { |
| | | this.examPaperScoreService = examPaperScoreService; |
| | | this.examPaperScoreDetailService = examPaperScoreDetailService; |
| | | this.textContentService = textContentService; |
| | | this.examCustomerAnswerService = examCustomerAnswerService; |
| | | } |
| | |
| | | |
| | | ExamPaperAnswerInfo examPaperAnswerInfo = (ExamPaperAnswerInfo) calculateExamPaperAnswerCompleteEvent.getSource(); |
| | | ExamPaper examPaper = examPaperAnswerInfo.getExamPaper(); |
| | | ExamPaperAnswer examPaperAnswer = examPaperAnswerInfo.getExamPaperAnswer(); |
| | | List<ExamPaperQuestionCustomerAnswer> examPaperQuestionCustomerAnswers = examPaperAnswerInfo.getExamPaperQuestionCustomerAnswers(); |
| | | ExamPaperScore examPaperScore = examPaperAnswerInfo.getExamPaperScore(); |
| | | List<ExamPaperScoreDetail> examPaperScoreDetails = examPaperAnswerInfo.getExamPaperScoreDetails(); |
| | | |
| | | examPaperAnswerService.save(examPaperAnswer); |
| | | examPaperQuestionCustomerAnswers.stream().filter(a -> QuestionTypeEnum.needSaveTextContent(a.getQuestionType())).forEach(d -> { |
| | | examPaperScoreService.save(examPaperScore); |
| | | examPaperScoreDetails.stream().filter(a -> QuestionTypeEnum.needSaveTextContent(a.getQuestionType())).forEach(d -> { |
| | | TextContent textContent = new TextContent(); |
| | | textContent.setContent(d.getAnswer()); |
| | | textContent.setCreateTime(now); |
| | |
| | | d.setTextContentId(textContent.getId()); |
| | | d.setAnswer(null); |
| | | }); |
| | | examPaperQuestionCustomerAnswers.forEach(d -> { |
| | | d.setExamPaperAnswerId(examPaperAnswer.getId()); |
| | | examPaperScoreDetails.forEach(d -> { |
| | | d.setExamPaperAnswerId(examPaperScore.getId()); |
| | | }); |
| | | examPaperQuestionCustomerAnswerService.insertList(examPaperQuestionCustomerAnswers); |
| | | examPaperScoreDetailService.insertList(examPaperScoreDetails); |
| | | |
| | | switch (ExamPaperTypeEnum.fromCode(examPaper.getPaperType())) { |
| | | case Task: { |
| | | examCustomerAnswerService.insertOrUpdate(examPaper, examPaperAnswer, now); |
| | | case RandomOrder: { |
| | | examCustomerAnswerService.insertOrUpdate(examPaper, examPaperScore, now); |
| | | break; |
| | | } |
| | | default: |