<?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.ruoyi.system.mapper.ElExamMapper">

    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.exam.ElExam">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="title" column="title" jdbcType="VARCHAR"/>
            <result property="content" column="content" jdbcType="VARCHAR"/>
            <result property="openType" column="open_type" jdbcType="INTEGER"/>
            <result property="state" column="state" jdbcType="INTEGER"/>
            <result property="timeLimit" column="time_limit" jdbcType="TINYINT"/>
            <result property="startTime" column="start_time" jdbcType="TIMESTAMP"/>
            <result property="endTime" column="end_time" jdbcType="TIMESTAMP"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
            <result property="totalScore" column="total_score" jdbcType="INTEGER"/>
            <result property="totalTime" column="total_time" jdbcType="INTEGER"/>
            <result property="qualifyScore" column="qualify_score" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,title,content,
        open_type,state,time_limit,
        start_time,end_time,create_time,
        update_time,total_score,total_time,
        qualify_score
    </sql>
    <select id="selectExamList"  resultType="com.ruoyi.system.domain.exam.dto.ExamDTO"  >
        SELECT   <include refid="Base_Column_List"/>  FROM el_exam
        <trim prefix="where" prefixOverrides="and|or">
            <if test="title!=null and title!=''">
                AND title LIKE CONCAT('%',#{title},'%')
            </if>
            <if test="openType!=null">
                AND open_type = #{openType}
            </if>

            <if test="startTime!=null">
                AND start_time >= #{startTime}
            </if>

            <if test="endTime!=null">
                AND end_time &lt;= #{endTime}
            </if>
        </trim>
       ORDER BY create_time DESC
    </select>
    <select id="onlineExamList" resultType="com.ruoyi.system.domain.exam.dto.response.ExamOnlineRespDTO">
        SELECT ex.*
        FROM el_exam ex
        LEFT JOIN el_exam_depart dept ON ex.id=dept.exam_id AND ex.open_type=2
        LEFT JOIN ${prefix}sys_user uc ON uc.dept_id=dept.depart_id
        WHERE ex.state=0 AND (ex.open_type=1 OR ex.open_type=3 OR uc.user_id=#{userId})
        <if test="title!=null and title!=''">
            AND ex.title LIKE CONCAT('%',#{title},'%')
        </if>
        <if test="openType!=null">
            AND ex.open_type=#{openType}
        </if>
    </select>
</mapper>
