From d470757bba19143fd3fc441365fcbb2362dfd0f0 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期六, 11 五月 2024 18:04:39 +0800
Subject: [PATCH] 个人练习

---
 src/main/java/com/mindskip/xzs/repository/QuestionMapper.java                 |    2 
 src/main/resources/mapper/QuestionMapper.xml                                  |  542 ++++++++++++++++++++------------------
 src/main/java/com/mindskip/xzs/repository/SelfPracticeMapper.java             |   16 +
 src/main/java/com/mindskip/xzs/domain/SelfPractice.java                       |    6 
 src/main/java/com/mindskip/xzs/domain/vo/QuestionVO.java                      |   34 ++
 src/main/java/com/mindskip/xzs/service/SelfPracticeService.java               |   15 +
 src/main/java/com/mindskip/xzs/domain/vo/SelfPracticeVO.java                  |    7 
 src/main/java/com/mindskip/xzs/controller/student/SelfPracticeController.java |   22 +
 src/main/java/com/mindskip/xzs/domain/enums/PracticeTypeEnum.java             |   23 +
 src/main/java/com/mindskip/xzs/domain/vo/QuestionContentVO.java               |   40 ++
 src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java      |   56 +++
 src/main/resources/mapper/SelfPracticeMapper.xml                              |   29 +
 src/main/resources/mapper/QuestionSubjectMapper.xml                           |   15 +
 src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java          |    4 
 14 files changed, 545 insertions(+), 266 deletions(-)

diff --git a/src/main/java/com/mindskip/xzs/controller/student/SelfPracticeController.java b/src/main/java/com/mindskip/xzs/controller/student/SelfPracticeController.java
index d4e5f27..7e6391d 100644
--- a/src/main/java/com/mindskip/xzs/controller/student/SelfPracticeController.java
+++ b/src/main/java/com/mindskip/xzs/controller/student/SelfPracticeController.java
@@ -31,9 +31,31 @@
         return selfPracticeService.page(vo);
     }
 
+    /**
+     * 鑾峰彇鎵�閫夎鐩笅鐨勯鐩暟閲�
+     *
+     * @param subjectIds
+     * @return
+     */
+    @PostMapping("/subject/questionNum")
+    public RestResponse subjectQuestionNum(@RequestBody List<Integer> subjectIds) {
+        return selfPracticeService.subjectQuestionNum(subjectIds);
+    }
+
     @PostMapping("/remove")
     public RestResponse remove(@RequestBody @NotEmpty(message = "璇烽�夋嫨瑕佸垹闄ょ殑鏁版嵁") List<Integer> ids) {
         return selfPracticeService.remove(ids);
     }
 
+    /**
+     * 寮�濮嬬粌涔�
+     *
+     * @param id 缁冧範id
+     * @return
+     */
+    @PostMapping("/start/{id}")
+    public RestResponse startPractice(@PathVariable("id") Integer id) {
+        return selfPracticeService.startPractice(id);
+    }
+
 }
diff --git a/src/main/java/com/mindskip/xzs/domain/SelfPractice.java b/src/main/java/com/mindskip/xzs/domain/SelfPractice.java
index f3bff48..a7fda38 100644
--- a/src/main/java/com/mindskip/xzs/domain/SelfPractice.java
+++ b/src/main/java/com/mindskip/xzs/domain/SelfPractice.java
@@ -21,6 +21,9 @@
     /** 澶囨敞 */
     private String remark;
 
+    /** 棰樼洰鏁伴噺 */
+    private Integer questionNum;
+
     /** 缁冧範绫诲瀷 */
     private String practiceType;
 
@@ -39,4 +42,7 @@
     /** 宸插仛棰樻暟 */
     private Integer doNum;
 
+    /** 棰樼洰ID JSON */
+    private String questionIds;
+
 }
