|
@@ -19,6 +19,7 @@ import org.springblade.business.entity.ArchiveFile;
|
|
|
import org.springblade.common.utils.CommonUtil;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.common.vo.DataVO;
|
|
|
+import org.springblade.common.vo.FileSize;
|
|
|
import org.springblade.core.oss.model.BladeFile;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springblade.core.tool.utils.ResourceUtil;
|
|
@@ -68,6 +69,10 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
public void test1() {
|
|
|
|
|
|
Long pkeyId = SnowFlakeUtil.getId();
|
|
|
+// String file2 = "upload/20230413/306c87ffc640699aa92d53a5f4e6d632.xlsx";
|
|
|
+// List<String> files = new ArrayList<>();
|
|
|
+// files.add(file2);
|
|
|
+// BladeFile bladeFile = newIOSSClient.uploadFile1(file2,"123");
|
|
|
|
|
|
String file_path = "D:\\tmp";
|
|
|
String excelUrl = file_path + "\\备考表.xlsx";
|
|
@@ -98,6 +103,7 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
Long projectId = 1578599210897772545L;
|
|
|
|
|
|
ArchivesAuto archivesAuto = new ArchivesAuto();
|
|
|
+ archivesAuto.setId(SnowFlakeUtil.getId());
|
|
|
archivesAuto.setProjectId(projectId);
|
|
|
archivesAuto.setName("案卷提名");
|
|
|
archivesAuto.setFileNumber("档号");
|
|
@@ -217,6 +223,14 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
buildFrontPdf(archivesAuto,number, variables,backUrls);
|
|
|
}
|
|
|
|
|
|
+ //将封面写入archivesAuto
|
|
|
+ frontUrls.addAll(backUrls);
|
|
|
+
|
|
|
+ //统计文件大小
|
|
|
+ flushFileSize(archivesAuto,archiveFileList,frontUrls);
|
|
|
+
|
|
|
+ String joinedUrls = String.join(", ", frontUrls);
|
|
|
+ archivesAuto.setOutUrl(joinedUrls);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -368,9 +382,17 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
|
|
|
//合并成一个
|
|
|
if (localUrls.size() > 1) {
|
|
|
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
- FileUtils.PdfCopyPublicMethods(bos, localUrls);
|
|
|
- BladeFile bladeFile = newIOSSClient.updateFile(bos.toByteArray(),fileName);
|
|
|
+ Long id = SnowFlakeUtil.getId();
|
|
|
+ String trialPdf = file_path + "/pdf/" + id + ".pdf";
|
|
|
+
|
|
|
+ //合并当前所有选择的试验pdf
|
|
|
+ FileUtils.mergePdfPublicMethods(localUrls, trialPdf);
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFile(fileName + ".pdf", trialPdf);
|
|
|
+
|
|
|
+
|
|
|
+// ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
+// FileUtils.PdfCopyPublicMethods(bos, localUrls);
|
|
|
+// BladeFile bladeFile = newIOSSClient.updateFile(bos.toByteArray(),fileName + ".pdf");
|
|
|
if (bladeFile!= null ) {
|
|
|
urls.add(bladeFile.getLink());
|
|
|
}
|
|
@@ -585,10 +607,12 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
|
|
|
// 将日期赋值给startDate和endDate
|
|
|
if (!minDate.isEmpty()) {
|
|
|
- archive.setStartDate(LocalDateTime.parse(minDate, formatter));
|
|
|
+ LocalDateTime localDateTime = FormulaUtil.parseStringToLocalDateTime(minDate,"yyyyMMdd");
|
|
|
+ archive.setStartDate(localDateTime);
|
|
|
}
|
|
|
if (!maxDate.isEmpty()) {
|
|
|
- archive.setEndDate(LocalDateTime.parse(maxDate, formatter));
|
|
|
+ LocalDateTime localDateTime = FormulaUtil.parseStringToLocalDateTime(maxDate,"yyyyMMdd");
|
|
|
+ archive.setEndDate(localDateTime);
|
|
|
}
|
|
|
|
|
|
Map<String, Object> archivesAutoMap = new ObjectMapper().convertValue(archive, Map.class);
|
|
@@ -626,92 +650,6 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
return url;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @Description 给多个PDF添加页码,按顺序依次累加
|
|
|
- * @Param [uris, storeName]
|
|
|
- * @return java.util.List<java.lang.String>
|
|
|
- * @Author yangyj
|
|
|
- * @Date 2021.12.17 14:21
|
|
|
- **/
|
|
|
- public static List<String> doForPageNumberUseItextpdf(List<String> uris) throws IOException {
|
|
|
- List<String> result = new ArrayList<>();
|
|
|
- if(uris!= null && uris.size() > 0){
|
|
|
- int cursor=0;
|
|
|
- for(String u:uris) {
|
|
|
- try {
|
|
|
- String url="";
|
|
|
- //todo 匿名访问特性
|
|
|
- String temporaryVisitUrl=u;
|
|
|
- if(temporaryVisitUrl.indexOf("?")!=-1){
|
|
|
- url = temporaryVisitUrl;
|
|
|
- }else{
|
|
|
- int lastIndexOf = u.lastIndexOf("/");
|
|
|
- String prefix=u.substring(0,lastIndexOf+1);
|
|
|
- String suffix=u.substring(lastIndexOf+1);
|
|
|
- url = prefix+ URLEncoder.encode(suffix,"UTF-8");
|
|
|
- }
|
|
|
-
|
|
|
- PdfReader pdfReader = new PdfReader(url);
|
|
|
- ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
- PdfStamper pdfStamper = new PdfStamper(pdfReader, out);
|
|
|
- int index = 1;
|
|
|
- boolean fi;
|
|
|
-// String path = u.replaceAll(FileUtils.DOMAIN_REG, "").replaceAll(".((?i)(pdf))$", "").replace("folderFile", FolderFileHelper.ARCHIVED_FILE).replace("showtmp",FolderFileHelper.ARCHIVED_FILE);
|
|
|
-
|
|
|
- String page = "page" + (cursor + 1);
|
|
|
- do {
|
|
|
- PdfContentByte over = pdfStamper.getOverContent(index);
|
|
|
- if (over != null) {
|
|
|
- over.beginText();
|
|
|
- BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
|
|
|
- over.setFontAndSize(bf, 16);
|
|
|
- over.setTextMatrix(30, 300);
|
|
|
-
|
|
|
-
|
|
|
- PdfArray pa = pdfReader.getPageN(index).getAsArray(new PdfName("MediaBox"));
|
|
|
- int width = pa.getAsNumber(2).intValue();
|
|
|
- int heigh = pa.getAsNumber(3).intValue();
|
|
|
-
|
|
|
- if(width>heigh){
|
|
|
- //横表旋转270
|
|
|
- pdfReader.getPageN(index).put(PdfName.ROTATE, new PdfNumber(270)); // 顺时针旋转270°
|
|
|
- //横表旋转后打页码坐标不一样
|
|
|
- over.showTextAligned(Element.ALIGN_LEFT, String.valueOf(cursor + index), heigh - 35, 20, 0);
|
|
|
- }else{
|
|
|
- over.showTextAligned(Element.ALIGN_LEFT, String.valueOf(cursor + index), width - 35, 20, 0);
|
|
|
- }
|
|
|
- over.endText();
|
|
|
- index++;
|
|
|
- fi = true;
|
|
|
- } else {
|
|
|
- /*累加*/
|
|
|
- cursor += index-1;
|
|
|
- /*重置*/
|
|
|
- fi = false;
|
|
|
- index = 1;
|
|
|
- }
|
|
|
- } while (fi);
|
|
|
- pdfStamper.close();
|
|
|
- page = page + "-" + cursor + ".pdf";
|
|
|
-// int lastindex = path.lastIndexOf("/");
|
|
|
-// String fileName = path.substring(lastindex + 1) + "-" + page;
|
|
|
-
|
|
|
- //newIOSSClient.uploadFile()
|
|
|
-
|
|
|
- //result.add(AliyunOSSUtil.uploadFile(out.toByteArray(), fileName, path.substring(0, lastindex), ".pdf", storeName));
|
|
|
- out.close();
|
|
|
- }catch(Exception e){
|
|
|
- System.out.println(u+"文件不存在");
|
|
|
- /*用来占位置空*/
|
|
|
- result.add("");
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 获取指定文件的pdf文件
|
|
|
* @param file
|
|
@@ -731,19 +669,35 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取案卷的大小
|
|
|
+ * 刷新文件大小
|
|
|
+ * @param archive
|
|
|
* @param datas
|
|
|
* @param frontUrls
|
|
|
- * @return
|
|
|
*/
|
|
|
- public Long getArchiveSize(List<ArchiveFile> datas,List<String> frontUrls){
|
|
|
- //
|
|
|
- return 0L;
|
|
|
+ public void flushFileSize(ArchivesAuto archive,List<ArchiveFile> datas,List<String> frontUrls){
|
|
|
|
|
|
- //todo 生成相册内容,待补充
|
|
|
+ List<String> fileUrls = new ArrayList<>();
|
|
|
+ for (ArchiveFile file: datas) {
|
|
|
+ fileUrls.add(getPdfFileUrl(file));
|
|
|
+ }
|
|
|
|
|
|
+ fileUrls.addAll(frontUrls);
|
|
|
+ List<FileSize> fileSizes = org.springblade.common.utils.FileUtils.getOssFileSize(fileUrls);
|
|
|
|
|
|
+ double totalSize = fileSizes.stream()
|
|
|
+ .mapToDouble(FileSize::getFileSize)
|
|
|
+ .sum();
|
|
|
+ Integer total = (int) Math.round(totalSize);
|
|
|
+ archive.setSize(total);
|
|
|
|
|
|
+ //todo 生成相册内容,待补充
|
|
|
+ int i = 0;
|
|
|
+ for (ArchiveFile file: datas) {
|
|
|
+ double size = fileSizes.get(i).getFileSize();
|
|
|
+ if (file.getFileSize()!= null) {
|
|
|
+ file.setFileSize(Math.round(size));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|