Commit b2a332a4d761446582617175fcf5907e5b664c20

Authored by 云中非
1 parent 83eb8fc0

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

... ... @@ -43,6 +43,7 @@ public class DeviceDTO extends TenantDTO {
43 43 @ApiModelProperty(value = "关联网关设备")
44 44 private String gatewayId;
45 45 private String gatewayName;
  46 + private String gatewayAlias;
46 47
47 48 @ApiModelProperty(value = "设备凭证")
48 49 private TkCredentialsDto deviceToken;
... ...
1 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 5 import lombok.Data;
3 6 import org.thingsboard.server.common.data.yunteng.enums.DeviceState;
4 7
  8 +import java.time.LocalDateTime;
  9 +
5 10 @Data
6 11 public class RelationDeviceDTO {
7 12 private String tbDeviceId;
8 13 private String tbDeviceName;
  14 + private String alias;
9 15 private String label;
10 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 21 private Long lastOnlineTime;
13 22
14 23 public void setDeviceState(boolean deviceState) {
... ...
... ... @@ -39,6 +39,7 @@
39 39 <result property="organizationId" column="organization_id"/>
40 40 <result property="gatewayId" column="gateway_id"/>
41 41 <result property="gatewayName" column="gateway_name"/>
  42 + <result property="gatewayAlias" column="gateway_alias"/>
42 43 <association property="deviceProfile"
43 44 javaType="org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO">
44 45 <result property="name" column="profile_name"/>
... ... @@ -50,8 +51,9 @@
50 51 </association>
51 52 </resultMap>
52 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 55 <result property="tbDeviceName" column="name"/>
  56 + <result property="alias" column="alias"/>
55 57 <result property="label" column="label"/>
56 58 <result property="deviceState" column="status"/>
57 59 <result property="createdTime" column="created_time"/>
... ... @@ -71,7 +73,7 @@
71 73 </sql>
72 74 <sql id="detailColumns">
73 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 77 </sql>
76 78 <sql id="pageColumns">
77 79 <include refid="basicColumns"/>
... ... @@ -209,27 +211,26 @@
209 211 </select>
210 212 <select id="getRelationDevicePage" resultMap="relationDeviceMap">
211 213 SELECT
212   - de.id,
  214 + de.tb_device_id,
213 215 de.name,
  216 + de.alias,
214 217 de.label,
215   - de.created_time,
  218 + de.create_time as created_time,
216 219 A.bool_v AS status,
217 220 b.long_v AS last_online_time
218 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 225 AND A.entity_type = 'DEVICE'
223 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 228 AND b.entity_type = 'DEVICE'
226 229 AND b.attribute_key = 'lastActivityTime'
227 230 <where>
228 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 234 <if test="queryMap.name !=null and queryMap.name !=''">
234 235 AND de.name LIKE concat('%',#{queryMap.name}::TEXT,'%')
235 236 </if>
... ...