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

    <select id="findMenuByRole" parameterType="HashMap" resultType="HashMap">
        SELECT MENU_ID as id, MENU_NAME as text, PARENT_ID as parentid, SEQ, LINK_URL as urls, ISACTIVE, CREATE_TIME,
        RESLEVEL,LINK_IMG,LINK_IMG_SIZE FROM menu t
        where t.isactive = '1'
        <if test="user_id!=null and user_id!=''">
            AND MENU_ID in (select a.MENU_ID from menu_role a where a.ROLE_ID in (select role_id from user_role where
            user_id = #{user_id}))
        </if>

        order by length(t.MENU_ID),t.SEQ
    </select>

    <select id="findMenuByUrl" parameterType="HashMap" resultType="HashMap">
        select t.menu_id, t.menu_name, t.link_url
        from menu t
        where t.isactive = 1
          and t.link_url = #{url}
    </select>

    <select id="findRoleByUserAndMenu" parameterType="HashMap" resultType="HashMap">
        select *
        from user_role t
        where t.user_id = #{userid}
          and exists(select 1 from menu_role mr where mr.role_id = t.role_id and mr.menu_id = #{menu_id})
    </select>
</mapper>