yangdamao 2 жил өмнө
parent
commit
3d77c8e919

+ 24 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/impl/CourseFileServiceImpl.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.Page;
 import com.zhongzheng.common.exception.CustomException;
+import com.zhongzheng.common.utils.DateUtils;
+import com.zhongzheng.common.utils.file.FileUtils;
 import com.zhongzheng.modules.course.bo.CourseHandoutsAddBo;
 import com.zhongzheng.modules.course.bo.CourseHandoutsEditBo;
 import com.zhongzheng.modules.course.domain.CourseFile;
@@ -17,10 +19,15 @@ import org.springframework.stereotype.Service;
 
 import java.io.*;
 import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Comparator;
 import java.util.List;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
@@ -70,6 +77,15 @@ public class CourseFileServiceImpl extends ServiceImpl<CourseFileMapper, CourseF
         }
 
         iCourseHandoutsService.updateHandouts(fromPath,bo);
+
+        //删除本地资源
+        Path pathStr = Paths.get(fromPath);
+        try (Stream<Path> walk = Files.walk(pathStr)) {
+            walk.sorted(Comparator.reverseOrder())
+                    .forEach(FileUtils::deleteDirectoryStream);
+        }catch (IOException e) {
+            log.error("讲义删除本地资源失败:"+ DateUtils.getNowTime());
+        }
         return true;
     }
 
@@ -87,6 +103,14 @@ public class CourseFileServiceImpl extends ServiceImpl<CourseFileMapper, CourseF
             }
         }
         iCourseHandoutsService.addHandouts(fromPath,bo);
+        //删除本地资源
+        Path pathStr = Paths.get(fromPath);
+        try (Stream<Path> walk = Files.walk(pathStr)) {
+            walk.sorted(Comparator.reverseOrder())
+                    .forEach(FileUtils::deleteDirectoryStream);
+        }catch (IOException e) {
+            log.error("讲义删除本地资源失败:"+ DateUtils.getNowTime());
+        }
         return true;
     }
 

+ 0 - 12
zhongzheng-system/src/main/java/com/zhongzheng/modules/course/service/impl/CourseHandoutsServiceImpl.java

@@ -138,8 +138,6 @@ public class CourseHandoutsServiceImpl extends ServiceImpl<CourseHandoutsMapper,
                             courseFile.setHandoutsId(add.getHandoutsId());
                             courseFile.setType(1);//文件
                             courseFile.setParentId(0L);
-                            //删除本地资源
-                            file1.delete();
                             iCourseFileService.save(courseFile);
                         } catch (Exception e) {
                             e.printStackTrace();
@@ -238,8 +236,6 @@ public class CourseHandoutsServiceImpl extends ServiceImpl<CourseHandoutsMapper,
                     courseFile.setType(1);//文件
                     courseFile.setParentId(fileId);
                     iCourseFileService.save(courseFile);
-                    //清楚本地资源
-                    file1.delete();
                     return courseFile.getFileId();
                 } catch (Exception e) {
                     e.printStackTrace();
@@ -266,14 +262,6 @@ public class CourseHandoutsServiceImpl extends ServiceImpl<CourseHandoutsMapper,
         iCourseFileService.save(courseFile);
         //处理讲义文件
         getFileNames(new File(path), courseFile.getFileId(), handoutsId);
-        //删除本地资源
-        Path pathStr = Paths.get(path);
-        try (Stream<Path> walk = Files.walk(pathStr)) {
-            walk.sorted(Comparator.reverseOrder())
-                    .forEach(FileUtils::deleteDirectoryStream);
-        }catch (IOException e) {
-            log.error("讲义删除本地资源失败:"+DateUtils.getNowTime());
-        }
         return courseFile.getFileId();
     }