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

    <resultMap type="FsMenu" id="FsMenuResult">
        <result property="menuId"    column="menu_id"    />
        <result property="menuName"    column="menu_name"    />
        <result property="icon"    column="icon"    />
        <result property="isShow"    column="is_show"    />
        <result property="linkType"    column="link_type"    />
        <result property="linkUrl"    column="link_url"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="sort"    column="sort"    />
        <result property="menuType"    column="menu_type"    />
    </resultMap>

    <sql id="selectFsMenuVo">
        select menu_id, menu_name,menu_type, icon, is_show,link_type,link_url, create_time, update_time,sort from fs_menu
    </sql>

    <select id="selectFsMenuList" parameterType="FsMenu" resultMap="FsMenuResult">
        <include refid="selectFsMenuVo"/>
        <where>
            <if test="menuName != null  and menuName != ''"> and menu_name like concat('%', #{menuName}, '%')</if>
            <if test="icon != null  and icon != ''"> and icon = #{icon}</if>
            <if test="isShow != null "> and is_show = #{isShow}</if>
            <if test="linkType != null "> and link_type = #{linkType}</if>
            <if test="linkUrl != null "> and link_url = #{linkUrl}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="menuType != null "> and menu_type = #{menuType}</if>
        </where>
        order by sort asc
    </select>

    <select id="selectFsMenuById" parameterType="Long" resultMap="FsMenuResult">
        <include refid="selectFsMenuVo"/>
        where menu_id = #{menuId}
    </select>

    <insert id="insertFsMenu" parameterType="FsMenu" useGeneratedKeys="true" keyProperty="menuId">
        insert into fs_menu
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="menuName != null">menu_name,</if>
            <if test="icon != null">icon,</if>
            <if test="isShow != null">is_show,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="linkType != null">link_type,</if>
            <if test="linkUrl != null">link_url,</if>
            <if test="sort != null">sort,</if>
            <if test="menuType != null">menu_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="menuName != null">#{menuName},</if>
            <if test="icon != null">#{icon},</if>
            <if test="isShow != null">#{isShow},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="linkType != null">#{linkType},</if>
            <if test="linkUrl != null">#{linkUrl},</if>
            <if test="sort != null">#{sort},</if>
            <if test="menuType != null">#{menuType},</if>
         </trim>
    </insert>

    <update id="updateFsMenu" parameterType="FsMenu">
        update fs_menu
        <trim prefix="SET" suffixOverrides=",">
            <if test="menuName != null">menu_name = #{menuName},</if>
            <if test="icon != null">icon = #{icon},</if>
            <if test="isShow != null">is_show = #{isShow},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="linkType != null">link_type = #{linkType},</if>
            <if test="linkUrl != null">link_url = #{linkUrl},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="menuType != null">menu_type = #{menuType},</if>
        </trim>
        where menu_id = #{menuId}
    </update>

    <delete id="deleteFsMenuById" parameterType="Long">
        delete from fs_menu where menu_id = #{menuId}
    </delete>

    <delete id="deleteFsMenuByIds" parameterType="String">
        delete from fs_menu where menu_id in
        <foreach item="menuId" collection="array" open="(" separator="," close=")">
            #{menuId}
        </foreach>
    </delete>

</mapper>
