xiangpei
2024-05-11 d470757bba19143fd3fc441365fcbb2362dfd0f0
个人练习
11个文件已修改
3个文件已添加
811 ■■■■■ 已修改文件
src/main/java/com/mindskip/xzs/controller/student/SelfPracticeController.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/SelfPractice.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/enums/PracticeTypeEnum.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/vo/QuestionContentVO.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/vo/QuestionVO.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/vo/SelfPracticeVO.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/repository/QuestionMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/repository/SelfPracticeMapper.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/service/SelfPracticeService.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/QuestionMapper.xml 542 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/QuestionSubjectMapper.xml 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/SelfPracticeMapper.xml 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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);
    }
}
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;
}
src/main/java/com/mindskip/xzs/domain/enums/PracticeTypeEnum.java
New file
@@ -0,0 +1,23 @@
package com.mindskip.xzs.domain.enums;
import lombok.Getter;
/**
 * 个人练习类型
 *
 * @author:xp
 * @date:2024/5/10 9:52
 */
@Getter
public enum PracticeTypeEnum {
    RANDOM("random"),
    ORDERED("ordered"),
    ;
    private final String value;
    PracticeTypeEnum(String value) {
        this.value = value;
    }
}
src/main/java/com/mindskip/xzs/domain/vo/QuestionContentVO.java
New file
@@ -0,0 +1,40 @@
package com.mindskip.xzs.domain.vo;
import lombok.Data;
import java.util.List;
/**
 * @author:xp
 * @date:2024/5/11 15:04
 */
@Data
public class QuestionContentVO {
    /** 题干 */
    private String titleContent;
    /** 解析 */
    private String analyze;
    /** 选项 */
    private List<OptionItem> questionItemObjects;
    @Data
    public class OptionItem {
        /** 选项 */
        private String prefix;
        /** 选项内容 */
        private String content;
        /** 选项顺序 */
        private Integer itemOrder;
        /** id */
        private String itemUuid;
    }
}
src/main/java/com/mindskip/xzs/domain/vo/QuestionVO.java
New file
@@ -0,0 +1,34 @@
package com.mindskip.xzs.domain.vo;
import lombok.Data;
import java.util.List;
/**
 * @author:xp
 * @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;
}
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;
}
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();
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);
}
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);
}
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);
}
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);
            }
        });
    }
}
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>
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>
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>