ad5081d3
孙向锦
初始化项目
|
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
373
374
375
376
377
378
379
380
|
<?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="UserMapper">
<resultMap type="User" id="userAndRoleResultMap">
<id column="USER_ID" property="USER_ID"/>
<result column="USERNAME" property="USERNAME"/>
<result column="PASSWORD" property="PASSWORD"/>
<result column="NAME" property="NAME"/>
<result column="RIGHTS" property="RIGHTS"/>
<result column="LAST_LOGIN" property="LAST_LOGIN"/>
<result column="IP" property="IP"/>
<result column="STATUS" property="STATUS"/>
<result column="SKIN" property="SKIN"/>
<result column="ROLE_IDS" property="ROLE_IDS"/>
<association property="role" column="ROLE_ID" javaType="Role">
<id column="ROLE_ID" property="ROLE_ID"/>
<result column="ROLE_NAME" property="ROLE_NAME"/>
<result column="ROLE_RIGHTS" property="RIGHTS"/>
</association>
</resultMap>
<resultMap type="User" id="userResultMap">
<id column="USER_ID" property="USER_ID"/>
<result column="USERNAME" property="USERNAME"/>
<result column="PASSWORD" property="PASSWORD"/>
<result column="NAME" property="NAME"/>
<result column="RIGHTS" property="RIGHTS"/>
<result column="LAST_LOGIN" property="LAST_LOGIN"/>
<result column="IP" property="IP"/>
<result column="STATUS" property="STATUS"/>
<result column="ROLE_ID" property="ROLE_ID"/>
<result column="SKIN" property="SKIN"/>
<result column="ROLE_IDS" property="ROLE_IDS"/>
</resultMap>
<!--表名 -->
<sql id="tableName">
SYS_USER
</sql>
<sql id="roleTableName">
SYS_ROLE
</sql>
<sql id="staffTableName">
OA_STAFF
</sql>
<!-- 字段 -->
<sql id="Field">
USER_ID,
USERNAME,
PASSWORD,
NAME,
RIGHTS,
ROLE_ID,
LAST_LOGIN,
IP,
STATUS,
BZ,
SKIN,
EMAIL,
NUMBER,
PHONE,
ROLE_IDS
</sql>
<!-- 字段值 -->
<sql id="FieldValue">
#{USER_ID},
#{USERNAME},
#{PASSWORD},
#{NAME},
#{RIGHTS},
#{ROLE_ID},
#{LAST_LOGIN},
#{IP},
#{STATUS},
#{BZ},
#{SKIN},
#{EMAIL},
#{NUMBER},
#{PHONE},
#{ROLE_IDS}
</sql>
<!-- 判断用户名和密码 -->
<select id="getUserInfo" parameterType="pd" resultType="pd">
select <include refid="Field"></include> from
<include refid="tableName"></include>
where 1=1
<if test="USERNAME!=null and PASSWORD!=null">
and USERNAME = #{USERNAME} and PASSWORD=#{PASSWORD}
</if>
<if test="USER_ID!=null and USER_ID>0">
and USER_ID = #{USER_ID}
</if>
</select>
<!-- 更新登录时间 -->
<update id="updateLastLogin" parameterType="pd" >
update
<include refid="tableName"></include>
set
LAST_LOGIN = #{LAST_LOGIN}
where USER_ID = #{USER_ID}
</update>
<!-- 通过用户ID获取用户信息和角色信息 -->
<select id="getUserAndRoleById" parameterType="String" resultMap="userAndRoleResultMap">
select u.USER_ID,
u.USERNAME,
u.NAME,
u.RIGHTS as USER_RIGHTS,
u.PASSWORD,
u.SKIN,
u.ROLE_IDS,
r.ROLE_ID,
r.ROLE_NAME,
r.RIGHTS as ROLE_RIGHTS
from
<include refid="tableName"></include> u
left join
<include refid="roleTableName"></include> r
on u.ROLE_ID=r.ROLE_ID
where u.STATUS=0
and u.USER_ID=#{USER_ID}
</select>
<!-- 通过USERNAME获取数据 -->
<select id="findByUsername" parameterType="pd" resultType="pd" >
select
<include refid="Field"></include>
from
<include refid="tableName"></include>
where
USERNAME = #{USERNAME}
</select>
<!-- 存入IP -->
<update id="saveIP" parameterType="pd" >
update
<include refid="tableName"></include>
set
IP = #{IP}
where
USERNAME = #{USERNAME}
</update>
<!-- 列出某角色下的所有用户 -->
<select id="listAllUserByRoldId" parameterType="pd" resultType="pd" >
select USER_ID
from
<include refid="tableName"></include>
where
ROLE_ID = #{ROLE_ID}
</select>
<!-- 用户列表 -->
<select id="userlistPage" parameterType="page" resultType="pd" >
select u.USER_ID,
u.USERNAME,
u.PASSWORD,
u.LAST_LOGIN,
u.NAME,
u.IP,
u.EMAIL,
u.NUMBER,
u.PHONE,
r.ROLE_ID,
r.ROLE_NAME
from <include refid="tableName"></include> u, <include refid="roleTableName"></include> r
where u.ROLE_ID = r.ROLE_ID
and u.USERNAME != 'admin'
and r.PARENT_ID = '1'
<if test="pd.keywords!= null and pd.keywords != ''"><!-- 关键词检索 -->
and
(
u.USERNAME LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
or
u.EMAIL LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
or
u.NUMBER LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
or
u.NAME LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
or
u.PHONE LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
)
</if>
<if test="pd.ROLE_ID != null and pd.ROLE_ID != ''"><!-- 角色检索 -->
and u.ROLE_ID=#{pd.ROLE_ID}
</if>
<if test="pd.lastLoginStart!=null and pd.lastLoginStart!=''"><!-- 登录时间检索 -->
and u.LAST_LOGIN >= #{pd.lastLoginStart}
</if>
<if test="pd.lastLoginEnd!=null and pd.lastLoginEnd!=''"><!-- 登录时间检索 -->
and u.LAST_LOGIN <= #{pd.lastLoginEnd}
</if>
order by u.LAST_LOGIN desc
</select>
<!-- 用户列表(弹窗选择用) -->
<select id="userBystafflistPage" parameterType="page" resultType="pd" >
select u.USER_ID,
u.USERNAME,
u.PASSWORD,
u.LAST_LOGIN,
u.NAME,
u.IP,
u.EMAIL,
u.NUMBER,
u.PHONE,
r.ROLE_ID,
r.ROLE_NAME
from <include refid="tableName"></include> u, <include refid="roleTableName"></include> r
where u.ROLE_ID = r.ROLE_ID
and u.USERNAME != 'admin'
and r.PARENT_ID = '1'
<if test="pd.keywords!= null and pd.keywords != ''"><!-- 关键词检索 -->
and
(
u.USERNAME LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
or
u.EMAIL LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
or
u.NUMBER LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
or
u.NAME LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
or
u.PHONE LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
)
</if>
<if test="pd.ROLE_ID != null and pd.ROLE_ID != ''"><!-- 角色检索 -->
and u.ROLE_ID=#{pd.ROLE_ID}
</if>
<if test="pd.lastLoginStart!=null and pd.lastLoginStart!=''"><!-- 登录时间检索 -->
and u.LAST_LOGIN >= #{pd.lastLoginStart}
</if>
<if test="pd.lastLoginEnd!=null and pd.lastLoginEnd!=''"><!-- 登录时间检索 -->
and u.LAST_LOGIN <= #{pd.lastLoginEnd}
</if>
and u.USERNAME not in (select s.USER_ID from <include refid="staffTableName"></include> s where s.USER_ID !='')
order by u.LAST_LOGIN desc
</select>
<!-- 通过邮箱获取数据 -->
<select id="findByUE" parameterType="pd" resultType="pd" >
select
<include refid="Field"></include>
from
<include refid="tableName"></include>
where
EMAIL = #{EMAIL}
<if test="USERNAME != null and USERNAME != ''">
and USERNAME != #{USERNAME}
</if>
</select>
<!-- 通过编号获取数据 -->
<select id="findByUN" parameterType="pd" resultType="pd" >
select
<include refid="Field"></include>
from
<include refid="tableName"></include>
where
NUMBER = #{NUMBER}
<if test="USERNAME != null and USERNAME != ''">
and USERNAME != #{USERNAME}
</if>
</select>
<!-- 通过user_id获取数据 -->
<select id="findById" parameterType="pd" resultType="pd" >
select
<include refid="Field"></include>
from
<include refid="tableName"></include>
where
USER_ID = #{USER_ID}
</select>
<!-- 新增用户 -->
<insert id="saveU" parameterType="pd" >
insert into <include refid="tableName"></include> (
<include refid="Field"></include>
) values (
<include refid="FieldValue"></include>
)
</insert>
<!-- 修改 -->
<update id="editU" parameterType="pd" >
update <include refid="tableName"></include>
set NAME = #{NAME},
ROLE_ID = #{ROLE_ID},
ROLE_IDS = #{ROLE_IDS},
BZ = #{BZ},
EMAIL = #{EMAIL},
NUMBER = #{NUMBER},
PHONE = #{PHONE}
<if test="PASSWORD != null and PASSWORD != ''">
,PASSWORD = #{PASSWORD}
</if>
where
USER_ID = #{USER_ID}
</update>
<!-- 删除用户 -->
<delete id="deleteU" parameterType="pd" flushCache="false">
delete from <include refid="tableName"></include>
where
USER_ID = #{USER_ID}
and
USER_ID != '1'
</delete>
<!-- 批量删除用户 -->
<delete id="deleteAllU" parameterType="String" >
delete from <include refid="tableName"></include>
where
USER_ID in
<foreach item="item" index="index" collection="array" open="(" separator="," close=")">
#{item}
</foreach>
and
USER_ID != '1'
</delete>
<!-- 用户列表(全部) -->
<select id="listAllUser" parameterType="pd" resultType="pd" >
select u.USER_ID,
u.USERNAME,
u.PASSWORD,
u.LAST_LOGIN,
u.NAME,
u.IP,
u.EMAIL,
u.NUMBER,
u.PHONE,
r.ROLE_ID,
r.ROLE_NAME
from <include refid="tableName"></include> u, <include refid="roleTableName"></include> r
where u.ROLE_ID = r.ROLE_ID
and u.USERNAME != 'admin'
and r.PARENT_ID = '1'
<if test="keywords!= null and keywords != ''"><!-- 关键词检索 -->
and
(
u.USERNAME LIKE CONCAT(CONCAT('%', #{keywords}),'%')
or
u.EMAIL LIKE CONCAT(CONCAT('%', #{keywords}),'%')
or
u.NUMBER LIKE CONCAT(CONCAT('%', #{keywords}),'%')
or
u.NAME LIKE CONCAT(CONCAT('%', #{keywords}),'%')
or
u.PHONE LIKE CONCAT(CONCAT('%', #{keywords}),'%')
)
</if>
<if test="ROLE_ID != null and ROLE_ID != ''"><!-- 角色检索 -->
and u.ROLE_ID=#{ROLE_ID}
</if>
<if test="lastLoginStart!=null and lastLoginStart!=''"><!-- 登录时间检索 -->
and u.LAST_LOGIN >= #{lastLoginStart}
</if>
<if test="lastLoginEnd!=null and lastLoginEnd!=''"><!-- 登录时间检索 -->
and u.LAST_LOGIN <= #{lastLoginEnd}
</if>
order by u.LAST_LOGIN desc
</select>
<!-- 获取总数 -->
<select id="getUserCount" parameterType="String" resultType="pd">
select
count(USER_ID) userCount
from
<include refid="tableName"></include>
</select>
<!-- fh313596790qq(青苔) -->
</mapper>
|