Browse Source

导出纯数据excel时,元素区域外的数据会缺失,所以暂时恢复元素高度的动态调整;返回更多错误信息以便调试;

sunyj 9 years ago
parent
commit
92467d466d
1 changed files with 20 additions and 14 deletions
  1. 20 14
      src/main/java/com/uas/report/service/impl/PrintServiceImpl.java

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

@@ -31,11 +31,7 @@ import com.uas.report.support.JasperserverRestAPIConf;
 import com.uas.report.util.ContextUtils;
 import com.uas.report.util.ReportConstants;
 
-import net.sf.jasperreports.engine.JRBand;
-import net.sf.jasperreports.engine.JRElement;
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JRSection;
-import net.sf.jasperreports.engine.JRTextField;
 import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperExportManager;
 import net.sf.jasperreports.engine.JasperFillManager;
@@ -101,6 +97,7 @@ public class PrintServiceImpl implements PrintService {
 			resourceService.syncResources(userName);
 		} catch (URISyntaxException | IOException e1) {
 			e1.printStackTrace();
+			throw new SystemError(e1.getMessage());
 		}
 
 		String message = "";
@@ -143,7 +140,7 @@ public class PrintServiceImpl implements PrintService {
 			}
 		} catch (JRException e) {
 			logger.error(e);
-			throw new SystemError("编译报表模板失败");
+			throw new SystemError("编译报表模板失败:" + e.getMessage());
 		}
 
 		// 向报表模板传递参数:报表路径、where条件、其他参数
@@ -231,14 +228,17 @@ public class PrintServiceImpl implements PrintService {
 			throw new SystemError(message);
 		} catch (JRException e) {
 			e.printStackTrace();
+			throw new SystemError(e.getMessage());
 		} catch (IOException e) {
 			e.printStackTrace();
+			throw new SystemError(e.getMessage());
 		} finally {
 			if (connection != null) {
 				try {
 					connection.close();
 				} catch (SQLException e) {
 					e.printStackTrace();
+					throw new SystemError(e.getMessage());
 				}
 			}
 		}
@@ -289,8 +289,10 @@ public class PrintServiceImpl implements PrintService {
 			}
 		} catch (SQLException e) {
 			e.printStackTrace();
+			throw new SystemError(e.getMessage());
 		} catch (Exception e) {
 			e.printStackTrace();
+			throw new SystemError(e.getMessage());
 		} finally {
 			try {
 				if (resultSet != null) {
@@ -298,6 +300,7 @@ public class PrintServiceImpl implements PrintService {
 				}
 			} catch (SQLException e) {
 				e.printStackTrace();
+				throw new SystemError(e.getMessage());
 			}
 			try {
 				if (preparedStatement != null) {
@@ -305,11 +308,13 @@ public class PrintServiceImpl implements PrintService {
 				}
 			} catch (SQLException e) {
 				e.printStackTrace();
+				throw new SystemError(e.getMessage());
 			}
 			try {
 				connection.close();
 			} catch (SQLException e) {
 				e.printStackTrace();
+				throw new SystemError(e.getMessage());
 			}
 		}
 		return null;
@@ -335,7 +340,8 @@ public class PrintServiceImpl implements PrintService {
 			}
 		} catch (JRException e) {
 			e.printStackTrace();
-			return false;
+			throw new SystemError(e.getMessage());
+//			return false;
 		}
 		return true;
 	}
@@ -368,7 +374,7 @@ public class PrintServiceImpl implements PrintService {
 	}
 
 	/**
-	 * 移除除Column Header和Detail之外的元素
+	 * 移除除Column Header和Detail之外的元素
 	 * 
 	 * @param jasperDesign
 	 */
@@ -396,12 +402,12 @@ public class PrintServiceImpl implements PrintService {
 		jasperDesign.setRightMargin(0);
 
 		// 设置DetailBand中的元素高度不动态调整
-		JRSection detailSection = jasperDesign.getDetailSection();
-		JRBand[] bands = detailSection.getBands();
-		JRElement[] elements = bands[0].getElements();
-		for (JRElement element : elements) {
-			JRTextField textField = (JRTextField) element;
-			textField.setStretchWithOverflow(false);
-		}
+		// JRSection detailSection = jasperDesign.getDetailSection();
+		// JRBand[] bands = detailSection.getBands();
+		// JRElement[] elements = bands[0].getElements();
+		// for (JRElement element : elements) {
+		// JRTextField textField = (JRTextField) element;
+		// textField.setStretchWithOverflow(false);
+		// }
 	}
 }