<?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.model.mapper.AnswerMapper">
    
    <resultMap type="Answer" id="AnswerResult">
        <result property="answerId"    column="answer_id"    />
        <result property="answerCorrect"    column="answer_correct"    />
        <result property="answerExaminationId"    column="answer_examination_id"    />
        <result property="answerRed"    column="answer_red"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="reamk"    column="reamk"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAnswerVo">
        select answer_id, answer_correct, answer_examination_id, answer_red, create_by, create_time, del_flag, reamk, update_by, update_time from answer
    </sql>

    <select id="selectAnswerList" parameterType="Answer" resultMap="AnswerResult">
        <include refid="selectAnswerVo"/>
        <where>  
            <if test="answerCorrect != null "> and answer_correct = #{answerCorrect}</if>
            <if test="answerExaminationId != null "> and answer_examination_id = #{answerExaminationId}</if>
            <if test="answerRed != null  and answerRed != ''"> and answer_red = #{answerRed}</if>
            <if test="reamk != null  and reamk != ''"> and reamk = #{reamk}</if>
        </where>
    </select>
    
    <select id="selectAnswerByAnswerId" parameterType="Long" resultMap="AnswerResult">
        <include refid="selectAnswerVo"/>
        where answer_id = #{answerId}
    </select>

    <insert id="insertAnswer" parameterType="Answer">
        insert into answer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="answerId != null">answer_id,</if>
            <if test="answerCorrect != null">answer_correct,</if>
            <if test="answerExaminationId != null">answer_examination_id,</if>
            <if test="answerRed != null">answer_red,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="reamk != null">reamk,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="answerId != null">#{answerId},</if>
            <if test="answerCorrect != null">#{answerCorrect},</if>
            <if test="answerExaminationId != null">#{answerExaminationId},</if>
            <if test="answerRed != null">#{answerRed},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="reamk != null">#{reamk},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateAnswer" parameterType="Answer">
        update answer
        <trim prefix="SET" suffixOverrides=",">
            <if test="answerCorrect != null">answer_correct = #{answerCorrect},</if>
            <if test="answerExaminationId != null">answer_examination_id = #{answerExaminationId},</if>
            <if test="answerRed != null">answer_red = #{answerRed},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="reamk != null">reamk = #{reamk},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where answer_id = #{answerId}
    </update>

    <delete id="deleteAnswerByAnswerId" parameterType="Long">
        delete from answer where answer_id = #{answerId}
    </delete>

    <delete id="deleteAnswerByAnswerIds" parameterType="String">
        delete from answer where answer_id in 
        <foreach item="answerId" collection="array" open="(" separator="," close=")">
            #{answerId}
        </foreach>
    </delete>
</mapper>