<?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.abuwx.mapper.exam.ExmQuestionMapper">
    
    <resultMap type="ExmQuestion" id="ExmQuestionResult">
        <result property="id"    column="ID"    />
        <result property="type"    column="TYPE"    />
        <result property="title"    column="TITLE"    />
        <result property="markType"    column="MARK_TYPE"    />
        <result property="markOptions"    column="MARK_OPTIONS"    />
        <result property="analysis"    column="ANALYSIS"    />
        <result property="score"    column="SCORE"    />
        <result property="state"    column="STATE"    />
        <result property="questionTypeId"    column="QUESTION_TYPE_ID"    />
        <result property="createUserId"    column="CREATE_USER_ID"    />
        <result property="updateUserId"    column="UPDATE_USER_ID"    />
        <result property="updateTime"    column="UPDATE_TIME"    />
    </resultMap>

    <sql id="selectExmQuestionVo">
        select ID, TYPE, TITLE, MARK_TYPE, MARK_OPTIONS, ANALYSIS, SCORE, STATE, QUESTION_TYPE_ID, CREATE_USER_ID, UPDATE_USER_ID, UPDATE_TIME from exm_question
    </sql>

    <select id="selectExmQuestionList" parameterType="ExmQuestion" resultMap="ExmQuestionResult">
        <include refid="selectExmQuestionVo"/>
        <where>  
            <if test="type != null "> and TYPE = #{type}</if>
            <if test="title != null  and title != ''"> and TITLE = #{title}</if>
            <if test="markType != null "> and MARK_TYPE = #{markType}</if>
            <if test="markOptions != null  and markOptions != ''"> and MARK_OPTIONS = #{markOptions}</if>
            <if test="analysis != null  and analysis != ''"> and ANALYSIS = #{analysis}</if>
            <if test="score != null "> and SCORE = #{score}</if>
            <if test="state != null "> and STATE = #{state}</if>
            <if test="questionTypeId != null "> and QUESTION_TYPE_ID = #{questionTypeId}</if>
            <if test="createUserId != null "> and CREATE_USER_ID = #{createUserId}</if>
            <if test="updateUserId != null "> and UPDATE_USER_ID = #{updateUserId}</if>
            <if test="updateTime != null "> and UPDATE_TIME = #{updateTime}</if>
        </where>
    </select>
    
    <select id="selectExmQuestionById" parameterType="Long" resultMap="ExmQuestionResult">
        <include refid="selectExmQuestionVo"/>
        where ID = #{id}
    </select>
        
    <insert id="insertExmQuestion" parameterType="ExmQuestion" useGeneratedKeys="true" keyProperty="id">
        insert into exm_question
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null">TYPE,</if>
            <if test="title != null">TITLE,</if>
            <if test="markType != null">MARK_TYPE,</if>
            <if test="markOptions != null">MARK_OPTIONS,</if>
            <if test="analysis != null">ANALYSIS,</if>
            <if test="score != null">SCORE,</if>
            <if test="state != null">STATE,</if>
            <if test="questionTypeId != null">QUESTION_TYPE_ID,</if>
            <if test="createUserId != null">CREATE_USER_ID,</if>
            <if test="updateUserId != null">UPDATE_USER_ID,</if>
            <if test="updateTime != null">UPDATE_TIME,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null">#{type},</if>
            <if test="title != null">#{title},</if>
            <if test="markType != null">#{markType},</if>
            <if test="markOptions != null">#{markOptions},</if>
            <if test="analysis != null">#{analysis},</if>
            <if test="score != null">#{score},</if>
            <if test="state != null">#{state},</if>
            <if test="questionTypeId != null">#{questionTypeId},</if>
            <if test="createUserId != null">#{createUserId},</if>
            <if test="updateUserId != null">#{updateUserId},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateExmQuestion" parameterType="ExmQuestion">
        update exm_question
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">TYPE = #{type},</if>
            <if test="title != null">TITLE = #{title},</if>
            <if test="markType != null">MARK_TYPE = #{markType},</if>
            <if test="markOptions != null">MARK_OPTIONS = #{markOptions},</if>
            <if test="analysis != null">ANALYSIS = #{analysis},</if>
            <if test="score != null">SCORE = #{score},</if>
            <if test="state != null">STATE = #{state},</if>
            <if test="questionTypeId != null">QUESTION_TYPE_ID = #{questionTypeId},</if>
            <if test="createUserId != null">CREATE_USER_ID = #{createUserId},</if>
            <if test="updateUserId != null">UPDATE_USER_ID = #{updateUserId},</if>
            <if test="updateTime != null">UPDATE_TIME = #{updateTime},</if>
        </trim>
        where ID = #{id}
    </update>

    <delete id="deleteExmQuestionById" parameterType="Long">
        delete from exm_question where ID = #{id}
    </delete>

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