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

    <resultMap type="TElQuAnswer" id="TElQuAnswerResult">
        <result property="answerId"    column="answer_id"    />
        <result property="quId"    column="qu_id"    />
        <result property="isRight"    column="is_right"    />
        <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="selectTElQuAnswerVo">
        select d.answer_id, d.qu_id, d.is_right, d.content, d.image, d.analysis, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_el_qu_answer d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTElQuAnswerList" parameterType="TElQuAnswer" resultMap="TElQuAnswerResult">
        <include refid="selectTElQuAnswerVo"/>
        <where>
            <if test="isRight != null "> and is_right = #{isRight}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="analysis != null  and analysis != ''"> and analysis = #{analysis}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="quId != null  and quId != ''"> and qu_id = #{quId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTElQuAnswerById" parameterType="Long" resultMap="TElQuAnswerResult">
        <include refid="selectTElQuAnswerVo"/>
        where answer_id = #{answerId}
    </select>

    <insert id="insertTElQuAnswer" parameterType="TElQuAnswer">
        <selectKey keyProperty="answerId" resultType="long" order="BEFORE">
            SELECT seq_t_el_qu_answer.NEXTVAL as answerId FROM DUAL
        </selectKey>
        insert into t_el_qu_answer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="answerId != null">answer_id,</if>
            <if test="quId != null">qu_id,</if>
            <if test="isRight != null">is_right,</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="answerId != null">#{answerId},</if>
            <if test="quId != null">#{quId},</if>
            <if test="isRight != null">#{isRight},</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="updateTElQuAnswer" parameterType="TElQuAnswer">
        update t_el_qu_answer
        <trim prefix="SET" suffixOverrides=",">
            <if test="quId != null">qu_id = #{quId},</if>
            <if test="isRight != null">is_right = #{isRight},</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 answer_id = #{answerId}
    </update>

    <update id="deleteTElQuAnswerById" parameterType="Long">
        update t_el_qu_answer set del_flag = 2 where answer_id = #{answerId}
    </update>

    <update id="deleteTElQuAnswerByIds" parameterType="String">
        update t_el_qu_answer set del_flag = 2 where answer_id in
        <foreach item="answerId" collection="array" open="(" separator="," close=")">
            #{answerId}
        </foreach>
    </update>

</mapper>
