|
@@ -4,6 +4,7 @@ package cn.chinaunicom.omniFlowNetCompute.until;
|
|
|
import cn.chinaunicom.omniFlowNetCompute.pojo.DashboardVO;
|
|
import cn.chinaunicom.omniFlowNetCompute.pojo.DashboardVO;
|
|
|
import cn.chinaunicom.omniFlowNetCompute.pojo.SystemStatsDetailVO;
|
|
import cn.chinaunicom.omniFlowNetCompute.pojo.SystemStatsDetailVO;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
+import org.apache.poi.ss.util.RegionUtil;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
@@ -75,7 +76,7 @@ public class ExcelExportUtil {
|
|
|
createOverallStatsSheetNew(workbook, headerStyle, dataStyle, month, dashboardVO);
|
|
createOverallStatsSheetNew(workbook, headerStyle, dataStyle, month, dashboardVO);
|
|
|
|
|
|
|
|
// 2. 创建系统统计Sheet
|
|
// 2. 创建系统统计Sheet
|
|
|
- createSystemStatsSheetNew(workbook, headerStyle, dataStyle, month, dashboardVO);
|
|
|
|
|
|
|
+ createSystemStatsColumnSheet(workbook, headerStyle, dashboardVO);
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置响应头
|
|
// 设置响应头
|
|
@@ -96,16 +97,16 @@ public class ExcelExportUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void createOverallStatsSheetNew(final Workbook workbook, final CellStyle headerStyle, final CellStyle dataStyle, final String month, final DashboardVO dashboardVO) {
|
|
private void createOverallStatsSheetNew(final Workbook workbook, final CellStyle headerStyle, final CellStyle dataStyle, final String month, final DashboardVO dashboardVO) {
|
|
|
- Sheet sheet = workbook.createSheet("整体统计");
|
|
|
|
|
|
|
+ Sheet sheet = workbook.createSheet("汇总");
|
|
|
|
|
|
|
|
// 创建标题行
|
|
// 创建标题行
|
|
|
Row titleRow = sheet.createRow(0);
|
|
Row titleRow = sheet.createRow(0);
|
|
|
Cell titleCell = titleRow.createCell(0);
|
|
Cell titleCell = titleRow.createCell(0);
|
|
|
- titleCell.setCellValue(month + "告警整体统计");
|
|
|
|
|
|
|
+ titleCell.setCellValue(month + "告警数据统计");
|
|
|
titleCell.setCellStyle(headerStyle);
|
|
titleCell.setCellStyle(headerStyle);
|
|
|
- sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(0, 0, 0, 7));
|
|
|
|
|
|
|
+ sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(0, 0, 0, 6));
|
|
|
Row headerRow = sheet.createRow(1);
|
|
Row headerRow = sheet.createRow(1);
|
|
|
- String[] headers = {"统计项", "总数", "未处理", "已处理", "内容类告警", "阈值类告警","存在性告警"};
|
|
|
|
|
|
|
+ String[] headers = {"月份", "告警总数", "存在性告警条数","非阈值类告警数(内容类)","阈值类告警","已处理告警总数", "未处理告警总数"};
|
|
|
for (int i = 0; i < headers.length; i++) {
|
|
for (int i = 0; i < headers.length; i++) {
|
|
|
Cell cell = headerRow.createCell(i);
|
|
Cell cell = headerRow.createCell(i);
|
|
|
cell.setCellValue(headers[i]);
|
|
cell.setCellValue(headers[i]);
|
|
@@ -115,15 +116,16 @@ public class ExcelExportUtil {
|
|
|
// 创建数据行
|
|
// 创建数据行
|
|
|
Row dataRow = sheet.createRow(2);
|
|
Row dataRow = sheet.createRow(2);
|
|
|
Cell cell0 = dataRow.createCell(0);
|
|
Cell cell0 = dataRow.createCell(0);
|
|
|
- cell0.setCellValue("告警统计");
|
|
|
|
|
|
|
+ cell0.setCellValue(month);
|
|
|
cell0.setCellStyle(dataStyle);
|
|
cell0.setCellStyle(dataStyle);
|
|
|
Map<String, Supplier<Number>> fieldGetters = new LinkedHashMap<>();
|
|
Map<String, Supplier<Number>> fieldGetters = new LinkedHashMap<>();
|
|
|
fieldGetters.put("totalAlarms", dashboardVO::getTotalAlarms);
|
|
fieldGetters.put("totalAlarms", dashboardVO::getTotalAlarms);
|
|
|
- fieldGetters.put("totalUntreated", dashboardVO::getTotalUntreated);
|
|
|
|
|
- fieldGetters.put("totalProcessed", dashboardVO::getTotalProcessed);
|
|
|
|
|
|
|
+ fieldGetters.put("existenceAlarms", dashboardVO::getExistenceAlarms);
|
|
|
fieldGetters.put("contentAlarms", dashboardVO::getToralContentAlarms);
|
|
fieldGetters.put("contentAlarms", dashboardVO::getToralContentAlarms);
|
|
|
fieldGetters.put("thresholdAlarms", dashboardVO::getTotalThresholdAlarms);
|
|
fieldGetters.put("thresholdAlarms", dashboardVO::getTotalThresholdAlarms);
|
|
|
- fieldGetters.put("existenceAlarms", dashboardVO::getExistenceAlarms);
|
|
|
|
|
|
|
+ fieldGetters.put("totalProcessed", dashboardVO::getTotalProcessed);
|
|
|
|
|
+ fieldGetters.put("totalUntreated", dashboardVO::getTotalUntreated);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
int cellIndex = 1;
|
|
int cellIndex = 1;
|
|
|
for (Map.Entry<String, Supplier<Number>> entry : fieldGetters.entrySet()) {
|
|
for (Map.Entry<String, Supplier<Number>> entry : fieldGetters.entrySet()) {
|
|
@@ -139,7 +141,7 @@ public class ExcelExportUtil {
|
|
|
|
|
|
|
|
// 自动调整列宽
|
|
// 自动调整列宽
|
|
|
for (int i = 0; i < headers.length; i++) {
|
|
for (int i = 0; i < headers.length; i++) {
|
|
|
- sheet.setColumnWidth(i, 20 * 256);
|
|
|
|
|
|
|
+ sheet.setColumnWidth(i, 20 * 500);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -147,7 +149,162 @@ public class ExcelExportUtil {
|
|
|
/**
|
|
/**
|
|
|
* 创建系统统计Sheet
|
|
* 创建系统统计Sheet
|
|
|
*/
|
|
*/
|
|
|
- private void createSystemStatsSheetNew(Workbook workbook, CellStyle headerStyle, CellStyle dataStyle, String month, DashboardVO dashboardVO) {
|
|
|
|
|
|
|
+ private void createSystemStatsColumnSheet(Workbook workbook, CellStyle headerStyle, DashboardVO dashboardVO) {
|
|
|
|
|
+ Sheet sheet = workbook.createSheet("月份");
|
|
|
|
|
+
|
|
|
|
|
+ // 创建表头
|
|
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
|
|
+ String[] headers = {"系统名称", "告警类型", "告警指标", "告警总量", "未处理告警数量"};
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < headers.length; i++) {
|
|
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
|
|
+ cell.setCellValue(headers[i]);
|
|
|
|
|
+ cell.setCellStyle(headerStyle);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 创建数据行
|
|
|
|
|
+ int rowNum = 1;
|
|
|
|
|
+ long totalAlarms = 0;
|
|
|
|
|
+ long totalUntreated = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if (dashboardVO != null) {
|
|
|
|
|
+ List<SystemStatsDetailVO> systemStatsList = dashboardVO.getSystemStats();
|
|
|
|
|
+
|
|
|
|
|
+ if (systemStatsList != null && !systemStatsList.isEmpty()) {
|
|
|
|
|
+ for (SystemStatsDetailVO stats : systemStatsList) {
|
|
|
|
|
+ String systemName = stats.getSystemName() != null ? stats.getSystemName() : "";
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 用户权限变更监控(内容类)
|
|
|
|
|
+ if (stats.getPermissionCount() != null && stats.getPermissionCount() > 0) {
|
|
|
|
|
+ Long count = stats.getPermissionCount();
|
|
|
|
|
+ createDataRow(sheet, rowNum++, systemName, "用户权限变更监控", "内容告警", count, count);
|
|
|
|
|
+ totalAlarms += count;
|
|
|
|
|
+ totalUntreated += count;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 数据库监控(阈值类)
|
|
|
|
|
+ if (stats.getDbCount() != null && stats.getDbCount() > 0) {
|
|
|
|
|
+ Long count = stats.getDbCount();
|
|
|
|
|
+ createDataRow(sheet, rowNum++, systemName, "数据库监控", "阈值告警", count, count);
|
|
|
|
|
+ totalAlarms += count;
|
|
|
|
|
+ totalUntreated += count;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 系统内部连接性监控(内容类)
|
|
|
|
|
+ if (stats.getConnectCount() != null && stats.getConnectCount() > 0) {
|
|
|
|
|
+ Long count = stats.getConnectCount();
|
|
|
|
|
+ createDataRow(sheet, rowNum++, systemName, "系统内部连接性监控", "内容告警", count, count);
|
|
|
|
|
+ totalAlarms += count;
|
|
|
|
|
+ totalUntreated += count;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 异常IP访问监控(内容类)
|
|
|
|
|
+ if (stats.getIpCount() != null && stats.getIpCount() > 0) {
|
|
|
|
|
+ Long count = stats.getIpCount();
|
|
|
|
|
+ createDataRow(sheet, rowNum++, systemName, "异常IP访问监控", "内容告警", count, count);
|
|
|
|
|
+ totalAlarms += count;
|
|
|
|
|
+ totalUntreated += count;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 定时任务异常监控(内容类)
|
|
|
|
|
+ if (stats.getTaskCount() != null && stats.getTaskCount() > 0) {
|
|
|
|
|
+ Long count = stats.getTaskCount();
|
|
|
|
|
+ createDataRow(sheet, rowNum++, systemName, "定时任务异常监控", "内容告警", count, count);
|
|
|
|
|
+ totalAlarms += count;
|
|
|
|
|
+ totalUntreated += count;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 存在性告警(单独一行)
|
|
|
|
|
+ if (stats.getExistenceAlarms() != null && stats.getExistenceAlarms() > 0) {
|
|
|
|
|
+ Long count = stats.getExistenceAlarms();
|
|
|
|
|
+ createDataRow(sheet, rowNum++, systemName, "数据未送达", "存在性告警", count, count);
|
|
|
|
|
+ totalAlarms += count;
|
|
|
|
|
+ totalUntreated += count;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 添加汇总行(前3列合并,并确保有边框)
|
|
|
|
|
+ if (rowNum > 1) { // 如果有数据行
|
|
|
|
|
+ int summaryRowNum = rowNum++;
|
|
|
|
|
+ Row summaryRow = sheet.createRow(summaryRowNum);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建带边框的汇总样式
|
|
|
|
|
+ CellStyle summaryStyle = workbook.createCellStyle();
|
|
|
|
|
+ Font font = workbook.createFont();
|
|
|
|
|
+ font.setBold(true);
|
|
|
|
|
+ summaryStyle.setFont(font);
|
|
|
|
|
+ summaryStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
|
+
|
|
|
|
|
+ // 添加边框
|
|
|
|
|
+ BorderStyle borderStyle = BorderStyle.THIN;
|
|
|
|
|
+ summaryStyle.setBorderTop(borderStyle);
|
|
|
|
|
+ summaryStyle.setBorderBottom(borderStyle);
|
|
|
|
|
+ summaryStyle.setBorderLeft(borderStyle);
|
|
|
|
|
+ summaryStyle.setBorderRight(borderStyle);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建合并区域的第一个单元格(第0列)
|
|
|
|
|
+ Cell summaryCell1 = summaryRow.createCell(0);
|
|
|
|
|
+ summaryCell1.setCellValue("汇总");
|
|
|
|
|
+ summaryCell1.setCellStyle(summaryStyle);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建合并区域的第二个单元格(第1列)- 空单元格,但需要有边框
|
|
|
|
|
+ Cell summaryCell2 = summaryRow.createCell(1);
|
|
|
|
|
+ summaryCell2.setCellValue(""); // 空值
|
|
|
|
|
+ summaryCell2.setCellStyle(summaryStyle);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建合并区域的第三个单元格(第2列)- 空单元格,但需要有边框
|
|
|
|
|
+ Cell summaryCell3 = summaryRow.createCell(2);
|
|
|
|
|
+ summaryCell3.setCellValue(""); // 空值
|
|
|
|
|
+ summaryCell3.setCellStyle(summaryStyle);
|
|
|
|
|
+
|
|
|
|
|
+ // 合并前3列:A列到C列(0-2列)
|
|
|
|
|
+ // 注意:必须在创建了所有单元格之后再进行合并
|
|
|
|
|
+ sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(summaryRowNum, summaryRowNum, 0, 2));
|
|
|
|
|
+
|
|
|
|
|
+ // 第4列:告警总量
|
|
|
|
|
+ Cell totalCell = summaryRow.createCell(3);
|
|
|
|
|
+ totalCell.setCellValue(totalAlarms);
|
|
|
|
|
+ totalCell.setCellStyle(summaryStyle);
|
|
|
|
|
+
|
|
|
|
|
+ // 第5列:未处理告警数量
|
|
|
|
|
+ Cell untreatedCell = summaryRow.createCell(4);
|
|
|
|
|
+ untreatedCell.setCellValue(totalUntreated);
|
|
|
|
|
+ untreatedCell.setCellStyle(summaryStyle);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 自动调整列宽
|
|
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
|
|
+ sheet.setColumnWidth(i, 20 * 256);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void createDataRow(Sheet sheet, int rowNum, String systemName, String alarmType,
|
|
|
|
|
+ String alarmCategory, Long total, Long untreated) {
|
|
|
|
|
+ Row dataRow = sheet.createRow(rowNum);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建单元格样式(带边框)
|
|
|
|
|
+ CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
|
|
|
|
|
+ BorderStyle borderStyle = BorderStyle.THIN;
|
|
|
|
|
+ cellStyle.setBorderTop(borderStyle);
|
|
|
|
|
+ cellStyle.setBorderBottom(borderStyle);
|
|
|
|
|
+ cellStyle.setBorderLeft(borderStyle);
|
|
|
|
|
+ cellStyle.setBorderRight(borderStyle);
|
|
|
|
|
+
|
|
|
|
|
+ // 设置数据单元格
|
|
|
|
|
+ dataRow.createCell(0).setCellValue(systemName);
|
|
|
|
|
+ dataRow.createCell(1).setCellValue(alarmType);
|
|
|
|
|
+ dataRow.createCell(2).setCellValue(alarmCategory);
|
|
|
|
|
+ dataRow.createCell(3).setCellValue(total != null ? total.doubleValue() : 0);
|
|
|
|
|
+ dataRow.createCell(4).setCellValue(untreated != null ? untreated.doubleValue() : 0);
|
|
|
|
|
+
|
|
|
|
|
+ // 应用边框样式到所有单元格
|
|
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
|
|
+ dataRow.getCell(i).setCellStyle(cellStyle);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ /*private void createSystemStatsSheetNew(Workbook workbook, CellStyle headerStyle, CellStyle dataStyle, String month, DashboardVO dashboardVO) {
|
|
|
Sheet sheet = workbook.createSheet("系统统计");
|
|
Sheet sheet = workbook.createSheet("系统统计");
|
|
|
|
|
|
|
|
// 创建标题行
|
|
// 创建标题行
|
|
@@ -205,7 +362,8 @@ public class ExcelExportUtil {
|
|
|
for (int i = 0; i < headers.length; i++) {
|
|
for (int i = 0; i < headers.length; i++) {
|
|
|
sheet.setColumnWidth(i, 20 * 256);
|
|
sheet.setColumnWidth(i, 20 * 256);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 创建整体统计Sheet
|
|
* 创建整体统计Sheet
|