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

    <resultMap type="TElPaperQuAnswer" id="TElPaperQuAnswerResult">
        <result property="id"    column="id"    />
        <result property="paperId"    column="paper_id"    />
        <result property="quId"    column="qu_id"    />
        <result property="answerId"    column="answer_id"    />
        <result property="isRight"    column="is_right"    />
        <result property="checked"    column="checked"    />
        <result property="sort"    column="sort"    />
        <result property="abc"    column="abc"    />
    </resultMap>

    <sql id="selectTElPaperQuAnswerVo">
        select d.id, d.paper_id, d.qu_id, d.answer_id, d.is_right, d.checked, d.sort, d.abc  from t_el_paper_qu_answer d
    </sql>

    <select id="selectTElPaperQuAnswerList" parameterType="TElPaperQuAnswer" resultMap="TElPaperQuAnswerResult">
        <include refid="selectTElPaperQuAnswerVo"/>
        <where>
            <if test="paperId != null "> and paper_id = #{paperId}</if>
            <if test="quId != null "> and qu_id = #{quId}</if>
            <if test="answerId != null "> and answer_id = #{answerId}</if>
            <if test="isRight != null "> and is_right = #{isRight}</if>
            <if test="checked != null "> and checked = #{checked}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="abc != null  and abc != ''"> and abc = #{abc}</if>
        </where>
    </select>

    <select id="selectTElPaperQuAnswerListByExam" parameterType="TElPaperQuAnswer" resultMap="TElPaperQuAnswerResult">
        select d.id, d.paper_id, d.qu_id, d.answer_id, d.is_right, d.checked, d.sort, d.abc,qa.content,qa.image  from t_el_paper_qu_answer d
        LEFT JOIN t_el_qu_answer qa ON d.answer_id = qa.answer_id
        <where>
            <if test="paperId != null "> and d.paper_id = #{paperId}</if>
            <if test="quId != null "> and d.qu_id = #{quId}</if>
            <if test="answerId != null "> and d.answer_id = #{answerId}</if>
            <if test="isRight != null "> and d.is_right = #{isRight}</if>
            <if test="checked != null "> and d.checked = #{checked}</if>
            <if test="sort != null "> and d.sort = #{sort}</if>
            <if test="abc != null  and abc != ''"> and d.abc = #{abc}</if>
        </where>
        ORDER BY d.sort ASC
    </select>

    <select id="selectTElPaperQuAnswerListByPaper" parameterType="TElPaperQuAnswer" resultMap="TElPaperQuAnswerResult">
        select d.id, d.paper_id, d.qu_id, d.answer_id, d.is_right, d.checked, d.sort, d.abc,qa.content,qa.image  from t_el_paper_qu_answer d
        LEFT JOIN t_el_qu_answer qa ON d.answer_id = qa.answer_id
        <where>
            <if test="paperId != null "> and d.paper_id = #{paperId}</if>
            <if test="quId != null "> and d.qu_id = #{quId}</if>
            <if test="answerId != null "> and d.answer_id = #{answerId}</if>
            <if test="isRight != null "> and d.is_right = #{isRight}</if>
            <if test="checked != null "> and d.checked = #{checked}</if>
            <if test="sort != null "> and d.sort = #{sort}</if>
            <if test="abc != null  and abc != ''"> and d.abc = #{abc}</if>
        </where>
        ORDER BY d.sort ASC
    </select>

    <select id="selectTElPaperQuAnswerById" parameterType="Long" resultMap="TElPaperQuAnswerResult">
        <include refid="selectTElPaperQuAnswerVo"/>
        where id = #{id}
    </select>

    <insert id="insertTElPaperQuAnswer" parameterType="TElPaperQuAnswer">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_el_paper_qu_answer.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_el_paper_qu_answer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="paperId != null">paper_id,</if>
            <if test="quId != null">qu_id,</if>
            <if test="answerId != null">answer_id,</if>
            <if test="isRight != null">is_right,</if>
            <if test="checked != null">checked,</if>
            <if test="sort != null">sort,</if>
            <if test="abc != null">abc,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="paperId != null">#{paperId},</if>
            <if test="quId != null">#{quId},</if>
            <if test="answerId != null">#{answerId},</if>
            <if test="isRight != null">#{isRight},</if>
            <if test="checked != null">#{checked},</if>
            <if test="sort != null">#{sort},</if>
            <if test="abc != null">#{abc},</if>
         </trim>
    </insert>

    <update id="updateTElPaperQuAnswer" parameterType="TElPaperQuAnswer">
        update t_el_paper_qu_answer
        <trim prefix="SET" suffixOverrides=",">
            <if test="paperId != null">paper_id = #{paperId},</if>
            <if test="quId != null">qu_id = #{quId},</if>
            <if test="answerId != null">answer_id = #{answerId},</if>
            <if test="isRight != null">is_right = #{isRight},</if>
            <if test="checked != null">checked = #{checked},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="abc != null">abc = #{abc},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTElPaperQuAnswerById" parameterType="Long">
        delete from t_el_paper_qu_answer  where id = #{id}
    </delete>

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

</mapper>
