TkDeviceProfileMapper.xml
4.18 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
<?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.common.data.yunteng.dto.DeviceProfileDTO" 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="scriptId" column="script_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"/>
</resultMap>
<sql id="basicColumns">
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
,iot.id,iot.script_id,iot.device_type,iot.create_time,iot.update_time,iot.creator,iot.updater,iot.tb_profile_id
</sql>
<select id="getProfilePage" resultMap="detail">
SELECT
<include refid="basicColumns"/>
FROM device_profile base
LEFT JOIN tk_device_profile iot ON iot.tb_profile_id = base.id::TEXT
<where>
<if test="tenantId !=null and tenantId !=''">
AND iot.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::TEXT IN
<foreach collection="deviceProfileIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
</select>
<select id="selectDetail" resultMap="detail">
SELECT
<include refid="basicColumns"/>
FROM device_profile base
LEFT JOIN tk_device_profile iot ON iot.tb_profile_id = base.id::TEXT
<where>
<if test="tenantId !=null and tenantId !=''">
AND iot.tenant_id = #{tenantId}
</if>
<if test="id !=null and id !=''">
AND (iot.id = #{id} OR iot.tb_profile_id = #{id})
</if>
</where>
</select>
<select id="profileByScriptId" resultMap="detail">
SELECT
<include refid="basicColumns"/>
FROM device_profile base
LEFT JOIN tk_device_profile iot ON iot.tb_profile_id = base.id::TEXT
<where>
iot.tenant_id = #{tenantId}
<if test="scriptId !=null and scriptId !=''">
AND iot.script_id = #{scriptId}
</if>
<if test="deviceType !=null">
AND iot.device_type = #{deviceType}
</if>
</where>
</select>
<select id="getDeviceProfileIds" resultType="java.lang.String">
SELECT iot.id
FROM device_profile base
LEFT JOIN tk_device_profile iot ON iot.tb_profile_id = base.id::TEXT
WHERE iot.tenant_id = #{tenantId}
AND base.transport_type = #{transportType}
</select>
</mapper>