From 47cd9ecc0eff38ffe6b3b794b2bf197e958f4403 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期三, 14 五月 2025 15:50:57 +0800 Subject: [PATCH] bug:学员有状态不能修改问题 --- src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java | 68 +++++++++++++++++++++++++++------- 1 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java b/src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java index 1968c85..6040be6 100644 --- a/src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java +++ b/src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java @@ -10,6 +10,7 @@ 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; @@ -74,7 +75,7 @@ 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)) { @@ -147,16 +148,10 @@ throw new RuntimeException("娌℃湁鎵惧埌棰樼洰锛屽彲鑳芥墍閫夎鐩寘鍚鐩笉瓒�"); } QuestionVO questionVO = one.get(0); - jsonQuestion(questionVO); + 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 @@ -171,9 +166,52 @@ 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(); } /** @@ -181,7 +219,7 @@ * * @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); @@ -192,9 +230,11 @@ 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(""); + } } } -- Gitblit v1.8.0