<?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.backendsys.modules.system.dao.SysUserRoleMenuDao">

    <sql id="includeUserRoleMenuSimple">
        id,
        parent_id,
        menu_name,
        menu_name_en,
        type,
        COALESCE(path, '') path,
        COALESCE(component, '') component,
        COALESCE(meta, '') meta,
        COALESCE(icon, '') icon,
        COALESCE(permission_id, '') permission_id,
        COALESCE(sort, '') sort,
        COALESCE(status, '') status
    </sql>

    <resultMap id="resultMapUserRoleMenuSimple" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />
        <result property="parent_id" column="parent_id" javaType="java.lang.Long" />
        <result property="menu_name" column="menu_name" />
        <result property="menu_name_en" column="menu_name_en" />
        <result property="type" column="type" javaType="java.lang.Integer" />
        <result property="path" column="path" />
        <result property="component" column="component" />
        <result property="meta" column="meta" />
        <result property="icon" column="icon" />
        <result property="permission_id" column="permission_id" />
        <result property="sort" column="sort" javaType="java.lang.Integer" />
        <result property="status" column="status" javaType="java.lang.Integer" />
    </resultMap>

    <select id="selectUserRoleMenuList" resultMap="resultMapUserRoleMenuSimple">
        SELECT <include refid="includeUserRoleMenuSimple" />
        FROM sys_user_role_menu
        <where>
            status = 1
            <if test="permission_ids != null and permission_ids.size() > 0">
                AND (
                    permission_id IS NULL OR permission_id = '' OR
                    permission_id IN
                    <foreach collection="permission_ids" item="permission_id" open="(" separator="," close=")">
                        #{permission_id}
                    </foreach>
                )
            </if>
            <if test="type != null and type != ''">
                AND type = #{type}
            </if>
        </where>
        ORDER BY sort DESC
    </select>

</mapper>