OrganizationMapper.xml
10.7 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
<?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.OrganizationMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.shield.modules.entity.Organization">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="superior_id" jdbcType="INTEGER" property="superiorId"/>
<result column="sub_id" jdbcType="INTEGER" property="subId"/>
<result column="depth" jdbcType="INTEGER" property="depth"/>
<result column="tenant_id" jdbcType="INTEGER" property="tenantId"/>
<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
, superior_id, sub_id, `depth`, tenant_id, del_flag,
created_date, created_by, updated_date, updated_by
</sql>
<insert id="insertRootPath">
insert into t_organization(superior_id, sub_id, depth, tenant_id, created_date, created_by)
values (#{superiorId}, #{subId}, 0, #{tenantId}, #{createdDate}, #{createdBy})
</insert>
<insert id="insertOrgPath" useGeneratedKeys="false">
insert into t_organization(superior_id, sub_id, depth, tenant_id, created_date, created_by)
select tor.superior_id, #{subId}, tor.depth + 1, #{tenantId}, #{createdDate}, #{createdBy}
from t_organization as tor
where tor.sub_id = #{superiorId}
union all
select #{subId}, #{subId}, 0, #{tenantId}, #{createdDate}, #{createdBy}
</insert>
<delete id="deleteOrgAllPath">
delete
a from t_organization a join t_organization b on (a.sub_id = b.sub_id)
where b.superior_id=
#{nodeId};
</delete>
<select id="selectOrgList" resultType="cn.com.glsx.usercenter.api.dto.tree.OrgModel">
select tor.sub_id orgId,
max(tor.superior_id) parentId,
min(tor2.superior_id) superiorId,
max(tor.depth) depth,
td.tenant_id tenantId,
td.department_name orgName,
td.is_root isRoot,
'' type,
td.order_num orderNum
from t_organization tor,t_organization tor2
left join t_department td on tor2.sub_id = td.id
where td.del_flag = 0
and td.enable_status = 1
and tor.id = tor2.id
and (tor.superior_id <![CDATA[<>]]> tor.sub_id or td.is_root = 1)
<if test="tenantId != null">
and td.tenant_id = #{tenantId}
</if>
<if test="tenantIds != null and tenantIds.size() > 0">
and td.tenant_id in
<foreach collection="tenantIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="orgIds != null and orgIds.size() > 0">
and tor.sub_id in
<foreach collection="orgIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
group by tor.sub_id
order by max(tor.superior_id),max(tor.depth),tor.sub_id
</select>
<select id="selectSuperiorIdsByOrgId" resultType="cn.com.glsx.shield.modules.model.OrgSuperiorModel">
select td1.id orgId, group_concat(to1.superior_id) superiorIds
from t_department td1,
t_organization to1
where td1.del_flag = 0
and td1.id = to1.sub_id
and td1.id = #{orgId}
group by to1.sub_id
</select>
<select id="selectSuperiorIdsByOrgIds" resultType="cn.com.glsx.shield.modules.model.OrgSuperiorModel">
select td1.id orgId,group_concat(to1.superior_id) superiorIds
from t_department td1, t_organization to1
where td1.del_flag = 0
and td1.id = to1.sub_id
and td1.id in
<foreach collection="orgIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
group by to1.sub_id
</select>
<select id="selectSuperiorIdsByOrg" resultType="cn.com.glsx.shield.modules.model.OrgSuperiorModel">
select td1.id orgId,group_concat(to1.superior_id) superiorIds
from t_department td1, t_organization to1
where td1.del_flag = 0
and td1.id = to1.sub_id
<if test="tenantId != null">
and td1.tenant_id = #{tenantId}
</if>
<if test="orgId != null">
and td1.id = #{orgId}
</if>
<if test="orgName != null and orgName !=''">
and td1.department_name LIKE CONCAT('%',#{orgName},'%')
</if>
<if test="enableStatus != null">
and td1.enable_status = #{enableStatus}
</if>
<if test="tenantIds != null and tenantIds.size() > 0">
and td1.tenant_id in
<foreach collection="tenantIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="orgIds != null and orgIds.size() > 0">
and td1.id in
<foreach collection="orgIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
group by to1.sub_id
</select>
<select id="selectRootSubAllPaths" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_organization
where tenant_id = #{tenantId}
and depth = 0
and del_flag = 0
</select>
<select id="selectRootPathBySubId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_organization
where sub_id = #{subId} and del_flag = 0
and depth = (
select max(depth)
from t_organization
where sub_id = #{subId} and del_flag = 0
)
</select>
<select id="selectAllSuperiorBySubId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_organization
where del_flag = 0
and sub_id = #{subId}
order by sub_id, depth desc
</select>
<select id="selectAllSubBySuperiorId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_organization
where del_flag = 0
and superior_id = #{superiorId}
order by superior_id, depth
</select>
<select id="selectTenantsSubBySuperiorId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_organization
where del_flag = 0
and superior_id = #{superiorId}
and tenant_id in
<foreach collection="tenantIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
order by depth
</select>
<select id="selectSuperiorOrgByDepth" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_organization
where sub_id = #{superiorId}
and depth = #{depth}
and del_flag = 0
</select>
<select id="selectSuperiorOrgsByDepths" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_organization
where sub_id = #{superiorId}
and depth in
<foreach collection="depths" separator="," open="(" close=")" item="depth">
#{depth}
</foreach>
and del_flag = 0
order by depth
</select>
<select id="selectRootIdList" resultType="cn.com.glsx.shield.modules.entity.Organization">
select superior_id superiorId, sub_id subId ,max(depth) depth
from t_organization
where del_flag = 0
and sub_id in
<foreach collection="subIds" separator="," open="(" close=")" item="subId">
#{subId}
</foreach>
group by sub_id
</select>
<select id="selectChildrenList" resultType="cn.com.glsx.shield.modules.entity.Department"
parameterType="cn.com.glsx.shield.modules.model.param.OrganizationSearch">
select tde.id id, tde.department_name departmentName, order_num orderNum,
tde.created_date createdDate, tde.enable_status enableStatus
from t_organization tor, t_department tde
where tor.sub_id = tde.id
and tor.del_flag = 0 and tde.del_flag = 0
and tor.superior_id = #{rootId} and tor.depth = 1
<if test="tenantId != null">
and tde.tenant_id = #{tenantId}
</if>
<if test="orgName != null">
and tde.department_name like CONCAT('%',#{orgName},'%')
</if>
<if test="enableStatus != null">
and tde.enable_status = #{enableStatus}
</if>
<if test="tenantIds != null and tenantIds.size() > 0">
and tde.tenant_id in
<foreach collection="tenantIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="orgIds != null and orgIds.size() > 0">
and tde.id in
<foreach collection="orgIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
order by tde.order_num
</select>
<select id="selectSubOrgList" resultType="cn.com.glsx.shield.modules.entity.Organization">
select
distinct(sub_id) subId, superior_id superiorId
from t_organization
where del_flag = 0
and superior_id in
<foreach collection="superiorIds" item="superiorId" open="(" close=")" separator=",">
#{superiorId}
</foreach>
<if test="depth != null">
and depth = #{depth}
</if>
order by sub_id
</select>
<select id="selectList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_organization
where del_flag = 0
<if test="subIdList != null and subIdList.size() > 0">
and sub_id in
<foreach collection="subIdList" item="subId" open="(" close=")" separator=",">
#{subId}
</foreach>
</if>
<if test="superiorIdList != null">
and superior_id in
<foreach collection="superiorIdList" item="superiorId" open="(" close=")" separator=",">
#{superiorId}
</foreach>
</if>
<if test="biggerDepth != null">
and depth >= #{biggerDepth}
</if>
</select>
</mapper>