| | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.ycl.jxkg.context.WebContext; |
| | | import com.ycl.jxkg.domain.entity.*; |
| | | import com.ycl.jxkg.domain.exam.PaperFixQuestionDTO; |
| | | import com.ycl.jxkg.domain.vo.*; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperEditRequestVO; |
| | | import com.ycl.jxkg.enums.ExamPaperTypeEnum; |
| | | import com.ycl.jxkg.enums.QuestionTypeEnum; |
| | | import com.ycl.jxkg.enums.general.ExamStatusEnum; |
| | | import com.ycl.jxkg.enums.general.ExamSubmitTempStatusEnum; |
| | | import com.ycl.jxkg.mapper.*; |
| | | import com.ycl.jxkg.service.ExamPaperService; |
| | | import com.ycl.jxkg.service.ExamService; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private final ExamSubmitTempMapper examSubmitTempMapper; |
| | | private final ClassesUserMapper classesUserMapper; |
| | | private final ExamPaperMapper examPaperMapper; |
| | | private final ExamPaperService examPaperService; |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | @Override |
| | | public Result page(ExamQuery query) { |
| | | IPage<ExamVO> page = PageUtil.getPage(query, ExamVO.class); |
| | | baseMapper.getPage(page, query); |
| | | baseMapper.getPage(page, query, webContext.getCurrentUser().getId()); |
| | | page.getRecords().stream().forEach(item -> { |
| | | if (! StringUtils.hasText(item.getClassName())) { |
| | | item.setClassName("班级不存在或被删除"); |
| | |
| | | } |
| | | }); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Result studentPage(ExamQuery query) { |
| | | IPage<ExamVO> page = PageUtil.getPage(query, ExamVO.class); |
| | | baseMapper.studentPage(page, query, webContext.getCurrentUser().getId()); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Result start(Integer id) { |
| | | Exam exam = baseMapper.selectById(id); |
| | | if (Objects.isNull(exam)) { |
| | | throw new RuntimeException("该考试不存在"); |
| | | } |
| | | if (Objects.isNull(exam.getExamPaperId())) { |
| | | throw new RuntimeException("考试未绑定试卷"); |
| | | } |
| | | // 查出考试试卷 |
| | | ExamPaper examPaper = examPaperMapper.selectById(exam.getExamPaperId()); |
| | | if (Objects.isNull(examPaper)) { |
| | | throw new RuntimeException("试卷不存在"); |
| | | } |
| | | if (StringUtils.hasText(examPaper.getContent())) { |
| | | throw new RuntimeException("试卷题目为空"); |
| | | } |
| | | // 将题目转换为可临时保存的题目结构 |
| | | if (ExamPaperTypeEnum.Fixed.getCode().equals(examPaper.getPaperType()) |
| | | || ExamPaperTypeEnum.RandomOrder.getCode().equals(examPaper.getPaperType())) { |
| | | // 转换 |
| | | List<PaperFixQuestionVO> data = this.coverTo(examPaper); |
| | | return Result.ok().data(data); |
| | | } else if (ExamPaperTypeEnum.Random.getCode().equals(examPaper.getPaperType())) { |
| | | // todo 随机题目生成 |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 将数据库存储的题目,转为可临时保存的题目结构 |
| | | * |
| | | * @param examPaper 试卷 |
| | | * @return |
| | | */ |
| | | private List<PaperFixQuestionVO> coverTo(ExamPaper examPaper) { |
| | | List<PaperFixQuestionDTO> questionWarpList = JSON.parseArray(examPaper.getContent(), PaperFixQuestionDTO.class); |
| | | return questionWarpList.stream().map(item -> { |
| | | PaperFixQuestionVO vo = new PaperFixQuestionVO(); |
| | | vo.setTitle(item.getTitle()); |
| | | vo.setQuestionType(item.getQuestionType()); |
| | | List<DoQuestionVO> doQuestionVOS = item.getQuestionList().stream().map(question -> { |
| | | DoQuestionVO doQuestionVO = new DoQuestionVO(); |
| | | doQuestionVO.setTitle(question.getTitle()); |
| | | doQuestionVO.setQuestionType(item.getQuestionType()); |
| | | doQuestionVO.setQuestionItemList(question.getItems()); |
| | | doQuestionVO.setId(question.getId()); |
| | | doQuestionVO.setOriginalFile(question.getOriginalFile()); |
| | | doQuestionVO.setAudioFile(question.getAudioFile()); |
| | | return doQuestionVO; |
| | | }).collect(Collectors.toList()); |
| | | if (ExamPaperTypeEnum.RandomOrder.getCode().equals(examPaper.getPaperType())) { |
| | | // 随序试卷打乱顺序 |
| | | Collections.shuffle(doQuestionVOS); |
| | | } |
| | | vo.setQuestionList(doQuestionVOS); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (Objects.isNull(exam)) { |
| | | throw new RuntimeException("该考试不存在"); |
| | | } |
| | | // 判断单选、多选、判断题对错 |
| | | List<Integer> questionIds = submitData.getQuestionList().stream().map(DoQuestionVO::getId).collect(Collectors.toList()); |
| | | List<Question> questionList = questionMapper.getAnswerInfo(questionIds); |
| | | Map<Integer, Question> answerMap = questionList.stream().collect(Collectors.toMap(Question::getId, entity -> entity)); |
| | | submitData.getQuestionList().stream().forEach(item -> { |
| | | Question question = answerMap.get(item.getId()); |
| | | if (Objects.nonNull(question) |
| | | && (QuestionTypeEnum.SingleChoice.getCode().equals(question.getQuestionType()) |
| | | || QuestionTypeEnum.MultipleChoice.getCode().equals(question.getQuestionType()) |
| | | || QuestionTypeEnum.TrueFalse.getCode().equals(question.getQuestionType()) |
| | | )) { |
| | | String correct = question.getCorrect(); |
| | | if (QuestionTypeEnum.MultipleChoice.getCode().equals(question.getQuestionType())) { |
| | | // 如果是选择题,那么将答案转为list |
| | | List<String> answerList = JSON.parseArray(correct, String.class); |
| | | item.setRight(answerList.containsAll(item.getAnswerList())); |
| | | } else { |
| | | item.setRight(question.getCorrect().equals(item.getAnswer())); |
| | | } |
| | | } |
| | | }); |
| | | // // 判断单选、多选、判断题对错 |
| | | // List<Integer> questionIds = new ArrayList<>(24); |
| | | // submitData.getPaperQuestionList().forEach(item -> { |
| | | // List<Integer> ids = item.getQuestionList().stream().map(DoQuestionVO::getId).collect(Collectors.toList()); |
| | | // questionIds.addAll(ids); |
| | | // }); |
| | | // List<Question> questionList = questionMapper.getAnswerInfo(questionIds); |
| | | // Map<Integer, Question> answerMap = questionList.stream().collect(Collectors.toMap(Question::getId, entity -> entity)); |
| | | // submitData.getQuestionList().stream().forEach(item -> { |
| | | // Question question = answerMap.get(item.getId()); |
| | | // if (Objects.nonNull(question) |
| | | // && (QuestionTypeEnum.SingleChoice.getCode().equals(question.getQuestionType()) |
| | | // || QuestionTypeEnum.MultipleChoice.getCode().equals(question.getQuestionType()) |
| | | // || QuestionTypeEnum.TrueFalse.getCode().equals(question.getQuestionType()) |
| | | // )) { |
| | | // String correct = question.getCorrect(); |
| | | // if (QuestionTypeEnum.MultipleChoice.getCode().equals(question.getQuestionType())) { |
| | | // // 如果是选择题,那么将答案转为list |
| | | // List<String> answerList = JSON.parseArray(correct, String.class); |
| | | // item.setRight(answerList.containsAll(item.getAnswerList())); |
| | | // } else { |
| | | // item.setRight(question.getCorrect().equals(item.getAnswer())); |
| | | // } |
| | | // } |
| | | // }); |
| | | // 阅卷后才往exam_paper_answer保存考试成绩、以及保存到exam_paper_customer_answer |
| | | // 现在只需要保存到一张临时表 |
| | | // 该接口是主动提交,所以状态都设置为完成,以便后续老师阅卷 |
| | |
| | | return; |
| | | } |
| | | one.setDoTime(submitData.getDoTime()); |
| | | one.setExamSubmit(JSON.toJSONString(submitData.getQuestionList())); |
| | | one.setExamSubmit(JSON.toJSONString(submitData.getPaperQuestionList())); |
| | | one.setCreateTime(new Date()); |
| | | one.setStatus(status); |
| | | examSubmitTempMapper.updateById(one); |
| | |
| | | examSubmitTemp.setDoTime(submitData.getDoTime()); |
| | | examSubmitTemp.setStatus(status); |
| | | examSubmitTemp.setUserId(webContext.getCurrentUser().getId()); |
| | | examSubmitTemp.setExamSubmit(JSON.toJSONString(submitData.getQuestionList())); |
| | | examSubmitTemp.setExamSubmit(JSON.toJSONString(submitData.getPaperQuestionList())); |
| | | examSubmitTemp.setMarkPaperStatus(ExamSubmitTempStatusEnum.TEMP); |
| | | examSubmitTempMapper.insert(examSubmitTemp); |
| | | } |
| | |
| | | markPaperVO.setSuggestTime(examPaper.getSuggestTime()); |
| | | return Result.ok().data(markPaperVO); |
| | | } |
| | | |
| | | } |