UsersMapper.xml
11.4 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
<?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.runsa.portal.base.dao.UsersMapper" >
<resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Users" >
<id column="usId" property="id" jdbcType="INTEGER" />
<result column="plId" property="plId" jdbcType="INTEGER" />
<result column="ptValid" property="valid" jdbcType="BIT" />
<result column="laId" property="laId" jdbcType="INTEGER" />
<result column="usStartDate" property="startDate" jdbcType="TIMESTAMP" />
<result column="usEndDate" property="endDate" jdbcType="TIMESTAMP" />
<result column="usDataDay" property="dataDay" jdbcType="INTEGER" />
<result column="usFrozen" property="frozen" jdbcType="SMALLINT" />
<result column="usLogin" property="usLogin" jdbcType="SMALLINT" />
<result column="ptUpdater" property="updater" jdbcType="INTEGER" />
<result column="ptUpTime" property="uptime" jdbcType="TIMESTAMP" />
<association property="employee" javaType="cn.runsa.portal.base.entity.Employee" column="employee">
<id column="emId" property="id" jdbcType="INTEGER" />
<result column="emName" property="name" jdbcType="VARCHAR" />
<result column="emCode" property="code" jdbcType="VARCHAR" />
<result column="ptPhone" property="phone" jdbcType="VARCHAR" />
<result column="ptEmail" property="email" jdbcType="VARCHAR" />
<result column="entryFlg" property="entryFlg" jdbcType="INTEGER" />
<result column="emEntryDate" property="entrydate" jdbcType="TIMESTAMP" />
<result column="emLeaveDate" property="leavedate" jdbcType="TIMESTAMP" />
<result column="emLostPhone" property="lostphone" jdbcType="VARCHAR" />
</association>
<association property="platform" javaType="cn.runsa.portal.base.entity.Platform">
<id column="plId" property="id" />
<result column="plName" property="name"/>
</association>
<association property="platType" javaType="cn.runsa.portal.base.entity.PlatformType">
<id column="pltId" property="id"/>
</association>
<association property="corp" javaType="cn.runsa.portal.base.entity.Corp">
<id column="coId" property="id" />
<result column="coName" property="name"/>
</association>
<association property="dept" javaType="cn.runsa.portal.base.entity.Dept">
<id column="deId" property="id" />
<result column="deName" property="name"/>
</association>
</resultMap>
<sql id="Base_Column_List" >
usId, plId, ptValid, emId, laId, usStartDate, usEndDate, usDataDay,
usFrozen, ptUpdater, ptUpTime
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from smUsers
where usId = #{id,jdbcType=INTEGER}
</select>
<delete id="delete" parameterType="java.lang.Integer" >
delete from smUsers
where usId = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="cn.runsa.portal.base.entity.Users" >
<selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into smUsers (plId, ptValid, emId,
laId, usStartDate,
usEndDate, usDataDay, usFrozen,
ptUpdater, ptUpTime)
values (#{plId,jdbcType=INTEGER}, #{valid,jdbcType=BIT}, #{emId,jdbcType=INTEGER},
#{laId,jdbcType=INTEGER}, #{startDate,jdbcType=TIMESTAMP},
#{endDate,jdbcType=TIMESTAMP}, #{dataDay,jdbcType=INTEGER}, #{frozen,jdbcType=SMALLINT},
#{updater,jdbcType=INTEGER}, #{uptime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" useGeneratedKeys="true" keyProperty="id" parameterType="cn.runsa.portal.base.entity.Users" >
insert into smUsers
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="platform.id != null" >
plId,
</if>
<if test="valid != null" >
ptValid,
</if>
<if test="employee.id != null" >
emId,
</if>
<if test="laId != null" >
laId,
</if>
<if test="startDate != null" >
usStartDate,
</if>
<if test="endDate != null" >
usEndDate,
</if>
<if test="dataDay != null" >
usDataDay,
</if>
<if test="frozen != null" >
usFrozen,
</if>
<if test="updater != null" >
ptUpdater,
</if>
<if test="uptime != null" >
ptUpTime,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="platform.id != null" >
#{platform.id,jdbcType=INTEGER},
</if>
<if test="valid != null" >
#{valid,jdbcType=BIT},
</if>
<if test="employee.id != null" >
#{employee.id,jdbcType=INTEGER},
</if>
<if test="laId != null" >
#{laId,jdbcType=INTEGER},
</if>
<if test="startDate != null" >
#{startDate,jdbcType=TIMESTAMP},
</if>
<if test="endDate != null" >
#{endDate,jdbcType=TIMESTAMP},
</if>
<if test="dataDay != null" >
#{dataDay,jdbcType=INTEGER},
</if>
<if test="frozen != null" >
#{frozen,jdbcType=SMALLINT},
</if>
<if test="updater != null" >
#{updater,jdbcType=INTEGER},
</if>
<if test="uptime != null" >
#{uptime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateSelective" parameterType="cn.runsa.portal.base.entity.Users" >
update smUsers
<set >
<if test="platform != null and platform.id != null" >
plId = #{platform.id,jdbcType=INTEGER},
</if>
<if test="usLogin != null" >
usLogin = #{usLogin},
</if>
<if test="valid != null" >
ptValid = #{valid,jdbcType=BIT},
</if>
<if test="empid != null" >
emId = #{empid,jdbcType=INTEGER},
</if>
<if test="laId != null" >
laId = #{laId,jdbcType=INTEGER},
</if>
<if test="startDate != null">
usStartDate = #{startDate,jdbcType=TIMESTAMP},
</if>
<if test="endDate != null">
usEndDate = #{endDate,jdbcType=TIMESTAMP},
</if>
<if test="dataDay != null" >
usDataDay = #{dataDay,jdbcType=INTEGER},
</if>
<if test="frozen != null" >
usFrozen = #{frozen,jdbcType=SMALLINT},
</if>
<if test="updater != null" >
ptUpdater = #{updater,jdbcType=INTEGER},
</if>
<if test="uptime != null" >
ptUpTime = #{uptime,jdbcType=TIMESTAMP},
</if>
</set>
where usId = #{id,jdbcType=INTEGER}
</update>
<update id="update" parameterType="cn.runsa.portal.base.entity.Users" >
update smUsers
set plId = #{plId,jdbcType=INTEGER},
ptValid = #{valid,jdbcType=BIT},
emId = #{employee.id,jdbcType=INTEGER},
laId = #{laId,jdbcType=INTEGER},
usStartDate = #{startDate,jdbcType=TIMESTAMP},
usEndDate = #{endDate,jdbcType=TIMESTAMP},
usDataDay = #{dataDay,jdbcType=INTEGER},
usFrozen = #{frozen,jdbcType=SMALLINT},
ptUpdater = #{updater,jdbcType=INTEGER},
ptUpTime = #{uptime,jdbcType=TIMESTAMP}
where usId = #{id,jdbcType=INTEGER}
</update>
<select id="existsUsername" parameterType="String" resultType="boolean">
select (
select count(1)
from smUsers t1
inner join smUsername t2 on t1.emId=t2.emId and t2.usnName=#{username} <!-- and t2.usnValid=1 -->
where t1.ptValid=1
) + (
SELECT count(1) FROM mtEmployee WHERE emCode = #{username}
) FROM DUAL
</select>
<select id="login" resultMap="BaseResultMap">
select t1.*,t4.*,t5.plName,t5.pltId
from smUsers t1
inner join smUsername t2 on t1.emId=t2.emId and t2.usnName=#{username} <!-- and t2.usnValid=1 -->
inner join smPassword t3 on (t1.usId=t3.usId or t1.emId=t3.emId) and t3.pwdCode=#{password}
left join mtEmployee t4 on t1.emId=t4.emId
inner join smPlatform t5 on t1.plId=t5.plId
<if test="ptValid != null">
and t5.ptValid=#{ptValid,jdbcType=INTEGER}
</if>
where t1.ptValid=1 <!-- and t1.usFrozen=0 -->
UNION
select t1.*,t4.*,t5.plName,t5.pltId
from smUsers t1
inner join smPassword t3 on (t1.usId=t3.usId or t1.emId=t3.emId) and t3.pwdCode=#{password}
INNER JOIN mtEmployee t4 ON t1.emId = t4.emId AND t4.emCode =#{username}
inner join smPlatform t5 on t1.plId=t5.plId
<if test="ptValid != null">
and t5.ptValid=#{ptValid,jdbcType=INTEGER}
</if>
where t1.ptValid=1 <!-- and t1.usFrozen=0 -->
</select>
<select id="findById" resultMap="BaseResultMap" parameterType="cn.runsa.portal.base.entity.Users">
SELECT
us.usId,
em.emName,
em.emId,
em.emCode,
pl.plName,
pl.plId,
us.laId,
us.usStartDate,
us.usEndDate,
GROUP_CONCAT(DISTINCT usn.usnName) as ptPhone,
GROUP_CONCAT(DISTINCT usna.usnName) as ptEmail,
em.emEntryDate,
em.emLeaveDate,
GROUP_CONCAT(lost.usnName) emLostPhone,
co.coId,
co.coName,
GROUP_CONCAT(DISTINCT de.deName) deName,
us.ptValid,
us.usFrozen,
us.usDataDay
FROM
smUsers us
INNER JOIN mtEmployee em ON us.emId = em.emId
LEFT JOIN mtEmployeeDept emd ON em.emId = emd.emId
LEFT JOIN mtDept de ON emd.deId = de.deId
LEFT JOIN smPlatform pl ON us.plId = pl.plId
LEFT JOIN mtCorp co ON em.coId = co.coId
LEFT JOIN smUsername usn ON usn.emId = em.emId AND usn.usnValid =1 AND usn.usnType=2
LEFT JOIN smUsername usna ON usna.emId = em.emId AND usna.usnValid =1 AND usna.usnType=3
LEFT JOIN smUsername lost ON lost.emId = em.emId AND lost.usnValid =0 AND lost.usnType=2
WHERE
us.usId = #{id,jdbcType=INTEGER}
GROUP BY
us.usId
</select>
<update id="updateFrozenByUsername">
update smUsers t1
inner join smUsername t2 on t2.emId=t1.emId
set t1.usFrozen=#{frozen}
where t2.usnName = #{username}
</update>
<select id="existsPassword" resultType="Boolean" parameterType="java.lang.Integer">
SELECT COUNT(*) FROM smPassword WHERE emId =#{id,jdbcType=INTEGER}
</select>
<insert id="insertPassword">
insert into smPassword (emId, pwdCode )
values (#{emId},#{password})
</insert>
<update id="updatePassword">
update smPassword set pwdCode=#{password}
where emId=#{emId}
</update>
<select id="verifyPassword" resultType="Boolean">
select count(*) from smPassword
where emId=#{emId} and pwdCode=#{password}
</select>
<update id="updatePasswordByUser">
update smPassword set pwdCode=#{password}
where emId=(select distinct emId from smUsers where usId=#{usId})
</update>
<select id="verifyPasswordByUser" resultType="Boolean">
select count(*)
from smPassword
where emId=(select distinct emId from smUsers where usId=#{usId}) and pwdCode=#{password}
</select>
<select id="judgeLogin" resultMap="BaseResultMap" parameterType="java.lang.Integer">
SELECT usLogin FROM `smUsers` WHERE usId = #{id,jdbcType=INTEGER}
</select>
<select id="selectSysManager" resultMap="BaseResultMap">
SELECT
a.usId,
a.plId,
a.ptValid,
a.emId,
a.laId,
a.usStartDate,
a.usEndDate,
a.usDataDay,
a.usFrozen,
a.ptUpdater,
a.ptUpTime,
b.emName,
b.emCode,
b.ptPhone,
b.ptEmail,
b.emEntryDate,
b.emLeaveDate,
b.emLostPhone
FROM smusers a,mtemployee b WHERE a.emId = b.emId AND a.usId = 1 AND
a.plId = 1
</select>
<select id="verifyPasswordByUserName" resultType="Boolean">
select count(*) from smPassword
where emId=(select distinct emId from smUsers where usId IN
<foreach collection="list" item="item" index="index" separator="," open="(" close=")">
#{item.emid,jdbcType=INTEGER}
</foreach>
and pwdCode=#{password}
</select>
</mapper>