<?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.store.mapper.FsQuestionsMapper">

    <resultMap type="FsQuestions" id="FsQuestionsResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="sort"    column="sort"    />
        <result property="answers"    column="answers"    />
        <result property="tags"    column="tags"    />
        <result property="createTime"    column="create_time"    />
        <result property="status"    column="status"    />
        <result property="views"    column="views"    />
        <result property="questionsType"    column="questions_type"    />
        <result property="deptId"    column="dept_id"    />
    </resultMap>

    <sql id="selectFsQuestionsVo">
        select id,views,questions_type,dept_id, title, sort, answers, tags, create_time, status from fs_questions
    </sql>

    <select id="selectFsQuestionsList" parameterType="FsQuestions" resultMap="FsQuestionsResult">
        <include refid="selectFsQuestionsVo"/>
        <where>
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%')</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="answers != null  and answers != ''"> and answers = #{answers}</if>
            <if test="tags != null  and tags != ''"> and tags = #{tags}</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
        order by sort,id desc
    </select>

    <select id="selectFsQuestionsById" parameterType="Long" resultMap="FsQuestionsResult">
        <include refid="selectFsQuestionsVo"/>
        where id = #{id}
    </select>

    <insert id="insertFsQuestions" parameterType="FsQuestions" useGeneratedKeys="true" keyProperty="id">
        insert into fs_questions
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">title,</if>
            <if test="sort != null">sort,</if>
            <if test="answers != null">answers,</if>
            <if test="tags != null">tags,</if>
            <if test="createTime != null">create_time,</if>
            <if test="status != null">status,</if>
            <if test="views != null">views,</if>
            <if test="questionsType != null">questions_type,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">#{title},</if>
            <if test="sort != null">#{sort},</if>
            <if test="answers != null">#{answers},</if>
            <if test="tags != null">#{tags},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null">#{status},</if>
            <if test="views != null">#{views},</if>
            <if test="questionsType != null">#{questionsType},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateFsQuestions" parameterType="FsQuestions">
        update fs_questions
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="answers != null">answers = #{answers},</if>
            <if test="tags != null">tags = #{tags},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="views != null">views = #{views},</if>
            <if test="questionsType != null">questions_type = #{questionsType},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsQuestionsById" parameterType="Long">
        delete from fs_questions where id = #{id}
    </delete>

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