|
|
@@ -2,6 +2,7 @@ package com.uas.report.service.impl;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
import java.net.URISyntaxException;
|
|
|
@@ -9,6 +10,7 @@ import java.sql.Connection;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Properties;
|
|
|
@@ -29,6 +31,7 @@ import com.uas.report.service.PrintService;
|
|
|
import com.uas.report.service.ResourceService;
|
|
|
import com.uas.report.support.JasperserverRestAPIConf;
|
|
|
import com.uas.report.util.ContextUtils;
|
|
|
+import com.uas.report.util.PathUtils;
|
|
|
import com.uas.report.util.ReportConstants;
|
|
|
|
|
|
import net.sf.jasperreports.engine.JRException;
|
|
|
@@ -80,6 +83,27 @@ public class PrintServiceImpl implements PrintService {
|
|
|
return print(userName, reportName, whereCondition, otherParameters, null, pageIndex);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String writePdfFile(String reportName, byte[] data) {
|
|
|
+ String pdfFilePath = "resources/generate/pdf/" + reportName + "_" + new Date().getTime() + ".pdf";
|
|
|
+ File pdfFile = new File(PathUtils.getAppPath() + pdfFilePath);
|
|
|
+
|
|
|
+ if (!pdfFile.getParentFile().exists()) {
|
|
|
+ pdfFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ FileOutputStream fos = new FileOutputStream(pdfFile);
|
|
|
+ fos.write(data);
|
|
|
+ fos.flush();
|
|
|
+ logger.info("Generated pdf file: " + pdfFile.getPath());
|
|
|
+ fos.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new SystemError(e.getMessage());
|
|
|
+ }
|
|
|
+ return pdfFilePath;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 输出报表的数据
|
|
|
*
|
|
|
@@ -341,7 +365,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
} catch (JRException e) {
|
|
|
e.printStackTrace();
|
|
|
throw new SystemError(e.getMessage());
|
|
|
-// return false;
|
|
|
+ // return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|