|
@ -1,4 +1,5 @@ |
|
|
package com.example.device.controller; |
|
|
package com.example.device.controller; |
|
|
|
|
|
|
|
|
import com.example.device.entity.Device; |
|
|
import com.example.device.entity.Device; |
|
|
import com.example.device.entity.Status; |
|
|
import com.example.device.entity.Status; |
|
|
import com.example.device.service.DeviceService; |
|
|
import com.example.device.service.DeviceService; |
|
@ -8,18 +9,18 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.scheduling.annotation.EnableScheduling; |
|
|
import org.springframework.scheduling.annotation.EnableScheduling; |
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.net.InetAddress; |
|
|
import java.net.InetAddress; |
|
|
import java.time.LocalDateTime; |
|
|
import java.time.LocalDateTime; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.time.temporal.ChronoUnit; |
|
|
import java.time.temporal.ChronoUnit; |
|
|
import java.util.ArrayList; |
|
|
import java.util.*; |
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
|
|
|
|
|
import java.io.FileOutputStream; |
|
|
import java.io.FileOutputStream; |
|
|
import java.io.BufferedReader; |
|
|
import java.io.BufferedReader; |
|
|
import java.io.InputStreamReader; |
|
|
import java.io.InputStreamReader; |
|
@ -42,11 +43,12 @@ public class DeviceStatus { |
|
|
@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 generateDeviceStatus() { |
|
|
public void generateDeviceStatus() { |
|
|
|
|
|
System.out.println("开始执行" + new Date()); |
|
|
deviceStatus(); |
|
|
deviceStatus(); |
|
|
|
|
|
System.out.println("执行完毕" + new Date()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public void deviceStatus() {
|
|
|
// public void deviceStatus() {
|
|
|
// Status status = new Status();
|
|
|
// Status status = new Status();
|
|
|
// List<Device> deviceList = deviceService.SelectList();
|
|
|
// List<Device> deviceList = deviceService.SelectList();
|
|
@ -77,7 +79,6 @@ public class DeviceStatus { |
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void deviceStatus() { |
|
|
public void deviceStatus() { |
|
|
ExecutorService executor = Executors.newFixedThreadPool(100); |
|
|
ExecutorService executor = Executors.newFixedThreadPool(100); |
|
|
List<Device> deviceList = deviceService.SelectList(); |
|
|
List<Device> deviceList = deviceService.SelectList(); |
|
@ -92,7 +93,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(); |
|
|