Browse Source

pdfPath接口直接返回pdf数据,而不是pdf路径

sunyj 8 years ago
parent
commit
b3931fd236

+ 45 - 39
src/main/java/com/uas/report/axis/repository/RepositoryManagementServiceImpl.java

@@ -67,7 +67,7 @@ public class RepositoryManagementServiceImpl implements RepositoryManagementServ
 
 	private ReloadableResourceBundleMessageSource messageSource;
 
-	private String attachmentsPath = specialProperties.getLocalBaseDir() + "/tmp/jasperserver/axis_attachments";
+	// private String attachmentsPath;
 
 	private Logger logger = LoggerFactory.getLogger(getClass());
 
@@ -78,6 +78,8 @@ public class RepositoryManagementServiceImpl implements RepositoryManagementServ
 		messageSource.setUseCodeAsDefaultMessage(true);
 		messageSource.setFallbackToSystemLocale(false);
 		messageSource.setBasenames("bundlePathsListCe");
+		// attachmentsPath = specialProperties.getLocalBaseDir() +
+		// "/tmp/jasperserver/axis_attachments";
 	}
 
 	@Override
@@ -362,46 +364,50 @@ public class RepositoryManagementServiceImpl implements RepositoryManagementServ
 
 	/**
 	 * Function to get attachments from an Axis message
-	 * @throws WSException 
-	 * @throws NoSuchMessageException 
-	 * @throws AxisFault 
+	 * 
+	 * @throws WSException
+	 * @throws NoSuchMessageException
+	 * @throws AxisFault
 	 *
 	 */
