Merge pull request #7790 from dataease/pr@dev@fix_report_log_export
fix: 定时报告执行记录导出乱码
This commit is contained in:
commit
aa1740742e
@ -1,6 +1,5 @@
|
|||||||
package io.dataease.plugins.server;
|
package io.dataease.plugins.server;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
@ -24,6 +23,8 @@ import io.dataease.service.ScheduleService;
|
|||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.io.ByteArrayResource;
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
@ -35,10 +36,10 @@ import org.springframework.web.util.HtmlUtils;
|
|||||||
import springfox.documentation.annotations.ApiIgnore;
|
import springfox.documentation.annotations.ApiIgnore;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.ServletOutputStream;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.*;
|
import java.io.OutputStream;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -340,35 +341,52 @@ public class XEmailTaskServer {
|
|||||||
Pager<List<XpackTaskInstanceDTO>> listPager = instancesGrid(0, 0, request);
|
Pager<List<XpackTaskInstanceDTO>> listPager = instancesGrid(0, 0, request);
|
||||||
List<XpackTaskInstanceDTO> instanceDTOS = listPager.getListObject();
|
List<XpackTaskInstanceDTO> instanceDTOS = listPager.getListObject();
|
||||||
ExcelSheetModel excelSheetModel = excelSheetModel(instanceDTOS);
|
ExcelSheetModel excelSheetModel = excelSheetModel(instanceDTOS);
|
||||||
List<ExcelSheetModel> sheetModels = new ArrayList<>();
|
|
||||||
sheetModels.add(excelSheetModel);
|
|
||||||
File file = ExcelUtils.exportExcel(sheetModels, null, null);
|
|
||||||
InputStream inputStream = new FileInputStream(file);
|
|
||||||
HttpServletResponse response = ServletUtils.response();
|
HttpServletResponse response = ServletUtils.response();
|
||||||
|
OutputStream outputStream = response.getOutputStream();
|
||||||
try {
|
try {
|
||||||
String filename = file.getName();
|
Workbook wb = new SXSSFWorkbook();
|
||||||
response.reset();
|
Sheet detailsSheet = wb.createSheet(excelSheetModel.getSheetName());
|
||||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
CellStyle cellStyle = wb.createCellStyle();
|
||||||
response.setContentType("application/octet-stream;charset=UTF-8");
|
Font font = wb.createFont();
|
||||||
response.addHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));
|
//设置字体大小
|
||||||
ServletOutputStream outputStream = response.getOutputStream();
|
font.setFontHeightInPoints((short) 12);
|
||||||
byte[] buff = new byte[1024];
|
//设置字体加粗
|
||||||
BufferedInputStream bis = null;
|
font.setBold(true);
|
||||||
// 读取文件
|
//给字体设置样式
|
||||||
bis = new BufferedInputStream(inputStream);
|
cellStyle.setFont(font);
|
||||||
int i = bis.read(buff);
|
//设置单元格背景颜色
|
||||||
while (i != -1) {
|
cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
||||||
outputStream.write(buff, 0, buff.length);
|
//设置单元格填充样式(使用纯色背景颜色填充)
|
||||||
outputStream.flush();
|
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||||
i = bis.read(buff);
|
List<List<String>> details = null;
|
||||||
|
if (CollectionUtils.isNotEmpty(details = excelSheetModel.getData())) {
|
||||||
|
details.add(0, excelSheetModel.getHeads());
|
||||||
|
for (int i = 0; i < details.size(); i++) {
|
||||||
|
Row row = detailsSheet.createRow(i);
|
||||||
|
List<String> rowData = details.get(i);
|
||||||
|
if (rowData != null) {
|
||||||
|
for (int j = 0; j < rowData.size(); j++) {
|
||||||
|
Cell cell = row.createCell(j);
|
||||||
|
cell.setCellValue(rowData.get(j));
|
||||||
|
if (i == 0) {// 头部
|
||||||
|
detailsSheet.setColumnWidth(j, 255 * 20);
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response.setContentType("application/vnd.ms-excel");
|
||||||
|
//文件名称
|
||||||
|
String fileName = excelSheetModel.getSheetName();
|
||||||
|
String encodeFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8);
|
||||||
|
response.setHeader("Content-disposition", "attachment;filename=" + encodeFileName + ".xlsx");
|
||||||
|
wb.write(outputStream);
|
||||||
|
outputStream.flush();
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
inputStream.close();
|
} catch (Exception e) {
|
||||||
} catch (IOException ex) {
|
DataEaseException.throwException(e);
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (file.exists())
|
|
||||||
FileUtil.del(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user