|
|
@@ -1,14 +1,10 @@
|
|
|
package com.uas.report.controller;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
-import java.sql.SQLException;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
+import com.uas.report.model.ExportType;
|
|
|
+import com.uas.report.service.FileService;
|
|
|
+import com.uas.report.service.PrintService;
|
|
|
+import com.uas.report.util.*;
|
|
|
+import net.sf.jasperreports.engine.JRException;
|
|
|
import org.dom4j.DocumentException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
@@ -16,17 +12,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
-import com.uas.report.model.ExportType;
|
|
|
-import com.uas.report.service.FileService;
|
|
|
-import com.uas.report.service.PrintService;
|
|
|
-import com.uas.report.util.ArrayUtils;
|
|
|
-import com.uas.report.util.CollectionUtils;
|
|
|
-import com.uas.report.util.FileUtils;
|
|
|
-import com.uas.report.util.Platform;
|
|
|
-import com.uas.report.util.ReportConstants;
|
|
|
-import com.uas.report.util.ReportUtils;
|
|
|
-
|
|
|
-import net.sf.jasperreports.engine.JRException;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 获取pdf
|
|
|
@@ -230,6 +222,25 @@ public class PdfController {
|
|
|
throw new IllegalStateException("数据量过大,无法提供服务");
|
|
|
}
|
|
|
}
|
|
|
- fileService.rangeDownload(file, n == null ? null : n + ".pdf", request, response);
|
|
|
+ fileService.rangeDownload(file, n == null ? null : n + "."+ExportType.PDF.getQualifier(), request, response);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 预览 pdf (Content Type 为 application/pdf)
|
|
|
+ *
|
|
|
+ * @param p
|
|
|
+ * pdf 相对路径
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/preview")
|
|
|
+ @ResponseBody
|
|
|
+ public void preview(@RequestParam(required = true) String p, HttpServletRequest request, HttpServletResponse response)
|
|
|
+ throws JRException, IOException, DocumentException, SQLException, IllegalStateException {
|
|
|
+ File file = new File(ReportConstants.GENERATED_FILES_DIR + p);
|
|
|
+ if(!file.getName().toLowerCase().endsWith(".pdf")){
|
|
|
+ throw new IOException("并非 pdf 文件:" + p);
|
|
|
+ }
|
|
|
+ fileService.rangeDownloadWithContentType(file, "application/pdf", request, response);
|
|
|
}
|
|
|
}
|