Переглянути джерело

不处理子报表的参数、字段等,因为其参数来自主报表,无法处理

sunyj 8 роки тому
батько
коміт
39d85292ff

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

@@ -168,7 +168,7 @@ public class PrintServiceImpl implements PrintService {
 			connection = dataSource.getConnection();
 			logger.info("dataSource.getConnection done..." + userName);
 
-			String jasperFilePath = maybeCompileJrxmlFile(jrxmlFilePath, otherParameters, connection);
+			String jasperFilePath = maybeCompileJrxmlFile(jrxmlFilePath, false, otherParameters, connection);
 
 			Map<String, Object> result = new HashMap<>();
 			byte[] data = null;
@@ -237,6 +237,8 @@ public class PrintServiceImpl implements PrintService {
 	 * 
 	 * @param jrxmlFilePath
 	 *            报表模板文件
+	 * @param isSub
+	 *            是否为子报表
 	 * @param otherParameters
 	 * @param connection
 	 * @return 编译后的jasper文件路径
@@ -244,8 +246,8 @@ public class PrintServiceImpl implements PrintService {
 	 * @throws SQLException
 	 * @throws DocumentException
 	 */
-	private String maybeCompileJrxmlFile(String jrxmlFilePath, String otherParameters, Connection connection)
-			throws IOException, DocumentException, SQLException {
+	private String maybeCompileJrxmlFile(String jrxmlFilePath, boolean isSub, String otherParameters,
+			Connection connection) throws IOException, DocumentException, SQLException {
 		if (StringUtils.isEmpty(jrxmlFilePath)) {
 			logger.error("参数不能为空:" + jrxmlFilePath);
 			return null;
@@ -260,7 +262,7 @@ public class PrintServiceImpl implements PrintService {
 		// 首先解析jrxml文件,检查是否引用子报表,如果是,先(递归)编译子报表
 		List<String> subJrxmlFilePaths = getSubJrxmlFilePath(jrxmlFilePath);
 		for (String subJrxmlFilePath : subJrxmlFilePaths) {
-			maybeCompileJrxmlFile(subJrxmlFilePath, otherParameters, connection);
+			maybeCompileJrxmlFile(subJrxmlFilePath, true, otherParameters, connection);
 		}
 
 		String jasperFilePath = jrxmlFilePath.replace(".jrxml", ".jasper");
@@ -270,12 +272,12 @@ public class PrintServiceImpl implements PrintService {
 			// 报表模板未编译过
 			if (!jasperFile.exists()) {
 				logger.info("正在编译报表模板... " + jrxmlFilePath);
-				compileReportToFile(jrxmlFilePath, jasperFilePath, otherParameters, connection);
+				compileReportToFile(jrxmlFilePath, isSub, jasperFilePath, otherParameters, connection);
 			}
 			// 如果在编译之后,报表模板有更改过 ,重新编译
 			else if (jrxmlFile.lastModified() > jasperFile.lastModified()) {
 				logger.info("正在重新编译报表模板... " + jrxmlFilePath);
-				compileReportToFile(jrxmlFilePath, jasperFilePath, otherParameters, connection);
+				compileReportToFile(jrxmlFilePath, isSub, jasperFilePath, otherParameters, connection);
 			}
 		} catch (JRException e) {
 			throw new IllegalStateException("编译报表模板失败: " + jrxmlFilePath + " " + ExceptionUtils.getDetailedMessage(e));
@@ -317,6 +319,8 @@ public class PrintServiceImpl implements PrintService {
 	 * 
 	 * @param jrxmlFilePath
 	 *            模板文件
+	 * @param isSub
+	 *            是否为子报表
 	 * @param jasperFilePath
 	 *            编译后的文件
 	 * @param otherParameters
@@ -328,11 +332,14 @@ public class PrintServiceImpl implements PrintService {
 	 * @throws DocumentException
 	 * @throws SQLException
 	 */
-	private void compileReportToFile(String jrxmlFilePath, String jasperFilePath, String otherParameters,
+	private void compileReportToFile(String jrxmlFilePath, boolean isSub, String jasperFilePath, String otherParameters,
 			Connection connection)
 			throws JRException, FileNotFoundException, IOException, DocumentException, SQLException {
 		replaceFont(jrxmlFilePath);
-		processFields(jrxmlFilePath, otherParameters, connection);
+		// 不处理子报表,因为其参数来自主报表,无法处理
+		if (!isSub) {
+			processFields(jrxmlFilePath, otherParameters, connection);
+		}
 		JasperCompileManager.compileReportToFile(jrxmlFilePath, jasperFilePath);
 	}