Explorar el Código

must preprint before print

sunyj hace 7 años
padre
commit
f6acc6360c

+ 28 - 0
report-common/src/main/java/com/uas/report/util/Assert.java

@@ -0,0 +1,28 @@
+package com.uas.report.util;
+
+/**
+ * 断言
+ *
+ * @author sunyj
+ * @since 2018/1/17 10:23
+ */
+public class Assert {
+
+    public static void hasText(String text, String message) {
+        if (!StringUtils.hasText(text)) {
+            throw new IllegalArgumentException(message);
+        }
+    }
+
+    public static void notNull(Object object, String message) {
+        if (object == null) {
+            throw new IllegalArgumentException(message);
+        }
+    }
+
+    public static void notEmpty(Object object, String message) {
+        if (ObjectUtils.isEmpty(object)) {
+            throw new IllegalArgumentException(message);
+        }
+    }
+}

+ 86 - 0
report-common/src/main/java/com/uas/report/util/ObjectUtils.java

@@ -0,0 +1,86 @@
+package com.uas.report.util;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * 对象工具类
+ *
+ * @author sunyj
+ * @since 2017年9月1日 下午3:54:26
+ */
+public class ObjectUtils {
+
+    /**
+     * 判断是否为 null、空数组、空串或者空集合
+     *
+     * @param obj 对象
+     * @return 是否为 null、空数组、空串或者空集合
+     */
+    public static boolean isEmpty(Object obj) {
+        if (obj == null) {
+            return true;
+        }
+        if (obj.getClass().isArray()) {
+            if (obj instanceof long[]) {
+                return ArrayUtils.isEmpty((long[]) obj);
+            } else if (obj instanceof int[]) {
+                return ArrayUtils.isEmpty((int[]) obj);
+            } else if (obj instanceof short[]) {
+                return ArrayUtils.isEmpty((short[]) obj);
+            } else if (obj instanceof byte[]) {
+                return ArrayUtils.isEmpty((byte[]) obj);
+            } else if (obj instanceof char[]) {
+                return ArrayUtils.isEmpty((char[]) obj);
+            } else if (obj instanceof boolean[]) {
+                return ArrayUtils.isEmpty((boolean[]) obj);
+            } else if (obj instanceof float[]) {
+                return ArrayUtils.isEmpty((float[]) obj);
+            } else if (obj instanceof double[]) {
+                return ArrayUtils.isEmpty((double[]) obj);
+            }
+            return ArrayUtils.isEmpty((Object[]) obj);
+        }
+        return (obj instanceof String && StringUtils.isEmpty(obj))
+                || (obj instanceof Collection && CollectionUtils.isEmpty((Collection<?>) obj))
+                || (obj instanceof Map && CollectionUtils.isEmpty((Map<?, ?>) obj));
+    }
+
+    /**
+     * 将对象转为 String
+     *
+     * @param obj 对象
+     * @return 转换的 String
+     */
+    public static String toString(Object obj) {
+        if (obj == null) {
+            return "";
+        }
+        if (obj instanceof String) {
+            return (String) obj;
+        }
+        if (obj.getClass().isArray()) {
+            if (obj instanceof long[]) {
+                return Arrays.toString((long[]) obj);
+            } else if (obj instanceof int[]) {
+                return Arrays.toString((int[]) obj);
+            } else if (obj instanceof short[]) {
+                return Arrays.toString((short[]) obj);
+            } else if (obj instanceof byte[]) {
+                return Arrays.toString((byte[]) obj);
+            } else if (obj instanceof char[]) {
+                return Arrays.toString((char[]) obj);
+            } else if (obj instanceof boolean[]) {
+                return Arrays.toString((boolean[]) obj);
+            } else if (obj instanceof float[]) {
+                return Arrays.toString((float[]) obj);
+            } else if (obj instanceof double[]) {
+                return Arrays.toString((double[]) obj);
+            }
+            return Arrays.toString((Object[]) obj);
+        }
+        return obj.toString();
+    }
+
+}

+ 83 - 3
report-common/src/main/java/com/uas/report/util/StringUtils.java

