<?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.fs.course.mapper.FsCourseQuestionBankMapper">

    <resultMap type="FsCourseQuestionBank" id="FsCourseQuestionBankResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="sort"    column="sort"    />
        <result property="type"    column="type"    />
        <result property="status"    column="status"    />
        <result property="question"    column="question"    />
        <result property="createTime"    column="create_time"    />
        <result property="answer"    column="answer"    />
        <result property="createBy"    column="create_by"    />
        <result property="questionType"    column="question_type"    />
    </resultMap>

    <sql id="selectFsCourseQuestionBankVo">
        select id, title, sort, type, status,question_type, question, create_time, answer, create_by from fs_course_question_bank
    </sql>

    <select id="selectFsCourseQuestionBankList" parameterType="FsCourseQuestionBank" resultMap="FsCourseQuestionBankResult">
        <include refid="selectFsCourseQuestionBankVo"/>
        <where>
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%') </if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="questionType != null "> and question_type = #{questionType}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="question != null  and question != ''"> and question = #{question}</if>
            <if test="answer != null  and answer != ''"> and answer = #{answer}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectFsCourseQuestionBankById" parameterType="Long" resultMap="FsCourseQuestionBankResult">
        <include refid="selectFsCourseQuestionBankVo"/>
        where id = #{id}
    </select>

    <insert id="insertFsCourseQuestionBank" parameterType="FsCourseQuestionBank" useGeneratedKeys="true" keyProperty="id">
        insert into fs_course_question_bank
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="sort != null">sort,</if>
            <if test="type != null">type,</if>
            <if test="status != null">status,</if>
            <if test="question != null">question,</if>
            <if test="createTime != null">create_time,</if>
            <if test="answer != null">answer,</if>
            <if test="createBy != null">create_by,</if>
            <if test="questionType != null">question_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},</if>
            <if test="sort != null">#{sort},</if>
            <if test="type != null">#{type},</if>
            <if test="status != null">#{status},</if>
            <if test="question != null">#{question},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="answer != null">#{answer},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="questionType != null">#{questionType},</if>
         </trim>
    </insert>

    <update id="updateFsCourseQuestionBank" parameterType="FsCourseQuestionBank">
        update fs_course_question_bank
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="type != null">type = #{type},</if>
            <if test="status != null">status = #{status},</if>
            <if test="question != null">question = #{question},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="answer != null">answer = #{answer},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="questionType != null">question_type = #{questionType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsCourseQuestionBankById" parameterType="Long">
        delete from fs_course_question_bank where id = #{id}
    </delete>

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

    <select id="selectFsCourseQuestionBankByIds" resultType="FsCourseQuestionBank">
        SELECT *
        FROM fs_course_question_bank
        WHERE id IN
        <foreach collection="list" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
</mapper>
