Browse Source

修复sql缺少空格、子报表名称错误;sort类型无法识别时,不进行排序;

sunyj 8 years ago
parent
commit
97806e4474

+ 13 - 6
src/main/java/com/uas/report/crystal2jasper/CrystalToJasper.java

@@ -299,7 +299,7 @@ public class CrystalToJasper {
 		// XPath格式为:/*[name()='Meta']
 		// XPath格式为:/*[name()='Meta']
 		Node node = document.selectSingleNode("//*[name()='Title']");
 		Node node = document.selectSingleNode("//*[name()='Title']");
 		String text = node.getText();
 		String text = node.getText();
-		text = text.substring(0, text.length() - ".RPT".length());
+		text = text.endsWith(".RPT") ? text.substring(0, text.length() - ".RPT".length()) : text;
 		return text;
 		return text;
 	}
 	}
 
 
@@ -485,16 +485,22 @@ public class CrystalToJasper {
 			if (sortTypeElement != null) {
 			if (sortTypeElement != null) {
 				sortType = sortTypeElement.attributeValue("value");
 				sortType = sortTypeElement.attributeValue("value");
 			}
 			}
-			Sort sort = new Sort(field, getSortType(sortType));
-			sorts.add(sort);
+			SortType sortType2 = getSortType(sortType);
+			if (sortType2 != null) {
+				Sort sort = new Sort(field, sortType2);
+				sorts.add(sort);
+			}
 		}
 		}
 		// 普通排序字段
 		// 普通排序字段
 		List<Element> sortElements = document.selectNodes("//SortFields/Field");
 		List<Element> sortElements = document.selectNodes("//SortFields/Field");
 		for (Element element : sortElements) {
 		for (Element element : sortElements) {
 			String field = element.element("Name").attributeValue("value");
 			String field = element.element("Name").attributeValue("value");
 			String sortType = element.element("Operation").attributeValue("value");
 			String sortType = element.element("Operation").attributeValue("value");
-			Sort sort = new Sort(field, getSortType(sortType));
-			sorts.add(sort);
+			SortType sortType2 = getSortType(sortType);
+			if (sortType2 != null) {
+				Sort sort = new Sort(field, getSortType(sortType));
+				sorts.add(sort);
+			}
 		}
 		}
 
 
 		return getQueryString(columnNames, tableNames, joins, sorts);
 		return getQueryString(columnNames, tableNames, joins, sorts);
@@ -538,7 +544,8 @@ public class CrystalToJasper {
 		} else if ("1".equalsIgnoreCase(type)) {
 		} else if ("1".equalsIgnoreCase(type)) {
 			return SortType.DESC;
 			return SortType.DESC;
 		} else {
 		} else {
-			throw new ReportException("无法解析sort类型:" + type);
+			logger.error("无法解析sort类型:" + type);
+			return null;
 		}
 		}
 	}
 	}
 
 

+ 1 - 1
src/main/java/com/uas/report/crystal2jasper/Join.java

@@ -81,7 +81,7 @@ public class Join {
 		int i = 0;
 		int i = 0;
 		for (Link link : links) {
 		for (Link link : links) {
 			if (i++ != 0) {
 			if (i++ != 0) {
-				builder.append("and ");
+				builder.append(" and ");
 			}
 			}
 			builder.append(fromTableName).append(".").append(link.getFromColumnName()).append(" ")
 			builder.append(fromTableName).append(".").append(link.getFromColumnName()).append(" ")
 					.append(link.getJoinType().getExpression()).append(" ").append(toTableName).append(".")
 					.append(link.getJoinType().getExpression()).append(" ").append(toTableName).append(".")