OrganizationMapper.xml
2.03 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
<?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="org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper">
<resultMap type="org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO" id="organizationDTOMap">
<result property="id" column="id"/>
<result property="parentId" column="parent_id"/>
<result property="sort" column="sort"/>
<result property="name" column="name"/>
<result property="creator" column="creator"/>
<result property="createTime" column="create_time"/>
<result property="updater" column="updater"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
<select id="findOrganizationTreeList" resultMap="organizationDTOMap">
WITH RECURSIVE organization AS (
SELECT id, parent_id, name, sort,creator,create_time,updater,update_time,remark,tenant_id
FROM tk_organization
WHERE tenant_id = #{tenantId}
<if test="organizationIds !=null and organizationIds.size() > 0">
AND id IN
<foreach collection="organizationIds" item="organizationId" open="(" separator="," close=")">
#{organizationId}
</foreach>
</if>
UNION ALL
SELECT ig.id, ig.parent_id, ig.name, ig.sort,ig.creator,ig.create_time,ig.updater,ig.update_time,ig.remark,ig.tenant_id
FROM tk_organization ig
<if test="sort =='UP'">
JOIN organization ON ig.id = organization.parent_id
</if>
<if test="sort == 'DOWN'">
JOIN organization ON ig.parent_id = organization.id
</if>
WHERE ig.tenant_id = #{tenantId}
)
SELECT id, parent_id, name, sort,creator,create_time,updater,update_time,remark,tenant_id
FROM organization WHERE tenant_id = #{tenantId}
</select>
</mapper>