Showing
4 changed files
with
42 additions
and
15 deletions
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/KvDictionaryValueDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModelProperty; | |
4 | +import lombok.Data; | |
5 | + | |
6 | +@Data | |
7 | +public class KvDictionaryValueDTO { | |
8 | + @ApiModelProperty(value = "查询的条件key") | |
9 | + private String key; | |
10 | + @ApiModelProperty(value = "查询的key值") | |
11 | + private Integer value; | |
12 | +} | ... | ... |
... | ... | @@ -621,15 +621,28 @@ public class TkHomePageServiceImpl implements HomePageService { |
621 | 621 | String tenantId, HomePageTopMessage messageInfo, BaseHomePageTop alarm) |
622 | 622 | throws ExecutionException, InterruptedException { |
623 | 623 | List<String> dictionaries = new ArrayList<>(); |
624 | - dictionaries.add("transportMsgCount"); | |
625 | - dictionaries.add("transportDataPointsCount"); | |
626 | - dictionaries.add("createdAlarmsCount"); | |
624 | + String key= "transportMsgCount"; | |
625 | + String key1= "transportDataPointsCount"; | |
626 | + String key2= "createdAlarmsCount"; | |
627 | + dictionaries.add(key); | |
628 | + dictionaries.add(key1); | |
629 | + dictionaries.add(key2); | |
627 | 630 | //查询所有数据 |
628 | - List<Integer> sumCount = deviceMapper.getMsgSumByTenantIdAndDictionary(tenantId,dictionaries); | |
631 | + List<KvDictionaryValueDTO> sumCount = deviceMapper.getMsgSumByTenantIdAndDictionary(tenantId,dictionaries); | |
629 | 632 | if(!sumCount.isEmpty()){ |
630 | - messageInfo.setMessageCount(sumCount.get(0)); | |
631 | - messageInfo.setDataPointsCount(sumCount.get(1)); | |
632 | - alarm.setSumCount(sumCount.get(2)); | |
633 | + for (KvDictionaryValueDTO kvDictionary : sumCount) { | |
634 | + if(Objects.equals(key,kvDictionary.getKey())){ | |
635 | + messageInfo.setMessageCount(kvDictionary.getValue()); | |
636 | + continue; | |
637 | + } | |
638 | + if(Objects.equals(key1,kvDictionary.getKey())){ | |
639 | + messageInfo.setDataPointsCount(kvDictionary.getValue()); | |
640 | + continue; | |
641 | + } | |
642 | + if(Objects.equals(key2,kvDictionary.getKey())){ | |
643 | + alarm.setSumCount(kvDictionary.getValue()); | |
644 | + } | |
645 | + } | |
633 | 646 | } |
634 | 647 | TenantId currentTenantId = TenantId.fromUUID(UUID.fromString(tenantId)); |
635 | 648 | ApiUsageState apiUsageState = apiUsageStateService.findTenantApiUsageState(currentTenantId); | ... | ... |
... | ... | @@ -4,10 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
4 | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; |
5 | 5 | import org.apache.ibatis.annotations.Mapper; |
6 | 6 | import org.apache.ibatis.annotations.Param; |
7 | -import org.thingsboard.server.common.data.yunteng.dto.BaseHomePageTop; | |
8 | -import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | |
9 | -import org.thingsboard.server.common.data.yunteng.dto.RelationDeviceDTO; | |
10 | -import org.thingsboard.server.common.data.yunteng.dto.SelectItemDTO; | |
7 | +import org.thingsboard.server.common.data.yunteng.dto.*; | |
11 | 8 | import org.thingsboard.server.dao.yunteng.entities.TkDeviceEntity; |
12 | 9 | |
13 | 10 | import java.util.List; |
... | ... | @@ -147,5 +144,5 @@ public interface DeviceMapper extends BaseMapper<TkDeviceEntity> { |
147 | 144 | |
148 | 145 | DeviceDTO findDeviceInfo(@Param("tenantId") String tenantId,@Param("tbDeviceId") String tbDeviceId); |
149 | 146 | |
150 | - List<Integer> getMsgSumByTenantIdAndDictionary(@Param("tenantId") String tenantId, @Param("dictionaries")List<String> dictionaries); | |
147 | + List<KvDictionaryValueDTO> getMsgSumByTenantIdAndDictionary(@Param("tenantId") String tenantId, @Param("dictionaries")List<String> dictionaries); | |
151 | 148 | } | ... | ... |
... | ... | @@ -65,6 +65,11 @@ |
65 | 65 | <result property="sumCount" column="sum_count"/> |
66 | 66 | <result property="todayAdd" column="today_add"/> |
67 | 67 | </resultMap> |
68 | + | |
69 | + <resultMap id="kvDictionaryMap" type="org.thingsboard.server.common.data.yunteng.dto.KvDictionaryValueDTO"> | |
70 | + <result property="key" column="key"></result> | |
71 | + <result property="value" column="msg_count"></result> | |
72 | + </resultMap> | |
68 | 73 | |
69 | 74 | <sql id="basicColumns"> |
70 | 75 | ifd.id,ifd.gateway_id,ifd.code |
... | ... | @@ -461,8 +466,8 @@ |
461 | 466 | AND ifd.tenant_id = #{tenantId} |
462 | 467 | </select> |
463 | 468 | |
464 | - <select id="getMsgSumByTenantIdAndDictionary" resultType="java.lang.Integer"> | |
465 | - SELECT SUM ( long_v ) AS msgCount FROM | |
469 | + <select id="getMsgSumByTenantIdAndDictionary" resultMap="kvDictionaryMap"> | |
470 | + SELECT tkd."key",SUM ( long_v ) AS msg_count FROM | |
466 | 471 | ts_kv tk |
467 | 472 | LEFT JOIN api_usage_state aus ON tk.entity_id = aus.ID |
468 | 473 | LEFT JOIN ts_kv_dictionary tkd ON tkd.key_id = tk."key" |
... | ... | @@ -473,6 +478,6 @@ |
473 | 478 | #{dictionary} |
474 | 479 | </foreach> |
475 | 480 | GROUP BY |
476 | - tk."key"; | |
481 | + tkd."key"; | |
477 | 482 | </select> |
478 | 483 | </mapper> | ... | ... |