leo.xie 3 vuotta sitten
vanhempi
commit
2c6d49fb66
1 muutettua tiedostoa jossa 17 lisäystä ja 1 poistoa
  1. 17 1
      src/main/java/com/ads/business/service/impl/DocServiceImpl.java

+ 17 - 1
src/main/java/com/ads/business/service/impl/DocServiceImpl.java

@@ -197,6 +197,18 @@ public class DocServiceImpl extends ServiceImpl<DocDao, Doc> implements DocServi
             docRoleDao.insertBatch(docRoles);
         }
         if (flag) {
+
+            //不相等,那么删除当前目录的下的文件
+            File imageFile = new File(getImageFilePath(doc.getId()));
+            File pdfFile = new File(getImageFilePath(doc.getId())+".pdf");
+            if(imageFile.exists()){
+                imageFile.delete();
+            }
+            if(pdfFile.exists()){
+                pdfFile.delete();
+            }
+
+
             DocHistory docHistory = new DocHistory();
             BeanUtil.copyProperties(doc, docHistory);
             docHistory.setCreateTime(new Date());
@@ -318,6 +330,10 @@ public class DocServiceImpl extends ServiceImpl<DocDao, Doc> implements DocServi
         return doc;
     }
 
+    private String getImageFilePath(Long docId){
+        return pictureConfig.getServerBasePath() +"/"+ pictureConfig.getUploadPath() + "/produce/" +  docId;
+    }
+
     @Override
     public JsonResult pdfDetail(HttpServletRequest request, Long docId, String userNo) {
 
@@ -336,7 +352,7 @@ public class DocServiceImpl extends ServiceImpl<DocDao, Doc> implements DocServi
         String domain = pictureConfig.getServerPath();
         String path = domain + request.getContextPath() + "/";
         String filePath = pictureConfig.getServerBasePath() +"/"+ pictureConfig.getUploadPath() + "/produce/" + docId + ".pdf";
-        String imageFilePath = pictureConfig.getServerBasePath() +"/"+ pictureConfig.getUploadPath() + "/produce/" +  docId + File.separator;
+        String imageFilePath = getImageFilePath(docId) + "/";
         String createPath = pictureConfig.getBasePath() + "/" + pictureConfig.getUploadPath() + "/produce/" + docId + ".pdf";
         File fromFile = new File(createPath);
         //判断目标文件所在的目录是否存在