Browse Source

代码优化第二弹

高家顺 3 years ago
parent
commit
e650f367d1

+ 18 - 12
src/main/java/com/macro/mall/tiny/common/util/MyFileUtils.java

@@ -3,7 +3,6 @@ package com.macro.mall.tiny.common.util;
 
 import com.google.common.collect.Lists;
 import com.macro.mall.tiny.config.UploadConfig;
-import com.macro.mall.tiny.domain.AdminUserDetails;
 import com.macro.mall.tiny.modules.business.model.BDirectory;
 import com.macro.mall.tiny.modules.business.model.BFile;
 import com.macro.mall.tiny.modules.business.model.BFileDetail;
@@ -12,7 +11,10 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
 import java.util.stream.Collectors;
 
 /**
@@ -100,16 +102,16 @@ public class MyFileUtils {
         return "";
     }
 
-    public static List<BFile> getSonFiles(String basePath) {
+    public static List<BFile> getSubBFiles(String basePath) {
         boolean access = AuthUtil.checkAccess(AuthUtil.ACCESS);
-        return getSonFiles(basePath, null, access);
+        return getSubBFiles(basePath, null, access);
     }
 
-    public static List<BFile> getSonFiles(String basePath, boolean auth) {
-        return getSonFiles(basePath, null, auth);
+    public static List<BFile> getSubBFiles(String basePath, boolean auth) {
+        return getSubBFiles(basePath, null, auth);
     }
 
-    public static List<BFile> getSonFiles(String basePath, FilenameFilter filter, boolean auth) {
+    public static List<BFile> getSubBFiles(String basePath, FilenameFilter filter, boolean auth) {
         if (StringUtils.isBlank(basePath)) return Lists.newArrayList();
         File oriDic = new File(basePath);
         if (!oriDic.exists() || oriDic.isFile() || (!auth && basePath.contains(String.valueOf(UploadConfig.AUTH_STR)))) {
@@ -125,7 +127,7 @@ public class MyFileUtils {
                         sonFile.setPath(son.getPath());
                         sonFile.setIsDirectory(son.isDirectory() ? 1 : 0);
                         if (son.isDirectory()) {
-                            sonFile.setSubFile(getSonFiles(son.getPath(), filter, auth));
+                            sonFile.setSubFile(getSubBFiles(son.getPath(), filter, auth));
                         }
                         return sonFile;
                     })
@@ -155,7 +157,7 @@ public class MyFileUtils {
         List<BDirectory> subDirectory = null;
         boolean hasFile = false;
 
-        final File[] subFiles = file.listFiles((dir, name) -> access || !name.startsWith(String.valueOf(UploadConfig.AUTH_STR)));
+        final File[] subFiles = getSubBFiles(file, access);
         if (subFiles != null && subFiles.length > 0) {
             for (File subFile : subFiles) {
                 if (subFile.isFile()) {
@@ -184,7 +186,7 @@ public class MyFileUtils {
         if (!oriDic.exists() || oriDic.isFile() || (!access && path.contains(String.valueOf(UploadConfig.AUTH_STR)))) {
             return Lists.newArrayList();
         }
-        File[] subFiles = oriDic.listFiles((dir, name) -> access || !name.startsWith(String.valueOf(UploadConfig.AUTH_STR)));
+        File[] subFiles = getSubBFiles(oriDic, access);
         if (subFiles == null) return Lists.newArrayList();
         return Arrays.stream(subFiles)
                 .filter(File::isFile)
@@ -232,7 +234,7 @@ public class MyFileUtils {
         if (!dic.exists() || !dic.isDirectory()) {
             return false;
         }
-        File[] subFiles = filter == null ? dic.listFiles((dir, name) -> access || !name.startsWith(String.valueOf(UploadConfig.AUTH_STR))) : dic.listFiles(filter);
+        File[] subFiles = filter == null ? getSubBFiles(dic, access) : dic.listFiles(filter);
         if (subFiles == null) {
             return false;
         }
@@ -248,7 +250,7 @@ public class MyFileUtils {
         if (!directory.exists() || !directory.isDirectory()) {
             return;
         }
-        File[] subFiles = directory.listFiles((dir, name) -> access || !name.startsWith(String.valueOf(UploadConfig.AUTH_STR)));
+        File[] subFiles = getSubBFiles(directory, access);
         if (subFiles == null) {
             return;
         }
@@ -260,4 +262,8 @@ public class MyFileUtils {
             }
         });
     }
+
+    private static File[] getSubBFiles(File directory, boolean access) {
+        return directory.listFiles((dir, name) -> access || !name.startsWith(String.valueOf(UploadConfig.AUTH_STR)));
+    }
 }

+ 1 - 1
src/main/java/com/macro/mall/tiny/modules/business/service/impl/BLineServiceImpl.java

@@ -84,6 +84,6 @@ public class BLineServiceImpl extends ServiceImpl<BLineMapper, BLine> implements
         String basePath = UploadConfig.powerPath +
                 province.getProvince() + UploadConfig.SEPARATOR +
                 line.getName();
-        return MyFileUtils.getSonFiles(basePath, auth);
+        return MyFileUtils.getSubBFiles(basePath, auth);
     }
 }

+ 3 - 3
src/main/java/com/macro/mall/tiny/modules/business/service/impl/BTowerServiceImpl.java

@@ -78,7 +78,7 @@ public class BTowerServiceImpl extends ServiceImpl<BTowerMapper, BTower> impleme
         if (StringUtils.isNotBlank(shape)) {
             secBasePath = MyFileUtils.getAuthFilePath(basePath, DirectoryEnum.TOWER_PIC.getName(), auth);
             thirdBasePath = MyFileUtils.getAuthFilePath(secBasePath, shape, auth);
-            sonList = MyFileUtils.getSonFiles(thirdBasePath, auth);
+            sonList = MyFileUtils.getSubBFiles(thirdBasePath, auth);
         } else {
             sonList = Lists.newArrayList();
         }
@@ -89,7 +89,7 @@ public class BTowerServiceImpl extends ServiceImpl<BTowerMapper, BTower> impleme
         String hardwareType = tower.getHardwareType().replace('/', ' ');
         if (StringUtils.isNotBlank(hardwareType)) {
             FilenameFilter hardwareTypeFilter = (dir, name) -> name.startsWith(hardwareType) || (name.startsWith(UploadConfig.AUTH_STR + hardwareType) && auth);
-            sonList = MyFileUtils.getSonFiles(secBasePath, hardwareTypeFilter, auth);
+            sonList = MyFileUtils.getSubBFiles(secBasePath, hardwareTypeFilter, auth);
         } else {
             sonList = Lists.newArrayList();
         }
@@ -99,7 +99,7 @@ public class BTowerServiceImpl extends ServiceImpl<BTowerMapper, BTower> impleme
         secBasePath = MyFileUtils.getAuthFilePath(basePath, DirectoryEnum.TEAM_CHECK_PIC.getName(), auth);
         String towerName = tower.getName();
         thirdBasePath = MyFileUtils.getAuthFilePath(secBasePath, towerName, auth);
-        sonList = MyFileUtils.getSonFiles(thirdBasePath, auth);
+        sonList = MyFileUtils.getSubBFiles(thirdBasePath, auth);
         resultMap.put("teamCheckFileList", sonList);
 
         return resultMap;

+ 1 - 1
src/main/java/com/macro/mall/tiny/modules/business/service/impl/FileServiceImpl.java

@@ -115,7 +115,7 @@ public class FileServiceImpl implements FileService {
 
     @Override
     public List<BFile> getFileList(String path) {
-        return MyFileUtils.getSonFiles(path);
+        return MyFileUtils.getSubBFiles(path);
     }
 
     @Override