| | |
| | | package com.ycl.jxkg.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.jxkg.domain.*; |
| | | import com.ycl.jxkg.domain.enums.ExamPaperAnswerStatusEnum; |
| | | import com.ycl.jxkg.domain.enums.ExamPaperTypeEnum; |
| | |
| | | import com.ycl.jxkg.domain.other.KeyValue; |
| | | import com.ycl.jxkg.domain.other.ExamPaperAnswerUpdate; |
| | | import com.ycl.jxkg.domain.task.TaskItemAnswerObject; |
| | | import com.ycl.jxkg.repository.ExamPaperAnswerMapper; |
| | | import com.ycl.jxkg.repository.ExamPaperMapper; |
| | | import com.ycl.jxkg.repository.QuestionMapper; |
| | | import com.ycl.jxkg.repository.TaskExamCustomerAnswerMapper; |
| | | import com.ycl.jxkg.mapper.ExamPaperAnswerMapper; |
| | | import com.ycl.jxkg.mapper.ExamPaperMapper; |
| | | import com.ycl.jxkg.mapper.QuestionMapper; |
| | | import com.ycl.jxkg.mapper.TaskExamCustomerAnswerMapper; |
| | | import com.ycl.jxkg.service.ExamPaperAnswerService; |
| | | 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.exam.ExamPaperSubmitVM; |
| | | import com.ycl.jxkg.viewmodel.student.exampaper.ExamPaperAnswerPageVM; |
| | | import com.ycl.jxkg.utils.DateTimeUtil; |
| | | import com.ycl.jxkg.utils.ExamUtil; |
| | | import com.ycl.jxkg.utils.JsonUtil; |
| | | import com.ycl.jxkg.vo.admin.paper.ExamPaperAnswerPageRequestVO; |
| | | import com.ycl.jxkg.vo.student.exam.ExamPaperSubmitItemVO; |
| | | import com.ycl.jxkg.vo.student.exam.ExamPaperSubmitVO; |
| | | import com.ycl.jxkg.vo.student.exampaper.ExamPaperAnswerPageVO; |
| | | 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 org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class ExamPaperAnswerServiceImpl extends BaseServiceImpl<ExamPaperAnswer> implements ExamPaperAnswerService { |
| | | @RequiredArgsConstructor |
| | | public class ExamPaperAnswerServiceImpl extends ServiceImpl<ExamPaperAnswerMapper ,ExamPaperAnswer> implements ExamPaperAnswerService { |
| | | |
| | | private final ExamPaperAnswerMapper examPaperAnswerMapper; |
| | | private final ExamPaperMapper examPaperMapper; |
| | |
| | | private final ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService; |
| | | private final TaskExamCustomerAnswerMapper taskExamCustomerAnswerMapper; |
| | | |
| | | @Autowired |
| | | public ExamPaperAnswerServiceImpl(ExamPaperAnswerMapper examPaperAnswerMapper, ExamPaperMapper examPaperMapper, TextContentService textContentService, QuestionMapper questionMapper, ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService, TaskExamCustomerAnswerMapper taskExamCustomerAnswerMapper) { |
| | | super(examPaperAnswerMapper); |
| | | this.examPaperAnswerMapper = examPaperAnswerMapper; |
| | | this.examPaperMapper = examPaperMapper; |
| | | this.textContentService = textContentService; |
| | | this.questionMapper = questionMapper; |
| | | this.examPaperQuestionCustomerAnswerService = examPaperQuestionCustomerAnswerService; |
| | | this.taskExamCustomerAnswerMapper = taskExamCustomerAnswerMapper; |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<ExamPaperAnswer> studentPage(ExamPaperAnswerPageVM requestVM) { |
| | | public PageInfo<ExamPaperAnswer> studentPage(ExamPaperAnswerPageVO requestVM) { |
| | | return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() -> |
| | | examPaperAnswerMapper.studentPage(requestVM)); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ExamPaperAnswerInfo calculateExamPaperAnswer(ExamPaperSubmitVM examPaperSubmitVM, User user) { |
| | | public ExamPaperAnswerInfo calculateExamPaperAnswer(ExamPaperSubmitVO examPaperSubmitVO, User user) { |
| | | ExamPaperAnswerInfo examPaperAnswerInfo = new ExamPaperAnswerInfo(); |
| | | Date now = new Date(); |
| | | ExamPaper examPaper = examPaperMapper.selectByPrimaryKey(examPaperSubmitVM.getId()); |
| | | ExamPaper examPaper = examPaperMapper.selectById(examPaperSubmitVO.getId()); |
| | | ExamPaperTypeEnum paperTypeEnum = ExamPaperTypeEnum.fromCode(examPaper.getPaperType()); |
| | | //任务试卷只能做一次 |
| | | if (paperTypeEnum == ExamPaperTypeEnum.Task) { |
| | | ExamPaperAnswer examPaperAnswer = examPaperAnswerMapper.getByPidUid(examPaperSubmitVM.getId(), user.getId()); |
| | | ExamPaperAnswer examPaperAnswer = examPaperAnswerMapper.getByPidUid(examPaperSubmitVO.getId(), user.getId()); |
| | | if (null != examPaperAnswer) |
| | | return null; |
| | | } |
| | | String frameTextContent = textContentService.selectById(examPaper.getFrameTextContentId()).getContent(); |
| | | String frameTextContent = textContentService.getById(examPaper.getFrameTextContentId()).getContent(); |
| | | List<ExamPaperTitleItemObject> examPaperTitleItemObjects = JsonUtil.toJsonListObject(frameTextContent, ExamPaperTitleItemObject.class); |
| | | List<Integer> questionIds = examPaperTitleItemObjects.stream().flatMap(t -> t.getQuestionItems().stream().map(q -> q.getId())).collect(Collectors.toList()); |
| | | List<Question> questions = questionMapper.selectByIds(questionIds); |
| | |
| | | .flatMap(t -> t.getQuestionItems().stream() |
| | | .map(q -> { |
| | | Question question = questions.stream().filter(tq -> tq.getId().equals(q.getId())).findFirst().get(); |
| | | ExamPaperSubmitItemVM customerQuestionAnswer = examPaperSubmitVM.getAnswerItems().stream() |
| | | ExamPaperSubmitItemVO customerQuestionAnswer = examPaperSubmitVO.getAnswerItems().stream() |
| | | .filter(tq -> tq.getQuestionId().equals(q.getId())) |
| | | .findFirst() |
| | | .orElse(null); |
| | |
| | | }) |
| | | ).collect(Collectors.toList()); |
| | | |
| | | ExamPaperAnswer examPaperAnswer = ExamPaperAnswerFromVM(examPaperSubmitVM, examPaper, examPaperQuestionCustomerAnswers, user, now); |
| | | ExamPaperAnswer examPaperAnswer = ExamPaperAnswerFromVM(examPaperSubmitVO, examPaper, examPaperQuestionCustomerAnswers, user, now); |
| | | examPaperAnswerInfo.setExamPaper(examPaper); |
| | | examPaperAnswerInfo.setExamPaperAnswer(examPaperAnswer); |
| | | examPaperAnswerInfo.setExamPaperQuestionCustomerAnswers(examPaperQuestionCustomerAnswers); |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public String judge(ExamPaperSubmitVM examPaperSubmitVM) { |
| | | ExamPaperAnswer examPaperAnswer = examPaperAnswerMapper.selectByPrimaryKey(examPaperSubmitVM.getId()); |
| | | List<ExamPaperSubmitItemVM> judgeItems = examPaperSubmitVM.getAnswerItems().stream().filter(d -> d.getDoRight() == null).collect(Collectors.toList()); |
| | | public String judge(ExamPaperSubmitVO examPaperSubmitVO) { |
| | | ExamPaperAnswer examPaperAnswer = examPaperAnswerMapper.selectById(examPaperSubmitVO.getId()); |
| | | List<ExamPaperSubmitItemVO> judgeItems = examPaperSubmitVO.getAnswerItems().stream().filter(d -> d.getDoRight() == null).collect(Collectors.toList()); |
| | | List<ExamPaperAnswerUpdate> examPaperAnswerUpdates = new ArrayList<>(judgeItems.size()); |
| | | Integer customerScore = examPaperAnswer.getUserScore(); |
| | | Integer questionCorrect = examPaperAnswer.getQuestionCorrect(); |
| | | for (ExamPaperSubmitItemVM d : judgeItems) { |
| | | for (ExamPaperSubmitItemVO d : judgeItems) { |
| | | ExamPaperAnswerUpdate examPaperAnswerUpdate = new ExamPaperAnswerUpdate(); |
| | | examPaperAnswerUpdate.setId(d.getId()); |
| | | examPaperAnswerUpdate.setCustomerScore(ExamUtil.scoreFromVM(d.getScore())); |
| | |
| | | examPaperAnswer.setUserScore(customerScore); |
| | | examPaperAnswer.setQuestionCorrect(questionCorrect); |
| | | examPaperAnswer.setStatus(ExamPaperAnswerStatusEnum.Complete.getCode()); |
| | | examPaperAnswerMapper.updateByPrimaryKeySelective(examPaperAnswer); |
| | | examPaperAnswerMapper.updateById(examPaperAnswer); |
| | | examPaperQuestionCustomerAnswerService.updateScore(examPaperAnswerUpdates); |
| | | |
| | | ExamPaperTypeEnum examPaperTypeEnum = ExamPaperTypeEnum.fromCode(examPaperAnswer.getPaperType()); |
| | | switch (examPaperTypeEnum) { |
| | | case Task: |
| | | //任务试卷批改完成后,需要更新任务的状态 |
| | | ExamPaper examPaper = examPaperMapper.selectByPrimaryKey(examPaperAnswer.getExamPaperId()); |
| | | ExamPaper examPaper = examPaperMapper.selectById(examPaperAnswer.getExamPaperId()); |
| | | Integer taskId = examPaper.getTaskExamId(); |
| | | Integer userId = examPaperAnswer.getCreateUser(); |
| | | TaskExamCustomerAnswer taskExamCustomerAnswer = taskExamCustomerAnswerMapper.getByTUid(taskId, userId); |
| | | TextContent textContent = textContentService.selectById(taskExamCustomerAnswer.getTextContentId()); |
| | | TextContent textContent = textContentService.getById(taskExamCustomerAnswer.getTextContentId()); |
| | | List<TaskItemAnswerObject> taskItemAnswerObjects = JsonUtil.toJsonListObject(textContent.getContent(), TaskItemAnswerObject.class); |
| | | taskItemAnswerObjects.stream() |
| | | .filter(d -> d.getExamPaperAnswerId().equals(examPaperAnswer.getId())) |
| | | .findFirst().ifPresent(taskItemAnswerObject -> taskItemAnswerObject.setStatus(examPaperAnswer.getStatus())); |
| | | textContentService.jsonConvertUpdate(textContent, taskItemAnswerObjects, null); |
| | | textContentService.updateByIdFilter(textContent); |
| | | textContentService.updateById(textContent); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ExamPaperSubmitVM examPaperAnswerToVM(Integer id) { |
| | | ExamPaperSubmitVM examPaperSubmitVM = new ExamPaperSubmitVM(); |
| | | ExamPaperAnswer examPaperAnswer = examPaperAnswerMapper.selectByPrimaryKey(id); |
| | | examPaperSubmitVM.setId(examPaperAnswer.getId()); |
| | | examPaperSubmitVM.setDoTime(examPaperAnswer.getDoTime()); |
| | | examPaperSubmitVM.setScore(ExamUtil.scoreToVM(examPaperAnswer.getUserScore())); |
| | | public ExamPaperSubmitVO examPaperAnswerToVM(Integer id) { |
| | | ExamPaperSubmitVO examPaperSubmitVO = new ExamPaperSubmitVO(); |
| | | ExamPaperAnswer examPaperAnswer = examPaperAnswerMapper.selectById(id); |
| | | examPaperSubmitVO.setId(examPaperAnswer.getId()); |
| | | examPaperSubmitVO.setDoTime(examPaperAnswer.getDoTime()); |
| | | examPaperSubmitVO.setScore(ExamUtil.scoreToVM(examPaperAnswer.getUserScore())); |
| | | List<ExamPaperQuestionCustomerAnswer> examPaperQuestionCustomerAnswers = examPaperQuestionCustomerAnswerService.selectListByPaperAnswerId(examPaperAnswer.getId()); |
| | | List<ExamPaperSubmitItemVM> examPaperSubmitItemVMS = examPaperQuestionCustomerAnswers.stream() |
| | | List<ExamPaperSubmitItemVO> examPaperSubmitItemVOS = examPaperQuestionCustomerAnswers.stream() |
| | | .map(a -> examPaperQuestionCustomerAnswerService.examPaperQuestionCustomerAnswerToVM(a)) |
| | | .collect(Collectors.toList()); |
| | | examPaperSubmitVM.setAnswerItems(examPaperSubmitItemVMS); |
| | | return examPaperSubmitVM; |
| | | examPaperSubmitVO.setAnswerItems(examPaperSubmitItemVOS); |
| | | return examPaperSubmitVO; |
| | | } |
| | | |
| | | @Override |
| | |
| | | * @param now now |
| | | * @return ExamPaperQuestionCustomerAnswer |
| | | */ |
| | | private ExamPaperQuestionCustomerAnswer ExamPaperQuestionCustomerAnswerFromVM(Question question, ExamPaperSubmitItemVM customerQuestionAnswer, ExamPaper examPaper, Integer itemOrder, User user, Date now) { |
| | | private ExamPaperQuestionCustomerAnswer ExamPaperQuestionCustomerAnswerFromVM(Question question, ExamPaperSubmitItemVO customerQuestionAnswer, ExamPaper examPaper, Integer itemOrder, User user, Date now) { |
| | | ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer = new ExamPaperQuestionCustomerAnswer(); |
| | | examPaperQuestionCustomerAnswer.setQuestionId(question.getId()); |
| | | examPaperQuestionCustomerAnswer.setExamPaperId(examPaper.getId()); |
| | |
| | | * @param question question |
| | | * @param customerQuestionAnswer customerQuestionAnswer |
| | | */ |
| | | private void setSpecialFromVM(ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer, Question question, ExamPaperSubmitItemVM customerQuestionAnswer) { |
| | | private void setSpecialFromVM(ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer, Question question, ExamPaperSubmitItemVO customerQuestionAnswer) { |
| | | QuestionTypeEnum questionTypeEnum = QuestionTypeEnum.fromCode(examPaperQuestionCustomerAnswer.getQuestionType()); |
| | | switch (questionTypeEnum) { |
| | | case SingleChoice: |
| | |
| | | } |
| | | } |
| | | |
| | | private ExamPaperAnswer ExamPaperAnswerFromVM(ExamPaperSubmitVM examPaperSubmitVM, ExamPaper examPaper, List<ExamPaperQuestionCustomerAnswer> examPaperQuestionCustomerAnswers, User user, Date now) { |
| | | private ExamPaperAnswer ExamPaperAnswerFromVM(ExamPaperSubmitVO examPaperSubmitVO, ExamPaper examPaper, List<ExamPaperQuestionCustomerAnswer> examPaperQuestionCustomerAnswers, User user, Date now) { |
| | | Integer systemScore = examPaperQuestionCustomerAnswers.stream().mapToInt(a -> a.getCustomerScore()).sum(); |
| | | long questionCorrect = examPaperQuestionCustomerAnswers.stream().filter(a -> a.getCustomerScore().equals(a.getQuestionScore())).count(); |
| | | ExamPaperAnswer examPaperAnswer = new ExamPaperAnswer(); |
| | | examPaperAnswer.setPaperName(examPaper.getName()); |
| | | examPaperAnswer.setDoTime(examPaperSubmitVM.getDoTime()); |
| | | examPaperAnswer.setDoTime(examPaperSubmitVO.getDoTime()); |
| | | examPaperAnswer.setExamPaperId(examPaper.getId()); |
| | | examPaperAnswer.setCreateUser(user.getId()); |
| | | examPaperAnswer.setCreateTime(now); |
| | |
| | | |
| | | |
| | | @Override |
| | | public PageInfo<ExamPaperAnswer> adminPage(com.ycl.jxkg.viewmodel.admin.paper.ExamPaperAnswerPageRequestVM requestVM) { |
| | | public PageInfo<ExamPaperAnswer> adminPage(ExamPaperAnswerPageRequestVO requestVM) { |
| | | return PageHelper.startPage(requestVM.getPageIndex(), requestVM.getPageSize(), "id desc").doSelectPageInfo(() -> |
| | | examPaperAnswerMapper.adminPage(requestVM)); |
| | | } |