fix:数据总览支持基于tag返回标签信息
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package com.sdm.common.entity.req.data;
|
package com.sdm.common.entity.req.data;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
@@ -16,36 +15,72 @@ public class TagReq {
|
|||||||
@Schema(description = "标签1")
|
@Schema(description = "标签1")
|
||||||
private String tag1;
|
private String tag1;
|
||||||
|
|
||||||
|
@Schema(description = "标签1名称")
|
||||||
|
private String tag1Name;
|
||||||
|
|
||||||
@Schema(description = "标签2")
|
@Schema(description = "标签2")
|
||||||
private String tag2;
|
private String tag2;
|
||||||
|
|
||||||
|
@Schema(description = "标签2名称")
|
||||||
|
private String tag2Name;
|
||||||
|
|
||||||
@Schema(description = "标签3")
|
@Schema(description = "标签3")
|
||||||
private String tag3;
|
private String tag3;
|
||||||
|
|
||||||
|
@Schema(description = "标签3名称")
|
||||||
|
private String tag3Name;
|
||||||
|
|
||||||
@Schema(description = "标签4")
|
@Schema(description = "标签4")
|
||||||
private String tag4;
|
private String tag4;
|
||||||
|
|
||||||
|
@Schema(description = "标签4名称")
|
||||||
|
private String tag4Name;
|
||||||
|
|
||||||
@Schema(description = "标签5")
|
@Schema(description = "标签5")
|
||||||
private String tag5;
|
private String tag5;
|
||||||
|
|
||||||
|
@Schema(description = "标签5名称")
|
||||||
|
private String tag5Name;
|
||||||
|
|
||||||
@Schema(description = "标签6")
|
@Schema(description = "标签6")
|
||||||
private String tag6;
|
private String tag6;
|
||||||
|
|
||||||
|
@Schema(description = "标签6名称")
|
||||||
|
private String tag6Name;
|
||||||
|
|
||||||
@Schema(description = "标签7")
|
@Schema(description = "标签7")
|
||||||
private String tag7;
|
private String tag7;
|
||||||
|
|
||||||
|
@Schema(description = "标签7名称")
|
||||||
|
private String tag7Name;
|
||||||
|
|
||||||
@Schema(description = "标签8")
|
@Schema(description = "标签8")
|
||||||
private String tag8;
|
private String tag8;
|
||||||
|
|
||||||
|
@Schema(description = "标签8名称")
|
||||||
|
private String tag8Name;
|
||||||
|
|
||||||
@Schema(description = "标签9")
|
@Schema(description = "标签9")
|
||||||
private String tag9;
|
private String tag9;
|
||||||
|
|
||||||
|
@Schema(description = "标签9名称")
|
||||||
|
private String tag9Name;
|
||||||
|
|
||||||
@Schema(description = "标签10")
|
@Schema(description = "标签10")
|
||||||
private String tag10;
|
private String tag10;
|
||||||
|
|
||||||
|
@Schema(description = "标签10名称")
|
||||||
|
private String tag10Name;
|
||||||
|
|
||||||
@Schema(description= "任务ID")
|
@Schema(description= "任务ID")
|
||||||
private String taskId;
|
private String taskId;
|
||||||
|
|
||||||
|
@Schema(description= "任务名称")
|
||||||
|
private String taskName;
|
||||||
|
|
||||||
@Schema(description= "算例ID")
|
@Schema(description= "算例ID")
|
||||||
private String runId;
|
private String runId;
|
||||||
|
|
||||||
|
@Schema(description= "算例名称")
|
||||||
|
private String runName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.sdm.data.model.dto;
|
package com.sdm.data.model.dto;
|
||||||
|
|
||||||
import com.sdm.common.entity.resp.data.FileMetadataInfoResp;
|
import com.sdm.common.entity.resp.data.FileMetadataInfoResp;
|
||||||
import com.sdm.common.entity.resp.project.SimulationRunResp;
|
import com.sdm.common.entity.req.data.TagReq;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
@@ -23,4 +23,7 @@ public class FileMetadataChildrenDTO extends FileMetadataInfoResp {
|
|||||||
|
|
||||||
@Schema(description = "总名称(去除projectNode/前缀的bucketName)")
|
@Schema(description = "总名称(去除projectNode/前缀的bucketName)")
|
||||||
private String totalName;
|
private String totalName;
|
||||||
|
|
||||||
|
@Schema(description = "标签信息")
|
||||||
|
private TagReq tagReq;
|
||||||
}
|
}
|
||||||
@@ -347,22 +347,18 @@ public class DimensionTemplateServiceImpl extends ServiceImpl<DimensionTemplateM
|
|||||||
List<FileMetadataInfo> group = entry.getValue();
|
List<FileMetadataInfo> group = entry.getValue();
|
||||||
|
|
||||||
if (!group.isEmpty()) {
|
if (!group.isEmpty()) {
|
||||||
FileMetadataHierarchyHelper.FileHierarchyResult filesWithParentCache = hierarchyHelper.getFilesWithParentCache(group.stream().map(FileMetadataInfo::getId).toList());
|
|
||||||
Map<Long, FileMetadataInfo> parentCacheMap = filesWithParentCache.getParentCacheMap();
|
|
||||||
|
|
||||||
|
|
||||||
// 使用第一个作为基础对象
|
// 使用第一个作为基础对象
|
||||||
FileMetadataInfo baseInfo = group.get(0);
|
FileMetadataInfo baseInfo = group.get(0);
|
||||||
|
|
||||||
// 创建包含children的DTO对象
|
// 创建包含children的DTO对象
|
||||||
FileMetadataChildrenDTO dto = FileMetadataConvert.INSTANCE.convertToFileMetadataChildrenDTO(baseInfo);
|
FileMetadataChildrenDTO dto = FileMetadataConvert.INSTANCE.convertToFileMetadataChildrenDTO(baseInfo);
|
||||||
hierarchyHelper.backtrackAndSetHierarchy(baseInfo, parentCacheMap, dto, FileMetadataHierarchyHelper::setFileHierarchy);
|
hierarchyHelper.setTagReqFromFileMetadata(baseInfo, dto);
|
||||||
|
|
||||||
// 转换children列表,并为每个child设置totalName
|
// 转换children列表,并为每个child设置totalName
|
||||||
List<FileMetadataInfoResp> children = new ArrayList<>();
|
List<FileMetadataInfoResp> children = new ArrayList<>();
|
||||||
for (FileMetadataInfo fileInfo : group) {
|
for (FileMetadataInfo fileInfo : group) {
|
||||||
FileMetadataChildrenDTO childDto = FileMetadataConvert.INSTANCE.convertToFileMetadataChildrenDTO(fileInfo);
|
FileMetadataChildrenDTO childDto = FileMetadataConvert.INSTANCE.convertToFileMetadataChildrenDTO(fileInfo);
|
||||||
hierarchyHelper.backtrackAndSetHierarchy(fileInfo, parentCacheMap, childDto, FileMetadataHierarchyHelper::setFileHierarchy);
|
hierarchyHelper.setTagReqFromFileMetadata(fileInfo, childDto);
|
||||||
// 设置totalName(从bucketName中提取)
|
// 设置totalName(从bucketName中提取)
|
||||||
String objectKey = fileInfo.getObjectKey();
|
String objectKey = fileInfo.getObjectKey();
|
||||||
String baseDirPath = DirTypeEnum.PROJECT_NODE_DIR.getDirName() + "/";
|
String baseDirPath = DirTypeEnum.PROJECT_NODE_DIR.getDirName() + "/";
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ import com.sdm.data.model.entity.FileMetadataInfo;
|
|||||||
import com.sdm.data.service.IFileMetadataInfoService;
|
import com.sdm.data.service.IFileMetadataInfoService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -275,50 +275,8 @@ public class FileMetadataHierarchyHelper {
|
|||||||
void setHierarchyInfo(T resp, FileMetadataInfo folder, String ownType);
|
void setHierarchyInfo(T resp, FileMetadataInfo folder, String ownType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================ 预定义的层级信息设置器 ================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SimulationTaskResultCurveResp 的层级设置器
|
|
||||||
* 设置 projectName/projectId, phaseName/phaseId, disciplineName/disciplineId
|
|
||||||
*/
|
|
||||||
public static <T> void setSimulationTaskHierarchy(T resp, FileMetadataInfo folder, String ownType) {
|
|
||||||
try {
|
|
||||||
if (NodeTypeEnum.PROJECT.getValue().equals(ownType)) {
|
|
||||||
resp.getClass().getMethod("setProjectName", String.class).invoke(resp, folder.getOriginalName());
|
|
||||||
resp.getClass().getMethod("setProjectId", String.class).invoke(resp, folder.getRelatedResourceUuid());
|
|
||||||
} else if (NodeTypeEnum.PHASE.getValue().equals(ownType)) {
|
|
||||||
resp.getClass().getMethod("setPhaseName", String.class).invoke(resp, folder.getOriginalName());
|
|
||||||
resp.getClass().getMethod("setPhaseId", String.class).invoke(resp, folder.getRelatedResourceUuid());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("设置SimulationTask层级信息失败", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ListBigFileResp 的层级设置器
|
|
||||||
* 设置 ownProjectName/ownProjectId, ownPhaseName/ownPhaseId,
|
|
||||||
* ownDisciplineName/ownDisciplineId, owntaskName/owntaskId, ownRunName/ownRunId
|
|
||||||
*/
|
|
||||||
public static <T> void setListBigFileHierarchy(T resp, FileMetadataInfo folder, String ownType) {
|
|
||||||
try {
|
|
||||||
if (NodeTypeEnum.PROJECT.getValue().equals(ownType)) {
|
|
||||||
resp.getClass().getMethod("setOwnProjectName", String.class).invoke(resp, folder.getOriginalName());
|
|
||||||
resp.getClass().getMethod("setOwnProjectId", String.class).invoke(resp, folder.getRelatedResourceUuid());
|
|
||||||
} else if (NodeTypeEnum.PHASE.getValue().equals(ownType)) {
|
|
||||||
resp.getClass().getMethod("setOwnPhaseName", String.class).invoke(resp, folder.getOriginalName());
|
|
||||||
resp.getClass().getMethod("setOwnPhaseId", String.class).invoke(resp, folder.getRelatedResourceUuid());
|
|
||||||
} else if (NodeTypeEnum.TASK.getValue().equals(ownType)) {
|
|
||||||
resp.getClass().getMethod("setOwntaskName", String.class).invoke(resp, folder.getOriginalName());
|
|
||||||
resp.getClass().getMethod("setOwntaskId", String.class).invoke(resp, folder.getRelatedResourceUuid());
|
|
||||||
} else if (NodeTypeEnum.RUN.getValue().equals(ownType)) {
|
|
||||||
resp.getClass().getMethod("setOwnRunName", String.class).invoke(resp, folder.getOriginalName());
|
|
||||||
resp.getClass().getMethod("setOwnRunId", String.class).invoke(resp, folder.getRelatedResourceUuid());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("设置ListBigFile层级信息失败", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> void setFileHierarchy(T resp, FileMetadataInfo folder, String ownType) {
|
public static <T> void setFileHierarchy(T resp, FileMetadataInfo folder, String ownType) {
|
||||||
try {
|
try {
|
||||||
@@ -346,4 +304,97 @@ public class FileMetadataHierarchyHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 直接使用FileMetadataInfo中已存储的tag1~tag10、taskId、runId构建并设置tagReq
|
||||||
|
* 并基于relatedResourceUuid查询对应originalName填充tagName/taskName/runName
|
||||||
|
*/
|
||||||
|
public <T> void setTagReqFromFileMetadata(FileMetadataInfo file, T resp) {
|
||||||
|
if (Objects.isNull(file) || Objects.isNull(resp)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Class<?> tagReqClass = Class.forName("com.sdm.common.entity.req.data.TagReq");
|
||||||
|
Object tagReq = tagReqClass.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
List<String> tagValues = new ArrayList<>();
|
||||||
|
for (int i = 1; i <= 10; i++) {
|
||||||
|
Object tagValue = FileMetadataInfo.class.getMethod("getTag" + i).invoke(file);
|
||||||
|
String value = Objects.toString(tagValue, null);
|
||||||
|
tagValues.add(value);
|
||||||
|
tagReqClass.getMethod("setTag" + i, String.class).invoke(tagReq, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskId = file.getTaskId();
|
||||||
|
String runId = file.getRunId();
|
||||||
|
tagReqClass.getMethod("setTaskId", String.class).invoke(tagReq, taskId);
|
||||||
|
tagReqClass.getMethod("setRunId", String.class).invoke(tagReq, runId);
|
||||||
|
|
||||||
|
Set<String> relatedUuids = new HashSet<>();
|
||||||
|
for (String tagValue : tagValues) {
|
||||||
|
parseUuidChain(tagValue).forEach(relatedUuids::add);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(taskId)) {
|
||||||
|
relatedUuids.add(taskId);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(runId)) {
|
||||||
|
relatedUuids.add(runId);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> uuidNameMap = new HashMap<>();
|
||||||
|
if (CollectionUtils.isNotEmpty(relatedUuids)) {
|
||||||
|
List<FileMetadataInfo> tagNameFiles = fileMetadataInfoService.lambdaQuery()
|
||||||
|
.eq(FileMetadataInfo::getTenantId, ThreadLocalContext.getTenantId())
|
||||||
|
.in(FileMetadataInfo::getRelatedResourceUuid, relatedUuids)
|
||||||
|
.isNull(FileMetadataInfo::getDeletedAt)
|
||||||
|
.list();
|
||||||
|
|
||||||
|
uuidNameMap = tagNameFiles.stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(item -> StringUtils.isNotBlank(item.getRelatedResourceUuid()))
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
FileMetadataInfo::getRelatedResourceUuid,
|
||||||
|
FileMetadataInfo::getOriginalName,
|
||||||
|
(left, right) -> left
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= 10; i++) {
|
||||||
|
String tagValue = tagValues.get(i - 1);
|
||||||
|
String currentUuid = getLastUuid(tagValue);
|
||||||
|
String tagName = uuidNameMap.get(currentUuid);
|
||||||
|
tagReqClass.getMethod("setTag" + i + "Name", String.class).invoke(tagReq, tagName);
|
||||||
|
}
|
||||||
|
tagReqClass.getMethod("setTaskName", String.class).invoke(tagReq, uuidNameMap.get(taskId));
|
||||||
|
tagReqClass.getMethod("setRunName", String.class).invoke(tagReq, uuidNameMap.get(runId));
|
||||||
|
|
||||||
|
resp.getClass().getMethod("setTagReq", tagReqClass).invoke(resp, tagReq);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("设置tagReq失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析逗号拼接的uuid链
|
||||||
|
*/
|
||||||
|
private List<String> parseUuidChain(String uuidChain) {
|
||||||
|
if (StringUtils.isBlank(uuidChain)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return Arrays.stream(uuidChain.split(","))
|
||||||
|
.map(String::trim)
|
||||||
|
.filter(StringUtils::isNotBlank)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取逗号拼接uuid链中的最后一个uuid(当前节点)
|
||||||
|
*/
|
||||||
|
private String getLastUuid(String uuidChain) {
|
||||||
|
List<String> uuids = parseUuidChain(uuidChain);
|
||||||
|
if (CollectionUtils.isEmpty(uuids)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return uuids.get(uuids.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user