diff --git a/src/main/java/com/example/device/controller/DeviceStatus.java b/src/main/java/com/example/device/controller/DeviceStatus.java index fc6ec3a..9212915 100644 --- a/src/main/java/com/example/device/controller/DeviceStatus.java +++ b/src/main/java/com/example/device/controller/DeviceStatus.java @@ -38,7 +38,7 @@ public class DeviceStatus { private ExcelExportService excelExportService; - @Scheduled(cron = "* * 0/1 * * ?") + @Scheduled(cron = "0 0 0-23 * * ?") // @Scheduled(cron = "0 0 1,5,7,8,11,14,17,19,21,23") public void generateDeviceStatus() { deviceStatus(); @@ -126,7 +126,6 @@ public class DeviceStatus { } executor.shutdown(); - calculateSuccessRate(); } @@ -169,12 +168,14 @@ public class DeviceStatus { /** * 成功率和丢包率按小时分组 + * */ + + @Scheduled(cron = "0 5 1 * * ?") public void calculateSuccessRate() { LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS); LocalDateTime currentTime = LocalDateTime.now(); - Map ipMap = new HashMap<>(); Status status = new Status(); diff --git a/src/main/java/com/example/device/service/ExcelExportService.java b/src/main/java/com/example/device/service/ExcelExportService.java index e457104..15bd045 100644 --- a/src/main/java/com/example/device/service/ExcelExportService.java +++ b/src/main/java/com/example/device/service/ExcelExportService.java @@ -47,7 +47,11 @@ public class ExcelExportService { rowNum = 2; List groupItems = entry.getValue(); for (Status ignored : groupItems) { - Row row = sheet.createRow(rowNum++); + int a=rowNum++; + Row row = sheet.getRow(a); // 获取指定索引的行 + if (row == null) { // 如果行不存在,则创建新行 + row = sheet.createRow(a); + } if(flag) { row.createCell(0).setCellValue(ignored.getDeviceName()); row.createCell(1).setCellValue(ignored.getDeviceIp());