ai-course/app/api/playedu-exam/src/main/resources/mapper/ExamQuestionMapper.xml

183 lines
6.6 KiB
XML
Raw Normal View History

2025-11-18 13:32:46 +08:00
<?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="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,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>
</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>
</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>
</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>
</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>
</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>
</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>
</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>
</where>
ORDER BY RAND()
LIMIT #{type6Number})
</select>
</mapper>