<?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.securitycontrol.system.mapper.IMenuMapper">
    <!--新增/修改菜单-->
    <insert id="addOrUpdateMenu">
        <if test="type == 1">
            INSERT INTO sys_menu
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="menuName != null and menuName != ''">menu_name,</if>
                <if test="menuUrl != null and menuUrl!=''">menu_url,</if>
                <if test="menuType != null">menu_type,</if>
                <if test="menuAuth != null and menuAuth!=''">menu_auth,</if>
                <if test="parentId != null">p_id,</if>
                <if test="menuSort != null">menu_sort,</if>
                <if test="menuLogo != null and menuLogo!=''">menu_logo,</if>
                <if test="createTime != null and createTime!=''">create_time,</if>
            </trim>
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="menuName != null and menuName != ''">#{menuName},</if>
                <if test="menuUrl != null and menuUrl!=''">#{menuUrl},</if>
                <if test="menuType != null">#{menuType},</if>
                <if test="menuAuth != null and menuAuth!=''">#{menuAuth},</if>
                <if test="parentId != null">#{parentId},</if>
                <if test="menuSort != null">#{menuSort},</if>
                <if test="menuLogo != null and menuLogo!=''">#{menuLogo},</if>
                <if test="createTime != null and createTime!=''">#{createTime},</if>
            </trim>
        </if>
        <if test="type == 2">
            UPDATE sys_menu SET menu_name = #{menuName},menu_url = #{menuUrl},menu_type = #{menuType},
            menu_auth = #{menuAuth},p_id = #{parentId},menu_sort = #{menuSort},menu_logo = #{menuLogo}
            WHERE menu_id = #{menuId}
        </if>
    </insert>
    <!--删除菜单-->
    <delete id="delMenu">
        DELETE FROM sys_menu WHERE menu_id = #{menuId}
    </delete>
    <!--菜单列表-->
    <select id="getMenuList" resultType="com.securitycontrol.entity.system.vo.MenuVo">
        SELECT menu_id AS menuId,
        menu_name AS menuName,
        menu_url AS menuUrl,
        menu_type AS menuType,
        menu_auth AS menuAuth,
        menu_sort AS menuSort,
        menu_logo AS menuLogo,
        create_time AS createTime,
        p_id AS parentId
        FROM sys_menu
        <where>
            <if test="menuName!=null and menuName!=''">
                INSTR(menu_name,#{menuName}) > 0
            </if>
            AND del_flag = 0
        </where>
        ORDER BY menu_sort,create_time
    </select>
    <!--菜单名称是否存在-->
    <select id="isMenuName" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM sys_menu WHERE menu_name = #{menuName} AND p_id = #{parentId} AND del_flag = 0
    </select>
    <!--当前节点是否存在子节点-->
    <select id="isExistChild" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM sys_menu WHERE p_id = #{menuId} AND del_flag = 0
    </select>
    <!--菜单详情-->
    <select id="getMenuById" resultType="com.securitycontrol.entity.system.vo.MenuVo">
        SELECT menu_id AS menuId,
        menu_name AS menuName,
        menu_url AS menuUrl,
        menu_type AS menuType,
        menu_auth AS menuAuth,
        menu_sort AS menuSort,
        menu_logo AS menuLogo,
        create_time AS createTime,
        p_id AS parentId
        FROM sys_menu
        WHERE menu_id = #{menuId}
    </select>
</mapper>