zhangherong
13 小时以前 35f7901210de45eefaa58b38db23405c561f9484
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?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="org.jeecg.modules.system.mapper.SysUserRoleMapper">
    <select id="getUsersByRoles" resultType="org.jeecg.modules.system.entity.SysUser">
        select t.* from sys_user t where t.del_flag = 0
        and t.id in (
        select t1.user_id from sys_user_role t1
        left join sys_role t2 on t1.role_id = t2.id
        <if test="roleList!=null  and roleList.size()>0">
            and t2.role_code in
            <foreach collection="roleList" index="index" item="roleCode" open="(" separator="," close=")">
                #{roleCode}
            </foreach>
        </if>
        where t2.id is not null
        )
    </select>
 
    <select id="queryRoleNamesByUserIds" resultType="org.jeecg.modules.system.vo.SysUserRoleExitVo">
        SELECT
            t1.username,
            ISNULL(
                    STUFF(
                            (
                                SELECT ',' + t3.role_name
                                FROM sys_user_role t2
                                         INNER JOIN sys_role t3 ON t2.role_id = t3.id
                                WHERE t2.user_id = t1.id
                                FOR XML PATH(''), TYPE
                            ).value('.', 'NVARCHAR(MAX)'), 1, 1, ''
                    ), ''
            ) AS roleNames
        FROM sys_user t1
        <where>
            <if test="userIds!=null  and userIds.size()>0">
                AND t1.id IN
                <foreach collection="userIds" index="index" item="userId" open="(" separator="," close=")">
                    #{userId}
                </foreach>
            </if>
        </where>
        GROUP BY t1.username, t1.id
    </select>
</mapper>