<?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.system.mapper.TdQuestionMapper">
    
    <resultMap type="TdQuestion" id="TdQuestionResult">
        <result property="ID"    column="ID"    />
        <result property="TYPEID"    column="TYPEID"    />
        <result property="qSubject"    column="Q_SUBJECT"    />
        <result property="OPTIONA"    column="OPTIONA"    />
        <result property="OPTIONB"    column="OPTIONB"    />
        <result property="OPTIONC"    column="OPTIONC"    />
        <result property="OPTIOND"    column="OPTIOND"    />
        <result property="NOTE"    column="NOTE"    />
        <result property="CREATEPERSON"    column="CREATEPERSON"    />
        <result property="CREATEDATE"    column="CREATEDATE"    />
    </resultMap>

    <sql id="selectTdQuestionVo">
        select ID, TYPEID, Q_SUBJECT, OPTIONA, OPTIONB, OPTIONC, OPTIOND, NOTE, CREATEPERSON, CREATEDATE from td_question
    </sql>

    <select id="selectTdQuestionList" parameterType="TdQuestion" resultMap="TdQuestionResult">
        <include refid="selectTdQuestionVo"/>
        <where>  
            <if test="TYPEID != null "> and TYPEID = #{TYPEID}</if>
            <if test="qSubject != null  and qSubject != ''"> and Q_SUBJECT like concat('%', #{qSubject}, '%')</if>
            <if test="OPTIONA != null  and OPTIONA != ''"> and OPTIONA = #{OPTIONA}</if>
            <if test="OPTIONB != null  and OPTIONB != ''"> and OPTIONB = #{OPTIONB}</if>
            <if test="OPTIONC != null  and OPTIONC != ''"> and OPTIONC = #{OPTIONC}</if>
            <if test="OPTIOND != null  and OPTIOND != ''"> and OPTIOND = #{OPTIOND}</if>
            <if test="NOTE != null  and NOTE != ''"> and NOTE = #{NOTE}</if>
            <if test="CREATEPERSON != null  and CREATEPERSON != ''"> and CREATEPERSON = #{CREATEPERSON}</if>
            <if test="CREATEDATE != null "> and CREATEDATE = #{CREATEDATE}</if>
        </where>
    </select>
    
    <select id="selectTdQuestionByID" parameterType="Long" resultMap="TdQuestionResult">
        <include refid="selectTdQuestionVo"/>
        where ID = #{ID}
    </select>
        
    <insert id="insertTdQuestion" parameterType="TdQuestion" useGeneratedKeys="true" keyProperty="ID">
        insert into td_question
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="TYPEID != null">TYPEID,</if>
            <if test="qSubject != null">Q_SUBJECT,</if>
            <if test="OPTIONA != null">OPTIONA,</if>
            <if test="OPTIONB != null">OPTIONB,</if>
            <if test="OPTIONC != null">OPTIONC,</if>
            <if test="OPTIOND != null">OPTIOND,</if>
            <if test="NOTE != null">NOTE,</if>
            <if test="CREATEPERSON != null">CREATEPERSON,</if>
            <if test="CREATEDATE != null">CREATEDATE,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="TYPEID != null">#{TYPEID},</if>
            <if test="qSubject != null">#{qSubject},</if>
            <if test="OPTIONA != null">#{OPTIONA},</if>
            <if test="OPTIONB != null">#{OPTIONB},</if>
            <if test="OPTIONC != null">#{OPTIONC},</if>
            <if test="OPTIOND != null">#{OPTIOND},</if>
            <if test="NOTE != null">#{NOTE},</if>
            <if test="CREATEPERSON != null">#{CREATEPERSON},</if>
            <if test="CREATEDATE != null">#{CREATEDATE},</if>
         </trim>
    </insert>

    <update id="updateTdQuestion" parameterType="TdQuestion">
        update td_question
        <trim prefix="SET" suffixOverrides=",">
            <if test="TYPEID != null">TYPEID = #{TYPEID},</if>
            <if test="qSubject != null">Q_SUBJECT = #{qSubject},</if>
            <if test="OPTIONA != null">OPTIONA = #{OPTIONA},</if>
            <if test="OPTIONB != null">OPTIONB = #{OPTIONB},</if>
            <if test="OPTIONC != null">OPTIONC = #{OPTIONC},</if>
            <if test="OPTIOND != null">OPTIOND = #{OPTIOND},</if>
            <if test="NOTE != null">NOTE = #{NOTE},</if>
            <if test="CREATEPERSON != null">CREATEPERSON = #{CREATEPERSON},</if>
            <if test="CREATEDATE != null">CREATEDATE = #{CREATEDATE},</if>
        </trim>
        where ID = #{ID}
    </update>

    <delete id="deleteTdQuestionByID" parameterType="Long">
        delete from td_question where ID = #{ID}
    </delete>

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

</mapper>