bc_zhang il y a 4 ans
Parent
commit
17f3b4c34b

+ 21 - 13
src/main/java/com/zglc/fm/controller/BookController.java

@@ -22,6 +22,7 @@ import com.zglc.fm.utils.*;
 import com.zglc.fm.utils.FileTypeUtil.Type;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.io.File;
 import java.util.Date;
 import java.util.List;
 
@@ -56,35 +57,42 @@ public class BookController {
         sourcePath1 = "d:\\sourcefm";
         String filePath = FileTool.fileUp(file, sourcePath1, date.getTime() + file.getOriginalFilename());
 
-        Type fileType = FileTypeUtil.getFileType(file.getOriginalFilename());
-        if (fileType == Type.DOC || fileType == Type.DOCX ||  fileType == Type.RTF ) {
+        FileTypeUtil.Type fileType = FileTypeUtil.getFileType(file.getOriginalFilename());
+        if (fileType == FileTypeUtil.Type.DOC || fileType == FileTypeUtil.Type.DOCX ||  fileType == FileTypeUtil.Type.RTF ) {
             DocToPdf.convertDoc2Pdf(filePath, sourcePath1);
         }
-        if (fileType == Type.PPT || fileType == Type.PPTX) {
+        if (fileType == FileTypeUtil.Type.PPT || fileType == FileTypeUtil.Type.PPTX) {
             Ppt2ToPdf.convertPpt2Pdf(filePath, sourcePath1);
         }
-        if (fileType == Type.DOC) {
+        if (fileType == FileTypeUtil.Type.DOC) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "doc","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
-        if (fileType == Type.DOCX) {
+        if (fileType == FileTypeUtil.Type.DOCX) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "docx","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
-        if (fileType == Type.RTF) {
+        if (fileType == FileTypeUtil.Type.RTF) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "rtf","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
-        if (fileType == Type.PPT) {
+        if (fileType == FileTypeUtil.Type.PPT) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "ppt","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
-        if (fileType == Type.PPTX) {
+        if (fileType == FileTypeUtil.Type.PPTX) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "pptx","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
+        filePath = filePath.replaceAll( "d:","");
         return Result.success(filePath);
     }
+    private void deleteDir(File file) {
+        if (file == null) {
+            return;
+        }
+        file.delete();
+    }
 
 
     @ApiOperation("列出所有")

+ 13 - 5
src/main/java/com/zglc/fm/controller/CardController.java

@@ -22,6 +22,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.io.File;
 import java.util.Date;
 import java.util.List;
 
@@ -61,27 +62,34 @@ public class CardController {
             Ppt2ToPdf.convertPpt2Pdf(filePath, sourcePath1);
         }
         if (fileType == FileTypeUtil.Type.DOC) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "doc","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.DOCX) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "docx","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.RTF) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "rtf","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.PPT) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "ppt","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.PPTX) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "pptx","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
+        filePath = filePath.replaceAll( "d:","");
         return Result.success(filePath);
     }
+    private void deleteDir(File file) {
+        if (file == null) {
+            return;
+        }
+        file.delete();
+    }
 
     @ApiOperation("列出所有")
     @ApiResponses({

+ 13 - 5
src/main/java/com/zglc/fm/controller/FaultController.java

@@ -22,6 +22,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.io.File;
 import java.util.Date;
 import java.util.List;
 
@@ -61,27 +62,34 @@ public class FaultController {
             Ppt2ToPdf.convertPpt2Pdf(filePath, sourcePath1);
         }
         if (fileType == FileTypeUtil.Type.DOC) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "doc","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.DOCX) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "docx","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.RTF) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "rtf","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.PPT) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "ppt","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.PPTX) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "pptx","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
+        filePath = filePath.replaceAll( "d:","");
         return Result.success(filePath);
     }
+    private void deleteDir(File file) {
+        if (file == null) {
+            return;
+        }
+        file.delete();
+    }
 
     @ApiOperation("列出所有")
     @ApiResponses({

+ 13 - 5
src/main/java/com/zglc/fm/controller/ManuelController.java

@@ -22,6 +22,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.io.File;
 import java.util.Date;
 import java.util.List;
 
@@ -61,27 +62,34 @@ public class ManuelController {
             Ppt2ToPdf.convertPpt2Pdf(filePath, sourcePath1);
         }
         if (fileType == FileTypeUtil.Type.DOC) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "doc","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.DOCX) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "docx","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.RTF) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "rtf","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.PPT) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "ppt","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.PPTX) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "pptx","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
+        filePath = filePath.replaceAll( "d:","");
         return Result.success(filePath);
     }
+    private void deleteDir(File file) {
+        if (file == null) {
+            return;
+        }
+        file.delete();
+    }
 
 
     @ApiOperation("列出所有")

+ 13 - 5
src/main/java/com/zglc/fm/controller/OutlineController.java

@@ -23,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.io.File;
 import java.util.Date;
 import java.util.List;
 
@@ -62,27 +63,34 @@ public class OutlineController {
             Ppt2ToPdf.convertPpt2Pdf(filePath, sourcePath1);
         }
         if (fileType == FileTypeUtil.Type.DOC) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "doc","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.DOCX) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "docx","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.RTF) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "rtf","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.PPT) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "ppt","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
         if (fileType == FileTypeUtil.Type.PPTX) {
+            deleteDir(new File(filePath));
             filePath = filePath.replaceAll( "pptx","pdf");
-            filePath = filePath.replaceAll( "d:","");
         }
+        filePath = filePath.replaceAll( "d:","");
         return Result.success(filePath);
     }
