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

    <resultMap type="RealExamCollection" id="RealExamCollectionResult">
        <result property="examCollectionId" column="exam_collection_id"/>
        <result property="simType" column="sim_type"/>
        <result property="questionSettingMethod" column="question_setting_method"/>
        <result property="examCollectionType" column="exam_collection_type"/>
        <result property="examCollectionState" column="exam_collection_state"/>
        <result property="examCollectionName" column="exam_collection_name"/>
        <result property="taskId" column="task_id"/>
        <result property="limitDuration" column="limit_duration"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="createUserId" column="create_user_id"/>
        <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="selectRealExamCollectionVo">
        select exam_collection_id,
               sim_type,
               question_setting_method,
               exam_collection_type,
               exam_collection_state,
               exam_collection_name,
               task_id,
               limit_duration,
               start_time,
               end_time,
               create_user_id,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from mx_real_exam_collection
    </sql>

    <select id="selectRealExamCollectionList" parameterType="RealExamCollection" resultMap="RealExamCollectionResult">
        <include refid="selectRealExamCollectionVo"/>
        <where>
            <if test="simType != null  and simType != ''">and sim_type = #{simType}</if>
            <if test="questionSettingMethod != null  and questionSettingMethod != ''">and question_setting_method =
                #{questionSettingMethod}
            </if>
            <if test="examCollectionType != null  and examCollectionType != ''">and exam_collection_type =
                #{examCollectionType}
            </if>
            <if test="examCollectionState != null  and examCollectionState != ''">and exam_collection_state =
                #{examCollectionState}
            </if>
            <if test="examCollectionName != null  and examCollectionName != ''">and exam_collection_name like
                concat('%', #{examCollectionName}, '%')
            </if>
            <if test="taskId != null ">and task_id = #{taskId}</if>
            <if test="limitDuration != null ">and limit_duration = #{limitDuration}</if>
            <if test="startTime != null ">and start_time = #{startTime}</if>
            <if test="endTime != null ">and end_time = #{endTime}</if>
            <if test="createUserId != null ">and create_user_id = #{createUserId}</if>
        </where>
    </select>

    <select id="selectRealExamCollectionByExamCollectionId" parameterType="Long" resultMap="RealExamCollectionResult">
        <include refid="selectRealExamCollectionVo"/>
        where exam_collection_id = #{examCollectionId}
    </select>

    <insert id="insertRealExamCollection" parameterType="RealExamCollection" useGeneratedKeys="true"
            keyProperty="examCollectionId">
        <selectKey keyProperty="examCollectionId" order="AFTER" resultType="java.lang.Long">
            select LAST_INSERT_ID()
        </selectKey>
        insert into mx_real_exam_collection
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="simType != null and simType != ''">sim_type,</if>
            <if test="questionSettingMethod != null and questionSettingMethod != ''">question_setting_method,</if>
            <if test="examCollectionType != null and examCollectionType != ''">exam_collection_type,</if>
            <if test="examCollectionState != null">exam_collection_state,</if>
            <if test="examCollectionName != null and examCollectionName != ''">exam_collection_name,</if>
            <if test="taskId != null">task_id,</if>
            <if test="limitDuration != null">limit_duration,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="createUserId != null">create_user_id,</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="simType != null and simType != ''">#{simType},</if>
            <if test="questionSettingMethod != null and questionSettingMethod != ''">#{questionSettingMethod},</if>
            <if test="examCollectionType != null and examCollectionType != ''">#{examCollectionType},</if>
            <if test="examCollectionState != null">#{examCollectionState},</if>
            <if test="examCollectionName != null and examCollectionName != ''">#{examCollectionName},</if>
            <if test="taskId != null">#{taskId},</if>
            <if test="limitDuration != null">#{limitDuration},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="createUserId != null">#{createUserId},</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="updateRealExamCollection" parameterType="RealExamCollection">
        update mx_real_exam_collection
        <trim prefix="SET" suffixOverrides=",">
            <if test="simType != null and simType != ''">sim_type = #{simType},</if>
            <if test="questionSettingMethod != null and questionSettingMethod != ''">question_setting_method =
                #{questionSettingMethod},
            </if>
            <if test="examCollectionType != null and examCollectionType != ''">exam_collection_type =
                #{examCollectionType},
            </if>
            <if test="examCollectionState != null">exam_collection_state = #{examCollectionState},</if>
            <if test="examCollectionName != null and examCollectionName != ''">exam_collection_name =
                #{examCollectionName},
            </if>
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="limitDuration != null">limit_duration = #{limitDuration},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</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_collection_id = #{examCollectionId}
    </update>

    <delete id="deleteRealExamCollectionByExamCollectionId" parameterType="Long">
        delete
        from mx_real_exam_collection
        where exam_collection_id = #{examCollectionId}
    </delete>

    <delete id="deleteRealExamCollectionByExamCollectionIds" parameterType="String">
        delete from mx_real_exam_collection where exam_collection_id in
        <foreach item="examCollectionId" collection="array" open="(" separator="," close=")">
            #{examCollectionId}
        </foreach>
    </delete>
</mapper>