<?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.xunmei.system.mapper.MenuMapper">

    <select id="selectMenuListByUserId" resultType="com.xunmei.system.domain.SysMenu"
            parameterType="com.xunmei.system.domain.SysMenu">
        SELECT DISTINCT
            m.menu_id,
            m.parent_id,
            m.menu_name,
            m.path,
            m.component,
            m.`query`,
            m.visible,
            m.STATUS,
            ifnull( m.perms, '' ) AS perms,
            m.is_frame,
            m.is_cache,
            m.menu_type,
            m.icon,
            m.order_num,
            m.create_time
        FROM
            t_menu m
                LEFT JOIN t_role_menu rm ON m.menu_id = rm.menu_id
                LEFT JOIN t_user_role ur ON rm.role_id = ur.role_id
                LEFT JOIN t_role ro ON ur.role_id = ro.id
        where ur.user_id = #{params.userId}
        <if test="menuName != null and menuName != ''">
            AND m.menu_name like concat('%', #{menuName}, '%')
        </if>
        <if test="visible != null and visible != ''">
            AND m.visible = #{visible}
        </if>
        <if test="status != null and status != ''">
            AND m.status = #{status}
        </if>
        order by m.parent_id, m.order_num
    </select>

    <select id="selectMenuPermsByRoleId" resultType="java.lang.String" parameterType="java.lang.Long">
        select distinct m.perms
        from t_menu m
                 left join t_role_menu rm on m.id = rm.menu_id
        where m.status = 0 and rm.role_id = #{roleId}
    </select>
    <select id="selectMenuPermsByUserId" resultType="java.lang.String" parameterType="java.lang.Long">
        select distinct m.perms
        from t_menu m
                 left join t_role_menu rm on m.id = rm.menu_id
                 left join t_user_role ur on rm.role_id = ur.role_id
                 left join t_role r on r.id = ur.role_id
        where m.status = 0 and r.status = 0 and ur.user_id = #{userId}
    </select>
</mapper>
