lyhzzz пре 1 дан
родитељ
комит
38567dec86

+ 36 - 0
src/main/java/com/fdkankan/manage/common/MyFileUtil.java

@@ -0,0 +1,36 @@
+package com.fdkankan.manage.common;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.File;
+import java.nio.file.FileSystemException;
+
+@Slf4j
+public class MyFileUtil {
+
+    public static void del(File file){
+        try {
+            for (int i = 0; i < 3; i++) {
+                try {
+                    if(!file.exists()){
+                        return;
+                    }
+                    file.delete();
+                    return;
+                } catch (Exception e) {
+                    if (i == 2) throw e;
+                    Thread.sleep(2000L * (i + 1));
+                }
+            }
+        }catch (Exception e){
+
+        }
+
+    }
+    public static void del(String filePath){
+        if(StringUtils.isNotBlank(filePath)){
+            del(new File(filePath));
+        }
+    }
+}

+ 9 - 8
src/main/java/com/fdkankan/manage/service/impl/CommonServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.core.io.FileUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONObject;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.fdkankan.common.util.SecurityUtil;
 import com.fdkankan.common.util.SecurityUtil;
+import com.fdkankan.manage.common.MyFileUtil;
 import com.fdkankan.manage.common.OssPath;
 import com.fdkankan.manage.common.OssPath;
 import com.fdkankan.manage.common.ResultCode;
 import com.fdkankan.manage.common.ResultCode;
 import com.fdkankan.manage.common.ResultData;
 import com.fdkankan.manage.common.ResultData;
@@ -80,7 +81,7 @@ public class CommonServiceImpl implements ICommonService {
             throw new BusinessException(ResultCode.UPLOAD_ERROR);
             throw new BusinessException(ResultCode.UPLOAD_ERROR);
         }finally {
         }finally {
             if(tempFile != null){
             if(tempFile != null){
-                tempFile.delete();
+                MyFileUtil.del(tempFile);
             }
             }
         }
         }
 
 
@@ -135,7 +136,7 @@ public class CommonServiceImpl implements ICommonService {
             }
             }
             String format = extName.replace(".", "");
             String format = extName.replace(".", "");
             CommonUpload commonUpload = commonUploadService.add(originalFilename.replace(extName, ""), url, String.valueOf(file.getSize()), uuid, fileTypeEnum, format,format,1,null,dictId);
             CommonUpload commonUpload = commonUploadService.add(originalFilename.replace(extName, ""), url, String.valueOf(file.getSize()), uuid, fileTypeEnum, format,format,1,null,dictId);
-            tempFile.delete();
+            MyFileUtil.del(tempFile);
             return ResultData.ok(commonUpload);
             return ResultData.ok(commonUpload);
         }catch ( BusinessException e){
         }catch ( BusinessException e){
             log.info("upload-file-error:{}",e);
             log.info("upload-file-error:{}",e);
@@ -203,7 +204,7 @@ public class CommonServiceImpl implements ICommonService {
         Integer status = StringUtils.isNotBlank(url) ?1:-1;
         Integer status = StringUtils.isNotBlank(url) ?1:-1;
         CommonUpload commonUpload = commonUploadService.add(oldName,url, String.valueOf(tempFile.length()),
         CommonUpload commonUpload = commonUploadService.add(oldName,url, String.valueOf(tempFile.length()),
                 null, fileTypeEnum, modelFileFormat,resultFormat,status,unzipPath,dictId);
                 null, fileTypeEnum, modelFileFormat,resultFormat,status,unzipPath,dictId);
-        tempFile.delete();
+        MyFileUtil.del(tempFile);
         return ResultData.ok(commonUpload);
         return ResultData.ok(commonUpload);
     }
     }
 
 
@@ -216,7 +217,7 @@ public class CommonServiceImpl implements ICommonService {
         if(!fYunFileServiceInterface.fileExist(localGlbPath.replace(OssPath.localPath,""))){
         if(!fYunFileServiceInterface.fileExist(localGlbPath.replace(OssPath.localPath,""))){
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
         }
         }
-        FileUtil.del(unzipPath);
+        MyFileUtil.del(unzipPath);
         return  ossUrlPrefix +  localGlbPath.replace(OssPath.localPath,"");
         return  ossUrlPrefix +  localGlbPath.replace(OssPath.localPath,"");
     }
     }
 
 
@@ -230,7 +231,7 @@ public class CommonServiceImpl implements ICommonService {
         if(!fYunFileServiceInterface.fileExist(ossPath)){
         if(!fYunFileServiceInterface.fileExist(ossPath)){
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
         }
         }
-        FileUtil.del(unzipPath);
+        MyFileUtil.del(unzipPath);
         return ossUrlPrefix +  ossPath;
         return ossUrlPrefix +  ossPath;
     }
     }
 
 
@@ -249,7 +250,7 @@ public class CommonServiceImpl implements ICommonService {
         if(!fYunFileServiceInterface.fileExist(modelOssPath)){
         if(!fYunFileServiceInterface.fileExist(modelOssPath)){
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
         }
         }
-        FileUtil.del(unzipPath);
+        MyFileUtil.del(unzipPath);
         return ossUrlPrefix +  ossPath;
         return ossUrlPrefix +  ossPath;
     }
     }
 
 
@@ -260,7 +261,7 @@ public class CommonServiceImpl implements ICommonService {
         if(!fYunFileServiceInterface.fileExist(modelOssPath)){
         if(!fYunFileServiceInterface.fileExist(modelOssPath)){
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
             throw new BusinessException(ResultCode.UPLOAD_FILE_ERROR);
         }
         }
-        FileUtil.del(unzipPath);
+        MyFileUtil.del(unzipPath);
         return ossUrlPrefix +  modelOssPath;
         return ossUrlPrefix +  modelOssPath;
     }
     }
 
 
@@ -271,7 +272,7 @@ public class CommonServiceImpl implements ICommonService {
         if(!fYunFileServiceInterface.fileExist(ossPath+"/webcloud/cloud.js")){
         if(!fYunFileServiceInterface.fileExist(ossPath+"/webcloud/cloud.js")){
             throw new BusinessException(-1,"缺少cloud.js文件");
             throw new BusinessException(-1,"缺少cloud.js文件");
         }
         }
-        FileUtil.del(unzipPath);
+        MyFileUtil.del(unzipPath);
         return ossUrlPrefix +  ossPath + "/webcloud";
         return ossUrlPrefix +  ossPath + "/webcloud";
     }
     }