diff --git a/src/main/java/com/mindskip/xzs/domain/enums/PracticeTypeEnum.java b/src/main/java/com/mindskip/xzs/domain/enums/PracticeTypeEnum.java
new file mode 100644
index 0000000..5e58d63
--- /dev/null
+++ b/src/main/java/com/mindskip/xzs/domain/enums/PracticeTypeEnum.java
@@ -0,0 +1,23 @@
+package com.mindskip.xzs.domain.enums;
+
+import lombok.Getter;
+
+/**
+ * 涓汉缁冧範绫诲瀷
+ *
+ * @author锛歺p
+ * @date锛�2024/5/10 9:52
+ */
+@Getter
+public enum PracticeTypeEnum {
+
+    RANDOM("random"),
+    ORDERED("ordered"),
+    ;
+
+    private final String value;
+
+    PracticeTypeEnum(String value) {
+        this.value = value;
+    }
+}
diff --git a/src/main/java/com/mindskip/xzs/domain/vo/QuestionContentVO.java b/src/main/java/com/mindskip/xzs/domain/vo/QuestionContentVO.java
new file mode 100644
index 0000000..c77409c
--- /dev/null
+++ b/src/main/java/com/mindskip/xzs/domain/vo/QuestionContentVO.java
@@ -0,0 +1,40 @@
+package com.mindskip.xzs.domain.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author锛歺p
+ * @date锛�2024/5/11 15:04
+ */
+@Data
+public class QuestionContentVO {
+
+    /** 棰樺共 */
+    private String titleContent;
+
+    /** 瑙f瀽 */
+    private String analyze;
+
+    /** 閫夐」 */
+    private List<OptionItem> questionItemObjects;
+
+    @Data
+    public class OptionItem {
+
+        /** 閫夐」 */
+        private String prefix;
+
+        /** 閫夐」鍐呭 */
+        private String content;
+
+        /** 閫夐」椤哄簭 */
+        private Integer itemOrder;
+
+        /** id */
+        private String itemUuid;
+
+    }
+
+}
diff --git a/src/main/java/com/mindskip/xzs/domain/vo/QuestionVO.java b/src/main/java/com/mindskip/xzs/domain/vo/QuestionVO.java
new file mode 100644
index 0000000..da60a68
--- /dev/null
+++ b/src/main/java/com/mindskip/xzs/domain/vo/QuestionVO.java
@@ -0,0 +1,34 @@
+package com.mindskip.xzs.domain.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author锛歺p
+ * @date锛�2024/5/10 11:07
+ */
+@Data
+public class QuestionVO {
+
+    private Integer id;
+
+    /** 棰樼洰鍐呭JSON */
+    private String contentJson;
+
+    /** 棰樼洰绫诲瀷 */
+    private Integer questionType;
+
+    /** 闅惧害 */
+    private Integer difficult;
+
+    /** 鍐呭瀵硅薄 */
+    private QuestionContentVO content;
+
+    /** 鏅�氶鐩瓟妗堬細鍗曢�夈�佸垽鏂�侀棶绛� */
+    private String correct;
+
+    /** 澶氶�夐绛旀 */
+    private List<String> correctList;
+
+}
diff --git a/src/main/java/com/mindskip/xzs/domain/vo/SelfPracticeVO.java b/src/main/java/com/mindskip/xzs/domain/vo/SelfPracticeVO.java
index ec33a53..ea47da3 100644
--- a/src/main/java/com/mindskip/xzs/domain/vo/SelfPracticeVO.java
+++ b/src/main/java/com/mindskip/xzs/domain/vo/SelfPracticeVO.java
@@ -51,6 +51,13 @@
     /** 鍋氶鎬绘暟 */
     private Integer totalQuestionNum;
 
+    /** 棰樼洰鎬绘暟 */
+    @NotBlank(message = "棰樼洰鏁伴噺涓嶈兘涓虹┖")
+    private Integer questionNum;
+
+    private String questionIds;
+
+
     private Integer pageSize = 10;
     private Integer pageNum = 1;
 }
diff --git a/src/main/java/com/mindskip/xzs/repository/QuestionMapper.java b/src/main/java/com/mindskip/xzs/repository/QuestionMapper.java
index dbb8924..a9aeb95 100644
--- a/src/main/java/com/mindskip/xzs/repository/QuestionMapper.java
+++ b/src/main/java/com/mindskip/xzs/repository/QuestionMapper.java
@@ -2,6 +2,7 @@
 
 import com.mindskip.xzs.domain.other.KeyValue;
 import com.mindskip.xzs.domain.Question;
+import com.mindskip.xzs.domain.vo.QuestionVO;
 import com.mindskip.xzs.viewmodel.admin.question.QuestionPageRequestVM;
 import com.mindskip.xzs.vo.QuestionExportVO;
 import com.mindskip.xzs.vo.QuestionImportVO;
@@ -17,6 +18,7 @@
     List<Question> page(QuestionPageRequestVM requestVM);
 
     List<Question> selectByIds(@Param("ids") List<Integer> ids);
+    List<QuestionVO> getVoByIds(@Param("ids") List<Integer> ids);
 
     Integer selectAllCount();
 
diff --git a/src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java b/src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java
index a4f3b25..bdb4835 100644
--- a/src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java
+++ b/src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java
@@ -1,6 +1,7 @@
 package com.mindskip.xzs.repository;
 
 import com.mindskip.xzs.domain.QuestionSubject;
+import com.mindskip.xzs.domain.vo.QuestionVO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -32,4 +33,7 @@
 
     /** 缁熻璇剧洰鐨勯鐩暟 */
     Integer countQuestionNum(@Param("subjects") List<Integer> subjects);
+
+    /** 闅忔満棰樼洰 */
+    List<QuestionVO> getRandomQuestionId(@Param("subjectIds") List<Integer> subjectIds, @Param("questionNum") Integer questionNum);
 }
diff --git a/src/main/java/com/mindskip/xzs/repository/SelfPracticeMapper.java b/src/main/java/com/mindskip/xzs/repository/SelfPracticeMapper.java
index b1374a5..f74cd23 100644
--- a/src/main/java/com/mindskip/xzs/repository/SelfPracticeMapper.java
+++ b/src/main/java/com/mindskip/xzs/repository/SelfPracticeMapper.java
@@ -35,4 +35,20 @@
      * @param ids
      */
     void remove(List<Integer> ids);
