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

    <sql id="relSelect">
        SELECT a.*, b.menu_name parent_name
        FROM sys_menu a
        LEFT JOIN sys_menu b ON a.parent_id = b.menu_id
        <where>
            <if test="page!=null and page.pageData!=null">
                <if test="page.pageData.menuId!=null">
                    AND a.menu_id = #{page.pageData.menuId}
                </if>
                <if test="page.pageData.parentId!=null">
                    AND a.parent_id = #{page.pageData.parentId}
                </if>
                <if test="page.pageData.menuName!=null">
                    AND a.menu_name LIKE CONCAT('%', #{page.pageData.menuName}, '%')
                </if>
                <if test="page.pageData.path!=null">
                    AND a.menu_url LIKE CONCAT('%', #{page.pageData.path}, '%')
                </if>
                <if test="page.pageData.authority!=null">
                    AND a.authority LIKE CONCAT('%', #{page.pageData.authority}, '%')
                </if>
                <if test="page.pageData.createTimeStart!=null">
                    AND a.create_time &gt;= #{page.pageData.createTimeStart}
                </if>
                <if test="page.pageData.createTimeEnd!=null">
                    AND a.create_time &lt;= #{page.pageData.createTimeEnd}
                </if>
                <if test="page.pageData.deleted!=null">
                    AND a.deleted = #{page.pageData.deleted}
                </if>
                <if test="page.pageData.deleted==null">
                    AND a.deleted = 0
                </if>
                <if test="page.pageData.parentName != null">
                    AND parent_name LIKE CONCAT('%', #{page.pageData.parentName}, '%')
                </if>
            </if>
        </where>
    </sql>

    <select id="listPage" resultType="com.bomaos.common.system.entity.Menu">
        <include refid="relSelect"></include>
    </select>

    <select id="listByUserId" resultType="com.bomaos.common.system.entity.Menu">
        SELECT DISTINCT b.*
        FROM sys_role_menu a
        LEFT JOIN sys_menu b ON a.menu_id = b.menu_id
        LEFT JOIN sys_role c ON a.role_id = c.role_id
        WHERE a.role_id IN ( SELECT role_id FROM sys_user_role WHERE user_id=#{userId} )
        AND b.deleted = 0 AND c.deleted=0
        <if test="menuType!=null">AND b.menu_type=#{menuType}</if>
        ORDER BY b.sort_number
    </select>

</mapper>
