RoleMapper.xml
6.99 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?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.diligrp.manage.dao.impl.RoleDaoImpl">
<resultMap id="RoleRM" type="com.diligrp.manage.domain.Role">
<id property="id" column="id"/>
<result property="roleName" column="role_name"/>
<result property="description" column="description"/>
<result property="created" column="created"/>
<result property="modified" column="modified"/>
</resultMap>
<resultMap id="UserRoleRM" type="com.diligrp.manage.domain.UserRole">
<id property="id" column="id"/>
<result property="roleId" column="role_id"/>
</resultMap>
<resultMap id="RoleUserRM" type="com.diligrp.manage.domain.RoleUser">
<id property="id" column="id"/>
<result property="userId" column="user_id"/>
</resultMap>
<select id="findUserByRoleId" parameterType="Long" resultMap="UserRoleRM">
<![CDATA[
SELECT
u.id,
u.role_id
FROM security_user_role u
WHERE u.role_id=#{id}
]]>
</select>
<select id="getById" parameterType="Long" resultMap="RoleRM">
<![CDATA[
SELECT
id
,role_name
,description
,created
,modified
FROM security_role
WHERE id=#{pk}
and (yn is null or yn = 1)
]]>
</select>
<select id="findByUserId" parameterType="Long" resultMap="RoleRM">
<![CDATA[
SELECT
r.id
,r.role_name
,r.description
,r.created
,r.modified
FROM security_role r
left join security_user_role ru on ru.role_id = r.id
WHERE
1 = 1
and ru.user_id=#{pk}
and (yn is null or yn = 1)
]]>
</select>
<select id="findByResource" parameterType="Long" resultMap="RoleRM">
<![CDATA[
SELECT
r.id
,r.role_name
,r.description
,r.created
,r.modified
FROM security_role r
left join security_role_permission rp on rp.role_id = r.id
WHERE rp.resource_id=#{pk}
and (yn is null or yn = 1)
]]>
</select>
<select id="getByMenu" parameterType="Long" resultMap="RoleRM">
<![CDATA[
SELECT
sr.id
,sr.role_name
,sr.description
,sr.created
,sr.modified
FROM security_role sr
LEFT JOIN security_role_menu srm on sr.id = srm.role_id
WHERE srm.menu_id=#{pk}
and (yn is null or yn = 1)
]]>
</select>
<select id="getAllRoles" resultMap="RoleRM">
<![CDATA[
SELECT
id
,role_name
,description
,created
,modified
FROM security_role where yn = 1
]]>
</select>
<insert id="save" parameterType="com.diligrp.manage.domain.Role">
<selectKey keyProperty="id" resultType="long" order="AFTER">
SELECT LAST_INSERT_ID();
</selectKey>
<![CDATA[
INSERT INTO security_role(
role_name
,description
) VALUES(
#{roleName}
,#{description}
)
]]>
</insert>
<insert id="saveRoleMenu" parameterType="map">
<selectKey keyProperty="id" resultType="long" order="AFTER">
SELECT LAST_INSERT_ID();
</selectKey>
INSERT INTO security_role_menu(
role_id
, menu_id
) VALUES (
#{roleId}
, #{menuId}
)
</insert>
<delete id="delByRole" parameterType="long">
DELETE FROM security_role_menu WHERE role_id = #{id}
</delete>
<update id="update" parameterType="com.diligrp.manage.domain.Role">
<![CDATA[
UPDATE security_role set
role_name=#{roleName}
,description=#{description}
,modified=#{modified}
where 1=1
and id = #{id}
]]>
</update>
<select id="countByCondition" parameterType="Query" resultType="Integer">
<![CDATA[
SELECT count(1) FROM security_role where 1=1
]]>
<if test="param != null">
<if test="param.id != null and param.id != ''">
and id = #{param.id}
</if>
<if test="param.roleName != null and param.roleName != ''">
and role_name = #{param.roleName}
</if>
<if test="param.description != null and param.description != ''">
and description = #{param.description}
</if>
<if test="param.created != null and param.created != ''">
and DATE_FORMAT(created, '%Y-%m-%d') = #{param.created}
</if>
<if test="param.modified != null and param.modified != ''">
and DATE_FORMAT(modified, '%Y-%m-%d') = #{param.modified}
</if>
and yn = 1
</if>
</select>
<select id="listByCondition" parameterType="Query" resultMap="RoleRM">
<![CDATA[
SELECT
id
,role_name
,description
,created
,modified
FROM security_role where 1=1
]]>
<if test="param != null">
<if test="param.id != null and param.id != ''">
and id = #{param.id}
</if>
<if test="param.roleName != null and param.roleName != ''">
and role_name = #{param.roleName}
</if>
<if test="param.description != null and param.description != ''">
and description = #{param.description}
</if>
<if test="param.created != null and param.created != ''">
and DATE_FORMAT(created, '%Y-%m-%d') = #{param.created}
</if>
<if test="param.modified != null and param.modified != ''">
and DATE_FORMAT(modified, '%Y-%m-%d') = #{param.modified}
</if>
and yn = 1
</if>
order by id desc
<![CDATA[
limit #{startRow},#{pageSize}
]]>
</select>
<update id="deleteById" parameterType="Long">
<![CDATA[
update security_role set
yn = 2
where 1 = 1
and id = #{id}
]]>
</update>
<insert id="roleResourceBatchInsert" parameterType="map">
<![CDATA[
insert into security_role_permission(role_id, resource_id) values
]]>
<foreach collection="resourceIds" item="resourceId" separator=",">
(#{roleId},#{resourceId})
</foreach>
</insert>
<delete id="roleResourceBatchDelete" parameterType="map">
<![CDATA[
delete from
security_role_permission
where
role_id = #{roleId} and
]]>
resource_id in (
<foreach collection="resourceIds" item="resourceId" separator="," >
#{resourceId}
</foreach>
)
</delete>
<select id="findUsersByRoleId" parameterType="Long" resultMap="RoleUserRM">
<![CDATA[
SELECT
u.id,
u.user_id
FROM security_user_role u
WHERE u.role_id=#{roleId}
]]>
</select>
<delete id="delUser" parameterType="map">
DELETE FROM security_user_role where user_id = #{userId} and role_id = #{roleId}
</delete>
</mapper>