<?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.FsArticleMapper">
    
    <resultMap type="FsArticle" id="FsArticleResult">
        <result property="articleId"    column="article_id"    />
        <result property="cateId"    column="cate_id"    />
        <result property="title"    column="title"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="isTui"    column="is_tui"    />
        <result property="isNews"    column="is_news"    />
        <result property="contents"    column="contents"    />
        <result property="views"    column="views"    />
        <result property="sort"    column="sort"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="publishTime"    column="publish_time"    />
    </resultMap>

    <sql id="selectFsArticleVo">
        select article_id, cate_id, title, image_url, is_tui, is_news, contents, views, sort, create_time, update_time, publish_time from fs_article
    </sql>

    <select id="selectFsArticleList" parameterType="FsArticle" resultMap="FsArticleResult">
        <include refid="selectFsArticleVo"/>
        <where>  
            <if test="cateId != null "> and cate_id = #{cateId}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="imageUrl != null  and imageUrl != ''"> and image_url = #{imageUrl}</if>
            <if test="isTui != null "> and is_tui = #{isTui}</if>
            <if test="isNews != null "> and is_news = #{isNews}</if>
            <if test="contents != null  and contents != ''"> and contents = #{contents}</if>
            <if test="views != null "> and views = #{views}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="publishTime != null "> and publish_time = #{publishTime}</if>
        </where>
    </select>
    
    <select id="selectFsArticleById" parameterType="Integer" resultMap="FsArticleResult">
        <include refid="selectFsArticleVo"/>
        where article_id = #{articleId}
    </select>
        
    <insert id="insertFsArticle" parameterType="FsArticle" useGeneratedKeys="true" keyProperty="articleId">
        insert into fs_article
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cateId != null">cate_id,</if>
            <if test="title != null">title,</if>
            <if test="imageUrl != null">image_url,</if>
            <if test="isTui != null">is_tui,</if>
            <if test="isNews != null">is_news,</if>
            <if test="contents != null">contents,</if>
            <if test="views != null">views,</if>
            <if test="sort != null">sort,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="publishTime != null">publish_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cateId != null">#{cateId},</if>
            <if test="title != null">#{title},</if>
            <if test="imageUrl != null">#{imageUrl},</if>
            <if test="isTui != null">#{isTui},</if>
            <if test="isNews != null">#{isNews},</if>
            <if test="contents != null">#{contents},</if>
            <if test="views != null">#{views},</if>
            <if test="sort != null">#{sort},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="publishTime != null">#{publishTime},</if>
         </trim>
    </insert>

    <update id="updateFsArticle" parameterType="FsArticle">
        update fs_article
        <trim prefix="SET" suffixOverrides=",">
            <if test="cateId != null">cate_id = #{cateId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="imageUrl != null">image_url = #{imageUrl},</if>
            <if test="isTui != null">is_tui = #{isTui},</if>
            <if test="isNews != null">is_news = #{isNews},</if>
            <if test="contents != null">contents = #{contents},</if>
            <if test="views != null">views = #{views},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="publishTime != null">publish_time = #{publishTime},</if>
        </trim>
        where article_id = #{articleId}
    </update>

    <delete id="deleteFsArticleById" parameterType="Integer">
        delete from fs_article where article_id = #{articleId}
    </delete>

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