From 2ab4b238da1fefd13a6dbee9cd3102ba6dbec75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Fri, 8 Nov 2024 11:20:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=AA=E9=98=B3=E8=83=BD=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E4=B8=A4=E4=BD=8D=E5=B0=8F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/zc/business/controller/DcDeviceController.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index acc2eb02..88b58a97 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -476,11 +476,10 @@ private VideoController videoController; // 保留两位小数 double formatValue = Double.parseDouble(decimalFormat.format(parsedValue)); // 汇总每个小时的数据 - deviceHourlyAggregates.merge(key, formatValue, Double::sum); - } + deviceHourlyAggregates.merge(key, formatValue, (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); } // 将设备的数据合并到所有设备的汇总数据中 for (String key : deviceHourlyAggregates.keySet()) { - allDevicesHourlyAggregates.merge(key, deviceHourlyAggregates.get(key), Double::sum); + allDevicesHourlyAggregates.merge(key, deviceHourlyAggregates.get(key), (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); } } @@ -524,8 +523,8 @@ private VideoController videoController; double value2 = Double.parseDouble(valueWithoutUnit); double value = Double.parseDouble(decimalFormat.format(value2)); - - attributeMap.merge(property, value, (oldVal, newVal) -> oldVal + newVal); + // 在合并时重新应用格式化 + attributeMap.merge(property, value, (oldVal, newVal) -> Double.parseDouble(decimalFormat.format(oldVal + newVal))); } } }