| | |
| | | import com.ycl.jxkg.domain.entity.*; |
| | | import com.ycl.jxkg.domain.exam.PaperFixQuestionDTO; |
| | | import com.ycl.jxkg.domain.exam.PaperQuestionSettingDTO; |
| | | import com.ycl.jxkg.domain.question.QuestionObject; |
| | | import com.ycl.jxkg.domain.vo.*; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperEditRequestVO; |
| | | import com.ycl.jxkg.enums.ExamPaperTypeEnum; |
| | |
| | | if (Objects.isNull(examPaper)) { |
| | | throw new RuntimeException("试卷不存在"); |
| | | } |
| | | if (StringUtils.hasText(examPaper.getContent())) { |
| | | throw new RuntimeException("试卷题目为空"); |
| | | } |
| | | // 将题目转换为可临时保存的题目结构 |
| | | // 将题目转换为可临时保存的题目结构。固定试卷和随序试卷的题目是直接保存到content字段的 |
| | | if (ExamPaperTypeEnum.Fixed.getCode().equals(examPaper.getPaperType()) |
| | | || ExamPaperTypeEnum.RandomOrder.getCode().equals(examPaper.getPaperType())) { |
| | | if (StringUtils.hasText(examPaper.getContent())) { |
| | | throw new RuntimeException("试卷题目为空"); |
| | | } |
| | | // 转换 |
| | | List<PaperFixQuestionVO> data = this.coverTo(examPaper); |
| | | |
| | | return Result.ok().data(data); |
| | | } else if (ExamPaperTypeEnum.Random.getCode().equals(examPaper.getPaperType())) { |
| | | // todo 随机题目生成 |
| | | // 根据随机试卷的配置,随机生成对应题目 |
| | | if (! StringUtils.hasText(examPaper.getContent())) { |
| | | throw new RuntimeException("试卷配置异常,请联系老师"); |
| | | } |
| | | List<PaperQuestionSettingDTO> paperSettingList = JSON.parseArray(examPaper.getContent(), PaperQuestionSettingDTO.class); |
| | | List<Question> questionList = new ArrayList<>(24); |
| | | List<DoQuestionVO> questionList = new ArrayList<>(24); |
| | | for (PaperQuestionSettingDTO paperSetting : paperSettingList) { |
| | | if (QuestionTypeEnum.SingleChoice.getCode().equals(paperSetting.getQuestionType())) { |
| | | // questionMapper.getRandomQuestion(examPaper.getSubjectId(), paperSetting.getQuestionType()) |
| | | // 拿到课目下某类题型的x道随机题 |
| | | List<Question> questions = questionMapper.getRandomQuestion(examPaper.getSubjectId(), paperSetting.getQuestionType(), paperSetting.getNum()); |
| | | if (paperSetting.getNum() > questions.size()) { |
| | | throw new RuntimeException("配置的题目数不足以生成试卷"); |
| | | } |
| | | // 拿到题目后组装为可临时保存的题目结构 |
| | | List<DoQuestionVO> childQuestions = questions.stream().map(item -> { |
| | | DoQuestionVO doQuestionVO = new DoQuestionVO(); |
| | | doQuestionVO.setTitle(item.getTitle()); |
| | | doQuestionVO.setQuestionType(item.getQuestionType()); |
| | | if (StringUtils.hasText(item.getContent())) { |
| | | QuestionObject questionObject = JSON.parseObject(item.getContent(), QuestionObject.class); |
| | | doQuestionVO.setQuestionItemList(questionObject.getQuestionItemObjects()); |
| | | } |
| | | doQuestionVO.setId(item.getId()); |
| | | doQuestionVO.setOriginalFile(item.getOriginalFile()); |
| | | doQuestionVO.setAudioFile(item.getAudioFile()); |
| | | return doQuestionVO; |
| | | }).collect(Collectors.toList()); |
| | | questionList.addAll(childQuestions); |
| | | } |
| | | } |
| | | return null; |
| | | return Result.ok(); |
| | | } |
| | | |
| | | /** |