联表查询SQL原创
<!-- 用户分页列表 -->
<select id="getUserPage" resultType="com.youlai.system.model.bo.UserBO">
SELECT
u.id,
u.username,
u.nickname,
u.mobile,
u.gender,
u.avatar,
u.STATUS,
d.NAME AS dept_name,
GROUP_CONCAT( r.NAME ) AS roleNames,
u.create_time
FROM
sys_user u
LEFT JOIN sys_dept d ON u.dept_id = d.id
LEFT JOIN sys_user_role sur ON u.id = sur.user_id
LEFT JOIN sys_role r ON sur.role_id = r.id
<where>
u.deleted = 0 AND u.username != 'root'
<if test='queryParams.keywords!=null and queryParams.keywords.trim() neq ""'>
AND (
u.username LIKE CONCAT('%',#{queryParams.keywords},'%')
OR u.nickname LIKE CONCAT('%',#{queryParams.keywords},'%')
OR u.mobile LIKE CONCAT('%',#{queryParams.keywords},'%')
)
</if>
<if test='queryParams.status!=null'>
AND u.status = #{queryParams.status}
</if>
<if test='queryParams.deptId!=null'>
AND concat(',',concat(d.tree_path,',',d.id),',') like concat('%,',#{queryParams.deptId},',%')
</if>
</where>
GROUP BY u.id
</select>
<!-- 获取路由列表 -->
<select id="listRoutes" resultMap="RouteMap">
SELECT
t1.id,
t1.name,
t1.parentId,
t1.path,
t1.component,
t1.icon,
t1.sort,
t1.visible,
t1.redirect,
t1.type,
t3.code
FROM
sys_menu t1
LEFT JOIN sys_role_menu t2 ON t1.id = t2.menuId
LEFT JOIN sys_role t3 ON t2.roleId = t3.id
WHERE
t1.type != '${@com.youlai.system.common.enums.MenuTypeEnum@BUTTON.getValue()}'
ORDER BY t1.sort asc
</select>
<!-- 获取角色拥有的权限集合 -->
<select id="listRolePerms" resultType="java.lang.String">
SELECT
DISTINCT t1.perm
FROM
sys_menu t1
INNER JOIN sys_role_menu t2 ON t1.id = t2.menuId
INNER JOIN sys_role t3 ON t3.id = t2.roleId
WHERE
t1.type = '${@com.youlai.system.common.enums.MenuTypeEnum@BUTTON.getValue()}'
AND t1.perm IS NOT NULL
<choose>
<when test="roles!=null and roles.size()>0">
AND t3.CODE IN
<foreach collection="roles" item="role" separator="," open="(" close=")">
#{role}
</foreach>
</when>
<otherwise>
AND t1.id = -1
</otherwise>
</choose>
</select>
<!-- 获取角色拥有的菜单ID集合 -->
<select id="listMenuIdsByRoleId" resultType="java.lang.Long">
SELECT
rm.menuId
FROM
sys_role_menu rm
INNER JOIN sys_menu m ON rm.menuId = m.id
WHERE
rm.roleId = #{roleId}
</select>
<!-- 获取用户导出列表 -->
<select id="listExportUsers" resultType="com.youlai.system.model.vo.UserExportVO">
SELECT
u.username,
u.nickname,
u.mobile,
CASE u.gender
WHEN 1 THEN '男'
WHEN 2 THEN '女'
ELSE '未知'
END gender,
d.NAME AS dept_name,
u.createTime
FROM
sys_user u
LEFT JOIN sys_dept d ON u.deptId = d.id
<where>
u.isDelete = 0 AND u.username != 'root'
<if test='keywords!=null and keywords.trim() neq ""'>
AND (u.username LIKE CONCAT('%',#{keywords},'%')
OR u.nickname LIKE CONCAT('%',#{keywords},'%')
OR u.mobile LIKE CONCAT('%',#{keywords},'%'))
</if>
<if test='status!=null'>
AND u.status = #{status}
</if>
<if test='deptId!=null'>
AND concat(',',concat(d.tree_path,',',d.id),',') like concat('%,',#{deptId},',%')
</if>
</where>
GROUP BY u.id
</select>
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
上次更新: 2024/01/14 16:27:31
- 01
- element-plus多文件手动上传 原创11-03
- 02
- TrueLicense 创建及安装证书 原创10-25
- 03
- 手动修改迅捷配置 原创09-03
- 04
- 安装 acme.sh 原创08-29
- 05
- zabbix部署 原创08-20