leo.xie 3 vuotta sitten
vanhempi
commit
3908a05bdf
1 muutettua tiedostoa jossa 16 lisäystä ja 10 poistoa
  1. 16 10
      src/main/java/com/ads/business/service/impl/DocServiceImpl.java

+ 16 - 10
src/main/java/com/ads/business/service/impl/DocServiceImpl.java

@@ -323,9 +323,10 @@ public class DocServiceImpl extends ServiceImpl<DocDao, Doc> implements DocServi
 
         String fileName = doc.getName();
         String docUrl = doc.getDocUrl();
-        String path = request.getScheme() + "://" + request.getServerName() + ":" + "19050" + request.getContextPath() + "/";
-        String filePath = pictureConfig.getServerBasePath() + "/" + pictureConfig.getUploadPath() + "/" + userNo + "/" + docId + fileName + ".pdf";
-        String imageFilePath = pictureConfig.getServerBasePath() + "/" + pictureConfig.getUploadPath() + "/" + userNo + "/" + docId + fileName + File.separator;
+        String domain = pictureConfig.getServerBasePath();
+        String path = domain + request.getContextPath() + "/";
+        String filePath = domain + pictureConfig.getUploadPath() + "/" + userNo + "/" + docId + fileName + ".pdf";
+        String imageFilePath = domain + pictureConfig.getUploadPath() + "/" + userNo + "/" + docId + fileName + File.separator;
         String createPath = pictureConfig.getBasePath() + "/" + pictureConfig.getUploadPath() + "/" + userNo + "/" + docId + fileName + ".pdf";
         File fromFile = new File(createPath);
         //判断目标文件所在的目录是否存在
@@ -333,15 +334,20 @@ public class DocServiceImpl extends ServiceImpl<DocDao, Doc> implements DocServi
             //如果目标文件所在的目录不存在,则创建父目录
             fromFile.getParentFile().mkdirs();
         }
-        if (fromFile.exists()) {
-            fromFile.delete();
+        String pictureFilePath = docUrl.replace(domain,pictureConfig.getBasePath());
+        if(!new File(pictureFilePath).exists()){
+            throw new BusinessException("当前图片不存在");
         }
-        try {
-            PdfUtil.setWatermark(new BufferedOutputStream(new FileOutputStream(new File(createPath))), docUrl, watermark);
-        } catch (FileNotFoundException e) {
-            e.printStackTrace();
-            throw new BusinessException("生成pdf文件水印有异常!");
+
+        if (!fromFile.exists()) {
+            try {
+                PdfUtil.setWatermark(new BufferedOutputStream(new FileOutputStream(new File(createPath))), pictureFilePath, watermark);
+            } catch (FileNotFoundException e) {
+                e.printStackTrace();
+                throw new BusinessException("生成pdf文件水印有异常!");
+            }
         }
+
         log.info("pdfDetail--文件路径:{}", path + filePath);
         log.info("createPath---路径:{}", createPath);
         // 生成图片