|
@@ -22,6 +22,7 @@ import org.springblade.common.constant.CommonConstant;
|
|
|
import org.springblade.common.constant.OssConstant;
|
|
|
import org.springblade.common.utils.CommonUtil;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.common.utils.SystemUtils;
|
|
|
import org.springblade.common.vo.DataVO;
|
|
|
import org.springblade.common.vo.FileSize;
|
|
|
import org.springblade.core.oss.model.BladeFile;
|
|
@@ -895,21 +896,27 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
public String upFile(InputStream inputStream, Long projectId) {
|
|
|
String url = "";
|
|
|
Long id = SnowFlakeUtil.getId();
|
|
|
- String localPdf = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL) + "/pdf/" + id + ".pdf";
|
|
|
+ Long id1 = SnowFlakeUtil.getId();
|
|
|
+ String localPdfIn = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL) + "/pdf/" + id + ".pdf";
|
|
|
+ String localPdfOut = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL) + "/pdf/" + id1 + ".pdf";
|
|
|
+ if (SystemUtils.isWindows()) {
|
|
|
+ localPdfIn = "c://upload/pdf/" + id + ".pdf";
|
|
|
+ localPdfOut = "c://upload/pdf/" + id1 + ".pdf";
|
|
|
+ }
|
|
|
String fileName = id + ".pdf";
|
|
|
OutputStream outputStream = null;
|
|
|
try {
|
|
|
//合并PDF
|
|
|
byte[] bytes = FileUtils.InputStreamToBytes(inputStream);
|
|
|
- outputStream = new FileOutputStream(localPdf);
|
|
|
+ outputStream = new FileOutputStream(localPdfIn);
|
|
|
outputStream.write(bytes);
|
|
|
|
|
|
//设置PDF每页大小为A4,内容等比缩放,方向同步
|
|
|
- //PdfResizeTool.resizeToA4WithContentScaling(localPdf, localPdf);
|
|
|
+ PdfResizeTool.resizeToA4WithContentScaling(localPdfIn, localPdfOut);
|
|
|
|
|
|
//上传到OSS
|
|
|
String absoluteFileName = FileUtils.getOssPath(OssConstant.ARCHIVE_DIRECTORY, fileName, projectId);
|
|
|
- BladeFile file = newIOSSClient.uploadFile(absoluteFileName, localPdf);
|
|
|
+ BladeFile file = newIOSSClient.uploadFile(absoluteFileName, localPdfOut);
|
|
|
url = file.getLink();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -919,6 +926,15 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
if (outputStream != null) {
|
|
|
outputStream.close();
|
|
|
}
|
|
|
+ //删除临时文件
|
|
|
+ File localPdfInFile = new File(localPdfIn);
|
|
|
+ if (localPdfInFile.exists()) {
|
|
|
+ localPdfInFile.delete();
|
|
|
+ }
|
|
|
+ File localPdfOutFile = new File(localPdfOut);
|
|
|
+ if (localPdfOutFile.exists()) {
|
|
|
+ localPdfOutFile.delete();
|
|
|
+ }
|
|
|
} catch (IOException ex) {
|
|
|
ex.printStackTrace();
|
|
|
}
|