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

    <resultMap type="RealExamCompRequest" id="RealExamCompRequestResult">
        <result property="relId" column="rel_id"/>
        <result property="examId" column="exam_id"/>
        <result property="faultId" column="fault_id"/>
        <result property="requestStatus" column="request_status"/>
        <result property="createByUserId" column="create_by_user_id"/>
        <result property="updateByUserId" column="update_by_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="selectRealExamCompRequestVo">
        select rel_id,
               exam_id,
               fault_id,
               request_status,
               create_by_user_id,
               update_by_user_id,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from sim_real_exam_comp_request
    </sql>

    <select id="selectRealExamCompRequestList" parameterType="RealExamCompRequest"
            resultMap="RealExamCompRequestResult">
        <include refid="selectRealExamCompRequestVo"/>
        <where>
            <if test="examId != null ">and exam_id = #{examId}</if>
            <if test="faultId != null  and faultId != ''">and fault_id = #{faultId}</if>
            <if test="requestStatus != null  and requestStatus != ''">and request_status = #{requestStatus}</if>
            <if test="createByUserId != null ">and create_by_user_id = #{createByUserId}</if>
            <if test="updateByUserId != null ">and update_by_user_id = #{updateByUserId}</if>
        </where>
    </select>

    <select id="selectRealExamCompRequestByRelId" parameterType="Long" resultMap="RealExamCompRequestResult">
        <include refid="selectRealExamCompRequestVo"/>
        where rel_id = #{relId}
    </select>

    <insert id="insertRealExamCompRequest" parameterType="RealExamCompRequest" useGeneratedKeys="true"
            keyProperty="relId">
        <selectKey keyProperty="relId" order="AFTER" resultType="java.lang.Long">
            select LAST_INSERT_ID()
        </selectKey>
        insert into sim_real_exam_comp_request
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="examId != null">exam_id,</if>
            <if test="faultId != null and faultId != ''">fault_id,</if>
            <if test="requestStatus != null and requestStatus != ''">request_status,</if>
            <if test="createByUserId != null">create_by_user_id,</if>
            <if test="updateByUserId != null">update_by_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="examId != null">#{examId},</if>
            <if test="faultId != null and faultId != ''">#{faultId},</if>
            <if test="requestStatus != null and requestStatus != ''">#{requestStatus},</if>
            <if test="createByUserId != null">#{createByUserId},</if>
            <if test="updateByUserId != null">#{updateByUserId},</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="updateRealExamCompRequest" parameterType="RealExamCompRequest">
        update sim_real_exam_comp_request
        <trim prefix="SET" suffixOverrides=",">
            <if test="examId != null">exam_id = #{examId},</if>
            <if test="faultId != null and faultId != ''">fault_id = #{faultId},</if>
            <if test="requestStatus != null and requestStatus != ''">request_status = #{requestStatus},</if>
            <if test="createByUserId != null">create_by_user_id = #{createByUserId},</if>
            <if test="updateByUserId != null">update_by_user_id = #{updateByUserId},</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 rel_id = #{relId}
    </update>

    <delete id="deleteRealExamCompRequestByRelId" parameterType="Long">
        delete
        from sim_real_exam_comp_request
        where rel_id = #{relId}
    </delete>

    <delete id="deleteRealExamCompRequestByRelIds" parameterType="String">
        delete from sim_real_exam_comp_request where rel_id in
        <foreach item="relId" collection="array" open="(" separator="," close=")">
            #{relId}
        </foreach>
    </delete>
</mapper>