From d27733bfee7a01ddf615a8731c47f9c9a1b5c7bc Mon Sep 17 00:00:00 2001 From: mengff <1198151809@qq.com> Date: Tue, 9 Jan 2024 08:02:25 +0800 Subject: [PATCH] =?UTF-8?q?----=E5=BE=AA=E7=8E=AF=E6=8F=92=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/device/controller/DeviceStatus.java | 7 ++++--- .../com/example/device/service/ExcelExportService.java | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) 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());