فهرست منبع

Merge branch 'feature-lihb-20250610' of http://219.151.181.73:3000/zhuwei/bladex into test-merge-02

LHB 3 ماه پیش
والد
کامیت
dcd5247366

+ 26 - 4
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/PrivateStandardServiceImpl.java

@@ -218,6 +218,8 @@ public class PrivateStandardServiceImpl extends ServiceImpl<PrivateStandardMappe
             e.printStackTrace();
             throw new ServiceException("Oss删除文件失败");
         }
+        //文件集合
+        List<StandardFile> standardFiles = new ArrayList<>();
         try {
 
             // 文件索引计数器
@@ -231,6 +233,16 @@ public class PrivateStandardServiceImpl extends ServiceImpl<PrivateStandardMappe
                     }
                     //先上传文件,上传成功在执行添加
                     if(dto.getFile() != null){
+                        //再去查询当前规范文件是否在数据库中存在未删除的文件
+                        List<StandardFile> list = standardFileService.list(Wrappers.<StandardFile>lambdaQuery()
+                                .eq(StandardFile::getStandardId, dto.getId()));
+                        if(CollectionUtils.isNotEmpty(list)){
+                            //删除文件
+                            for (StandardFile standardFile : standardFiles) {
+                                String pdfName = standardFile.getStandardFileUrl().split("upload")[1];
+                                this.newIOSSClient.removeFile("upload" + pdfName);
+                            }
+                        }
                         MultipartFile file = dto.getFile();
                         StandardFile standardFile = new StandardFile();
                         standardFile.setId(SnowFlakeUtil.getId());
@@ -243,15 +255,16 @@ public class PrivateStandardServiceImpl extends ServiceImpl<PrivateStandardMappe
 
                         //Oss上传 传特殊文件名 在oss中做特殊路径处理
                         BladeFile bladeFile = newIOSSClient.uploadFileByInputStream(multipartFile);
+                        if (bladeFile == null) {
+                            throw new ServiceException("Oss异常");
+                        }
                         standardFile.setStandardFileUrl(bladeFile.getLink());
-
                         //添加新文件
                         standardFileService.save(standardFile);
                     }
                 }
 
 
-
                 //创建数据
                 PrivateStandard privateStandard = BeanUtil.copyProperties(dto, PrivateStandard.class);
                 //修改
@@ -259,8 +272,17 @@ public class PrivateStandardServiceImpl extends ServiceImpl<PrivateStandardMappe
                 return true;
             }
             return false;
-        } catch (IOException e) {
-            throw new RuntimeException(e);
+        } catch (Exception e) {
+            //删除之前上传的文件
+            if(CollectionUtils.isNotEmpty(standardFiles)){
+                for (StandardFile standardFile : standardFiles) {
+                    String pdfName = standardFile.getStandardFileUrl().split("upload")[1];
+                    this.newIOSSClient.removeFile("upload" + pdfName);
+                }
+                throw new ServiceException("Oss异常");
+            }
+            e.printStackTrace();
+            throw new ServiceException("更新失败");
         }
     }
 }