龚焕茏
2024-06-05 c93bdeb8ed528d015865f763dfc240cbad7aa00b
src/main/java/com/ycl/jxkg/service/impl/ExamPaperQuestionCustomerAnswerServiceImpl.java
@@ -1,21 +1,22 @@
package com.ycl.jxkg.service.impl;
import com.ycl.jxkg.domain.ExamPaperQuestionCustomerAnswer;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.jxkg.domain.entity.ExamPaperQuestionCustomerAnswer;
import com.ycl.jxkg.domain.other.ExamPaperAnswerUpdate;
import com.ycl.jxkg.domain.other.KeyValue;
import com.ycl.jxkg.domain.TextContent;
import com.ycl.jxkg.domain.entity.TextContent;
import com.ycl.jxkg.domain.enums.QuestionTypeEnum;
import com.ycl.jxkg.repository.ExamPaperQuestionCustomerAnswerMapper;
import com.ycl.jxkg.mapper.ExamPaperQuestionCustomerAnswerMapper;
import com.ycl.jxkg.service.ExamPaperQuestionCustomerAnswerService;
import com.ycl.jxkg.service.TextContentService;
import com.ycl.jxkg.utility.DateTimeUtil;
import com.ycl.jxkg.utility.ExamUtil;
import com.ycl.jxkg.utility.JsonUtil;
import com.ycl.jxkg.viewmodel.student.exam.ExamPaperSubmitItemVM;
import com.ycl.jxkg.viewmodel.student.question.answer.QuestionPageStudentRequestVM;
import com.ycl.jxkg.utils.DateTimeUtil;
import com.ycl.jxkg.utils.ExamUtil;
import com.ycl.jxkg.utils.JsonUtil;
import com.ycl.jxkg.domain.vo.student.exam.ExamPaperSubmitItemVO;
import com.ycl.jxkg.domain.vo.student.question.answer.QuestionPageStudentRequestVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Date;
@@ -23,21 +24,15 @@
import java.util.stream.Collectors;
@Service
public class ExamPaperQuestionCustomerAnswerServiceImpl extends BaseServiceImpl<ExamPaperQuestionCustomerAnswer> implements ExamPaperQuestionCustomerAnswerService {
@RequiredArgsConstructor
public class ExamPaperQuestionCustomerAnswerServiceImpl extends ServiceImpl<ExamPaperQuestionCustomerAnswerMapper, ExamPaperQuestionCustomerAnswer> implements ExamPaperQuestionCustomerAnswerService {
    private final ExamPaperQuestionCustomerAnswerMapper examPaperQuestionCustomerAnswerMapper;
    private final TextContentService textContentService;
    @Autowired
    public ExamPaperQuestionCustomerAnswerServiceImpl(ExamPaperQuestionCustomerAnswerMapper examPaperQuestionCustomerAnswerMapper, TextContentService textContentService) {
        super(examPaperQuestionCustomerAnswerMapper);
        this.examPaperQuestionCustomerAnswerMapper = examPaperQuestionCustomerAnswerMapper;
        this.textContentService = textContentService;
    }
    @Override
    public PageInfo<ExamPaperQuestionCustomerAnswer> studentPage(QuestionPageStudentRequestVM requestVM) {
    public PageInfo<ExamPaperQuestionCustomerAnswer> studentPage(QuestionPageStudentRequestVO requestVM) {
        return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() ->
                examPaperQuestionCustomerAnswerMapper.studentPage(requestVM)
        );
@@ -55,16 +50,16 @@
    }
    @Override
    public ExamPaperSubmitItemVM examPaperQuestionCustomerAnswerToVM(ExamPaperQuestionCustomerAnswer qa) {
        ExamPaperSubmitItemVM examPaperSubmitItemVM = new ExamPaperSubmitItemVM();
        examPaperSubmitItemVM.setId(qa.getId());
        examPaperSubmitItemVM.setQuestionId(qa.getQuestionId());
        examPaperSubmitItemVM.setDoRight(qa.getDoRight());
        examPaperSubmitItemVM.setItemOrder(qa.getItemOrder());
        examPaperSubmitItemVM.setQuestionScore(ExamUtil.scoreToVM(qa.getQuestionScore()));
        examPaperSubmitItemVM.setScore(ExamUtil.scoreToVM(qa.getCustomerScore()));
        setSpecialToVM(examPaperSubmitItemVM, qa);
        return examPaperSubmitItemVM;
    public ExamPaperSubmitItemVO examPaperQuestionCustomerAnswerToVM(ExamPaperQuestionCustomerAnswer qa) {
        ExamPaperSubmitItemVO examPaperSubmitItemVO = new ExamPaperSubmitItemVO();
        examPaperSubmitItemVO.setId(qa.getId());
        examPaperSubmitItemVO.setQuestionId(qa.getQuestionId());
        examPaperSubmitItemVO.setDoRight(qa.getDoRight());
        examPaperSubmitItemVO.setItemOrder(qa.getItemOrder());
        examPaperSubmitItemVO.setQuestionScore(ExamUtil.scoreToVM(qa.getQuestionScore()));
        examPaperSubmitItemVO.setScore(ExamUtil.scoreToVM(qa.getCustomerScore()));
        setSpecialToVM(examPaperSubmitItemVO, qa);
        return examPaperSubmitItemVO;
    }
    @Override
@@ -89,24 +84,24 @@
        return examPaperQuestionCustomerAnswerMapper.updateScore(examPaperAnswerUpdates);
    }
    private void setSpecialToVM(ExamPaperSubmitItemVM examPaperSubmitItemVM, ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer) {
    private void setSpecialToVM(ExamPaperSubmitItemVO examPaperSubmitItemVO, ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer) {
        QuestionTypeEnum questionTypeEnum = QuestionTypeEnum.fromCode(examPaperQuestionCustomerAnswer.getQuestionType());
        switch (questionTypeEnum) {
            case MultipleChoice:
                examPaperSubmitItemVM.setContent(examPaperQuestionCustomerAnswer.getAnswer());
                examPaperSubmitItemVM.setContentArray(ExamUtil.contentToArray(examPaperQuestionCustomerAnswer.getAnswer()));
                examPaperSubmitItemVO.setContent(examPaperQuestionCustomerAnswer.getAnswer());
                examPaperSubmitItemVO.setContentArray(ExamUtil.contentToArray(examPaperQuestionCustomerAnswer.getAnswer()));
                break;
            case GapFilling:
                TextContent textContent = textContentService.selectById(examPaperQuestionCustomerAnswer.getTextContentId());
                TextContent textContent = textContentService.getById(examPaperQuestionCustomerAnswer.getTextContentId());
                List<String> correctAnswer = JsonUtil.toJsonListObject(textContent.getContent(), String.class);
                examPaperSubmitItemVM.setContentArray(correctAnswer);
                examPaperSubmitItemVO.setContentArray(correctAnswer);
                break;
            default:
                if (QuestionTypeEnum.needSaveTextContent(examPaperQuestionCustomerAnswer.getQuestionType())) {
                    TextContent content = textContentService.selectById(examPaperQuestionCustomerAnswer.getTextContentId());
                    examPaperSubmitItemVM.setContent(content.getContent());
                    TextContent content = textContentService.getById(examPaperQuestionCustomerAnswer.getTextContentId());
                    examPaperSubmitItemVO.setContent(content.getContent());
                } else {
                    examPaperSubmitItemVM.setContent(examPaperQuestionCustomerAnswer.getAnswer());
                    examPaperSubmitItemVO.setContent(examPaperQuestionCustomerAnswer.getAnswer());
                }
                break;
        }