UserMapper.xml
13.5 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<?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.com.glsx.shield.modules.mapper.UserMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.shield.modules.entity.User">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="username" jdbcType="VARCHAR" property="username"/>
<result column="account" jdbcType="VARCHAR" property="account"/>
<result column="password" jdbcType="VARCHAR" property="password"/>
<result column="phone_number" jdbcType="VARCHAR" property="phoneNumber"/>
<result column="portrait" jdbcType="VARCHAR" property="portrait"/>
<result column="email" jdbcType="VARCHAR" property="email"/>
<result column="gender" jdbcType="INTEGER" property="gender"/>
<result column="position_" jdbcType="VARCHAR" property="position"/>
<result column="tenant_id" jdbcType="INTEGER" property="tenantId"/>
<result column="department_id" jdbcType="INTEGER" property="departmentId"/>
<result column="superior_id" jdbcType="INTEGER" property="superiorId"/>
<result column="salt" jdbcType="VARCHAR" property="salt"/>
<result column="enable_status" jdbcType="INTEGER" property="enableStatus"/>
<result column="global_type" jdbcType="TINYINT" property="globalType"/>
<result column="local_type" jdbcType="TINYINT" property="localType"/>
<result column="special_login" jdbcType="TINYINT" property="specialLogin"/>
<result column="special_mark" jdbcType="VARCHAR" property="specialMark"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
</resultMap>
<sql id="Base_Column_List">
id
, username, account, `password`, phone_number,
portrait, email, gender, position, salt, tenant_id, department_id,
superior_id, global_type, local_type,special_login,special_mark,del_flag, enable_status,
created_date, created_by, updated_date, updated_by
</sql>
<select id="selectById" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_user
where id = #{id}
and del_flag = 0
</select>
<select id="selectAllNotDel" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_user where del_flag = 0
</select>
<select id="selectByIds" resultMap="BaseResultMap">
select *
from t_user
where del_flag = 0
and id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
<select id="selectByTenantId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_user
where del_flag = 0
and tenant_id = #{tenantId}
</select>
<select id="selectByTenantIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_user
where del_flag = 0
and tenant_id in
<foreach collection="tenantIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</select>
<select id="selectByDepartmentId" resultMap="BaseResultMap">
select *
from t_user
where department_id = #{departmentId}
and del_flag = 0
</select>
<select id="selectUserOrgModelById" resultType="cn.com.glsx.usercenter.api.dto.tree.OrgModel">
select tu.id orgId,
tu.department_id parentId,
1 depth,
tu.tenant_id tenantId,
concat(tu.account, '/', tu.username) orgName,
0 isRoot,
'u' type,
0 orderNum
from t_user tu
where tu.id = #{id}
and del_flag = 0
</select>
<select id="selectUserOrgModels" resultType="cn.com.glsx.usercenter.api.dto.tree.OrgModel">
select tu.id orgId,
tu.department_id parentId,
1 depth,
tu.tenant_id tenantId,
concat(tu.account, '/', tu.username) orgName,
0 isRoot,
'u' type,
tu.id orderNum
from t_user tu
where del_flag = 0
and department_id in
<foreach collection="departmentIds" item="departmentId" open="(" close=")" separator=",">
#{departmentId}
</foreach>
<if test="userIds != null and userIds.size() > 0">
and tu.id in
<foreach collection="userIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
order by tu.id desc
</select>
<select id="selectByDepartmentIds" resultMap="BaseResultMap">
select *
from t_user
where del_flag = 0
and department_id in
<foreach collection="departmentIds" item="departmentId" open="(" close=")" separator=",">
#{departmentId}
</foreach>
</select>
<select id="selectExcludeUserIdByDepartmentId" resultMap="BaseResultMap">
select *
from t_user
where del_flag = 0
and department_id = #{departmentId}
and id <![CDATA[ <> ]]> #{userId}
</select>
<select id="countByAccount" resultType="java.lang.Integer">
select count(account)
from t_user
where account = #{account}
and del_flag = 0
</select>
<select id="selectByAccount" resultMap="BaseResultMap">
select *
from t_user
where account = #{account}
and del_flag = 0
</select>
<select id="countByAccountAndTenantId" resultType="java.lang.Integer">
select count(account)
from t_user
where account = #{account}
and tenant_id = #{tenantId}
and del_flag = 0
</select>
<select id="selectByAccountAndTenantId" resultMap="BaseResultMap">
select *
from t_user
where account = #{account}
and tenant_id = #{tenantId}
and del_flag = 0
</select>
<select id="selectByUsername" resultMap="BaseResultMap">
select *
from t_user
where username = #{username}
and del_flag = 0
</select>
<select id="search" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_user where del_flag = 0
<if test="searchField != null and searchField !=''">
and (
account like CONCAT('%',#{searchField},'%')
or
phone_number like CONCAT('%',#{searchField},'%')
or
username like CONCAT('%',#{searchField},'%')
or
id = #{searchField}
)
</if>
<if test="userId != null">
and id = #{userId}
</if>
<if test="userStatus != null">
and enable_status = #{userStatus}
</if>
<if test="tenantIds != null and tenantIds.size() > 0">
and tenant_id in
<foreach collection="tenantIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="departmentIds != null and departmentIds.size() > 0">
and department_id in
<foreach collection="departmentIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="userIds != null and userIds.size() > 0">
and id in
<foreach collection="userIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
order by id desc
</select>
<update id="logicDeleteById">
update t_user
set del_flag = -1
where id = #{id}
</update>
<update id="updatePassword">
update t_user
set password = #{password}
where id = #{id}
</update>
<select id="countByCriterial" parameterType="cn.com.glsx.shield.modules.model.param.UserBO"
resultType="java.lang.Integer">
select count(*) from t_user
where del_flag = 0
<if test="departmentId != null">
and department_id = #{departmentId}
</if>
<if test="departmentIds != null and departmentIds.size() > 0">
and department_id in
<foreach collection="departmentIds" item="departmentId" open="(" close=")" separator=",">
#{departmentId}
</foreach>
</if>
</select>
<select id="countDepartmentsUser" resultType="cn.com.glsx.shield.modules.model.view.DepartmentCount">
select department_id as departmentId, count(*) as userNumber from t_user
where del_flag = 0
<if test="departmentIds != null and departmentIds.size() > 0">
and department_id in
<foreach collection="departmentIds" item="departmentId" open="(" close=")" separator=",">
#{departmentId}
</foreach>
</if>
group by department_id
</select>
<select id="selectDepartmentsSubordinate" resultType="cn.com.glsx.shield.modules.entity.User">
select tu.id id,
tu.account account,
tu.username username,
tu.department_id departmentId,
tu.superior_id superiorId,
tu.phone_number phoneNumber,
tu.local_type localType,
tu.enable_status enableStatus,
tu.created_date createdDate
from t_user tu, t_user_path tup
where tu.del_flag = 0 and tup.del_flag = 0
and tu.id = tup.sub_id
<if test="userId != null">
and tup.superior_id = #{userId}
</if>
<if test="userStatus != null">
and tu.enable_status = #{userStatus}
</if>
<if test="userIds != null and userIds.size() > 0">
and tu.id in
<foreach collection="userIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="departmentIds != null and departmentIds.size() > 0">
and tu.department_id in
<foreach collection="departmentIds" separator="," close=")" open="(" item="item">
#{item}
</foreach>
</if>
<if test="searchField != null">
and (
tu.account like CONCAT('%',#{searchField},'%')
or
tu.phone_number like CONCAT('%',#{searchField},'%')
or
tu.username like CONCAT('%',#{searchField},'%')
)
</if>
</select>
<select id="selectUsersByCondition" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_user tu
where del_flag = 0
<if test="account != null and account !=''">
and tu.account like CONCAT('%',#{account},'%')
</if>
<if test="username != null and username !=''">
and tu.username like CONCAT('%',#{username},'%')
</if>
<if test="orgIds != null and orgIds.size() > 0">
and tu.department_id in
<foreach collection="orgIds" separator="," close=")" open="(" item="item">
#{item}
</foreach>
</if>
<if test="userIds != null and userIds.size() > 0">
and tu.id in
<foreach collection="userIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
</select>
<select id="selectSuperiorUserById" resultMap="BaseResultMap">
select tu.*
from t_user tu
left join t_user tu2 on tu2.superior_id = tu.id
where tu2.id = #{id}
</select>
<select id="selectSuperiorUserByIds" resultType="cn.com.glsx.usercenter.api.dto.response.User">
select tu.id, tu.department_id orgId, tu.username, tu.account, tu2.id mid
from t_user tu
left join t_user tu2 on tu2.superior_id = tu.id
where tu.del_flag = 0 and tu2.del_flag = 0
and tu2.id in
<foreach collection="ids" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</select>
<select id="selectByRelUserIds" resultType="cn.com.glsx.usercenter.api.dto.response.CUser">
select tcu.id userId, tu.id relUserId, tu.account, tu.username, tcula2.avatar
from t_user tu
left join t_cust_user tcu on tu.id = tcu.rel_user_id
left join t_cust_user_auth_rel tcuar on tcu.id = tcuar.user_id and tcuar.auth_type = 'local'
left join t_cust_user_local_auth tcula on tcuar.auth_id = tcula.id
left join t_cust_user_local_account tcula2 on tcuar.auth_id = tcula2.auth_id
where tu.del_flag = 0
and tu.id in
<foreach collection="relUserIds" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</select>
<update id="saveUIDById">
update t_user
set special_mark = #{specialMark}
where id = #{id}
</update>
<update id="resetUIDById">
update t_user
set special_mark = null
where id = #{id}
</update>
</mapper>