Commit b2a332a4d761446582617175fcf5907e5b664c20

Authored by 云中非
1 parent 83eb8fc0

fix: 存在设备别名时优先显示别名

@@ -43,6 +43,7 @@ public class DeviceDTO extends TenantDTO { @@ -43,6 +43,7 @@ public class DeviceDTO extends TenantDTO {
43 @ApiModelProperty(value = "关联网关设备") 43 @ApiModelProperty(value = "关联网关设备")
44 private String gatewayId; 44 private String gatewayId;
45 private String gatewayName; 45 private String gatewayName;
  46 + private String gatewayAlias;
46 47
47 @ApiModelProperty(value = "设备凭证") 48 @ApiModelProperty(value = "设备凭证")
48 private TkCredentialsDto deviceToken; 49 private TkCredentialsDto deviceToken;
1 package org.thingsboard.server.common.data.yunteng.dto; 1 package org.thingsboard.server.common.data.yunteng.dto;
  2 +import com.fasterxml.jackson.annotation.JsonFormat;
  3 +import com.fasterxml.jackson.databind.annotation.JsonSerialize;
  4 +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
2 import lombok.Data; 5 import lombok.Data;
3 import org.thingsboard.server.common.data.yunteng.enums.DeviceState; 6 import org.thingsboard.server.common.data.yunteng.enums.DeviceState;
4 7
  8 +import java.time.LocalDateTime;
  9 +
5 @Data 10 @Data
6 public class RelationDeviceDTO { 11 public class RelationDeviceDTO {
7 private String tbDeviceId; 12 private String tbDeviceId;
8 private String tbDeviceName; 13 private String tbDeviceName;
  14 + private String alias;
9 private String label; 15 private String label;
10 private DeviceState deviceState; 16 private DeviceState deviceState;
11 - private Long createdTime; 17 +
  18 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  19 + @JsonSerialize(using = LocalDateTimeSerializer.class)
  20 + private LocalDateTime createdTime;
12 private Long lastOnlineTime; 21 private Long lastOnlineTime;
13 22
14 public void setDeviceState(boolean deviceState) { 23 public void setDeviceState(boolean deviceState) {
@@ -39,6 +39,7 @@ @@ -39,6 +39,7 @@
39 <result property="organizationId" column="organization_id"/> 39 <result property="organizationId" column="organization_id"/>
40 <result property="gatewayId" column="gateway_id"/> 40 <result property="gatewayId" column="gateway_id"/>
41 <result property="gatewayName" column="gateway_name"/> 41 <result property="gatewayName" column="gateway_name"/>
  42 + <result property="gatewayAlias" column="gateway_alias"/>
42 <association property="deviceProfile" 43 <association property="deviceProfile"
43 javaType="org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO"> 44 javaType="org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO">
44 <result property="name" column="profile_name"/> 45 <result property="name" column="profile_name"/>
@@ -50,8 +51,9 @@ @@ -50,8 +51,9 @@
50 </association> 51 </association>
51 </resultMap> 52 </resultMap>
52 <resultMap id="relationDeviceMap" type="org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO"> 53 <resultMap id="relationDeviceMap" type="org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO">
53 - <result property="tbDeviceId" column="id"/> 54 + <result property="tbDeviceId" column="tb_device_id"/>
54 <result property="tbDeviceName" column="name"/> 55 <result property="tbDeviceName" column="name"/>
  56 + <result property="alias" column="alias"/>
55 <result property="label" column="label"/> 57 <result property="label" column="label"/>
56 <result property="deviceState" column="status"/> 58 <result property="deviceState" column="status"/>
57 <result property="createdTime" column="created_time"/> 59 <result property="createdTime" column="created_time"/>
@@ -71,7 +73,7 @@ @@ -71,7 +73,7 @@
71 </sql> 73 </sql>
72 <sql id="detailColumns"> 74 <sql id="detailColumns">
73 <include refid="pageColumns"/> 75 <include refid="pageColumns"/>
74 - ,ifd.gateway_id,idg.name gateway_name 76 + ,ifd.gateway_id,idg.name gateway_name,idg.alias gateway_alias
75 </sql> 77 </sql>
76 <sql id="pageColumns"> 78 <sql id="pageColumns">
77 <include refid="basicColumns"/> 79 <include refid="basicColumns"/>
@@ -209,27 +211,26 @@ @@ -209,27 +211,26 @@
209 </select> 211 </select>
210 <select id="getRelationDevicePage" resultMap="relationDeviceMap"> 212 <select id="getRelationDevicePage" resultMap="relationDeviceMap">
211 SELECT 213 SELECT
212 - de.id, 214 + de.tb_device_id,
213 de.name, 215 de.name,
  216 + de.alias,
214 de.label, 217 de.label,
215 - de.created_time, 218 + de.create_time as created_time,
216 A.bool_v AS status, 219 A.bool_v AS status,
217 b.long_v AS last_online_time 220 b.long_v AS last_online_time
218 FROM 221 FROM
219 - device de  
220 - LEFT JOIN relation rt ON de."id" = rt.to_id  
221 - LEFT JOIN attribute_kv A ON de."id" = A.entity_id 222 + tk_device de
  223 + LEFT JOIN relation rt ON de.tb_device_id::uuid = rt.to_id
  224 + LEFT JOIN attribute_kv A ON de.tb_device_id::uuid = A.entity_id
222 AND A.entity_type = 'DEVICE' 225 AND A.entity_type = 'DEVICE'
223 AND A.attribute_key = 'active' 226 AND A.attribute_key = 'active'
224 - LEFT JOIN attribute_kv b ON de."id" = b.entity_id 227 + LEFT JOIN attribute_kv b ON de.tb_device_id::uuid = b.entity_id
225 AND b.entity_type = 'DEVICE' 228 AND b.entity_type = 'DEVICE'
226 AND b.attribute_key = 'lastActivityTime' 229 AND b.attribute_key = 'lastActivityTime'
227 <where> 230 <where>
228 rt.from_id ::TEXT = #{queryMap.fromId} 231 rt.from_id ::TEXT = #{queryMap.fromId}
229 - AND de.tenant_id ::TEXT = #{queryMap.tenantId}  
230 - <if test="queryMap.customerId !=null and queryMap.customerId !=''">  
231 - AND de.customer_id ::TEXT = #{queryMap.customerId}  
232 - </if> 232 + AND de.tenant_id = #{queryMap.tenantId}
  233 +
233 <if test="queryMap.name !=null and queryMap.name !=''"> 234 <if test="queryMap.name !=null and queryMap.name !=''">
234 AND de.name LIKE concat('%',#{queryMap.name}::TEXT,'%') 235 AND de.name LIKE concat('%',#{queryMap.name}::TEXT,'%')
235 </if> 236 </if>