<?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.sim.mapper.RealExamMapper">

    <resultMap type="RealExam" id="RealExamResult">
        <result property="examId" column="exam_id"/>
        <result property="examCollectionId" column="exam_collection_id"/>
        <result property="userId" column="user_id"/>
        <result property="seatId" column="seat_id"/>
        <result property="simId" column="sim_id"/>
        <result property="examStatus" column="exam_status"/>
        <result property="totalScore" column="total_score"/>
        <result property="deductionTotalScore" column="deduction_total_score"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="loginTime" column="login_time"/>
        <result property="logoutTime" column="logout_time"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectRealExamVo">
        select exam_id,
               exam_collection_id,
               user_id,
               seat_id,
               sim_id,
               exam_status,
               total_score,
               deduction_total_score,
               start_time,
               end_time,
               login_time,
               logout_time,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from mx_real_exam
    </sql>

    <select id="selectRealExamList" parameterType="RealExam" resultMap="RealExamResult">
        <include refid="selectRealExamVo"/>
        <where>
            <if test="examCollectionId != null ">and exam_collection_id = #{examCollectionId}</if>
            <if test="userId != null ">and user_id = #{userId}</if>
            <if test="seatId != null ">and seat_id = #{seatId}</if>
            <if test="simId != null ">and sim_id = #{simId}</if>
            <if test="examStatus != null  and examStatus != ''">and exam_status = #{examStatus}</if>
            <if test="totalScore != null ">and total_score = #{totalScore}</if>
            <if test="deductionTotalScore != null ">and deduction_total_score = #{deductionTotalScore}</if>
            <if test="startTime != null ">and start_time = #{startTime}</if>
            <if test="endTime != null ">and end_time = #{endTime}</if>
            <if test="loginTime != null ">and login_time = #{loginTime}</if>
            <if test="logoutTime != null ">and logout_time = #{logoutTime}</if>
        </where>
    </select>

    <select id="selectRealExamByExamId" parameterType="Long" resultMap="RealExamResult">
        <include refid="selectRealExamVo"/>
        where exam_id = #{examId}
    </select>

    <insert id="insertRealExam" parameterType="RealExam">
        <selectKey keyProperty="examId" order="AFTER" resultType="java.lang.Long">
            select LAST_INSERT_ID()
        </selectKey>
        insert into mx_real_exam
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="examId != null">exam_id,</if>
            <if test="examCollectionId != null">exam_collection_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="seatId != null">seat_id,</if>
            <if test="simId != null">sim_id,</if>
            <if test="examStatus != null">exam_status,</if>
            <if test="totalScore != null">total_score,</if>
            <if test="deductionTotalScore != null">deduction_total_score,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="loginTime != null">login_time,</if>
            <if test="logoutTime != null">logout_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="examId != null">#{examId},</if>
            <if test="examCollectionId != null">#{examCollectionId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="seatId != null">#{seatId},</if>
            <if test="simId != null">#{simId},</if>
            <if test="examStatus != null">#{examStatus},</if>
            <if test="totalScore != null">#{totalScore},</if>
            <if test="deductionTotalScore != null">#{deductionTotalScore},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="loginTime != null">#{loginTime},</if>
            <if test="logoutTime != null">#{logoutTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateRealExam" parameterType="RealExam">
        update mx_real_exam
        <trim prefix="SET" suffixOverrides=",">
            <if test="examCollectionId != null">exam_collection_id = #{examCollectionId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="seatId != null">seat_id = #{seatId},</if>
            <if test="simId != null">sim_id = #{simId},</if>
            <if test="examStatus != null">exam_status = #{examStatus},</if>
            <if test="totalScore != null">total_score = #{totalScore},</if>
            <if test="deductionTotalScore != null">deduction_total_score = #{deductionTotalScore},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="loginTime != null">login_time = #{loginTime},</if>
            <if test="logoutTime != null">logout_time = #{logoutTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where exam_id = #{examId}
    </update>

    <delete id="deleteRealExamByExamId" parameterType="Long">
        delete
        from mx_real_exam
        where exam_id = #{examId}
    </delete>

    <delete id="deleteRealExamByExamIds" parameterType="String">
        delete from mx_real_exam where exam_id in
        <foreach item="examId" collection="array" open="(" separator="," close=")">
            #{examId}
        </foreach>
    </delete>
</mapper>