<?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.cyksj.mapper.manage.cms.CmsRoleMapper">

    <select id="getCmsRolesByUserId" resultType="com.cyksj.model.entity.CmsRole">
        select distinct r.id,
                        r.role_name,
                        r.remark
        from `cms_role` r
                 inner join `cms_user_role` ur on r.id = ur.role_id
                 inner join `cms_user` u on u.id = ur.user_id
        where u.id = #{userId}
    </select>

    <select id="getAllCmsUserByRoleId" resultType="com.cyksj.model.entity.CmsUser">
        select u.*
        from `cms_user` u
                 inner join `cms_user_role` ur on ur.user_id = u.id
        where ur.role_id = #{roleId}
    </select>

    <select id="getAllMenusByRoleIds" resultType="java.lang.String">
        select distinct cm.id from `cms_menu` cm inner join `cms_role_menu` cmr on cm.id = cmr.menu_id
        where cmr.role_id in
        <foreach collection="list" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </select>

    <select id="getCmsRolesByAccount" resultType="com.cyksj.model.entity.CmsRole">
        select distinct r.id,
                        r.role_name,
                        r.remark
        from `cms_role` r
                 inner join `cms_user_role` ur on r.id = ur.role_id
                 inner join `cms_user` u on u.id = ur.user_id
        where u.id = #{account}
    </select>
</mapper>