ai-course/app/api/playedu-exam/src/main/resources/mapper/ExamQuestionMapper.xml
menft f1881865de feat(exam): 随机试卷支持难度与知识点筛选
- 后端新增 /knowledge-codes 接口,根据题库/题型/难度获取知识点列表
- ExamQuestionMapper.xml 添加 level 和 knowledge_code 过滤条件
- IKnowledgeService 新增 getByKnowledgeCodes 批量查询方法
- 前端 random-paper.tsx 各题型增加难度和知识点下拉选择
- 知识点动态加载,支持编辑时回显名称
- 更新前端 CLAUDE.md 文档,补充 httpClient 响应结构说明
2025-11-30 10:37:31 +08:00

268 lines
10 KiB
XML

<?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="xyz.playedu.exam.mapper.ExamQuestionMapper">
<resultMap id="BaseResultMap" type="xyz.playedu.exam.domain.ExamQuestion">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="categoryId" column="category_id" jdbcType="INTEGER"/>
<result property="adminId" column="admin_id" jdbcType="INTEGER"/>
<result property="type" column="type" jdbcType="INTEGER"/>
<result property="level" column="level" jdbcType="TINYINT"/>
<result property="knowledgeCode" column="knowledge_code" jdbcType="VARCHAR"/>
<result property="content" column="content" jdbcType="VARCHAR"/>
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
<result property="deleted" column="deleted" jdbcType="TINYINT"/>
</resultMap>
<sql id="Base_Column_List">
id,category_id,admin_id,type,
level,knowledge_code,content,created_at,
updated_at,deleted
</sql>
<select id="paginate" resultType="xyz.playedu.exam.domain.ExamQuestion">
SELECT `exam_question`.*
FROM `exam_question`
<where>
<if test="adminIds != null and !adminIds.isEmpty()">
AND `exam_question`.`admin_id` IN (<foreach collection="adminIds" item="tmpId" separator=",">
#{tmpId}</foreach>)
</if>
<if test="categoryId != null and categoryId != ''">
AND `exam_question`.`category_id` IN (#{categoryId})
</if>
<if test="content != null and content != ''">
AND `exam_question`.`content` LIKE concat('%',#{content},'%')
</if>
<if test="type != null">
AND `exam_question`.`type` = #{type}
</if>
<if test="level != null">
AND `exam_question`.`level` = #{level}
</if>
<if test="knowledgeCode != null and knowledgeCode != ''">
AND FIND_IN_SET(#{knowledgeCode}, `exam_question`.`knowledge_code`)
</if>
</where>
<if test="sortAlgo == 'asc'">
<choose>
<when test="sortField == 'created_at'">
ORDER BY `exam_question`.`created_at` ASC
</when>
<otherwise>
ORDER BY `exam_question`.`id` ASC
</otherwise>
</choose>
</if>
<if test="sortAlgo != 'asc'">
<choose>
<when test="sortField == 'created_at'">
ORDER BY `exam_question`.`created_at` DESC
</when>
<otherwise>
ORDER BY `exam_question`.`id` DESC
</otherwise>
</choose>
</if>
LIMIT #{pageStart}, #{pageSize};
</select>
<select id="paginateCount" resultType="java.lang.Long">
SELECT count(1)
FROM `exam_question`
<where>
<if test="adminIds != null and !adminIds.isEmpty()">
AND `exam_question`.`admin_id` IN (<foreach collection="adminIds" item="tmpId" separator=",">
#{tmpId}</foreach>)
</if>
<if test="categoryId != null and categoryId != ''">
AND `exam_question`.`category_id` IN (#{categoryId})
</if>
<if test="content != null and content != ''">
AND `exam_question`.`content` LIKE concat('%',#{content},'%')
</if>
<if test="type != null">
AND `exam_question`.`type` = #{type}
</if>
<if test="level != null">
AND `exam_question`.`level` = #{level}
</if>
<if test="knowledgeCode != null and knowledgeCode != ''">
AND FIND_IN_SET(#{knowledgeCode}, `exam_question`.`knowledge_code`)
</if>
</where>
</select>
<select id="chunksByCategoryIdAndLimit" resultType="xyz.playedu.exam.domain.ExamQuestion">
(SELECT `exam_question`.* FROM `exam_question`
<where>
and `exam_question`.`type` = 1
<if test="categoryIds != null">
and `exam_question`.`category_id` IN
<foreach collection="categoryIds" item="categoryId" open="(" separator="," close=")">
#{categoryId}
</foreach>
</if>
<if test="type1Level != null">
and `exam_question`.`level` = #{type1Level}
</if>
<if test="type1KnowledgeCodes != null and type1KnowledgeCodes != ''">
and (
<foreach collection="type1KnowledgeCodes.split(',')" item="code" separator=" OR ">
FIND_IN_SET(#{code}, `exam_question`.`knowledge_code`)
</foreach>
)
</if>
</where>
ORDER BY RAND()
LIMIT #{type1Number})
UNION ALL
(SELECT `exam_question`.* FROM `exam_question`
<where>
and `exam_question`.`type` = 2
<if test="categoryIds != null">
and `exam_question`.`category_id` IN
<foreach collection="categoryIds" item="categoryId" open="(" separator="," close=")">
#{categoryId}
</foreach>
</if>
<if test="type2Level != null">
and `exam_question`.`level` = #{type2Level}
</if>
<if test="type2KnowledgeCodes != null and type2KnowledgeCodes != ''">
and (
<foreach collection="type2KnowledgeCodes.split(',')" item="code" separator=" OR ">
FIND_IN_SET(#{code}, `exam_question`.`knowledge_code`)
</foreach>
)
</if>
</where>
ORDER BY RAND()
LIMIT #{type2Number})
UNION ALL
(SELECT `exam_question`.* FROM `exam_question`
<where>
and `exam_question`.`type` = 3
<if test="categoryIds != null">
and `exam_question`.`category_id` IN
<foreach collection="categoryIds" item="categoryId" open="(" separator="," close=")">
#{categoryId}
</foreach>
</if>
<if test="type3Level != null">
and `exam_question`.`level` = #{type3Level}
</if>
<if test="type3KnowledgeCodes != null and type3KnowledgeCodes != ''">
and (
<foreach collection="type3KnowledgeCodes.split(',')" item="code" separator=" OR ">
FIND_IN_SET(#{code}, `exam_question`.`knowledge_code`)
</foreach>
)
</if>
</where>
ORDER BY RAND()
LIMIT #{type3Number})
UNION ALL
(SELECT `exam_question`.* FROM `exam_question`
<where>
and `exam_question`.`type` = 4
<if test="categoryIds != null">
and `exam_question`.`category_id` IN
<foreach collection="categoryIds" item="categoryId" open="(" separator="," close=")">
#{categoryId}
</foreach>
</if>
<if test="type4Level != null">
and `exam_question`.`level` = #{type4Level}
</if>
<if test="type4KnowledgeCodes != null and type4KnowledgeCodes != ''">
and (
<foreach collection="type4KnowledgeCodes.split(',')" item="code" separator=" OR ">
FIND_IN_SET(#{code}, `exam_question`.`knowledge_code`)
</foreach>
)
</if>
</where>
ORDER BY RAND()
LIMIT #{type4Number})
UNION ALL
(SELECT `exam_question`.* FROM `exam_question`
<where>
and `exam_question`.`type` = 5
<if test="categoryIds != null">
and `exam_question`.`category_id` IN
<foreach collection="categoryIds" item="categoryId" open="(" separator="," close=")">
#{categoryId}
</foreach>
</if>
<if test="type5Level != null">
and `exam_question`.`level` = #{type5Level}
</if>
<if test="type5KnowledgeCodes != null and type5KnowledgeCodes != ''">
and (
<foreach collection="type5KnowledgeCodes.split(',')" item="code" separator=" OR ">
FIND_IN_SET(#{code}, `exam_question`.`knowledge_code`)
</foreach>
)
</if>
</where>
ORDER BY RAND()
LIMIT #{type5Number})
UNION ALL
(SELECT `exam_question`.* FROM `exam_question`
<where>
and `exam_question`.`type` = 6
<if test="categoryIds != null">
and `exam_question`.`category_id` IN
<foreach collection="categoryIds" item="categoryId" open="(" separator="," close=")">
#{categoryId}
</foreach>
</if>
<if test="type6Level != null">
and `exam_question`.`level` = #{type6Level}
</if>
<if test="type6KnowledgeCodes != null and type6KnowledgeCodes != ''">
and (
<foreach collection="type6KnowledgeCodes.split(',')" item="code" separator=" OR ">
FIND_IN_SET(#{code}, `exam_question`.`knowledge_code`)
</foreach>
)
</if>
</where>
ORDER BY RAND()
LIMIT #{type6Number})
</select>
<select id="getDistinctKnowledgeCodes" resultType="java.lang.String">
SELECT DISTINCT `knowledge_code`
FROM `exam_question`
<where>
AND `knowledge_code` IS NOT NULL
AND `knowledge_code` != ''
<if test="categoryIds != null and categoryIds != ''">
AND `category_id` IN (${categoryIds})
</if>
<if test="type != null">
AND `type` = #{type}
</if>
<if test="level != null">
AND `level` = #{level}
</if>
</where>
</select>
</mapper>