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

    <resultMap type="FsDoctorArticle" id="FsDoctorArticleResult">
        <result property="articleId"    column="article_id"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="cateId"    column="cate_id"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="views"    column="views"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="videoUrl"    column="video_url"    />
    </resultMap>

    <sql id="selectFsDoctorArticleVo">
        select article_id, image_url, cate_id, title, content, views, status, create_time, update_time,video_url from fs_doctor_article
    </sql>

    <select id="selectFsDoctorArticleList" parameterType="FsDoctorArticle" resultMap="FsDoctorArticleResult">
        <include refid="selectFsDoctorArticleVo"/>
        <where>
            <if test="imageUrl != null  and imageUrl != ''"> and image_url = #{imageUrl}</if>
            <if test="cateId != null "> and cate_id = #{cateId}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="views != null "> and views = #{views}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectFsDoctorArticleByArticleId" parameterType="Long" resultMap="FsDoctorArticleResult">
        <include refid="selectFsDoctorArticleVo"/>
        where article_id = #{articleId}
    </select>

    <insert id="insertFsDoctorArticle" parameterType="FsDoctorArticle" useGeneratedKeys="true" keyProperty="articleId">
        insert into fs_doctor_article
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="imageUrl != null">image_url,</if>
            <if test="cateId != null">cate_id,</if>
            <if test="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="views != null">views,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="videoUrl  != null">video_url,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="imageUrl != null">#{imageUrl},</if>
            <if test="cateId != null">#{cateId},</if>
            <if test="title != null">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="views != null">#{views},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="videoUrl != null">#{videoUrl},</if>
         </trim>
    </insert>

    <update id="updateFsDoctorArticle" parameterType="FsDoctorArticle">
        update fs_doctor_article
        <trim prefix="SET" suffixOverrides=",">
            <if test="imageUrl != null">image_url = #{imageUrl},</if>
            <if test="cateId != null">cate_id = #{cateId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="views != null">views = #{views},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="videoUrl != null">video_url = #{videoUrl},</if>
        </trim>
        where article_id = #{articleId}
    </update>

    <delete id="deleteFsDoctorArticleByArticleId" parameterType="Long">
        delete from fs_doctor_article where article_id = #{articleId}
    </delete>

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