EmployeeMapper.xml
10.6 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
<?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.EmployeeMapper" >
<resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Employee" >
<id column="emId" property="id" />
<result column="emCode" property="code"/>
<result column="emName" property="name"/>
<result column="emSex" property="sex"/>
<result column="emExtId" property="extid"/>
<result column="coId" property="coid" />
<result column="emEntryDate" property="entrydate"/>
<result column="emLeaveDate" property="leavedate"/>
<result column="ptEmail" property="email"/>
<result column="ptPhone" property="phone"/>
<result column="emCtType" property="cttype" />
<result column="emCtCode" property="ctcode" />
<result column="emRelman" property="relman" />
<result column="emRelTel" property="reltel" />
<result column="ptPost" property="post" />
<result column="diId" property="diid"/>
<result column="ptAddr" property="addr"/>
<result column="emLostPhone" property="lostphone"/>
<result column="ptRemark1" property="remark1"/>
<result column="ptRemark2" property="remark2" />
<result column="ptRemark3" property="remark3" />
<result column="ptUpTime" property="uptime" />
<result column="ptUpdater" property="updater" />
<association property="cou" javaType="cn.runsa.portal.base.entity.Country">
<id column="coId" property="id" />
<result column="coName" property="name"/>
</association>
<association property="pro" javaType="cn.runsa.portal.base.entity.Province">
<id column="prId" property="id" />
<result column="prName" property="name"/>
</association>
<association property="city" javaType="cn.runsa.portal.base.entity.City">
<id column="ciId" property="id" />
<result column="ciName" property="name"/>
</association>
<association property="corp" javaType="cn.runsa.portal.base.entity.Corp">
<id column="coId" property="id" />
<result column="coName" property="name"/>
</association>
<collection property="pld" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.EmployeeDept">
<id column="emId" property="id"/>
<result column="deId" property="deid" />
</collection>
<collection property="plp" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.EmployeePost">
<id column="emId" property="id"/>
<result column="poId" property="poid" />
</collection>
<collection property="uname" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.Username">
<id column="usnId" property="id"/>
<result column="usnName" property="name" />
<result column="usnType" property="type" />
<result column="usnValid" property="valid" />
</collection>
<collection property="depts" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.Dept">
<id column="deId" property="id"/>
<result column="deName" property="name" />
</collection>
<collection property="posts" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.Post">
<id column="poId" property="id"/>
<result column="poName" property="name" />
</collection>
<collection property="users" javaType="ArrayList" ofType="cn.runsa.portal.base.entity.Users">
<id column="usId" property="id"/>
</collection>
</resultMap>
<select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
SELECT
t1.emId,
t1.emCode,
t1.emName,
t1.emEntryDate,
t1.emLeaveDate,
t1.emCtType,
t1.emCtCode,
t1.emRelman,
t1.emRelTel,
t1.emSex,
t1.ptPost,
t1.diId,
t1.ptAddr,
t1.ptRemark1,
t2.coId,
t2.coName,
t4.deId,
t4.deName,
t6.poId,
t6.poName,
t7.usnId,
t7.usnType,
t7.usnName,
t7.usnValid,
t10.usId
FROM
mtEmployee t1
LEFT JOIN mtCorp t2 ON t2.coId = t1.coId
LEFT JOIN mtEmployeeDept t3 ON t3.emId = t1.emId
LEFT JOIN mtDept t4 ON t4.deId = t3.deId
LEFT JOIN mtEmployeePost t5 ON t5.emId = t1.emId
LEFT JOIN mtPost t6 ON t6.poId = t5.poId
LEFT JOIN smUsername t7 ON t7.emId = t1.emId
LEFT JOIN smUsers t10 on t10.emId = t1.emId
where t1.emId=#{emid}
</select>
<select id="selectExitEmp" resultMap="BaseResultMap" parameterType="cn.runsa.portal.base.entity.Employee" >
SELECT
t1.emId,
t1.emCode,
t1.emName,
t1.emEntryDate,
t1.emLeaveDate,
t1.emCtType,
t1.emCtCode,
t1.emRelman,
t1.emRelTel,
t1.emSex,
t1.ptPost,
t1.diId,
t1.ptAddr,
t1.ptRemark1,
t2.coId,
t2.coName,
t4.deId,
t4.deName,
t6.poId,
t6.poName,
t7.usnId,
t7.usnType,
t7.usnName,
t7.usnValid,
t10.usId
FROM
mtEmployee t1
LEFT JOIN mtCorp t2 ON t2.coId = t1.coId
LEFT JOIN mtEmployeeDept t3 ON t3.emId = t1.emId
LEFT JOIN mtDept t4 ON t4.deId = t3.deId
LEFT JOIN mtEmployeePost t5 ON t5.emId = t1.emId
LEFT JOIN mtPost t6 ON t6.poId = t5.poId
LEFT JOIN smUsername t7 ON t7.emId = t1.emId
LEFT JOIN smUsers t10 on t10.emId = t1.emId
where t1.coId = #{coid} and t1.emCode=#{code} and t1.emName=#{name}
</select>
<insert id="insertEmp" parameterType="cn.runsa.portal.base.entity.Employee">
<selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into mtEmployee(emCode,emName,emSex,emExtId
,coId,emEntryDate,emLeaveDate,ptEmail,ptPhone
,emCtType,emCtCode,emRelman,emRelTel,ptPost,diId,ptAddr,emLostPhone,ptRemark1
,ptRemark2,ptRemark3,ptUpTime,ptUpdater)
values(#{code},#{name},#{sex},#{extid},#{coid},#{entrydate},#{leavedate},#{email},
#{phone},#{cttype},#{ctcode},#{relman},#{reltel},#{post},
#{diid},#{addr},#{lostphone},#{remark1},#{remark2},#{remark3},now(),#{updater})
</insert>
<insert id="insertEdept" parameterType="cn.runsa.portal.base.entity.Employee">
insert into mtEmployeeDept (emId,deId) values
<foreach collection="pld" item="item" separator=",">
(#{id},#{item.deid})
</foreach>
</insert>
<insert id="insertEpost" parameterType="cn.runsa.portal.base.entity.Employee">
insert into mtEmployeePost (emId,poId) values
<foreach collection="plp" item="item" separator=",">
(#{id},#{item.poid})
</foreach>
</insert>
<insert id="insertUname" parameterType="map">
insert into smUsername (usId,emId,usnName,usnType) values
<foreach collection="uname" item="item" separator=",">
(#{usid},#{emid},#{item.name},#{item.type})
</foreach>
</insert>
<update id="updateEmp" parameterType="cn.runsa.portal.base.entity.Employee">
update mtEmployee set ptUpTime=now(),ptUpdater=#{updater}
<if test="code!=null and code!=''">
,emCode=#{code}
</if>
<if test="name!=null and name!=''">
,emName=#{name}
</if>
,emSex=#{sex}
,emExtId=#{extid}
<if test="coid!=null">
,coId=#{coid}
</if>
<if test="entrydate!=null">
,emEntryDate=#{entrydate}
</if>
,emLeaveDate=#{leavedate}
,ptEmail=#{email}
,ptPhone=#{phone}
,emCtType=#{cttype}
,emCtCode=#{ctcode}
,emRelman=#{relman}
,emRelTel=#{reltel}
,ptPost=#{post}
,diId=#{diid}
,ptAddr=#{addr}
,emLostPhone=#{lostphone}
,ptRemark1=#{remark1}
,ptRemark2=#{remark2}
,ptRemark3=#{remark3}
where emId = #{id}
</update>
<update id="updateUname" parameterType="map">
<foreach collection="uname" item="item" separator=",">
update smUsername
<set>
usId=#{usid},usnName=#{item.name},usnType=#{item.type}
</set>
where usnId=#{item.id}
</foreach>
</update>
<delete id="deleteDept" parameterType="java.lang.Integer">
delete from mtEmployeeDept where emId=#{id}
</delete>
<delete id="deletePost" parameterType="java.lang.Integer">
delete from mtEmployeePost where emId=#{id}
</delete>
<delete id="deleteUName" parameterType="java.lang.Integer">
delete from smUsername where emId=#{id}
</delete>
<delete id="deleteEmp" parameterType="java.lang.Integer">
delete from mtEmployee where emId=#{id}
</delete>
<select id="existsUsers" resultType="java.lang.Integer" parameterType="java.lang.Integer" >
select
COUNT(*)
from smUsers
where emId = #{id}
</select>
<select id="selectByDiid" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
*
from vDistrict
where diId = #{id}
</select>
<select id="existsEmps" resultType="java.lang.Integer" parameterType="cn.runsa.portal.base.entity.Employee">
select
COUNT(*)
from mtEmployee
where coId = #{coid} and emCode=#{code} and emName=#{name}
</select>
<select id="existsCode" resultType="java.lang.Integer" parameterType="map">
select
COUNT(*)
from mtEmployee
where emCode=#{code} and coId=#{coid}
</select>
<select id="existsCodeAll" resultType="java.lang.Integer" parameterType="map">
select
COUNT(*)
from mtEmployee
where emCode=#{code}
</select>
<select id="existsCodeWithPhone" resultType="java.lang.Integer" parameterType="map">
select
COUNT(*)
from smUsername
where usnName=#{code} and usnType=2
</select>
<select id="existsCtCode" resultType="java.lang.Integer" parameterType="map">
select
COUNT(*)
from mtEmployee
where CAST(emCtCode AS CHAR)=#{ctcode} and coId=#{coid}
</select>
<select id="existsNamePhone" resultType="java.lang.Integer" parameterType="map">
SELECT
COUNT(1)
FROM
mtEmployee t1
LEFT JOIN smUsername t2 ON t1.emId = t2.emId
AND t2.usnType = 2
AND t2.usnValid = 1
<if test="coid!=null and coid!=''">
AND t1.coId=#{coid}
</if>
where t2.usnName=#{name}
</select>
<select id="existsNameEmail" resultType="java.lang.Integer" parameterType="map">
SELECT
COUNT(1)
FROM
mtEmployee t1
LEFT JOIN smUsername t2 ON t1.emId = t2.emId
AND t2.usnType = 3
AND t2.usnValid = 1
<if test="coid!=null and coid!=''">
AND t1.coId=#{coid}
</if>
where t2.usnName=#{name}
</select>
<select id="existsNameEmailNoCoid" resultType="java.lang.Integer" parameterType="map">
SELECT
COUNT(1)
FROM
mtEmployee t1
LEFT JOIN smUsername t2 ON t1.emId = t2.emId
AND t2.usnType = 3
AND t2.usnValid = 1
where t2.usnName=#{name} and t1.emName=#{emname} and t1.coId!=#{coid}
</select>
<select id="existsNamePhoneNoCoid" resultType="java.lang.Integer" parameterType="map">
SELECT
COUNT(1)
FROM
mtEmployee t1
LEFT JOIN smUsername t2 ON t1.emId = t2.emId
AND t2.usnType = 2
AND t2.usnValid = 1
where t2.usnName=#{name} and t1.emName=#{emname} and t1.coId!=#{coid}
</select>
</mapper>