TkDeviceProfileMapper.xml
6.01 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
<?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.TkDeviceProfileMapper">
<resultMap type="org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity" id="detail">
<result property="id" column="id"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="creator" column="creator" />
<result property="updater" column="updater" />
<result property="name" column="name"/>
<result property="image" column="image"/>
<result property="description" column="description"/>
<result property="tenantId" column="tenant_id" />
<result property="transportType" column="transport_type"/>
<result property="provisionType" column="provision_type"/>
<result property="deviceType" column="device_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
<result property="tbProfileId" column="tb_profile_id" />
<result property="profileData" column="profile_data" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
<result property="defaultQueueName" column="default_queue_name"/>
<result property="defaultRuleChainId" column="default_rule_chain_id"/>
<result property="default" column="is_default"/>
<result property="type" column="type"/>
<result property="categoryId" column="category_id"/>
<result property="categoryName" column="categoryName"/>
<result property="firmwareId" column="firmware_id" />
<result property="softwareId" column="software_id" />
<result property="isEdge" column="is_edge"/>
</resultMap>
<sql id="basicColumns">
base.id,
base.id AS tb_profile_id,
base.name,
base.image,
base.description,
base.tenant_id,
base.transport_type,
base.provision_type,
base.profile_data,
base.default_queue_name,
base.default_rule_chain_id,
base.is_default,
base.type,
base.script_id,
base.device_type,
base.created_time AS create_time,
base.category_id
</sql>
<select id="getProfilePage" resultMap="detail">
SELECT
<include refid="basicColumns"/>,cate.name as categoryName ,
CASE
WHEN re.to_id is not null THEN 1
ELSE 0
END AS is_edge
FROM device_profile base
LEFT JOIN relation re on re.to_id = base.id and from_type = 'EDGE' and re.relation_type = 'ManagedByEdge'
LEFT JOIN tk_device_profile_category cate on cate.id = base.category_id
<where>
<if test="tenantId !=null">
AND base.tenant_id = #{tenantId}
</if>
<if test="profileName !=null and profileName !=''">
AND base.name LIKE CONCAT('%',#{profileName},'%')
</if>
<if test="transportType !=null and transportType !=''">
AND base.transport_type = #{transportType}
</if>
<if test="deviceProfileIds != null">
AND base.id IN
<foreach collection="deviceProfileIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
</select>
<select id="selectDetail" resultMap="detail">
SELECT
<include refid="basicColumns"/>,base.firmware_id,base.software_id
FROM device_profile base
<where>
<if test="tenantId !=null">
AND base.tenant_id = #{tenantId}
</if>
<if test="id !=null">
AND (base.id = #{id} OR base.id = #{id})
</if>
</where>
</select>
<select id="profileByScriptId" resultMap="detail">
SELECT
<include refid="basicColumns"/>
FROM device_profile base
<if test="isSceneLinkage == true">
LEFT JOIN relation re on re.to_id = base.id and from_type = 'EDGE' and re.relation_type = 'ManagedByEdge'
</if>
<where>
base.tenant_id = #{tenantId}
<if test="isSceneLinkage == true">
and re.to_id is null
</if>
<if test="scriptId !=null and scriptId !=''">
AND base.script_id = #{scriptId}
</if>
<if test="ruleChainId !=null and ruleChainId !=''">
AND base.default_rule_chain_id::TEXT = #{ruleChainId}
</if>
<if test="deviceType !=null">
AND base.device_type = #{deviceType}
</if>
<if test="transportType !=null">
AND base.transport_type = #{transportType}
</if>
<if test="deviceProfileIds != null">
AND base.id IN
<foreach collection="deviceProfileIds" item="deviceProfile_id" open="(" separator="," close=")">
#{deviceProfile_id}
</foreach>
</if>
</where>
</select>
<select id="profileByTransportAndIds" resultMap="detail">
SELECT
<include refid="basicColumns"/>
FROM device_profile base
<where>
iot.tenant_id = #{tenantId}
<if test="projectIds != null">
AND base.id IN
<foreach collection="projectIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="transportType !=null">
AND base.transport_type = #{transportType}
</if>
</where>
</select>
<select id="getDeviceProfileIds" resultType="java.lang.String">
SELECT base.id
FROM device_profile base
WHERE base.tenant_id = #{tenantId}
AND base.transport_type = #{transportType}
</select>
</mapper>