<?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.ElUserExamMapper">

    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.userexam.ElUserExam">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="userId" column="user_id" jdbcType="INTEGER"/>
            <result property="examId" column="exam_id" jdbcType="VARCHAR"/>
            <result property="tryCount" column="try_count" jdbcType="INTEGER"/>
            <result property="maxScore" column="max_score" jdbcType="INTEGER"/>
            <result property="passed" column="passed" jdbcType="TINYINT"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,user_id,exam_id,
        try_count,max_score,passed,
        create_time,update_time
    </sql>

    <select id="selectExamList" parameterType="com.ruoyi.system.domain.userexam.dto.request.UserExamReqDTO" resultType="com.ruoyi.system.domain.userexam.dto.response.UserExamRespDTO">
        SELECT ue.*,ee.title,uc.user_name FROM el_user_exam ue
        LEFT JOIN el_exam ee ON ue.exam_id=ee.id
        LEFT JOIN ${prefix}sys_user uc ON ue.user_id=uc.user_id
        WHERE ee.id IS NOT NULL AND uc.user_id IS NOT NULL
        <if test="userId!=null and userId!=''">
            AND ue.user_id= #{userId}
        </if>
        <if test="examId!=null and examId!=''">
            AND ue.exam_id = #{examId}
        </if>
        <if test="title!=null and title!=''">
            AND ee.title LIKE CONCAT('%',#{title},'%')
        </if>
        <if test="userName!=null and userName!=''">
            AND uc.user_name LIKE CONCAT('%',#{userName},'%')
        </if>
    </select>
</mapper>
