<?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.TTrainCourseTopicMapper">
    
    <resultMap type="TTrainCourseTopic" id="TTrainCourseTopicResult">
        <result property="topicId"    column="topic_id"    />
        <result property="courseId"    column="course_id"    />
        <result property="topicTitle"    column="topic_title"    />
        <result property="topicOption"    column="topic_option"    />
        <result property="answer"    column="answer"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTTrainCourseTopicVo">
        select topic_id, course_id, topic_title, topic_option, answer, create_time from t_train_course_topic
    </sql>

    <select id="selectTTrainCourseTopicList" parameterType="TTrainCourseTopic" resultMap="TTrainCourseTopicResult">
        <include refid="selectTTrainCourseTopicVo"/>
        <where>  
            <if test="courseId != null "> and course_id = #{courseId}</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>
        </where>
    </select>
    <select id="selectCourseTopicList" resultMap="TTrainCourseTopicResult">
                select topic_id, course_id, topic_title, topic_option, answer, create_time from t_train_course_topic
        WHERE course_id = #{courseId}
    </select>
    <select id="selectTTrainCourseTopicById" parameterType="Long" resultMap="TTrainCourseTopicResult">
        <include refid="selectTTrainCourseTopicVo"/>
        where topic_id = #{topicId}
    </select>
        
    <insert id="insertTTrainCourseTopic" parameterType="TTrainCourseTopic">
        insert into t_train_course_topic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="topicId != null">topic_id,</if>
            <if test="courseId != null">course_id,</if>
            <if test="topicTitle != null">topic_title,</if>
            <if test="topicOption != null">topic_option,</if>
            <if test="answer != null">answer,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="topicId != null">#{topicId},</if>
            <if test="courseId != null">#{courseId},</if>
            <if test="topicTitle != null">#{topicTitle},</if>
            <if test="topicOption != null">#{topicOption},</if>
            <if test="answer != null">#{answer},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateTTrainCourseTopic" parameterType="TTrainCourseTopic">
        update t_train_course_topic
        <trim prefix="SET" suffixOverrides=",">
            <if test="courseId != null">course_id = #{courseId},</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="createTime != null">create_time = #{createTime},</if>
        </trim>
        where topic_id = #{topicId}
    </update>

    <delete id="deleteTTrainCourseTopicById" parameterType="Long">
        delete from t_train_course_topic where topic_id = #{topicId}
    </delete>

    <delete id="deleteTTrainCourseTopicByIds" parameterType="String">
        delete from t_train_course_topic where topic_id in 
        <foreach item="topicId" collection="array" open="(" separator="," close=")">
            #{topicId}
        </foreach>
    </delete>
</mapper>