<?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.zehong.system.mapper.TBankSubjectMapper">

    <resultMap type="TBankSubject" id="TBankSubjectResult">
        <result property="subjectId"    column="subject_id"    />
        <result property="bankId"    column="bank_id"    />
        <result property="topicTitle"    column="topic_title"    />
        <result property="topicOption"    column="topic_option"    />
        <result property="answer"    column="answer"    />
        <result property="datetime"    column="datetime"    />
        <result property="topicType"    column="topic_type"    />
    </resultMap>

    <sql id="selectTBankSubjectVo">
        select subject_id, bank_id, topic_title, topic_option, answer, datetime ,topic_type from t_bank_subject
    </sql>

    <select id="selectTBankSubjectList" parameterType="TBankSubject" resultMap="TBankSubjectResult">
        <include refid="selectTBankSubjectVo"/>
        <where>
            <if test="bankId != null "> and bank_id = #{bankId}</if>
<!--            <if test="topicTitle != null  and topicTitle != ''"> and topic_title = #{topicTitle}</if>-->
<!--            <if test="topicOption != null  and topicOption != ''"> and topic_option = #{topicOption}</if>-->
<!--            <if test="answer != null "> and answer = #{answer}</if>-->
<!--            <if test="datetime != null "> and datetime = #{datetime}</if>-->
        </where>
        group by subject_id desc
    </select>

    <select id="selectTBankSubjectById" parameterType="Long" resultMap="TBankSubjectResult">
        <include refid="selectTBankSubjectVo"/>
        where subject_id = #{subjectId}
    </select>

    <insert id="insertTBankSubject" parameterType="TBankSubject" useGeneratedKeys="true" keyProperty="subjectId">
        insert into t_bank_subject
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bankId != null">bank_id,</if>
            <if test="topicTitle != null">topic_title,</if>
            <if test="topicOption != null">topic_option,</if>
            <if test="answer != null">answer,</if>
            <if test="datetime != null">datetime,</if>
            <if test="topicType != null">topic_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bankId != null">#{bankId},</if>
            <if test="topicTitle != null">#{topicTitle},</if>
            <if test="topicOption != null">#{topicOption},</if>
            <if test="answer != null">#{answer},</if>
            <if test="datetime != null">#{datetime},</if>
            <if test="topicType != null">#{topicType},</if>
         </trim>
    </insert>

    <update id="updateTBankSubject" parameterType="TBankSubject">
        update t_bank_subject
        <trim prefix="SET" suffixOverrides=",">
            <if test="bankId != null">bank_id = #{bankId},</if>
            <if test="topicTitle != null">topic_title = #{topicTitle},</if>
            <if test="topicOption != null">topic_option = #{topicOption},</if>
            <if test="answer != null">answer = #{answer},</if>
            <if test="datetime != null">datetime = #{datetime},</if>
            <if test="topicType != null">topic_type = #{topicType},</if>
        </trim>
        where subject_id = #{subjectId}
    </update>

    <delete id="deleteTBankSubjectById" parameterType="Long">
        delete from t_bank_subject where subject_id = #{subjectId}
    </delete>

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

    <!--excel导入-->
    <insert id="insertBank">
        insert into t_bank_subject (bank_id,topic_title,topic_option,answer,datetime,topic_type)
        values
        <foreach collection="list" item="item" index= "index" separator =",">
        ( #{item.bankId},#{item.topicTitle},#{item.topicOption},#{item.answer},#{item.datetime},#{item.topicType})
        </foreach>
    </insert>

</mapper>