package com.mindskip.xzs.listener;
|
|
import com.mindskip.xzs.domain.*;
|
import com.mindskip.xzs.domain.enums.ExamPaperTypeEnum;
|
import com.mindskip.xzs.domain.enums.QuestionTypeEnum;
|
import com.mindskip.xzs.event.CalculateExamPaperAnswerCompleteEvent;
|
import com.mindskip.xzs.service.ExamPaperAnswerService;
|
import com.mindskip.xzs.service.ExamPaperQuestionCustomerAnswerService;
|
import com.mindskip.xzs.service.TaskExamCustomerAnswerService;
|
import com.mindskip.xzs.service.TextContentService;
|
import lombok.AllArgsConstructor;
|
import org.springframework.context.ApplicationListener;
|
import org.springframework.stereotype.Component;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Date;
|
import java.util.List;
|
|
|
/**
|
* @version 2.2.0
|
* @description: 分数计算完成监听器
|
* Copyright (C), 2020-2021, 武汉思维跳跃科技有限公司
|
* @date 2021 /9/7 9:45
|
*/
|
@Component
|
@AllArgsConstructor
|
public class CalculateExamPaperAnswerListener implements ApplicationListener<CalculateExamPaperAnswerCompleteEvent> {
|
|
|
private final ExamPaperAnswerService examPaperAnswerService;
|
private final ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService;
|
private final TextContentService textContentService;
|
private final TaskExamCustomerAnswerService examCustomerAnswerService;
|
|
/**
|
* 数据入库
|
*
|
* @param calculateExamPaperAnswerCompleteEvent
|
*/
|
@Override
|
@Transactional
|
public void onApplicationEvent(CalculateExamPaperAnswerCompleteEvent calculateExamPaperAnswerCompleteEvent) {
|
Date now = new Date();
|
|
ExamPaperAnswerInfo examPaperAnswerInfo = (ExamPaperAnswerInfo) calculateExamPaperAnswerCompleteEvent.getSource();
|
ExamPaper examPaper = examPaperAnswerInfo.getExamPaper();
|
ExamPaperAnswer examPaperAnswer = examPaperAnswerInfo.getExamPaperAnswer();
|
List<ExamPaperQuestionCustomerAnswer> examPaperQuestionCustomerAnswers = examPaperAnswerInfo.getExamPaperQuestionCustomerAnswers();
|
|
examPaperAnswerService.insertByFilter(examPaperAnswer);
|
examPaperQuestionCustomerAnswers.stream().filter(a -> QuestionTypeEnum.needSaveTextContent(a.getQuestionType())).forEach(d -> {
|
TextContent textContent = new TextContent(d.getAnswer(), now);
|
textContentService.insertByFilter(textContent);
|
d.setTextContentId(textContent.getId());
|
d.setAnswer(null);
|
});
|
examPaperQuestionCustomerAnswers.forEach(d -> {
|
d.setExamPaperAnswerId(examPaperAnswer.getId());
|
});
|
examPaperQuestionCustomerAnswerService.insertList(examPaperQuestionCustomerAnswers);
|
|
switch (ExamPaperTypeEnum.fromCode(examPaper.getPaperType())) {
|
case Task: {
|
examCustomerAnswerService.insertOrUpdate(examPaper, examPaperAnswer, now);
|
break;
|
}
|
default:
|
break;
|
}
|
}
|
}
|