+
+    /**
+     * id鏌ヨ鎯�
+     *
+     * @param id
+     * @return
+     */
+    SelfPractice selectById(Integer id);
+
+    /**
+     * 璁剧疆棰樼洰id
+     *
+     * @param id
+     * @param questionIds
+     */
+    void setQuestionIds(@Param("id") Integer id, @Param("questionIds") String questionIds);
 }
diff --git a/src/main/java/com/mindskip/xzs/service/SelfPracticeService.java b/src/main/java/com/mindskip/xzs/service/SelfPracticeService.java
index d407084..fea3b33 100644
--- a/src/main/java/com/mindskip/xzs/service/SelfPracticeService.java
+++ b/src/main/java/com/mindskip/xzs/service/SelfPracticeService.java
@@ -38,4 +38,19 @@
      */
     RestResponse remove(List<Integer> ids);
 
+    /**
+     * 寮�濮嬬粌涔�
+     *
+     * @param id
+     * @return
+     */
+    RestResponse startPractice(Integer id);
+
+    /**
+     * 鏌ヨ璇剧洰涓嬬殑棰樼洰鏁伴噺
+     *
+     * @param subjectIds
+     * @return
+     */
+    RestResponse subjectQuestionNum(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 6a5eaa6..e7305d3 100644
--- a/src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java
+++ b/src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java
@@ -7,17 +7,21 @@
 import com.mindskip.xzs.base.RestResponse;
 import com.mindskip.xzs.context.WebContext;
 import com.mindskip.xzs.domain.ExamPaperAnswer;
+import com.mindskip.xzs.domain.Question;
 import com.mindskip.xzs.domain.SelfPractice;
+import com.mindskip.xzs.domain.vo.QuestionContentVO;
+import com.mindskip.xzs.domain.vo.QuestionVO;
 import com.mindskip.xzs.domain.vo.SelfPracticeVO;
+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.service.QuestionSubjectService;
 import com.mindskip.xzs.service.SelfPracticeService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
 
 import java.util.Date;
 import java.util.List;
@@ -36,6 +40,7 @@
     private final WebContext webContext;
     private final QuestionSubjectMapper questionSubjectMapper;
     private final SubjectMapper subjectMapper;
+    private final QuestionMapper questionMapper;
 
     @Override
     public RestResponse add(SelfPracticeVO vo) {
@@ -75,4 +80,53 @@
         selfPracticeMapper.remove(ids);
         return RestResponse.ok("鍒犻櫎鎴愬姛");
     }
+
+    @Override
+    public RestResponse startPractice(Integer id) {
+        SelfPractice en = selfPracticeMapper.selectById(id);
+        if (Objects.isNull(en)) {
+            throw new RuntimeException("缁冧範涓嶅瓨鍦�");
+        }
+        if (StringUtils.hasText(en.getQuestionIds())) {
+            // 鐢熸垚浜嗛鐩氨鐩存帴鏌�
+            List<Integer> questionIdList = JSON.parseArray(en.getQuestionIds(), Integer.class);
+            List<QuestionVO> vos = questionMapper.getVoByIds(questionIdList);
+            jsonQuestion(vos);
+            return RestResponse.ok(vos);
+        } else {
+            // 娌$敓鎴愯繃灏遍殢鏈虹敓鎴愰鐩�
+            List<Integer> subjectIds = JSON.parseArray(en.getSubjects(), Integer.class);
+            Integer totalQuestionNum = questionSubjectMapper.countQuestionNum(subjectIds);
+            if (totalQuestionNum < en.getQuestionNum()) {
+                throw new RuntimeException("浣犳墍閫夌殑璇剧洰棰樼洰鏁伴噺涓嶈冻");
+            }
+            // 鏌ヨ鍑鸿鐩笅闅忔満鐨勮瀹氭暟閲忛鐩�
+            List<QuestionVO> questionVOList = questionSubjectMapper.getRandomQuestionId(subjectIds, en.getQuestionNum());
+            List<Integer> ids = questionVOList.stream().map(QuestionVO::getId).collect(Collectors.toList());
+            selfPracticeMapper.setQuestionIds(en.getId(), JSON.toJSONString(ids));
+            jsonQuestion(questionVOList);
+            return RestResponse.ok(questionVOList);
+        }
+    }
+
+    @Override
+    public RestResponse subjectQuestionNum(List<Integer> subjectIds) {
+        Integer num = questionSubjectMapper.countQuestionNum(subjectIds);
+        return RestResponse.ok(num);
+    }
+
+
+    /**
+     * 澶勭悊棰樼洰鍐呭JSON
+     *
+     * @param vos
+     */
+    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);
+            }
+        });
+    }
 }
