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

    <select id="queryListParentId" resultType="com.dxhy.admin.sys.entity.SysMenuEntity">
        select *
        from sys_menu
        where parent_id = #{parentId}
        order by order_num
    </select>

    <select id="queryNotButtonList" resultType="com.dxhy.admin.sys.entity.SysMenuEntity">
        select *
        from sys_menu
        where type != 3
        order by order_num
    </select>

    <select id="queryList" resultType="com.dxhy.admin.sys.entity.SysMenuEntity">
        select *
        from sys_menu
    </select>

    <select id="queryMenuRoleList" resultType="com.dxhy.admin.sys.entity.SysMenuEntity" databaseId="mysql">
        SELECT menu.*
        FROM sys_menu menu,
             sys_role_menu rm,
             sys_user_role role
        WHERE rm.role_id = role.role_id
          and menu.menu_id = rm.menu_id
          and role.user_id = #{userId}

        group by rm.menu_id
        order by menu.order_num
    </select>
    <select id="queryMenuRoleList" resultType="com.dxhy.admin.sys.entity.SysMenuEntity" databaseId="oracle">
        SELECT menu.*
        FROM sys_menu menu,
             sys_role_menu rm,
             sys_user_role role
        WHERE rm.role_id = role.role_id
          and menu.menu_id = rm.menu_id
          and role.user_id = #{userId}
          and rm.id = (select max(id) from sys_role_menu sys where rm.menu_id = sys.menu_id)
        order by menu.order_num
    </select>

    <select id="queryMenuLog" resultType="com.dxhy.admin.sys.entity.SysMenuEntity">
        SELECT CONCAT(CONCAT(menu.parent_name, ' : '), menu.name) parentName,
               m.name                                             name,
               m.url                                              url

        FROM sys_menu menu,
             (SELECT name, url, parent_id FROM sys_menu WHERE url = #{menuUrl}) m
        WHERE menu.menu_id = m.parent_id

    </select>

    <select id="queryMenuRoleCompanyList" resultType="com.dxhy.admin.sys.entity.SysMenuEntity" databaseId="mysql">
        SELECT menu.*
        FROM sys_menu menu,
             sys_role_menu rm,
             sys_role role
        WHERE rm.role_id = role.role_id
          and menu.menu_id = rm.menu_id
          and role.company = #{company}
        group by rm.menu_id
        order by menu.order_num
    </select>
    <select id="queryMenuRoleCompanyList" resultType="com.dxhy.admin.sys.entity.SysMenuEntity" databaseId="oracle">
        SELECT menu.*
        FROM sys_menu menu,
             sys_role_menu rm,
             sys_role role
        WHERE rm.role_id = role.role_id
          and menu.menu_id = rm.menu_id
          and role.company = #{company}
          and rm.id = (select max(id) from sys_role_menu sys where rm.menu_id = sys.menu_id)
        order by menu.order_num
    </select>
    <select id="queryMenuType" resultType="com.dxhy.admin.sys.entity.SysMenuEntity">
        select *
        from sys_menu_middle
        where url = #{url}
          and type = #{type}
          and system_code = #{systemCode}
    </select>

    <select id="queryIdList" resultType="long">
        select menu_id from sys_menu
        where type = 4 and parent_id in
        <foreach item="parentId" collection="menuIds" open="(" separator="," close=")">
            #{parentId}
        </foreach>
    </select>

</mapper>
