Bladeren bron

预览时先提示需加载多少条数据

sunyj 8 jaren geleden
bovenliggende
commit
ff3f43ba24

+ 29 - 0
src/main/java/com/uas/report/controller/PrintController.java

@@ -301,4 +301,33 @@ public class PrintController {
 		return result;
 	}
 
+	/**
+	 * 获取该模板在当前条件下的结果数目
+	 * 
+	 * @param userName不为null;当前账套用户名
+	 * @param profile
+	 *            用于标识请求源(B2C、B2B)是正式、测试还是开发版本:prod、test、dev
+	 * @param reportName
+	 *            不为null;需要导出的报表的名称,不带任何后缀(如导出采购单,即为"Purchase")
+	 * @param whereCondition
+	 *            可为null;where之后的条件(包括where)
+	 * @param otherParameters
+	 *            若模板已指定需要的参数,则不可为null;其他参数,区别于whereCondition,报表某些字段的值取决于这些参数;
+	 *            JSON格式,数据为键值对
+	 * @param request
+	 * @param response
+	 * @return 结果数目
+	 * @throws SQLException
+	 * @throws IOException
+	 * @throws DocumentException
+	 */
+	@RequestMapping(value = "/count")
+	@ResponseBody
+	public int getCount(String userName, String profile, String reportName, String whereCondition,
+			String otherParameters, HttpServletRequest request, HttpServletResponse response)
+			throws SQLException, IOException, DocumentException {
+		userName = userName == null ? null : userName.toUpperCase();
+		ReportUtils.checkParameters(userName, reportName);
+		return printService.getCount(userName, profile, reportName, whereCondition, otherParameters);
+	}
 }

+ 21 - 0
src/main/java/com/uas/report/service/PrintService.java

@@ -107,4 +107,25 @@ public interface PrintService {
 	public boolean overload(String userName, String profile, String reportName, String whereCondition,
 			String otherParameters, Platform platform) throws SQLException, IOException, DocumentException;
 
+	/**
+	 * 获取该模板在当前条件下的结果数目
+	 * 
+	 * @param userName不为null;当前账套用户名
+	 * @param profile
+	 *            用于标识请求源(B2C、B2B)是正式、测试还是开发版本:prod、test、dev
+	 * @param reportName
+	 *            不为null;需要导出的报表的名称,不带任何后缀(如导出采购单,即为"Purchase")
+	 * @param whereCondition
+	 *            可为null;where之后的条件(包括where)
+	 * @param otherParameters
+	 *            若模板已指定需要的参数,则不可为null;其他参数,区别于whereCondition,报表某些字段的值取决于这些参数;
+	 *            JSON格式,数据为键值对
+	 * @return 结果数目
+	 * @throws SQLException
+	 * @throws IOException
+	 * @throws DocumentException
+	 */
+	public int getCount(String userName, String profile, String reportName, String whereCondition,
+			String otherParameters) throws SQLException, IOException, DocumentException;
+
 }

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

