Skip to content

Commit

Permalink
[fix]: fix query latest data
Browse files Browse the repository at this point in the history
  • Loading branch information
lgt1126 committed Jan 11, 2022
1 parent 6661bb2 commit 2892b56
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ public List<LatestDto> qeuryLatest(String deviceId, List<Long> attrIds) {
return Collections.emptyList();
}

//取出属性对应的ItemID
List<String> zbxIds = list.parallelStream().map(ProductAttribute::getZbxId).collect(Collectors.toList());
Map<String, List<ProductAttribute>> valueTypeMap = list.parallelStream().collect(Collectors.groupingBy(ProductAttribute::getValueType));
Map<String, ProductAttribute> itemIdMap = list.parallelStream().collect(Collectors.toMap(ProductAttribute::getZbxId, o -> o));
List<LatestDto> latestDtos;
if (checkTDengine()) {
latestDtos = queryLatestFromTD(deviceId, zbxIds, valueTypeMap);
latestDtos = queryLatestFromTD(deviceId, valueTypeMap);
} else {
latestDtos = queryLatestFromZbx(one.getZbxId(), zbxIds, valueTypeMap);
latestDtos = queryLatestFromZbx(one.getZbxId(), valueTypeMap);
}


Expand Down Expand Up @@ -140,11 +138,13 @@ private boolean checkTDengine() {
}

//从TDengine取数
public List<LatestDto> queryLatestFromTD(String deviceId, List<String> itemIds, Map<String, List<ProductAttribute>> valueTypeMap) {
public List<LatestDto> queryLatestFromTD(String deviceId, Map<String, List<ProductAttribute>> valueTypeMap) {

List<LatestDto> latestDtos = new ArrayList<>();
//根据属性值类型 分组查询最新数据
for (Map.Entry<String, List<ProductAttribute>> map : valueTypeMap.entrySet()) {
//取出属性对应的ItemID
List<String> itemIds = map.getValue().parallelStream().map(ProductAttribute::getZbxId).collect(Collectors.toList());
latestDtos.addAll(queryLatestFromTD(deviceId, itemIds, Integer.parseInt(map.getKey())));
}
return latestDtos;
Expand Down Expand Up @@ -193,10 +193,12 @@ private static String getHistoryTableName(int unitType) {
}

//从Zbx接口取数
private List<LatestDto> queryLatestFromZbx(String zbxId, List<String> itemIds, Map<String, List<ProductAttribute>> valueTypeMap) {
private List<LatestDto> queryLatestFromZbx(String zbxId, Map<String, List<ProductAttribute>> valueTypeMap) {
List<LatestDto> latestDtos = new ArrayList<>();
//根据属性值类型 分组查询最新数据
for (Map.Entry<String, List<ProductAttribute>> map : valueTypeMap.entrySet()) {
//取出属性对应的ItemID
List<String> itemIds = map.getValue().parallelStream().map(ProductAttribute::getZbxId).collect(Collectors.toList());
String res = zbxHistoryGet.historyGet(zbxId, itemIds, map.getValue().size(), Integer.parseInt(map.getKey()), null, null);
latestDtos.addAll(JSONObject.parseArray(res, LatestDto.class));
}
Expand Down

0 comments on commit 2892b56

Please sign in to comment.