You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
exam/mapper/paper/PaperMapper.xml

103 lines
6.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!-- 声明 XML 文档版本为 1.0,指定字符编码为 UTF-8确保文档能正确处理各种字符 -->
<?xml version="1.0" encoding="UTF-8"?>
<!-- 定义文档类型,引用 MyBatis Mapper 3.0 的 DTD用于验证当前 XML 文档是否符合 MyBatis Mapper 规范 -->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 定义 Mapper 命名空间,将此 XML 映射文件与对应的 Java Mapper 接口关联起来,方便 MyBatis 找到对应的操作方法 -->
<mapper namespace="com.yf.exam.modules.paper.mapper.PaperMapper">
<!-- 通用查询映射结果,将数据库查询结果映射到 Java 实体类 com.yf.exam.modules.paper.entity.Paper -->
<resultMap id="BaseResultMap" type="com.yf.exam.modules.paper.entity.Paper">
<!-- 映射数据库表的主键列 id 到 Java 实体类的 id 属性 -->
<id column="id" property="id" />
<!-- 映射数据库表的 user_id 列到 Java 实体类的 userId 属性 -->
<result column="user_id" property="userId" />
<!-- 映射数据库表的 depart_id 列到 Java 实体类的 departId 属性 -->
<result column="depart_id" property="departId" />
<!-- 映射数据库表的 exam_id 列到 Java 实体类的 examId 属性 -->
<result column="exam_id" property="examId" />
<!-- 映射数据库表的 title 列到 Java 实体类的 title 属性 -->
<result column="title" property="title" />
<!-- 映射数据库表的 total_time 列到 Java 实体类的 totalTime 属性 -->
<result column="total_time" property="totalTime" />
<!-- 映射数据库表的 user_time 列到 Java 实体类的 userTime 属性 -->
<result column="user_time" property="userTime" />
<!-- 映射数据库表的 total_score 列到 Java 实体类的 totalScore 属性 -->
<result column="total_score" property="totalScore" />
<!-- 映射数据库表的 qualify_score 列到 Java 实体类的 qualifyScore 属性 -->
<result column="qualify_score" property="qualifyScore" />
<!-- 映射数据库表的 obj_score 列到 Java 实体类的 objScore 属性 -->
<result column="obj_score" property="objScore" />
<!-- 映射数据库表的 subj_score 列到 Java 实体类的 subjScore 属性 -->
<result column="subj_score" property="subjScore" />
<!-- 映射数据库表的 user_score 列到 Java 实体类的 userScore 属性 -->
<result column="user_score" property="userScore" />
<!-- 映射数据库表的 has_saq 列到 Java 实体类的 hasSaq 属性 -->
<result column="has_saq" property="hasSaq" />
<!-- 映射数据库表的 state 列到 Java 实体类的 state 属性 -->
<result column="state" property="state" />
<!-- 映射数据库表的 create_time 列到 Java 实体类的 createTime 属性 -->
<result column="create_time" property="createTime" />
<!-- 映射数据库表的 update_time 列到 Java 实体类的 updateTime 属性 -->
<result column="update_time" property="updateTime" />
<!-- 映射数据库表的 limit_time 列到 Java 实体类的 limitTime 属性 -->
<result column="limit_time" property="limitTime" />
</resultMap>
<!-- 定义通用查询结果列,可在其他 SQL 语句中通过 <include> 标签引用,提高代码复用性 -->
<sql id="Base_Column_List">
`id`,`user_id`,`depart_id`,`exam_id`,`title`,`total_time`,`user_time`,`total_score`,`qualify_score`,`obj_score`,`subj_score`,`user_score`,`has_saq`,`state`,`create_time`,`update_time`,`limit_time`
</sql>
<!-- 定义列表查询结果映射,继承 BaseResultMap将结果映射到 Java DTO 类 com.yf.exam.modules.paper.dto.response.PaperListRespDTO -->
<resultMap id="ListResultMap"
extends="BaseResultMap"
type="com.yf.exam.modules.paper.dto.response.PaperListRespDTO">
<!-- 映射数据库表的 real_name 列到 Java DTO 类的 realName 属性 -->
<result column="real_name" property="realName" />
</resultMap>
<!-- 定义分页查询方法,使用 ListResultMap 进行结果映射 -->
<select id="paging" resultMap="ListResultMap">
<!-- 查询 el_paper 表的所有列和 sys_user 表的 real_name 列 -->
SELECT pp.*,uc.real_name FROM el_paper pp
<!-- 左连接 sys_user 表,通过 user_id 关联 -->
LEFT JOIN sys_user uc ON pp.user_id=uc.id
<!-- <where> 标签会自动处理 SQL 语句中的 AND 关键字,避免多余的连接词 -->
<where>
<!-- 判断查询参数 query 是否不为空 -->
<if test="query!=null">
<!-- 判断查询参数中的 examId 是否不为空且不为空字符串 -->
<if test="query.examId!=null and query.examId!=''">
<!-- 添加筛选条件,根据 examId 过滤 -->
AND pp.exam_id=#{query.examId}
</if>
<!-- 判断查询参数中的 userId 是否不为空且不为空字符串 -->
<if test="query.userId!=null and query.userId!=''">
<!-- 添加筛选条件,根据 userId 过滤 -->
AND pp.user_id=#{query.userId}
</if>
<!-- 判断查询参数中的 departId 是否不为空且不为空字符串 -->
<if test="query.departId!=null and query.departId!=''">
<!-- 添加筛选条件,根据 departId 过滤 -->
AND pp.depart_id=#{query.departId}
</if>
<!-- 判断查询参数中的 state 是否不为空 -->
<if test="query.state!=null">
<!-- 添加筛选条件,根据 state 过滤 -->
AND pp.state=#{query.state}
</if>
<!-- 判断查询参数中的 realName 是否不为空且不为空字符串 -->
<if test="query.realName!=null and query.realName!=''">
<!-- 添加模糊查询条件,根据 realName 过滤 -->
AND uc.real_name LIKE CONCAT('%',#{query.realName},'%')
</if>
</if>
</where>
<!-- 按创建时间倒序排序 -->
ORDER BY create_time DESC
</select>
</mapper>