<?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.FsArticleViewsMapper">

    <resultMap type="FsArticleViews" id="FsArticleViewsResult">
        <result property="viewId"    column="view_id"    />
        <result property="articleId"    column="article_id"    />
        <result property="userId"    column="user_id"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectFsArticleViewsVo">
        select view_id, article_id, user_id from fs_article_views
    </sql>

    <select id="selectFsArticleViewsList" parameterType="FsArticleViews" resultMap="FsArticleViewsResult">
        <include refid="selectFsArticleViewsVo"/>
        <where>
            <if test="articleId != null "> and article_id = #{articleId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
    </select>

    <select id="selectFsArticleViewsById" parameterType="Long" resultMap="FsArticleViewsResult">
        <include refid="selectFsArticleViewsVo"/>
        where view_id = #{viewId}
    </select>

    <insert id="insertFsArticleViews" parameterType="FsArticleViews" useGeneratedKeys="true" keyProperty="viewId">
        insert into fs_article_views
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="articleId != null">article_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="articleId != null">#{articleId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateFsArticleViews" parameterType="FsArticleViews">
        update fs_article_views
        <trim prefix="SET" suffixOverrides=",">
            <if test="articleId != null">article_id = #{articleId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where view_id = #{viewId}
    </update>

    <delete id="deleteFsArticleViewsById" parameterType="Long">
        delete from fs_article_views where view_id = #{viewId}
    </delete>

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

</mapper>
