package com.ycl.jxkg.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ycl.jxkg.domain.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.enums.QuestionTypeEnum; import com.ycl.jxkg.mapper.ExamPaperQuestionCustomerAnswerMapper; import com.ycl.jxkg.service.ExamPaperQuestionCustomerAnswerService; import com.ycl.jxkg.service.TextContentService; import com.ycl.jxkg.utils.DateTimeUtil; import com.ycl.jxkg.utils.ExamUtil; import com.ycl.jxkg.utils.JsonUtil; import com.ycl.jxkg.vo.student.exam.ExamPaperSubmitItemVO; import com.ycl.jxkg.vo.student.question.answer.QuestionPageStudentRequestVO; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @Service @RequiredArgsConstructor public class ExamPaperQuestionCustomerAnswerServiceImpl extends ServiceImpl implements ExamPaperQuestionCustomerAnswerService { private final ExamPaperQuestionCustomerAnswerMapper examPaperQuestionCustomerAnswerMapper; private final TextContentService textContentService; @Override public PageInfo studentPage(QuestionPageStudentRequestVO requestVM) { return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() -> examPaperQuestionCustomerAnswerMapper.studentPage(requestVM) ); } @Override public List selectListByPaperAnswerId(Integer id) { return examPaperQuestionCustomerAnswerMapper.selectListByPaperAnswerId(id); } @Override public void insertList(List examPaperQuestionCustomerAnswers) { examPaperQuestionCustomerAnswerMapper.insertList(examPaperQuestionCustomerAnswers); } @Override 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 public Integer selectAllCount() { return examPaperQuestionCustomerAnswerMapper.selectAllCount(); } @Override public List selectMothCount() { Date startTime = DateTimeUtil.getMonthStartDay(); Date endTime = DateTimeUtil.getMonthEndDay(); List mouthCount = examPaperQuestionCustomerAnswerMapper.selectCountByDate(startTime, endTime); List mothStartToNowFormat = DateTimeUtil.MothStartToNowFormat(); return mothStartToNowFormat.stream().map(md -> { KeyValue keyValue = mouthCount.stream().filter(kv -> kv.getName().equals(md)).findAny().orElse(null); return null == keyValue ? 0 : keyValue.getValue(); }).collect(Collectors.toList()); } @Override public int updateScore(List examPaperAnswerUpdates) { return examPaperQuestionCustomerAnswerMapper.updateScore(examPaperAnswerUpdates); } private void setSpecialToVM(ExamPaperSubmitItemVO examPaperSubmitItemVO, ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer) { QuestionTypeEnum questionTypeEnum = QuestionTypeEnum.fromCode(examPaperQuestionCustomerAnswer.getQuestionType()); switch (questionTypeEnum) { case MultipleChoice: examPaperSubmitItemVO.setContent(examPaperQuestionCustomerAnswer.getAnswer()); examPaperSubmitItemVO.setContentArray(ExamUtil.contentToArray(examPaperQuestionCustomerAnswer.getAnswer())); break; case GapFilling: TextContent textContent = textContentService.getById(examPaperQuestionCustomerAnswer.getTextContentId()); List correctAnswer = JsonUtil.toJsonListObject(textContent.getContent(), String.class); examPaperSubmitItemVO.setContentArray(correctAnswer); break; default: if (QuestionTypeEnum.needSaveTextContent(examPaperQuestionCustomerAnswer.getQuestionType())) { TextContent content = textContentService.getById(examPaperQuestionCustomerAnswer.getTextContentId()); examPaperSubmitItemVO.setContent(content.getContent()); } else { examPaperSubmitItemVO.setContent(examPaperQuestionCustomerAnswer.getAnswer()); } break; } } }