<?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.project.training.elearn.mapper.TElQuRepoMapper">

    <resultMap type="TElQuRepo" id="TElQuRepoResult">
        <result property="id" column="id"/>
        <result property="quId" column="qu_id"/>
        <result property="repoId" column="repo_id"/>
        <result property="quType" column="qu_type"/>
        <result property="sort" column="sort"/>
    </resultMap>

    <sql id="selectTElQuRepoVo">
        select d.id, d.qu_id, d.repo_id, d.qu_type, d.sort
        from t_el_qu_repo d
    </sql>

    <select id="selectTElQuRepoList" parameterType="TElQuRepo" resultMap="TElQuRepoResult">
        <include refid="selectTElQuRepoVo"/>
        <where>
            <if test="quId != null ">and qu_id = #{quId}</if>
            <if test="repoId != null ">and repo_id = #{repoId}</if>
            <if test="quType != null ">and qu_type = #{quType}</if>
            <if test="sort != null ">and sort = #{sort}</if>
        </where>
        <!-- 数据范围过滤 -->
    </select>

    <select id="selectTElQuRepoById" parameterType="Long" resultMap="TElQuRepoResult">
        <include refid="selectTElQuRepoVo"/>
        where id = #{id}
    </select>


    <select id="selectTElQuRepoLast" parameterType="TElUserQu" resultMap="TElQuRepoResult">
        select * from (select d.id, d.qu_id, d.repo_id, d.qu_type, d.sort from t_el_qu_repo d
        <where>
            <if test="repoId != null ">and repo_id = #{repoId}</if>
            <if test="quId != null ">and #{quId} > qu_id</if>

        </where>
        order by d.qu_id desc)
        where rownum = 1
    </select>

    <insert id="insertTElQuRepo" parameterType="TElQuRepo">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_el_qu_repo.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_el_qu_repo
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="quId != null">qu_id,</if>
            <if test="repoId != null">repo_id,</if>
            <if test="quType != null">qu_type,</if>
            <if test="sort != null">sort,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="quId != null">#{quId},</if>
            <if test="repoId != null">#{repoId},</if>
            <if test="quType != null">#{quType},</if>
            <if test="sort != null">#{sort},</if>
        </trim>
    </insert>

    <update id="updateTElQuRepo" parameterType="TElQuRepo">
        update t_el_qu_repo
        <trim prefix="SET" suffixOverrides=",">
            <if test="quId != null">qu_id = #{quId},</if>
            <if test="repoId != null">repo_id = #{repoId},</if>
            <if test="quType != null">qu_type = #{quType},</if>
            <if test="sort != null">sort = #{sort},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTElQuRepoById" parameterType="Long">
        delete
        from t_el_qu_repo
        where id = #{id}
    </delete>

    <delete id="deleteTElQuRepoByIds" parameterType="String">
        delete from t_el_qu_repo where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>
