Explorar el Código

remove duplicate code in /print/pdfData

sunyj hace 8 años
padre
commit
92be32e1d0

+ 7 - 22
report/src/main/java/com/uas/report/controller/PrintController.java

@@ -6,7 +6,8 @@ import com.uas.report.model.Platform;
 import com.uas.report.model.PrintType;
 import com.uas.report.model.PrintType;
 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.*;
+import com.uas.report.util.ReportUtils;
+import com.uas.report.util.StringUtils;
 import net.sf.jasperreports.engine.JRException;
 import net.sf.jasperreports.engine.JRException;
 import org.dom4j.DocumentException;
 import org.dom4j.DocumentException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -18,10 +19,8 @@ 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 java.io.File;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.IOException;
 import java.sql.SQLException;
 import java.sql.SQLException;
-import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -45,6 +44,9 @@ public class PrintController {
 	@Autowired
 	@Autowired
 	private FileService fileService;
 	private FileService fileService;
 
 
+	@Autowired
+	private PdfController pdfController;
+
 	/**
 	/**
 	 * 为UAS系统打印提供服务, 根据printType进行预览、打印、下载pdf、下载纯数据excel等操作
 	 * 为UAS系统打印提供服务, 根据printType进行预览、打印、下载pdf、下载纯数据excel等操作
 	 *
 	 *
@@ -143,6 +145,7 @@ public class PrintController {
 	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) throws JRException, IOException, DocumentException, SQLException {
 			HttpServletResponse response) throws JRException, IOException, DocumentException, SQLException {
+		// TODO show download process
 		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);
@@ -243,25 +246,7 @@ public class PrintController {
 	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 {
 			throws JRException, IOException, DocumentException, SQLException {
-		userName = userName == null ? null : userName.toUpperCase();
-		ReportUtils.checkParameters(userName, reportName);
-		Map<String, Object> result = new HashMap<>();
-		// 判断是否过载
-		if (printService.overload(userName, profile, reportName, whereCondition, otherParameters, Platform.PHONE)) {
-			result.put("data", "");
-			result.put("pageSize", 0);
-			result.put("overload", true);
-		} else {
-			String pdfPath = reportName + "/"
-					+ fileService.generateFileName(userName, profile, whereCondition, otherParameters, ExportType.PDF.getQualifier())
-					+ "." + ExportType.PDF.getQualifier();
-			File file = new File(ReportUtils.getDocumentsDir(), pdfPath);
-			int pageSize = printService.export(userName, profile, reportName, whereCondition, otherParameters, ExportType.PDF, file, null, true);
-			result.put("data", FileUtils.readData(new FileInputStream(file)));
-			result.put("pageSize", pageSize);
-			result.put("overload", false);
-		}
-		return result;
+		return pdfController.getData(userName, profile, reportName, whereCondition, otherParameters, Platform.PHONE.name(), request, response);
 	}
 	}
 
 
 	/**
 	/**