id数据类型调整

This commit is contained in:
2025-10-31 13:48:13 +08:00
parent d259059620
commit e606a85203
13 changed files with 124 additions and 50 deletions

View File

@@ -77,7 +77,7 @@ public class DataFileController implements IDataFeignClient {
*/
@PostMapping("/fileSearch")
@Operation(summary = "搜索文件", description = "根据搜索条件查找匹配的文件")
public SdmResponse fileSearch( @RequestBody @Validated FileSearchReq req) {
public SdmResponse fileSearch(@RequestBody @Validated FileSearchReq req) {
return IDataFileService.fileSearch(req);
}
@@ -152,6 +152,7 @@ public class DataFileController implements IDataFeignClient {
public SdmResponse updatePermission(@RequestBody @Validated UpdatePermissionReq req) {
return IDataFileService.updatePermission(req);
}
/**
* 获取文件用户的综合访问权限,该权限可以从祖先继承
*
@@ -265,7 +266,6 @@ public class DataFileController implements IDataFeignClient {
}
/**
* 上传文件
*
@@ -328,19 +328,19 @@ public class DataFileController implements IDataFeignClient {
@GetMapping("/listDir")
@Operation(summary = "获取文件夹列表", description = "获取文件夹列表")
@ApiResponse(content = @Content(mediaType = "application/json", schema = @Schema(implementation = FileMetadataInfo.class)))
public SdmResponse<List<FileMetadataInfoResp>> listDir(@Parameter(description = "父目录ID或路径") @RequestParam(value = "parentDirId", required = false) Long parentDirId) {
return IDataFileService.listDir(parentDirId);
public SdmResponse<List<FileMetadataInfoResp>> listDir(
@Parameter(name = "文件夹类型DirType1 知识库文件夹2 项目节点文件夹3 头像库文件夹4 仿真参数库文件夹,5 训练模型文件夹") @RequestParam(value = "dirType") Integer dirType
, @Parameter(description = "父目录ID或路径") @RequestParam(value = "parentDirId", required = false) Long parentDirId) {
return IDataFileService.listDir(dirType, parentDirId);
}
@PostMapping(value = "/uploadAvatar")
@Operation(summary = "上传头像", description = "上传头像")
public SdmResponse uploadAvatar(@RequestParam("avatar") MultipartFile avatar){
public SdmResponse uploadAvatar(@RequestParam("avatar") MultipartFile avatar) {
return IDataFileService.uploadAvatar(avatar);
}
// 图片预览
@GetMapping("/previewImage")
@Operation(summary = "图片预览", description = "图片预览")

View File

@@ -64,7 +64,7 @@ public class FileMetadataInfo implements Serializable {
@TableField("originalName")
private String originalName;
@ApiModelProperty(value = "文件夹数据类型仅文件夹有效data_type=2时非空")
@ApiModelProperty(value = "文件夹数据类型仅文件夹有效data_type=2时非空 1 知识库文件夹2 项目节点文件夹3 头像库文件夹4 仿真参数库文件夹,5 训练模型文件夹")
@TableField("dirType")
private Integer dirType;

View File

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -140,4 +142,14 @@ public class TrainingModel implements Serializable {
@ApiModelProperty(value = "说明")
@TableField("description")
private String description;
@ApiModelProperty(value = "创建时间")
@TableField("createTime")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
@ApiModelProperty(value = "更新时间")
@TableField("updateTime")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
}

View File

@@ -193,10 +193,12 @@ public interface IDataFileService {
/**
* 目录树查询
*
* @param dirType
* @param parentDirId 父目录ID
* @return 目录内容列表响应
*/
default SdmResponse<List<FileMetadataInfoResp>> listDir(Long parentDirId){
default SdmResponse<List<FileMetadataInfoResp>> listDir(Integer dirType, Long parentDirId){
return null;
}

View File

@@ -51,6 +51,7 @@ import java.util.stream.Collectors;
@Service
public class MinioFileIDataFileServiceImpl implements IDataFileService {
private static final List<Constants.DirType> INIT_DIR = List.of(
Constants.DirType.KNOWLEDGE_BASE_DIR, Constants.DirType.PROJECT_NODE_DIR,
Constants.DirType.AVATAR_DIR, Constants.DirType.SIMULATION_PARAMETER_DIR, Constants.DirType.TRAIN_MODEL_DIR);
@@ -109,21 +110,42 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
*/
public SdmResponse<?> createRootDir(CreateDirReq req) {
if(ObjectUtils.isNull(req.getDirType())){
return SdmResponse.failed("请选择目录类型:1 知识库文件夹2 项目节点文件夹3 头像库文件夹4 仿真参数库文件夹,5 训练模型文件夹");
}
Constants.DirType dirTypeByValue = Constants.DirType.getDirTypeByValue(req.getDirType());
if (dirTypeByValue == null) {
return SdmResponse.failed("请选择正确的目录类型:1 知识库文件夹2 项目节点文件夹3 头像库文件夹4 仿真参数库文件夹,5 训练模型文件夹");
}
// 先检查根目录是否已存在
String rootDirMinioObjectKey = getDirMinioObjectKey(dirTypeByValue.getDirName());
Optional<FileMetadataInfo> fileMetadataInfoByObjectKey = getFileMetadataInfoByObjectKey(rootDirMinioObjectKey);
// 检查目录是否已存在
if (!fileMetadataInfoByObjectKey.isPresent()) {
return SdmResponse.failed("知识库、项目根目录不存在,等待initSystemDirectory 初始化完成");
}
// 获取根目录的 id
FileMetadataInfo rootDirMetadataInfo = fileMetadataInfoByObjectKey.get();
Long rootDirId = rootDirMetadataInfo.getId();
String dirName = req.getDirName();
String dirMinioObjectKey = getDirMinioObjectKey(dirName);
String dirMinioObjectKey = getDirMinioObjectKey(rootDirMetadataInfo.getObjectKey()+dirName);
Long nodeId = req.getNodeId();
try {
// 检查目录是否已存在
if (getFileMetadataInfoByObjectKey(dirMinioObjectKey).isPresent()) {
return SdmResponse.failed("目录已存在");
return SdmResponse.failed("目录已存在");
}
// 在MinIO中创建目录
minioService.createDirectoryByObjectKey(dirMinioObjectKey);
// 创建目录元数据并保存到数据库
FileMetadataInfo dirInfo = createDirectoryMetadata(dirMinioObjectKey, dirName, true, null, nodeId,req.getDirType());
FileMetadataInfo dirInfo = createDirectoryMetadata(dirMinioObjectKey, dirName, false, rootDirId, nodeId,req.getDirType());
fileMetadataInfoService.save(dirInfo);
// 创建默认权限记录
@@ -180,7 +202,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
minioService.createDirectoryByObjectKey(childDirMinioObjectKey);
// 创建子目录元数据并保存到数据库
FileMetadataInfo dirInfo = createDirectoryMetadata(childDirMinioObjectKey, req.getDirName(), false, parDirId, req.getNodeId(),req.getDirType());
FileMetadataInfo dirInfo = createDirectoryMetadata(childDirMinioObjectKey, req.getDirName(), false, parDirId, req.getNodeId(),parDirInfo.getDirType());
fileMetadataInfoService.save(dirInfo);
// 创建默认权限记录
@@ -305,7 +327,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
return dirPath;
}
private static String dealFileMinioObjectKey(String filePath) {
private static String getFileMinioObjectKey(String filePath) {
if (filePath.startsWith("/")) {
filePath = filePath.substring(1);
}
@@ -774,7 +796,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
return SdmResponse.failed("文件名没有后缀");
}
String fileMinioObjectKey = dealFileMinioObjectKey(dirMetadataInfo.getObjectKey() + modifiedFileName);
String fileMinioObjectKey = getFileMinioObjectKey(dirMetadataInfo.getObjectKey() + modifiedFileName);
boolean hasUploadPermission = fileUserPermissionService.hasFilePermission(dirMetadataInfo.getId(), ThreadLocalContext.getUserId(), Constants.FilePermission.UPLOAD);
@@ -837,11 +859,31 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
}
@Override
public SdmResponse<List<FileMetadataInfoResp>> listDir(Long parentDirId) {
public SdmResponse<List<FileMetadataInfoResp>> listDir(Integer dirType, Long parentDirId) {
try {
if(ObjectUtils.isNull(dirType)){
return SdmResponse.failed("请选择目录类型:1 知识库文件夹2 项目节点文件夹3 头像库文件夹4 仿真参数库文件夹,5 训练模型文件夹");
}
Constants.DirType dirTypeByValue = Constants.DirType.getDirTypeByValue(dirType);
if (dirTypeByValue == null) {
return SdmResponse.failed("请选择正确的目录类型:1 知识库文件夹2 项目节点文件夹3 头像库文件夹4 仿真参数库文件夹,5 训练模型文件夹");
}
// 先检查根目录是否已存在
String rootDirMinioObjectKey = getDirMinioObjectKey(dirTypeByValue.getDirName());
Optional<FileMetadataInfo> fileMetadataInfoByObjectKey = getFileMetadataInfoByObjectKey(rootDirMinioObjectKey);
// 检查目录是否已存在
if (!fileMetadataInfoByObjectKey.isPresent()) {
return SdmResponse.failed("知识库、项目根目录不存在,等待initSystemDirectory 初始化完成");
}
// 获取根目录的 id
Long rootDirId = fileMetadataInfoByObjectKey.get().getId();
LambdaQueryChainWrapper<FileMetadataInfo> fileMetadataInfoLambdaQueryChainWrapper = fileMetadataInfoService.lambdaQuery();
if (ObjectUtils.isEmpty(parentDirId)) {
fileMetadataInfoLambdaQueryChainWrapper.isNull(FileMetadataInfo::getParentId);
fileMetadataInfoLambdaQueryChainWrapper.eq(FileMetadataInfo::getDirType, dirType).eq(FileMetadataInfo::getParentId, rootDirId);
} else {
fileMetadataInfoLambdaQueryChainWrapper.eq(FileMetadataInfo::getParentId, parentDirId);
}
@@ -909,7 +951,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
}
// 处理历史版本objectkey= 1/test1_V1.txt originalName=test1.txt 替换为 newFileMinioObjectKey= 1/test1_V2.txt
newFileMinioObjectKey = dealFileMinioObjectKey(oldFileMinioObjectKey.substring(0, oldFileMinioObjectKey.lastIndexOf(fileMetadataInfo.getOriginalName().substring(0, fileMetadataInfo.getOriginalName().lastIndexOf('.')))) + modifiedFileName);
newFileMinioObjectKey = getFileMinioObjectKey(oldFileMinioObjectKey.substring(0, oldFileMinioObjectKey.lastIndexOf(fileMetadataInfo.getOriginalName().substring(0, fileMetadataInfo.getOriginalName().lastIndexOf('.')))) + modifiedFileName);
minioService.uploadFile(req.getFile(), newFileMinioObjectKey, null);
@@ -990,7 +1032,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
String newFilename = filenameWithoutSuffix + "_" + timestamp + "." + suffix;
// 再上传头像
String avatarMinioObjectKey = dealFileMinioObjectKey(avatarDirMetadataInfo.getObjectKey() + newFilename);
String avatarMinioObjectKey = getFileMinioObjectKey(avatarDirMetadataInfo.getObjectKey() + newFilename);
try {
minioService.uploadFile(avatar, avatarMinioObjectKey, null);
@@ -1051,7 +1093,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
String newFilename = filenameWithoutSuffix + "_" + timestamp + "." + suffix;
// 再上传仿真参数文件
String simulationParamMinioObjectKey = dealFileMinioObjectKey(SimulationParamDirMetadataInfo.getObjectKey() + newFilename);
String simulationParamMinioObjectKey = getFileMinioObjectKey(SimulationParamDirMetadataInfo.getObjectKey() + newFilename);
try {
minioService.uploadFile(paramFile, simulationParamMinioObjectKey, null);
@@ -1097,7 +1139,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
String newFilename = filenameWithoutSuffix + "_" + timestamp + "." + suffix;
// 再上传训练模型文件
String simulationParamMinioObjectKey = dealFileMinioObjectKey(trainModelDirMetadataInfo.getObjectKey() + newFilename);
String simulationParamMinioObjectKey = getFileMinioObjectKey(trainModelDirMetadataInfo.getObjectKey() + newFilename);
try {
minioService.uploadFile(trainModelFile, simulationParamMinioObjectKey, null);

View File

@@ -160,7 +160,7 @@ public class ModelServiceImpl implements IModelService {
@Override
public SdmResponse getModelList(BaseReq baseReq) {
PageHelper.startPage(baseReq.getCurrent(), baseReq.getSize());
List<TrainingModel> models = trainingModelService.list();
List<TrainingModel> models = trainingModelService.lambdaQuery().orderByDesc(TrainingModel::getCreateTime).list();
PageInfo<TrainingModel> page = new PageInfo<>(models);
return PageUtils.getJsonObjectSdmResponse(models, page);
}