|
|
@ -10,7 +10,11 @@ import org.springframework.stereotype.Component; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.InetAddress; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Component |
|
|
|
@EnableScheduling |
|
|
@ -23,10 +27,12 @@ public class DeviceStatus { |
|
|
|
|
|
|
|
|
|
|
|
//每天凌晨开始执行,每4小时执行一次
|
|
|
|
@Scheduled(cron = "0 0 4/0 * * ?") |
|
|
|
@Scheduled(cron = "0 33 * * * ?") |
|
|
|
// @Scheduled(cron = "0 0 1,5,7,8,11,14,17,19,21,23")
|
|
|
|
public void generateDeviceStatus() { |
|
|
|
deviceStatus(); |
|
|
|
} |
|
|
|
|
|
|
|
public void deviceStatus() { |
|
|
|
Status status = new Status(); |
|
|
|
List<Device> deviceList = deviceService.SelectList(); |
|
|
@ -51,5 +57,32 @@ public class DeviceStatus { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 计算成功率 |
|
|
|
*/ |
|
|
|
public Map<String, String> calculateSuccessRate() { |
|
|
|
|
|
|
|
LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS); |
|
|
|
LocalDateTime currentTime = LocalDateTime.now(); |
|
|
|
Map<String, String> ipMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
Status status = new Status(); |
|
|
|
status.setStartTime(todayStart); |
|
|
|
status.setTime(currentTime); |
|
|
|
List<Status> listStatus = statusService.list(status); |
|
|
|
Map<String, List<Status>> map = listStatus.stream().collect(Collectors.groupingBy(Status::getDeviceIp)); |
|
|
|
|
|
|
|
for (String ip : map.keySet()) { |
|
|
|
// 成功的次数
|
|
|
|
long successNumber = map.get(ip).stream().filter(item -> item.getDeviceStatus() == 1).count(); |
|
|
|
// 此ip对应的成功率
|
|
|
|
String successRate = String.format("%.2f%%", (double) successNumber / map.get(ip).size() * 100); |
|
|
|
ipMap.put(ip, successRate); |
|
|
|
} |
|
|
|
|
|
|
|
return ipMap; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|