|
@ -1,6 +1,8 @@ |
|
|
package com.zc.business.controller; |
|
|
package com.zc.business.controller; |
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.spring.SpringUtils; |
|
|
import com.ruoyi.common.utils.spring.SpringUtils; |
|
|
import com.zc.business.service.IDeviceService; |
|
|
import com.zc.business.domain.DcDevice; |
|
|
|
|
|
import com.zc.business.service.IDcDeviceService; |
|
|
import com.zc.business.service.impl.ExcelExportService; |
|
|
import com.zc.business.service.impl.ExcelExportService; |
|
|
import com.zc.business.service.impl.StatusService; |
|
|
import com.zc.business.service.impl.StatusService; |
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
@ -9,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.scheduling.annotation.EnableScheduling; |
|
|
import org.springframework.scheduling.annotation.EnableScheduling; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
import com.zc.business.domain.Status; |
|
|
import com.zc.business.domain.Status; |
|
|
import com.zc.business.domain.Device; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
import java.io.BufferedReader; |
|
|
import java.io.FileOutputStream; |
|
|
import java.io.FileOutputStream; |
|
@ -29,7 +30,7 @@ import java.util.stream.Collectors; |
|
|
@EnableScheduling |
|
|
@EnableScheduling |
|
|
public class DeviceStatus { |
|
|
public class DeviceStatus { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private IDeviceService deviceService; |
|
|
private IDcDeviceService deviceService; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private StatusService statusService; |
|
|
private StatusService statusService; |
|
@ -38,19 +39,18 @@ public class DeviceStatus { |
|
|
private ExcelExportService excelExportService; |
|
|
private ExcelExportService excelExportService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//每天凌晨0点到晚上23点整点测试设备状态
|
|
|
//每天凌晨0点到晚上23点整点测试设备状态
|
|
|
// @Scheduled(cron = "0 0 0-23 * * ?")
|
|
|
// @Scheduled(cron = "0 0 0-23 * * ?")
|
|
|
// @Scheduled(cron = "0 0 1,5,7,8,11,14,17,19,21,23")
|
|
|
// @Scheduled(cron = "0 0 1,5,7,8,11,14,17,19,21,23")
|
|
|
public void deviceStatus() { |
|
|
public void deviceStatus() { |
|
|
Device devices=new Device(); |
|
|
IDcDeviceService deviceService= SpringUtils.getBean(IDcDeviceService.class); |
|
|
IDeviceService deviceService= SpringUtils.getBean(IDeviceService.class); |
|
|
|
|
|
StatusService statusService= SpringUtils.getBean(StatusService.class); |
|
|
StatusService statusService= SpringUtils.getBean(StatusService.class); |
|
|
ExecutorService executor = Executors.newFixedThreadPool(100); |
|
|
ExecutorService executor = Executors.newFixedThreadPool(100); |
|
|
List<Device> deviceList = deviceService.selectDeviceList(devices); |
|
|
List<DcDevice> deviceList = deviceService.list(); |
|
|
|
|
|
|
|
|
List<Future<Void>> futures = new ArrayList<>(); |
|
|
List<Future<Void>> futures = new ArrayList<>(); |
|
|
|
|
|
|
|
|
for (Device device : deviceList) { |
|
|
for (DcDevice device : deviceList) { |
|
|
Callable<Void> task = () -> { |
|
|
Callable<Void> task = () -> { |
|
|
try { |
|
|
try { |
|
|
Status status = new Status(); |
|
|
Status status = new Status(); |
|
@ -58,7 +58,7 @@ public class DeviceStatus { |
|
|
String lostRate = getPingPacketLossRate(device.getDeviceIp()); |
|
|
String lostRate = getPingPacketLossRate(device.getDeviceIp()); |
|
|
boolean reachable = address.isReachable(5000); // Timeout: 5 seconds
|
|
|
boolean reachable = address.isReachable(5000); // Timeout: 5 seconds
|
|
|
|
|
|
|
|
|
status.setDeviceNo(device.getDeviceNo()); |
|
|
status.setDeviceNo(device.getStakeMark()); |
|
|
status.setDeviceName(device.getDeviceName()); |
|
|
status.setDeviceName(device.getDeviceName()); |
|
|
status.setDeviceIp(device.getDeviceIp()); |
|
|
status.setDeviceIp(device.getDeviceIp()); |
|
|
LocalDateTime localDateTime = LocalDateTime.now(); |
|
|
LocalDateTime localDateTime = LocalDateTime.now(); |
|
@ -116,7 +116,7 @@ public class DeviceStatus { |
|
|
// Extract the number of packets sent and lost
|
|
|
// Extract the number of packets sent and lost
|
|
|
String[] stats = line.split(", "); |
|
|
String[] stats = line.split(", "); |
|
|
packetsSent = Integer.parseInt(stats[0].split(" ")[0]); |
|
|
packetsSent = Integer.parseInt(stats[0].split(" ")[0]); |
|
|
packetsLost = Integer.parseInt(stats[0].split(" ")[0])-Integer.parseInt(stats[1].split(" ")[0]); |
|
|
packetsLost = Integer.parseInt(stats[0].split(" ")[0]) - Integer.parseInt(stats[1].split(" ")[0]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -138,9 +138,9 @@ public class DeviceStatus { |
|
|
* 每天17点 23点 30分导出excel表 |
|
|
* 每天17点 23点 30分导出excel表 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
// @Scheduled(cron = "0 30 17,23 * * ?")
|
|
|
// @Scheduled(cron = "0 30 17,23 * * ?")
|
|
|
public void calculateSuccessRate() { |
|
|
public void calculateSuccessRate() { |
|
|
StatusService statusService= SpringUtils.getBean(StatusService.class); |
|
|
StatusService statusService = SpringUtils.getBean(StatusService.class); |
|
|
ExcelExportService excelExportService= SpringUtils.getBean(ExcelExportService.class); |
|
|
ExcelExportService excelExportService= SpringUtils.getBean(ExcelExportService.class); |
|
|
|
|
|
|
|
|
LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS); |
|
|
LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS); |
|
@ -155,28 +155,28 @@ public class DeviceStatus { |
|
|
Map<Integer, List<Status>> map = listStatus.stream() |
|
|
Map<Integer, List<Status>> map = listStatus.stream() |
|
|
.collect(Collectors.groupingBy(Status -> Status.getTime().getHour())); |
|
|
.collect(Collectors.groupingBy(Status -> Status.getTime().getHour())); |
|
|
//根据类型分组
|
|
|
//根据类型分组
|
|
|
Map<String, List<Status>> maps = listStatus.stream().filter(iteam->iteam.getType()!=null).collect(Collectors.groupingBy(Status::getType)); |
|
|
Map<String, List<Status>> maps = listStatus.stream().filter(iteam -> iteam.getType() != null).collect(Collectors.groupingBy(Status::getType)); |
|
|
|
|
|
|
|
|
String filePath=CreateNamedExcel(); |
|
|
String filePath = CreateNamedExcel(); |
|
|
excelExportService.exportDataToExcel(map,maps,filePath); |
|
|
excelExportService.exportDataToExcel(map, maps, filePath); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String CreateNamedExcel() { |
|
|
public String CreateNamedExcel() { |
|
|
LocalDateTime dateTime = LocalDateTime.now(); |
|
|
LocalDateTime dateTime = LocalDateTime.now(); |
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
|
String formattedDateTime = dateTime.format(formatter); |
|
|
String formattedDateTime = dateTime.format(formatter); |
|
|
//修改成服务器地址
|
|
|
//修改成服务器地址
|
|
|
String filePath = "/home/excel/"+formattedDateTime+"--deviceStatus.xlsx"; |
|
|
String filePath = "/home/excel/" + formattedDateTime + "--deviceStatus.xlsx"; |
|
|
try (Workbook workbook = new XSSFWorkbook()) { |
|
|
try (Workbook workbook = new XSSFWorkbook()) { |
|
|
FileOutputStream fileOut = new FileOutputStream(filePath); |
|
|
FileOutputStream fileOut = new FileOutputStream(filePath); |
|
|
workbook.write(fileOut); |
|
|
workbook.write(fileOut); |
|
|
System.out.println("Empty named Excel created successfully."); |
|
|
System.out.println("Empty named Excel created successfully."); |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
} |
|
|
|
|
|
return filePath; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
return filePath; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|