| | |
| | | import com.mindskip.xzs.domain.PracticeQuestionCondition; |
| | | import com.mindskip.xzs.domain.Question; |
| | | import com.mindskip.xzs.domain.SelfPractice; |
| | | import com.mindskip.xzs.domain.enums.PracticeModeENum; |
| | | import com.mindskip.xzs.domain.enums.PracticeQuestionTypeEnum; |
| | | import com.mindskip.xzs.domain.enums.PracticeTypeEnum; |
| | | import com.mindskip.xzs.domain.enums.QuestionTypeEnum; |
| | |
| | | throw new RuntimeException("没有找到题目,可能所选课目包含题目不足"); |
| | | } |
| | | QuestionVO questionVO = one.get(0); |
| | | jsonQuestion(questionVO); |
| | | jsonQuestion(questionVO, Boolean.TRUE); |
| | | return RestResponse.ok(questionVO); |
| | | } |
| | | return RestResponse.ok(); |
| | |
| | | throw new RuntimeException("没有找到题目,可能所选课目包含题目不足"); |
| | | } |
| | | QuestionVO questionVO = one.get(0); |
| | | jsonQuestion(questionVO); |
| | | jsonQuestion(questionVO, Boolean.TRUE); |
| | | |
| | | return RestResponse.ok(questionVO); |
| | | } |
| | | |
| | | @Override |
| | | public RestResponse startLook(Integer id) { |
| | | SelfPractice en = selfPracticeMapper.selectById(id); |
| | | if (Objects.isNull(en)) { |
| | | throw new RuntimeException("练习不存在"); |
| | | } |
| | | List<Integer> subjectIds = JSON.parseArray(en.getSubjects(), Integer.class); |
| | | if (PracticeTypeEnum.ORDERED.getValue().equals(en.getPracticeType())) { |
| | | List<SubjectQuestionVO> list = new ArrayList<>(2); |
| | | // 顺序做题,把选择的题库的题(id)全部查出来,前端有个序号面板,点击哪道题做哪道 |
| | | for (Integer subjectId : subjectIds) { |
| | | // 查课目名字 |
| | | String subjectName = subjectMapper.selectSubjectNameById(subjectId); |
| | | List<QuestionVO> questionVOs = new ArrayList<>(); |
| | | if (PracticeQuestionTypeEnum.ALL.getValue().equals(en.getQuestionType())) { |
| | | questionVOs = questionSubjectMapper.bySubjectId(subjectId); |
| | | } else { |
| | | questionVOs = questionSubjectMapper.bySubjectIdAndQuestionType(subjectId, PracticeQuestionTypeEnum.getDataBaseValueByValue(en.getQuestionType())); |
| | | } |
| | | questionVOs.stream().forEach(question -> { |
| | | question.setContent(JSON.parseObject(question.getContentJson(), QuestionContentVO.class)); |
| | | }); |
| | | // 返回响应数据 |
| | | SubjectQuestionVO subjectQuestionVO = new SubjectQuestionVO(); |
| | | subjectQuestionVO.setSubjectId(subjectId); |
| | | subjectQuestionVO.setSubjectName(subjectName); |
| | | subjectQuestionVO.setLookQuestionList(questionVOs); |
| | | list.add(subjectQuestionVO); |
| | | } |
| | | return RestResponse.ok(list); |
| | | } else if (PracticeTypeEnum.RANDOM.getValue().equals(en.getPracticeType())) { |
| | | // 随机练习,是一道题一道题练习 |
| | | List<QuestionVO> one = questionSubjectMapper.getRandomQuestionId(subjectIds, PracticeQuestionTypeEnum.getDataBaseValueByValue(en.getQuestionType()), 1); |
| | | if (one.size() < 1) { |
| | | throw new RuntimeException("没有找到题目,可能所选课目包含题目不足"); |
| | | } |
| | | QuestionVO questionVO = one.get(0); |
| | | jsonQuestion(questionVO, Boolean.FALSE); |
| | | return RestResponse.ok(questionVO); |
| | | } |
| | | return RestResponse.ok(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param questionVO |
| | | */ |
| | | public void jsonQuestion(QuestionVO questionVO) { |
| | | public void jsonQuestion(QuestionVO questionVO, Boolean clearAnswer) { |
| | | if (StringUtils.hasText(questionVO.getContentJson())) { |
| | | QuestionContentVO questionContent = JSON.parseObject(questionVO.getContentJson(), QuestionContentVO.class); |
| | | questionVO.setContent(questionContent); |
| | |
| | | questionVO.setAnswerNum(questionVO.getCorrect().split(",").length); |
| | | } |
| | | } |
| | | questionVO.setContentJson(""); |
| | | questionVO.setCorrect(""); |
| | | questionVO.getContent().setCorrect(""); |
| | | questionVO.getContent().setAnalyze(""); |
| | | if (clearAnswer) { |
| | | questionVO.setContentJson(""); |
| | | questionVO.setCorrect(""); |
| | | questionVO.getContent().setCorrect(""); |
| | | questionVO.getContent().setAnalyze(""); |
| | | } |
| | | } |
| | | } |