|
|
@@ -194,6 +194,7 @@ public class IotDailyCheckDataServiceImpl extends ServiceImpl<IotDailyCheckDataM
|
|
|
|
|
|
List<DailyCheckItemExportVo> exportDataList = new ArrayList<>();
|
|
|
String data = checkData.getData();
|
|
|
+ data = data.replaceAll("<br/>", "\r\n");
|
|
|
DailyCheckReq checkReq = JSON.parseObject(data, DailyCheckReq.class);
|
|
|
exportDataList.add(new DailyCheckItemExportVo(checkReq.getFsuElectric(), "电器火灾"));
|
|
|
exportDataList.add(new DailyCheckItemExportVo(checkReq.getVideoRecordComplete(), "昨日录像丢失"));
|
|
|
@@ -230,19 +231,35 @@ public class IotDailyCheckDataServiceImpl extends ServiceImpl<IotDailyCheckDataM
|
|
|
|
|
|
// 创建三行表头
|
|
|
createHeader(sheet, exportDataList.get(0));
|
|
|
-
|
|
|
+ // 创建单元格样式,并设置边框
|
|
|
+ CellStyle cellStyle = getCellStyle(workbook);
|
|
|
// 填充数据
|
|
|
int rowNum = 3; // 数据从第四行开始
|
|
|
for (DailyCheckItemExportVo exportVo : exportDataList) {
|
|
|
Row row = sheet.createRow(rowNum++);
|
|
|
- row.setHeight((short) 700);
|
|
|
+ row.setHeight((short) 800);
|
|
|
int colNum = 0;
|
|
|
// 填充行数据
|
|
|
- row.createCell(colNum++).setCellValue(exportVo.getType());
|
|
|
- row.createCell(colNum++).setCellValue(exportVo.getTotalCount());
|
|
|
- row.createCell(colNum++).setCellValue(exportVo.getExceptionCount());
|
|
|
- row.createCell(colNum++).setCellValue(exportVo.getResult());
|
|
|
- row.createCell(colNum++).setCellValue(exportVo.getResolution());
|
|
|
+ // 填充行数据
|
|
|
+ Cell cell = row.createCell(colNum++);
|
|
|
+ cell.setCellValue(exportVo.getType());
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ cell = row.createCell(colNum++);
|
|
|
+ cell.setCellValue(exportVo.getTotalCount());
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ cell = row.createCell(colNum++);
|
|
|
+ cell.setCellValue(exportVo.getExceptionCount());
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ cell = row.createCell(colNum++);
|
|
|
+ cell.setCellValue(exportVo.getResult());
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ cell = row.createCell(colNum++);
|
|
|
+ cell.setCellValue(exportVo.getResolution());
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
}
|
|
|
|
|
|
// 设置下载响应头
|
|
|
@@ -259,6 +276,16 @@ public class IotDailyCheckDataServiceImpl extends ServiceImpl<IotDailyCheckDataM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static CellStyle getCellStyle(Workbook workbook) {
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ cellStyle.setWrapText(true);
|
|
|
+ return cellStyle;
|
|
|
+ }
|
|
|
+
|
|
|
private static void createHeader(Sheet sheet, DailyCheckItemExportVo exportVo) {
|
|
|
|
|
|
|
|
|
@@ -269,7 +296,7 @@ public class IotDailyCheckDataServiceImpl extends ServiceImpl<IotDailyCheckDataM
|
|
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4)); // 合并第一行中的8个单元格
|
|
|
sheet.setHorizontallyCenter(true);
|
|
|
Workbook workbook = sheet.getWorkbook();
|
|
|
- firstRowCell.setCellStyle(createHeaderCellStyle(workbook, 24, HorizontalAlignment.CENTER, true));
|
|
|
+ firstRowCell.setCellStyle(createHeaderCellStyle(workbook, 24, HorizontalAlignment.CENTER, true, firstRow.getRowNum()));
|
|
|
|
|
|
|
|
|
// 第二行表头
|
|
|
@@ -277,17 +304,17 @@ public class IotDailyCheckDataServiceImpl extends ServiceImpl<IotDailyCheckDataM
|
|
|
Cell dateCell = secondRow.createCell(0);
|
|
|
dateCell.setCellValue("日期:" + exportVo.getTime()); // 假设第二行包含日期
|
|
|
sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 2)); // 合并第二行中的前3个单元格
|
|
|
- dateCell.setCellStyle(createHeaderCellStyle(workbook, 14, HorizontalAlignment.CENTER, true));
|
|
|
+ dateCell.setCellStyle(createHeaderCellStyle(workbook, 14, HorizontalAlignment.CENTER, true, secondRow.getRowNum()));
|
|
|
|
|
|
|
|
|
Cell orgCell = secondRow.createCell(3);
|
|
|
orgCell.setCellValue("机构:" + exportVo.getOrgName()); // 假设第二行包含日期
|
|
|
- orgCell.setCellStyle(createHeaderCellStyle(workbook, 14, null, true));
|
|
|
+ orgCell.setCellStyle(createHeaderCellStyle(workbook, 14, null, true, secondRow.getRowNum()));
|
|
|
|
|
|
|
|
|
Cell userNameCell = secondRow.createCell(4);
|
|
|
userNameCell.setCellValue("登记人:" + exportVo.getUserName()); // 假设第二行包含日期
|
|
|
- userNameCell.setCellStyle(createHeaderCellStyle(workbook, 14, null, true));
|
|
|
+ userNameCell.setCellStyle(createHeaderCellStyle(workbook, 14, null, true, secondRow.getRowNum()));
|
|
|
|
|
|
// 第三行表头
|
|
|
Row thirdRow = sheet.createRow(2);
|
|
|
@@ -297,13 +324,13 @@ public class IotDailyCheckDataServiceImpl extends ServiceImpl<IotDailyCheckDataM
|
|
|
Cell cell = thirdRow.createCell(i);
|
|
|
cell.setCellValue(thirdHeaders[i]);
|
|
|
// 设置字体加粗
|
|
|
- cell.setCellStyle(createHeaderCellStyle(workbook, 12, null, false));
|
|
|
+ cell.setCellStyle(createHeaderCellStyle(workbook, 12, null, false, thirdRow.getRowNum()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private static CellStyle createHeaderCellStyle(Workbook workbook, int fontSize, HorizontalAlignment alignment,
|
|
|
- boolean bgColor) {
|
|
|
+ boolean bgColor, Integer rowNums) {
|
|
|
CellStyle headerStyle = workbook.createCellStyle();
|
|
|
if (bgColor) {
|
|
|
headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
|
|
@@ -319,6 +346,13 @@ public class IotDailyCheckDataServiceImpl extends ServiceImpl<IotDailyCheckDataM
|
|
|
//是否加粗
|
|
|
headerFont.setBold(true);
|
|
|
headerStyle.setFont(headerFont);
|
|
|
+ if (rowNums == 2) {
|
|
|
+ headerStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ headerStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ headerStyle.setWrapText(true);
|
|
|
+ }
|
|
|
|
|
|
return headerStyle;
|
|
|
}
|