|
|
@@ -1,10 +1,7 @@
|
|
|
package com.uas.report.controller;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.OutputStream;
|
|
|
-import java.net.URLEncoder;
|
|
|
import java.sql.SQLException;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
@@ -15,8 +12,6 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import org.dom4j.DocumentException;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@@ -53,8 +48,6 @@ public class PrintController {
|
|
|
@Autowired
|
|
|
private FileService fileService;
|
|
|
|
|
|
- private static Logger logger = LoggerFactory.getLogger(PrintController.class);
|
|
|
-
|
|
|
/**
|
|
|
* 为UAS系统打印提供服务, 根据printType进行预览、打印、下载pdf、下载纯数据excel等操作
|
|
|
*
|
|
|
@@ -156,8 +149,6 @@ public class PrintController {
|
|
|
exportFileType = ReportConstants.FILE_TYPE_PDF;
|
|
|
}
|
|
|
|
|
|
- byte[] data = null;
|
|
|
-
|
|
|
String filePath = ReportConstants.GENERATED_FILES_PATH + reportName + "/"
|
|
|
+ fileService.generateFileName(userName, profile, whereCondition, otherParameters, exportFileType);
|
|
|
if (exportFileType.equals(ReportConstants.FILE_TYPE_EXCEL_DATA)) {
|
|
|
@@ -173,34 +164,24 @@ public class PrintController {
|
|
|
if (printService.overload(userName, profile, reportName, whereCondition, otherParameters, Platform.PC)) {
|
|
|
throw new IllegalStateException("数据量过大,无法提供服务");
|
|
|
}
|
|
|
- data = printService.export(userName, profile, reportName, whereCondition, otherParameters, exportFileType);
|
|
|
+ byte[] data = printService.export(userName, profile, reportName, whereCondition, otherParameters,
|
|
|
+ exportFileType);
|
|
|
if (ArrayUtils.isEmpty(data)) {
|
|
|
throw new IllegalStateException("报表导出失败:" + userName + "/" + reportName + "\n");
|
|
|
}
|
|
|
FileUtils.write(file.getPath(), data);
|
|
|
- } else {
|
|
|
- data = FileUtils.readData(new FileInputStream(file));
|
|
|
}
|
|
|
|
|
|
- try {
|
|
|
- String exportFileName = title;
|
|
|
- if (StringUtils.isEmpty(exportFileName)) {
|
|
|
- exportFileName = reportName;
|
|
|
- }
|
|
|
- if (exportFileType.equals(ReportConstants.FILE_TYPE_EXCEL_DATA)) {
|
|
|
- exportFileName += "." + ReportConstants.FILE_TYPE_EXCEL;
|
|
|
- } else {
|
|
|
- exportFileName += "." + exportFileType;
|
|
|
- }
|
|
|
- response.setHeader("Content-Disposition",
|
|
|
- "attachment;filename=" + URLEncoder.encode(exportFileName, "UTF-8"));
|
|
|
- OutputStream outputStream = response.getOutputStream();
|
|
|
- outputStream.write(data);
|
|
|
- outputStream.flush();
|
|
|
- outputStream.close();
|
|
|
- } catch (IOException e) {
|
|
|
- logger.error("浏览器重复请求!");
|
|
|
+ String exportFileName = title;
|
|
|
+ if (StringUtils.isEmpty(exportFileName)) {
|
|
|
+ exportFileName = reportName;
|
|
|
+ }
|
|
|
+ if (exportFileType.equals(ReportConstants.FILE_TYPE_EXCEL_DATA)) {
|
|
|
+ exportFileName += "." + ReportConstants.FILE_TYPE_EXCEL;
|
|
|
+ } else {
|
|
|
+ exportFileName += "." + exportFileType;
|
|
|
}
|
|
|
+ fileService.rangeDownload(file, exportFileName, request, response);
|
|
|
}
|
|
|
|
|
|
/**
|