فهرست منبع

打印接口增加参数title,用于指定导出为文件时的名称

sunyj 8 سال پیش
والد
کامیت
1ae555af14
2فایلهای تغییر یافته به همراه15 افزوده شده و 8 حذف شده
  1. 13 6
      src/main/java/com/uas/report/controller/PrintController.java
  2. 2 2
      src/main/webapp/WEB-INF/views/console.html

+ 13 - 6
src/main/java/com/uas/report/controller/PrintController.java

@@ -64,12 +64,14 @@ public class PrintController {
 	 * @param printType
 	 *            打印类型,可为PREVIEW_PRINT_TYPE、PRINT_PRINT_TYPE、PDF_PRINT_TYPE、
 	 *            EXCEL_PRINT_TYPE
+	 * @param title
+	 *            导出为文件时的名称
 	 * @param request
 	 * @param response
 	 */
 	@RequestMapping()
 	public void print(String userName, String profile, String reportName, String whereCondition, String otherParameters,
-			String printType, HttpServletRequest request, HttpServletResponse response) {
+			String printType, String title, HttpServletRequest request, HttpServletResponse response) {
 		// printType为空,默认进入预览页
 		if (StringUtils.isEmpty(printType)) {
 			printType = ReportConstants.PREVIEW_PRINT_TYPE;
@@ -87,18 +89,18 @@ public class PrintController {
 		// 下载pdf、纯数据excel
 		else if (printType.equals(ReportConstants.PDF_PRINT_TYPE)) {
 			export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.PDF_FILE_TYPE, true,
-					request, response);
+					title, request, 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, true, request, response);
+					ReportConstants.EXCEL_WITH_ONLY_DATA_FILE_TYPE, true, title, request, response);
 		}
 		// 下载word
 		else if (printType.equals(ReportConstants.WORD_PRINT_TYPE)) {
 			export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.WORD_FILE_TYPE, true,
-					request, response);
+					title, request, response);
 		} else {
 			throw new ReportException("printType不合法");
 		}
@@ -122,13 +124,15 @@ public class PrintController {
 	 *            报表导出的格式,默认为pdf
 	 * @param flush
 	 *            是否强制刷新pdf、xls
+	 * @param title
+	 *            导出为文件时的名称
 	 * @param request
 	 * @param response
 	 */
 	@RequestMapping("/export")
 	@ResponseBody
 	public void export(String userName, String profile, String reportName, String whereCondition,
-			String otherParameters, String exportFileType, Boolean flush, HttpServletRequest request,
+			String otherParameters, String exportFileType, Boolean flush, String title, HttpServletRequest request,
 			HttpServletResponse response) {
 		ReportUtils.checkParameters(userName, reportName);
 		if (printService.overload(userName, profile, reportName, whereCondition)) {
@@ -178,7 +182,10 @@ public class PrintController {
 		}
 
 		try {
-			String exportFileName = reportName;
+			String exportFileName = title;
+			if (StringUtils.isEmpty(exportFileName)) {
+				exportFileName = reportName;
+			}
 			if (exportFileType.equals(ReportConstants.EXCEL_WITH_ONLY_DATA_FILE_TYPE)) {
 				exportFileName += "." + ReportConstants.EXCEL_FILE_TYPE;
 			} else {

+ 2 - 2
src/main/webapp/WEB-INF/views/console.html

@@ -13,9 +13,9 @@
 				<strong><li class="title1">预览</li></strong>
 				<ol>
 					<li><a target="_blank">print?userName=UAS&reportName=Purchase&whereCondition=where
-							%20rownum<10&otherParameters={'id':1}&printType=PREVIEW</a></li>
+							%20rownum<10&otherParameters={'id':1}&printType=PREVIEW&title=采购单123</a></li>
 					<li><a target="_blank">preview?userName=UAS_TEST&reportName=Purchase&whereCondition=where
-							%20rownum<11&printType=PREVIEW</a></li>
+							%20rownum<11&printType=PREVIEW&title=采购单123</a></li>
 				</ol>
 
 				<strong><li class="title1">打印</li></strong>