-	public AttachmentPart[] getMessageAttachments() throws NoSuchMessageException, WSException, AxisFault {
-		try {
-			MessageContext msgContext = MessageContext.getCurrentContext();
-			File file = new File(attachmentsPath);
-			if (!file.exists()) {
-				file.mkdirs();
-			}
-			msgContext.setProperty(MessageContext.ATTACHMENTS_DIR, attachmentsPath);
-			Message reqMsg = msgContext.getRequestMessage();
-			Attachments messageAttachments = reqMsg.getAttachmentsImpl();
-			if (null == messageAttachments) {
-				logger.error("no attachment support");
-				return new AttachmentPart[0];
-			}
-			int attachmentCount = messageAttachments.getAttachmentCount();
-			AttachmentPart attachments[] = new AttachmentPart[attachmentCount];
-
-			Iterator<?> it = messageAttachments.getAttachments().iterator();
-			int count = 0;
-			while (it.hasNext()) {
-				AttachmentPart part = (AttachmentPart) it.next();
-				attachments[count++] = part;
-			}
-			return attachments;
-		} catch (AxisFault e) {
-			if (e.getFaultString().startsWith("java.io.IOException")) {
-//				throw new JSExceptionWrapper(new WSException(WSException.GENERAL_ERROR,
-//						messageSource.getMessage("webservices.error.attachments.folder", null, getLocale())));
-				throw new WSException(WSException.GENERAL_ERROR,
-						messageSource.getMessage("webservices.error.attachments.folder", null, getLocale()));
-			}
-//			throw new JSExceptionWrapper(e);
-			throw e;
-		}
-	}
+	// public AttachmentPart[] getMessageAttachments() throws
+	// NoSuchMessageException, WSException, AxisFault {
+	// try {
+	// MessageContext msgContext = MessageContext.getCurrentContext();
+	// File file = new File(attachmentsPath);
+	// if (!file.exists()) {
+	// file.mkdirs();
+	// }
+	// msgContext.setProperty(MessageContext.ATTACHMENTS_DIR, attachmentsPath);
+	// Message reqMsg = msgContext.getRequestMessage();
+	// Attachments messageAttachments = reqMsg.getAttachmentsImpl();
+	// if (null == messageAttachments) {
+	// logger.error("no attachment support");
+	// return new AttachmentPart[0];
+	// }
+	// int attachmentCount = messageAttachments.getAttachmentCount();
+	// AttachmentPart attachments[] = new AttachmentPart[attachmentCount];
+	//
+	// Iterator<?> it = messageAttachments.getAttachments().iterator();
+	// int count = 0;
+	// while (it.hasNext()) {
+	// AttachmentPart part = (AttachmentPart) it.next();
+	// attachments[count++] = part;
+	// }
+	// return attachments;
+	// } catch (AxisFault e) {
+	// if (e.getFaultString().startsWith("java.io.IOException")) {
+	//// throw new JSExceptionWrapper(new WSException(WSException.GENERAL_ERROR,
+	//// messageSource.getMessage("webservices.error.attachments.folder", null,
+	// getLocale())));
+	// throw new WSException(WSException.GENERAL_ERROR,
+	// messageSource.getMessage("webservices.error.attachments.folder", null,
+	// getLocale()));
+	// }
+	//// throw new JSExceptionWrapper(e);
+	// throw e;
+	// }
+	// }
 
 	public Locale getLocale() {
 		return locale;

+ 16 - 26
src/main/java/com/uas/report/controller/PrintController.java

@@ -277,7 +277,7 @@ public class PrintController {
 	}
 
 	/**
-	 * 获取pdf路径
+	 * 获取pdf数据(该接口暂时供手机端访问)
 	 * 
 	 * @param userName
 	 *            不为null;当前账套名称
@@ -292,41 +292,31 @@ public class PrintController {
 	 *            JSON格式,数据为键值对
 	 * @param request
 	 * @param response
-	 * @return 包括pageSize、pdfPath(或overload)
+	 * @return 包括pageSize、data(或overload)
 	 */
-	@RequestMapping(value = "/pdfPath")
+	@RequestMapping(value = "/pdfData")
 	@ResponseBody
 	public Map<String, Object> getPdfPath(final String userName, final String profile, final String reportName,
 			final String whereCondition, final String otherParameters, HttpServletRequest request,
 			HttpServletResponse response) {
 		ReportUtils.checkParameters(userName, reportName);
-		Map<String, Object> result = new HashMap<>();
 
-		// pdf相对路径
-		String pdfPath = ReportConstants.GENERATED_FILES_PATH + reportName + "/"
-				+ fileService.generateFileName(userName, profile, reportName, whereCondition, otherParameters,
-						ReportConstants.PDF_FILE_TYPE)
-				+ "." + ReportConstants.PDF_FILE_TYPE;
-		final File file = new File(ReportConstants.GENERATED_FILES_DIR + pdfPath);
-		// 创建pdf文件
-		// 需要生成第一页,再生成总的pdf(可能页数过多,此时不再生成总的pdf)
-		Integer pageSize = printService.createPdfFile(userName, profile, reportName, whereCondition, otherParameters,
-				file.getPath().replace("." + ReportConstants.PDF_FILE_TYPE, "_1." + ReportConstants.PDF_FILE_TYPE), 1);
-		result.put("pageSize", pageSize);
+		// 通过预览第一页,获取总页数
+		// TODO 需重写判断页数的方法
+		Map<String, Object> result = printService.preview(userName, profile, reportName, whereCondition,
+				otherParameters, 1);
+		Integer pageSize = null;
+		if (result != null && result.containsKey("data") && result.containsKey("pageSize")) {
+			pageSize = (Integer) result.remove("pageSize");
+		}
+		if (pageSize == null) {
+			throw new ReportException("获取预览数据失败");
+		}
 		if (pageSize > MAX_PAGE_SIZE) {
+			result = new HashMap<>();
 			result.put("overload", "true");
 		} else {
-			result.put("pdfPath", pdfPath);
-			// 生成总的pdf
-			printService.createPdfFile(userName, profile, reportName, whereCondition, otherParameters, file.getPath(),
-					null);
-			// 再开线程生成后面页的pdf
-			new Thread(new Runnable() {
-				@Override
-				public void run() {
-					fileService.createPagedPdfFiles(file.getPath());
-				}
-			}).start();
+			result = printService.preview(userName, profile, reportName, whereCondition, otherParameters, null);
 		}
 		return result;
 	}