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

    <resultMap type="RealExamCollectionDept" id="RealExamCollectionDeptResult">
        <result property="relId" column="rel_id"/>
        <result property="examCollectionId" column="exam_collection_id"/>
        <result property="deptId" column="dept_id"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectRealExamCollectionDeptVo">
        select rel_id, exam_collection_id, dept_id, update_time
        from sim_real_exam_collection_dept
    </sql>

    <select id="selectRealExamCollectionDeptList" parameterType="RealExamCollectionDept"
            resultMap="RealExamCollectionDeptResult">
        <include refid="selectRealExamCollectionDeptVo"/>
        <where>
            <if test="examCollectionId != null ">and exam_collection_id = #{examCollectionId}</if>
            <if test="deptId != null ">and dept_id = #{deptId}</if>
        </where>
    </select>

    <select id="selectRealExamCollectionDeptByRelId" parameterType="Long" resultMap="RealExamCollectionDeptResult">
        <include refid="selectRealExamCollectionDeptVo"/>
        where rel_id = #{relId}
    </select>

    <insert id="insertRealExamCollectionDept" parameterType="RealExamCollectionDept" useGeneratedKeys="true"
            keyProperty="relId">
        <selectKey keyProperty="relId" order="AFTER" resultType="java.lang.Long">
            select LAST_INSERT_ID()
        </selectKey>
        insert into sim_real_exam_collection_dept
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="examCollectionId != null">exam_collection_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="examCollectionId != null">#{examCollectionId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateRealExamCollectionDept" parameterType="RealExamCollectionDept">
        update sim_real_exam_collection_dept
        <trim prefix="SET" suffixOverrides=",">
            <if test="examCollectionId != null">exam_collection_id = #{examCollectionId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where rel_id = #{relId}
    </update>

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

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