xiangpei
2024-05-23 9a1c378ec5566a727efcb85120cdafd52c3ee9f1
在线练习增加练习模式、融合在线练题
11个文件已修改
1个文件已添加
188 ■■■■ 已修改文件
src/main/java/com/mindskip/xzs/controller/student/SelfPracticeController.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/SelfPractice.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/enums/PracticeModeENum.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/vo/SelfPracticeVO.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/vo/SubjectQuestionVO.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/service/SelfPracticeService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/service/impl/QuestionServiceImpl.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java 60 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/DeptQuestionMapper.xml 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/QuestionSubjectMapper.xml 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/SelfPracticeMapper.xml 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/controller/student/SelfPracticeController.java
@@ -48,6 +48,17 @@
    }
    /**
     * 开始看题
     *
     * @param id 练习id
     * @return
     */
    @PostMapping("/start/look/{id}")
    public RestResponse startLook(@PathVariable("id") Integer id) {
        return selfPracticeService.startLook(id);
    }
    /**
     * 随机一道题
     *
     * @param id
src/main/java/com/mindskip/xzs/domain/SelfPractice.java
@@ -18,6 +18,9 @@
    /** 用户ID */
    private Integer userId;
    /** 练习模式:刷题、看题 */
    private String practiceMode;
    /** 备注 */
    private String remark;
src/main/java/com/mindskip/xzs/domain/enums/PracticeModeENum.java
New file
@@ -0,0 +1,23 @@
package com.mindskip.xzs.domain.enums;
import lombok.Getter;
/**
 * @author:xp
 * @date:2024/5/23 11:24
 */
@Getter
public enum PracticeModeENum {
    BRUSH("brush", "刷题"),
    LOOK("look", "看题"),
    ;
    private final String value;
    private final String desc;
    PracticeModeENum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }
}
src/main/java/com/mindskip/xzs/domain/vo/SelfPracticeVO.java
@@ -23,6 +23,9 @@
    /** 用户ID */
    private Integer userId;
    /** 练习模式:刷题、看题 */
    private String practiceMode;
    /** 备注 */
    @NotBlank(message = "请填写此处模拟的名称")
    private String remark;
src/main/java/com/mindskip/xzs/domain/vo/SubjectQuestionVO.java
@@ -16,6 +16,10 @@
    private String subjectName;
    /** 刷题模式下的题列表 */
    private List<PracticeQuestionCondition.QuestionFinishCondition> questionConditions;
    /** 看题模式下的题列表 */
    private List<QuestionVO> lookQuestionList;
}
src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java
@@ -45,4 +45,10 @@
    /** 根据课目和题型查询题目ID */
    List<Integer> questionsBySubjectIdAndQuestionType(@Param("subjectId") Integer subjectId, @Param("questionType") Integer questionType);
    /** 根据课目ID查询题目详情 */
    List<QuestionVO> bySubjectId(@Param("subjectId") Integer subjectId);
    /** 根据课目和题型查找题目数据 */
    List<QuestionVO> bySubjectIdAndQuestionType(Integer subjectId, Integer dataBaseValueByValue);
}
src/main/java/com/mindskip/xzs/service/SelfPracticeService.java
@@ -54,4 +54,12 @@
     * @return
     */
    RestResponse randomOneQuestion(Integer id);
    /**
     * 开始看题
     *
     * @param id
     * @return
     */
    RestResponse startLook(Integer id);
}
src/main/java/com/mindskip/xzs/service/impl/QuestionServiceImpl.java
@@ -39,6 +39,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.Arrays;
@@ -108,7 +109,9 @@
            deptQuestion.setDeptId(deptId);
            return deptQuestion;
        }).collect(Collectors.toList());
        deptQuestionMapper.add(deptQuestions);
        if (! CollectionUtils.isEmpty(model.getDeptIds())) {
            deptQuestionMapper.add(deptQuestions);
        }
        //批量添加
        List<QuestionSubject> list = Arrays.asList(model.getSubjectIds()).stream().map(e -> {
@@ -143,7 +146,9 @@
            deptQuestion.setDeptId(deptId);
            return deptQuestion;
        }).collect(Collectors.toList());
        deptQuestionMapper.add(deptQuestions);
        if (! CollectionUtils.isEmpty(model.getDeptIds())) {
            deptQuestionMapper.add(deptQuestions);
        }
        //题干、解析、选项等 更新
        TextContent infoTextContent = textContentService.selectById(question.getInfoTextContentId());
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;
@@ -147,7 +148,7 @@
                throw new RuntimeException("没有找到题目,可能所选课目包含题目不足");
            }
            QuestionVO questionVO = one.get(0);
            jsonQuestion(questionVO);
            jsonQuestion(questionVO, Boolean.TRUE);
            return RestResponse.ok(questionVO);
        }
        return RestResponse.ok();
