mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
support batchUpdateClassifications for Metric (#980)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.tencent.supersonic.headless.api.pojo.request;
|
||||
|
||||
import com.tencent.supersonic.common.pojo.enums.EventType;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,4 +18,10 @@ public class MetaBatchReq {
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 批量执行分类信息
|
||||
*/
|
||||
private EventType type;
|
||||
private List<String> classifications;
|
||||
|
||||
}
|
||||
|
||||
@@ -19,4 +19,5 @@ public class PageSchemaItemReq extends PageBaseReq {
|
||||
private String key;
|
||||
private List<Long> ids;
|
||||
private boolean hasCollect;
|
||||
private List<String> classifications;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ public interface MetricDOCustomMapper {
|
||||
|
||||
void batchUnPublish(List<MetricDO> metricDOS);
|
||||
|
||||
void updateClassificationsBatch(List<MetricDO> metricDOS);
|
||||
|
||||
List<MetricDO> query(MetricFilter metricFilter);
|
||||
|
||||
List<MetricDO> queryMetrics(MetricsFilter metricsFilter);
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ public interface MetricRepository {
|
||||
|
||||
void batchUnPublish(List<MetricDO> metricDOS);
|
||||
|
||||
void updateClassificationsBatch(List<MetricDO> metricDOS);
|
||||
|
||||
MetricDO getMetricById(Long id);
|
||||
|
||||
List<MetricDO> getMetric(MetricFilter metricFilter);
|
||||
|
||||
@@ -62,6 +62,11 @@ public class MetricRepositoryImpl implements MetricRepository {
|
||||
metricDOCustomMapper.batchUnPublish(metricDOS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClassificationsBatch(List<MetricDO> metricDOS) {
|
||||
metricDOCustomMapper.updateClassificationsBatch(metricDOS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricDO getMetricById(Long id) {
|
||||
return metricDOMapper.selectById(id);
|
||||
|
||||
@@ -83,6 +83,15 @@ public class MetricController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/batchUpdateClassifications")
|
||||
public Boolean batchUpdateClassifications(@RequestBody MetaBatchReq metaBatchReq,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
User user = UserHolder.findUser(request, response);
|
||||
metricService.batchUpdateClassifications(metaBatchReq, user);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/mockMetricAlias")
|
||||
public List<String> mockMetricAlias(@RequestBody MetricBaseReq metricReq,
|
||||
HttpServletRequest request,
|
||||
@@ -141,11 +150,17 @@ public class MetricController {
|
||||
return metricService.getMetrics(metricFilter);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@GetMapping("/getMetricTags")
|
||||
public Set<String> getMetricTags() {
|
||||
return metricService.getMetricTags();
|
||||
}
|
||||
|
||||
@GetMapping("/getMetricClassifications")
|
||||
public Set<String> getMetricClassifications() {
|
||||
return metricService.getMetricTags();
|
||||
}
|
||||
|
||||
@GetMapping("/getDrillDownDimension")
|
||||
public List<DrillDownDimension> getDrillDownDimension(Long metricId) {
|
||||
return metricService.getDrillDownDimension(metricId);
|
||||
|
||||
@@ -33,6 +33,8 @@ public interface MetricService {
|
||||
|
||||
void batchUnPublish(List<Long> metricIds, User user);
|
||||
|
||||
void batchUpdateClassifications(MetaBatchReq metaBatchReq, User user);
|
||||
|
||||
void deleteMetric(Long id, User user) throws Exception;
|
||||
|
||||
PageInfo<MetricResp> queryMetricMarket(PageMetricReq pageMetricReq, User user);
|
||||
|
||||
@@ -72,6 +72,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -229,6 +230,41 @@ public class MetricServiceImpl implements MetricService {
|
||||
metricRepository.batchUnPublish(metrics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchUpdateClassifications(MetaBatchReq metaBatchReq, User user) {
|
||||
MetricFilter metricFilter = new MetricFilter();
|
||||
metricFilter.setIds(metaBatchReq.getIds());
|
||||
List<MetricDO> metrics = metricRepository.getMetric(metricFilter);
|
||||
for (MetricDO metricDO : metrics) {
|
||||
metricDO.setUpdatedAt(new Date());
|
||||
metricDO.setUpdatedBy(user.getName());
|
||||
fillClassifications(metaBatchReq, metricDO);
|
||||
}
|
||||
metricRepository.updateClassificationsBatch(metrics);
|
||||
}
|
||||
|
||||
private void fillClassifications(MetaBatchReq metaBatchReq, MetricDO metricDO) {
|
||||
String classificationStr = metricDO.getClassifications();
|
||||
Set<String> classificationsList;
|
||||
if (StringUtils.isBlank(classificationStr)) {
|
||||
classificationsList = new HashSet<>();
|
||||
} else {
|
||||
classificationsList = new HashSet<>(Arrays.asList(classificationStr.split(",")));
|
||||
}
|
||||
|
||||
if (EventType.ADD.equals(metaBatchReq.getType())) {
|
||||
classificationsList.addAll(metaBatchReq.getClassifications());
|
||||
}
|
||||
if (EventType.DELETE.equals(metaBatchReq.getType())) {
|
||||
classificationsList.removeAll(metaBatchReq.getClassifications());
|
||||
}
|
||||
String classifications = "";
|
||||
if (!CollectionUtils.isEmpty(classificationsList)) {
|
||||
classifications = StringUtils.join(classificationsList, ",");
|
||||
}
|
||||
metricDO.setClassifications(classifications);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMetric(Long id, User user) {
|
||||
MetricDO metricDO = metricRepository.getMetricById(id);
|
||||
@@ -263,7 +299,7 @@ public class MetricServiceImpl implements MetricService {
|
||||
.flatMap(Collection::stream).filter(schemaElementMatch ->
|
||||
SchemaElementType.METRIC.equals(schemaElementMatch.getElement().getType()))
|
||||
.collect(Collectors.toMap(schemaElementMatch ->
|
||||
schemaElementMatch.getElement().getId(), SchemaElementMatch::getSimilarity,
|
||||
schemaElementMatch.getElement().getId(), SchemaElementMatch::getSimilarity,
|
||||
(existingValue, newValue) -> existingValue));
|
||||
List<Long> metricIds = new ArrayList<>(result.keySet());
|
||||
if (CollectionUtils.isEmpty(result.keySet())) {
|
||||
@@ -294,7 +330,7 @@ public class MetricServiceImpl implements MetricService {
|
||||
List<Long> idsToFilter = getIdsToFilter(pageMetricReq, collectIds);
|
||||
metricFilter.setIds(idsToFilter);
|
||||
PageInfo<MetricDO> metricDOPageInfo = PageHelper.startPage(pageMetricReq.getCurrent(),
|
||||
pageMetricReq.getPageSize())
|
||||
pageMetricReq.getPageSize())
|
||||
.doSelectPageInfo(() -> queryMetric(metricFilter));
|
||||
PageInfo<MetricResp> pageInfo = new PageInfo<>();
|
||||
BeanUtils.copyProperties(metricDOPageInfo, pageInfo);
|
||||
@@ -435,8 +471,8 @@ public class MetricServiceImpl implements MetricService {
|
||||
metricFilter.setModelIds(Lists.newArrayList(modelId));
|
||||
List<MetricResp> 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());
|
||||
}
|
||||
|
||||
@@ -626,11 +662,7 @@ public class MetricServiceImpl implements MetricService {
|
||||
return convertList(metricDOS, new ArrayList<>());
|
||||
}
|
||||
|
||||
private void sendEventBatch(List<MetricDO> metricDOS, EventType eventType) {
|
||||
DataEvent dataEvent = getDataEvent(metricDOS, eventType);
|
||||
eventPublisher.publishEvent(dataEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataEvent getDataEvent() {
|
||||
MetricsFilter metricsFilter = new MetricsFilter();
|
||||
List<MetricDO> metricDOS = metricRepository.getMetrics(metricsFilter);
|
||||
@@ -643,6 +675,11 @@ public class MetricServiceImpl implements MetricService {
|
||||
return new DataEvent(this, dataItems, eventType);
|
||||
}
|
||||
|
||||
private void sendEventBatch(List<MetricDO> metricDOS, EventType eventType) {
|
||||
DataEvent dataEvent = getDataEvent(metricDOS, eventType);
|
||||
eventPublisher.publishEvent(dataEvent);
|
||||
}
|
||||
|
||||
private void sendEvent(DataItem dataItem, EventType eventType) {
|
||||
eventPublisher.publishEvent(new DataEvent(this,
|
||||
Lists.newArrayList(dataItem), eventType));
|
||||
@@ -657,6 +694,7 @@ public class MetricServiceImpl implements MetricService {
|
||||
.type(TypeEnums.METRIC).defaultAgg(metricResp.getDefaultAgg()).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryStructReq convert(QueryMetricReq queryMetricReq) {
|
||||
//1. If a domainId exists, the modelIds obtained from the domainId.
|
||||
Set<Long> modelIdsByDomainId = getModelIdsByDomainId(queryMetricReq);
|
||||
|
||||
@@ -117,6 +117,16 @@
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="updateClassificationsBatch" parameterType="java.util.List">
|
||||
<foreach collection="list" item="metric" separator=";">
|
||||
update s2_metric
|
||||
set classifications = #{metric.classifications,jdbcType=VARCHAR},
|
||||
updated_at = #{metric.updatedAt,jdbcType=TIMESTAMP},
|
||||
updated_by = #{metric.updatedBy,jdbcType=VARCHAR}
|
||||
where id = #{metric.id,jdbcType=BIGINT}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<select id="query" resultMap="ResultMapWithBLOBs">
|
||||
select t.*
|
||||
from s2_metric t
|
||||
|
||||
Reference in New Issue
Block a user