fix:优化标签查询
This commit is contained in:
@@ -2118,7 +2118,9 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
/**
|
||||
* 批量填充文件标签信息到 FileMetadataInfoResp
|
||||
* 从 file_tag_rel 和 simulation_data_dictionary 查询标签,按 dictClass 分组
|
||||
* 格式:disciplineTypeDictClass: DISCIPLINE_TYPE, disciplineDictValue: '流体,机器人,动画'
|
||||
* 格式:
|
||||
* disciplineTypeDictClass: DISCIPLINE_TYPE,
|
||||
* disciplineDictValue: '流体,机器人,动画'
|
||||
*
|
||||
* @param dtoList 文件元数据响应列表
|
||||
*/
|
||||
@@ -2139,12 +2141,14 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 批量查询 file_tag_rel 获取文件对应的 tagId
|
||||
List<FileTagRel> fileTagRels = fileTagRelService.lambdaQuery()
|
||||
.eq(FileTagRel::getTenantId, tenantId)
|
||||
.in(FileTagRel::getFileId, fileIds)
|
||||
.select(FileTagRel::getFileId, FileTagRel::getTagId)
|
||||
.list();
|
||||
// 2. 批量查询 file_tag_rel 获取文件对应的 tagId(数据库层去重)
|
||||
// 注意:因为冗余记录了祖先父目录id,会导致 (fileId, tagId) 组合重复,需要在查询时去重
|
||||
List<FileTagRel> fileTagRels = fileTagRelService.getBaseMapper().selectList(
|
||||
Wrappers.<FileTagRel>query()
|
||||
.select("DISTINCT fileId, tagId")
|
||||
.eq("tenantId", tenantId)
|
||||
.in("fileId", fileIds)
|
||||
);
|
||||
|
||||
if (CollectionUtils.isEmpty(fileTagRels)) {
|
||||
return;
|
||||
@@ -2183,16 +2187,11 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
(v1, v2) -> v1
|
||||
));
|
||||
|
||||
// 6. 构建 fileId -> tagIds 的映射(tagId 去重)
|
||||
// 6. 构建 fileId -> tagIds 的映射(数据库已去重,直接使用 toList)
|
||||
Map<Long, List<Integer>> fileToTagsMap = fileTagRels.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
FileTagRel::getFileId,
|
||||
Collectors.mapping(FileTagRel::getTagId, Collectors.toSet())
|
||||
))
|
||||
.entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
entry -> new ArrayList<>(entry.getValue())
|
||||
Collectors.mapping(FileTagRel::getTagId, Collectors.toList())
|
||||
));
|
||||
|
||||
// 7. 为每个文件填充标签信息
|
||||
@@ -2554,6 +2553,22 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
fileMetadataInfo.setUpdateTime(LocalDateTime.now());
|
||||
fileMetadataInfo.setUpdaterId(ThreadLocalContext.getUserId());
|
||||
fileMetadataInfo.setFileType(req.getFileType());
|
||||
|
||||
//绑定文件和工况库的关系
|
||||
if (CollectionUtils.isNotEmpty(req.getSimulationPoolInfoList())) {
|
||||
// 先删除原先所有的文件绑定关系
|
||||
fileSimulationMappingService.lambdaUpdate().eq(FileSimulationMapping::getFileId, fileMetadataInfo.getId()).remove();
|
||||
for (SimulationPoolInfo simulationPoolInfo : req.getSimulationPoolInfoList()) {
|
||||
for (String simulationPoolTaskId : simulationPoolInfo.getSimulationPoolTaskIds()) {
|
||||
FileSimulationMapping fileSimulationMapping = new FileSimulationMapping();
|
||||
fileSimulationMapping.setFileId(fileMetadataInfo.getId());
|
||||
fileSimulationMapping.setSimulationPoolId(simulationPoolInfo.getSimulationPoolId());
|
||||
fileSimulationMapping.setSimulationPoolVersion(simulationPoolInfo.getSimulationPoolVersion());
|
||||
fileSimulationMapping.setSimulationPoolTaskId(simulationPoolTaskId);
|
||||
fileSimulationMappingService.save(fileSimulationMapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新标签(如果有)
|
||||
if (CollectionUtils.isNotEmpty(req.getDictTags())) {
|
||||
|
||||
Reference in New Issue
Block a user