@@ -165,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();
    }
    /**
@@ -175,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);
@@ -186,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("");
        }
    }
}
src/main/resources/mapper/DeptQuestionMapper.xml
@@ -16,14 +16,19 @@
        DELETE
        FROM t_dept_question
        WHERE question_id = #{questionId}
        AND dept_id IN
        <foreach collection="deptIds" open="(" separator="," close=")" item="deptId">
            #{deptId}
        </foreach>
        <if test="deptIds != null and deptIds.size > 0">
            AND dept_id IN
            <foreach collection="deptIds" open="(" separator="," close=")" item="deptId">
                #{deptId}
            </foreach>
        </if>
    </delete>
    <select id="deptByQuestionId" resultType="com.mindskip.xzs.domain.vo.DeptQuestionVO">
        SELECT tdq.dept_id, td.name as deptName FROM t_dept_question tdq INNER JOIN t_department td ON td.id = tdq.dept_id WHERE tdq.question_id = #{questionId}
        SELECT tdq.dept_id, td.name as deptName
        FROM t_dept_question tdq
                 INNER JOIN t_department td ON td.id = tdq.dept_id
        WHERE tdq.question_id = #{questionId}
    </select>
</mapper>
src/main/resources/mapper/QuestionSubjectMapper.xml
@@ -98,24 +98,54 @@
            id DESC
    </select>
    <select id="questionsBySubjectId"  resultType="integer">
    <select id="questionsBySubjectId" resultType="integer">
        SELECT
            tqs.question_id
            tqs.question_id, ttc.content
        FROM
            t_question_subject tqs
                INNER JOIN t_question tq ON tqs.question_id = tq.id AND tqs.subject_id = #{subjectId}
                INNER JOIN t_text_content ttc tct.id = tq.info_text_content_id
        ORDER BY
            tqs.id DESC
    </select>
    <select id="questionsBySubjectIdAndQuestionType" resultType="integer">
        SELECT
            tqs.question_id
            tqs.question_id, ttc.content
        FROM
            t_question_subject tqs
                INNER JOIN t_question tq ON tqs.question_id = tq.id AND tqs.subject_id = #{subjectId} AND tq.question_type = #{questionType}
                INNER JOIN t_text_content ttc ttc.id = tq.info_text_content_id
        ORDER BY
            tqs.id DESC
    </select>
    <select id="bySubjectId" resultType="com.mindskip.xzs.domain.vo.QuestionVO">
        SELECT
           tq.id,
           tq.question_type,
           tq.correct,
           ttc.content as contentJson
        FROM
            t_question_subject tqs
                INNER JOIN t_question tq ON tqs.question_id = tq.id AND tqs.subject_id = #{subjectId}
                INNER JOIN t_text_content ttc ON ttc.id = tq.info_text_content_id
        ORDER BY
            tq.id DESC
    </select>
    <select id="bySubjectIdAndQuestionType" resultType="com.mindskip.xzs.domain.vo.QuestionVO">
        SELECT
            tq.id,
            tq.question_type,
            tq.correct,
            ttc.content as contentJson
        FROM
            t_question_subject tqs
                INNER JOIN t_question tq ON tqs.question_id = tq.id AND tqs.subject_id = #{subjectId} AND tq.question_type = #{questionType}
                INNER JOIN t_text_content ttc ON tct.id = tq.info_text_content_id
        ORDER BY
            tq.id DESC
    </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, question_type, deleted)
            t_self_practice(user_id, remark, subjects, practice_type, create_time, update_time, question_type, deleted, practice_mode)
        VALUE
            (#{userId}, #{remark}, #{subjects}, #{practiceType}, #{createTime}, #{updateTime}, #{questionType}, #{deleted})
            (#{userId}, #{remark}, #{subjects}, #{practiceType}, #{createTime}, #{updateTime}, #{questionType}, #{deleted}, #{practiceMode})
    </insert>
    <select id="page" resultType="com.mindskip.xzs.domain.vo.SelfPracticeVO">
@@ -19,7 +19,8 @@
               practice_type as practiceType,
               create_time createTime,
               update_time as updateTime,
               question_type as questionType
               question_type as questionType,
               practice_mode as practiceMode
        FROM
             t_self_practice
        <where>
@@ -47,7 +48,8 @@
            practice_type as practiceType,
            create_time createTime,
            update_time as updateTime,
            question_type as questionType
            question_type as questionType,
            practice_mode as practiceMode
        FROM
             t_self_practice
        WHERE