Browse Source

设备在线率

develop
wangsixiang 4 months ago
parent
commit
16b3824db4
  1. 4
      zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java
  2. 11
      zc-business/src/main/java/com/zc/business/domain/OnlineLog.java
  3. 10
      zc-business/src/main/resources/mapper/business/OnlineLogMapper.xml

4
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 LOST_RATE = "lostRate";//丢包率
String RTT_AVG = "rttAvg";//平均往返时延 String RTT_AVG = "rttAvg";//平均往返时延
String MONITOR_TIME = "time";//监控时间 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 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")); LocalDateTime end = LocalDateTime.parse(queryDate + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
List<OnlineLog> onlineLogs = onlineLogService.queryByDateAndDevice(start, end, deviceId); List<OnlineLog> onlineLogs = onlineLogService.queryByDateAndDevice(start, end, deviceId);
@ -512,14 +513,17 @@ public class DcDeviceOnlineController extends BaseController {
List<String> xAxis = new ArrayList<>(); List<String> xAxis = new ArrayList<>();
List<Double> lossRate = new ArrayList<>(); List<Double> lossRate = new ArrayList<>();
List<Double> rttAvg = new ArrayList<>(); List<Double> rttAvg = new ArrayList<>();
List<Double> onlineRateList = new ArrayList<>();//在线率
onlineLogs.stream().sorted(Comparator.comparing(OnlineLog::getMonitorTime)).forEach(onlineLog -> { onlineLogs.stream().sorted(Comparator.comparing(OnlineLog::getMonitorTime)).forEach(onlineLog -> {
xAxis.add(onlineLog.getMonitorTime().format(DateTimeFormatter.ofPattern("HH:mm:ss"))); xAxis.add(onlineLog.getMonitorTime().format(DateTimeFormatter.ofPattern("HH:mm:ss")));
lossRate.add(onlineLog.getLossRate()); lossRate.add(onlineLog.getLossRate());
rttAvg.add(onlineLog.getRttAvg()); rttAvg.add(onlineLog.getRttAvg());
onlineRateList.add(onlineLog.getOnlineRate());
}); });
returnMap.put(LOST_RATE, lossRate); returnMap.put(LOST_RATE, lossRate);
returnMap.put(RTT_AVG, rttAvg); returnMap.put(RTT_AVG, rttAvg);
returnMap.put(MONITOR_TIME, xAxis); returnMap.put(MONITOR_TIME, xAxis);
returnMap.put(ONLINE_RATE, onlineRateList);
return AjaxResult.success(new TreeMap<>(returnMap)); return AjaxResult.success(new TreeMap<>(returnMap));
} }

11
zc-business/src/main/java/com/zc/business/domain/OnlineLog.java

