From 1556e912df62cd2f5958eed27a0c77c7b4dd5216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Tue, 5 Nov 2024 11:32:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=AA=E9=98=B3=E8=83=BD=E6=9D=BF=EF=BC=8C?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=9C=A8=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcDeviceController.java | 31 ++++++++++++++++--- .../controller/DcDeviceOnlineController.java | 2 +- .../main/resources/mapper/OnlineSumMapper.xml | 10 ++++-- 3 files changed, 36 insertions(+), 7 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 81eb058c..e5d25f7b 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 @@ -455,10 +455,12 @@ public class DcDeviceController extends BaseController { calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), hour); -//转换为 double 类型,去除单位 + //转换为 double 类型,去除单位 String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", ""); - double formatValue = Double.parseDouble(decimalFormat.format(valueWithoutUnit)); - + // double formatValue = Double.parseDouble(valueWithoutUnit); + double parsedValue = Double.parseDouble(valueWithoutUnit); + // 保留两位小数 + double formatValue = Double.parseDouble(decimalFormat.format(parsedValue)); // 汇总每个小时的数据 deviceHourlyAggregates.merge(key, formatValue, Double::sum); } @@ -505,7 +507,10 @@ public class DcDeviceController extends BaseController { String property = data.get("property").getAsString(); String formatValueStr = data.get("formatValue").getAsString(); String valueWithoutUnit = formatValueStr.replaceAll("[^\\d.]", ""); - double value = Double.parseDouble(decimalFormat.format(valueWithoutUnit)); + + double value2 = Double.parseDouble(valueWithoutUnit); + double value = Double.parseDouble(decimalFormat.format(value2)); + attributeMap.merge(property, value, (oldVal, newVal) -> oldVal + newVal); } } @@ -897,8 +902,26 @@ public class DcDeviceController extends BaseController { //获取要回滚的数据 JSONObject mdJSONObject = (JSONObject) JSON.toJSON(getDeviceLatestProperty(iotDeviceId, UniversalEnum.MD.getValue()).get("data")); + if (mdJSONObject==null) { + JSONObject result = new JSONObject(); + result.put("device", device.getString("id")); + result.put("deviceType", device.getInteger("deviceType")); + result.put("functionId", UniversalEnum.MD.getValue()); + result.put("result", AjaxResult.error()); + resultArray.add(result); + break; + } String mdValue = mdJSONObject.getString("value"); JSONObject tmJSONObject = (JSONObject) JSON.toJSON(getDeviceLatestProperty(iotDeviceId, UniversalEnum.TM.getValue()).get("data")); + if (tmJSONObject==null) { + JSONObject result = new JSONObject(); + result.put("device", device.getString("id")); + result.put("deviceType", device.getInteger("deviceType")); + result.put("functionId", UniversalEnum.TM.getValue()); + result.put("result", AjaxResult.error()); + resultArray.add(result); + break; + } String tmValue = tmJSONObject.getString("value"); //循环执行功能 for (Object function : functions) { diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java index 6168318f..1211d7c1 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java @@ -496,7 +496,7 @@ public class DcDeviceOnlineController extends BaseController { List lossRate = new ArrayList<>(); List rttAvg = new ArrayList<>(); onlineLogs.stream().sorted(Comparator.comparing(OnlineLog::getMonitorTime)).forEach(onlineLog -> { - xAxis.add(onlineLog.getMonitorTime().format(DateTimeFormatter.ofPattern("HH:mm"))); + xAxis.add(onlineLog.getMonitorTime().format(DateTimeFormatter.ofPattern("HH:mm:ss"))); lossRate.add(onlineLog.getLossRate()); rttAvg.add(onlineLog.getRttAvg()); }); diff --git a/zc-business/src/main/resources/mapper/OnlineSumMapper.xml b/zc-business/src/main/resources/mapper/OnlineSumMapper.xml index 8b8aceeb..7dbbbec4 100644 --- a/zc-business/src/main/resources/mapper/OnlineSumMapper.xml +++ b/zc-business/src/main/resources/mapper/OnlineSumMapper.xml @@ -88,10 +88,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" offline_rate,loss_rate,rtt_avg,network_quality,statistical_date from dc_device d join dc_online_sum s on s.device_id = d.id + JOIN + (SELECT device_id, MAX(statistical_date) AS max_date + FROM dc_online_sum + WHERE DATE(statistical_date) = CURDATE() + GROUP BY device_id) s_max + ON + s.device_id = s_max.device_id AND s.statistical_date = s_max.max_date where - DATE(s.statistical_date) = CURDATE() - and (d.device_type in + (d.device_type in #{typeItem}