From bab470926b3edba404d455f1cf0f6c8bf929f7b5 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期一, 28 八月 2023 15:07:25 +0800
Subject: [PATCH] 导出修复
---
server/src/main/java/doumeemes/dao/system/model/SystemLoginLog.java | 27 +++---
platform_web/.env.development | 4
server/src/main/java/doumeemes/api/system/SystemLoginLogController.java | 3
platform_web/src/views/system/loginLog.vue | 4
server/src/main/java/doumeemes/core/annotation/excel/ExcelColumn.java | 2
server/src/main/resources/application.yml | 3
server/src/main/java/doumeemes/core/annotation/excel/ExcelExporter.java | 182 +++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 204 insertions(+), 21 deletions(-)
diff --git a/platform_web/.env.development b/platform_web/.env.development
index 53c2611..797c589 100644
--- a/platform_web/.env.development
+++ b/platform_web/.env.development
@@ -16,10 +16,10 @@
#姹熻悕鏈湴
-# VUE_APP_BASE_URL = 'http://192.168.0.35:10021/'
+VUE_APP_BASE_URL = 'http://192.168.0.35:10021/'
#鐒︽澗
-VUE_APP_BASE_URL = 'http://192.168.0.36:10021/'
+#VUE_APP_BASE_URL = 'http://192.168.0.36:10021/'
#鍒樼纾婃湰鍦�
# VUE_APP_BASE_URL = 'http://192.168.0.18:10021/'
diff --git a/platform_web/src/views/system/loginLog.vue b/platform_web/src/views/system/loginLog.vue
index 3673268..e7c0584 100644
--- a/platform_web/src/views/system/loginLog.vue
+++ b/platform_web/src/views/system/loginLog.vue
@@ -62,9 +62,9 @@
<el-table-column prop="companyUserId" label="鐢ㄦ埛id" align="center" min-width="100px"></el-table-column>
<el-table-column prop="companyName" label="浼佷笟鍚嶇О" align="center" min-width="100px"></el-table-column>
<el-table-column prop="loginUsername" label="鐧诲綍鐢ㄦ埛鍚�" align="center" min-width="100px"></el-table-column>
- <el-table-column prop="companyUserName" label="鐧诲綍鐢ㄦ埛鍚�" align="center" min-width="100px">
+ <el-table-column prop="companyUserName" label="浼佷笟鐢ㄦ埛鍚嶇О" align="center" min-width="100px">
<template slot-scope="{row}">
- {{ row.companyUserName || row.loginUsername }}
+ {{ row.companyUserName}}
</template>
</el-table-column>
<el-table-column prop="ip" label="鐧诲綍IP" align="center" min-width="120px"></el-table-column>
diff --git a/server/src/main/java/doumeemes/api/system/SystemLoginLogController.java b/server/src/main/java/doumeemes/api/system/SystemLoginLogController.java
index d9054cd..de8b960 100644
--- a/server/src/main/java/doumeemes/api/system/SystemLoginLogController.java
+++ b/server/src/main/java/doumeemes/api/system/SystemLoginLogController.java
@@ -5,6 +5,7 @@
import doumeemes.core.model.ApiResponse;
import doumeemes.core.model.PageData;
import doumeemes.core.model.PageWrap;
+import doumeemes.core.utils.DateUtil;
import doumeemes.dao.system.dto.QuerySystemLoginLogDTO;
import doumeemes.dao.system.model.SystemLoginLog;
import doumeemes.service.system.SystemLoginLogService;
@@ -39,6 +40,6 @@
@ApiOperation("瀵煎嚭Excel")
@RequiresPermissions("system:loginLog:query")
public void export (@RequestBody PageWrap<QuerySystemLoginLogDTO> pageWrap, HttpServletResponse response) {
- ExcelExporter.build(SystemLoginLog.class).export(systemLoginLogService.findPage(pageWrap).getRecords(), "鐧诲綍鏃ュ織", response);
+ ExcelExporter.build(SystemLoginLog.class).exportWithFirstAndEnd(systemLoginLogService.findPage(pageWrap).getRecords(), "鐧诲綍鏃ュ織_"+System.currentTimeMillis(),"鐧诲綍鏃ュ織-"+ DateUtil.getPlusTime2(DateUtil.getCurrentDate()),null, response);
}
}
diff --git a/server/src/main/java/doumeemes/core/annotation/excel/ExcelColumn.java b/server/src/main/java/doumeemes/core/annotation/excel/ExcelColumn.java
index 8755537..91cb9cd 100644
--- a/server/src/main/java/doumeemes/core/annotation/excel/ExcelColumn.java
+++ b/server/src/main/java/doumeemes/core/annotation/excel/ExcelColumn.java
@@ -34,7 +34,7 @@
/**
* 瀵归綈鏂瑰紡
*/
- HorizontalAlignment align() default HorizontalAlignment.LEFT;
+ HorizontalAlignment align() default HorizontalAlignment.LEFT;
/**
* 鍒楄儗鏅壊
diff --git a/server/src/main/java/doumeemes/core/annotation/excel/ExcelExporter.java b/server/src/main/java/doumeemes/core/annotation/excel/ExcelExporter.java
index 010996c..5ac8412 100644
--- a/server/src/main/java/doumeemes/core/annotation/excel/ExcelExporter.java
+++ b/server/src/main/java/doumeemes/core/annotation/excel/ExcelExporter.java
@@ -10,8 +10,10 @@
import org.apache.commons.lang3.CharUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
+import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
@@ -150,8 +152,188 @@
public void export (List<T> data, String fileName, HttpServletResponse response) {
this.export(data, fileName, DEFAULT_SHEET_NAME, response);
}
+ /**
+ * 瀵煎嚭鑷冲搷搴旀祦
+ * @param data 鏁版嵁
+ * @param fileName Excel鏂囦欢鍚�
+ * @param response HttpServletResponse瀵硅薄
+ */
+ public void exportWithFirstAndEnd (List<T> data, String fileName,String first,String end, HttpServletResponse response) {
+ this.exportWithFirstAndEnd(data, fileName, DEFAULT_SHEET_NAME, first,end,response);
+ }
/**
+ * 瀵煎嚭鑷冲搷搴旀祦
+ * @param data 鏁版嵁
+ * @param fileName Excel鏂囦欢鍚�
+ * @param sheetName Sheet鍚嶇О
+ * @param response HttpServletResponse瀵硅薄
+ */
+ public void exportWithFirstAndEnd (List<T> data, String fileName, String sheetName, String first,String end ,HttpServletResponse response) {
+ try {
+ String encodeFileName = URLEncoder.encode(fileName, Charset.forName("UTF-8").toString()) + ".xlsx";
+ response.setHeader("Content-Disposition","attachment;filename=" + encodeFileName);
+ response.setContentType("application/octet-stream");
+ response.setHeader("eva-opera-type", "download");
+ response.setHeader("eva-download-filename", encodeFileName);
+ this.exportWithFirstAndEnd(data, sheetName,first,end, response.getOutputStream());
+ } catch (IOException e) {
+ throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
+ }
+ }
+ /**
+ * 瀵煎嚭鍒版寚瀹氳緭鍑烘祦
+ * @param data 鏁版嵁
+ * @param sheetName Sheet鍚嶇О
+ */
+ public void exportWithFirstAndEnd (List<T> data, String sheetName,String first,String end, OutputStream os) {
+ SXSSFWorkbook sxssfWorkbook;
+ try {
+ sxssfWorkbook = new SXSSFWorkbook();
+ Sheet sheet = sxssfWorkbook.createSheet(sheetName);
+ // 鍒涘缓鍒楀ご
+ sheet.createFreezePane(0, 2);
+ sheet.addMergedRegion(new CellRangeAddress(0 ,0,0,this.getColumns().size()-1));
+ Row title = sheet.createRow(0);
+ title.setHeight((short) 1000);
+ Cell c = title.createCell(0);
+ c.setCellValue(first);
+ configFirstCell(sxssfWorkbook,c);
+
+ Row header = sheet.createRow(1);
+ header.setHeight((short)600);
+ List<ColumnInfo> columns = this.getColumns();
+ for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) {
+ ColumnInfo column = columns.get(columnIndex);
+ Cell cell = header.createCell(columnIndex);
+ cell.setCellValue(new HSSFRichTextString(column.columnConfig.name()));
+ // 鍒楀璁剧疆
+ if (column.columnConfig.width() == -1) {
+ sheet.setColumnWidth(columnIndex, column.columnConfig.name().length() * 2 * 256);
+ } else {
+ sheet.setColumnWidth(columnIndex, column.columnConfig.width() * 2 * 256);
+ }
+ // 璁剧疆鍒楀ご鍗曞厓鏍�
+ configHeaderCell(sxssfWorkbook, cell, column.columnConfig);
+ }
+ // 鍒涘缓鏁版嵁璁板綍
+ for (int rowIndex = 0; rowIndex < data.size(); rowIndex++) {
+ Row row = sheet.createRow(rowIndex + 2);
+ for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) {
+ ColumnInfo column = columns.get(columnIndex);
+ Cell cell = row.createCell(columnIndex);
+ cell.setCellValue(getCellData(column, data.get(rowIndex)));
+ // 璁剧疆鏁版嵁鍗曞厓鏍�
+ configDataCell(sxssfWorkbook, cell, column.columnConfig);
+ }
+ }
+ if(StringUtils.isNotBlank(end)){
+ sheet.addMergedRegion(new CellRangeAddress(data.size()+2 ,data.size()+2,0,this.getColumns().size()-1));
+ Row endRow = sheet.createRow(data.size()+2);
+// endRow.setHeight((short) 600);
+ Cell c1 = endRow.createCell(0);
+ c1.setCellValue(end);
+ configEndCell(sxssfWorkbook,c1);
+ }
+ sxssfWorkbook.write(os);
+ os.close();
+ } catch (Exception e) {
+ throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
+ } finally {
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ /**
+ * 閰嶇疆鏁版嵁鍗曞厓鏍�
+ */
+ private void configDataCell (SXSSFWorkbook workbook, Cell cell, ExcelColumn columnConfig) {
+ CellStyle style = workbook.createCellStyle();
+ style.setAlignment(columnConfig.align());
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鑳屾櫙
+ style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+ style.setFillForegroundColor(columnConfig.dataBackgroundColor().getIndex());
+ // 瀛椾綋
+ Font font = workbook.createFont();
+ font.setFontHeightInPoints(columnConfig.fontSize());
+ // 瀛椾綋棰滆壊
+ font.setColor(columnConfig.color().getIndex());
+ // 绮椾綋
+ font.setBold(columnConfig.bold());
+ // 鏂滀綋
+ font.setItalic(columnConfig.italic());
+ style.setFont(font);
+ // 杈规
+ configCellBorder(style);
+ style.setWrapText(true);
+ cell.setCellStyle(style);
+ }
+ /**
+ * 閰嶇疆鍒楀ご鍗曞厓鏍�
+ */
+ private void configFirstCell (SXSSFWorkbook workbook, Cell cell ) {
+ CellStyle style = workbook.createCellStyle();
+ style.setAlignment(HorizontalAlignment.CENTER);
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鑳屾櫙
+ style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+ style.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
+ // 瀛椾綋
+ Font font = workbook.createFont();
+ font.setFontHeightInPoints((short)24);
+ font.setBold(true);
+ style.setFont(font);
+ // 璁剧疆杈规
+ configCellBorder(style);
+ cell.setCellStyle(style);
+ }
+ /**
+ * 閰嶇疆鍒楀ご鍗曞厓鏍�
+ */
+ private void configEndCell (SXSSFWorkbook workbook, Cell cell ) {
+ CellStyle style = workbook.createCellStyle();
+ style.setAlignment(HorizontalAlignment.RIGHT);
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鑳屾櫙
+ style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+ style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
+ // 瀛椾綋
+ Font font = workbook.createFont();
+ font.setFontHeightInPoints((short)14);
+ style.setFont(font);
+ // 璁剧疆杈规
+ configCellBorder(style);
+ cell.setCellStyle(style);
+ }
+ /**
+ * 閰嶇疆鍒楀ご鍗曞厓鏍�
+ */
+ private void configHeaderCell (SXSSFWorkbook workbook, Cell cell, ExcelColumn columnConfig) {
+ CellStyle style = workbook.createCellStyle();
+ style.setAlignment(columnConfig.align());
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鑳屾櫙
+ style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+// style.setFillForegroundColor(columnConfig.backgroundColor().getIndex());
+ style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
+ // 瀛椾綋
+ Font font = workbook.createFont();
+ font.setFontHeightInPoints((short)11);
+ font.setColor(columnConfig.color().index);
+ font.setBold(true);
+ style.setFont(font);
+ // 璁剧疆杈规
+ style.setWrapText(true);
+ configCellBorder(style);
+ cell.setCellStyle(style);
+ }
+ /**
* 鑾峰彇鍒楅泦鍚�
*/
private List<ColumnInfo> getColumns () {
diff --git a/server/src/main/java/doumeemes/dao/system/model/SystemLoginLog.java b/server/src/main/java/doumeemes/dao/system/model/SystemLoginLog.java
index 2b32cbe..a21e31d 100644
--- a/server/src/main/java/doumeemes/dao/system/model/SystemLoginLog.java
+++ b/server/src/main/java/doumeemes/dao/system/model/SystemLoginLog.java
@@ -33,14 +33,25 @@
@ExcelColumn(name="鏉ユ簮", valueMapping = "0=PC骞冲彴;1=閽夐拤骞冲彴;2=缇氱緤骞冲彴;3=EDGP骞冲彴;4=寰俊灏忕▼搴�",width = 6,align = HorizontalAlignment.CENTER)
private Integer orgin;
@ApiModelProperty(value = "浼佷笟鐢ㄦ埛缂栫爜", example = "1")
+ @ExcelColumn(name="浼佷笟鐢ㄦ埛ID", width = 6)
private Integer companyUserId;
+
+ @ApiModelProperty(value = "浼佷笟鍚嶇О")
+ @ExcelColumn(name="浼佷笟鍚嶇О", width = 16)
+ @TableField(exist = false)
+ private String companyName;
+
+ @ApiModelProperty(value = "浼佷笟鐢ㄦ埛鍚嶇О")
+ @ExcelColumn(name="浼佷笟鐢ㄦ埛鍚嶇О", width = 16)
+ @TableField(exist = false)
+ private String companyUserName;
@ApiModelProperty(value = "鐧诲綍鐢ㄦ埛鍚�")
@ExcelColumn(name="鐧诲綍鐢ㄦ埛鍚�")
private String loginUsername;
@ApiModelProperty(value = "鐧诲綍IP")
- @ExcelColumn(name="鐧诲綍IP", color = IndexedColors.RED, width = 8)
+ @ExcelColumn(name="鐧诲綍IP", width = 8)
private String ip;
@ApiModelProperty(value = "鐧诲綍鍦板潃")
@@ -68,24 +79,14 @@
private String serverIp;
@ApiModelProperty(value = "鏄惁鐧诲綍鎴愬姛")
- @ExcelColumn(name="鏄惁鐧诲綍鎴愬姛", valueMapping = "true=鏄�;false=鍚�", align = HorizontalAlignment.CENTER)
+ @ExcelColumn(name="鏄惁鎴愬姛", valueMapping = "true=鎴愬姛;false=澶辫触", align = HorizontalAlignment.CENTER)
private Boolean success;
@ApiModelProperty(value = "澶辫触鍘熷洜")
- @ExcelColumn(name="澶辫触鍘熷洜", color = IndexedColors.RED, width = 16)
+ @ExcelColumn(name="澶辫触鍘熷洜", width = 16)
private String reason;
@ApiModelProperty(value = "鐧诲綍鏃堕棿")
@ExcelColumn(name="鐧诲綍鏃堕棿", dateFormat = "yyyy-MM-dd HH:mm:ss", width = 10)
private Date loginTime;
- @ApiModelProperty(value = "浼佷笟鍚嶇О")
- @ExcelColumn(name="浼佷笟鍚嶇О", color = IndexedColors.RED, width = 16)
- @TableField(exist = false)
- private String companyName;
-
- @ApiModelProperty(value = "浼佷笟鐢ㄦ埛鍚嶇О")
- @ExcelColumn(name="浼佷笟鐢ㄦ埛鍚嶇О", color = IndexedColors.RED, width = 16)
- @TableField(exist = false)
- private String companyUserName;
-
}
diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml
index dd0fac5..1fa517e 100644
--- a/server/src/main/resources/application.yml
+++ b/server/src/main/resources/application.yml
@@ -5,12 +5,11 @@
env: development
# env: production
-
spring:
# application:
# name: doumeemes
profiles:
- active: standardPro
+ active: standard
# JSON杩斿洖閰嶇疆
jackson:
# 榛樿鏃跺尯
--
Gitblit v1.9.3