+    private void deleteDir(File file) {
+        if (file == null) {
+            return;
+        }
+        file.delete();
+    }
 
     @ApiOperation("列出所有")
     @ApiResponses({

+ 22 - 10
src/main/java/com/zglc/fm/schedule/ScheduleTasks.java

@@ -98,13 +98,14 @@ public class ScheduleTasks {
                 //转为pdf
                 DocToPdf.convertDoc2Pdf(filePath, sourcePath1);
                 if (f.getName().endsWith(ExcelUtils.DOC))  {
+                    deleteDir1(new File(filePath));
                     filePath = filePath.replaceAll( "doc","pdf");
-                    filePath = filePath.replaceAll( "d:","");
                 }
                 if (f.getName().endsWith(ExcelUtils.DOCX))  {
+                    deleteDir1(new File(filePath));
                     filePath = filePath.replaceAll( "docx","pdf");
-                    filePath = filePath.replaceAll( "d:","");
                 }
+                filePath = filePath.replaceAll( "d:","");
                 String name = null;
                 if (f.getName().endsWith(ExcelUtils.DOC)) {
                     name = f.getName().replace(ExcelUtils.DOC, "");
@@ -147,13 +148,14 @@ public class ScheduleTasks {
                 //转为pdf
                 DocToPdf.convertDoc2Pdf(filePath, sourcePath1);
                 if (f.getName().endsWith(ExcelUtils.DOC))  {
+                    deleteDir1(new File(filePath));
                     filePath = filePath.replaceAll( "doc","pdf");
-                    filePath = filePath.replaceAll( "d:","");
                 }
                 if (f.getName().endsWith(ExcelUtils.DOCX))  {
+                    deleteDir1(new File(filePath));
                     filePath = filePath.replaceAll( "docx","pdf");
-                    filePath = filePath.replaceAll( "d:","");
                 }
+                filePath = filePath.replaceAll( "d:","");
                 String name = null;
                 if (f.getName().endsWith(ExcelUtils.DOC)) {
                     name = f.getName().replace(ExcelUtils.DOC, "");
@@ -196,13 +198,14 @@ public class ScheduleTasks {
                 //转为pdf
                 DocToPdf.convertDoc2Pdf(filePath, sourcePath1);
                 if (f.getName().endsWith(ExcelUtils.DOC))  {
+                    deleteDir1(new File(filePath));
                     filePath = filePath.replaceAll( "doc","pdf");
-                    filePath = filePath.replaceAll( "d:","");
                 }
                 if (f.getName().endsWith(ExcelUtils.DOCX))  {
+                    deleteDir1(new File(filePath));
                     filePath = filePath.replaceAll( "docx","pdf");
-                    filePath = filePath.replaceAll( "d:","");
                 }
+                filePath = filePath.replaceAll( "d:","");
                 String name = null;
                 if (f.getName().endsWith(ExcelUtils.DOC)) {
                     name = f.getName().replace(ExcelUtils.DOC, "");
@@ -245,13 +248,14 @@ public class ScheduleTasks {
                 //转为pdf
                 DocToPdf.convertDoc2Pdf(filePath, sourcePath1);
                 if (f.getName().endsWith(ExcelUtils.DOC))  {
+                    deleteDir1(new File(filePath));
                     filePath = filePath.replaceAll( "doc","pdf");
-                    filePath = filePath.replaceAll( "d:","");
                 }
                 if (f.getName().endsWith(ExcelUtils.DOCX))  {
+                    deleteDir1(new File(filePath));
                     filePath = filePath.replaceAll( "docx","pdf");
-                    filePath = filePath.replaceAll( "d:","");
                 }
+                filePath = filePath.replaceAll( "d:","");
                 String name = null;
                 if (f.getName().endsWith(ExcelUtils.DOC)) {
                     name = f.getName().replace(ExcelUtils.DOC, "");
@@ -294,13 +298,14 @@ public class ScheduleTasks {
                 //转为pdf
                 DocToPdf.convertDoc2Pdf(filePath, sourcePath1);
                 if (f.getName().endsWith(ExcelUtils.DOC))  {
+                    deleteDir1(new File(filePath));
                     filePath = filePath.replaceAll( "doc","pdf");
-                    filePath = filePath.replaceAll( "d:","");
                 }
                 if (f.getName().endsWith(ExcelUtils.DOCX))  {
+                    deleteDir1(new File(filePath));
                     filePath = filePath.replaceAll( "docx","pdf");
-                    filePath = filePath.replaceAll( "d:","");
                 }
+                filePath = filePath.replaceAll( "d:","");
                 String name = null;
                 if (f.getName().endsWith(ExcelUtils.DOC)) {
                     name = f.getName().replace(ExcelUtils.DOC, "");
@@ -345,6 +350,13 @@ public class ScheduleTasks {
         }
     }
 
+    private void deleteDir1(File file) {
+        if (file == null) {
+            return;
+        }
+        file.delete();
+    }
+
     private MultipartFile transtTo(File file) {
         MultipartFile mfile = null;
         try {

+ 10 - 0
src/main/java/com/zglc/fm/service/BookService.java

@@ -8,6 +8,7 @@ import com.zglc.fm.entity.BookEntity;
 import org.springframework.stereotype.Service;
 import tk.mybatis.mapper.entity.Example;
 
+import java.io.File;
 import java.util.Iterator;
 import java.util.List;
 
@@ -51,6 +52,8 @@ public class BookService {
         Iterator iter = ids.iterator();
         while(iter.hasNext()) {
             Integer id = (Integer)iter.next();
+            BookEntity tmpData = bookDao.selectByPrimaryKey(id);
+            deleteDir(new File("d:"+tmpData.getFile_path()));
             int index = bookDao.deleteByPrimaryKey(id);
             if (index == 0) {
                 flag = false;
@@ -62,6 +65,13 @@ public class BookService {
         return Result.result(flag, msg, msg);
     }
 
+    private void deleteDir(File file) {
+        if (file == null) {
+            return;
+        }
+        file.delete();
+    }
+
     public Result<String> edit(BookEntity data) {
         boolean flag = true;
         String msg = "";

+ 10 - 0
src/main/java/com/zglc/fm/service/CardService.java

@@ -7,6 +7,7 @@ import com.zglc.fm.entity.CardEntity;
 import org.springframework.stereotype.Service;
 import tk.mybatis.mapper.entity.Example;
 
+import java.io.File;
 import java.util.Iterator;
 import java.util.List;
 
@@ -49,6 +50,8 @@ public class CardService {
         Iterator iter = ids.iterator();
         while(iter.hasNext()) {
             Integer id = (Integer)iter.next();
+            CardEntity tmpData = cardDao.selectByPrimaryKey(id);
+            deleteDir(new File("d:"+tmpData.getFile_path()));
             int index = cardDao.deleteByPrimaryKey(id);
             if (index == 0) {
                 flag = false;
@@ -60,6 +63,13 @@ public class CardService {
         return Result.result(flag, msg, msg);
     }
 
+    private void deleteDir(File file) {
+        if (file == null) {
+            return;
+        }
+        file.delete();
+    }
+
     public Result<String> edit(CardEntity data) {
         boolean flag = true;
         String msg = "";

+ 13 - 0
src/main/java/com/zglc/fm/service/FaultService.java

@@ -3,9 +3,11 @@ package com.zglc.fm.service;
 import com.zglc.fm.base.Result;
 import com.zglc.fm.dao.FaultDao;
 import com.zglc.fm.entity.FaultEntity;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import tk.mybatis.mapper.entity.Example;
 
+import java.io.File;
 import java.util.Iterator;
 import java.util.List;
 
@@ -41,6 +43,8 @@ public class FaultService {
 
         return Result.result(flag, msg, msg);
     }
+    @Value("${spring.fault.uploadPath}")
+    private String uploadPath;
 
     public Result<String> delete(List<Integer> ids) {
         boolean flag = true;
@@ -48,6 +52,8 @@ public class FaultService {
         Iterator iter = ids.iterator();
         while(iter.hasNext()) {
             Integer id = (Integer)iter.next();
+            FaultEntity tmpData = faultDao.selectByPrimaryKey(id);
+            deleteDir(new File("d:"+tmpData.getFile_path()));
             int index = faultDao.deleteByPrimaryKey(id);
             if (index == 0) {
                 flag = false;
@@ -59,6 +65,13 @@ public class FaultService {
         return Result.result(flag, msg, msg);
     }
 
+    private void deleteDir(File file) {
+        if (file == null) {
+            return;
+        }
+        file.delete();
+    }
+
     public Result<String> edit(FaultEntity data) {
         boolean flag = true;
         String msg = "";

+ 10 - 0
src/main/java/com/zglc/fm/service/ManuelService.java

@@ -7,6 +7,7 @@ import com.zglc.fm.entity.ManuelEntity;
 import org.springframework.stereotype.Service;
 import tk.mybatis.mapper.entity.Example;
 
+import java.io.File;
 import java.util.Iterator;
 import java.util.List;
 
@@ -49,6 +50,8 @@ public class ManuelService {
         Iterator iter = ids.iterator();
         while(iter.hasNext()) {
             Integer id = (Integer)iter.next();
+            ManuelEntity tmpData = manuelDao.selectByPrimaryKey(id);
+            deleteDir(new File("d:"+tmpData.getFile_path()));
             int index = manuelDao.deleteByPrimaryKey(id);
             if (index == 0) {
                 flag = false;
@@ -60,6 +63,13 @@ public class ManuelService {
         return Result.result(flag, msg, msg);
     }
 
+    private void deleteDir(File file) {
+        if (file == null) {
+            return;
+        }
+        file.delete();
+    }
+
     public Result<String> edit(ManuelEntity data) {
         boolean flag = true;
         String msg = "";

+ 10 - 0
src/main/java/com/zglc/fm/service/OutlineService.java

@@ -7,6 +7,7 @@ import com.zglc.fm.entity.OutlineEntity;
 import org.springframework.stereotype.Service;
 import tk.mybatis.mapper.entity.Example;
 
+import java.io.File;
 import java.util.Iterator;
 import java.util.List;
 
@@ -49,6 +50,8 @@ public class OutlineService {
         Iterator iter = ids.iterator();
         while(iter.hasNext()) {
             Integer id = (Integer)iter.next();
+            OutlineEntity tmpData = outlineDao.selectByPrimaryKey(id);
+            deleteDir(new File("d:"+tmpData.getFile_path()));
             int index = outlineDao.deleteByPrimaryKey(id);
             if (index == 0) {
                 flag = false;
@@ -60,6 +63,13 @@ public class OutlineService {
         return Result.result(flag, msg, msg);
     }
 
+    private void deleteDir(File file) {
+        if (file == null) {
+            return;
+        }
+        file.delete();
+    }
+
     public Result<String> edit(OutlineEntity data) {
         boolean flag = true;
         String msg = "";