Selaa lähdekoodia

Merge branch 'master' of http://47.110.251.215:3000/java_org/bladex

“zhifk” 2 vuotta sitten
vanhempi
commit
d9be4d8f81

+ 31 - 92
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchiveAutoPdfServiceImpl.java

@@ -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;
@@ -222,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);
     }
 
     /**
@@ -641,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
@@ -746,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));
+            }
+        }
     }
 
 }