| 
						
						
							
								
							
						
						
					 | 
					@ -13,6 +13,7 @@ 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.HashMap; | 
					 | 
					 | 
					import java.util.HashMap; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import java.util.List; | 
					 | 
					 | 
					import java.util.List; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import java.util.Map; | 
					 | 
					 | 
					import java.util.Map; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -22,6 +23,7 @@ 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; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					import java.util.concurrent.*; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					@Component | 
					 | 
					 | 
					@Component | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					@EnableScheduling | 
					 | 
					 | 
					@EnableScheduling | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -36,7 +38,7 @@ public class DeviceStatus { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    private ExcelExportService excelExportService; | 
					 | 
					 | 
					    private ExcelExportService excelExportService; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    @Scheduled(cron = "0 20 14 * * ?") | 
					 | 
					 | 
					    @Scheduled(cron = "* * 0/1 * * ?") | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    // @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() { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        deviceStatus(); | 
					 | 
					 | 
					        deviceStatus(); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -44,35 +46,90 @@ public class DeviceStatus { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//    public void deviceStatus() {
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//        Status status = new Status();
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//        List<Device> deviceList = deviceService.SelectList();
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//        for (Device device : deviceList) {
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//            try {
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                InetAddress address = InetAddress.getByName(device.getDeviceIp());
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                String lostReat=getPingPacketLossRate(device.getDeviceIp());
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                boolean reachable = address.isReachable(5000); // Timeout: 5 seconds
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                status.setDeviceNo(device.getDeviceNo());
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                status.setDeviceName(device.getDeviceName());
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                LocalDateTime localDateTime = LocalDateTime.now();
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                status.setTime(localDateTime);
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                status.setLostRate(lostReat);
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                //1-在线   0-离线
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                if (reachable) {
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                    status.setDeviceStatus(1);
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                    status.setSuccessRate("100.00%");
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                } else {
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                    status.setDeviceStatus(0);
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                    status.setSuccessRate("0.00%");
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                }
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                statusService.Add(status);
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//            } catch (IOException e) {
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//                System.out.println("Error pinging " + device.getDeviceIp() + ": " + e.getMessage());
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//            }
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//        }
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//        calculateSuccessRate();
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					//    }
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    public void deviceStatus() { | 
					 | 
					 | 
					    public void deviceStatus() { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        Status status = new Status(); | 
					 | 
					 | 
					        ExecutorService executor = Executors.newFixedThreadPool(100); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					        List<Device> deviceList = deviceService.SelectList(); | 
					 | 
					 | 
					        List<Device> deviceList = deviceService.SelectList(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        List<Future<Void>> futures = new ArrayList<>(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        for (Device device : deviceList) { | 
					 | 
					 | 
					        for (Device device : deviceList) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            try { | 
					 | 
					 | 
					            Callable<Void> task = () -> { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                InetAddress address = InetAddress.getByName(device.getDeviceIp()); | 
					 | 
					 | 
					                try { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                String lostReat=getPingPacketLossRate(device.getDeviceIp()); | 
					 | 
					 | 
					                    Status status = new Status(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                boolean reachable = address.isReachable(5000); // Timeout: 5 seconds
 | 
					 | 
					 | 
					                    InetAddress address = InetAddress.getByName(device.getDeviceIp()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                status.setDeviceNo(device.getDeviceNo()); | 
					 | 
					 | 
					                    String lostRate = getPingPacketLossRate(device.getDeviceIp()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                status.setDeviceName(device.getDeviceName()); | 
					 | 
					 | 
					                    boolean reachable = address.isReachable(5000); // Timeout: 5 seconds
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                LocalDateTime localDateTime = LocalDateTime.now(); | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                status.setTime(localDateTime); | 
					 | 
					 | 
					                    status.setDeviceNo(device.getDeviceNo()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                status.setLostRate(lostReat); | 
					 | 
					 | 
					                    status.setDeviceName(device.getDeviceName()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                //1-在线   0-离线
 | 
					 | 
					 | 
					                    status.setDeviceIp(device.getDeviceIp()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                if (reachable) { | 
					 | 
					 | 
					                    LocalDateTime localDateTime = LocalDateTime.now(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    status.setDeviceStatus(1); | 
					 | 
					 | 
					                    status.setTime(localDateTime); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    status.setSuccessRate("100.00%"); | 
					 | 
					 | 
					                    status.setLostRate(lostRate); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                } else { | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    status.setDeviceStatus(0); | 
					 | 
					 | 
					                    if (reachable) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    status.setSuccessRate("0.00%"); | 
					 | 
					 | 
					                        status.setDeviceStatus(1); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                        status.setSuccessRate("100.00%"); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    } else { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                        status.setDeviceStatus(0); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                        status.setSuccessRate("0.00%"); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    statusService.Add(status); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                } catch (IOException e) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    System.out.println("Error pinging " + device.getDeviceIp() + ": " + e.getMessage()); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                } | 
					 | 
					 | 
					                } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					                statusService.Add(status); | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            } catch (IOException e) { | 
					 | 
					 | 
					                return null; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                System.out.println("Error pinging " + device.getDeviceIp() + ": " + e.getMessage()); | 
					 | 
					 | 
					            }; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            futures.add(executor.submit(task)); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        for (Future<Void> future : futures) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            try { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                future.get(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            } catch (InterruptedException | ExecutionException e) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                e.printStackTrace(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        executor.shutdown(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        calculateSuccessRate(); | 
					 | 
					 | 
					        calculateSuccessRate(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    } | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    /** | 
					 | 
					 | 
					    /** | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					     * 计算丢包率 | 
					 | 
					 | 
					     * 计算丢包率 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					     */ | 
					 | 
					 | 
					     */ | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -129,6 +186,8 @@ public class DeviceStatus { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        String  filePath=CreateNamedExcel(); | 
					 | 
					 | 
					        String  filePath=CreateNamedExcel(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        excelExportService.exportDataToExcel(map,filePath); | 
					 | 
					 | 
					        excelExportService.exportDataToExcel(map,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"); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |