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

    <resultMap type="FsHomeArticleCategory" id="FsHomeArticleCategoryResult">
        <result property="categoryId"    column="category_id"    />
        <result property="categoryName"    column="category_name"    />
        <result property="status"    column="status"    />
        <result property="isDel"    column="is_del"    />
        <result property="sort"    column="sort"    />
    </resultMap>

    <sql id="selectFsHomeArticleCategoryVo">
        select category_id, category_name, status, is_del, sort, image_url from fs_home_article_category
    </sql>

    <select id="selectFsHomeArticleCategoryList" parameterType="FsHomeArticleCategory" resultMap="FsHomeArticleCategoryResult">
        <include refid="selectFsHomeArticleCategoryVo"/>
        <where>
            and is_del = 0
            <if test="categoryName != null  and categoryName != ''"> and category_name like concat('%', #{categoryName}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="sort != null "> and sort = #{sort}</if>
        </where>
        order by sort
    </select>

    <select id="selectFsHomeArticleCategoryById" parameterType="Long" resultMap="FsHomeArticleCategoryResult">
        <include refid="selectFsHomeArticleCategoryVo"/>
        where category_id = #{categoryId}
    </select>

    <insert id="insertFsHomeArticleCategory" parameterType="FsHomeArticleCategory" useGeneratedKeys="true" keyProperty="categoryId">
        insert into fs_home_article_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="categoryName != null and categoryName != ''">category_name,</if>
            <if test="imageUrl != null">image_url,</if>
            <if test="status != null">status,</if>
            <if test="isDel != null">is_del,</if>
            <if test="sort != null">sort,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="categoryName != null and categoryName != ''">#{categoryName},</if>
            <if test="imageUrl != null">#{imageUrl},</if>
            <if test="status != null">#{status},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="sort != null">#{sort},</if>
         </trim>
    </insert>

    <update id="updateFsHomeArticleCategory" parameterType="FsHomeArticleCategory">
        update fs_home_article_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="categoryName != null and categoryName != ''">category_name = #{categoryName},</if>
            <if test="imageUrl != null">image_url = #{imageUrl},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="sort != null">sort = #{sort},</if>
        </trim>
        where category_id = #{categoryId}
    </update>

    <delete id="deleteFsHomeArticleCategoryById" parameterType="Long">
        delete from fs_home_article_category where category_id = #{categoryId}
    </delete>

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

    <select id="selectHomeArticleCategoryPageList" resultType="HomeArticleCategoryListVO">
        select category_id, category_name, status,image_url from fs_home_article_category
        <where>
            is_del = 0 and status = 1
            <if test="keywords != null  and keywords != ''"> and category_name like concat('%', #{keywords}, '%')</if>
        </where>
        order by sort asc
    </select>

</mapper>