diff --git a/src/main/resources/mapper/QuestionMapper.xml b/src/main/resources/mapper/QuestionMapper.xml
index fe253d0..0764bb9 100644
--- a/src/main/resources/mapper/QuestionMapper.xml
+++ b/src/main/resources/mapper/QuestionMapper.xml
@@ -1,282 +1,300 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.mindskip.xzs.repository.QuestionMapper">
-  <resultMap id="BaseResultMap" type="com.mindskip.xzs.domain.Question">
-    <id column="id" jdbcType="INTEGER" property="id" />
-    <result column="question_type" jdbcType="INTEGER" property="questionType" />
-    <result column="subject_id" jdbcType="INTEGER" property="subjectId" />
-    <result column="score" jdbcType="INTEGER" property="score" />
-    <result column="grade_level" jdbcType="INTEGER" property="gradeLevel" />
-    <result column="difficult" jdbcType="INTEGER" property="difficult" />
-    <result column="correct" jdbcType="VARCHAR" property="correct" />
-    <result column="info_text_content_id" jdbcType="INTEGER" property="infoTextContentId" />
-    <result column="create_user" jdbcType="INTEGER" property="createUser" />
-    <result column="status" jdbcType="INTEGER" property="status" />
-    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
-    <result column="deleted" jdbcType="BIT" property="deleted" />
-  </resultMap>
-  <sql id="Base_Column_List">
-    id, question_type, subject_id, score, grade_level, difficult, correct, info_text_content_id,
+    <resultMap id="BaseResultMap" type="com.mindskip.xzs.domain.Question">
+        <id column="id" jdbcType="INTEGER" property="id"/>
+        <result column="question_type" jdbcType="INTEGER" property="questionType"/>
+        <result column="subject_id" jdbcType="INTEGER" property="subjectId"/>
+        <result column="score" jdbcType="INTEGER" property="score"/>
+        <result column="grade_level" jdbcType="INTEGER" property="gradeLevel"/>
+        <result column="difficult" jdbcType="INTEGER" property="difficult"/>
+        <result column="correct" jdbcType="VARCHAR" property="correct"/>
+        <result column="info_text_content_id" jdbcType="INTEGER" property="infoTextContentId"/>
+        <result column="create_user" jdbcType="INTEGER" property="createUser"/>
+        <result column="status" jdbcType="INTEGER" property="status"/>
+        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
+        <result column="deleted" jdbcType="BIT" property="deleted"/>
+    </resultMap>
+    <sql id="Base_Column_List">
+        id
+        , question_type, subject_id, score, grade_level, difficult, correct, info_text_content_id,
     create_user, status, create_time, deleted
