fix:优化回收站全量删除
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.sdm.common.entity.req.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@@ -9,7 +8,6 @@ import java.util.List;
|
||||
@Data
|
||||
@Schema(description = "从回收站彻底删除请求")
|
||||
public class PermanentDeleteFromRecycleReq {
|
||||
@Schema(description = "要彻底删除的文件/目录ID列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "文件/目录ID列表不能为空")
|
||||
@Schema(description = "要彻底删除的文件/目录ID列表(为空则全量删除)")
|
||||
private List<Long> ids;
|
||||
}
|
||||
|
||||
@@ -118,6 +118,7 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
List<FileMetadataInfo> deliverableFileInfoList = fileMetadataInfoService.lambdaQuery()
|
||||
.eq(FileMetadataInfo::getParentId, queryBigFileReq.getDirId())
|
||||
.eq(FileMetadataInfo::getOriginalName, CommonConstants.DELIVERABLE_DIR_NAME)
|
||||
.isNull(FileMetadataInfo::getDeletedAt)
|
||||
.eq(FileMetadataInfo::getTenantId, ThreadLocalContext.getTenantId())
|
||||
.list();
|
||||
if (CollectionUtils.isNotEmpty(deliverableFileInfoList)) {
|
||||
@@ -128,6 +129,7 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
List<FileMetadataInfo> secondDirFileMetadataInfoList = fileMetadataInfoService.lambdaQuery()
|
||||
.eq(FileMetadataInfo::getParentId, deliverableDirId)
|
||||
.eq(FileMetadataInfo::getOriginalName, secondDirName)
|
||||
.isNull(FileMetadataInfo::getDeletedAt)
|
||||
.eq(FileMetadataInfo::getTenantId, ThreadLocalContext.getTenantId())
|
||||
.list();
|
||||
if (CollectionUtils.isNotEmpty(secondDirFileMetadataInfoList)) {
|
||||
@@ -139,6 +141,7 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
List<FileMetadataInfo> fileMetadataInfoList = fileMetadataInfoService.lambdaQuery()
|
||||
.eq(FileMetadataInfo::getParentId, secondDirId)
|
||||
.eq(FileMetadataInfo::getTenantId, ThreadLocalContext.getTenantId())
|
||||
.isNull(FileMetadataInfo::getDeletedAt)
|
||||
.list();
|
||||
PageInfo<FileMetadataInfo> page = new PageInfo<>(fileMetadataInfoList);
|
||||
long total = page.getTotal();
|
||||
|
||||
@@ -4815,17 +4815,28 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SdmResponse permanentDeleteFromRecycle(PermanentDeleteFromRecycleReq req) {
|
||||
if (ObjectUtils.isEmpty(req.getIds())) {
|
||||
return SdmResponse.failed("未选择要删除的文件");
|
||||
List<Long> ids = req.getIds();
|
||||
if (ObjectUtils.isEmpty(ids)) {
|
||||
Long userId = ThreadLocalContext.getUserId();
|
||||
// 查询回收站中的顶层节点(避免对子节点重复触发递归删除)
|
||||
List<FileMetadataInfo> list = fileMetadataInfoService.lambdaQuery()
|
||||
.eq(FileMetadataInfo::getCreatorId, userId)
|
||||
.isNotNull(FileMetadataInfo::getDeletedAt)
|
||||
.apply("(parentId IS NULL OR NOT EXISTS (SELECT 1 FROM file_metadata_info p WHERE p.id = file_metadata_info.parentId AND p.deletedAt IS NOT NULL))")
|
||||
.list();
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return SdmResponse.success("回收站为空");
|
||||
}
|
||||
ids = list.stream().map(FileMetadataInfo::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
for (Long id : req.getIds()) {
|
||||
for (Long id : ids) {
|
||||
SdmResponse resp = permanentDeleteSingleFile(id);
|
||||
if (!resp.isSuccess()) {
|
||||
throw new RuntimeException("删除文件(ID:" + id + ")失败: " + resp.getMessage());
|
||||
}
|
||||
}
|
||||
return SdmResponse.success("批量彻底删除成功");
|
||||
return SdmResponse.success("彻底删除成功");
|
||||
}
|
||||
|
||||
private SdmResponse permanentDeleteSingleFile(Long id) {
|
||||
|
||||
Reference in New Issue
Block a user