diff --git a/headless/api/src/main/java/com/tencent/supersonic/headless/api/pojo/response/MetricResp.java b/headless/api/src/main/java/com/tencent/supersonic/headless/api/pojo/response/MetricResp.java index e92752ec1..d41b5f4d3 100644 --- a/headless/api/src/main/java/com/tencent/supersonic/headless/api/pojo/response/MetricResp.java +++ b/headless/api/src/main/java/com/tencent/supersonic/headless/api/pojo/response/MetricResp.java @@ -61,6 +61,8 @@ public class MetricResp extends SchemaItem { private MetricDefineByMetricParams metricDefineByMetricParams; + private int isTag; + public void setTag(String tag) { if (StringUtils.isBlank(tag)) { tags = Lists.newArrayList(); diff --git a/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/TagFilter.java b/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/TagFilter.java index e37bd906e..c5e0a04d1 100644 --- a/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/TagFilter.java +++ b/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/TagFilter.java @@ -2,6 +2,8 @@ import java.util.List; + +import com.tencent.supersonic.headless.api.pojo.enums.TagDefineType; import lombok.Data; @Data @@ -9,5 +11,6 @@ public class TagFilter extends MetaFilter { private String type; private List statusList; + private TagDefineType tagDefineType; } diff --git a/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/TagFilterPage.java b/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/TagFilterPage.java index bb1dbb1b4..4ed30aad9 100644 --- a/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/TagFilterPage.java +++ b/headless/server/src/main/java/com/tencent/supersonic/headless/server/pojo/TagFilterPage.java @@ -1,6 +1,7 @@ package com.tencent.supersonic.headless.server.pojo; +import com.tencent.supersonic.headless.api.pojo.enums.TagDefineType; import com.tencent.supersonic.headless.api.pojo.request.PageSchemaItemReq; import java.util.List; @@ -8,4 +9,5 @@ public class TagFilterPage extends PageSchemaItemReq { private String type; private List statusList; + private TagDefineType tagDefineType; } \ No newline at end of file diff --git a/headless/server/src/main/java/com/tencent/supersonic/headless/server/service/impl/DimensionServiceImpl.java b/headless/server/src/main/java/com/tencent/supersonic/headless/server/service/impl/DimensionServiceImpl.java index e851f1b9c..92235e50e 100644 --- a/headless/server/src/main/java/com/tencent/supersonic/headless/server/service/impl/DimensionServiceImpl.java +++ b/headless/server/src/main/java/com/tencent/supersonic/headless/server/service/impl/DimensionServiceImpl.java @@ -18,6 +18,7 @@ import com.tencent.supersonic.common.util.ChatGptHelper; import com.tencent.supersonic.headless.api.pojo.DimValueMap; import com.tencent.supersonic.headless.api.pojo.ModelDetail; +import com.tencent.supersonic.headless.api.pojo.enums.TagDefineType; import com.tencent.supersonic.headless.api.pojo.request.DimensionReq; import com.tencent.supersonic.headless.api.pojo.request.MetaBatchReq; import com.tencent.supersonic.headless.api.pojo.request.PageDimensionReq; @@ -26,16 +27,19 @@ import com.tencent.supersonic.headless.api.pojo.response.DimensionResp; import com.tencent.supersonic.headless.api.pojo.response.ModelResp; import com.tencent.supersonic.headless.api.pojo.response.SemanticQueryResp; +import com.tencent.supersonic.headless.api.pojo.response.TagResp; import com.tencent.supersonic.headless.server.persistence.dataobject.DimensionDO; import com.tencent.supersonic.headless.server.persistence.repository.DimensionRepository; import com.tencent.supersonic.headless.server.pojo.DimensionFilter; import com.tencent.supersonic.headless.server.pojo.DimensionsFilter; import com.tencent.supersonic.headless.server.pojo.MetaFilter; +import com.tencent.supersonic.headless.server.pojo.TagFilter; import com.tencent.supersonic.headless.server.service.DataSetService; import com.tencent.supersonic.headless.server.service.DatabaseService; import com.tencent.supersonic.headless.server.service.DimensionService; import com.tencent.supersonic.headless.server.service.ModelRelaService; import com.tencent.supersonic.headless.server.service.ModelService; +import com.tencent.supersonic.headless.server.service.TagMetaService; import com.tencent.supersonic.headless.server.utils.DimensionConverter; import com.tencent.supersonic.headless.server.utils.NameCheckUtils; import lombok.extern.slf4j.Slf4j; @@ -50,6 +54,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; @Service @@ -69,22 +74,26 @@ public class DimensionServiceImpl implements DimensionService { private DataSetService dataSetService; + private TagMetaService tagMetaService; + @Autowired private ApplicationEventPublisher eventPublisher; public DimensionServiceImpl(DimensionRepository dimensionRepository, - ModelService modelService, - ChatGptHelper chatGptHelper, - DatabaseService databaseService, - ModelRelaService modelRelaService, - DataSetService dataSetService) { + ModelService modelService, + ChatGptHelper chatGptHelper, + DatabaseService databaseService, + ModelRelaService modelRelaService, + DataSetService dataSetService, + TagMetaService tagMetaService) { this.modelService = modelService; this.dimensionRepository = dimensionRepository; this.chatGptHelper = chatGptHelper; this.databaseService = databaseService; this.modelRelaService = modelRelaService; this.dataSetService = dataSetService; + this.tagMetaService = tagMetaService; } @Override @@ -115,7 +124,7 @@ public void createDimensionBatch(List dimensionReqs, User user) { return; } List dimensionDOS = dimensionToInsert.stream().peek(dimension -> - dimension.createdBy(user.getName())) + dimension.createdBy(user.getName())) .map(DimensionConverter::convert2DimensionDO) .collect(Collectors.toList()); dimensionRepository.createDimensionBatch(dimensionDOS); @@ -206,7 +215,7 @@ public PageInfo queryDimension(PageDimensionReq pageDimensionReq) BeanUtils.copyProperties(pageDimensionReq, dimensionFilter); dimensionFilter.setModelIds(pageDimensionReq.getModelIds()); PageInfo dimensionDOPageInfo = PageHelper.startPage(pageDimensionReq.getCurrent(), - pageDimensionReq.getPageSize()) + pageDimensionReq.getPageSize()) .doSelectPageInfo(() -> queryDimension(dimensionFilter)); PageInfo pageInfo = new PageInfo<>(); BeanUtils.copyProperties(dimensionDOPageInfo, pageInfo); @@ -272,7 +281,7 @@ public List getDimensionInModelCluster(Long modelId) { } private List convertList(List dimensionDOS, - Map modelRespMap) { + Map modelRespMap) { List dimensionResps = Lists.newArrayList(); if (!CollectionUtils.isEmpty(dimensionDOS)) { dimensionResps = dimensionDOS.stream() @@ -280,9 +289,28 @@ private List convertList(List dimensionDOS, .convert2DimensionResp(dimensionDO, modelRespMap)) .collect(Collectors.toList()); } + fillTagInfo(dimensionResps); return dimensionResps; } + private void fillTagInfo(List dimensionResps) { + if (CollectionUtils.isEmpty(dimensionResps)) { + return; + } + TagFilter tagFilter = new TagFilter(); + tagFilter.setTagDefineType(TagDefineType.DIMENSION); + Map keyAndTagMap = tagMetaService.getTags(tagFilter).stream() + .collect(Collectors.toMap(tag -> tag.getModelId() + "_" + tag.getBizName(), tag -> tag)); + if (Objects.nonNull(keyAndTagMap)) { + dimensionResps.stream().forEach(dim -> { + String key = dim.getModelId() + "_" + dim.getBizName(); + if (keyAndTagMap.containsKey(key)) { + dim.setIsTag(1); + } + }); + } + } + @Override public List mockAlias(DimensionReq dimensionReq, String mockType, User user) { String mockAlias = chatGptHelper.mockAlias(mockType, dimensionReq.getName(), dimensionReq.getBizName(), diff --git a/headless/server/src/main/java/com/tencent/supersonic/headless/server/service/impl/MetricServiceImpl.java b/headless/server/src/main/java/com/tencent/supersonic/headless/server/service/impl/MetricServiceImpl.java index b2a612954..f7b796eb9 100644 --- a/headless/server/src/main/java/com/tencent/supersonic/headless/server/service/impl/MetricServiceImpl.java +++ b/headless/server/src/main/java/com/tencent/supersonic/headless/server/service/impl/MetricServiceImpl.java @@ -23,6 +23,7 @@ import com.tencent.supersonic.headless.api.pojo.MetricQueryDefaultConfig; import com.tencent.supersonic.headless.api.pojo.SchemaItem; import com.tencent.supersonic.headless.api.pojo.enums.MetricDefineType; +import com.tencent.supersonic.headless.api.pojo.enums.TagDefineType; import com.tencent.supersonic.headless.api.pojo.request.MetaBatchReq; import com.tencent.supersonic.headless.api.pojo.request.MetricBaseReq; import com.tencent.supersonic.headless.api.pojo.request.MetricReq; @@ -33,6 +34,7 @@ import com.tencent.supersonic.headless.api.pojo.response.DimensionResp; import com.tencent.supersonic.headless.api.pojo.response.MetricResp; import com.tencent.supersonic.headless.api.pojo.response.ModelResp; +import com.tencent.supersonic.headless.api.pojo.response.TagResp; import com.tencent.supersonic.headless.server.persistence.dataobject.CollectDO; import com.tencent.supersonic.headless.server.persistence.dataobject.MetricDO; import com.tencent.supersonic.headless.server.persistence.dataobject.MetricQueryDefaultConfigDO; @@ -42,11 +44,13 @@ import com.tencent.supersonic.headless.server.pojo.MetricFilter; import com.tencent.supersonic.headless.server.pojo.MetricsFilter; import com.tencent.supersonic.headless.server.pojo.ModelCluster; +import com.tencent.supersonic.headless.server.pojo.TagFilter; import com.tencent.supersonic.headless.server.service.CollectService; import com.tencent.supersonic.headless.server.service.DataSetService; import com.tencent.supersonic.headless.server.service.DimensionService; import com.tencent.supersonic.headless.server.service.MetricService; import com.tencent.supersonic.headless.server.service.ModelService; +import com.tencent.supersonic.headless.server.service.TagMetaService; import com.tencent.supersonic.headless.server.utils.MetricCheckUtils; import com.tencent.supersonic.headless.server.utils.MetricConverter; import com.tencent.supersonic.headless.server.utils.ModelClusterBuilder; @@ -64,6 +68,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -85,13 +90,16 @@ public class MetricServiceImpl implements MetricService { private ApplicationEventPublisher eventPublisher; + private TagMetaService tagMetaService; + public MetricServiceImpl(MetricRepository metricRepository, - ModelService modelService, - ChatGptHelper chatGptHelper, - CollectService collectService, - DataSetService dataSetService, - ApplicationEventPublisher eventPublisher, - DimensionService dimensionService) { + ModelService modelService, + ChatGptHelper chatGptHelper, + CollectService collectService, + DataSetService dataSetService, + ApplicationEventPublisher eventPublisher, + DimensionService dimensionService, + TagMetaService tagMetaService) { this.metricRepository = metricRepository; this.modelService = modelService; this.chatGptHelper = chatGptHelper; @@ -99,6 +107,7 @@ public MetricServiceImpl(MetricRepository metricRepository, this.collectService = collectService; this.dataSetService = dataSetService; this.dimensionService = dimensionService; + this.tagMetaService = tagMetaService; } @Override @@ -211,12 +220,13 @@ public PageInfo queryMetric(PageMetricReq pageMetricReq, User user) } } PageInfo metricDOPageInfo = PageHelper.startPage(pageMetricReq.getCurrent(), - pageMetricReq.getPageSize()) + pageMetricReq.getPageSize()) .doSelectPageInfo(() -> queryMetric(metricFilter)); PageInfo pageInfo = new PageInfo<>(); BeanUtils.copyProperties(metricDOPageInfo, pageInfo); List metricResps = convertList(metricDOPageInfo.getList(), collectIds); fillAdminRes(metricResps, user); + fillTagInfo(metricResps); pageInfo.setList(metricResps); return pageInfo; } @@ -240,6 +250,24 @@ public List getMetrics(MetaFilter metaFilter) { return metricResps; } + private void fillTagInfo(List metricRespList) { + if (CollectionUtils.isEmpty(metricRespList)) { + return; + } + TagFilter tagFilter = new TagFilter(); + tagFilter.setTagDefineType(TagDefineType.METRIC); + Map keyAndTagMap = tagMetaService.getTags(tagFilter).stream() + .collect(Collectors.toMap(tag -> tag.getModelId() + "_" + tag.getBizName(), tag -> tag)); + if (Objects.nonNull(keyAndTagMap)) { + metricRespList.stream().forEach(metric -> { + String key = metric.getModelId() + "_" + metric.getBizName(); + if (keyAndTagMap.containsKey(key)) { + metric.setIsTag(1); + } + }); + } + } + private List filterByField(List metricResps, List fields) { Set metricRespFiltered = Sets.newHashSet(); for (MetricResp metricResp : metricResps) { @@ -249,7 +277,7 @@ private List filterByField(List metricResps, List metricResps, MetricResp metricResp, - List fields, Set metricRespFiltered) { + List fields, Set metricRespFiltered) { if (MetricDefineType.METRIC.equals(metricResp.getMetricDefineType())) { List ids = metricResp.getMetricDefineByMetricParams().getMetrics() .stream().map(MetricParam::getId).collect(Collectors.toList()); @@ -287,8 +315,8 @@ public List getMetricsToCreateNewMetric(Long modelId) { metricFilter.setModelIds(Lists.newArrayList(modelId)); List metricResps = getMetrics(metricFilter); return metricResps.stream().filter(metricResp -> - MetricDefineType.FIELD.equals(metricResp.getMetricDefineType()) - || MetricDefineType.MEASURE.equals(metricResp.getMetricDefineType())) + MetricDefineType.FIELD.equals(metricResp.getMetricDefineType()) + || MetricDefineType.MEASURE.equals(metricResp.getMetricDefineType())) .collect(Collectors.toList()); } @@ -450,6 +478,7 @@ private List convertList(List metricDOS) { private List convertList(List metricDOS, List collect) { List metricResps = Lists.newArrayList(); + Map modelMap = modelService.getModelMap(); if (!CollectionUtils.isEmpty(metricDOS)) { metricResps = metricDOS.stream() @@ -560,7 +589,7 @@ private ModelCluster getModelCluster(List metricResps, Set mod } private Set getModelIds(Set modelIdsByDomainId, List metricResps, - List dimensionResps) { + List dimensionResps) { Set result = new HashSet<>(); if (org.apache.commons.collections.CollectionUtils.isNotEmpty(modelIdsByDomainId)) { result.addAll(modelIdsByDomainId); diff --git a/headless/server/src/main/resources/mapper/custom/TagCustomMapper.xml b/headless/server/src/main/resources/mapper/custom/TagCustomMapper.xml index b6862ec28..85c6cc316 100644 --- a/headless/server/src/main/resources/mapper/custom/TagCustomMapper.xml +++ b/headless/server/src/main/resources/mapper/custom/TagCustomMapper.xml @@ -67,6 +67,9 @@ and type = #{type} + + and define_type = #{tagDefineType} + and ( id like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or name like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or diff --git a/headless/server/src/test/java/com/tencent/supersonic/headless/server/service/MetricServiceImplTest.java b/headless/server/src/test/java/com/tencent/supersonic/headless/server/service/MetricServiceImplTest.java index 6341b2ffc..9ba929ea1 100644 --- a/headless/server/src/test/java/com/tencent/supersonic/headless/server/service/MetricServiceImplTest.java +++ b/headless/server/src/test/java/com/tencent/supersonic/headless/server/service/MetricServiceImplTest.java @@ -69,8 +69,9 @@ private MetricService mockMetricService(MetricRepository metricRepository, ApplicationEventPublisher eventPublisher = Mockito.mock(ApplicationEventPublisher.class); DataSetService dataSetService = Mockito.mock(DataSetServiceImpl.class); DimensionService dimensionService = Mockito.mock(DimensionService.class); + TagMetaService tagMetaService = Mockito.mock(TagMetaService.class); return new MetricServiceImpl(metricRepository, modelService, chatGptHelper, collectService, dataSetService, - eventPublisher, dimensionService); + eventPublisher, dimensionService, tagMetaService); } private MetricReq buildMetricReq() {