Browse Source

----循环插入

main
mengff 11 months ago
parent
commit
d27733bfee
  1. 7
      src/main/java/com/example/device/controller/DeviceStatus.java
  2. 6
      src/main/java/com/example/device/service/ExcelExportService.java

7
src/main/java/com/example/device/controller/DeviceStatus.java

@ -38,7 +38,7 @@ public class DeviceStatus {
private ExcelExportService excelExportService; 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") // @Scheduled(cron = "0 0 1,5,7,8,11,14,17,19,21,23")
public void generateDeviceStatus() { public void generateDeviceStatus() {
deviceStatus(); deviceStatus();
@ -126,7 +126,6 @@ public class DeviceStatus {
} }
executor.shutdown(); executor.shutdown();
calculateSuccessRate();
} }
@ -169,12 +168,14 @@ public class DeviceStatus {
/** /**
* 成功率和丢包率按小时分组 * 成功率和丢包率按小时分组
*
*/ */
@Scheduled(cron = "0 5 1 * * ?")
public void calculateSuccessRate() { public void calculateSuccessRate() {
LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS); LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
LocalDateTime currentTime = LocalDateTime.now(); LocalDateTime currentTime = LocalDateTime.now();
Map<String, String> ipMap = new HashMap<>();
Status status = new Status(); Status status = new Status();

6
src/main/java/com/example/device/service/ExcelExportService.java

@ -47,7 +47,11 @@ public class ExcelExportService {
rowNum = 2; rowNum = 2;
List<Status> groupItems = entry.getValue(); List<Status> groupItems = entry.getValue();
for (Status ignored : groupItems) { 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) { if(flag) {
row.createCell(0).setCellValue(ignored.getDeviceName()); row.createCell(0).setCellValue(ignored.getDeviceName());
row.createCell(1).setCellValue(ignored.getDeviceIp()); row.createCell(1).setCellValue(ignored.getDeviceIp());

Loading…
Cancel
Save