@ -29,6 +29,7 @@ public class OnlineLog implements Serializable {
private int lossCount;//丢包数 private int lossCount;//丢包数
private double lossRate;//丢包率 private double lossRate;//丢包率
private double rttAvg;//平均往返时延 private double rttAvg;//平均往返时延
private double onlineRate;//在线率
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime monitorTime; private LocalDateTime monitorTime;
@ -153,7 +154,13 @@ public class OnlineLog implements Serializable {
this.deviceType = deviceType; this.deviceType = deviceType;
} }
public double getOnlineRate() {
return onlineRate;
}
public void setOnlineRate(double onlineRate) {
this.onlineRate = onlineRate;
}
@Override @Override
public String toString() { public String toString() {
@ -173,6 +180,7 @@ public class OnlineLog implements Serializable {
", lossRate='" + lossRate + '\'' + ", lossRate='" + lossRate + '\'' +
", rttAvg=" + rttAvg + ", rttAvg=" + rttAvg +
", monitorTime=" + monitorTime + ", monitorTime=" + monitorTime +
", onlineRate=" + onlineRate +
'}'; '}';
} }
@ -206,6 +214,7 @@ public class OnlineLog implements Serializable {
onlineLog.setLossRate(lossRate); onlineLog.setLossRate(lossRate);
onlineLog.setNetworkQuality(NetworkQuality.ofNetworkQuality(onlineLog.getLossRate(),onlineLog.getRttAvg())); onlineLog.setNetworkQuality(NetworkQuality.ofNetworkQuality(onlineLog.getLossRate(),onlineLog.getRttAvg()));
onlineLog.setMonitorTime(LocalDateTime.now()); onlineLog.setMonitorTime(LocalDateTime.now());
onlineLog.setOnlineRate((int)lossRate==100?MathUtil.doubleTwoDecimal(100):MathUtil.doubleTwoDecimal(0));
return onlineLog; return onlineLog;
} }
public OnlineLog buildBad(DcDevice device){ public OnlineLog buildBad(DcDevice device){
@ -223,6 +232,7 @@ public class OnlineLog implements Serializable {
onlineLog.setLossRate(MathUtil.doubleTwoDecimal(100)); onlineLog.setLossRate(MathUtil.doubleTwoDecimal(100));
onlineLog.setRttAvg(0); onlineLog.setRttAvg(0);
onlineLog.setDeviceStatus(UniversalEnum.ZERO.getValue()); onlineLog.setDeviceStatus(UniversalEnum.ZERO.getValue());
onlineLog.setOnlineRate(MathUtil.doubleTwoDecimal(0));
return onlineLog; return onlineLog;
} }
public OnlineLog buildGood(DcDevice device){ public OnlineLog buildGood(DcDevice device){
@ -240,6 +250,7 @@ public class OnlineLog implements Serializable {
onlineLog.setLossRate(MathUtil.doubleTwoDecimal(0)); onlineLog.setLossRate(MathUtil.doubleTwoDecimal(0));
onlineLog.setRttAvg(30); onlineLog.setRttAvg(30);
onlineLog.setDeviceStatus(UniversalEnum.ONE.getValue()); onlineLog.setDeviceStatus(UniversalEnum.ONE.getValue());
onlineLog.setOnlineRate(MathUtil.doubleTwoDecimal(100));//在线率
return onlineLog; return onlineLog;
} }
} }

10
zc-business/src/main/resources/mapper/business/OnlineLogMapper.xml

@ -18,13 +18,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="networkQuality" column="network_quality"/> <result property="networkQuality" column="network_quality"/>
<result property="rttAvg" column="rtt_avg"/> <result property="rttAvg" column="rtt_avg"/>
<result property="monitorTime" column="monitor_time"/> <result property="monitorTime" column="monitor_time"/>
<result property="onlineRate" column="online_rate"/>
</resultMap> </resultMap>
<insert id="addBatch"> <insert id="addBatch">
insert into dc_online_log insert into dc_online_log
( (
device_id,device_name,device_ip,stake_mark,device_status,send_count, 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 values
<foreach collection="list" item="item" index="index" separator=","> <foreach collection="list" item="item" index="index" separator=",">
@ -40,19 +41,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item.lossRate}, #{item.lossRate},
#{item.networkQuality}, #{item.networkQuality},
#{item.rttAvg}, #{item.rttAvg},
#{item.monitorTime} #{item.monitorTime},
#{item.onlineRate}
) )
</foreach> </foreach>
</insert> </insert>
<select id="queryByDate" resultMap="OnlineLog"> <select id="queryByDate" resultMap="OnlineLog">
select id,device_id,device_name,device_ip,stake_mark,device_status,send_count, select id,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
from dc_online_log where monitor_time between #{startTime} and #{endTime} from dc_online_log where monitor_time between #{startTime} and #{endTime}
</select> </select>
<select id="queryByDateAndDevice" resultMap="OnlineLog"> <select id="queryByDateAndDevice" resultMap="OnlineLog">
select id,device_id,device_name,device_ip,stake_mark,device_status,send_count, select id,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
from dc_online_log where device_id = #{deviceId} and monitor_time between #{startTime} and #{endTime} from dc_online_log where device_id = #{deviceId} and monitor_time between #{startTime} and #{endTime}
order by monitor_time desc order by monitor_time desc
</select> </select>

Loading…
Cancel
Save