-  </sql>
-  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
-    select
-    <include refid="Base_Column_List" />
-    from t_question
-    where id = #{id,jdbcType=INTEGER}
-  </select>
-  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
-    delete from t_question
-    where id = #{id,jdbcType=INTEGER}
-  </delete>
-  <insert id="insert" parameterType="com.mindskip.xzs.domain.Question" useGeneratedKeys="true" keyProperty="id">
-    insert into t_question (id, question_type, subject_id,
-      score, grade_level, difficult,
-      correct, info_text_content_id, create_user,
-      status, create_time, deleted
-      )
-    values (#{id,jdbcType=INTEGER}, #{questionType,jdbcType=INTEGER}, #{subjectId,jdbcType=INTEGER},
-      #{score,jdbcType=INTEGER}, #{gradeLevel,jdbcType=INTEGER}, #{difficult,jdbcType=INTEGER},
-      #{correct,jdbcType=VARCHAR}, #{infoTextContentId,jdbcType=INTEGER}, #{createUser,jdbcType=INTEGER},
-      #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT}
-      )
-  </insert>
-  <insert id="insertSelective" parameterType="com.mindskip.xzs.domain.Question" useGeneratedKeys="true" keyProperty="id">
-    insert into t_question
-    <trim prefix="(" suffix=")" suffixOverrides=",">
-      <if test="id != null">
-        id,
-      </if>
-      <if test="questionType != null">
-        question_type,
-      </if>
-      <if test="subjectId != null">
-        subject_id,
-      </if>
-      <if test="score != null">
-        score,
-      </if>
-      <if test="gradeLevel != null">
-        grade_level,
-      </if>
-      <if test="difficult != null">
-        difficult,
-      </if>
-      <if test="correct != null">
-        correct,
-      </if>
-      <if test="infoTextContentId != null">
-        info_text_content_id,
-      </if>
-      <if test="createUser != null">
-        create_user,
-      </if>
-      <if test="status != null">
-        status,
-      </if>
-      <if test="createTime != null">
-        create_time,
-      </if>
-      <if test="deleted != null">
-        deleted,
-      </if>
-    </trim>
-    <trim prefix="values (" suffix=")" suffixOverrides=",">
-      <if test="id != null">
-        #{id,jdbcType=INTEGER},
-      </if>
-      <if test="questionType != null">
-        #{questionType,jdbcType=INTEGER},
-      </if>
-      <if test="subjectId != null">
-        #{subjectId,jdbcType=INTEGER},
-      </if>
-      <if test="score != null">
-        #{score,jdbcType=INTEGER},
-      </if>
-      <if test="gradeLevel != null">
-        #{gradeLevel,jdbcType=INTEGER},
-      </if>
-      <if test="difficult != null">
-        #{difficult,jdbcType=INTEGER},
-      </if>
-      <if test="correct != null">
-        #{correct,jdbcType=VARCHAR},
-      </if>
-      <if test="infoTextContentId != null">
-        #{infoTextContentId,jdbcType=INTEGER},
-      </if>
-      <if test="createUser != null">
-        #{createUser,jdbcType=INTEGER},
-      </if>
-      <if test="status != null">
-        #{status,jdbcType=INTEGER},
-      </if>
-      <if test="createTime != null">
-        #{createTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="deleted != null">
-        #{deleted,jdbcType=BIT},
-      </if>
-    </trim>
-  </insert>
-  <update id="updateByPrimaryKeySelective" parameterType="com.mindskip.xzs.domain.Question">
-    update t_question
-    <set>
-      <if test="questionType != null">
-        question_type = #{questionType,jdbcType=INTEGER},
-      </if>
-      <if test="subjectId != null">
-        subject_id = #{subjectId,jdbcType=INTEGER},
-      </if>
-      <if test="score != null">
-        score = #{score,jdbcType=INTEGER},
-      </if>
-      <if test="gradeLevel != null">
-        grade_level = #{gradeLevel,jdbcType=INTEGER},
-      </if>
-      <if test="difficult != null">
-        difficult = #{difficult,jdbcType=INTEGER},
-      </if>
-      <if test="correct != null">
-        correct = #{correct,jdbcType=VARCHAR},
-      </if>
-      <if test="infoTextContentId != null">
-        info_text_content_id = #{infoTextContentId,jdbcType=INTEGER},
-      </if>
-      <if test="createUser != null">
-        create_user = #{createUser,jdbcType=INTEGER},
-      </if>
-      <if test="status != null">
-        status = #{status,jdbcType=INTEGER},
-      </if>
-      <if test="createTime != null">
-        create_time = #{createTime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="deleted != null">
-        deleted = #{deleted,jdbcType=BIT},
-      </if>
-    </set>
-    where id = #{id,jdbcType=INTEGER}
-  </update>
-  <update id="updateByPrimaryKey" parameterType="com.mindskip.xzs.domain.Question">
-    update t_question
-    set question_type = #{questionType,jdbcType=INTEGER},
-      subject_id = #{subjectId,jdbcType=INTEGER},
-      score = #{score,jdbcType=INTEGER},
-      grade_level = #{gradeLevel,jdbcType=INTEGER},
-      difficult = #{difficult,jdbcType=INTEGER},
-      correct = #{correct,jdbcType=VARCHAR},
-      info_text_content_id = #{infoTextContentId,jdbcType=INTEGER},
-      create_user = #{createUser,jdbcType=INTEGER},
-      status = #{status,jdbcType=INTEGER},
-      create_time = #{createTime,jdbcType=TIMESTAMP},
-      deleted = #{deleted,jdbcType=BIT}
-    where id = #{id,jdbcType=INTEGER}
-  </update>
+    </sql>
+    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from t_question
+        where id = #{id,jdbcType=INTEGER}
+    </select>
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
+        delete
+        from t_question
+        where id = #{id,jdbcType=INTEGER}
+    </delete>
+    <insert id="insert" parameterType="com.mindskip.xzs.domain.Question" useGeneratedKeys="true" keyProperty="id">
+        insert into t_question (id, question_type, subject_id,
+                                score, grade_level, difficult,
+                                correct, info_text_content_id, create_user,
+                                status, create_time, deleted)
+        values (#{id,jdbcType=INTEGER}, #{questionType,jdbcType=INTEGER}, #{subjectId,jdbcType=INTEGER},
+                #{score,jdbcType=INTEGER}, #{gradeLevel,jdbcType=INTEGER}, #{difficult,jdbcType=INTEGER},
+                #{correct,jdbcType=VARCHAR}, #{infoTextContentId,jdbcType=INTEGER}, #{createUser,jdbcType=INTEGER},
+                #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT})
+    </insert>
+    <insert id="insertSelective" parameterType="com.mindskip.xzs.domain.Question" useGeneratedKeys="true"
+            keyProperty="id">
+        insert into t_question
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="id != null">
+                id,
+            </if>
+            <if test="questionType != null">
+                question_type,
+            </if>
+            <if test="subjectId != null">
+                subject_id,
+            </if>
+            <if test="score != null">
+                score,
+            </if>
+            <if test="gradeLevel != null">
+                grade_level,
+            </if>
+            <if test="difficult != null">
+                difficult,
+            </if>
+            <if test="correct != null">
+                correct,
+            </if>
+            <if test="infoTextContentId != null">
+                info_text_content_id,
+            </if>
+            <if test="createUser != null">
+                create_user,
+            </if>
+            <if test="status != null">
+                status,
+            </if>
+            <if test="createTime != null">
+                create_time,
+            </if>
+            <if test="deleted != null">
+                deleted,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="id != null">
+                #{id,jdbcType=INTEGER},
+            </if>
+            <if test="questionType != null">
+                #{questionType,jdbcType=INTEGER},
+            </if>
+            <if test="subjectId != null">
+                #{subjectId,jdbcType=INTEGER},
+            </if>
+            <if test="score != null">
+                #{score,jdbcType=INTEGER},
+            </if>
+            <if test="gradeLevel != null">
+                #{gradeLevel,jdbcType=INTEGER},
+            </if>
+            <if test="difficult != null">
+                #{difficult,jdbcType=INTEGER},
+            </if>
+            <if test="correct != null">
+                #{correct,jdbcType=VARCHAR},
+            </if>
+            <if test="infoTextContentId != null">
+                #{infoTextContentId,jdbcType=INTEGER},
+            </if>
+            <if test="createUser != null">
+                #{createUser,jdbcType=INTEGER},
+            </if>
+            <if test="status != null">
+                #{status,jdbcType=INTEGER},
+            </if>
+            <if test="createTime != null">
+                #{createTime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="deleted != null">
+                #{deleted,jdbcType=BIT},
+            </if>
+        </trim>
+    </insert>
+    <update id="updateByPrimaryKeySelective" parameterType="com.mindskip.xzs.domain.Question">
+        update t_question
+        <set>
+            <if test="questionType != null">
+                question_type = #{questionType,jdbcType=INTEGER},
+            </if>
+            <if test="subjectId != null">
+                subject_id = #{subjectId,jdbcType=INTEGER},
+            </if>
+            <if test="score != null">
+                score = #{score,jdbcType=INTEGER},
+            </if>
+            <if test="gradeLevel != null">
+                grade_level = #{gradeLevel,jdbcType=INTEGER},
+            </if>
+            <if test="difficult != null">
+                difficult = #{difficult,jdbcType=INTEGER},
+            </if>
+            <if test="correct != null">
+                correct = #{correct,jdbcType=VARCHAR},
+            </if>
+            <if test="infoTextContentId != null">
+                info_text_content_id = #{infoTextContentId,jdbcType=INTEGER},
+            </if>
+            <if test="createUser != null">
+                create_user = #{createUser,jdbcType=INTEGER},
+            </if>
+            <if test="status != null">
+                status = #{status,jdbcType=INTEGER},
+            </if>
+            <if test="createTime != null">
+                create_time = #{createTime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="deleted != null">
+                deleted = #{deleted,jdbcType=BIT},
+            </if>
+        </set>
+        where id = #{id,jdbcType=INTEGER}
+    </update>
+    <update id="updateByPrimaryKey" parameterType="com.mindskip.xzs.domain.Question">
+        update t_question
+        set question_type        = #{questionType,jdbcType=INTEGER},
+            subject_id           = #{subjectId,jdbcType=INTEGER},
+            score                = #{score,jdbcType=INTEGER},
+            grade_level          = #{gradeLevel,jdbcType=INTEGER},
+            difficult            = #{difficult,jdbcType=INTEGER},
+            correct              = #{correct,jdbcType=VARCHAR},
+            info_text_content_id = #{infoTextContentId,jdbcType=INTEGER},
+            create_user          = #{createUser,jdbcType=INTEGER},
+            status               = #{status,jdbcType=INTEGER},
+            create_time          = #{createTime,jdbcType=TIMESTAMP},
+            deleted              = #{deleted,jdbcType=BIT}
+        where id = #{id,jdbcType=INTEGER}
+    </update>
 
 
+    <select id="page" resultMap="BaseResultMap"
+            parameterType="com.mindskip.xzs.viewmodel.admin.question.QuestionPageRequestVM">
+        SELECT
+        q.*
+        FROM t_question q
+        LEFT JOIN t_question_subject qs on q.id = qs.question_id
+        LEFT JOIN t_text_content t on q.info_text_content_id = t.id
+        <where>
+            and q.deleted=0 and qs.deleted = 0
+            <if test="id != null ">
+                and q.id= #{id}
+            </if>
+            <if test="level != null ">
+                and q.grade_level= #{level}
+            </if>
+            <if test="subjectId != null ">
+                and qs.subject_id in
+                <foreach item="subjectId" collection="subjectId" open="(" separator=","
+                         close=")">
+                    #{subjectId}
+                </foreach>
+            </if>
+            <if test="questionType != null ">
+                and q.question_type= #{questionType}
+            </if>
+            <if test="questionName != null and questionName != ''">
+                and t.content->'$."titleContent"' LIKE concat('%',#{questionName},'%')
+            </if>
+            <if test="content != null">
+                and q.info_text_content_id in (SELECT id FROM t_text_content WHERE content like
+                concat('%',#{content},'%') )
+            </if>
+        </where>
+        group by q.id
+    </select>
 
 
-  <select id="page" resultMap="BaseResultMap" parameterType="com.mindskip.xzs.viewmodel.admin.question.QuestionPageRequestVM">
-    SELECT
-    q.*
-    FROM t_question q
-    LEFT JOIN t_question_subject qs on q.id = qs.question_id
-    LEFT JOIN t_text_content t on q.info_text_content_id = t.id
-    <where>
-        and q.deleted=0 and qs.deleted = 0
-      <if test="id != null ">
-        and q.id= #{id}
-      </if>
-      <if test="level != null ">
-        and q.grade_level= #{level}
-      </if>
-      <if test="subjectId != null ">
-        and qs.subject_id in
-        <foreach item="subjectId" collection="subjectId" open="(" separator=","
+    <select id="selectByIds" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        FROM t_question where id in
+        <foreach item="id" collection="ids" open="(" separator=","
                  close=")">
-          #{subjectId}
+            #{id}
         </foreach>
-      </if>
-      <if test="questionType != null ">
-        and q.question_type= #{questionType}
-      </if>
-      <if test="questionName != null and questionName != ''">
-        and t.content->'$."titleContent"' LIKE concat('%',#{questionName},'%')
-      </if>
-      <if test="content != null">
-        and q.info_text_content_id in (SELECT id FROM t_text_content WHERE content like concat('%',#{content},'%') )
-      </if>
-    </where>
-    group by q.id
-  </select>
+    </select>
 
 
+    <select id="selectAllCount" resultType="java.lang.Integer">
+        SELECT count(*)
+        from t_question
+        where deleted = 0
+    </select>
 
-  <select id="selectByIds" resultMap="BaseResultMap" >
-    SELECT
-    <include refid="Base_Column_List"/>
-    FROM t_question where id in
-    <foreach item="id" collection="ids" open="(" separator=","
-             close=")">
-      #{id}
-    </foreach>
-  </select>
+    <select id="selectCountByDate" resultType="com.mindskip.xzs.domain.other.KeyValue">
+        SELECT create_time as name, COUNT(create_time) as value
+        from
+            (
+            SELECT DATE_FORMAT(create_time, '%Y-%m-%d') as create_time from t_question
+            WHERE deleted=0 and create_time between #{startTime} and #{endTime}
+            ) a
+        GROUP BY create_time
+    </select>
 
+    <select id="getAll" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        from t_question where deleted=0
+    </select>
 
-  <select id="selectAllCount"  resultType="java.lang.Integer">
-		SELECT count(*) from t_question where  deleted=0
-	</select>
+    <select id="export" resultMap="exportMap">
+        SELECT
+        q.*, ttc.content
+        FROM
+        t_question q
+        INNER JOIN t_text_content ttc on q.info_text_content_id = ttc.id AND q.deleted = 0
+        <where>
+            <if test="query.questionType != null">
+                q.question_type = #{query.questionType}
+            </if>
+            <if test="query.start != null and query.end != null">
+                q.create_time between #{query.start} and #{query.end}
+            </if>
+        </where>
+    </select>
 
-  <select id="selectCountByDate"  resultType="com.mindskip.xzs.domain.other.KeyValue">
-		SELECT create_time as name,COUNT(create_time) as value from
-		        (
-				  SELECT DATE_FORMAT(create_time,'%Y-%m-%d') as create_time from t_question
-					WHERE  deleted=0  and  create_time  between  #{startTime}  and  #{endTime}
-				) a
-		GROUP BY create_time
-	</select>
+    <resultMap id="exportMap" type="com.mindskip.xzs.vo.QuestionImportVO">
+        <result column="question_type" property="questionType"/>
+        <result column="title" property="title"/>
+        <result column="analyze" property="analyze"/>
+        <result column="score" property="score"/>
+        <result column="difficult" property="difficult"/>
+        <result column="content" property="questionContent"/>
+        <result column="score" property="score"/>
+        <result column="correct" property="correct"/>
+        <collection property="subjectList" column="id" ofType="string" select="selectSubjects"/>
+    </resultMap>
 
-  <select id="getAll"  resultMap="BaseResultMap">
-    SELECT <include refid="Base_Column_List"/>
-        from t_question where  deleted=0
-  </select>
+    <select id="selectSubjects" resultType="string">
+        SELECT ts.name
+        FROM t_question_subject tqs
+                 INNER JOIN t_subject ts
+                            ON tqs.subject_id = ts.id AND tqs.question_id = #{id} AND tqs.deleted = 0 AND ts.deleted = 0
+    </select>
 
-  <select id="export" resultMap="exportMap">
-    SELECT
-           q.*, ttc.content
-    FROM
-         t_question q
-             INNER JOIN t_text_content ttc on q.info_text_content_id = ttc.id AND q.deleted = 0
-    <where>
-      <if test="query.questionType != null">
-        q.question_type = #{query.questionType}
-      </if>
-      <if test="query.start != null and query.end != null">
-        q.create_time between #{query.start} and #{query.end}
-      </if>
-    </where>
-  </select>
-
-  <resultMap id="exportMap" type="com.mindskip.xzs.vo.QuestionImportVO">
-    <result column="question_type" property="questionType" />
-    <result column="title" property="title" />
-    <result column="analyze" property="analyze" />
-    <result column="score" property="score" />
-    <result column="difficult" property="difficult" />
-    <result column="content" property="questionContent" />
-    <result column="score" property="score" />
-    <result column="correct" property="correct" />
-    <collection property="subjectList" column="id" ofType="string" select="selectSubjects"/>
-  </resultMap>
-
-  <select id="selectSubjects" resultType="string">
-    SELECT
-           ts.name
-    FROM
-        t_question_subject tqs
-             INNER JOIN t_subject ts ON tqs.subject_id = ts.id AND tqs.question_id = #{id} AND tqs.deleted = 0 AND ts.deleted = 0
-  </select>
+    <select id="getVoByIds" resultType="com.mindskip.xzs.domain.vo.QuestionVO">
+        SELECT
+            tq.id,
+            tq.question_type as questionType,
+            tq.difficult,
+            ttc.content as contentJson
+        FROM
+            t_question tq
+                INNER JOIN t_text_content ttc ON tq.info_text_content_id = ttc.id AND tq.deleted = 0 AND tq.id IN
+        <foreach
+                collection="ids" open="(" separator="," close=")" item="id">
+            #{id}
+        </foreach>
+    </select>
 
 </mapper>
diff --git a/src/main/resources/mapper/QuestionSubjectMapper.xml b/src/main/resources/mapper/QuestionSubjectMapper.xml
index 24ef74e..90ac102 100644
--- a/src/main/resources/mapper/QuestionSubjectMapper.xml
+++ b/src/main/resources/mapper/QuestionSubjectMapper.xml
@@ -64,4 +64,19 @@
               subject_id IN <foreach collection="subjects" open="(" separator="," close=")" item="subjectId">#{subjectId}</foreach>
     </select>
 
+    <select id="getRandomQuestionId" resultType="com.mindskip.xzs.domain.vo.QuestionVO">
+        SELECT
+            distinct
+            tq.id,
+            tq.question_type as questionType,
+            tq.difficult,
+            ttc.content as contentJson
+        FROM
+             t_question_subject tqs
+                 INNER JOIN t_question tq ON tqs.question_id = tq.id AND tq.deleted = 0 AND tqs.subject_id IN <foreach collection="subjectIds" open="(" separator="," close=")" item="subjectId">#{subjectId}</foreach>
+                 INNER JOIN t_text_content ttc ON tq.info_text_content_id = ttc.id
+        ORDER BY
+             RAND() LIMIT #{questionNum}
+    </select>
+
 </mapper>
diff --git a/src/main/resources/mapper/SelfPracticeMapper.xml b/src/main/resources/mapper/SelfPracticeMapper.xml
index cb25add..a713dd3 100644
--- a/src/main/resources/mapper/SelfPracticeMapper.xml
+++ b/src/main/resources/mapper/SelfPracticeMapper.xml
@@ -5,9 +5,9 @@
 
     <insert id="add" keyColumn="id" useGeneratedKeys="true" parameterType="com.mindskip.xzs.domain.SelfPractice">
         INSERT INTO
-            t_self_practice(user_id, remark, subjects, practice_type, create_time, update_time, deleted)
+            t_self_practice(user_id, remark, subjects, practice_type, create_time, update_time, question_num, deleted)
         VALUE
-            (#{userId}, #{remark}, #{subjects}, #{practiceType}, #{createTime}, #{updateTime}, #{deleted})
+            (#{userId}, #{remark}, #{subjects}, #{practiceType}, #{createTime}, #{updateTime}, #{questionNum}, #{deleted})
     </insert>
 
     <select id="page" resultType="com.mindskip.xzs.domain.vo.SelfPracticeVO">
@@ -18,7 +18,9 @@
                subjects as subjectString,
                practice_type as practiceType,
                create_time createTime,
-               update_time as updateTime
+               update_time as updateTime,
+               question_num as questionNum,
+               question_ids as questionIds
         FROM
              t_self_practice
         <where>
@@ -37,5 +39,26 @@
               id IN <foreach collection="ids" open="(" separator="," close=")" item="id">#{id}</foreach>
     </update>
 
+    <select id="selectById" resultType="com.mindskip.xzs.domain.SelfPractice">
+        SELECT
+            id,
+            user_id as userId,
+            remark,
+            subjects as subjects,
+            practice_type as practiceType,
+            create_time createTime,
+            update_time as updateTime,
+            question_num as questionNum,
+            question_ids as questionIds
+        FROM
+             t_self_practice
+        WHERE
+              id = #{id}
+    </select>
+
+    <update id="setQuestionIds">
+        UPDATE t_self_practice SET question_ids = #{questionIds} WHERE id = #{id}
+    </update>
+
 
 </mapper>

--
Gitblit v1.8.0