Explorar o código

删除ReportException

sunyj %!s(int64=8) %!d(string=hai) anos
pai
achega
0e8973b7f2

+ 14 - 8
src/main/java/com/uas/report/controller/FileController.java

@@ -1,5 +1,6 @@
 package com.uas.report.controller;
 package com.uas.report.controller;
 
 
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
@@ -32,14 +33,14 @@ public class FileController {
 
 
 	@RequestMapping("/autoDeploy")
 	@RequestMapping("/autoDeploy")
 	@ResponseBody
 	@ResponseBody
-	public String autoDeploy(String sourceUserName, String destinationUserNames) {
+	public String autoDeploy(String sourceUserName, String destinationUserNames) throws IOException {
 		return fileService.autoDeploy(sourceUserName, destinationUserNames);
 		return fileService.autoDeploy(sourceUserName, destinationUserNames);
 	}
 	}
 
 
 	@RequestMapping("/upload")
 	@RequestMapping("/upload")
 	@ResponseBody
 	@ResponseBody
 	public String upload(String userName, String fileType, String filePath, Boolean isAbsolutePath,
 	public String upload(String userName, String fileType, String filePath, Boolean isAbsolutePath,
-			@RequestParam("file") MultipartFile[] files) {
+			@RequestParam("file") MultipartFile[] files) throws IOException {
 		userName = userName == null ? null : userName.toUpperCase();
 		userName = userName == null ? null : userName.toUpperCase();
 		// 未指定上传文件路径,则按照账套名称上传
 		// 未指定上传文件路径,则按照账套名称上传
 		// 该情况下,不会上传多个文件的
 		// 该情况下,不会上传多个文件的
@@ -58,9 +59,10 @@ public class FileController {
 	 * @param isAbsolutePath
 	 * @param isAbsolutePath
 	 *            文件路径是否为绝对路径
 	 *            文件路径是否为绝对路径
 	 * @param response
 	 * @param response
+	 * @throws IOException
 	 */
 	 */
 	@RequestMapping("/download")
 	@RequestMapping("/download")
-	public void download(String filePath, Boolean isAbsolutePath, HttpServletResponse response) {
+	public void download(String filePath, Boolean isAbsolutePath, HttpServletResponse response) throws IOException {
 		fileService.download(filePath, isAbsolutePath, response);
 		fileService.download(filePath, isAbsolutePath, response);
 	}
 	}
 
 
@@ -70,9 +72,10 @@ public class FileController {
 	 * @param userName
 	 * @param userName
 	 *            账套名
 	 *            账套名
 	 * @param response
 	 * @param response
+	 * @throws IOException
 	 */
 	 */
 	@RequestMapping("/download/zip")
 	@RequestMapping("/download/zip")
-	public void downloadZip(String userName, HttpServletResponse response) {
+	public void downloadZip(String userName, HttpServletResponse response) throws IOException {
 		userName = userName == null ? null : userName.toUpperCase();
 		userName = userName == null ? null : userName.toUpperCase();
 		fileService.downloadZip(userName, response);
 		fileService.downloadZip(userName, response);
 	}
 	}
@@ -85,9 +88,10 @@ public class FileController {
 	 * @param reportName
 	 * @param reportName
 	 *            模板名称
 	 *            模板名称
 	 * @param response
 	 * @param response
+	 * @throws IOException
 	 */
 	 */
 	@RequestMapping("/download/jrxml")
 	@RequestMapping("/download/jrxml")
-	public void downloadJrxml(String userName, String reportName, HttpServletResponse response) {
+	public void downloadJrxml(String userName, String reportName, HttpServletResponse response) throws IOException {
 		userName = userName == null ? null : userName.toUpperCase();
 		userName = userName == null ? null : userName.toUpperCase();
 		fileService.download(fileService.getJrxmlFilePath(userName, reportName), true, response);
 		fileService.download(fileService.getJrxmlFilePath(userName, reportName), true, response);
 	}
 	}
@@ -97,10 +101,12 @@ public class FileController {
 	 * 
 	 * 
 	 * @param onlyData
 	 * @param onlyData
 	 *            是否只获取数据
 	 *            是否只获取数据
+	 * @throws IOException
 	 */
 	 */
 	@RequestMapping("/standardJrxmls")
 	@RequestMapping("/standardJrxmls")
 	@ResponseBody
 	@ResponseBody
-	public Map<String, Object> standardJrxmls(String userName, String onlyData, HttpServletResponse response) {
+	public Map<String, Object> standardJrxmls(String userName, String onlyData, HttpServletResponse response)
+			throws IOException {
 		userName = userName == null ? null : userName.toUpperCase();
 		userName = userName == null ? null : userName.toUpperCase();
 		// onlyData为真,只返回字节数据(自动部署时只获取标准模板字节数据),否则下载标准模板zip
 		// onlyData为真,只返回字节数据(自动部署时只获取标准模板字节数据),否则下载标准模板zip
 		if (!StringUtils.isEmpty(onlyData) && (onlyData.equals("1") || onlyData.equals("true"))) {
 		if (!StringUtils.isEmpty(onlyData) && (onlyData.equals("1") || onlyData.equals("true"))) {
@@ -117,13 +123,13 @@ public class FileController {
 
 
 	@RequestMapping("/delete")
 	@RequestMapping("/delete")
 	@ResponseBody
 	@ResponseBody
-	public String delete(String filePath, Boolean isAbsolutePath) {
+	public String delete(String filePath, Boolean isAbsolutePath) throws IOException {
 		return "Deleted... " + fileService.delete(filePath, isAbsolutePath);
 		return "Deleted... " + fileService.delete(filePath, isAbsolutePath);
 	}
 	}
 
 
 	@RequestMapping("/listFiles")
 	@RequestMapping("/listFiles")
 	@ResponseBody
 	@ResponseBody
-	public List<Map<String, Object>> listFiles(String filePath, Boolean isAbsolutePath) {
+	public List<Map<String, Object>> listFiles(String filePath, Boolean isAbsolutePath) throws IOException {
 		return fileService.listFiles(filePath, isAbsolutePath);
 		return fileService.listFiles(filePath, isAbsolutePath);
 	}
 	}
 }
 }

+ 35 - 20
src/main/java/com/uas/report/controller/PrintController.java

@@ -5,6 +5,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStream;
 import java.net.URLEncoder;
 import java.net.URLEncoder;
+import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -12,6 +13,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 
 
+import org.dom4j.DocumentException;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,7 +21,6 @@ import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 
-import com.uas.report.core.exception.ReportException;
 import com.uas.report.service.FileService;
 import com.uas.report.service.FileService;
 import com.uas.report.service.PrintService;
 import com.uas.report.service.PrintService;
 import com.uas.report.util.ArrayUtils;
 import com.uas.report.util.ArrayUtils;
@@ -30,6 +31,8 @@ import com.uas.report.util.ReportConstants;
 import com.uas.report.util.ReportUtils;
 import com.uas.report.util.ReportUtils;
 import com.uas.report.util.StringUtils;
 import com.uas.report.util.StringUtils;
 
 
+import net.sf.jasperreports.engine.JRException;
+
 /**
 /**
  * 报表打印
  * 报表打印
  * 
  * 
@@ -70,10 +73,16 @@ public class PrintController {
 	 *            导出为文件时的名称
 	 *            导出为文件时的名称
 	 * @param request
 	 * @param request
 	 * @param response
 	 * @param response
+	 * @throws SQLException
+	 * @throws DocumentException
+	 * @throws IOException
+	 * @throws JRException
+	 * @throws ServletException
 	 */
 	 */
 	@RequestMapping()
 	@RequestMapping()
 	public void print(String userName, String profile, String reportName, String whereCondition, String otherParameters,
 	public void print(String userName, String profile, String reportName, String whereCondition, String otherParameters,
-			String printType, String title, HttpServletRequest request, HttpServletResponse response) {
+			String printType, String title, HttpServletRequest request, HttpServletResponse response)
+			throws JRException, IOException, DocumentException, SQLException, ServletException {
 		userName = userName == null ? null : userName.toUpperCase();
 		userName = userName == null ? null : userName.toUpperCase();
 		// printType为空,默认进入预览页
 		// printType为空,默认进入预览页
 		if (StringUtils.isEmpty(printType)) {
 		if (StringUtils.isEmpty(printType)) {
@@ -83,11 +92,7 @@ public class PrintController {
 		// 预览或打印
 		// 预览或打印
 		if (printType.equals(ReportConstants.PRINT_TYPE_PREVIEW)
 		if (printType.equals(ReportConstants.PRINT_TYPE_PREVIEW)
 				|| printType.equals(ReportConstants.PRINT_TYPE_PRINT)) {
 				|| printType.equals(ReportConstants.PRINT_TYPE_PRINT)) {
-			try {
-				request.getRequestDispatcher("preview").forward(request, response);
-			} catch (IOException | ServletException e) {
-				throw new ReportException(e).setDetailedMessage(e);
-			}
+			request.getRequestDispatcher("preview").forward(request, response);
 		}
 		}
 		// 下载pdf、纯数据excel
 		// 下载pdf、纯数据excel
 		else if (printType.equals(ReportConstants.PRINT_TYPE_PDF)) {
 		else if (printType.equals(ReportConstants.PRINT_TYPE_PDF)) {
@@ -105,7 +110,7 @@ public class PrintController {
 			export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.FILE_TYPE_WORD, true,
 			export(userName, profile, reportName, whereCondition, otherParameters, ReportConstants.FILE_TYPE_WORD, true,
 					title, request, response);
 					title, request, response);
 		} else {
 		} else {
-			throw new ReportException("printType不合法");
+			throw new IllegalArgumentException("printType不合法");
 		}
 		}
 	}
 	}
 
 
@@ -131,12 +136,16 @@ public class PrintController {
 	 *            导出为文件时的名称
 	 *            导出为文件时的名称
 	 * @param request
 	 * @param request
 	 * @param response
 	 * @param response
+	 * @throws SQLException
+	 * @throws DocumentException
+	 * @throws IOException
+	 * @throws JRException
 	 */
 	 */
 	@RequestMapping("/export")
 	@RequestMapping("/export")
 	@ResponseBody
 	@ResponseBody
 	public void export(String userName, String profile, String reportName, String whereCondition,
 	public void export(String userName, String profile, String reportName, String whereCondition,
 			String otherParameters, String exportFileType, Boolean flush, String title, HttpServletRequest request,
 			String otherParameters, String exportFileType, Boolean flush, String title, HttpServletRequest request,
-			HttpServletResponse response) {
+			HttpServletResponse response) throws JRException, IOException, DocumentException, SQLException {
 		userName = userName == null ? null : userName.toUpperCase();
 		userName = userName == null ? null : userName.toUpperCase();
 		ReportUtils.checkParameters(userName, reportName);
 		ReportUtils.checkParameters(userName, reportName);
 		String masterOfJrxml = printService.getMasterOfJrxml(userName, reportName);
 		String masterOfJrxml = printService.getMasterOfJrxml(userName, reportName);
@@ -159,19 +168,15 @@ public class PrintController {
 		if ((flush != null && flush.booleanValue())
 		if ((flush != null && flush.booleanValue())
 				|| !fileService.isFileValid(file.getPath(), fileService.getJrxmlFilePath(masterOfJrxml, reportName))) {
 				|| !fileService.isFileValid(file.getPath(), fileService.getJrxmlFilePath(masterOfJrxml, reportName))) {
 			if (printService.overload(userName, profile, reportName, whereCondition, otherParameters, Platform.PC)) {
 			if (printService.overload(userName, profile, reportName, whereCondition, otherParameters, Platform.PC)) {
-				throw new ReportException("数据量过大,无法提供服务");
+				throw new IllegalStateException("数据量过大,无法提供服务");
 			}
 			}
 			data = printService.export(userName, profile, reportName, whereCondition, otherParameters, exportFileType);
 			data = printService.export(userName, profile, reportName, whereCondition, otherParameters, exportFileType);
 			if (ArrayUtils.isEmpty(data)) {
 			if (ArrayUtils.isEmpty(data)) {
-				throw new ReportException("报表导出失败:" + userName + "/" + reportName + "\n");
+				throw new IllegalStateException("报表导出失败:" + userName + "/" + reportName + "\n");
 			}
 			}
 			FileUtils.write(file.getPath(), data);
 			FileUtils.write(file.getPath(), data);
 		} else {
 		} else {
-			try {
-				data = FileUtils.readData(new FileInputStream(file));
-			} catch (IOException e) {
-				throw new ReportException(e).setDetailedMessage(e);
-			}
+			data = FileUtils.readData(new FileInputStream(file));
 		}
 		}
 
 
 		try {
 		try {
@@ -214,11 +219,16 @@ public class PrintController {
 	 * @param request
 	 * @param request
 	 * @param response
 	 * @param response
 	 * @return pdf相对路径
 	 * @return pdf相对路径
+	 * @throws SQLException
+	 * @throws DocumentException
+	 * @throws IOException
+	 * @throws JRException
 	 */
 	 */
 	@RequestMapping(value = "/pdfPath")
 	@RequestMapping(value = "/pdfPath")
 	@ResponseBody
 	@ResponseBody
 	public String pdfPath(String userName, final String profile, final String reportName, final String whereCondition,
 	public String pdfPath(String userName, final String profile, final String reportName, final String whereCondition,
-			final String otherParameters, Boolean flush, HttpServletRequest request, HttpServletResponse response) {
+			final String otherParameters, Boolean flush, HttpServletRequest request, HttpServletResponse response)
+			throws JRException, IOException, DocumentException, SQLException {
 		userName = userName == null ? null : userName.toUpperCase();
 		userName = userName == null ? null : userName.toUpperCase();
 		ReportUtils.checkParameters(userName, reportName);
 		ReportUtils.checkParameters(userName, reportName);
 		String masterOfJrxml = printService.getMasterOfJrxml(userName, reportName);
 		String masterOfJrxml = printService.getMasterOfJrxml(userName, reportName);
@@ -233,12 +243,12 @@ public class PrintController {
 		if ((flush != null && flush.booleanValue())
 		if ((flush != null && flush.booleanValue())
 				|| !fileService.isFileValid(file.getPath(), fileService.getJrxmlFilePath(masterOfJrxml, reportName))) {
 				|| !fileService.isFileValid(file.getPath(), fileService.getJrxmlFilePath(masterOfJrxml, reportName))) {
 			if (printService.overload(userName, profile, reportName, whereCondition, otherParameters, Platform.PC)) {
 			if (printService.overload(userName, profile, reportName, whereCondition, otherParameters, Platform.PC)) {
-				throw new ReportException("数据量过大,无法提供服务");
+				throw new IllegalStateException("数据量过大,无法提供服务");
 			}
 			}
 			Map<String, Object> result = printService.preview(userName, profile, reportName, whereCondition,
 			Map<String, Object> result = printService.preview(userName, profile, reportName, whereCondition,
 					otherParameters, null);
 					otherParameters, null);
 			if (CollectionUtils.isEmpty(result) || ArrayUtils.isEmpty((byte[]) result.get("data"))) {
 			if (CollectionUtils.isEmpty(result) || ArrayUtils.isEmpty((byte[]) result.get("data"))) {
-				throw new ReportException("报表预览失败:" + userName + "/" + reportName + "\n");
+				throw new IllegalStateException("报表预览失败:" + userName + "/" + reportName + "\n");
 			}
 			}
 			byte[] data = (byte[]) result.remove("data");
 			byte[] data = (byte[]) result.remove("data");
 			FileUtils.write(file.getPath(), data);
 			FileUtils.write(file.getPath(), data);
@@ -263,11 +273,16 @@ public class PrintController {
 	 * @param request
 	 * @param request
 	 * @param response
 	 * @param response
 	 * @return 包括pageSize、data(或overload)
 	 * @return 包括pageSize、data(或overload)
+	 * @throws SQLException
+	 * @throws DocumentException
+	 * @throws IOException
+	 * @throws JRException
 	 */
 	 */
 	@RequestMapping(value = "/pdfData")
 	@RequestMapping(value = "/pdfData")
 	@ResponseBody
 	@ResponseBody
 	public Map<String, Object> getPdfData(String userName, String profile, String reportName, String whereCondition,
 	public Map<String, Object> getPdfData(String userName, String profile, String reportName, String whereCondition,
-			String otherParameters, HttpServletRequest request, HttpServletResponse response) {
+			String otherParameters, HttpServletRequest request, HttpServletResponse response)
+			throws JRException, IOException, DocumentException, SQLException {
 		userName = userName == null ? null : userName.toUpperCase();
 		userName = userName == null ? null : userName.toUpperCase();
 		ReportUtils.checkParameters(userName, reportName);
 		ReportUtils.checkParameters(userName, reportName);
 		Map<String, Object> result = new HashMap<>();
 		Map<String, Object> result = new HashMap<>();

+ 5 - 11
src/main/java/com/uas/report/core/advice/ExceptionHandlerAdvice.java

@@ -16,8 +16,7 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 
 
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
-import com.uas.report.core.exception.ReportException;
-import com.uas.report.util.StringUtils;
+import com.uas.report.util.ExceptionUtils;
 
 
 /**
 /**
  * 基于Application的异常处理,以AOP的形式注册到SpringMVC的处理链
  * 基于Application的异常处理,以AOP的形式注册到SpringMVC的处理链
@@ -41,15 +40,10 @@ public class ExceptionHandlerAdvice {
 		logger.error("", e);
 		logger.error("", e);
 		ModelMap map = new ModelMap();
 		ModelMap map = new ModelMap();
 		map.put("success", false);
 		map.put("success", false);
-		if (e instanceof ReportException) {
-			map.put("message", e.getMessage());
-			ReportException exception = (ReportException) e;
-			if (!StringUtils.isEmpty(exception.getDetailedMessage())) {
-				map.put("detailedMessage", exception.getDetailedMessage());
-			}
-		} else {
-			map.put("message", e.getClass().getSimpleName() + ": " + e.getMessage());
-		}
+		map.put("message",
+				ExceptionUtils.getMessage(e).replace("\n", "<br/>").replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;"));
+		map.put("detailedMessage",
+				ExceptionUtils.getDetailedMessage(e).replace("\n", "<br/>").replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;"));
 		HttpHeaders headers = new HttpHeaders();
 		HttpHeaders headers = new HttpHeaders();
 		headers.add("Content-Type", "application/json; charset=utf-8");
 		headers.add("Content-Type", "application/json; charset=utf-8");
 		return new ResponseEntity<ModelMap>(map, headers, HttpStatus.INTERNAL_SERVER_ERROR);
 		return new ResponseEntity<ModelMap>(map, headers, HttpStatus.INTERNAL_SERVER_ERROR);

+ 0 - 90
src/main/java/com/uas/report/core/exception/ReportException.java

@@ -1,90 +0,0 @@
-package com.uas.report.core.exception;
-
-/**
- * 将失败原因以成功的请求返回
- * 
- * @author sunyj
- * @since 2016年10月19日 上午8:52:17
- */
-public class ReportException extends RuntimeException {
-
-	private static final long serialVersionUID = 1L;
-
-	private String message;
-
-	/**
-	 * 详细信息
-	 */
-	private String detailedMessage;
-
-	public ReportException(String message) {
-		this.message = message;
-	}
-
-	public ReportException(Throwable e) {
-		this.message = getMessage(e);
-	}
-
-	/**
-	 * 获取异常及其Cause拼接成的字符串
-	 * 
-	 * @param e
-	 *            异常
-	 * @return 拼接后的结果
-	 */
-	public String getMessage(Throwable e) {
-		StringBuilder sb = new StringBuilder(e.toString());
-		if (e.getCause() != null) {
-			sb.append("\nCaused by: ").append(getMessage(e.getCause()));
-		}
-		return sb.toString();
-	}
-
-	/**
-	 * 获取异常及其Cause的StackTrace拼接成的字符串
-	 * 
-	 * @param e
-	 *            异常
-	 * @return 拼接后的结果
-	 */
-	public String getDetailedMessage(Throwable e) {
-		StringBuilder sb = new StringBuilder(e.toString());
-		StackTraceElement[] stackTraceElements = e.getStackTrace();
-		for (StackTraceElement stackTraceElement : stackTraceElements) {
-			sb.append("\n\t").append(stackTraceElement.toString());
-		}
-		if (e.getCause() != null) {
-			sb.append("\nCaused by: ").append(getDetailedMessage(e.getCause()));
-		}
-		return sb.toString();
-	}
-
-	/**
-	 * 获取异常及其Cause的StackTrace用以设置详细信息
-	 * 
-	 * @param e
-	 *            异常
-	 * @return 本SearchException对象
-	 */
-	public ReportException setDetailedMessage(Throwable e) {
-		this.detailedMessage = getDetailedMessage(e);
-		return this;
-	}
-
-	public String getMessage() {
-		return message;
-	}
-
-	public void setMessage(String message) {
-		this.message = message;
-	}
-
-	public String getDetailedMessage() {
-		return detailedMessage;
-	}
-
-	public void setDetailedMessage(String detailedMessage) {
-		this.detailedMessage = detailedMessage;
-	}
-
-}

+ 5 - 7
src/main/java/com/uas/report/crystal2jasper/CrystalToJasper.java

@@ -3,7 +3,6 @@ package com.uas.report.crystal2jasper;
 import java.io.BufferedReader;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.File;
 import java.io.FileFilter;
 import java.io.FileFilter;
-import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.ArrayList;
@@ -29,7 +28,6 @@ import org.dom4j.io.XMLWriter;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 
 
-import com.uas.report.core.exception.ReportException;
 import com.uas.report.crystal2jasper.Join.JoinType;
 import com.uas.report.crystal2jasper.Join.JoinType;
 import com.uas.report.crystal2jasper.Link.LinkType;
 import com.uas.report.crystal2jasper.Link.LinkType;
 import com.uas.report.crystal2jasper.Sort.SortType;
 import com.uas.report.crystal2jasper.Sort.SortType;
@@ -105,10 +103,10 @@ public class CrystalToJasper {
 	 *            是否保持生成的jasper与rpt压缩路径层级相同
 	 *            是否保持生成的jasper与rpt压缩路径层级相同
 	 * @param styleFile
 	 * @param styleFile
 	 *            映射规则文件
 	 *            映射规则文件
-	 * @throws FileNotFoundException
+	 * @throws IOException
 	 */
 	 */
 	private void toJaspers(File rptZipDir, File successDir, File outDir, boolean remainHierarchy, File styleFile)
 	private void toJaspers(File rptZipDir, File successDir, File outDir, boolean remainHierarchy, File styleFile)
-			throws FileNotFoundException {
+			throws IOException {
 		FileUtils.checkDir(rptZipDir);
 		FileUtils.checkDir(rptZipDir);
 		File[] files = rptZipDir.listFiles(new FileFilter() {
 		File[] files = rptZipDir.listFiles(new FileFilter() {
 			@Override
 			@Override
@@ -457,7 +455,7 @@ public class CrystalToJasper {
 			// 根据子报表id获取名称
 			// 根据子报表id获取名称
 			String subReportName = subReportNames.get(subReportId);
 			String subReportName = subReportNames.get(subReportId);
 			if (StringUtils.isEmpty(subReportName)) {
 			if (StringUtils.isEmpty(subReportName)) {
-				throw new ReportException("子报表名称不存在:" + subReportId);
+				throw new IllegalStateException("子报表名称不存在:" + subReportId);
 			}
 			}
 			Node subreportExpressionNode = element.selectSingleNode("*[name()='subreportExpression']");
 			Node subreportExpressionNode = element.selectSingleNode("*[name()='subreportExpression']");
 			// 修改subreportExpression节点
 			// 修改subreportExpression节点
@@ -587,7 +585,7 @@ public class CrystalToJasper {
 		} else if ("foj".equalsIgnoreCase(type)) {
 		} else if ("foj".equalsIgnoreCase(type)) {
 			return JoinType.FULL;
 			return JoinType.FULL;
 		} else {
 		} else {
-			throw new ReportException("无法解析join类型:" + type);
+			throw new IllegalArgumentException("无法解析join类型:" + type);
 		}
 		}
 	}
 	}
 
 
@@ -605,7 +603,7 @@ public class CrystalToJasper {
 		} else if ("le".equalsIgnoreCase(type)) {
 		} else if ("le".equalsIgnoreCase(type)) {
 			return LinkType.LTE;
 			return LinkType.LTE;
 		} else {
 		} else {
-			throw new ReportException("无法解析link类型:" + type);
+			throw new IllegalArgumentException("无法解析link类型:" + type);
 		}
 		}
 	}
 	}
 
 

+ 3 - 4
src/main/java/com/uas/report/schedule/service/impl/TaskServiceImpl.java

@@ -14,12 +14,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import com.uas.report.core.exception.ReportException;
 import com.uas.report.schedule.model.TaskInformation;
 import com.uas.report.schedule.model.TaskInformation;
 import com.uas.report.schedule.model.TaskLog;
 import com.uas.report.schedule.model.TaskLog;
 import com.uas.report.schedule.service.Executable;
 import com.uas.report.schedule.service.Executable;
 import com.uas.report.schedule.service.TaskService;
 import com.uas.report.schedule.service.TaskService;
 import com.uas.report.util.CollectionUtils;
 import com.uas.report.util.CollectionUtils;
+import com.uas.report.util.ExceptionUtils;
 import com.uas.report.util.StringUtils;
 import com.uas.report.util.StringUtils;
 
 
 /**
 /**
@@ -55,7 +55,7 @@ public class TaskServiceImpl implements TaskService {
 			throw new NullPointerException();
 			throw new NullPointerException();
 		}
 		}
 		if (containsTask(taskInformation)) {
 		if (containsTask(taskInformation)) {
-			throw new ReportException("任务已存在:" + taskInformation);
+			throw new IllegalStateException("任务已存在:" + taskInformation);
 		}
 		}
 		taskInformations.add(taskInformation);
 		taskInformations.add(taskInformation);
 	}
 	}
@@ -154,8 +154,7 @@ public class TaskServiceImpl implements TaskService {
 					String result = command.execute();
 					String result = command.execute();
 					saveLog(new TaskLog(taskInformation, new Date(), result));
 					saveLog(new TaskLog(taskInformation, new Date(), result));
 				} catch (Exception e) {
 				} catch (Exception e) {
-					saveLog(new TaskLog(taskInformation, new Date(),
-							"定时任务出错" + new ReportException(e).getDetailedMessage(e)));
+					saveLog(new TaskLog(taskInformation, new Date(), "定时任务出错:" + ExceptionUtils.getDetailedMessage(e)));
 				}
 				}
 			}
 			}
 		};
 		};

+ 19 - 9
src/main/java/com/uas/report/service/FileService.java

@@ -1,5 +1,6 @@
 package com.uas.report.service;
 package com.uas.report.service;
 
 
+import java.io.IOException;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -25,8 +26,9 @@ public interface FileService {
 	 * @param destinationUserNames
 	 * @param destinationUserNames
 	 *            新部署的账套
 	 *            新部署的账套
 	 * @return 部署结果
 	 * @return 部署结果
+	 * @throws IOException
 	 */
 	 */
-	public String autoDeploy(String sourceUserName, String destinationUserNames);
+	public String autoDeploy(String sourceUserName, String destinationUserNames) throws IOException;
 
 
 	/**
 	/**
 	 * 上传文件至指定的账套下
 	 * 上传文件至指定的账套下
@@ -51,8 +53,9 @@ public interface FileService {
 	 * @param files
 	 * @param files
 	 *            上传的文件
 	 *            上传的文件
 	 * @return 上传结果
 	 * @return 上传结果
+	 * @throws IOException
 	 */
 	 */
-	public String upload(String filePath, Boolean isAbsolutePath, MultipartFile[] files);
+	public String upload(String filePath, Boolean isAbsolutePath, MultipartFile[] files) throws IOException;
 
 
 	/**
 	/**
 	 * 获取账套下的模板路径
 	 * 获取账套下的模板路径
@@ -80,8 +83,9 @@ public interface FileService {
 	 * @param userName
 	 * @param userName
 	 *            账套名称
 	 *            账套名称
 	 * @param response
 	 * @param response
+	 * @throws IOException
 	 */
 	 */
-	public void downloadStandardJrxmls(String userName, HttpServletResponse response);
+	public void downloadStandardJrxmls(String userName, HttpServletResponse response) throws IOException;
 
 
 	/**
 	/**
 	 * 获取指定账套的标准模板数据
 	 * 获取指定账套的标准模板数据
@@ -89,8 +93,9 @@ public interface FileService {
 	 * @param userName
 	 * @param userName
 	 *            账套名称
 	 *            账套名称
 	 * @return 标准模板数据
 	 * @return 标准模板数据
+	 * @throws IOException
 	 */
 	 */
-	public byte[] getStandardJrxmls(String userName);
+	public byte[] getStandardJrxmls(String userName) throws IOException;
 
 
 	/**
 	/**
 	 * 获取账套下的所有资源
 	 * 获取账套下的所有资源
@@ -98,8 +103,9 @@ public interface FileService {
 	 * @param userName
 	 * @param userName
 	 *            账套名称
 	 *            账套名称
 	 * @param response
 	 * @param response
+	 * @throws IOException
 	 */
 	 */
-	public void downloadZip(String userName, HttpServletResponse response);
+	public void downloadZip(String userName, HttpServletResponse response) throws IOException;
 
 
 	/**
 	/**
 	 * 下载文件
 	 * 下载文件
@@ -109,8 +115,9 @@ public interface FileService {
 	 * @param isAbsolutePath
 	 * @param isAbsolutePath
 	 *            文件路径是否为绝对路径,不传的话默认为假
 	 *            文件路径是否为绝对路径,不传的话默认为假
 	 * @param response
 	 * @param response
+	 * @throws IOException
 	 */
 	 */
-	public void download(String filePath, Boolean isAbsolutePath, HttpServletResponse response);
+	public void download(String filePath, Boolean isAbsolutePath, HttpServletResponse response) throws IOException;
 
 
 	/**
 	/**
 	 * 下载文件
 	 * 下载文件
@@ -131,8 +138,9 @@ public interface FileService {
 	 * @param isAbsolutePath
 	 * @param isAbsolutePath
 	 *            文件(夹)路径是否为绝对路径,不传的话默认为假
 	 *            文件(夹)路径是否为绝对路径,不传的话默认为假
 	 * @return 文件(夹)绝对路径
 	 * @return 文件(夹)绝对路径
+	 * @throws IOException
 	 */
 	 */
-	public String delete(String filePath, Boolean isAbsolutePath);
+	public String delete(String filePath, Boolean isAbsolutePath) throws IOException;
 
 
 	/**
 	/**
 	 * 列出指定路径的文件信息
 	 * 列出指定路径的文件信息
@@ -143,8 +151,9 @@ public interface FileService {
 	 *            文件路径是否为绝对路径,不传的话默认为假
 	 *            文件路径是否为绝对路径,不传的话默认为假
 	 * @return 文件信息,包括name(String)、lastModified(String)、size(Long)、filePath(
 	 * @return 文件信息,包括name(String)、lastModified(String)、size(Long)、filePath(
 	 *         String,可能是相对路径,也可能是绝对路径,具体取决于isAbsolutePath)、isDirectory(Boolean)
 	 *         String,可能是相对路径,也可能是绝对路径,具体取决于isAbsolutePath)、isDirectory(Boolean)
+	 * @throws IOException
 	 */
 	 */
-	public List<Map<String, Object>> listFiles(String filePath, Boolean isAbsolutePath);
+	public List<Map<String, Object>> listFiles(String filePath, Boolean isAbsolutePath) throws IOException;
 
 
 	/**
 	/**
 	 * 判断文件是否有效(文件存在并且未过有效期,并且比模板新)
 	 * 判断文件是否有效(文件存在并且未过有效期,并且比模板新)
@@ -182,8 +191,9 @@ public interface FileService {
 	 * @param pdfFileAbsolutePath
 	 * @param pdfFileAbsolutePath
 	 *            给定的pdf文件绝对路径
 	 *            给定的pdf文件绝对路径
 	 * @return pdf文件的页数
 	 * @return pdf文件的页数
+	 * @throws IOException
 	 */
 	 */
-	public int getPageSize(String pdfFileAbsolutePath);
+	public int getPageSize(String pdfFileAbsolutePath) throws IOException;
 
 
 	/**
 	/**
 	 * 开启删除产生的pdf等文件的定时任务
 	 * 开启删除产生的pdf等文件的定时任务

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

@@ -1,9 +1,15 @@
 package com.uas.report.service;
 package com.uas.report.service;
 
 
+import java.io.IOException;
+import java.sql.SQLException;
 import java.util.Map;
 import java.util.Map;
 
 
+import org.dom4j.DocumentException;
+
 import com.uas.report.util.Platform;
 import com.uas.report.util.Platform;
 
 
+import net.sf.jasperreports.engine.JRException;
+
 /**
 /**
  * 报表打印
  * 报表打印
  * 
  * 
@@ -29,9 +35,14 @@ public interface PrintService {
 	 * @param exportFileType
 	 * @param exportFileType
 	 *            报表导出的格式,默认为pdf
 	 *            报表导出的格式,默认为pdf
 	 * @return 导出的文件的字节数组
 	 * @return 导出的文件的字节数组
+	 * @throws SQLException
+	 * @throws DocumentException
+	 * @throws IOException
+	 * @throws JRException
 	 */
 	 */
 	public byte[] export(String userName, String profile, String reportName, String whereCondition,
 	public byte[] export(String userName, String profile, String reportName, String whereCondition,
-			String otherParameters, String exportFileType);
+			String otherParameters, String exportFileType)
+			throws JRException, IOException, DocumentException, SQLException;
 
 
 	/**
 	/**
 	 * 预览报表
 	 * 预览报表
@@ -50,9 +61,13 @@ public interface PrintService {
 	 * @param pageIndex
 	 * @param pageIndex
 	 *            分页展示,当前页码,从0开始
 	 *            分页展示,当前页码,从0开始
 	 * @return 报表数据"data": byte[];总页数"pageSize": Integer
 	 * @return 报表数据"data": byte[];总页数"pageSize": Integer
+	 * @throws SQLException
+	 * @throws DocumentException
+	 * @throws IOException
+	 * @throws JRException
 	 */
 	 */
 	public Map<String, Object> preview(String userName, String profile, String reportName, String whereCondition,
 	public Map<String, Object> preview(String userName, String profile, String reportName, String whereCondition,
-			String otherParameters, Integer pageIndex);
+			String otherParameters, Integer pageIndex) throws JRException, IOException, DocumentException, SQLException;
 
 
 	/**
 	/**
 	 * 获取模板对应的账套
 	 * 获取模板对应的账套
@@ -85,8 +100,11 @@ public interface PrintService {
 	 * @param platform
 	 * @param platform
 	 *            请求来自的平台
 	 *            请求来自的平台
 	 * @return 结果数目超出限制,返回true
 	 * @return 结果数目超出限制,返回true
+	 * @throws SQLException
+	 * @throws IOException
+	 * @throws DocumentException
 	 */
 	 */
 	public boolean overload(String userName, String profile, String reportName, String whereCondition,
 	public boolean overload(String userName, String profile, String reportName, String whereCondition,
-			String otherParameters, Platform platform);
+			String otherParameters, Platform platform) throws SQLException, IOException, DocumentException;
 
 
 }
 }

+ 76 - 90
src/main/java/com/uas/report/service/impl/FileServiceImpl.java

@@ -3,6 +3,7 @@ package com.uas.report.service.impl;
 import java.io.File;
 import java.io.File;
 import java.io.FileFilter;
 import java.io.FileFilter;
 import java.io.FileInputStream;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStream;
@@ -29,12 +30,12 @@ import org.springframework.web.multipart.MultipartFile;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.lowagie.text.pdf.PdfReader;
 import com.lowagie.text.pdf.PdfReader;
 import com.uas.report.SpecialProperties;
 import com.uas.report.SpecialProperties;
-import com.uas.report.core.exception.ReportException;
 import com.uas.report.schedule.model.TaskInformation;
 import com.uas.report.schedule.model.TaskInformation;
 import com.uas.report.schedule.service.Executable;
 import com.uas.report.schedule.service.Executable;
 import com.uas.report.schedule.service.TaskService;
 import com.uas.report.schedule.service.TaskService;
 import com.uas.report.service.FileService;
 import com.uas.report.service.FileService;
 import com.uas.report.util.ArrayUtils;
 import com.uas.report.util.ArrayUtils;
+import com.uas.report.util.ExceptionUtils;
 import com.uas.report.util.FileUtils;
 import com.uas.report.util.FileUtils;
 import com.uas.report.util.ReportConstants;
 import com.uas.report.util.ReportConstants;
 import com.uas.report.util.ReportUtils;
 import com.uas.report.util.ReportUtils;
@@ -82,36 +83,32 @@ public class FileServiceImpl implements FileService {
 	};
 	};
 
 
 	@Override
 	@Override
-	public String autoDeploy(String sourceUserName, String destinationUserNames) {
+	public String autoDeploy(String sourceUserName, String destinationUserNames) throws IOException {
 		if (StringUtils.isEmpty(sourceUserName) || StringUtils.isEmpty(destinationUserNames)) {
 		if (StringUtils.isEmpty(sourceUserName) || StringUtils.isEmpty(destinationUserNames)) {
-			throw new ReportException("参数不能为空:sourceUserName,destinationUserNames");
+			throw new IllegalArgumentException("参数不能为空:sourceUserName,destinationUserNames");
 		}
 		}
-		try {
-			byte[] data = null;
-			String stantardJrxmlsUrl = String.format(specialProperties.getStandardJrxmlsUrl(), sourceUserName);
-			// 如果本机提供标准模板下载,直接从本地获取数据
-			if (specialProperties.hasStandardJrxmls()) {
-				data = getStandardJrxmls(sourceUserName);
-			}
-			// 本机没有标准模板,则先下载标准模板数据
-			else {
-				logger.info("get standardJrxmls from " + stantardJrxmlsUrl + "...");
-				JSONObject jsonObject = JSONObject.parseObject(IOUtils.toString(HttpClients.createDefault()
-						.execute(new HttpGet(URI.create(stantardJrxmlsUrl))).getEntity().getContent()));
-				data = jsonObject.getBytes("data");
-			}
-			if (ArrayUtils.isEmpty(data)) {
-				throw new ReportException("标准模板不存在");
-			}
-			String[] userNameArray = destinationUserNames.split(",");
-			// 创建账套路径并解压模板zip包
-			for (String userName : userNameArray) {
-				ZipUtils.unzip(data, getMasterPath(userName));
-			}
-			return "已自动部署:" + destinationUserNames;
-		} catch (UnsupportedOperationException | IOException e) {
-			throw new ReportException(e).setDetailedMessage(e);
+		byte[] data = null;
+		String stantardJrxmlsUrl = String.format(specialProperties.getStandardJrxmlsUrl(), sourceUserName);
+		// 如果本机提供标准模板下载,直接从本地获取数据
+		if (specialProperties.hasStandardJrxmls()) {
+			data = getStandardJrxmls(sourceUserName);
+		}
+		// 本机没有标准模板,则先下载标准模板数据
+		else {
+			logger.info("get standardJrxmls from " + stantardJrxmlsUrl + "...");
+			JSONObject jsonObject = JSONObject.parseObject(IOUtils.toString(HttpClients.createDefault()
+					.execute(new HttpGet(URI.create(stantardJrxmlsUrl))).getEntity().getContent()));
+			data = jsonObject.getBytes("data");
 		}
 		}
+		if (ArrayUtils.isEmpty(data)) {
+			throw new IllegalStateException("标准模板不存在");
+		}
+		String[] userNameArray = destinationUserNames.split(",");
+		// 创建账套路径并解压模板zip包
+		for (String userName : userNameArray) {
+			ZipUtils.unzip(data, getMasterPath(userName));
+		}
+		return "已自动部署:" + destinationUserNames;
 	}
 	}
 
 
 	@Override
 	@Override
@@ -134,7 +131,7 @@ public class FileServiceImpl implements FileService {
 					try {
 					try {
 						ZipUtils.unzip(file.getBytes(), getMasterPath(userName));
 						ZipUtils.unzip(file.getBytes(), getMasterPath(userName));
 					} catch (IOException e) {
 					} catch (IOException e) {
-						throw new ReportException("文件解压失败").setDetailedMessage(e);
+						throw new IllegalStateException("文件解压失败\n" + ExceptionUtils.getDetailedMessage(e));
 					}
 					}
 				}
 				}
 			}).start();
 			}).start();
@@ -151,7 +148,7 @@ public class FileServiceImpl implements FileService {
 		} else if (fileType.equals("other")) {
 		} else if (fileType.equals("other")) {
 			stringBuilder.append(userName).append("/");
 			stringBuilder.append(userName).append("/");
 		} else {
 		} else {
-			throw new ReportException("不支持上传该类型的文件:" + fileType);
+			throw new IllegalArgumentException("不支持上传该类型的文件:" + fileType);
 		}
 		}
 
 
 		stringBuilder.append(fileName);
 		stringBuilder.append(fileName);
@@ -163,14 +160,14 @@ public class FileServiceImpl implements FileService {
 		try {
 		try {
 			FileUtils.write(targetFile.getAbsolutePath(), file.getBytes(), true);
 			FileUtils.write(targetFile.getAbsolutePath(), file.getBytes(), true);
 			return "成功上传文件至:" + targetFile.getPath();
 			return "成功上传文件至:" + targetFile.getPath();
-		} catch (IllegalStateException | IOException | ReportException e) {
+		} catch (IllegalStateException | IOException e) {
 			logger.error("", e);
 			logger.error("", e);
 			return "文件上传失败: " + fileName;
 			return "文件上传失败: " + fileName;
 		}
 		}
 	}
 	}
 
 
 	@Override
 	@Override
-	public String upload(String filePath, Boolean isAbsolutePath, MultipartFile[] files) {
+	public String upload(String filePath, Boolean isAbsolutePath, MultipartFile[] files) throws IOException {
 		if (ArrayUtils.isEmpty(files)) {
 		if (ArrayUtils.isEmpty(files)) {
 			return "文件为空,无法进行上传!";
 			return "文件为空,无法进行上传!";
 		}
 		}
@@ -182,22 +179,18 @@ public class FileServiceImpl implements FileService {
 		}
 		}
 
 
 		StringBuilder stringBuilder = new StringBuilder();
 		StringBuilder stringBuilder = new StringBuilder();
-		try {
-			for (MultipartFile file : files) {
-				String fileName = file.getOriginalFilename();
-				targetFile = new File(targetFile.getParent() + "/" + fileName);
-				// 不能使用file.transferTo(targetFile),
-				// 因为在spring boot下上传文件时会对临时路径进行处理,
-				// 导致最终文件路径不正确,如果手动设置临时路径为根路径,
-				// 又会因为权限问题导致文件写入失败,
-				// 所以自己在指定路径创建文件,而不使用transferTo方法
-				FileUtils.write(targetFile.getAbsolutePath(), file.getBytes(), true);
-				stringBuilder.append("上传成功:").append(fileName).append("\n");
-			}
-			return stringBuilder.toString();
-		} catch (IllegalStateException | IOException e) {
-			throw new ReportException(e).setDetailedMessage(e);
+		for (MultipartFile file : files) {
+			String fileName = file.getOriginalFilename();
+			targetFile = new File(targetFile.getParent() + "/" + fileName);
+			// 不能使用file.transferTo(targetFile),
+			// 因为在spring boot下上传文件时会对临时路径进行处理,
+			// 导致最终文件路径不正确,如果手动设置临时路径为根路径,
+			// 又会因为权限问题导致文件写入失败,
+			// 所以自己在指定路径创建文件,而不使用transferTo方法
+			FileUtils.write(targetFile.getAbsolutePath(), file.getBytes(), true);
+			stringBuilder.append("上传成功:").append(fileName).append("\n");
 		}
 		}
+		return stringBuilder.toString();
 	}
 	}
 
 
 	@Override
 	@Override
@@ -210,82 +203,78 @@ public class FileServiceImpl implements FileService {
 	@Override
 	@Override
 	public String getMasterPath(String userName) {
 	public String getMasterPath(String userName) {
 		if (StringUtils.isEmpty(userName)) {
 		if (StringUtils.isEmpty(userName)) {
-			throw new ReportException("参数不能为空:userName");
+			throw new IllegalArgumentException("参数不能为空:userName");
 		}
 		}
 		return new StringBuilder(specialProperties.getLocalBaseDir()).append("/").append(userName).toString();
 		return new StringBuilder(specialProperties.getLocalBaseDir()).append("/").append(userName).toString();
 	}
 	}
 
 
 	@Override
 	@Override
-	public byte[] getStandardJrxmls(String userName) {
+	public byte[] getStandardJrxmls(String userName) throws IOException {
 		if (StringUtils.isEmpty(userName)) {
 		if (StringUtils.isEmpty(userName)) {
-			throw new ReportException("未传入当前账套名称!");
+			throw new IllegalArgumentException("未传入当前账套名称!");
 		}
 		}
 		if (!specialProperties.hasStandardJrxmls()) {
 		if (!specialProperties.hasStandardJrxmls()) {
-			throw new ReportException("没有" + userName + "标准模板!");
+			throw new IllegalStateException("没有" + userName + "标准模板!");
 		}
 		}
 		try {
 		try {
 			return ZipUtils.zipFolder(getMasterPath(specialProperties.getStandardMaster()) + "/" + userName,
 			return ZipUtils.zipFolder(getMasterPath(specialProperties.getStandardMaster()) + "/" + userName,
 					FileServiceImpl.fileFilter);
 					FileServiceImpl.fileFilter);
 		} catch (Throwable e) {
 		} catch (Throwable e) {
-			throw new ReportException("压缩失败").setDetailedMessage(e);
+			throw new IOException("压缩失败\n" + ExceptionUtils.getDetailedMessage(e));
 		}
 		}
 	}
 	}
 
 
 	@Override
 	@Override
-	public void downloadStandardJrxmls(String userName, HttpServletResponse response) {
+	public void downloadStandardJrxmls(String userName, HttpServletResponse response) throws IOException {
 		if (StringUtils.isEmpty(userName)) {
 		if (StringUtils.isEmpty(userName)) {
-			throw new ReportException("未传入当前账套名称!");
+			throw new IllegalArgumentException("未传入当前账套名称!");
 		}
 		}
 		if (!specialProperties.hasStandardJrxmls()) {
 		if (!specialProperties.hasStandardJrxmls()) {
-			throw new ReportException("没有" + userName + "标准模板!");
+			throw new IllegalStateException("没有" + userName + "标准模板!");
 		}
 		}
 		downloadZip(specialProperties.getStandardMaster() + "/" + userName, response);
 		downloadZip(specialProperties.getStandardMaster() + "/" + userName, response);
 	}
 	}
 
 
 	@Override
 	@Override
-	public void downloadZip(String userName, HttpServletResponse response) {
+	public void downloadZip(String userName, HttpServletResponse response) throws IOException {
 		if (StringUtils.isEmpty(userName)) {
 		if (StringUtils.isEmpty(userName)) {
-			throw new ReportException("未传入当前账套名称!");
+			throw new IllegalArgumentException("未传入当前账套名称!");
 		}
 		}
 		String masterPath = getMasterPath(userName);
 		String masterPath = getMasterPath(userName);
 		try {
 		try {
 			byte[] data = ZipUtils.zipFolder(masterPath, FileServiceImpl.fileFilter);
 			byte[] data = ZipUtils.zipFolder(masterPath, FileServiceImpl.fileFilter);
 			download(data, new File(masterPath).getName() + ".zip", response);
 			download(data, new File(masterPath).getName() + ".zip", response);
 		} catch (Throwable e) {
 		} catch (Throwable e) {
-			throw new ReportException("压缩失败").setDetailedMessage(e);
+			throw new IOException("压缩失败\n" + ExceptionUtils.getDetailedMessage(e));
 		}
 		}
 	}
 	}
 
 
 	@Override
 	@Override
-	public void download(String filePath, Boolean isAbsolutePath, HttpServletResponse response) {
+	public void download(String filePath, Boolean isAbsolutePath, HttpServletResponse response) throws IOException {
 		if (StringUtils.isEmpty(filePath) || response == null) {
 		if (StringUtils.isEmpty(filePath) || response == null) {
-			throw new ReportException("参数不能为空:filePath,response");
+			throw new IllegalArgumentException("参数不能为空:filePath,response");
 		}
 		}
 		filePath = getAbsolutePath(filePath, isAbsolutePath);
 		filePath = getAbsolutePath(filePath, isAbsolutePath);
 		File file = new File(filePath);
 		File file = new File(filePath);
 		if (!file.exists()) {
 		if (!file.exists()) {
-			throw new ReportException("文件不存在:" + filePath);
+			throw new FileNotFoundException("文件不存在:" + filePath);
 		}
 		}
 
 
 		byte[] data = null;
 		byte[] data = null;
 		String fileName = "";
 		String fileName = "";
 		// 下载文件夹之前,需进行压缩
 		// 下载文件夹之前,需进行压缩
-		try {
-			if (file.isDirectory()) {
-				fileName = file.getName() + ".zip";
-				data = ZipUtils.zipFolder(filePath, fileFilter);
-			} else {
-				fileName = file.getName();
-				InputStream inputStream = new FileInputStream(file);
-				data = new byte[inputStream.available()];
-				inputStream.read(data);
-				inputStream.close();
-			}
-		} catch (IOException e) {
-			throw new ReportException(e.getMessage()).setDetailedMessage(e);
+		if (file.isDirectory()) {
+			fileName = file.getName() + ".zip";
+			data = ZipUtils.zipFolder(filePath, fileFilter);
+		} else {
+			fileName = file.getName();
+			InputStream inputStream = new FileInputStream(file);
+			data = new byte[inputStream.available()];
+			inputStream.read(data);
+			inputStream.close();
 		}
 		}
 		if (ArrayUtils.isEmpty(data)) {
 		if (ArrayUtils.isEmpty(data)) {
-			throw new ReportException("下载失败:" + filePath);
+			throw new IOException("下载失败:" + filePath);
 		}
 		}
 		download(data, fileName, response);
 		download(data, fileName, response);
 	}
 	}
@@ -293,7 +282,7 @@ public class FileServiceImpl implements FileService {
 	@Override
 	@Override
 	public void download(byte[] data, String fileName, HttpServletResponse response) {
 	public void download(byte[] data, String fileName, HttpServletResponse response) {
 		if (ArrayUtils.isEmpty(data) || StringUtils.isEmpty(fileName) || response == null) {
 		if (ArrayUtils.isEmpty(data) || StringUtils.isEmpty(fileName) || response == null) {
-			throw new ReportException("参数不能为空:data,filePath,response");
+			throw new IllegalArgumentException("参数不能为空:data,filePath,response");
 		}
 		}
 		try {
 		try {
 			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
 			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
@@ -307,30 +296,30 @@ public class FileServiceImpl implements FileService {
 	}
 	}
 
 
 	@Override
 	@Override
-	public String delete(String filePath, Boolean isAbsolutePath) {
+	public String delete(String filePath, Boolean isAbsolutePath) throws IOException {
 		// 路径不能为空,不能只包含'/'(根路径),不能含有'..'(不允许通过该方式删除上一级)
 		// 路径不能为空,不能只包含'/'(根路径),不能含有'..'(不允许通过该方式删除上一级)
 		if (StringUtils.isEmpty(filePath) || StringUtils.isEmpty(filePath.replaceAll("/", ""))
 		if (StringUtils.isEmpty(filePath) || StringUtils.isEmpty(filePath.replaceAll("/", ""))
 				|| filePath.contains("..")) {
 				|| filePath.contains("..")) {
-			throw new ReportException("路径不合法:" + filePath);
+			throw new IllegalArgumentException("路径不合法:" + filePath);
 		}
 		}
 		filePath = getAbsolutePath(filePath, isAbsolutePath);
 		filePath = getAbsolutePath(filePath, isAbsolutePath);
 		if (StringUtils.isEmpty(filePath)) {
 		if (StringUtils.isEmpty(filePath)) {
-			throw new ReportException("参数不能为空:filePath");
+			throw new IllegalArgumentException("参数不能为空:filePath");
 		}
 		}
 		File file = new File(filePath);
 		File file = new File(filePath);
 		if (!file.exists()) {
 		if (!file.exists()) {
-			throw new ReportException("文件不存在,不必删除:" + filePath);
+			throw new IOException("文件不存在,不必删除:" + filePath);
 		}
 		}
 		FileUtils.delete(file);
 		FileUtils.delete(file);
 		return filePath;
 		return filePath;
 	}
 	}
 
 
 	@Override
 	@Override
-	public List<Map<String, Object>> listFiles(String filePath, Boolean isAbsolutePath) {
+	public List<Map<String, Object>> listFiles(String filePath, Boolean isAbsolutePath) throws IOException {
 		filePath = getAbsolutePath(filePath, isAbsolutePath);
 		filePath = getAbsolutePath(filePath, isAbsolutePath);
 		File file = new File(filePath);
 		File file = new File(filePath);
 		if (!file.exists()) {
 		if (!file.exists()) {
-			throw new ReportException("文件不存在:" + filePath);
+			throw new FileNotFoundException("文件不存在:" + filePath);
 		}
 		}
 
 
 		List<Map<String, Object>> result = new ArrayList<>();
 		List<Map<String, Object>> result = new ArrayList<>();
@@ -462,12 +451,8 @@ public class FileServiceImpl implements FileService {
 	}
 	}
 
 
 	@Override
 	@Override
-	public int getPageSize(String pdfFileAbsolutePath) {
-		try {
-			return new PdfReader(pdfFileAbsolutePath).getNumberOfPages();
-		} catch (IOException e) {
-			throw new ReportException(e).setDetailedMessage(e);
-		}
+	public int getPageSize(String pdfFileAbsolutePath) throws IOException {
+		return new PdfReader(pdfFileAbsolutePath).getNumberOfPages();
 	}
 	}
 
 
 	/**
 	/**
@@ -478,10 +463,11 @@ public class FileServiceImpl implements FileService {
 	 * @param isAbsolutePath
 	 * @param isAbsolutePath
 	 *            是否为绝对路径
 	 *            是否为绝对路径
 	 * @return 绝对路径
 	 * @return 绝对路径
+	 * @throws IOException
 	 */
 	 */
-	private String getAbsolutePath(String filePath, Boolean isAbsolutePath) {
+	private String getAbsolutePath(String filePath, Boolean isAbsolutePath) throws IOException {
 		if (StringUtils.isEmpty(filePath)) {
 		if (StringUtils.isEmpty(filePath)) {
-			throw new ReportException("路径不合法:" + filePath);
+			throw new IllegalArgumentException("路径不合法:" + filePath);
 		}
 		}
 		// 不是绝对路径的话,则相对于模板根路径
 		// 不是绝对路径的话,则相对于模板根路径
 		if (isAbsolutePath == null || !isAbsolutePath) {
 		if (isAbsolutePath == null || !isAbsolutePath) {

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

@@ -41,12 +41,12 @@ import org.springframework.stereotype.Service;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.uas.report.SpecialProperties;
 import com.uas.report.SpecialProperties;
 import com.uas.report.SystemProperties;
 import com.uas.report.SystemProperties;
-import com.uas.report.core.exception.ReportException;
 import com.uas.report.jasperreports.engine.export.CustomJRXlsExporter;
 import com.uas.report.jasperreports.engine.export.CustomJRXlsExporter;
 import com.uas.report.model.Master;
 import com.uas.report.model.Master;
 import com.uas.report.service.FileService;
 import com.uas.report.service.FileService;
 import com.uas.report.service.PrintService;
 import com.uas.report.service.PrintService;
 import com.uas.report.util.CollectionUtils;
 import com.uas.report.util.CollectionUtils;
+import com.uas.report.util.ExceptionUtils;
 import com.uas.report.util.FileUtils;
 import com.uas.report.util.FileUtils;
 import com.uas.report.util.MasterManager;
 import com.uas.report.util.MasterManager;
 import com.uas.report.util.Platform;
 import com.uas.report.util.Platform;
@@ -83,7 +83,7 @@ public class PrintServiceImpl implements PrintService {
 
 
 	@Autowired
 	@Autowired
 	private FileService fileService;
 	private FileService fileService;
-	
+
 	@Autowired
 	@Autowired
 	private SystemProperties systemProperties;
 	private SystemProperties systemProperties;
 
 
@@ -97,7 +97,8 @@ public class PrintServiceImpl implements PrintService {
 
 
 	@Override
 	@Override
 	public byte[] export(String userName, String profile, String reportName, String whereCondition,
 	public byte[] export(String userName, String profile, String reportName, String whereCondition,
-			String otherParameters, String exportFileType) {
+			String otherParameters, String exportFileType)
+			throws JRException, IOException, DocumentException, SQLException {
 		Map<String, Object> result = print(userName, profile, reportName, whereCondition, otherParameters,
 		Map<String, Object> result = print(userName, profile, reportName, whereCondition, otherParameters,
 				exportFileType, null);
 				exportFileType, null);
 		if (!CollectionUtils.isEmpty(result)) {
 		if (!CollectionUtils.isEmpty(result)) {
@@ -108,7 +109,8 @@ public class PrintServiceImpl implements PrintService {
 
 
 	@Override
 	@Override
 	public Map<String, Object> preview(String userName, String profile, String reportName, String whereCondition,
 	public Map<String, Object> preview(String userName, String profile, String reportName, String whereCondition,
-			String otherParameters, Integer pageIndex) {
+			String otherParameters, Integer pageIndex)
+			throws JRException, IOException, DocumentException, SQLException {
 		return print(userName, profile, reportName, whereCondition, otherParameters, null, pageIndex);
 		return print(userName, profile, reportName, whereCondition, otherParameters, null, pageIndex);
 	}
 	}
 
 
@@ -123,9 +125,14 @@ public class PrintServiceImpl implements PrintService {
 	 * @param exportFileType
 	 * @param exportFileType
 	 * @param pageIndex
 	 * @param pageIndex
 	 * @return 页码pageSize:int,数据data:byte[]
 	 * @return 页码pageSize:int,数据data:byte[]
+	 * @throws JRException
+	 * @throws IOException
+	 * @throws DocumentException
+	 * @throws SQLException
 	 */
 	 */
 	private Map<String, Object> print(String userName, String profile, String reportName, String whereCondition,
 	private Map<String, Object> print(String userName, String profile, String reportName, String whereCondition,
-			String otherParameters, String exportFileType, Integer pageIndex) {
+			String otherParameters, String exportFileType, Integer pageIndex)
+			throws JRException, IOException, DocumentException, SQLException {
 		// TODO 重新实现jasperserver接口
 		// TODO 重新实现jasperserver接口
 		// try {
 		// try {
 		// resourceService.syncResources(userName);
 		// resourceService.syncResources(userName);
@@ -135,7 +142,7 @@ public class PrintServiceImpl implements PrintService {
 
 
 		DataSource dataSource = MasterManager.getDataSource(userName, profile);
 		DataSource dataSource = MasterManager.getDataSource(userName, profile);
 		if (dataSource == null) {
 		if (dataSource == null) {
-			throw new ReportException("获取数据源失败");
+			throw new SQLException("获取数据源失败");
 		}
 		}
 
 
 		String masterOfJrxml = getMasterOfJrxml(userName, reportName);
 		String masterOfJrxml = getMasterOfJrxml(userName, reportName);
@@ -214,15 +221,9 @@ public class PrintServiceImpl implements PrintService {
 			}
 			}
 			result.put("data", data);
 			result.put("data", data);
 			return result;
 			return result;
-		} catch (Throwable e) {
-			throw new ReportException(e).setDetailedMessage(e);
 		} finally {
 		} finally {
 			if (connection != null) {
 			if (connection != null) {
-				try {
-					connection.close();
-				} catch (SQLException e) {
-					throw new ReportException(e).setDetailedMessage(e);
-				}
+				connection.close();
 			}
 			}
 		}
 		}
 	}
 	}
@@ -236,10 +237,11 @@ public class PrintServiceImpl implements PrintService {
 	 * @param connection
 	 * @param connection
 	 * @return 编译后的jasper文件路径
 	 * @return 编译后的jasper文件路径
 	 * @throws IOException
 	 * @throws IOException
-	 * @throws FileNotFoundException
+	 * @throws SQLException
+	 * @throws DocumentException
 	 */
 	 */
 	private String maybeCompileJrxmlFile(String jrxmlFilePath, String otherParameters, Connection connection)
 	private String maybeCompileJrxmlFile(String jrxmlFilePath, String otherParameters, Connection connection)
-			throws FileNotFoundException, IOException {
+			throws IOException, DocumentException, SQLException {
 		if (StringUtils.isEmpty(jrxmlFilePath)) {
 		if (StringUtils.isEmpty(jrxmlFilePath)) {
 			logger.error("参数不能为空:" + jrxmlFilePath);
 			logger.error("参数不能为空:" + jrxmlFilePath);
 			return null;
 			return null;
@@ -248,17 +250,13 @@ public class PrintServiceImpl implements PrintService {
 		// 报表模板不存在
 		// 报表模板不存在
 		if (!jrxmlFile.exists()) {
 		if (!jrxmlFile.exists()) {
 			// 替换windows下路径中的双反斜杠为单斜杠
 			// 替换windows下路径中的双反斜杠为单斜杠
-			throw new ReportException("未发现模板文件:" + jrxmlFilePath.replaceAll("\\\\", "/"));
+			throw new FileNotFoundException("未发现模板文件:" + jrxmlFilePath.replaceAll("\\\\", "/"));
 		}
 		}
 
 
 		// 首先解析jrxml文件,检查是否引用子报表,如果是,先(递归)编译子报表
 		// 首先解析jrxml文件,检查是否引用子报表,如果是,先(递归)编译子报表
-		try {
-			List<String> subJrxmlFilePaths = getSubJrxmlFilePath(jrxmlFilePath);
-			for (String subJrxmlFilePath : subJrxmlFilePaths) {
-				maybeCompileJrxmlFile(subJrxmlFilePath, otherParameters, connection);
-			}
-		} catch (DocumentException e) {
-			throw new ReportException(e).setDetailedMessage(e);
+		List<String> subJrxmlFilePaths = getSubJrxmlFilePath(jrxmlFilePath);
+		for (String subJrxmlFilePath : subJrxmlFilePaths) {
+			maybeCompileJrxmlFile(subJrxmlFilePath, otherParameters, connection);
 		}
 		}
 
 
 		String jasperFilePath = jrxmlFilePath.replace(".jrxml", ".jasper");
 		String jasperFilePath = jrxmlFilePath.replace(".jrxml", ".jasper");
@@ -276,8 +274,7 @@ public class PrintServiceImpl implements PrintService {
 				compileReportToFile(jrxmlFilePath, jasperFilePath, otherParameters, connection);
 				compileReportToFile(jrxmlFilePath, jasperFilePath, otherParameters, connection);
 			}
 			}
 		} catch (JRException e) {
 		} catch (JRException e) {
-			logger.error("", e);
-			throw new ReportException("编译报表模板失败: " + jrxmlFilePath + " " + e.getMessage()).setDetailedMessage(e);
+			throw new IllegalStateException("编译报表模板失败: " + jrxmlFilePath + " " + ExceptionUtils.getDetailedMessage(e));
 		}
 		}
 		return jasperFilePath;
 		return jasperFilePath;
 	}
 	}
@@ -303,7 +300,7 @@ public class PrintServiceImpl implements PrintService {
 			int beginIndex = text.indexOf("/jrxml/");
 			int beginIndex = text.indexOf("/jrxml/");
 			int endIndex = text.indexOf(".jasper");
 			int endIndex = text.indexOf(".jasper");
 			if (beginIndex < 0 || endIndex < 0) {
 			if (beginIndex < 0 || endIndex < 0) {
-				throw new ReportException("嵌套报表源码解析失败:" + jrxmlFile.getName() + ",子报表引用格式错误:" + text);
+				throw new IllegalStateException("嵌套报表源码解析失败:" + jrxmlFile.getName() + ",子报表引用格式错误:" + text);
 			}
 			}
 			beginIndex += "/jrxml/".length();
 			beginIndex += "/jrxml/".length();
 			subJrxmlFilePaths.add(jrxmlFile.getParent() + "/" + text.substring(beginIndex, endIndex) + ".jrxml");
 			subJrxmlFilePaths.add(jrxmlFile.getParent() + "/" + text.substring(beginIndex, endIndex) + ".jrxml");
@@ -324,9 +321,12 @@ public class PrintServiceImpl implements PrintService {
 	 * @throws JRException
 	 * @throws JRException
 	 * @throws IOException
 	 * @throws IOException
 	 * @throws FileNotFoundException
 	 * @throws FileNotFoundException
+	 * @throws DocumentException
+	 * @throws SQLException
 	 */
 	 */
 	private void compileReportToFile(String jrxmlFilePath, String jasperFilePath, String otherParameters,
 	private void compileReportToFile(String jrxmlFilePath, String jasperFilePath, String otherParameters,
-			Connection connection) throws JRException, FileNotFoundException, IOException {
+			Connection connection)
+			throws JRException, FileNotFoundException, IOException, DocumentException, SQLException {
 		replaceFont(jrxmlFilePath);
 		replaceFont(jrxmlFilePath);
 		processFields(jrxmlFilePath, otherParameters, connection);
 		processFields(jrxmlFilePath, otherParameters, connection);
 		JasperCompileManager.compileReportToFile(jrxmlFilePath, jasperFilePath);
 		JasperCompileManager.compileReportToFile(jrxmlFilePath, jasperFilePath);
@@ -338,8 +338,12 @@ public class PrintServiceImpl implements PrintService {
 	 * @param jrxmlFilePath
 	 * @param jrxmlFilePath
 	 * @param otherParameters
 	 * @param otherParameters
 	 * @param connection
 	 * @param connection
+	 * @throws IOException
+	 * @throws DocumentException
+	 * @throws SQLException
 	 */
 	 */
-	private void processFields(String jrxmlFilePath, String otherParameters, Connection connection) {
+	private void processFields(String jrxmlFilePath, String otherParameters, Connection connection)
+			throws IOException, DocumentException, SQLException {
 		XMLWriter xmlWriter = null;
 		XMLWriter xmlWriter = null;
 		try {
 		try {
 			SAXReader saxReader = new SAXReader();
 			SAXReader saxReader = new SAXReader();
@@ -359,7 +363,7 @@ public class PrintServiceImpl implements PrintService {
 			queryString = replaceOtherParameters(queryString, otherParameters);
 			queryString = replaceOtherParameters(queryString, otherParameters);
 			List<String> columnNames = getColumnNames(connection, queryString);
 			List<String> columnNames = getColumnNames(connection, queryString);
 			if (CollectionUtils.isEmpty(columnNames)) {
 			if (CollectionUtils.isEmpty(columnNames)) {
-				throw new ReportException("未查询到任何列:" + queryString);
+				throw new SQLException("未查询到任何列:" + queryString);
 			}
 			}
 			Set<String> usedFields = getUsedFields(jrxmlFilePath);
 			Set<String> usedFields = getUsedFields(jrxmlFilePath);
 			// 指定的field
 			// 指定的field
@@ -381,15 +385,9 @@ public class PrintServiceImpl implements PrintService {
 				xmlWriter.write(document);
 				xmlWriter.write(document);
 				xmlWriter.flush();
 				xmlWriter.flush();
 			}
 			}
-		} catch (DocumentException | SQLException | IOException e) {
-			throw new ReportException(e).setDetailedMessage(e);
 		} finally {
 		} finally {
 			if (xmlWriter != null) {
 			if (xmlWriter != null) {
-				try {
-					xmlWriter.close();
-				} catch (IOException e) {
-					throw new ReportException(e).setDetailedMessage(e);
-				}
+				xmlWriter.close();
 			}
 			}
 		}
 		}
 	}
 	}
@@ -627,10 +625,10 @@ public class PrintServiceImpl implements PrintService {
 
 
 	@Override
 	@Override
 	public boolean overload(String userName, String profile, String reportName, String whereCondition,
 	public boolean overload(String userName, String profile, String reportName, String whereCondition,
-			String otherParameters, Platform platform) {
+			String otherParameters, Platform platform) throws SQLException, IOException, DocumentException {
 		DataSource dataSource = MasterManager.getDataSource(userName, profile);
 		DataSource dataSource = MasterManager.getDataSource(userName, profile);
 		if (dataSource == null) {
 		if (dataSource == null) {
-			throw new ReportException("获取数据源失败");
+			throw new SQLException("获取数据源失败");
 		}
 		}
 		if (platform == null) {
 		if (platform == null) {
 			platform = Platform.PC;
 			platform = Platform.PC;
@@ -659,22 +657,16 @@ public class PrintServiceImpl implements PrintService {
 			// 报表模板不存在
 			// 报表模板不存在
 			if (!jrxmlFile.exists()) {
 			if (!jrxmlFile.exists()) {
 				// 替换windows下路径中的双反斜杠为单斜杠
 				// 替换windows下路径中的双反斜杠为单斜杠
-				throw new ReportException("未发现模板文件:" + jrxmlFilePath.replaceAll("\\\\", "/"));
+				throw new FileNotFoundException("未发现模板文件:" + jrxmlFilePath.replaceAll("\\\\", "/"));
 			}
 			}
 
 
 			// 因为子报表数据量较小,而且其参数来自主报表,无法简单地进行判断,所以不判断子报表是否过载
 			// 因为子报表数据量较小,而且其参数来自主报表,无法简单地进行判断,所以不判断子报表是否过载
 			int count = getCount(jrxmlFilePath, whereCondition, otherParameters, connection);
 			int count = getCount(jrxmlFilePath, whereCondition, otherParameters, connection);
 			logger.info("count... " + count);
 			logger.info("count... " + count);
 			return count >= maxRecordSize;
 			return count >= maxRecordSize;
-		} catch (Throwable e) {
-			throw new ReportException(e).setDetailedMessage(e);
 		} finally {
 		} finally {
 			if (connection != null) {
 			if (connection != null) {
-				try {
-					connection.close();
-				} catch (SQLException e) {
-					throw new ReportException(e).setDetailedMessage(e);
-				}
+				connection.close();
 			}
 			}
 		}
 		}
 	}
 	}
@@ -686,8 +678,12 @@ public class PrintServiceImpl implements PrintService {
 	 * @param whereCondition
 	 * @param whereCondition
 	 * @param otherParameters
 	 * @param otherParameters
 	 * @param connection
 	 * @param connection
+	 * @throws IOException
+	 * @throws SQLException
+	 * @throws DocumentException
 	 */
 	 */
-	private int getCount(String jrxmlFilePath, String whereCondition, String otherParameters, Connection connection) {
+	private int getCount(String jrxmlFilePath, String whereCondition, String otherParameters, Connection connection)
+			throws IOException, SQLException, DocumentException {
 		XMLWriter xmlWriter = null;
 		XMLWriter xmlWriter = null;
 		try {
 		try {
 			SAXReader saxReader = new SAXReader();
 			SAXReader saxReader = new SAXReader();
@@ -703,15 +699,9 @@ public class PrintServiceImpl implements PrintService {
 			}
 			}
 			queryString = replaceOtherParameters(queryString, otherParameters);
 			queryString = replaceOtherParameters(queryString, otherParameters);
 			return getCount(connection, queryString);
 			return getCount(connection, queryString);
-		} catch (DocumentException | SQLException e) {
-			throw new ReportException(e).setDetailedMessage(e);
 		} finally {
 		} finally {
 			if (xmlWriter != null) {
 			if (xmlWriter != null) {
-				try {
-					xmlWriter.close();
-				} catch (IOException e) {
-					throw new ReportException(e).setDetailedMessage(e);
-				}
+				xmlWriter.close();
 			}
 			}
 		}
 		}
 	}
 	}
@@ -727,7 +717,7 @@ public class PrintServiceImpl implements PrintService {
 		// 替换其他参数
 		// 替换其他参数
 		if (sql.contains("$P{")) {
 		if (sql.contains("$P{")) {
 			if (StringUtils.isEmpty(otherParameters)) {
 			if (StringUtils.isEmpty(otherParameters)) {
-				throw new ReportException("未传入动态参数");
+				throw new IllegalArgumentException("未传入动态参数");
 			}
 			}
 			JSONObject parameters = JSONObject.parseObject(otherParameters);
 			JSONObject parameters = JSONObject.parseObject(otherParameters);
 			Pattern pattern = Pattern.compile("\\$P\\{([^\\$]*)\\}");
 			Pattern pattern = Pattern.compile("\\$P\\{([^\\$]*)\\}");
@@ -737,7 +727,7 @@ public class PrintServiceImpl implements PrintService {
 				String parameterName = match.substring("$P{".length(), match.length() - 1);
 				String parameterName = match.substring("$P{".length(), match.length() - 1);
 				Object value = parameters.get(parameterName);
 				Object value = parameters.get(parameterName);
 				if (value == null) {
 				if (value == null) {
-					throw new ReportException("未传入动态参数:" + parameterName);
+					throw new IllegalArgumentException("未传入动态参数:" + parameterName);
 				}
 				}
 				// 如果不是数字,需以单引号括起来
 				// 如果不是数字,需以单引号括起来
 				if (value instanceof Number) {
 				if (value instanceof Number) {

+ 44 - 0
src/main/java/com/uas/report/util/ExceptionUtils.java

@@ -0,0 +1,44 @@
+package com.uas.report.util;
+
+/**
+ * 处理异常的工具类
+ * 
+ * @author sunyj
+ * @since 2017年8月10日 下午3:26:55
+ */
+public class ExceptionUtils {
+
+	/**
+	 * 获取异常及其Cause拼接成的字符串
+	 * 
+	 * @param e
+	 *            异常
+	 * @return 拼接后的结果
+	 */
+	public static String getMessage(Throwable e) {
+		StringBuilder sb = new StringBuilder(e.toString());
+		if (e.getCause() != null) {
+			sb.append("\nCaused by: ").append(getMessage(e.getCause()));
+		}
+		return sb.toString();
+	}
+
+	/**
+	 * 获取异常及其Cause的StackTrace拼接成的字符串
+	 * 
+	 * @param e
+	 *            异常
+	 * @return 拼接后的结果
+	 */
+	public static String getDetailedMessage(Throwable e) {
+		StringBuilder sb = new StringBuilder(e.toString());
+		StackTraceElement[] stackTraceElements = e.getStackTrace();
+		for (StackTraceElement stackTraceElement : stackTraceElements) {
+			sb.append("\n\t").append(stackTraceElement.toString());
+		}
+		if (e.getCause() != null) {
+			sb.append("\nCaused by: ").append(getDetailedMessage(e.getCause()));
+		}
+		return sb.toString();
+	}
+}

+ 16 - 21
src/main/java/com/uas/report/util/FileUtils.java

@@ -17,8 +17,6 @@ import java.nio.channels.WritableByteChannel;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 
 
-import com.uas.report.core.exception.ReportException;
-
 /**
 /**
  * 文件操作工具类
  * 文件操作工具类
  * 
  * 
@@ -36,8 +34,9 @@ public class FileUtils {
 	 *            文件路径
 	 *            文件路径
 	 * @param data
 	 * @param data
 	 *            数据
 	 *            数据
+	 * @throws IOException
 	 */
 	 */
-	public static void write(String filePath, byte[] data) {
+	public static void write(String filePath, byte[] data) throws IOException {
 		write(filePath, data, false);
 		write(filePath, data, false);
 	}
 	}
 
 
@@ -50,28 +49,25 @@ public class FileUtils {
 	 *            数据
 	 *            数据
 	 * @param allowNoData
 	 * @param allowNoData
 	 *            是否允许数据为空(文件无内容)
 	 *            是否允许数据为空(文件无内容)
+	 * @throws IOException
 	 */
 	 */
-	public static void write(String filePath, byte[] data, boolean allowNoData) {
+	public static void write(String filePath, byte[] data, boolean allowNoData) throws IOException {
 		if (StringUtils.isEmpty(filePath)) {
 		if (StringUtils.isEmpty(filePath)) {
-			throw new ReportException("参数不能为空:filePath");
+			throw new IllegalArgumentException("参数不能为空:filePath");
 		}
 		}
 		if (!allowNoData && ArrayUtils.isEmpty(data)) {
 		if (!allowNoData && ArrayUtils.isEmpty(data)) {
-			throw new ReportException("参数不能为空:data");
+			throw new IllegalArgumentException("参数不能为空:data");
 		}
 		}
 
 
 		File file = new File(filePath);
 		File file = new File(filePath);
 		if (!file.getParentFile().exists()) {
 		if (!file.getParentFile().exists()) {
 			file.getParentFile().mkdirs();
 			file.getParentFile().mkdirs();
 		}
 		}
-		try {
-			FileOutputStream fos = new FileOutputStream(file);
-			fos.write(data);
-			fos.flush();
-			logger.info("Writed... " + file.getPath());
-			fos.close();
-		} catch (IOException e) {
-			throw new ReportException(e).setDetailedMessage(e);
-		}
+		FileOutputStream fos = new FileOutputStream(file);
+		fos.write(data);
+		fos.flush();
+		logger.info("Writed... " + file.getPath());
+		fos.close();
 	}
 	}
 
 
 	/**
 	/**
@@ -277,13 +273,12 @@ public class FileUtils {
 	 * 检查文件夹
 	 * 检查文件夹
 	 * 
 	 * 
 	 * @param dir
 	 * @param dir
-	 * @throws FileNotFoundException
-	 *             文件夹不存在
+	 * @throws IOException
 	 */
 	 */
-	public static void checkDir(File dir) throws FileNotFoundException {
+	public static void checkDir(File dir) throws IOException {
 		checkFile(dir);
 		checkFile(dir);
 		if (dir.isFile()) {
 		if (dir.isFile()) {
-			throw new ReportException("路径并非文件夹:" + dir.getAbsolutePath());
+			throw new IOException("路径并非文件夹:" + dir.getAbsolutePath());
 		}
 		}
 	}
 	}
 
 
@@ -292,9 +287,9 @@ public class FileUtils {
 	 * 
 	 * 
 	 * @param dir
 	 * @param dir
 	 * @return
 	 * @return
-	 * @throws FileNotFoundException
+	 * @throws IOException
 	 */
 	 */
-	public static File initDir(File dir) throws FileNotFoundException {
+	public static File initDir(File dir) throws IOException {
 		if (!dir.exists()) {
 		if (!dir.exists()) {
 			dir.mkdirs();
 			dir.mkdirs();
 		}
 		}

+ 4 - 5
src/main/java/com/uas/report/util/MasterManager.java

@@ -18,7 +18,6 @@ import org.slf4j.LoggerFactory;
 import com.alibaba.druid.pool.DruidDataSource;
 import com.alibaba.druid.pool.DruidDataSource;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.uas.report.SpecialProperties;
 import com.uas.report.SpecialProperties;
-import com.uas.report.core.exception.ReportException;
 import com.uas.report.model.Master;
 import com.uas.report.model.Master;
 
 
 /**
 /**
@@ -68,8 +67,9 @@ public class MasterManager {
 	 * @param profile
 	 * @param profile
 	 *            用于识别B2B、B2C账套的环境(dev、test、prod)
 	 *            用于识别B2B、B2C账套的环境(dev、test、prod)
 	 * @return 数据源
 	 * @return 数据源
+	 * @throws SQLException
 	 */
 	 */
-	public static DataSource getDataSource(String userName, String profile) {
+	public static DataSource getDataSource(String userName, String profile) throws SQLException {
 		if (StringUtils.isEmpty(userName)) {
 		if (StringUtils.isEmpty(userName)) {
 			return null;
 			return null;
 		}
 		}
@@ -101,8 +101,9 @@ public class MasterManager {
 	 * @param mainMaster
 	 * @param mainMaster
 	 * @param userName
 	 * @param userName
 	 * @return
 	 * @return
+	 * @throws SQLException 
 	 */
 	 */
-	private static DruidDataSource getDataSourceFromMainMaster(DruidDataSource mainMaster, String userName) {
+	private static DruidDataSource getDataSourceFromMainMaster(DruidDataSource mainMaster, String userName) throws SQLException {
 		Connection connection = null;
 		Connection connection = null;
 		PreparedStatement preparedStatement = null;
 		PreparedStatement preparedStatement = null;
 		ResultSet resultSet = null;
 		ResultSet resultSet = null;
@@ -135,8 +136,6 @@ public class MasterManager {
 				result.setPassword(password);
 				result.setPassword(password);
 				return result;
 				return result;
 			}
 			}
-		} catch (Exception e) {
-			throw new ReportException(e).setDetailedMessage(e);
 		} finally {
 		} finally {
 			if (resultSet != null) {
 			if (resultSet != null) {
 				try {
 				try {

+ 2 - 3
src/main/java/com/uas/report/util/ReportUtils.java

@@ -1,7 +1,6 @@
 package com.uas.report.util;
 package com.uas.report.util;
 
 
 import com.uas.report.SystemProperties;
 import com.uas.report.SystemProperties;
-import com.uas.report.core.exception.ReportException;
 import com.uas.report.schedule.service.TaskService;
 import com.uas.report.schedule.service.TaskService;
 import com.uas.report.service.FileService;
 import com.uas.report.service.FileService;
 
 
@@ -22,10 +21,10 @@ public class ReportUtils {
 	 */
 	 */
 	public static void checkParameters(String userName, String reportName) {
 	public static void checkParameters(String userName, String reportName) {
 		if (StringUtils.isEmpty(userName)) {
 		if (StringUtils.isEmpty(userName)) {
-			throw new ReportException("未传入当前账套名称!");
+			throw new IllegalArgumentException("未传入当前账套名称!");
 		}
 		}
 		if (StringUtils.isEmpty(reportName)) {
 		if (StringUtils.isEmpty(reportName)) {
-			throw new ReportException("未传入报表名称!");
+			throw new IllegalArgumentException("未传入报表名称!");
 		}
 		}
 	}
 	}
 
 

+ 7 - 8
src/main/java/com/uas/report/util/ZipUtils.java

@@ -5,6 +5,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.File;
 import java.io.FileFilter;
 import java.io.FileFilter;
 import java.io.FileInputStream;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStream;
@@ -18,8 +19,6 @@ import java.util.zip.ZipOutputStream;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 
 
-import com.uas.report.core.exception.ReportException;
-
 /**
 /**
  * 压缩工具类
  * 压缩工具类
  * 
  * 
@@ -46,11 +45,11 @@ public class ZipUtils {
 		}
 		}
 		File folder = new File(sourceFolderPath);
 		File folder = new File(sourceFolderPath);
 		if (!folder.exists() || !folder.isDirectory()) {
 		if (!folder.exists() || !folder.isDirectory()) {
-			throw new ReportException("路径不存在或并非文件夹:" + sourceFolderPath);
+			throw new IOException("路径不存在或并非文件夹:" + sourceFolderPath);
 		}
 		}
 		File[] files = folder.listFiles();
 		File[] files = folder.listFiles();
 		if (files.length < 0) {
 		if (files.length < 0) {
-			throw new ReportException("空文件夹:" + sourceFolderPath);
+			throw new IOException("空文件夹:" + sourceFolderPath);
 		}
 		}
 
 
 		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
 		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@@ -82,11 +81,11 @@ public class ZipUtils {
 		}
 		}
 		File folder = new File(sourceFolderPath);
 		File folder = new File(sourceFolderPath);
 		if (!folder.exists() || !folder.isDirectory()) {
 		if (!folder.exists() || !folder.isDirectory()) {
-			throw new ReportException("路径不存在或并非文件夹:" + sourceFolderPath);
+			throw new IOException("路径不存在或并非文件夹:" + sourceFolderPath);
 		}
 		}
 		File[] files = folder.listFiles();
 		File[] files = folder.listFiles();
 		if (files.length < 0) {
 		if (files.length < 0) {
-			throw new ReportException("空文件夹:" + sourceFolderPath);
+			throw new IOException("空文件夹:" + sourceFolderPath);
 		}
 		}
 
 
 		ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipFilePath));
 		ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipFilePath));
@@ -183,7 +182,7 @@ public class ZipUtils {
 		}
 		}
 		File file = new File(zipFilePath);
 		File file = new File(zipFilePath);
 		if (!file.exists()) {
 		if (!file.exists()) {
-			throw new ReportException("压缩包不存在:" + zipFilePath);
+			throw new FileNotFoundException("压缩包不存在:" + zipFilePath);
 		}
 		}
 
 
 		File folder = new File(folderPath);
 		File folder = new File(folderPath);
@@ -191,7 +190,7 @@ public class ZipUtils {
 			folder.mkdirs();
 			folder.mkdirs();
 		}
 		}
 		if (!folder.isDirectory()) {
 		if (!folder.isDirectory()) {
-			throw new ReportException("并非文件夹:" + folderPath);
+			throw new IOException("并非文件夹:" + folderPath);
 		}
 		}
 
 
 		ZipFile zipFile = new ZipFile(file);
 		ZipFile zipFile = new ZipFile(file);