From 799fd65ef902c9e003a837dc11882fa2e5517a1e Mon Sep 17 00:00:00 2001 From: Arno Date: Thu, 22 Aug 2019 09:51:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=A9=BA=E6=96=AD=E5=B1=82=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/keepbx/jpom/system/TopManager.java | 59 +++++++++++++------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/modules/agent/src/main/java/cn/keepbx/jpom/system/TopManager.java b/modules/agent/src/main/java/cn/keepbx/jpom/system/TopManager.java index d110adc78..4fef17c87 100644 --- a/modules/agent/src/main/java/cn/keepbx/jpom/system/TopManager.java +++ b/modules/agent/src/main/java/cn/keepbx/jpom/system/TopManager.java @@ -98,43 +98,39 @@ public class TopManager { String lastTime = ""; List array = new ArrayList<>(); List scale = new ArrayList<>(); + JSONObject value = null; while (cacheObjIterator.hasNext()) { CacheObj cacheObj = cacheObjIterator.next(); String key = cacheObj.getKey(); if (StrUtil.isNotEmpty(lastTime)) { - if (!key.equals(getLastTime(lastTime))) { + if (!key.equals(getNextScaleTime(lastTime))) { array.clear(); scale.clear(); } } lastTime = key; scale.add(key); - JSONObject value = cacheObj.getValue(); + value = cacheObj.getValue(); array.add(value); } + if (value != null) { + String time = value.getString("time"); + //清除断开的监控数据 + if (!getNextScaleTime(time).equals(getNowNextScale())) { + array.clear(); + scale.clear(); + } + } int count = 24; if (array.size() > count) { array = array.subList(array.size() - count - 1, array.size() - 1); } while (scale.size() < count) { if (scale.size() == 0) { - DateTime date = DateUtil.date(); - int second = date.second(); - if (second <= 30 && second > 0) { - second = 30; - } else if (second > 30) { - second = 0; - date = date.offset(DateField.MINUTE, 1); - } - String format = DateUtil.format(date, "HH:mm"); - String secondStr = ":" + second; - if (second < 10) { - secondStr = ":0" + second; - } - scale.add(format + secondStr); + scale.add(getNowNextScale()); } String time = scale.get(scale.size() - 1); - String newTime = getLastTime(time); + String newTime = getNextScaleTime(time); scale.add(newTime); } JSONObject object = new JSONObject(); @@ -143,7 +139,34 @@ public class TopManager { return object; } - private static String getLastTime(String time) { + /** + * 当前时间的下一个刻度 + * + * @return String + */ + private static String getNowNextScale() { + DateTime date = DateUtil.date(); + int second = date.second(); + if (second <= 30 && second > 0) { + second = 30; + } else if (second > 30) { + second = 0; + date = date.offset(DateField.MINUTE, 1); + } + String format = DateUtil.format(date, "HH:mm"); + String secondStr = ":" + second; + if (second < 10) { + secondStr = ":0" + second; + } + return format + secondStr; + } + + /** + * 指定时间的下一个刻度 + * + * @return String + */ + private static String getNextScaleTime(String time) { DateTime dateTime = DateUtil.parseTime(time); DateTime newTime = dateTime.offsetNew(DateField.SECOND, 30); return DateUtil.formatTime(newTime);