<?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.tuoheng.admin.mapper.MenuMapper">
    <resultMap id="BaseResultMap" type="com.tuoheng.admin.entity.domain.Menu">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="create_user" jdbcType="INTEGER" property="createUser"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_user" jdbcType="INTEGER" property="updateUser"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="mark" jdbcType="BOOLEAN" property="mark"/>
        <result column="parent_id" jdbcType="INTEGER" property="parentId"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="client_id" jdbcType="VARCHAR" property="clientId"/>
        <result column="menu_icon" jdbcType="VARCHAR" property="menuIcon"/>
        <result column="path" jdbcType="VARCHAR" property="path"/>
        <result column="component" jdbcType="VARCHAR" property="component"/>
        <result column="target" jdbcType="VARCHAR" property="target"/>
        <result column="is_hidden" jdbcType="INTEGER" property="isHidden"/>
        <result column="sort" jdbcType="INTEGER" property="sort"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, create_user, create_time, update_user, update_time, mark, parent_id, name, client_id, menu_icon, path,
    component, is_hidden, sort
    </sql>

    <!--根据角色id获取对应的菜单集合 无父级-->
    <select id="getOpMenusByRoleId" resultType="com.tuoheng.admin.entity.domain.Menu">
        select
        <include refid="Base_Column_List"/>
        from op_menus
        where mark = 1 and parent_id = 0
        <if test="clientId != null and clientId !=''">
            and client_id = #{clientId}
        </if>
        and status = 1
        and id in (select menu_id from op_role_menu where role_id = #{roleId} and mark = 1)
        order by sort asc
    </select>
    <!--根据父级id查询所属对应的菜单列表-->
    <select id="getChildrenMenuByPid" resultType="com.tuoheng.admin.entity.domain.Menu">
        select
        <include refid="Base_Column_List"/>
        from op_menus
        where mark = 1 and status = 1 and parent_id = #{parentId} and client_id = #{clientId}
        order by sort asc
    </select>

    <!--    根据roleId 查询出所有的菜单-->
    <select id="getMenuListByRoleId" resultType="com.tuoheng.admin.entity.domain.Menu">
        select
        <include refid="Base_Column_List"/>
        from op_menus
        where mark = 1
        and status = 1
        and id in (select menu_id from op_role_menu where role_id = #{roleId} and mark = 1)
        order by sort asc
    </select>



</mapper>