From 87c1bdac0c88d208cd2786913742d818e4d2debb Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期二, 14 五月 2024 16:52:35 +0800
Subject: [PATCH] 在线练习多选题处理

---
 src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java |   39 +++++++++++++++++++++++++++++++--------
 1 files changed, 31 insertions(+), 8 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 09cac23..68ad3dd 100644
--- a/src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java
+++ b/src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java
@@ -129,18 +129,41 @@
         return RestResponse.ok(num);
     }
 
+    @Override
+    public RestResponse randomOneQuestion(Integer id) {
+        SelfPractice en = selfPracticeMapper.selectById(id);
+        if (Objects.isNull(en)) {
+            throw new RuntimeException("缁冧範涓嶅瓨鍦�");
+        }
+        List<Integer> subjectIds = JSON.parseArray(en.getSubjects(), Integer.class);
+        List<QuestionVO> one = questionSubjectMapper.getRandomQuestionId(subjectIds, 1);
+        if (one.size() < 1) {
+            throw new RuntimeException("娌℃湁鎵惧埌棰樼洰锛屽彲鑳芥墍閫夎鐩寘鍚鐩笉瓒�");
+        }
+        QuestionVO questionVO = one.get(0);
+        jsonQuestion(questionVO);
+        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 vos
+     * @param vo
      */
-    public void jsonQuestion(List<QuestionVO> vos) {
-        vos.stream().forEach(vo -> {
-            if (StringUtils.hasText(vo.getContentJson())) {
-                QuestionContentVO questionContent = JSON.parseObject(vo.getContentJson(), QuestionContentVO.class);
-                vo.setContent(questionContent);
-            }
-        });
+    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