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 a3c4a701..c66847ad 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 @@ -505,6 +505,7 @@ public class DcDeviceOnlineController extends BaseController { String LOST_RATE = "lostRate";//丢包率 String RTT_AVG = "rttAvg";//平均往返时延 String MONITOR_TIME = "time";//监控时间 + String ONLINE_RATE= "onlineRateList";//在线率 LocalDateTime start = LocalDateTime.parse(queryDate + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); LocalDateTime end = LocalDateTime.parse(queryDate + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); List onlineLogs = onlineLogService.queryByDateAndDevice(start, end, deviceId); @@ -512,14 +513,17 @@ public class DcDeviceOnlineController extends BaseController { List xAxis = new ArrayList<>(); List lossRate = new ArrayList<>(); List rttAvg = new ArrayList<>(); + List onlineRateList = new ArrayList<>();//在线率 onlineLogs.stream().sorted(Comparator.comparing(OnlineLog::getMonitorTime)).forEach(onlineLog -> { xAxis.add(onlineLog.getMonitorTime().format(DateTimeFormatter.ofPattern("HH:mm:ss"))); lossRate.add(onlineLog.getLossRate()); rttAvg.add(onlineLog.getRttAvg()); + onlineRateList.add(onlineLog.getOnlineRate()); }); returnMap.put(LOST_RATE, lossRate); returnMap.put(RTT_AVG, rttAvg); returnMap.put(MONITOR_TIME, xAxis); + returnMap.put(ONLINE_RATE, onlineRateList); return AjaxResult.success(new TreeMap<>(returnMap)); } diff --git a/zc-business/src/main/java/com/zc/business/domain/OnlineLog.java b/zc-business/src/main/java/com/zc/business/domain/OnlineLog.java index 2963eed4..417c3840 100644 --- a/zc-business/src/main/java/com/zc/business/domain/OnlineLog.java +++ b/zc-business/src/main/java/com/zc/business/domain/OnlineLog.java @@ -29,6 +29,7 @@ public class OnlineLog implements Serializable { private int lossCount;//丢包数 private double lossRate;//丢包率 private double rttAvg;//平均往返时延 + private double onlineRate;//在线率 @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime monitorTime; @@ -153,7 +154,13 @@ public class OnlineLog implements Serializable { this.deviceType = deviceType; } + public double getOnlineRate() { + return onlineRate; + } + public void setOnlineRate(double onlineRate) { + this.onlineRate = onlineRate; + } @Override public String toString() { @@ -173,6 +180,7 @@ public class OnlineLog implements Serializable { ", lossRate='" + lossRate + '\'' + ", rttAvg=" + rttAvg + ", monitorTime=" + monitorTime + + ", onlineRate=" + onlineRate + '}'; } @@ -206,6 +214,7 @@ public class OnlineLog implements Serializable { onlineLog.setLossRate(lossRate); onlineLog.setNetworkQuality(NetworkQuality.ofNetworkQuality(onlineLog.getLossRate(),onlineLog.getRttAvg())); onlineLog.setMonitorTime(LocalDateTime.now()); + onlineLog.setOnlineRate((int)lossRate==100?MathUtil.doubleTwoDecimal(100):MathUtil.doubleTwoDecimal(0)); return onlineLog; } public OnlineLog buildBad(DcDevice device){ @@ -223,6 +232,7 @@ public class OnlineLog implements Serializable { onlineLog.setLossRate(MathUtil.doubleTwoDecimal(100)); onlineLog.setRttAvg(0); onlineLog.setDeviceStatus(UniversalEnum.ZERO.getValue()); + onlineLog.setOnlineRate(MathUtil.doubleTwoDecimal(0)); return onlineLog; } public OnlineLog buildGood(DcDevice device){ @@ -240,6 +250,7 @@ public class OnlineLog implements Serializable { onlineLog.setLossRate(MathUtil.doubleTwoDecimal(0)); onlineLog.setRttAvg(30); onlineLog.setDeviceStatus(UniversalEnum.ONE.getValue()); + onlineLog.setOnlineRate(MathUtil.doubleTwoDecimal(100));//在线率 return onlineLog; } } diff --git a/zc-business/src/main/resources/mapper/business/OnlineLogMapper.xml b/zc-business/src/main/resources/mapper/business/OnlineLogMapper.xml index 4f3200bb..76bca1e5 100644 --- a/zc-business/src/main/resources/mapper/business/OnlineLogMapper.xml +++ b/zc-business/src/main/resources/mapper/business/OnlineLogMapper.xml @@ -18,13 +18,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + insert into dc_online_log ( device_id,device_name,device_ip,stake_mark,device_status,send_count, - receive_count,loss_count,loss_rate,network_quality,rtt_avg,monitor_time + receive_count,loss_count,loss_rate,network_quality,rtt_avg,monitor_time,online_rate ) values @@ -40,19 +41,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{item.lossRate}, #{item.networkQuality}, #{item.rttAvg}, - #{item.monitorTime} + #{item.monitorTime}, + #{item.onlineRate} )