<?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.ynfy.buss.exam.userexamresult.mapper.UserExamResultMapper">

    <select id="selectPageList" resultType="com.ynfy.buss.exam.userexamresult.entity.UserExamResult">
        SELECT
                u.*,
                IFNULL(u.update_time,u.create_time) AS  updateTime,
                e.title as examTitle,
                e.image as examCover
        FROM user_exam_result u
        INNER JOIN exam e on u.exam_id = e.id
        <where>
            <if test="userExamResult.examTitle != null and userExamResult.examTitle != ''">
                AND e.title like concat('%', #{userExamResult.examTitle}, '%')
            </if>
            <if test="userExamResult.userId != null and userExamResult.userId != ''">
                AND u.user_id = #{userExamResult.userId}
            </if>
            <if test="userExamResult.passed != null">
                AND u.passed = #{userExamResult.passed}
            </if>
        </where>
    </select>

    <select id="getUserExamScore" resultType="com.ynfy.buss.exam.userexamresult.entity.vo.UserExamScoreVO">
        SELECT
            u.try_count,
            u.max_score,
            u.passed,
            e.total_score,
            e.qualify_score,
            p.question_count
        FROM user_exam_result u
        LEFT JOIN exam e on u.exam_id = e.id
        LEFT JOIN paper p on e.paper_id=p.id
        WHERE
            u.user_id = #{userId} AND u.exam_id = #{examId}
    </select>
</mapper>