Эх сурвалжийг харах

规范PREVIEW_PRINT_TYPE等常量命名

sunyj 8 жил өмнө
parent
commit
b0a2bd7fd9

+ 21 - 22
src/main/java/com/uas/report/controller/PrintController.java

@@ -77,12 +77,12 @@ public class PrintController {
 		userName = userName == null ? null : userName.toUpperCase();
 		// printType为空,默认进入预览页
 		if (StringUtils.isEmpty(printType)) {
-			printType = ReportConstants.PREVIEW_PRINT_TYPE;
+			printType = ReportConstants.PRINT_TYPE_PREVIEW;
 		}
 
 		// 预览或打印
-		if (printType.equals(ReportConstants.PREVIEW_PRINT_TYPE)
-				|| printType.equals(ReportConstants.PRINT_PRINT_TYPE)) {
+		if (printType.equals(ReportConstants.PRINT_TYPE_PREVIEW)
+				|| printType.equals(ReportConstants.PRINT_TYPE_PRINT)) {
 			try {
 				request.getRequestDispatcher("preview").forward(request, response);
 			} catch (IOException | ServletException e) {
@@ -90,19 +90,19 @@ public class PrintController {
 			}
 		}
 		// 下载pdf、纯数据excel
-		else if (printType.equals(ReportConstants.PDF_PRINT_TYPE)) {
-			export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.PDF_FILE_TYPE, true,
+		else if (printType.equals(ReportConstants.PRINT_TYPE_PDF)) {
+			export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.FILE_TYPE_PDF, true,
 					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, 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,
+					true, title, request, response);
 		}
 		// 下载word
-		else if (printType.equals(ReportConstants.WORD_PRINT_TYPE)) {
-			export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.WORD_FILE_TYPE, true,
+		else if (printType.equals(ReportConstants.PRINT_TYPE_WORD)) {
+			export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.FILE_TYPE_WORD, true,
 					title, request, response);
 		} else {
 			throw new ReportException("printType不合法");
@@ -141,15 +141,15 @@ public class PrintController {
 		ReportUtils.checkParameters(userName, reportName);
 		String masterOfJrxml = printService.getMasterOfJrxml(userName, reportName);
 		if (StringUtils.isEmpty(exportFileType)) {
-			exportFileType = ReportConstants.PDF_FILE_TYPE;
+			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.EXCEL_WITH_ONLY_DATA_FILE_TYPE)) {
-			filePath += "." + ReportConstants.EXCEL_FILE_TYPE;
+		if (exportFileType.equals(ReportConstants.FILE_TYPE_EXCEL_DATA)) {
+			filePath += "." + ReportConstants.FILE_TYPE_EXCEL;
 		} else {
 			filePath += "." + exportFileType;
 		}
@@ -179,8 +179,8 @@ public class PrintController {
 			if (StringUtils.isEmpty(exportFileName)) {
 				exportFileName = reportName;
 			}
-			if (exportFileType.equals(ReportConstants.EXCEL_WITH_ONLY_DATA_FILE_TYPE)) {
-				exportFileName += "." + ReportConstants.EXCEL_FILE_TYPE;
+			if (exportFileType.equals(ReportConstants.FILE_TYPE_EXCEL_DATA)) {
+				exportFileName += "." + ReportConstants.FILE_TYPE_EXCEL;
 			} else {
 				exportFileName += "." + exportFileType;
 			}
@@ -217,17 +217,16 @@ public class PrintController {
 	 */
 	@RequestMapping(value = "/pdfPath")
 	@ResponseBody
-	public String pdfPath(String userName, final String profile, final String reportName,
-			final String whereCondition, final String otherParameters, Boolean flush, HttpServletRequest request,
-			HttpServletResponse response) {
+	public String pdfPath(String userName, final String profile, final String reportName, final String whereCondition,
+			final String otherParameters, Boolean flush, HttpServletRequest request, HttpServletResponse response) {
 		userName = userName == null ? null : userName.toUpperCase();
 		ReportUtils.checkParameters(userName, reportName);
 		String masterOfJrxml = printService.getMasterOfJrxml(userName, reportName);
 
 		// 相对路径,返回给前端
 		String pdfPath = ReportConstants.GENERATED_FILES_PATH + reportName + "/" + fileService
-				.generateFileName(userName, profile, whereCondition, otherParameters, ReportConstants.PDF_FILE_TYPE)
-				+ "." + ReportConstants.PDF_FILE_TYPE;
+				.generateFileName(userName, profile, whereCondition, otherParameters, ReportConstants.FILE_TYPE_PDF)
+				+ "." + ReportConstants.FILE_TYPE_PDF;
 		final File file = new File(ReportConstants.GENERATED_FILES_DIR + pdfPath);
 		// 指定flush为true(强制刷新pdf)
 		// 文件无效(不存在或过期),重新创建pdf文件

+ 5 - 5
src/main/java/com/uas/report/service/impl/PrintServiceImpl.java

@@ -168,17 +168,17 @@ public class PrintServiceImpl implements PrintService {
 				logger.info("export fillReport...");
 				boolean customCellStyle = false;
 				// 只导出数据
-				if (exportFileType.equals(ReportConstants.EXCEL_WITH_ONLY_DATA_FILE_TYPE)) {
+				if (exportFileType.equals(ReportConstants.FILE_TYPE_EXCEL_DATA)) {
 					// 需自定义单元格格式
 					customCellStyle = true;
 					JasperDesign jasperDesign = JRXmlLoader.load(jrxmlFilePath);
 					// 移除模板中多余元素
 					removeUnusedElements(jasperDesign);
-					exportFileType = ReportConstants.EXCEL_FILE_TYPE;
+					exportFileType = ReportConstants.FILE_TYPE_EXCEL;
 					JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
 					jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, connection);
 
-				} else if (exportFileType.equals(ReportConstants.WORD_FILE_TYPE)) {
+				} else if (exportFileType.equals(ReportConstants.FILE_TYPE_WORD)) {
 					// 导出word时需要对字体、行距等进行调整
 					InputStream inputStream = new ByteArrayInputStream(replaceFont(jrxmlFilePath).getBytes());
 					JasperReport jasperReport = JasperCompileManager.compileReport(inputStream);
@@ -188,9 +188,9 @@ public class PrintServiceImpl implements PrintService {
 					jasperPrint = JasperFillManager.fillReport(jasperFilePath, parameters, connection);
 				}
 
-				if (exportFileType.equals(ReportConstants.EXCEL_FILE_TYPE)) {
+				if (exportFileType.equals(ReportConstants.FILE_TYPE_EXCEL)) {
 					exportReportToXls(jasperPrint, outputStream, customCellStyle);
-				} else if (exportFileType.equals(ReportConstants.WORD_FILE_TYPE)) {
+				} else if (exportFileType.equals(ReportConstants.FILE_TYPE_WORD)) {
 					exportReportToDoc(jasperPrint, outputStream);
 				} else {
 					exportReportToPdf(jasperPrint, outputStream, pageIndex);

+ 9 - 9
src/main/java/com/uas/report/util/ReportConstants.java

@@ -21,47 +21,47 @@ public class ReportConstants {
 	/**
 	 * 请求类型:预览
 	 */
-	public static final String PREVIEW_PRINT_TYPE = "PREVIEW";
+	public static final String PRINT_TYPE_PREVIEW = "PREVIEW";
 
 	/**
 	 * 请求类型:打印
 	 */
-	public static final String PRINT_PRINT_TYPE = "PRINT";
+	public static final String PRINT_TYPE_PRINT = "PRINT";
 
 	/**
 	 * 请求类型:下载pdf
 	 */
-	public static final String PDF_PRINT_TYPE = "PDF";
+	public static final String PRINT_TYPE_PDF = "PDF";
 
 	/**
 	 * 请求类型:下载纯数据excel
 	 */
-	public static final String EXCEL_PRINT_TYPE = "EXCEL";
+	public static final String PRINT_TYPE_EXCEL = "EXCEL";
 
 	/**
 	 * 请求类型:下载word
 	 */
-	public static final String WORD_PRINT_TYPE = "WORD";
+	public static final String PRINT_TYPE_WORD = "WORD";
 
 	/**
 	 * 导出文件的格式:pdf
 	 */
-	public static final String PDF_FILE_TYPE = "pdf";
+	public static final String FILE_TYPE_PDF = "pdf";
 
 	/**
 	 * 导出文件的格式:excel
 	 */
-	public static final String EXCEL_FILE_TYPE = "xls";
+	public static final String FILE_TYPE_EXCEL = "xls";
 
 	/**
 	 * 导出文件的格式:纯数据excel
 	 */
-	public static final String EXCEL_WITH_ONLY_DATA_FILE_TYPE = "xls_with_only_data";
+	public static final String FILE_TYPE_EXCEL_DATA = "xls_data";
 
 	/**
 	 * 导出文件的格式:word
 	 */
-	public static final String WORD_FILE_TYPE = "doc";
+	public static final String FILE_TYPE_WORD = "doc";
 
 	/**
 	 * 生成的pdf、excel等文件的相对路径

+ 1 - 1
src/main/webapp/WEB-INF/views/preview.html

@@ -58,7 +58,7 @@
 			<button id="downloadExcel" class="toolbarButton" title="下载Excel">
 				<i class="fa fa-file-excel-o fa-lg" aria-hidden="true"></i>
 			</button>
-			<button id="downloadExcelWithOnlyData" class="toolbarButton"
+			<button id="downloadExcelData" class="toolbarButton"
 				title="下载Excel(仅数据)">
 				<i class="fa fa-file-excel-o fa-lg" aria-hidden="true"></i>
 			</button>

+ 2 - 2
src/main/webapp/resources/js/preview/app.js

@@ -126,11 +126,11 @@ $("#downloadExcel").click(function() {
 });
 
 // 下载纯数据excel
-$("#downloadExcelWithOnlyData").click(function() {
+$("#downloadExcelData").click(function() {
 	if (!pdfDoc) {
 		return;
 	}
-	window.open(downloadUrl("xls_with_only_data"));
+	window.open(downloadUrl("xls_data"));
 });
 
 // 键盘左右键进行翻页