<?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.kexue.skills.mapper.SysMenuMapper">

    <resultMap type="com.kexue.skills.entity.SysMenu" id="SysMenuMap">
        <result property="menuId" column="menu_id" jdbcType="INTEGER"/>
        <result property="menuPid" column="menu_pid" jdbcType="INTEGER"/>
        <result property="menuName" column="menu_name" jdbcType="VARCHAR"/>
        <result property="menuSrc" column="menu_src" jdbcType="VARCHAR"/>
        <result property="menuIcon" column="menu_icon" jdbcType="VARCHAR"/>
        <result property="menuStyle" column="menu_style" jdbcType="VARCHAR"/>
        <result property="sort" column="sort" jdbcType="INTEGER"/>
        <result property="note" column="note" jdbcType="VARCHAR"/>
        <result property="deleteFlag" column="delete_flag" jdbcType="OTHER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="SysMenuMap">
        select
          menu_id, menu_pid, menu_name, menu_src, menu_icon, menu_style, sort, note, delete_flag
        from sys_menu
        where menu_id = #{menuId}
    </select>

    <!--查询指定行数据-->
    <select id="getPageList" resultMap="SysMenuMap">
        select
          menu_id, menu_pid, menu_name, menu_src, menu_icon, menu_style, sort, note, delete_flag
        from sys_menu
        <where>
            <if test="menuId != null">
                and menu_id = #{menuId}
            </if>
            <if test="menuPid != null">
                and menu_pid = #{menuPid}
            </if>
            <if test="menuName != null and menuName != ''">
                and menu_name = #{menuName}
            </if>
            <if test="menuSrc != null and menuSrc != ''">
                and menu_src = #{menuSrc}
            </if>
            <if test="menuIcon != null and menuIcon != ''">
                and menu_icon = #{menuIcon}
            </if>
            <if test="menuStyle != null and menuStyle != ''">
                and menu_style = #{menuStyle}
            </if>
            <if test="sort != null">
                and sort = #{sort}
            </if>
            <if test="note != null and note != ''">
                and note = #{note}
            </if>
            <if test="deleteFlag != null">
                and delete_flag = #{deleteFlag}
            </if>
        </where>
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="SysMenuMap">
        select
          menu_id, menu_pid, menu_name, menu_src, menu_icon, menu_style, sort, note, delete_flag
        from sys_menu
        limit #{offset}, #{limit}
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultMap="SysMenuMap">
        select
          menu_id, menu_pid, menu_name, menu_src, menu_icon, menu_style, sort, note, delete_flag
        from sys_menu
        <where>
            <if test="menuId != null">
                and menu_id = #{menuId}
            </if>
            <if test="menuPid != null">
                and menu_pid = #{menuPid}
            </if>
            <if test="menuName != null and menuName != ''">
                and menu_name = #{menuName}
            </if>
            <if test="menuSrc != null and menuSrc != ''">
                and menu_src = #{menuSrc}
            </if>
            <if test="menuIcon != null and menuIcon != ''">
                and menu_icon = #{menuIcon}
            </if>
            <if test="menuStyle != null and menuStyle != ''">
                and menu_style = #{menuStyle}
            </if>
            <if test="sort != null">
                and sort = #{sort}
            </if>
            <if test="note != null and note != ''">
                and note = #{note}
            </if>
            <if test="deleteFlag != null">
                and delete_flag = #{deleteFlag}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="menuId" useGeneratedKeys="true">
        insert into sys_menu(menu_pid, menu_name, menu_src, menu_icon, menu_style, sort, note, delete_flag)
        values (#{menuPid}, #{menuName}, #{menuSrc}, #{menuIcon}, #{menuStyle}, #{sort}, #{note}, #{deleteFlag})
    </insert>
    
    
    <insert id="insertBatch" parameterType="java.util.List">
    INSERT INTO sys_menu (
        <!-- 动态生成列名 -->
        <foreach collection="list" item="item" index="index" open="" close="" separator="" >
            <if test="index == 0">
                <foreach collection="tableInfo.fullColumn" item="column" open="" close="" separator=",">
                    ${column.name}
                </foreach>
            </if>
        </foreach>
    ) VALUES
    <!-- 动态生成值 -->
    <foreach collection="list" item="item" index="index" open="" close="" separator=",">
        (
        <foreach collection="tableInfo.fullColumn" item="column" open="" close="" separator=",">
            #{item.${column.property}}
        </foreach>
        )
    </foreach>
</insert>

    <!--通过主键修改数据-->
    <update id="update">
        update sys_menu
        <set>
            <if test="menuPid != null">
                menu_pid = #{menuPid},
            </if>
            <if test="menuName != null and menuName != ''">
                menu_name = #{menuName},
            </if>
            <if test="menuSrc != null and menuSrc != ''">
                menu_src = #{menuSrc},
            </if>
            <if test="menuIcon != null and menuIcon != ''">
                menu_icon = #{menuIcon},
            </if>
            <if test="menuStyle != null and menuStyle != ''">
                menu_style = #{menuStyle},
            </if>
            <if test="sort != null">
                sort = #{sort},
            </if>
            <if test="note != null and note != ''">
                note = #{note},
            </if>
            <if test="deleteFlag != null">
                delete_flag = #{deleteFlag},
            </if>
        </set>
        where menu_id = #{menuId}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from sys_menu where menu_id = #{menuId}
    </delete>

</mapper>