@@ -627,14 +627,6 @@ public class PrintServiceImpl implements PrintService {
 	@Override
 	public boolean overload(String userName, String profile, String reportName, String whereCondition,
 			String otherParameters, Platform platform) throws SQLException, IOException, DocumentException {
-		DataSource dataSource = MasterManager.getDataSource(userName, profile);
-		if (dataSource == null) {
-			throw new SQLException("获取数据源失败");
-		}
-		if (platform == null) {
-			platform = Platform.PC;
-		}
-
 		// 支持打印的最大记录行数
 		int maxRecordSize = 0;
 		switch (platform) {
@@ -646,6 +638,18 @@ public class PrintServiceImpl implements PrintService {
 			break;
 		}
 
+		int count = getCount(userName, profile, reportName, whereCondition, otherParameters);
+		return count >= maxRecordSize;
+	}
+
+	@Override
+	public int getCount(String userName, String profile, String reportName, String whereCondition,
+			String otherParameters) throws SQLException, IOException, DocumentException {
+		DataSource dataSource = MasterManager.getDataSource(userName, profile);
+		if (dataSource == null) {
+			throw new SQLException("获取数据源失败");
+		}
+
 		String masterOfJrxml = getMasterOfJrxml(userName, reportName);
 		String jrxmlFilePath = fileService.getJrxmlFilePath(masterOfJrxml, reportName);
 		Connection connection = null;
@@ -664,7 +668,7 @@ public class PrintServiceImpl implements PrintService {
 			// 因为子报表数据量较小,而且其参数来自主报表,无法简单地进行判断,所以不判断子报表是否过载
 			int count = getCount(jrxmlFilePath, whereCondition, otherParameters, connection);
 			logger.info("count... " + count);
-			return count >= maxRecordSize;
+			return count;
 		} finally {
 			if (connection != null) {
 				connection.close();

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

@@ -81,10 +81,12 @@
 			<ol>
 				<strong><li class="title2">打印接口</li></strong>
 				<ol>
-					<li><a target="_blank">print/loadPdfData?userName=UAS&reportName=Purchase&whereCondition=where
+					<li><a target="_blank">print/pdfPath?userName=UAS&reportName=Purchase&whereCondition=where
 							%20rownum<30&pageIndex=2</a></li>
 					<li><a target="_blank">print/export?userName=UAS&reportName=Purchase&whereCondition=where
-							%20rownum<16&exportFileType=xls_with_only_data</a></li>
+							%20rownum<16&exportFileType=xls_data</a></li>
+					<li><a target="_blank">print/count?userName=UAS&reportName=Purchase&whereCondition=where
+							%20rownum<16</a></li>
 				</ol>
 				<strong><li class="title2">资源接口</li></strong>
 				<ol>

+ 59 - 29
src/main/webapp/resources/js/preview/app.js

@@ -28,8 +28,9 @@ var rendering = false;
 // 下一个要渲染的页面
 var nextRenderingPage;
 
+document.title = getParameter("reportName");
 getWindowWidth();
-loadData();
+count();
 
 // 缩小,最小不小于原大小的0.2/1.2倍
 $("#zoomOut").click(function() {
@@ -168,6 +169,27 @@ function getWindowWidth() {
 	}
 }
 
+/**
+ * 发送请求,获取当前条件下的结果数目
+ */
+function count() {
+	spinner = showLoading(spinner, spinnerContainer);
+	var countUrl = "print/count" + window.location.search;
+	$.ajax({
+		type : "get",
+		async : false,
+		url : countUrl,
+		success : function(count) {
+			alert(spinnerContainer, "需载入" + count + "条数据", 1000);
+			spinner = hideLoading(spinner);
+			loadData();
+		},
+		error : function(XMLHttpRequest) {
+			showError(XMLHttpRequest);
+		}
+	});
+}
+
 /**
  * 发送请求,服务器端进行填充报表、生成pdf文件等操作
  */
@@ -180,7 +202,6 @@ function loadData() {
 		async : true,
 		url : loadPdfDataUrl,
 		success : function(path) {
-			document.title = getParameter("reportName");
 			pdfPath = path;
 			hiddenFrame.src = pdfPath;
 			PDFJS.getDocument(pdfPath).then(function(pdfDoc_) {
@@ -194,33 +215,7 @@ function loadData() {
 			});
 		},
 		error : function(XMLHttpRequest) {
-			$("#theCanvas").remove();
-			spinner = hideLoading(spinner);
-			$("#errorMessageContainer").removeAttr("hidden");
-			var result = JSON.parse(XMLHttpRequest.responseText);
-			var message = result.message;
-			$("#message").html(message);
-			var detailedMessage = result.detailedMessage;
-			if (detailedMessage) {
-				// 处理后台传输的自定义的换行标志
-				detailedMessage = detailedMessage.replace(/\n/g, '<br/>')
-						.replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;');
-				$("#detailedMessageButton").removeAttr("hidden");
-				$("#detailedMessage").html(detailedMessage);
-			}
-			function hiddenDetailMessage() {
-				$("#detailedMessage").attr("hidden", "true");
-				$("#detailedMessageButton").html("展开");
-				$("#detailedMessageButton").unbind();
-				$("#detailedMessageButton").click(showDetailMessage);
-			}
-			function showDetailMessage() {
-				$("#detailedMessage").removeAttr("hidden");
-				$("#detailedMessageButton").html("收起");
-				$("#detailedMessageButton").unbind();
-				$("#detailedMessageButton").click(hiddenDetailMessage);
-			}
-			hiddenDetailMessage();
+			showError(XMLHttpRequest);
 		}
 	});
 };
@@ -360,4 +355,39 @@ function checkBrowser() {
 	if (userAgent.indexOf("Chrome") == -1 || userAgent.indexOf("Edge") !== -1) {
 		alert(spinnerContainer, "建议使用最新版Chrome浏览器打印");
 	}
+}
+
+/**
+ * 展示错误信息
+ * 
+ * @param XMLHttpRequest
+ */
+function showError(XMLHttpRequest) {
+	$("#theCanvas").remove();
+	spinner = hideLoading(spinner);
+	$("#errorMessageContainer").removeAttr("hidden");
+	var result = JSON.parse(XMLHttpRequest.responseText);
+	var message = result.message;
+	$("#message").html(message);
+	var detailedMessage = result.detailedMessage;
+	if (detailedMessage) {
+		// 处理后台传输的自定义的换行标志
+		detailedMessage = detailedMessage.replace(/\n/g, '<br/>').replace(
+				/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;');
+		$("#detailedMessageButton").removeAttr("hidden");
+		$("#detailedMessage").html(detailedMessage);
+	}
+	function hiddenDetailMessage() {
+		$("#detailedMessage").attr("hidden", "true");
+		$("#detailedMessageButton").html("展开");
+		$("#detailedMessageButton").unbind();
+		$("#detailedMessageButton").click(showDetailMessage);
+	}
+	function showDetailMessage() {
+		$("#detailedMessage").removeAttr("hidden");
+		$("#detailedMessageButton").html("收起");
+		$("#detailedMessageButton").unbind();
+		$("#detailedMessageButton").click(hiddenDetailMessage);
+	}
+	hiddenDetailMessage();
 }