<?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="cn.iocoder.mall.admin.dao.ResourceMapper">

    <sql id="FIELDS">
        id, type, sort, display_name, icon, permissions,
        create_time, pid, handler
    </sql>

    <select id="selectListByTypeAndRoleIds" resultType="ResourceDO">
        SELECT
            r.id, r.type, r.sort, r.display_name,
            r.create_time, r.pid, r.handler
        FROM resource r, role_resource rr
        WHERE r.deleted = 0
        AND rr.deleted = 0
        <if test="type != null">
            AND r.type = #{type}
        </if>
        AND rr.role_id IN
            <foreach item="roleId" collection="roleIds" separator="," open="(" close=")" index="">
                #{roleId}
            </foreach>
        AND r.id = rr.resource_id
    </select>

</mapper>