@@ -6,7 +6,87 @@ package com.uas.report.util;
  */
 public class StringUtils {
 
-	public static boolean isEmpty(Object str) {
-		return (str == null || "".equals(str));
-	}
+    public static boolean isEmpty(Object str) {
+        return (str == null || !hasText(str.toString()));
+    }
+
+    /**
+     * Check that the given {@code CharSequence} is neither {@code null} nor
+     * of length 0.
+     * <p>Note: this method returns {@code true} for a {@code CharSequence}
+     * that purely consists of whitespace.
+     * <p><pre class="code">
+     * StringUtils.hasLength(null) = false
+     * StringUtils.hasLength("") = false
+     * StringUtils.hasLength(" ") = true
+     * StringUtils.hasLength("Hello") = true
+     * </pre>
+     *
+     * @param str the {@code CharSequence} to check (may be {@code null})
+     * @return {@code true} if the {@code CharSequence} is not {@code null} and has length
+     * @see #hasText(String)
+     */
+    public static boolean hasLength(CharSequence str) {
+        return (str != null && str.length() > 0);
+    }
+
+    /**
+     * Check that the given {@code String} is neither {@code null} nor of length 0.
+     * <p>Note: this method returns {@code true} for a {@code String} that
+     * purely consists of whitespace.
+     *
+     * @param str the {@code String} to check (may be {@code null})
+     * @return {@code true} if the {@code String} is not {@code null} and has length
+     * @see #hasLength(CharSequence)
+     * @see #hasText(String)
+     */
+    public static boolean hasLength(String str) {
+        return hasLength((CharSequence) str);
+    }
+
+    /**
+     * Check whether the given {@code CharSequence} contains actual <em>text</em>.
+     * <p>More specifically, this method returns {@code true} if the
+     * {@code CharSequence} is not {@code null}, its length is greater than
+     * 0, and it contains at least one non-whitespace character.
+     * <p><pre class="code">
+     * StringUtils.hasText(null) = false
+     * StringUtils.hasText("") = false
+     * StringUtils.hasText(" ") = false
+     * StringUtils.hasText("12345") = true
+     * StringUtils.hasText(" 12345 ") = true
+     * </pre>
+     *
+     * @param str the {@code CharSequence} to check (may be {@code null})
+     * @return {@code true} if the {@code CharSequence} is not {@code null},
+     * its length is greater than 0, and it does not contain whitespace only
+     * @see Character#isWhitespace
+     */
+    public static boolean hasText(CharSequence str) {
+        if (!hasLength(str)) {
+            return false;
+        }
+        int strLen = str.length();
+        for (int i = 0; i < strLen; i++) {
+            if (!Character.isWhitespace(str.charAt(i))) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Check whether the given {@code String} contains actual <em>text</em>.
+     * <p>More specifically, this method returns {@code true} if the
+     * {@code String} is not {@code null}, its length is greater than 0,
+     * and it contains at least one non-whitespace character.
+     *
+     * @param str the {@code String} to check (may be {@code null})
+     * @return {@code true} if the {@code String} is not {@code null}, its
+     * length is greater than 0, and it does not contain whitespace only
+     * @see #hasText(CharSequence)
+     */
+    public static boolean hasText(String str) {
+        return hasText((CharSequence) str);
+    }
 }

+ 123 - 103
report/src/main/java/com/uas/report/controller/PrintController.java

@@ -3,9 +3,11 @@ package com.uas.report.controller;
 import com.uas.report.SystemProperties;
 import com.uas.report.model.ExportType;
 import com.uas.report.model.Platform;
+import com.uas.report.model.PrintParameter;
 import com.uas.report.model.PrintType;
 import com.uas.report.service.FileService;
 import com.uas.report.service.PrintService;
+import com.uas.report.util.Assert;
 import com.uas.report.util.ReportUtils;
 import com.uas.report.util.StringUtils;
 import net.sf.jasperreports.engine.JRException;
@@ -13,6 +15,7 @@ import org.dom4j.DocumentException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 import javax.servlet.ServletException;
@@ -23,6 +26,9 @@ import java.io.IOException;
 import java.sql.SQLException;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 /**
  * 报表打印
@@ -47,108 +53,130 @@ public class PrintController {
 	@Autowired
 	private PdfController pdfController;
 
+    /**
+     * 缓存的打印参数
+     */
+	private ConcurrentMap<String, PrintParameter> printParameters = new ConcurrentHashMap<>();
+
+    /**
+     * 预打印,用于缓存参数,以便之后通过 GET 方式调用打印接口(GET 下参数不能过长)
+     *
+     * @param userName        不为null;当前账套名称
+     * @param profile         可选(UAS等系统不必传递该参数),用于标识请求源(B2C、B2B)是正式、测试还是开发版本:prod、test、dev
+     * @param reportName      不为null;需要导出的报表的名称,不带任何后缀(如导出采购单,即为"Purchase")
+     * @param whereCondition  可为null;where之后的条件(包括where)
+     * @param otherParameters 若模板已指定需要的参数,则不可为null;其他参数,区别于whereCondition,报表某些字段的值取决于这些参数;
+     *                        JSON格式,数据为键值对
+     * @param printType       打印类型,可为PREVIEW_PRINT_TYPE、PRINT_PRINT_TYPE、PDF_PRINT_TYPE、
+     *                        EXCEL_PRINT_TYPE
+     * @param title           导出为文件时的名称
+     * @param request
+     * @param response
+     * @return 本次请求的 id
+     * @throws SQLException
+     * @throws DocumentException
+     * @throws IOException
+     * @throws JRException
+     * @throws ServletException
+     */
+    @RequestMapping(value = "/pre")
+    @ResponseBody
+    public String preprint(String userName, String profile, String reportName, String whereCondition, String otherParameters,
+                           String printType, String title, HttpServletRequest request, HttpServletResponse response)
+            throws JRException, IOException, DocumentException, SQLException, ServletException {
+        userName = userName == null ? null : userName.toUpperCase();
+        // printType为空,默认进入预览页
+        PrintType type = StringUtils.isEmpty(printType) ? PrintType.PREVIEW : PrintType.checkType(printType);
+        String requestId = UUID.randomUUID().toString().replace("-", "");
+        printParameters.put(requestId, new PrintParameter(userName, profile, reportName, whereCondition, otherParameters, type, title));
+        return requestId;
+    }
+
+    /**
+     * 获取缓存的打印参数
+     *
+     * @param id       预打印时获取的 id
+     * @param request
+     * @param response
+     * @return 缓存的打印参数
+     */
+    @RequestMapping("/parameter")
+    @ResponseBody
+    public PrintParameter getPrintParameter(@RequestParam String id, HttpServletRequest request, HttpServletResponse response) {
+        PrintParameter printParameter = printParameters.get(id);
+        Assert.notNull(printParameter, "id 不存在");
+        return printParameter;
+    }
+
 	/**
 	 * 为UAS系统打印提供服务, 根据printType进行预览、打印、下载pdf、下载纯数据excel等操作
 	 *
-	 * @param userName
-	 *            不为null;当前账套名称
-	 * @param profile
-	 *            可选(UAS等系统不必传递该参数),用于标识请求源(B2C、B2B)是正式、测试还是开发版本:prod、test、dev
-	 * @param reportName
-	 *            不为null;需要导出的报表的名称,不带任何后缀(如导出采购单,即为"Purchase")
-	 * @param whereCondition
-	 *            可为null;where之后的条件(包括where)
-	 * @param otherParameters
-	 *            若模板已指定需要的参数,则不可为null;其他参数,区别于whereCondition,报表某些字段的值取决于这些参数;
-	 *            JSON格式,数据为键值对
-	 * @param printType
-	 *            打印类型,可为PREVIEW_PRINT_TYPE、PRINT_PRINT_TYPE、PDF_PRINT_TYPE、
-	 *            EXCEL_PRINT_TYPE
-	 * @param title
-	 *            导出为文件时的名称
-	 * @param request
-	 * @param response
-	 * @throws SQLException
+     * @param id 预打印时获取的 id
+     * @param request
+     * @param response
+     * @throws SQLException
 	 * @throws DocumentException
 	 * @throws IOException
 	 * @throws JRException
-	 * @throws ServletException
+     * @throws ServletException
 	 */
-	@RequestMapping()
-	public void print(String userName, String profile, String reportName, String whereCondition, String otherParameters,
-			String printType, String title, HttpServletRequest request, HttpServletResponse response)
+	@RequestMapping
+	public void print(@RequestParam String id, HttpServletRequest request, HttpServletResponse response)
 			throws JRException, IOException, DocumentException, SQLException, ServletException {
-		userName = userName == null ? null : userName.toUpperCase();
-		// printType为空,默认进入预览页
-		PrintType type = StringUtils.isEmpty(printType) ? PrintType.PREVIEW : PrintType.checkType(printType);
-
-		switch (type) {
+        switch (getPrintParameter(id, request, response).getPrintType()) {
 		// 预览或打印
 		case PREVIEW:
 		case PRINT:
-			request.getRequestDispatcher("preview").forward(request, response);
+            request.getRequestDispatcher("preview").forward(request, response);
 			break;
 		case PDF:
-			export(userName, profile, reportName, whereCondition, otherParameters, ExportType.PDF.name(), true, title,
-					request, response);
+			export(id, ExportType.PDF.name(), true, request, response);
 			break;
 		// 该下载接口供 UAS 系统使用,应其要求,printType 为{@link PrintType.EXCEL}时,下载纯数据的 excel
 		case EXCEL:
 			if (systemProperties.isUseXlsx()) {
-				export(userName, profile, reportName, whereCondition, otherParameters, ExportType.XLSX_DATA.name(),
-						true, title, request, response);
+				export(id, ExportType.XLSX_DATA.name(), true, request, response);
 			} else {
-				export(userName, profile, reportName, whereCondition, otherParameters, ExportType.XLS_DATA.name(), true,
-						title, request, response);
+				export(id, ExportType.XLS_DATA.name(), true, request, response);
 			}
 			break;
 		case WORD:
-			export(userName, profile, reportName, whereCondition, otherParameters, ExportType.DOC.name(), true, title,
-					request, response);
+			export(id, ExportType.DOC.name(), true, request, response);
 			break;
 		case TEXT:
-			export(userName, profile, reportName, whereCondition, otherParameters, ExportType.TXT.name(), true, title,
-					request, response);
+			export(id, ExportType.TXT.name(), true, request, response);
 			break;
 		}
 	}
 
-	/**
-	 * 导出报表
-	 *
-	 * @param userName
-	 *            不为null;当前账套名称
-	 * @param profile
-	 *            可选(UAS等系统不必传递该参数),用于标识请求源(B2C、B2B)是正式、测试还是开发版本:prod、test、dev
-	 * @param reportName
-	 *            不为null;需要导出的报表的名称,不带任何后缀(如导出采购单,即为"Purchase")
-	 * @param whereCondition
-	 *            可为null;where之后的条件(包括where)
-	 * @param otherParameters
-	 *            若模板已指定需要的参数,则不可为null;其他参数,区别于whereCondition,报表某些字段的值取决于这些参数;
-	 *            JSON格式,数据为键值对
-	 * @param exportFileType
-	 *            报表导出的格式,默认为pdf
-	 * @param flush
-	 *            是否强制刷新pdf、xls
-	 * @param title
-	 *            导出为文件时的名称
-	 * @param request
-	 * @param response
-	 * @throws SQLException
-	 * @throws DocumentException
-	 * @throws IOException
-	 * @throws JRException
-	 */
-	@RequestMapping("/export")
-	@ResponseBody
-	public void export(String userName, String profile, String reportName, String whereCondition,
-			String otherParameters, String exportFileType, Boolean flush, String title, HttpServletRequest request,
+    /**
+     * 导出报表
+     *
+     * @param id             预打印时获取的 id
+     * @param exportFileType 报表导出的格式,默认为pdf
+     * @param flush          是否强制刷新pdf、xls
+     * @param request
+     * @param response
+     * @throws SQLException
+     * @throws DocumentException
+     * @throws IOException
+     * @throws JRException
+     */
+    @RequestMapping("/export")
+    @ResponseBody
+    public void export(@RequestParam String id, String exportFileType, Boolean flush, HttpServletRequest request,
 			HttpServletResponse response) throws JRException, IOException, DocumentException, SQLException {
 		// TODO show download process
-		userName = userName == null ? null : userName.toUpperCase();
-		ReportUtils.checkParameters(userName, reportName);
-		String masterOfJrxml = printService.getMasterOfJrxml(userName, reportName);
+        PrintParameter printParameter = getPrintParameter(id, request, response);
+        String userName = printParameter.getUserName();
+        String profile = printParameter.getProfile();
+        String reportName = printParameter.getReportName();
+        String whereCondition = printParameter.getWhereCondition();
+        String otherParameters = printParameter.getOtherParameters();
+        String title = printParameter.getTitle();
+        ReportUtils.checkParameters(userName, reportName);
+
+        String masterOfJrxml = printService.getMasterOfJrxml(userName, reportName);
 		ExportType exportType = StringUtils.isEmpty(exportFileType) ? ExportType.PDF
 				: ExportType.checkType(exportFileType);
 
@@ -170,39 +198,31 @@ public class PrintController {
 		fileService.rangeDownload(file, exportFileName, request, response);
 	}
 
-	/**
-	 * 报表预览时获取pdf相对路径
-	 *
-	 * @param userName
-	 *            不为null;当前账套名称
-	 * @param profile
-	 *            可选(UAS等系统不必传递该参数),用于标识请求源(B2C、B2B)是正式、测试还是开发版本:prod、test、dev
-	 * @param reportName
-	 *            不为null;需要预览的报表的名称,不带任何后缀(如预览采购单,即为"Purchase")
-	 * @param whereCondition
-	 *            可为null;where之后的条件(包括where)
-	 * @param otherParameters
-	 *            若模板已指定需要的参数,则不可为null;其他参数,区别于whereCondition,报表某些字段的值取决于这些参数;
-	 *            JSON格式,数据为键值对
-	 * @param flush
-	 *            是否强制刷新pdf、xls
-	 * @param request
-	 * @param response
-	 * @return pdf相对路径
-	 * @throws SQLException
-	 * @throws DocumentException
-	 * @throws IOException
-	 * @throws JRException
-	 */
-	@RequestMapping(value = "/pdfPath")
+    /**
+     * 报表预览时获取pdf相对路径
+     *
+     * @param id       预打印时获取的 id
+     * @param flush    是否强制刷新pdf、xls
+     * @param request
+     * @param response
+     * @return pdf相对路径
+     * @throws SQLException
+     * @throws DocumentException
+     * @throws IOException
+     * @throws JRException
+     */
+    @RequestMapping(value = "/pdfPath")
 	@ResponseBody
-	public String getPdfPath(String userName, final String profile, final String reportName,
-			final String whereCondition, final String otherParameters, Boolean flush, HttpServletRequest request,
-			HttpServletResponse response) throws JRException, IOException, DocumentException, SQLException {
-		userName = userName == null ? null : userName.toUpperCase();
+	public String getPdfPath(@RequestParam String id, Boolean flush, HttpServletRequest request, HttpServletResponse response) throws JRException, IOException, DocumentException, SQLException {
+        PrintParameter printParameter = getPrintParameter(id, request, response);
+        String userName = printParameter.getUserName();
+        String profile = printParameter.getProfile();
+        String reportName = printParameter.getReportName();
+        String whereCondition = printParameter.getWhereCondition();
+        String otherParameters = printParameter.getOtherParameters();
 		ReportUtils.checkParameters(userName, reportName);
-		String masterOfJrxml = printService.getMasterOfJrxml(userName, reportName);
 
+		String masterOfJrxml = printService.getMasterOfJrxml(userName, reportName);
         String pdfPath = reportName + "/"
                 + fileService.generateFileName(userName, profile, whereCondition, otherParameters, ExportType.PDF.getQualifier())
                 + "." + ExportType.PDF.getQualifier();

+ 83 - 0
report/src/main/java/com/uas/report/model/PrintParameter.java

@@ -0,0 +1,83 @@
+package com.uas.report.model;
+
+/**
+ * 打印参数
+ *
+ * @author sunyj
+ * @since 2018/1/23 14:13
+ */
+public class PrintParameter {
+
+    /**
+     * 当前账套名称
+     */
+    private String userName;
+
+    /**
+     * 用于标识请求源(B2C、B2B)是正式、测试还是开发版本:prod、test、dev(UAS等系统不必传递该参数)
+     */
+    private String profile;
+
+    /**
+     * 需要导出的报表的名称,不带任何后缀(如导出采购单,即为"Purchase")
+     */
+    private String reportName;
+
+    /**
+     * where 之后的条件(包括 where)
+     */
+    private String whereCondition;
+
+    /**
+     * 其他参数,区别于 whereCondition,报表某些字段的值取决于这些参数;JSON格式,数据为键值对
+     */
+    private String otherParameters;
+
+    /**
+     * 打印类型,可为 PREVIEW_PRINT_TYPE, PRINT_PRINT_TYPE, PDF_PRINT_TYPE, EXCEL_PRINT_TYPE
+     */
+    private PrintType printType;
+
+    /**
+     * 导出为文件时的名称
+     */
+    private String title;
+
+    public PrintParameter(String userName, String profile, String reportName, String whereCondition, String otherParameters, PrintType printType, String title) {
+        this.userName = userName;
+        this.profile = profile;
+        this.reportName = reportName;
+        this.whereCondition = whereCondition;
+        this.otherParameters = otherParameters;
+        this.printType = printType;
+        this.title = title;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public String getProfile() {
+        return profile;
+    }
+
+    public String getReportName() {
+        return reportName;
+    }
+
+    public String getWhereCondition() {
+        return whereCondition;
+    }
+
+    public String getOtherParameters() {
+        return otherParameters;
+    }
+
+    public PrintType getPrintType() {
+        return printType;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+}

+ 5 - 8
report/src/main/java/com/uas/report/util/ReportUtils.java

@@ -6,26 +6,23 @@ import com.uas.report.service.FileService;
 
 /**
  * 工具类
- * 
+ *
  * @author sunyj
  * @since 2016年11月2日 下午2:51:24
  */
 public class ReportUtils {
+
 	/**
 	 * 检查userName、reportName参数是否有效,无效则抛出异常
-	 * 
+	 *
 	 * @param userName
 	 *            账套名
 	 * @param reportName
 	 *            报表名
 	 */
 	public static void checkParameters(String userName, String reportName) {
-		if (StringUtils.isEmpty(userName)) {
-			throw new IllegalArgumentException("未传入当前账套名称!");
-		}
-		if (StringUtils.isEmpty(reportName)) {
-			throw new IllegalArgumentException("未传入报表名称!");
-		}
+        Assert.hasText(userName, "未传入当前账套名称!");
+        Assert.hasText(reportName, "未传入报表名称!");
 	}
 
 	/**

+ 10 - 9
report/src/main/webapp/WEB-INF/views/console.html

@@ -12,20 +12,21 @@
 			<ol>
 				<strong><li class="title1">预览</li></strong>
 				<ol>
-					<li><a target="_blank">print?userName=UAS&reportName=Purchase&whereCondition=where rownum<10&otherParameters={'id':1}&printType=PREVIEW&title=采购单123</a></li>
-					<li><a target="_blank">preview?userName=UAS_TEST&reportName=Purchase&whereCondition=where rownum<11&printType=PREVIEW&title=采购单123</a></li>
+					<li><a target="_blank">print/pre?userName=UAS&profile=test&reportName=PURCLIST&whereCondition=where%20rownum<30</a></li>
+                    <li><a target="_blank">print?id=81a7854cd907438f98968a3e2d0024d6</a></li>
+					<li><a target="_blank">preview?id=81a7854cd907438f98968a3e2d0024d6</a></li>
 				</ol>
 
 				<strong><li class="title1">打印</li></strong>
 				<ol>
-					<li><a target="_blank">print?userName=UAS_TEST&reportName=AccountRegZW_fybx&whereCondition=where rownum<13&printType=PRINT</a></li>
+					<li><a target="_blank">print/pre?userName=UAS_TEST&reportName=AccountRegZW_fybx&whereCondition=where rownum<13&printType=PRINT</a></li>
 				</ol>
 
 
 				<strong><li class="title1">导出</li></strong>
 				<ol>
-					<li><a target="_blank">print?userName=UAS&reportName=Purchase&whereCondition=where rownum<14&printType=PDF</a></li>
-					<li><a target="_blank">print?userName=UAS&reportName=Purchase&whereCondition=where rownum<15&printType=EXCEL</a></li>
+					<li><a target="_blank">print/pre?userName=UAS&reportName=Purchase&whereCondition=where rownum<14&printType=PDF</a></li>
+					<li><a target="_blank">print/pre?userName=UAS&reportName=Purchase&whereCondition=where rownum<15&printType=EXCEL</a></li>
 				</ol>
 			</ol>
 
@@ -73,8 +74,8 @@
 			<ol>
 				<strong><li class="title2">打印接口</li></strong>
 				<ol>
-					<li><a target="_blank">print/pdfPath?userName=UAS&reportName=Purchase&whereCondition=where rownum<30</a></li>
-					<li><a target="_blank">print/export?userName=UAS&reportName=Purchase&whereCondition=where rownum<16&exportFileType=xls_data&title=采购单</a></li>
+					<li><a target="_blank">print/pdfPath?id=81a7854cd907438f98968a3e2d0024d6</a></li>
+					<li><a target="_blank">print/export?id=81a7854cd907438f98968a3e2d0024d6</a></li>
 					<li><a target="_blank">print/pdfData?userName=UAS&reportName=Purchase&whereCondition=where rownum<30</a></li>
 					<li><a target="_blank">print/count?userName=UAS&reportName=Purchase&whereCondition=where rownum<16</a></li>
 					<li><a target="_blank">print/exportButtons</a></li>
@@ -88,12 +89,12 @@
 				</ol>
 				<strong><li class="title2">B2C</li></strong>
 				<ol>
-					<li><a target="_blank">print?userName=B2C&profile=test&reportName=order&whereCondition=where rownum<30</a></li>
+					<li><a target="_blank">print/pre?userName=B2C&profile=test&reportName=order&whereCondition=where rownum<30</a></li>
 					<li><a target="_blank">fileUpload?userName=B2C</a></li>
 				</ol>
 				<strong><li class="title2">B2B</li></strong>
 				<ol>
-					<li><a target="_blank">print?userName=B2B/10005740&profile=test&reportName=PURCLIST&whereCondition=where rownum<30</a></li>
+					<li><a target="_blank">print/pre?userName=B2B/10005740&profile=test&reportName=PURCLIST&whereCondition=where rownum<30</a></li>
 					<li><a target="_blank">fileUpload?userName=B2B/1111</a></li>
 				</ol>
 			</ol>

+ 29 - 4
report/src/main/webapp/resources/js/preview/app.js

@@ -22,14 +22,14 @@ var winWidth;
 // 将要打印的pdf相对路径
 var pdfPath;
 // 参数打印类型,可能为PRINT、PREVIEW
-var printType = getParameter("printType");
+var printType;
 // 是否正在渲染页面
 var rendering = false;
 // 下一个要渲染的页面
 var nextRenderingPage;
 
-document.title = getParameter("reportName");
 showExportButtons();
+getPreParameter();
 getWindowWidth();
 loadData();
 
@@ -122,7 +122,7 @@ $("body").keydown(function(event) {
  */
 function showExportButtons() {
 	$.ajax({
-		type: "get",
+		type: "post",
 		async: true,
 		url: "print/exportButtons",
 		success: function (exportButtons) {
@@ -147,6 +147,31 @@ function showExportButtons() {
 	});
 }
 
+/**
+ * 显示导出按钮
+ */
+function getPreParameter() {
+    $.ajax({
+        type: "post",
+        async: true,
+        url: "print/parameter",
+        data: {
+            "id": getParameter("id")
+        },
+        success: function (data) {
+            if(data.printType){
+                printType = data.printType;
+            }
+            if(data.reportName){
+                document.title = data.reportName;
+            }
+        },
+        error: function (XMLHttpRequest) {
+            showError(XMLHttpRequest);
+        }
+    });
+}
+
 /**
  * 获取窗口宽度
  */
@@ -187,7 +212,7 @@ function loadData() {
 				pageSize = pdfDoc.numPages;
 				document.getElementById('pageSize').textContent = pageSize;
 				renderPage(pageIndex);
-				if (printType == "PRINT") {
+				if (printType.toUpperCase() == "PRINT") {
 					spinner = showLoading(spinner, spinnerContainer);
 					setTimeout("printPdf()", 1000);
 				}