<?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.devplatform.admin.modules.sys.dao.SysMenuDao">

  <select id="queryListParentId" resultType="com.devplatform.admin.modules.sys.bean.SysMenuEntity">
        SELECT *
        FROM sys_menu
        WHERE status = 0 AND parent_id = #{parentId}
        ORDER BY order_num ASC
    </select>

  <select id="queryNotButtonList" resultType="com.devplatform.admin.modules.sys.bean.SysMenuEntity">
        SELECT *
        FROM sys_menu
        WHERE type != 2
        ORDER BY order_num ASC
    </select>

  <!-- 根据角色id获取权限列表-->
  <select id="getRoleMenu" resultType="java.util.HashMap">
    SELECT me.*
    FROM sys_menu me
    LEFT JOIN sys_role_menu srm ON me.menu_id = srm.menu_id
    LEFT JOIN sys_role sr ON srm.role_id = sr.role_id
    WHERE me.status = 0
    AND sr.role_id = #{roleId}
    <if test="stationId != null and stationId != ''">
      AND me.station_id = #{stationId}
    </if>
    -- AND me.type = 2
  </select>
  <select id="getAllMenuListByUserId" resultType="java.util.Map">
    SELECT DISTINCT sm.menu_id AS menuId, sm.parent_id AS parentId, sm.name,sm.name AS title,sm.url, sm.url AS path,
    sm.perms, sm.type, sm.icon, sm.order_num AS orderNum, sm.is_system_menu AS isSystemMenu, sm.status
    FROM sys_menu sm
    LEFT JOIN sys_role_menu srm ON sm.menu_id = srm.menu_id
    LEFT JOIN sys_user_role sur ON srm.role_id = sur.role_id
    LEFT JOIN sys_user su ON sur.user_id = su.user_id
    WHERE sm.status = 0 and sm.type != 2
    <if test="userId != null and userId != ''">
      AND su.user_id = #{userId}
    </if>
    <if test="stationId != null and stationId != ''">
      AND sm.station_Id = #{stationId}
    </if>
    or sm.menu_id = '01'
    ORDER BY sm.order_num
  </select>
  <select id="getAllMenuListByUserId1" resultType="java.util.Map">
        SELECT *
        FROM
            (SELECT DISTINCT sm.menu_id        AS menuId,
                             sm.parent_id      AS parentId,
                             sm.name,
                             sm.name           AS title,
                             sm.url,
                             sm.url            AS path,
                             sm.perms,
                             sm.type,
                             sm.icon,
                             sm.order_num      AS orderNum,
                             sm.is_system_menu AS isSystemMenu,
                             sm.status
             FROM sys_menu sm
                      LEFT JOIN rt_sys_role_menu srm ON sm.menu_id = srm.menu_id AND srm.byx1 = '2'
                      LEFT JOIN rt_sys_user_role sur ON srm.role_id = sur.role_id
                      LEFT JOIN rt_sys_user su ON sur.user_id = su.user_id
             WHERE sm.status = 0
               AND su.user_id = #{userId}
             UNION ALL
             SELECT DISTINCT sm.menu_id        AS menuId,
                             sm.parent_id      AS parentId,
                             sm.name,
                             sm.name           AS title,
                             sm.url,
                             sm.url            AS path,
                             sm.perms,
                             sm.type,
                             sm.icon,
                             sm.order_num      AS orderNum,
                             sm.is_system_menu AS isSystemMenu,
                             sm.status,
                             sm.sys_sign
                                               AS sysSign
             FROM sys_menu sm
             WHERE parent_id IN (
                 SELECT DISTINCT sm.menu_id
                 FROM sys_menu sm
                          LEFT JOIN rt_sys_role_menu srm ON sm.menu_id = srm.menu_id AND srm.byx1 = '2'
                          LEFT JOIN rt_sys_user_role sur ON srm.role_id = sur.role_id
                          LEFT JOIN rt_sys_user su ON sur.user_id = su.user_id
                 WHERE sm.status = 0
                   AND su.user_id = #{userId}
             )
               AND sm.status = 0) sm1
        ORDER BY sm1.orderNum
    </select>
  <select id="getNav" resultType="java.util.Map">
    SELECT DISTINCT sm.menu_id AS menuId,
    sm.parent_id AS parentId,
    sm.name,
    sm.url AS path,
    sm.type,
    sm.order_num
    FROM sys_menu sm
    LEFT JOIN sys_role_menu srm ON sm.menu_id = srm.menu_id
    LEFT JOIN sys_user_role sur ON srm.role_id = sur.role_id
    LEFT JOIN sys_user su ON sur.user_id = su.user_id
    WHERE sm.status = 0
    <if test="userId != null and userId != ''">
      AND su.user_id = #{userId}
    </if>
    <if test="stationId != null and stationId != ''">
      AND sm.station_id = #{stationId}
    </if>
    ORDER BY sm.order_num
  </select>

</mapper>