From d3d1235bab219b382a5bebfe34edabbba52d151c Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期二, 14 五月 2024 17:07:58 +0800
Subject: [PATCH] 在线练习多选题处理
---
src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java | 35 +++++++++++++++++++----------------
src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java | 2 +-
2 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java b/src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java
index 771188c..3d4a8a2 100644
--- a/src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java
+++ b/src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java
@@ -35,7 +35,7 @@
Integer countQuestionNum(@Param("subjects") List<Integer> subjects);
/** 闅忔満棰樼洰 */
- List<QuestionVO> getRandomQuestionId(@Param("subjectIds") List<Integer> subjectIds, @Param("questionNum") Integer questionNum);
+ List<QuestionVO> getRandomQuestionId(@Param("subjectIds") List<Integer> subjectIds, @Param("questionType") Integer questionType, @Param("questionNum") Integer questionNum);
/** 鏌ヨ棰樼洰ID锛屾牴鎹鐩甶ds */
List<Integer> questionsBySubjectIds(@Param("subjectIds") List<Integer> subjectIds);
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 68ad3dd..dba31af 100644
--- a/src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java
+++ b/src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java
@@ -114,11 +114,13 @@
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);
+ return RestResponse.ok(questionVO);
}
return RestResponse.ok();
}
@@ -136,12 +138,26 @@
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);
+
+ return RestResponse.ok(questionVO);
+ }
+
+ /**
+ * 澶勭悊棰樼洰鍐呭JSON
+ *
+ * @param questionVO
+ */
+ public void jsonQuestion(QuestionVO questionVO) {
+ 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())) {
@@ -152,18 +168,5 @@
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);
- }
}
}
--
Gitblit v1.8.0