OrganizationMapper.xml
9.25 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
<?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.neshield.modules.mapper.OrganizationMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.neshield.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="insertOrganizationPath" 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} and tor.depth <![CDATA[ <> ]]> 0
union all
select #{superiorId}, #{subId}, 1, #{tenantId}, #{createdDate}, #{createdBy}
</insert>
<delete id="deleteOrganizationPath">
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="getUserDepartmentId" resultType="java.lang.Long">
select superior_id
from t_organization
where sub_id = #{userId} and del_flag = 0
and depth = (
select min(depth)
from t_organization
where sub_id = #{userId}
and del_flag = 0
)
</select>
<select id="getUserSubDepartment" resultType="java.lang.Long">
select sub_id
from t_organization
where superior_id = #{userId} and type = 1 and del_flag = 0
and depth = (
select min(depth)
from t_organization
where superior_id = #{userId} and type = 1
and del_flag = 0
)
</select>
<select id="getUserSuperiorUser" resultType="java.lang.Long">
select superior_id
from t_organization
where sub_id = #{userId} and type = 0 and del_flag = 0
and depth = (
select max(depth)
from t_organization
where sub_id = #{userId} and type = 0
and del_flag = 0
order by depth limit 2
)
</select>
<select id="selectOrgList" resultType="cn.com.glsx.neshield.modules.model.OrgModel">
select tor.sub_id orgId,max(tor.superior_id) parentId,min(tor2.superior_id) superiorId,max(tor.depth) depth,
tt.id tenantId,tt.tenant_name tenantName,td.department_name orgName,td.is_root isRoot
from t_organization tor,t_organization tor2
left join t_department td on tor2.sub_id = td.id
left join t_user tu on tor2.sub_id = tu.id
left join t_tenant tt on tor2.tenant_id = tt.id
where td.del_flag = 0
and td.enable_status = 1
and tor.id = tor2.id
and tt.id = tor.tenant_id
<if test="tenantId != null">
and tt.id = #{tenantId}
</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="selectSuperiorIdsByOrg" resultType="cn.com.glsx.neshield.modules.model.OrgSuperiorModel">
select td1.id orgId,concat(group_concat(to1.superior_id),',',to1.sub_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 department_name LIKE CONCAT('%',#{orgName},'%')
</if>
group by to1.sub_id
</select>
<select id="selectByRootId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_organization
where del_flag = 0 and superior_id = #{organizationId}
</select>
<select id="selectRootPath" 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="selectRootIdList" resultType="cn.com.glsx.neshield.modules.entity.Organization">
select max(depth) depth, superior_id superiorId, sub_id subId 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="selectSuperiorOrganization" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_organization
where sub_id = #{organizationId} and del_flag = 0
and depth = 1
</select>
<select id="selectChildrenList" resultType="cn.com.glsx.neshield.modules.entity.Department"
parameterType="cn.com.glsx.neshield.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="orgName != null">
and tde.department_name like CONCAT('%',#{orgName},'%')
</if>
<if test="enableStatus != null">
and tde.enable_status = #{enableStatus}
</if>
order by tde.order_num
</select>
<select id="selectSubList" resultType="cn.com.glsx.neshield.modules.entity.Organization">
select
distinct(sub_id) subId, superior_id superiorId
from t_organization
where del_flag = 0
and superior_id in
<foreach collection="departmentIds" item="departmentId" open="(" close=")" separator=",">
#{departmentId}
</foreach>
<if test="depth != null">
and depth = #{depth}
</if>
</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>
<select id="selectRootByRootIdAndSubId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_organization
where del_flag = 0
and superior_id = #{rootId}
and sub_id = #{subId}
</select>
<select id="selectAllSuperiorBySubId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_organization
where del_flag = 0
and sub_id = #{subId}
</select>
<update id="logicDeleteSelfBySubId">
update t_organization set del_flag = -1 where sub_id = #{subId}
</update>
<update id="logicDeleteAllSubOrganization">
update t_organization set del_flag = -1 where superior_id=#{organizationId}
</update>
</mapper>