|
|
@@ -85,9 +85,14 @@ public class PrintController {
|
|
|
}
|
|
|
// 下载pdf、纯数据excel
|
|
|
else if (printType.equals(ReportConstants.PDF_PRINT_TYPE)) {
|
|
|
- export(userName, profile, reportName, whereCondition, otherParameters, "pdf", response);
|
|
|
- } else if (printType.equals(ReportConstants.EXCEL_PRINT_TYPE)) {
|
|
|
- export(userName, profile, reportName, whereCondition, otherParameters, "xls_with_only_data", response);
|
|
|
+ export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.PDF_FILE_TYPE,
|
|
|
+ response);
|
|
|
+ }
|
|
|
+ // 该下载接口供UAS系统使用,应其要求,EXCEL_PRINT_TYPE只能为EXCEL(该值意思本应为下载全部数据的excel),
|
|
|
+ // 导致与EXCEL_WITH_ONLY_DATA_FILE_TYPE(下载纯数据的excel)命名不相匹配
|
|
|
+ else if (printType.equals(ReportConstants.EXCEL_PRINT_TYPE)) {
|
|
|
+ export(userName, profile, reportName, whereCondition, otherParameters,
|
|
|
+ ReportConstants.EXCEL_WITH_ONLY_DATA_FILE_TYPE, response);
|
|
|
} else {
|
|
|
throw new ReportException("printType不合法");
|
|
|
}
|
|
|
@@ -119,15 +124,15 @@ public class PrintController {
|
|
|
|
|
|
logger.info("开始导出报表:" + reportName);
|
|
|
if (StringUtils.isEmpty(exportFileType)) {
|
|
|
- exportFileType = "pdf";
|
|
|
+ exportFileType = ReportConstants.PDF_FILE_TYPE;
|
|
|
}
|
|
|
|
|
|
byte[] data = null;
|
|
|
|
|
|
- String filePath = ReportConstants.GENERATED_FILES_PATH + reportName + "/"
|
|
|
- + fileService.generateFileName(userName, profile, reportName, whereCondition, otherParameters);
|
|
|
- if (exportFileType.equals("xls_with_only_data")) {
|
|
|
- filePath += ".xls";
|
|
|
+ String filePath = ReportConstants.GENERATED_FILES_PATH + reportName + "/" + fileService
|
|
|
+ .generateFileName(userName, profile, reportName, whereCondition, otherParameters, exportFileType);
|
|
|
+ if (exportFileType.equals(ReportConstants.EXCEL_WITH_ONLY_DATA_FILE_TYPE)) {
|
|
|
+ filePath += "." + ReportConstants.EXCEL_FILE_TYPE;
|
|
|
} else {
|
|
|
filePath += "." + exportFileType;
|
|
|
}
|
|
|
@@ -160,8 +165,8 @@ public class PrintController {
|
|
|
|
|
|
try {
|
|
|
String exportFileName = reportName;
|
|
|
- if (exportFileType.equals("xls_with_only_data")) {
|
|
|
- exportFileName += ".xls";
|
|
|
+ if (exportFileType.equals(ReportConstants.EXCEL_WITH_ONLY_DATA_FILE_TYPE)) {
|
|
|
+ exportFileName += "." + ReportConstants.EXCEL_FILE_TYPE;
|
|
|
} else {
|
|
|
exportFileName += "." + exportFileType;
|
|
|
}
|
|
|
@@ -206,7 +211,9 @@ public class PrintController {
|
|
|
|
|
|
// 相对路径,返回给前端
|
|
|
String pdfPath = ReportConstants.GENERATED_FILES_PATH + reportName + "/"
|
|
|
- + fileService.generateFileName(userName, profile, reportName, whereCondition, otherParameters) + ".pdf";
|
|
|
+ + fileService.generateFileName(userName, profile, reportName, whereCondition, otherParameters,
|
|
|
+ ReportConstants.PDF_FILE_TYPE)
|
|
|
+ + "." + ReportConstants.PDF_FILE_TYPE;
|
|
|
final File file = new File(PathUtils.getAppPath() + pdfPath);
|
|
|
if (pageIndex == null || pageIndex == 1) {
|
|
|
// 文件无效(不存在或过期),重新创建pdf文件
|
|
|
@@ -215,7 +222,9 @@ public class PrintController {
|
|
|
// 需要生成第一页(可能页数过多,提示用户不支持预览打印),再后台开线程生成总的pdf
|
|
|
// 先生成第一页pdf
|
|
|
Integer pageSize = printService.createPdfFile(userName, profile, reportName, whereCondition,
|
|
|
- otherParameters, file.getPath().replace(".pdf", "_1.pdf"), 1);
|
|
|
+ otherParameters, file.getPath().replace("." + ReportConstants.PDF_FILE_TYPE,
|
|
|
+ "_1." + ReportConstants.PDF_FILE_TYPE),
|
|
|
+ 1);
|
|
|
result.put("pageSize", pageSize);
|
|
|
// 再开线程生成后面页的pdf、总的pdf(即未分页的pdf)、纯数据excel
|
|
|
new Thread(new Runnable() {
|
|
|
@@ -232,10 +241,14 @@ public class PrintController {
|
|
|
}
|
|
|
} else {
|
|
|
// 文件无效(不存在或过期),重新创建pdf文件
|
|
|
- if (!fileService.isFileValid(file.getPath().replace(".pdf", "_" + pageIndex + ".pdf"),
|
|
|
+ if (!fileService.isFileValid(
|
|
|
+ file.getPath().replace("." + ReportConstants.PDF_FILE_TYPE,
|
|
|
+ "_" + pageIndex + "." + ReportConstants.PDF_FILE_TYPE),
|
|
|
fileService.getJrxmlFilePath(userName, reportName))) {
|
|
|
printService.createPdfFile(userName, profile, reportName, whereCondition, otherParameters,
|
|
|
- file.getPath().replace(".pdf", "_" + pageIndex + ".pdf"), pageIndex);
|
|
|
+ file.getPath().replace("." + ReportConstants.PDF_FILE_TYPE,
|
|
|
+ "_" + pageIndex + "." + ReportConstants.PDF_FILE_TYPE),
|
|
|
+ pageIndex);
|
|
|
}
|
|
|
}
|
|
|
result.put("pdfPath", pdfPath);
|
|
|
@@ -257,33 +270,40 @@ public class PrintController {
|
|
|
* @param otherParameters
|
|
|
* 若模板已指定需要的参数,则不可为null;其他参数,区别于whereCondition,报表某些字段的值取决于这些参数;
|
|
|
* JSON格式,数据为键值对
|
|
|
- * @param pdfOrXls
|
|
|
- * pdf或者xls
|
|
|
+ * @param fileType
|
|
|
+ * 文件格式,pdf、xls、xls_with_only_data
|
|
|
* @return 文件的信息
|
|
|
*/
|
|
|
@RequestMapping(value = "/getGeneratedPdfOrXlsInformation")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> getGeneratedPdfOrXlsInformation(String userName, String profile, String reportName,
|
|
|
- String whereCondition, String otherParameters, String pdfOrXls) {
|
|
|
+ String whereCondition, String otherParameters, String fileType) {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- if (StringUtils.isEmpty(pdfOrXls)) {
|
|
|
- pdfOrXls = "pdf";
|
|
|
+ if (StringUtils.isEmpty(fileType)) {
|
|
|
+ fileType = ReportConstants.PDF_FILE_TYPE;
|
|
|
}
|
|
|
- String filePath = ReportConstants.GENERATED_FILES_PATH + reportName + "/"
|
|
|
- + fileService.generateFileName(userName, profile, reportName, whereCondition, otherParameters);
|
|
|
- File file = new File(PathUtils.getAppPath() + filePath + "." + pdfOrXls);
|
|
|
- result.put("file", file.getPath());
|
|
|
- if (pdfOrXls.equals("pdf")) {
|
|
|
+ String filePath = ReportConstants.GENERATED_FILES_PATH + reportName + "/" + fileService.generateFileName(
|
|
|
+ userName, profile, reportName, whereCondition, otherParameters, ReportConstants.PDF_FILE_TYPE);
|
|
|
+ File file = null;
|
|
|
+ if (fileType.equals(ReportConstants.PDF_FILE_TYPE)) {
|
|
|
+ file = new File(PathUtils.getAppPath() + filePath + "." + ReportConstants.PDF_FILE_TYPE);
|
|
|
+ result.put("valid",
|
|
|
+ fileService.isFileValid(file.getPath(), fileService.getJrxmlFilePath(userName, reportName)));
|
|
|
+ result.put("size", file.length());
|
|
|
+ } else if (fileType.equals(ReportConstants.EXCEL_FILE_TYPE)) {
|
|
|
+ file = new File(PathUtils.getAppPath() + filePath + "." + ReportConstants.EXCEL_FILE_TYPE);
|
|
|
result.put("valid",
|
|
|
fileService.isFileValid(file.getPath(), fileService.getJrxmlFilePath(userName, reportName)));
|
|
|
result.put("size", file.length());
|
|
|
- } else if (pdfOrXls.equals("xls")) {
|
|
|
+ } else if (fileType.equals(ReportConstants.EXCEL_WITH_ONLY_DATA_FILE_TYPE)) {
|
|
|
+ file = new File(PathUtils.getAppPath() + filePath + "." + ReportConstants.EXCEL_FILE_TYPE);
|
|
|
result.put("valid",
|
|
|
fileService.isFileValid(file.getPath(), fileService.getJrxmlFilePath(userName, reportName)));
|
|
|
result.put("size", file.length());
|
|
|
} else {
|
|
|
- throw new ReportException("pdfOrXls只能为pdf或xls");
|
|
|
+ throw new ReportException("fileType只能为pdf、xls、xls_with_only_data");
|
|
|
}
|
|
|
+ result.put("file", file.getPath());
|
|
|
return result;
|
|
|
}
|
|
|
|