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

    <resultMap type="TElQu" id="TElQuResult">
        <result property="quId"    column="qu_id"    />
        <result property="quType"    column="qu_type"    />
        <result property="qlevel"    column="qlevel"    />
        <result property="content"    column="content"    />
        <result property="image"    column="image"    />
        <result property="analysis"    column="analysis"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTElQuVo">
        select d.qu_id, d.qu_type, d.qlevel, d.content, d.image, d.analysis, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks from t_el_qu d
    </sql>

    <sql id="selectTElQuVoRepo">
        select d.qu_id, d.qu_type, d.qlevel, d.content, d.image, d.analysis, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks from t_el_qu d
        LEFT JOIN t_el_qu_repo po ON d.qu_id=po.qu_id
    </sql>

    <select id="selectTElQuList" parameterType="TElQu" resultMap="TElQuResult">
        select d.qu_id, d.qu_type, d.qlevel, d.content, d.image, d.analysis, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks from t_el_qu d
        <if test="repoIds!=null and repoIds.size()>0">
            LEFT JOIN t_el_qu_repo po ON d.qu_id=po.qu_id
        </if>
        <where>
            <if test="repoIds!=null and repoIds.size()>0">
                AND po.repo_id IN
                <foreach collection="repoIds" open="(" close=")" separator="," item="repoId">#{repoId}</foreach>
            </if>
            <if test="quType != null "> and d.qu_type = #{quType}</if>
            <if test="qlevel != null "> and d.qlevel = #{qlevel}</if>
            <if test="content != null  and content != ''"> and cd.ontent = #{content}</if>
            <if test="image != null  and image != ''"> and d.image = #{image}</if>
            <if test="analysis != null  and analysis != ''"> and d.analysis = #{analysis}</if>
            <if test="createrCode != null  and createrCode != ''"> and d.creater_code = #{createrCode}</if>
            <if test="createdate != null "> and d.createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and d.updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and d.updatedate = #{updatedate}</if>
            <if test="deptId != null "> and d.dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and d.remarks = #{remarks}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
    </select>

    <select id="selectTElQuListByRepo" parameterType="TElExamRepo" resultMap="TElQuResult">
        select d.qu_id, d.qu_type, d.qlevel, d.content, d.image, d.analysis, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks from t_el_qu d
        LEFT JOIN t_el_qu_repo b ON d.qu_id=b.qu_id
        WHERE b.repo_id=#{repoId} AND d.qu_type=#{quType} and d.del_flag = 0

    </select>

    <select id="selectTElQuById" parameterType="Long" resultMap="TElQuResult">
        select d.qu_id, d.qu_type, d.qlevel, d.content, d.image, d.analysis, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks from t_el_qu d
        where d.qu_id = #{quId}
    </select>

    <insert id="insertTElQu" parameterType="TElQu">
        <selectKey keyProperty="quId" resultType="long" order="BEFORE">
            SELECT seq_t_el_qu.NEXTVAL as quId FROM DUAL
        </selectKey>
        insert into t_el_qu
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="quId != null">qu_id,</if>
            <if test="quType != null">qu_type,</if>
            <if test="qlevel != null">qlevel,</if>
            <if test="content != null">content,</if>
            <if test="image != null">image,</if>
            <if test="analysis != null">analysis,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="quId != null">#{quId},</if>
            <if test="quType != null">#{quType},</if>
            <if test="qlevel != null">#{qlevel},</if>
            <if test="content != null">#{content},</if>
            <if test="image != null">#{image},</if>
            <if test="analysis != null">#{analysis},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTElQu" parameterType="TElQu">
        update t_el_qu
        <trim prefix="SET" suffixOverrides=",">
            <if test="quType != null">qu_type = #{quType},</if>
            <if test="qlevel != null">qlevel = #{qlevel},</if>
            <if test="content != null">content = #{content},</if>
            <if test="image != null">image = #{image},</if>
            <if test="analysis != null">analysis = #{analysis},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where qu_id = #{quId}
    </update>

    <update id="deleteTElQuById" parameterType="Long">
        update t_el_qu set del_flag = 2 where qu_id = #{quId}
    </update>

    <update id="deleteTElQuByIds" parameterType="String">
        update t_el_qu set del_flag = 2 where qu_id in
        <foreach item="quId" collection="array" open="(" separator="," close=")">
            #{quId}
        </foreach>
    </update>

</mapper>
