DeptMapper.xml
6.67 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
<?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.DeptMapper">
<resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Dept">
<id column="deId" property="id" jdbcType="INTEGER" />
<result column="coId" property="coid" jdbcType="INTEGER" />
<result column="deName" property="name" jdbcType="VARCHAR" />
<result column="deLevel" property="level" jdbcType="INTEGER" />
<result column="deParent" property="parent" jdbcType="INTEGER" />
<result column="deSort" property="sort" jdbcType="INTEGER" />
<result column="ptRemark1" property="remark1" jdbcType="VARCHAR" />
<result column="ptRemark2" property="remark2" jdbcType="VARCHAR" />
<result column="ptRemark3" property="remark3" jdbcType="VARCHAR" />
<result column="ptUpTime" property="uptime" jdbcType="TIMESTAMP" />
<result column="ptUpdater" property="updater" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List">
deId, coId, deName, deLevel, deParent, deSort, ptRemark1,
ptRemark2,
ptRemark3, ptUpTime,
ptUpdater
</sql>
<select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List" />
from mtdept
where deId = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteById" parameterType="java.lang.Integer">
delete from mtdept
where
deId = #{id,jdbcType=INTEGER}
</delete>
<insert id="insertDept" parameterType="cn.runsa.portal.base.entity.Dept">
<selectKey resultType="java.lang.Integer" keyProperty="id"
order="AFTER">
SELECT LAST_INSERT_ID()
</selectKey>
insert into mtdept (coId, deName,
deLevel, deParent, deSort,
ptRemark1,
ptRemark2, ptRemark3,
ptUpTime, ptUpdater)
values
(#{coid,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
#{level,jdbcType=INTEGER}, #{parent,jdbcType=INTEGER},
#{sort,jdbcType=INTEGER},
#{remark1,jdbcType=VARCHAR},
#{remark2,jdbcType=VARCHAR}, #{remark3,jdbcType=VARCHAR},
now(),
#{updater,jdbcType=INTEGER})
</insert>
<update id="updateById" parameterType="cn.runsa.portal.base.entity.Dept">
update mtdept set deName = #{name,jdbcType=VARCHAR},deParent =
#{parent,jdbcType=INTEGER},ptUpTime=now()
<if test="level != null">
,deLevel = #{level,jdbcType=INTEGER}
</if>
<if test="sort != null">
,deSort = #{sort,jdbcType=INTEGER}
</if>
<if test="remark1 != null">
,ptRemark1 = #{remark1,jdbcType=VARCHAR}
</if>
<if test="remark2 != null">
,ptRemark2 = #{remark2,jdbcType=VARCHAR}
</if>
<if test="remark3 != null">
,ptRemark3 = #{remark3,jdbcType=VARCHAR}
</if>
<if test="updater != null">
,ptUpdater = #{updater,jdbcType=INTEGER}
</if>
where deId = #{id,jdbcType=INTEGER}
</update>
<select id="selectDeptsByPid" resultMap="BaseResultMap"
useCache="true">
select
<include refid="Base_Column_List" />
from mtdept
where coId = #{coid,jdbcType=INTEGER}
<if test="pid!=null and pid!=''">
AND deParent = #{pid,jdbcType=INTEGER}
</if>
<if test="pid==null or pid==''">
AND deParent IS NULL
</if>
ORDER BY deSort
</select>
<select id="existsDeName" resultType="Boolean"
parameterType="cn.runsa.portal.base.entity.Dept">
SELECT COUNT(*) FROM mtdept WHERE coId = #{coid} AND deName = #{name}
<if test="id!=null and id!=''">
AND deId != #{id}
</if>
</select>
<select id="selectDeptIdsByPid" resultType="java.lang.Integer"
parameterType="java.lang.Integer">
select deId
from mtDeptInfo
where deParent =
#{pid,jdbcType=INTEGER}
</select>
<delete id="deleteByIds" parameterType="java.util.List">
delete from mtdept
where
deId IN
<foreach item="item" collection="list" separator="," open="("
close=")" index="">
#{item}
</foreach>
</delete>
<delete id="deleteDeptInfoByIds" parameterType="java.util.List">
delete from mtDeptInfo
where
deId IN
<foreach item="item" collection="list" separator="," open="("
close=")" index="">
#{item}
</foreach>
</delete>
<select id="existsEmployee" resultType="Boolean" parameterType="java.util.List">
SELECT COUNT(*) FROM mtEmployeeDept WHERE deId IN
<foreach item="item" collection="list" separator="," open="("
close=")" index="">
#{item}
</foreach>
</select>
<insert id="insertDeptInfo" parameterType="cn.runsa.portal.base.entity.Dept">
insert into mtDeptInfo
(deId,deParent,deLevel) SELECT #{id},deParent,deLevel FROM mtdeptinfo
WHERE deId = #{parent}
</insert>
<insert id="insertDeptInfoSelf">
insert into mtDeptInfo (deId,deParent,deLevel) values
(#{deId},#{deId},#{deLevel})
</insert>
<select id="selectMaxLevel" resultType="java.lang.Integer"
parameterType="java.lang.Integer">
select MAX(deLevel) FROM mtDeptInfo where deId =
#{deId,jdbcType=INTEGER}
</select>
<select id="selectMaxSort" resultType="java.lang.Integer">
SELECT MAX(deSort) FROM mtdept WHERE coId = #{coid,jdbcType=INTEGER}
<if test="pid!=null and pid!=''">
AND deParent = #{pid,jdbcType=INTEGER}
</if>
<if test="pid==null or pid==''">
AND deParent IS NULL
</if>
</select>
<select id="selectPreviousDept" resultMap="BaseResultMap"
parameterType="cn.runsa.portal.base.entity.Dept">
select
<include refid="Base_Column_List" />
from mtdept
where deSort = (SELECT MAX(deSort) FROM mtdept where deSort <![CDATA[<]]>
#{sort,jdbcType=INTEGER}
<if test="parent!=null and parent!=''">
AND deParent = #{parent,jdbcType=INTEGER}
</if>
<if test="parent==null or parent==''">
AND deParent IS NULL
</if>
ORDER BY deSort)
<if test="parent!=null and parent!=''">
AND deParent = #{parent,jdbcType=INTEGER}
</if>
<if test="parent==null or parent==''">
AND deParent IS NULL
</if>
AND coId = #{coid,jdbcType=INTEGER}
</select>
<select id="selectNextDept" resultMap="BaseResultMap"
parameterType="cn.runsa.portal.base.entity.Dept">
select
<include refid="Base_Column_List" />
from mtdept
where deSort = (SELECT MIN(deSort) FROM mtdept where deSort <![CDATA[>]]>
#{sort,jdbcType=INTEGER}
<if test="parent!=null and parent!=''">
AND deParent = #{parent,jdbcType=INTEGER}
</if>
<if test="parent==null or parent==''">
AND deParent IS NULL
</if>
ORDER BY deSort)
<if test="parent!=null and parent!=''">
AND deParent = #{parent,jdbcType=INTEGER}
</if>
<if test="parent==null or parent==''">
AND deParent IS NULL
</if>
AND coId = #{coid,jdbcType=INTEGER}
</select>
<delete id="deleteEmployeeDeptById">
delete from mtEmployeeDept where deId =
#{deId,jdbcType=INTEGER} AND emId = #{emId,jdbcType=INTEGER}
</delete>
<insert id="insertEmployeeDept">
INSERT INTO mtemployeedept(emId,deId) VALUES (#{emId,jdbcType=INTEGER},#{deId,jdbcType=INTEGER})
</insert>
</mapper>