Commit 1f31fc78 authored by 张森's avatar 张森

站端设备平台v5>运行趋势>运行监视,消防水池绑定了2个探测器,水池液位错误显示其中1个探测器的液位而不是平均值

parent 6dc0d3c1
...@@ -2564,6 +2564,7 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -2564,6 +2564,7 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
String[] split = equipInfo.getIotCode().split(","); String[] split = equipInfo.getIotCode().split(",");
for (String iotCode : split) { for (String iotCode : split) {
HashMap<String, List<BigDecimal>> stringIntegerHashMapIn = new HashMap<>();
String equipIndexKey = iotCodeIndexKeyMap.get(iotCode); String equipIndexKey = iotCodeIndexKeyMap.get(iotCode);
String[] equipIndexKeyNew = equipIndexKey.split(","); String[] equipIndexKeyNew = equipIndexKey.split(",");
if (!ObjectUtils.isEmpty(iotDataInfoMap) && iotDataInfoMap.containsKey(iotCode)) { if (!ObjectUtils.isEmpty(iotDataInfoMap) && iotDataInfoMap.containsKey(iotCode)) {
...@@ -2574,20 +2575,51 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -2574,20 +2575,51 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
for (String key : equipIndexKeyNew) { for (String key : equipIndexKeyNew) {
if (mapList.containsKey(key) && !ObjectUtils.isEmpty(mapList.get(key))) { if (mapList.containsKey(key) && !ObjectUtils.isEmpty(mapList.get(key))) {
if (stringIntegerHashMap.containsKey(dateX)) { if (stringIntegerHashMapIn.containsKey(dateX)) {
stringIntegerHashMap.get(dateX).add(new BigDecimal(mapList.get(key))); stringIntegerHashMapIn.get(dateX).add(new BigDecimal(mapList.get(key)));
} else { } else {
List<BigDecimal> bigDecimals = new ArrayList<>(); List<BigDecimal> bigDecimals = new ArrayList<>();
bigDecimals.add(new BigDecimal(mapList.get(key))); bigDecimals.add(new BigDecimal(mapList.get(key)));
stringIntegerHashMap.put(dateX, bigDecimals); stringIntegerHashMapIn.put(dateX, bigDecimals);
} }
} }
} }
} }
} }
for (Map.Entry<String, List<BigDecimal>> stringListEntry : stringIntegerHashMapIn.entrySet()) {
BigDecimal lastNum = BigDecimal.ZERO;
List<BigDecimal> orDefault = stringListEntry.getValue();
// 计算非空值的总和
BigDecimal sum = orDefault.stream()
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 计算非空值的数量
long count = orDefault.stream().filter(Objects::nonNull).count();
// 检查除数是否为0
BigDecimal divide;
if (count == 0) {
// 如果非空值数量为0,可以选择返回0或其他默认值
divide = lastNum;
} else {
// 否则,进行除法运算
divide = sum.divide(new BigDecimal(count), 2, RoundingMode.HALF_UP);
} }
if (stringIntegerHashMap.containsKey(stringListEntry.getKey())) {
stringIntegerHashMap.get(stringListEntry.getKey()).add(divide);
} else {
List<BigDecimal> bigDecimals = new ArrayList<>();
bigDecimals.add(divide);
stringIntegerHashMap.put(stringListEntry.getKey(), bigDecimals);
}
}
}
List<Object> values = new ArrayList<>(); List<Object> values = new ArrayList<>();
BigDecimal lastNum = BigDecimal.ZERO; BigDecimal lastNum = BigDecimal.ZERO;
for (int i = 0; i < allTimeList.size(); i++) { for (int i = 0; i < allTimeList.size(); i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment