Commit 93ae35759e2628dd1c85719b48d06a41d708dd84

Authored by xp.Huang
2 parents f8fc4cee 771fae26

Merge branch 'master_dev' into 'master'

fix:小程序统计告警信息及告警分页查询

See merge request yunteng/thingskit!422
1 package org.thingsboard.server.common.data.yunteng.dto.statistics; 1 package org.thingsboard.server.common.data.yunteng.dto.statistics;
2 2
3 import lombok.Data; 3 import lombok.Data;
  4 +import org.thingsboard.server.common.data.alarm.AlarmStatus;
4 5
5 /** 6 /**
6 * @Description : 数据聚合统计对象 7 * @Description : 数据聚合统计对象
@@ -15,4 +16,22 @@ import lombok.Data; @@ -15,4 +16,22 @@ import lombok.Data;
15 public class AggregationDTO { 16 public class AggregationDTO {
16 private String key; 17 private String key;
17 private Integer value; 18 private Integer value;
  19 + private Boolean acknowledged;
  20 + private Boolean cleared;
  21 + public String getKey(){
  22 + String status = null;
  23 + if(!acknowledged&&!cleared){
  24 + status = AlarmStatus.ACTIVE_UNACK.name();//激活未确认
  25 + }
  26 + if(acknowledged&&!cleared){
  27 + status = AlarmStatus.ACTIVE_ACK.name();//激活已确认
  28 + }
  29 + if(!acknowledged&&cleared){
  30 + status = AlarmStatus.CLEARED_UNACK.name();//清除未确认
  31 + }
  32 + if(acknowledged&&cleared){
  33 + status = AlarmStatus.CLEARED_ACK.name();//清除已确认
  34 + }
  35 + return status;
  36 + }
18 } 37 }
@@ -85,7 +85,8 @@ public class TkAlarmEntity { @@ -85,7 +85,8 @@ public class TkAlarmEntity {
85 private String organizationId; 85 private String organizationId;
86 private String organizationName; 86 private String organizationName;
87 private String deviceAlias; 87 private String deviceAlias;
88 - 88 + @TableField(exist = false)
  89 + private AlarmStatus status;
89 public String getStartTs() { 90 public String getStartTs() {
90 return DateTimeUtils.format(this.startTs); 91 return DateTimeUtils.format(this.startTs);
91 } 92 }
@@ -109,4 +110,21 @@ public class TkAlarmEntity { @@ -109,4 +110,21 @@ public class TkAlarmEntity {
109 public String getUpdatedTime() { 110 public String getUpdatedTime() {
110 return DateTimeUtils.format(this.updatedTime); 111 return DateTimeUtils.format(this.updatedTime);
111 } 112 }
  113 +
  114 + public AlarmStatus getStatus() {
  115 + AlarmStatus alarmStatus = null;
  116 + if(!acknowledged&&!cleared){
  117 + alarmStatus = AlarmStatus.ACTIVE_UNACK;//激活未确认
  118 + }
  119 + if(acknowledged&&!cleared){
  120 + alarmStatus = AlarmStatus.ACTIVE_ACK;//激活已确认
  121 + }
  122 + if(!acknowledged&&cleared){
  123 + alarmStatus = AlarmStatus.CLEARED_UNACK;//清除未确认
  124 + }
  125 + if(acknowledged&&cleared){
  126 + alarmStatus = AlarmStatus.CLEARED_ACK;//清除已确认
  127 + }
  128 + return alarmStatus;
  129 + }
112 } 130 }
@@ -305,7 +305,7 @@ public class TkHomePageServiceImpl implements HomePageService { @@ -305,7 +305,7 @@ public class TkHomePageServiceImpl implements HomePageService {
305 app.setTodayCustomer(today); 305 app.setTodayCustomer(today);
306 } 306 }
307 307
308 - List<DeviceDTO> devices = getDeviceInfo(todayFilter); 308 + List<TkDeviceEntity> devices = getDeviceInfo(todayFilter);
309 AtomicInteger totalOnline = new AtomicInteger(); 309 AtomicInteger totalOnline = new AtomicInteger();
310 AtomicInteger totalOffline = new AtomicInteger(); 310 AtomicInteger totalOffline = new AtomicInteger();
311 AtomicInteger totalinactive = new AtomicInteger(); 311 AtomicInteger totalinactive = new AtomicInteger();
@@ -325,9 +325,9 @@ public class TkHomePageServiceImpl implements HomePageService { @@ -325,9 +325,9 @@ public class TkHomePageServiceImpl implements HomePageService {
325 totalinactive.incrementAndGet(); 325 totalinactive.incrementAndGet();
326 break; 326 break;
327 } 327 }
328 -  
329 - return device.getCreateTime().isAfter(startTime)  
330 - && device.getCreateTime().isBefore(endTime); 328 + LocalDateTime createTime = LocalDateTime.ofEpochSecond(device.getCreateTime()/ 1000, 0, ZoneOffset.UTC);
  329 + return createTime.isAfter(startTime)
  330 + && createTime.isBefore(endTime);
331 }) 331 })
332 .count(); 332 .count();
333 DeviceStatisticsDTO today = new DeviceStatisticsDTO(0); 333 DeviceStatisticsDTO today = new DeviceStatisticsDTO(0);
@@ -354,7 +354,7 @@ public class TkHomePageServiceImpl implements HomePageService { @@ -354,7 +354,7 @@ public class TkHomePageServiceImpl implements HomePageService {
354 EntityId entityId, LocalDateTime startTime, LocalDateTime endTime) { 354 EntityId entityId, LocalDateTime startTime, LocalDateTime endTime) {
355 Map<String, Object> filter = new HashMap<>(); 355 Map<String, Object> filter = new HashMap<>();
356 if (entityId != null) { 356 if (entityId != null) {
357 - String idStr = entityId.getId().toString(); 357 + UUID idStr = entityId.getId();
358 switch (entityId.getEntityType()) { 358 switch (entityId.getEntityType()) {
359 case TENANT: 359 case TENANT:
360 filter.put("tenantId", idStr); 360 filter.put("tenantId", idStr);
@@ -385,8 +385,8 @@ public class TkHomePageServiceImpl implements HomePageService { @@ -385,8 +385,8 @@ public class TkHomePageServiceImpl implements HomePageService {
385 * 385 *
386 * @param filter 数据过滤参数 386 * @param filter 数据过滤参数
387 */ 387 */
388 - private List<DeviceDTO> getDeviceInfo(Map<String, Object> filter) {  
389 - return deviceMapper.findDevices(filter).stream().map(e->CopyUtils.copyAndReturn(e,new DeviceDTO())).collect(Collectors.toList()); 388 + private List<TkDeviceEntity> getDeviceInfo(Map<String, Object> filter) {
  389 + return deviceMapper.findDevices(filter);
390 } 390 }
391 391
392 /** 392 /**
@@ -56,7 +56,8 @@ @@ -56,7 +56,8 @@
56 <result property="organizationName" column="organization_name"/> 56 <result property="organizationName" column="organization_name"/>
57 <result property="description" column="description"/> 57 <result property="description" column="description"/>
58 <result property="isEdge" column="is_edge"/> 58 <result property="isEdge" column="is_edge"/>
59 - 59 + <result property="createTime" column="createTime"/>
  60 + <result property="updateTime" column="updateTime"/>
60 61
61 <!-- <association property="deviceProfile" column="device_profile_id"--> 62 <!-- <association property="deviceProfile" column="device_profile_id"-->
62 <!-- javaType="org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity">--> 63 <!-- javaType="org.thingsboard.server.dao.yunteng.entities.TkDeviceProfileEntity">-->
@@ -272,6 +273,8 @@ @@ -272,6 +273,8 @@
272 io.NAME AS organization_name, 273 io.NAME AS organization_name,
273 attrAt.long_v last_online_time, 274 attrAt.long_v last_online_time,
274 ifd.customer_id, 275 ifd.customer_id,
  276 + ifd.created_time as createTime,
  277 + ifd.update_time as updateTime,
275 CASE 278 CASE
276 WHEN attrAt.long_v is null THEN 'INACTIVE' 279 WHEN attrAt.long_v is null THEN 'INACTIVE'
277 WHEN attrA0.bool_v =true THEN 'ONLINE' 280 WHEN attrA0.bool_v =true THEN 'ONLINE'
@@ -33,7 +33,8 @@ @@ -33,7 +33,8 @@
33 </resultMap> 33 </resultMap>
34 34
35 <resultMap type="org.thingsboard.server.common.data.yunteng.dto.statistics.AggregationDTO" id="aggregationMap"> 35 <resultMap type="org.thingsboard.server.common.data.yunteng.dto.statistics.AggregationDTO" id="aggregationMap">
36 - <result property="key" column="cleared"/> 36 + <result property="acknowledged" column="acknowledged"/>
  37 + <result property="cleared" column="cleared"/>
37 <result property="value" column="value"/> 38 <result property="value" column="value"/>
38 </resultMap> 39 </resultMap>
39 40
@@ -103,7 +104,7 @@ @@ -103,7 +104,7 @@
103 </select> 104 </select>
104 105
105 <select id="countAlarms" resultMap="aggregationMap"> 106 <select id="countAlarms" resultMap="aggregationMap">
106 - SELECT cleared , COUNT(m.id) AS value FROM alarm m 107 + SELECT acknowledged,cleared , COUNT(m.id) AS value FROM alarm m
107 <if test="queryMap.customerId !=null or queryMap.deviceIds !=null "> 108 <if test="queryMap.customerId !=null or queryMap.deviceIds !=null ">
108 LEFT JOIN device d ON m.originator_id = d.id 109 LEFT JOIN device d ON m.originator_id = d.id
109 </if> 110 </if>
@@ -127,7 +128,7 @@ @@ -127,7 +128,7 @@
127 </foreach> 128 </foreach>
128 </if> 129 </if>
129 </where> 130 </where>
130 - GROUP BY cleared; 131 + GROUP BY acknowledged, cleared;
131 </select> 132 </select>
132 <select id="getByTbDeviceId" resultType="java.lang.String"> 133 <select id="getByTbDeviceId" resultType="java.lang.String">
133 SELECT id FROM alarm where 1=1 134 SELECT id FROM alarm where 1=1
@@ -249,7 +249,7 @@ @@ -249,7 +249,7 @@
249 <where> 249 <where>
250 ro.role_type = 'CUSTOMER_USER' 250 ro.role_type = 'CUSTOMER_USER'
251 <if test="queryMap.tenantId !=null"> 251 <if test="queryMap.tenantId !=null">
252 - AND u.tenant_id= #{queryMap.tenantId} 252 + AND u.tenant_id= #{queryMap.tenantId}::TEXT
253 </if> 253 </if>
254 <if test="queryMap.startTime !=null"> 254 <if test="queryMap.startTime !=null">
255 AND u.create_time >= #{queryMap.startTime} 255 AND u.create_time >= #{queryMap.startTime}