| | |
| | | import com.mindskip.xzs.base.RestResponse; |
| | | import com.mindskip.xzs.context.WebContext; |
| | | import com.mindskip.xzs.domain.ExamPaperAnswer; |
| | | 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; |
| | |
| | | import com.mindskip.xzs.domain.vo.QuestionVO; |
| | | import com.mindskip.xzs.domain.vo.SelfPracticeVO; |
| | | import com.mindskip.xzs.domain.vo.SubjectQuestionVO; |
| | | import com.mindskip.xzs.repository.QuestionMapper; |
| | | import com.mindskip.xzs.repository.QuestionSubjectMapper; |
| | | import com.mindskip.xzs.repository.SelfPracticeMapper; |
| | | import com.mindskip.xzs.repository.SubjectMapper; |
| | | import com.mindskip.xzs.repository.*; |
| | | import com.mindskip.xzs.service.SelfPracticeService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | private final WebContext webContext; |
| | | private final QuestionSubjectMapper questionSubjectMapper; |
| | | private final SubjectMapper subjectMapper; |
| | | private final QuestionMapper questionMapper; |
| | | private final PracticeQuestionConditionMapper practiceQuestionConditionMapper; |
| | | |
| | | @Override |
| | | public RestResponse add(SelfPracticeVO vo) { |
| | |
| | | PageInfo<SelfPracticeVO> info = PageHelper.startPage(query.getPageNum(), query.getPageSize()).doSelectPageInfo(() -> |
| | | selfPracticeMapper.page(query)); |
| | | info.getList().stream().forEach(item -> { |
| | | // 查询课目名、课目总体数 |
| | | List<Integer> subjects = JSON.parseArray(item.getSubjectString(), Integer.class); |
| | | item.setSubjects(subjects); |
| | | List<String> subjectNames = subjectMapper.selectSubjectName(subjects); |
| | | if (! CollectionUtils.isEmpty(subjectNames)) { |
| | | item.setSubjectNames(subjectNames.stream().collect(Collectors.joining("、"))); |
| | | } |
| | | item.setTotalQuestionNum(questionSubjectMapper.countQuestionNum(subjects)); |
| | | item.setTotalQuestionNum(questionSubjectMapper.countQuestionNum(subjects, PracticeQuestionTypeEnum.getDataBaseValueByValue(item.getQuestionType()))); |
| | | // 查询已经做了多少 |
| | | PracticeQuestionCondition practiceQuestionCondition = practiceQuestionConditionMapper.selectByPracticeId(item.getId()); |
| | | if (Objects.nonNull(practiceQuestionCondition)) { |
| | | List<PracticeQuestionCondition.QuestionFinishCondition> questionFinishConditions = JSON.parseArray(practiceQuestionCondition.getContent(), PracticeQuestionCondition.QuestionFinishCondition.class); |
| | | item.setDoNum(questionFinishConditions.size()); |
| | | } else { |
| | | item.setDoNum(0); |
| | | } |
| | | }); |
| | | return RestResponse.ok(info); |
| | | } |
| | |
| | | List<SubjectQuestionVO> list = new ArrayList<>(2); |
| | | // 顺序做题,把选择的题库的题(id)全部查出来,前端有个序号面板,点击哪道题做哪道 |
| | | for (Integer subjectId : subjectIds) { |
| | | // 查课目名字 |
| | | String subjectName = subjectMapper.selectSubjectNameById(subjectId); |
| | | // todo根据做题记录查询做没做过 |
| | | List<Integer> questionIds = new ArrayList<>(); |
| | | if (PracticeQuestionTypeEnum.ALL.getValue().equals(en.getQuestionType())) { |
| | | questionIds = questionSubjectMapper.questionsBySubjectId(subjectId); |
| | | } else { |
| | | questionIds = questionSubjectMapper.questionsBySubjectIdAndQuestionType(subjectId, PracticeQuestionTypeEnum.getDataBaseValueByValue(en.getQuestionType())); |
| | | } |
| | | // 根据做题记录增加标识,页面渲染做没做过,做对没有 |
| | | PracticeQuestionCondition practiceQuestionCondition = practiceQuestionConditionMapper.selectByPracticeId(id); |
| | | List<PracticeQuestionCondition.QuestionFinishCondition> questionFinishConditions = new ArrayList<>(48); |
| | | if (Objects.nonNull(practiceQuestionCondition)) { // json反序列化得到做题情况 |
| | | questionFinishConditions = JSON.parseArray(practiceQuestionCondition.getContent(), PracticeQuestionCondition.QuestionFinishCondition.class); |
| | | } |
| | | List<PracticeQuestionCondition.QuestionFinishCondition> finalQuestionFinishConditions = questionFinishConditions; |
| | | // 组装前端数据 |
| | | List<PracticeQuestionCondition.QuestionFinishCondition> questionData = questionIds.stream().map(questionId -> { |
| | | PracticeQuestionCondition.QuestionFinishCondition questionPractice = new PracticeQuestionCondition.QuestionFinishCondition(); |
| | | questionPractice.setQuestionId(questionId); |
| | | for (PracticeQuestionCondition.QuestionFinishCondition questionFinishCondition : finalQuestionFinishConditions) { |
| | | if (questionFinishCondition.getQuestionId().equals(questionId)) { |
| | | questionPractice.setRight(questionFinishCondition.getRight()); |
| | | questionPractice.setAnswer(questionFinishCondition.getAnswer()); |
| | | questionPractice.setHasDo(questionFinishCondition.getHasDo()); |
| | | } |
| | | } |
| | | return questionPractice; |
| | | }).collect(Collectors.toList()); |
| | | // 返回响应数据 |
| | | SubjectQuestionVO subjectQuestionVO = new SubjectQuestionVO(); |
| | | subjectQuestionVO.setSubjectId(subjectId); |
| | | subjectQuestionVO.setSubjectName(subjectName); |
| | | subjectQuestionVO.setQuestionIds(questionIds); |
| | | subjectQuestionVO.setQuestionConditions(questionData); |
| | | list.add(subjectQuestionVO); |
| | | } |
| | | return RestResponse.ok(list); |
| | | } else if (PracticeTypeEnum.RANDOM.getValue().equals(en.getPracticeType())) { |
| | | // 随机练习,是一道题一道题练习 |
| | | List<QuestionVO> one = questionSubjectMapper.getRandomQuestionId(subjectIds, 1); |
| | | List<QuestionVO> one = questionSubjectMapper.getRandomQuestionId(subjectIds, PracticeQuestionTypeEnum.getDataBaseValueByValue(en.getQuestionType()), 1); |
| | | if (one.size() < 1) { |
| | | throw new RuntimeException("没有找到题目,可能所选课目包含题目不足"); |
| | | } |
| | | return RestResponse.ok(one.get(0)); |
| | | QuestionVO questionVO = one.get(0); |
| | | jsonQuestion(questionVO, Boolean.TRUE); |
| | | return RestResponse.ok(questionVO); |
| | | } |
| | | return RestResponse.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public RestResponse subjectQuestionNum(List<Integer> subjectIds) { |
| | | Integer num = questionSubjectMapper.countQuestionNum(subjectIds); |
| | | return RestResponse.ok(num); |
| | | } |
| | | |
| | | @Override |
| | |
| | | throw new RuntimeException("练习不存在"); |
| | | } |
| | | List<Integer> subjectIds = JSON.parseArray(en.getSubjects(), Integer.class); |
| | | List<QuestionVO> one = questionSubjectMapper.getRandomQuestionId(subjectIds, 1); |
| | | 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); |
| | | 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(); |
| | | } |
| | | |
| | | /** |
| | | * 处理题目内容JSON |
| | | * |
| | | * @param questionVO |
| | | */ |
| | | public void jsonQuestion(QuestionVO questionVO, Boolean clearAnswer) { |
| | | if (StringUtils.hasText(questionVO.getContentJson())) { |
| | | QuestionContentVO questionContent = JSON.parseObject(questionVO.getContentJson(), QuestionContentVO.class); |
| | | questionVO.setContent(questionContent); |
| | | } |
| | | if (QuestionTypeEnum.MultipleChoice.getCode().equals(questionVO.getQuestionType())) { |
| | | // 多选题需要返回答案数量,学员选中对应数量才查询答案 |
| | | if (StringUtils.hasText(questionVO.getCorrect())) { |
| | | questionVO.setAnswerNum(questionVO.getCorrect().split(",").length); |
| | | } |
| | | } |
| | | questionVO.setContentJson(""); |
| | | questionVO.setCorrect(""); |
| | | questionVO.getContent().setCorrect(""); |
| | | questionVO.getContent().setAnalyze(""); |
| | | return RestResponse.ok(questionVO); |
| | | } |
| | | |
| | | /** |
| | | * 处理题目内容JSON |
| | | * |
| | | * @param vo |
| | | */ |
| | | public void jsonQuestion(QuestionVO vo) { |
| | | if (StringUtils.hasText(vo.getContentJson())) { |
| | | QuestionContentVO questionContent = JSON.parseObject(vo.getContentJson(), QuestionContentVO.class); |
| | | vo.setContent(questionContent); |
| | | if (clearAnswer) { |
| | | questionVO.setContentJson(""); |
| | | questionVO.setCorrect(""); |
| | | questionVO.getContent().setCorrect(""); |
| | | questionVO.getContent().setAnalyze(""); |
| | | } |
| | | } |
| | | } |