fix:封装标签查询
This commit is contained in:
@@ -56,4 +56,19 @@ public class BaseResp {
|
||||
@Schema(description= "文件业务类型(1:模型文件 2:仿真报告、3:计算文件、4:曲线文件、5:云图文件,6:网格文件,7:计算过程文件)")
|
||||
@TableField("fileType")
|
||||
private Integer fileType;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// 很重要,用于设置标签
|
||||
@Schema(description = "文件类型字典类")
|
||||
private String fileTypeDictClass;
|
||||
@Schema(description = "文件类型字典值")
|
||||
private String fileTypeDictValue;
|
||||
|
||||
@Schema(description = "学科类型字典类")
|
||||
private String disciplineTypeDictClass;
|
||||
|
||||
@Schema(description = "学科类型字典值")
|
||||
private String disciplineDictValue;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -63,21 +63,6 @@ public class FileMetadataInfoResp extends BaseResp implements Serializable {
|
||||
@Schema(description= "文件业务类型(1:模型文件 2:仿真报告、3:计算文件、4:曲线文件、5:云图文件,6:网格文件,7:计算过程文件)")
|
||||
private Integer fileType;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// 很重要,用于设置标签
|
||||
@Schema(description = "文件类型字典类")
|
||||
private String fileTypeDictClass;
|
||||
@Schema(description = "文件类型字典值")
|
||||
private String fileTypeDictValue;
|
||||
|
||||
@Schema(description = "学科类型字典类")
|
||||
private String disciplineTypeDictClass;
|
||||
|
||||
@Schema(description = "学科类型字典值")
|
||||
private String disciplineDictValue;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
@Schema(description = "数据类型:1-文件,2-文件夹")
|
||||
private Integer dataType;
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.sdm.data.service;
|
||||
|
||||
import com.sdm.data.model.dto.FileDictTagsAggDTO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 文件字典标签聚合查询服务
|
||||
@@ -12,10 +10,14 @@ import java.util.Map;
|
||||
public interface IFileDictTagQueryService {
|
||||
|
||||
/**
|
||||
* 按文件ID批量查询并聚合字典标签
|
||||
* @param fileIds 文件ID列表
|
||||
* @return fileId -> 聚合结果
|
||||
* 泛型方法:为包含标签字段的响应对象列表批量填充文件字典标签
|
||||
* 要求 T 至少包含如下字段的 getter/setter:
|
||||
* - getId()
|
||||
* - setFileTypeDictClass(String)
|
||||
* - setFileTypeDictValue(String)
|
||||
* - setDisciplineTypeDictClass(String)
|
||||
* - setDisciplineDictValue(String)
|
||||
*/
|
||||
Map<Long, FileDictTagsAggDTO> queryByFileIds(List<Long> fileIds);
|
||||
<T> void fillFileTagsForRespList(List<T> respList, Function<T, Long> idGetter);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,7 @@ import com.sdm.data.model.entity.FileStorage;
|
||||
import com.sdm.common.entity.req.data.GetSimulationTaskFileReq;
|
||||
import com.sdm.data.model.req.QueryBigFileReq;
|
||||
import com.sdm.common.entity.resp.data.SimulationTaskResultCurveResp;
|
||||
import com.sdm.data.service.DataStorageAnalysis;
|
||||
import com.sdm.data.service.IDataAnalysisService;
|
||||
import com.sdm.data.service.IFileMetadataInfoService;
|
||||
import com.sdm.data.service.IMinioService;
|
||||
import com.sdm.data.service.*;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@@ -60,6 +57,9 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
@Autowired
|
||||
private ExportOperate exportOperate;
|
||||
|
||||
@Autowired
|
||||
IFileDictTagQueryService fileDictTagQueryService;
|
||||
|
||||
@Override
|
||||
public SdmResponse<PageDataResp<List<SimulationTaskResultCurveResp>>> getSimulationTaskFile(GetSimulationTaskFileReq getSimulationTaskFileReq) {
|
||||
// 1. 构造查询条件
|
||||
@@ -102,6 +102,8 @@ public class DataAnalysisServiceImpl implements IDataAnalysisService {
|
||||
FileMetadataHierarchyHelper::setFileHierarchy
|
||||
);
|
||||
|
||||
fileDictTagQueryService.fillFileTagsForRespList(finalResultList, SimulationTaskResultCurveResp::getId);
|
||||
|
||||
// 4. 构造分页信息并返回
|
||||
PageInfo<FileMetadataInfo> pageInfo = new PageInfo<>();
|
||||
pageInfo.setTotal(pageDataResp.getTotal());
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.sdm.data.model.req.QueryBigFileReq;
|
||||
import com.sdm.data.model.resp.FileStorageQuotaResp;
|
||||
import com.sdm.data.model.resp.ListBigFileResp;
|
||||
import com.sdm.data.service.*;
|
||||
import com.sdm.data.service.IFileDictTagQueryService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
@@ -77,6 +78,9 @@ public class DataStorageAnalysisImpl implements DataStorageAnalysis {
|
||||
@Autowired
|
||||
IFileTagRelService fileTagRelService;
|
||||
|
||||
@Autowired
|
||||
IFileDictTagQueryService fileDictTagQueryService;
|
||||
|
||||
/**
|
||||
* 根据节点类型获取存储空间占用(支持批量查询)
|
||||
*/
|
||||
@@ -442,6 +446,9 @@ public class DataStorageAnalysisImpl implements DataStorageAnalysis {
|
||||
FileMetadataHierarchyHelper::setFileHierarchy
|
||||
);
|
||||
|
||||
// 2.1 批量填充文件字典标签(文件类型、学科类型)
|
||||
fileDictTagQueryService.fillFileTagsForRespList(finalResultList, ListBigFileResp::getId);
|
||||
|
||||
// 3. 构造分页信息并返回
|
||||
PageInfo<FileMetadataInfo> pageInfo = new PageInfo<>();
|
||||
pageInfo.setTotal(pageDataResp.getTotal());
|
||||
@@ -451,6 +458,7 @@ public class DataStorageAnalysisImpl implements DataStorageAnalysis {
|
||||
return PageUtils.getJsonObjectSdmResponse(finalResultList, pageInfo);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SdmResponse<PageDataResp<List<FileStorage>>> listBigFile(QueryBigFileReq queryBigFileReq) {
|
||||
PageInfo<FileStorage> fileStorages = getFileStorages(queryBigFileReq);
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.sdm.data.service.IFileTagRelService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
@@ -31,8 +32,7 @@ public class FileDictTagQueryServiceImpl implements IFileDictTagQueryService {
|
||||
private final IFileTagRelService fileTagRelService;
|
||||
private final ISysConfigFeignClient sysConfigFeignClient;
|
||||
|
||||
@Override
|
||||
public Map<Long, FileDictTagsAggDTO> queryByFileIds(List<Long> fileIds) {
|
||||
private Map<Long, FileDictTagsAggDTO> queryByFileIds(List<Long> fileIds) {
|
||||
if (CollectionUtils.isEmpty(fileIds)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
@@ -135,5 +135,76 @@ public class FileDictTagQueryServiceImpl implements IFileDictTagQueryService {
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void fillFileTagsForRespList(List<T> respList, Function<T, Long> idGetter) {
|
||||
if (CollectionUtils.isEmpty(respList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 收集文件ID
|
||||
List<Long> fileIds = respList.stream()
|
||||
.map(idGetter)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.toList();
|
||||
if (CollectionUtils.isEmpty(fileIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 查询聚合标签
|
||||
Map<Long, FileDictTagsAggDTO> fileIdToTagsMap = queryByFileIds(fileIds);
|
||||
if (MapUtils.isEmpty(fileIdToTagsMap)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 通过反射,将标签字段填充到 Resp 对象中(基于 FileDictTagEnum 的配置)
|
||||
for (T resp : respList) {
|
||||
Long fileId = idGetter.apply(resp);
|
||||
if (fileId == null) {
|
||||
continue;
|
||||
}
|
||||
FileDictTagsAggDTO tags = fileIdToTagsMap.get(fileId);
|
||||
if (tags == null) {
|
||||
continue;
|
||||
}
|
||||
for (FileDictTagEnum tagEnum : FileDictTagEnum.values()) {
|
||||
String dictValues = getDictValuesByEnum(tags, tagEnum);
|
||||
if (dictValues == null) {
|
||||
continue;
|
||||
}
|
||||
String dictClass = tagEnum.getDictClass();
|
||||
String dictClassFieldName = tagEnum.getDictClassFieldName();
|
||||
String dictValueFieldName = tagEnum.getDictValueFieldName();
|
||||
try {
|
||||
// setXxxDictClass
|
||||
String classSetterName = "set" + Character.toUpperCase(dictClassFieldName.charAt(0)) + dictClassFieldName.substring(1);
|
||||
resp.getClass().getMethod(classSetterName, String.class)
|
||||
.invoke(resp, dictClass);
|
||||
// setXxxDictValue
|
||||
String valueSetterName = "set" + Character.toUpperCase(dictValueFieldName.charAt(0)) + dictValueFieldName.substring(1);
|
||||
resp.getClass().getMethod(valueSetterName, String.class)
|
||||
.invoke(resp, dictValues);
|
||||
} catch (Exception e) {
|
||||
log.warn("填充文件标签信息失败, fileId: {}, respClass: {}, dictClass: {}, error: {}",
|
||||
fileId, resp.getClass().getName(), dictClass, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据枚举类型,从聚合结果中取出对应的字典值
|
||||
*/
|
||||
private String getDictValuesByEnum(FileDictTagsAggDTO tags, FileDictTagEnum tagEnum) {
|
||||
if (tags == null || tagEnum == null) {
|
||||
return null;
|
||||
}
|
||||
if (tagEnum == FileDictTagEnum.FILE_TYPE) {
|
||||
return tags.getFileTypeDictValue();
|
||||
} else if (tagEnum == FileDictTagEnum.DISCIPLINE_TYPE) {
|
||||
return tags.getDisciplineDictValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -806,6 +806,11 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
dto.setKnowledgeBaseName(extractRelativePath(fileMetadataInfoService.lambdaQuery().eq(FileMetadataInfo::getId, dto.getParentId()).one()));
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
// 批量填充文件标签信息(仅对文件类型生效)
|
||||
List<FileMetadataInfoResp> fileDtos = dtoList.stream()
|
||||
.filter(dto -> dto != null && dto.getDataType() != null && DataTypeEnum.FILE.getValue() == dto.getDataType())
|
||||
.toList();
|
||||
fileDictTagQueryService.fillFileTagsForRespList(fileDtos, FileMetadataInfoResp::getId);
|
||||
PageDataResp<List<FileStorage>> pageDataResp = searchResult.getData();
|
||||
PageInfo page = new PageInfo();
|
||||
page.setPageNum(pageDataResp.getCurrentPage());
|
||||
@@ -892,7 +897,11 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
return dto;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
fillFileTagsToDtos(dtoList);
|
||||
// 批量填充文件标签信息(仅对文件类型生效)
|
||||
List<FileMetadataInfoResp> fileDtos = dtoList.stream()
|
||||
.filter(dto -> dto != null && dto.getDataType() != null && DataTypeEnum.FILE.getValue() == dto.getDataType())
|
||||
.toList();
|
||||
fileDictTagQueryService.fillFileTagsForRespList(fileDtos, FileMetadataInfoResp::getId);
|
||||
PageInfo<FileMetadataInfoResp> page1 = new PageInfo<>(dtoList);
|
||||
page1.setTotal(total);
|
||||
return PageUtils.getJsonObjectSdmResponse(dtoList, page1);
|
||||
@@ -2117,67 +2126,6 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 批量填充文件标签信息到 dtoList(只处理 dataType=FILE 的 dto)
|
||||
*/
|
||||
private void fillFileTagsToDtos(List<FileMetadataInfoResp> dtoList) {
|
||||
if (CollectionUtils.isEmpty(dtoList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Long> fileIdsForTagQuery = dtoList.stream()
|
||||
.filter(dto -> dto != null && dto.getId() != null && DataTypeEnum.FILE.getValue() == dto.getDataType())
|
||||
.map(FileMetadataInfoResp::getId)
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
Map<Long, FileDictTagsAggDTO> fileIdToTagsMap = fillFileTags(fileIdsForTagQuery);
|
||||
if (MapUtils.isEmpty(fileIdToTagsMap)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (FileMetadataInfoResp dto : dtoList) {
|
||||
if (dto == null || dto.getId() == null || DataTypeEnum.FILE.getValue() != dto.getDataType()) {
|
||||
continue;
|
||||
}
|
||||
FileDictTagsAggDTO tags = fileIdToTagsMap.get(dto.getId());
|
||||
if (tags == null) {
|
||||
continue;
|
||||
}
|
||||
dto.setFileTypeDictClass(tags.getFileTypeDictClass());
|
||||
dto.setFileTypeDictValue(tags.getFileTypeDictValue());
|
||||
dto.setDisciplineTypeDictClass(tags.getDisciplineTypeDictClass());
|
||||
dto.setDisciplineDictValue(tags.getDisciplineDictValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量填充文件标签信息到 FileMetadataInfoResp
|
||||
* 从 file_tag_rel 和 simulation_data_dictionary 查询标签,按 dictClass 分组
|
||||
* 格式:
|
||||
* disciplineTypeDictClass: DISCIPLINE_TYPE,
|
||||
* disciplineDictValue: '流体,机器人,动画'
|
||||
*
|
||||
* @param fileIds 文件ID列表
|
||||
* @return fileId -> 标签聚合结果
|
||||
*/
|
||||
private Map<Long, FileDictTagsAggDTO> fillFileTags(List<Long> fileIds) {
|
||||
if (CollectionUtils.isEmpty(fileIds)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<Long> idList = fileIds.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
if (CollectionUtils.isEmpty(idList)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
Map<Long, FileDictTagsAggDTO> map = fileDictTagQueryService.queryByFileIds(idList);
|
||||
return MapUtils.isEmpty(map) ? Collections.emptyMap() : map;
|
||||
}
|
||||
|
||||
private void bindSimulationPool(UploadFilesReq req, FileMetadataInfo fileInfo) {
|
||||
if (CollectionUtils.isEmpty(req.getSimulationPoolInfoList())) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user