|
|
@@ -35,7 +35,6 @@ 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;
|
|
|
@@ -88,13 +87,12 @@ public class PrintServiceImpl implements PrintService {
|
|
|
}
|
|
|
|
|
|
@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);
|
|
|
-
|
|
|
+ public void writePdfFile(String absolutePath, byte[] data) {
|
|
|
+ File pdfFile = new File(absolutePath);
|
|
|
if (!pdfFile.getParentFile().exists()) {
|
|
|
pdfFile.getParentFile().mkdirs();
|
|
|
}
|
|
|
+
|
|
|
try {
|
|
|
FileOutputStream fos = new FileOutputStream(pdfFile);
|
|
|
fos.write(data);
|
|
|
@@ -107,7 +105,36 @@ public class PrintServiceImpl implements PrintService {
|
|
|
e.printStackTrace();
|
|
|
throw new SystemError(e.getMessage());
|
|
|
}
|
|
|
- return pdfFilePath;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String generateFileName(String userName, String reportName, String whereCondition, String otherParameters) {
|
|
|
+ if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(reportName)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ StringBuilder stringBuilder = new StringBuilder(userName);
|
|
|
+ if (!StringUtils.isEmpty(whereCondition)) {
|
|
|
+ stringBuilder.append(whereCondition);
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(otherParameters)) {
|
|
|
+ stringBuilder.append(otherParameters);
|
|
|
+ }
|
|
|
+ // 文件名:reportName + hashCode
|
|
|
+ return reportName + "_" + stringBuilder.toString().hashCode();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isFileExpired(File file) {
|
|
|
+ if (file != null && file.exists()) {
|
|
|
+ long interval = new Date().getTime() - file.lastModified();
|
|
|
+ // 剩余的有效期(最高为5分钟)
|
|
|
+ long validity = 5 * 60 * 1000 - interval;
|
|
|
+ if (validity > 0) {
|
|
|
+ logger.info(file.getName() + " will be expired after " + validity / 1000.0 + "s");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -464,4 +491,5 @@ public class PrintServiceImpl implements PrintService {
|
|
|
// textField.setStretchWithOverflow(false);
|
|
|
// }
|
|
|
}
|
|
|
+
|
|
|
}
|