fix:批量同步节点下的普通文件夹
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.sdm.common.entity.req.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "批量创建普通文件夹请求参数")
|
||||
public class BatchCreateNormalDirReq {
|
||||
|
||||
@NotNull(message = "父节点UUID")
|
||||
@Schema(description = "父节点UUID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String parentUUId;
|
||||
|
||||
@NotNull(message = "父节点对应的文件夹ID")
|
||||
@Schema(description = "父节点对应的文件夹ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Long parentId;
|
||||
|
||||
@NotEmpty(message = "文件夹名称列表不能为空")
|
||||
@Schema(description = "待创建的文件夹名称列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<String> folderNames;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.sdm.common.entity.resp.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "批量创建普通文件夹响应结果")
|
||||
public class BatchCreateNormalDirResp {
|
||||
|
||||
@Schema(description = "创建成功的文件夹列表")
|
||||
private List<DirInfo> successList = new ArrayList<>();
|
||||
|
||||
@Schema(description = "创建失败的文件夹列表")
|
||||
private List<FailureInfo> failureList = new ArrayList<>();
|
||||
|
||||
public void addSuccess(Long id, String name) {
|
||||
this.successList.add(new DirInfo(id, name));
|
||||
}
|
||||
|
||||
public void addFailure(String name, String reason) {
|
||||
this.failureList.add(new FailureInfo(name, reason));
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class DirInfo {
|
||||
@Schema(description = "文件夹ID")
|
||||
private Long id;
|
||||
@Schema(description = "文件夹名称")
|
||||
private String name;
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class FailureInfo {
|
||||
@Schema(description = "文件夹名称")
|
||||
private String name;
|
||||
@Schema(description = "失败原因")
|
||||
private String reason;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.sdm.common.entity.req.data.*;
|
||||
import com.sdm.common.entity.req.system.LaunchApproveReq;
|
||||
import com.sdm.common.entity.resp.PageDataResp;
|
||||
import com.sdm.common.entity.resp.data.BatchAddFileInfoResp;
|
||||
import com.sdm.common.entity.resp.data.BatchCreateNormalDirResp;
|
||||
import com.sdm.common.entity.resp.data.FileMetadataInfoResp;
|
||||
import com.sdm.common.feign.inter.data.IDataFeignClient;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -198,6 +199,19 @@ public class DataClientFeignClientImpl implements IDataFeignClient {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse<BatchCreateNormalDirResp> batchCreateNormalDirs(BatchCreateNormalDirReq req) {
|
||||
SdmResponse<BatchCreateNormalDirResp> response;
|
||||
try {
|
||||
response = dataClient.batchCreateNormalDirs(req);
|
||||
log.info("批量创建普通文件夹响应:"+ response);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.error("批量创建普通文件夹失败", e);
|
||||
return SdmResponse.failed("批量创建普通文件夹失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse updatePermission(UpdatePermissionReq req) {
|
||||
SdmResponse response;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.sdm.common.entity.req.data.*;
|
||||
import com.sdm.common.entity.req.system.LaunchApproveReq;
|
||||
import com.sdm.common.entity.resp.PageDataResp;
|
||||
import com.sdm.common.entity.resp.data.BatchAddFileInfoResp;
|
||||
import com.sdm.common.entity.resp.data.BatchCreateNormalDirResp;
|
||||
import com.sdm.common.entity.resp.data.FileMetadataInfoResp;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@@ -30,6 +31,9 @@ public interface IDataFeignClient {
|
||||
@PostMapping("/data/batchCreateDir")
|
||||
SdmResponse<List<Long>> batchCreateDir(@RequestBody @Validated BatchCreateDirReq req);
|
||||
|
||||
@PostMapping("/data/batchCreateNormalDirs")
|
||||
SdmResponse<BatchCreateNormalDirResp> batchCreateNormalDirs(@RequestBody @Validated BatchCreateNormalDirReq req);
|
||||
|
||||
@PostMapping("/data/queryDir")
|
||||
SdmResponse<PageDataResp<List<FileMetadataInfoResp>>> queryDir(@RequestBody @Validated QueryDirReq req);
|
||||
|
||||
@@ -102,5 +106,4 @@ public interface IDataFeignClient {
|
||||
|
||||
@PostMapping("/data/copyFileToTask")
|
||||
SdmResponse copyFileToTask(@RequestBody CopyFileToTaskReq req);
|
||||
|
||||
}
|
||||
|
||||
@@ -3828,7 +3828,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SdmResponse<BatchCreateNormalDirResp> batchCreateNormalDirs(BatchCreateNormalDirReq req) {
|
||||
// 1. 基础校验
|
||||
if (req.getParentId() == null) {
|
||||
if (req.getParentUUId() == null) {
|
||||
return SdmResponse.failed("父文件夹ID不能为空");
|
||||
}
|
||||
if (CollectionUtils.isEmpty(req.getFolderNames())) {
|
||||
@@ -3836,13 +3836,15 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
}
|
||||
|
||||
// 2. 父目录校验与权限检查
|
||||
FileMetadataInfo parentDir = fileMetadataInfoService.getById(req.getParentId());
|
||||
FileMetadataInfo parentDir = fileMetadataInfoService.lambdaQuery()
|
||||
.eq(FileMetadataInfo::getRelatedResourceUuid, req.getParentUUId())
|
||||
.one();
|
||||
if (parentDir == null) {
|
||||
return SdmResponse.failed("父文件夹不存在");
|
||||
}
|
||||
|
||||
// 权限检查(需要写入权限)
|
||||
boolean hasWritePermission = fileUserPermissionService.hasFilePermission(req.getParentId(), ThreadLocalContext.getUserId(), FilePermissionEnum.WRITE);
|
||||
boolean hasWritePermission = fileUserPermissionService.hasFilePermission(parentDir.getId(), ThreadLocalContext.getUserId(), FilePermissionEnum.WRITE);
|
||||
if (!hasWritePermission) {
|
||||
return SdmResponse.failed("没有写入权限");
|
||||
}
|
||||
@@ -3860,7 +3862,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
|
||||
// 3. 检查数据库中是否已存在同名目录
|
||||
List<FileMetadataInfo> existingFiles = fileMetadataInfoService.lambdaQuery()
|
||||
.eq(FileMetadataInfo::getParentId, req.getParentId())
|
||||
.eq(FileMetadataInfo::getParentId, parentDir.getId())
|
||||
.eq(FileMetadataInfo::getTenantId, ThreadLocalContext.getTenantId())
|
||||
.eq(FileMetadataInfo::getDataType, DataTypeEnum.DIRECTORY.getValue())
|
||||
.in(FileMetadataInfo::getOriginalName, validFolderNames)
|
||||
|
||||
Reference in New Issue
Block a user