|
@@ -17,6 +17,8 @@ import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
|
|
|
|
+import com.uas.report.model.ExportType;
|
|
|
|
|
+import com.uas.report.model.PrintType;
|
|
|
import com.uas.report.service.FileService;
|
|
import com.uas.report.service.FileService;
|
|
|
import com.uas.report.service.PrintService;
|
|
import com.uas.report.service.PrintService;
|
|
|
import com.uas.report.util.ArrayUtils;
|
|
import com.uas.report.util.ArrayUtils;
|
|
@@ -81,37 +83,31 @@ public class PrintController {
|
|
|
throws JRException, IOException, DocumentException, SQLException, ServletException {
|
|
throws JRException, IOException, DocumentException, SQLException, ServletException {
|
|
|
userName = userName == null ? null : userName.toUpperCase();
|
|
userName = userName == null ? null : userName.toUpperCase();
|
|
|
// printType为空,默认进入预览页
|
|
// printType为空,默认进入预览页
|
|
|
- if (StringUtils.isEmpty(printType)) {
|
|
|
|
|
- printType = ReportConstants.PRINT_TYPE_PREVIEW;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ PrintType type = StringUtils.isEmpty(printType) ? PrintType.PREVIEW : PrintType.checkType(printType);
|
|
|
|
|
|
|
|
|
|
+ switch (type) {
|
|
|
// 预览或打印
|
|
// 预览或打印
|
|
|
- if (printType.equals(ReportConstants.PRINT_TYPE_PREVIEW)
|
|
|
|
|
- || printType.equals(ReportConstants.PRINT_TYPE_PRINT)) {
|
|
|
|
|
|
|
+ case PREVIEW:
|
|
|
|
|
+ case PRINT:
|
|
|
request.getRequestDispatcher("preview?t=" + timestamp).forward(request, response);
|
|
request.getRequestDispatcher("preview?t=" + timestamp).forward(request, response);
|
|
|
- }
|
|
|
|
|
- // 下载pdf、纯数据excel
|
|
|
|
|
- else if (printType.equals(ReportConstants.PRINT_TYPE_PDF)) {
|
|
|
|
|
- export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.FILE_TYPE_PDF, true,
|
|
|
|
|
|
|
+ break;
|
|
|
|
|
+ case PDF:
|
|
|
|
|
+ export(userName, profile, reportName, whereCondition, otherParameters, ExportType.PDF.getQualifier(), true,
|
|
|
title, request, response);
|
|
title, request, response);
|
|
|
- }
|
|
|
|
|
- // 该下载接口供UAS系统使用,应其要求,PRINT_TYPE_EXCEL只能为EXCEL(该值意思本应为下载全部数据的excel),
|
|
|
|
|
- // 导致与FILE_TYPE_EXCEL_DATA(下载纯数据的excel)命名不相匹配
|
|
|
|
|
- else if (printType.equals(ReportConstants.PRINT_TYPE_EXCEL)) {
|
|
|
|
|
- export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.FILE_TYPE_EXCEL_DATA,
|
|
|
|
|
|
|
+ break;
|
|
|
|
|
+ // 该下载接口供 UAS 系统使用,应其要求,printType 为{@link PrintType.EXCEL}时,下载纯数据的 excel
|
|
|
|
|
+ case EXCEL:
|
|
|
|
|
+ export(userName, profile, reportName, whereCondition, otherParameters, ExportType.XLS_DATA.getQualifier(),
|
|
|
true, title, request, response);
|
|
true, title, request, response);
|
|
|
- }
|
|
|
|
|
- // 下载word
|
|
|
|
|
- else if (printType.equals(ReportConstants.PRINT_TYPE_WORD)) {
|
|
|
|
|
- export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.FILE_TYPE_WORD, true,
|
|
|
|
|
|
|
+ break;
|
|
|
|
|
+ case WORD:
|
|
|
|
|
+ export(userName, profile, reportName, whereCondition, otherParameters, ExportType.DOC.getQualifier(), true,
|
|
|
title, request, response);
|
|
title, request, response);
|
|
|
- }
|
|
|
|
|
- // 下载text
|
|
|
|
|
- else if (printType.equals(ReportConstants.PRINT_TYPE_TEXT)) {
|
|
|
|
|
- export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.FILE_TYPE_TEXT, true,
|
|
|
|
|
|
|
+ break;
|
|
|
|
|
+ case TEXT:
|
|
|
|
|
+ export(userName, profile, reportName, whereCondition, otherParameters, ExportType.TXT.getQualifier(), true,
|
|
|
title, request, response);
|
|
title, request, response);
|
|
|
- } else {
|
|
|
|
|
- throw new IllegalArgumentException("printType不合法");
|
|
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -150,17 +146,12 @@ public class PrintController {
|
|
|
userName = userName == null ? null : userName.toUpperCase();
|
|
userName = userName == null ? null : userName.toUpperCase();
|
|
|
ReportUtils.checkParameters(userName, reportName);
|
|
ReportUtils.checkParameters(userName, reportName);
|
|
|
String masterOfJrxml = printService.getMasterOfJrxml(userName, reportName);
|
|
String masterOfJrxml = printService.getMasterOfJrxml(userName, reportName);
|
|
|
- if (StringUtils.isEmpty(exportFileType)) {
|
|
|
|
|
- exportFileType = ReportConstants.FILE_TYPE_PDF;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ExportType exportType = StringUtils.isEmpty(exportFileType) ? ExportType.PDF
|
|
|
|
|
+ : ExportType.checkType(exportFileType);
|
|
|
|
|
|
|
|
String filePath = ReportConstants.GENERATED_FILES_PATH + reportName + "/"
|
|
String filePath = ReportConstants.GENERATED_FILES_PATH + reportName + "/"
|
|
|
- + fileService.generateFileName(userName, profile, whereCondition, otherParameters, exportFileType);
|
|
|
|
|
- if (exportFileType.equals(ReportConstants.FILE_TYPE_EXCEL_DATA)) {
|
|
|
|
|
- filePath += "." + ReportConstants.FILE_TYPE_EXCEL;
|
|
|
|
|
- } else {
|
|
|
|
|
- filePath += "." + exportFileType;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ + fileService.generateFileName(userName, profile, whereCondition, otherParameters, exportFileType) + "."
|
|
|
|
|
+ + exportType.getQualifier();
|
|
|
File file = new File(ReportConstants.GENERATED_FILES_DIR + filePath);
|
|
File file = new File(ReportConstants.GENERATED_FILES_DIR + filePath);
|
|
|
// 指定flush为true(强制刷新pdf、xls)
|
|
// 指定flush为true(强制刷新pdf、xls)
|
|
|
// 文件无效(不存在或过期),创建
|
|
// 文件无效(不存在或过期),创建
|
|
@@ -170,22 +161,14 @@ public class PrintController {
|
|
|
throw new IllegalStateException("数据量过大,无法提供服务");
|
|
throw new IllegalStateException("数据量过大,无法提供服务");
|
|
|
}
|
|
}
|
|
|
byte[] data = printService.export(userName, profile, reportName, whereCondition, otherParameters,
|
|
byte[] data = printService.export(userName, profile, reportName, whereCondition, otherParameters,
|
|
|
- exportFileType);
|
|
|
|
|
|
|
+ exportType);
|
|
|
if (ArrayUtils.isEmpty(data)) {
|
|
if (ArrayUtils.isEmpty(data)) {
|
|
|
throw new IllegalStateException("报表导出失败:" + userName + "/" + reportName + "\n");
|
|
throw new IllegalStateException("报表导出失败:" + userName + "/" + reportName + "\n");
|
|
|
}
|
|
}
|
|
|
FileUtils.write(file.getPath(), data);
|
|
FileUtils.write(file.getPath(), data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- 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;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ String exportFileName = (!StringUtils.isEmpty(title) ? title : reportName) + "." + exportType.getQualifier();
|
|
|
fileService.rangeDownload(file, exportFileName, request, response);
|
|
fileService.rangeDownload(file, exportFileName, request, response);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -224,8 +207,8 @@ public class PrintController {
|
|
|
|
|
|
|
|
// 相对路径,返回给前端
|
|
// 相对路径,返回给前端
|
|
|
String pdfPath = ReportConstants.GENERATED_FILES_PATH + reportName + "/" + fileService
|
|
String pdfPath = ReportConstants.GENERATED_FILES_PATH + reportName + "/" + fileService
|
|
|
- .generateFileName(userName, profile, whereCondition, otherParameters, ReportConstants.FILE_TYPE_PDF)
|
|
|
|
|
- + "." + ReportConstants.FILE_TYPE_PDF;
|
|
|
|
|
|
|
+ .generateFileName(userName, profile, whereCondition, otherParameters, ExportType.PDF.getQualifier())
|
|
|
|
|
+ + "." + ExportType.PDF.getQualifier();
|
|
|
File file = new File(ReportConstants.GENERATED_FILES_DIR + pdfPath);
|
|
File file = new File(ReportConstants.GENERATED_FILES_DIR + pdfPath);
|
|
|
// 指定flush为true(强制刷新pdf)
|
|
// 指定flush为true(强制刷新pdf)
|
|
|
// 文件无效(不存在或过期),重新创建pdf文件
|
|
// 文件无效(不存在或过期),重新创建pdf文件
|