[improvement][project] supersonic 0.7.0 version backend update (#24)

* [improvement][project] supersonic 0.7.0 version backend update

* [improvement][project] supersonic 0.7.0 version backend update

* [improvement][project] supersonic 0.7.0 version readme update

---------

Co-authored-by: jolunoluo <jolunoluo@tencent.com>
This commit is contained in:
SunDean
2023-08-05 22:17:56 +08:00
committed by GitHub
parent 6951eada9d
commit aa0a100a85
184 changed files with 2609 additions and 1238 deletions

View File

@@ -109,6 +109,7 @@ public class DimensionServiceImpl implements DimensionService {
public PageInfo<DimensionResp> queryDimension(PageDimensionReq pageDimensionReq) {
DimensionFilter dimensionFilter = new DimensionFilter();
BeanUtils.copyProperties(pageDimensionReq, dimensionFilter);
dimensionFilter.setDomainIds(pageDimensionReq.getDomainIds());
PageInfo<DimensionDO> dimensionDOPageInfo = PageHelper.startPage(pageDimensionReq.getCurrent(),
pageDimensionReq.getPageSize())
.doSelectPageInfo(() -> queryDimension(dimensionFilter));

View File

@@ -2,7 +2,9 @@ package com.tencent.supersonic.semantic.model.application;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.service.UserService;
import com.tencent.supersonic.common.util.BeanMapper;
import com.tencent.supersonic.common.util.JsonUtil;
import com.tencent.supersonic.semantic.api.model.request.DomainReq;
@@ -24,12 +26,7 @@ import com.tencent.supersonic.semantic.model.domain.pojo.Domain;
import com.tencent.supersonic.semantic.model.domain.repository.DomainRepository;
import com.tencent.supersonic.semantic.model.domain.utils.DomainConvert;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
@@ -47,14 +44,17 @@ public class DomainServiceImpl implements DomainService {
private final MetricService metricService;
private final DimensionService dimensionService;
private final DatasourceService datasourceService;
private final UserService userService;
public DomainServiceImpl(DomainRepository domainRepository, @Lazy MetricService metricService,
@Lazy DimensionService dimensionService, @Lazy DatasourceService datasourceService) {
@Lazy DimensionService dimensionService, @Lazy DatasourceService datasourceService,
UserService userService) {
this.domainRepository = domainRepository;
this.metricService = metricService;
this.dimensionService = dimensionService;
this.datasourceService = datasourceService;
this.userService = userService;
}
@@ -130,7 +130,7 @@ public class DomainServiceImpl implements DomainService {
@Override
public List<DomainResp> getDomainListForAdmin(String userName) {
List<DomainDO> domainDOS = domainRepository.getDomainList();
List<String> orgIds = Lists.newArrayList();
Set<String> orgIds = Sets.newHashSet();
log.info("orgIds:{},userName:{}", orgIds, userName);
Map<Long, List<MetricResp>> metricDomainMap = metricService.getMetrics().stream()
.collect(Collectors.groupingBy(MetricResp::getDomainId));
@@ -144,7 +144,7 @@ public class DomainServiceImpl implements DomainService {
@Override
public List<DomainResp> getDomainListForViewer(String userName) {
List<DomainDO> domainDOS = domainRepository.getDomainList();
List<String> orgIds = Lists.newArrayList();
Set<String> orgIds = Sets.newHashSet();
log.info("orgIds:{},userName:{}", orgIds, userName);
return convertList(domainDOS, new HashMap<>(), new HashMap<>()).stream()
.filter(domainDesc -> checkViewerPermission(orgIds, userName, domainDesc))
@@ -165,7 +165,7 @@ public class DomainServiceImpl implements DomainService {
return "";
}
Map<Long, String> map = getDomainFullPathMap();
return map.containsKey(domainId) ? map.get(domainId) : "";
return map.getOrDefault(domainId, "");
}
@Override
@@ -201,6 +201,32 @@ public class DomainServiceImpl implements DomainService {
return getDomainList().stream().collect(Collectors.toMap(DomainResp::getId, a -> a, (k1, k2) -> k1));
}
@Override
public Set<DomainResp> getDomainChildren(List<Long> domainIds) {
Set<DomainResp> childDomains = new HashSet<>();
if (CollectionUtils.isEmpty(domainIds)) {
return childDomains;
}
Map<Long, DomainResp> allDomainMap = getDomainMap();
for (Long domainId : domainIds) {
DomainResp domain = allDomainMap.get(domainId);
if (domain != null) {
childDomains.add(domain);
Queue<DomainResp> queue = new LinkedList<>();
queue.add(domain);
while (!queue.isEmpty()) {
DomainResp currentDomain = queue.poll();
for (DomainResp child : allDomainMap.values()) {
if (Objects.equals(child.getParentId(), currentDomain.getId())) {
childDomains.add(child);
queue.add(child);
}
}
}
}
}
return childDomains;
}
public Map<Long, String> getDomainFullPathMap() {
Map<Long, String> domainFullPathMap = new HashMap<>();
@@ -286,13 +312,16 @@ public class DomainServiceImpl implements DomainService {
}
private boolean checkAdminPermission(List<String> orgIds, String userName, DomainResp domainDesc) {
private boolean checkAdminPermission(Set<String> orgIds, String userName, DomainResp domainDesc) {
List<String> admins = domainDesc.getAdmins();
List<String> adminOrgs = domainDesc.getAdminOrgs();
if (admins.contains(userName) || domainDesc.getCreatedBy().equals(userName)) {
return true;
}
if (CollectionUtils.isEmpty(adminOrgs)) {
return false;
}
for (String orgId : orgIds) {
if (adminOrgs.contains(orgId)) {
return true;
@@ -301,7 +330,7 @@ public class DomainServiceImpl implements DomainService {
return false;
}
private boolean checkViewerPermission(List<String> orgIds, String userName, DomainResp domainDesc) {
private boolean checkViewerPermission(Set<String> orgIds, String userName, DomainResp domainDesc) {
if (domainDesc.getIsOpen() == 1) {
return true;
}
@@ -312,6 +341,9 @@ public class DomainServiceImpl implements DomainService {
if (admins.contains(userName) || viewers.contains(userName) || domainDesc.getCreatedBy().equals(userName)) {
return true;
}
if (CollectionUtils.isEmpty(adminOrgs) && CollectionUtils.isEmpty(viewOrgs)) {
return false;
}
for (String orgId : orgIds) {
if (adminOrgs.contains(orgId)) {
return true;

View File

@@ -102,6 +102,9 @@ public class MetricServiceImpl implements MetricService {
public PageInfo<MetricResp> queryMetric(PageMetricReq pageMetricReq) {
MetricFilter metricFilter = new MetricFilter();
BeanUtils.copyProperties(pageMetricReq, metricFilter);
Set<DomainResp> domainResps = domainService.getDomainChildren(pageMetricReq.getDomainIds());
List<Long> domainIds = domainResps.stream().map(DomainResp::getId).collect(Collectors.toList());
metricFilter.setDomainIds(domainIds);
PageInfo<MetricDO> metricDOPageInfo = PageHelper.startPage(pageMetricReq.getCurrent(),
pageMetricReq.getPageSize())
.doSelectPageInfo(() -> queryMetric(metricFilter));

View File

@@ -8,6 +8,7 @@ import com.tencent.supersonic.semantic.api.model.response.DomainResp;
import com.tencent.supersonic.semantic.api.model.response.DomainSchemaResp;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface DomainService {
@@ -36,6 +37,8 @@ public interface DomainService {
List<DomainResp> getDomainListForViewer(String userName);
Set<DomainResp> getDomainChildren(List<Long> domainId);
List<DomainSchemaResp> fetchDomainSchema(DomainSchemaFilterReq filter, User user);
}

View File

@@ -1,6 +1,7 @@
package com.tencent.supersonic.semantic.model.domain.pojo;
import lombok.Data;
import java.util.List;
@Data
@@ -14,7 +15,7 @@ public class MetaFilter {
private String createdBy;
private Long domainId;
private List<Long> domainIds;
private Integer sensitiveLevel;

View File

@@ -4,6 +4,7 @@ package com.tencent.supersonic.semantic.model.infrastructure.mapper;
import com.tencent.supersonic.semantic.model.domain.dataobject.MetricDO;
import java.util.List;
import com.tencent.supersonic.semantic.model.domain.pojo.MetricFilter;
import org.apache.ibatis.annotations.Mapper;
@@ -14,4 +15,6 @@ public interface MetricDOCustomMapper {
void batchUpdate(List<MetricDO> metricDOS);
List<MetricDO> query(MetricFilter metricFilter);
}

View File

@@ -7,6 +7,7 @@ import com.tencent.supersonic.semantic.model.domain.pojo.DimensionFilter;
import com.tencent.supersonic.semantic.model.infrastructure.mapper.DimensionDOCustomMapper;
import com.tencent.supersonic.semantic.model.infrastructure.mapper.DimensionDOMapper;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
@@ -97,8 +98,8 @@ public class DimensionRepositoryImpl implements DimensionRepository {
if (dimensionFilter.getCreatedBy() != null) {
dimensionDOExample.getOredCriteria().get(0).andCreatedByEqualTo(dimensionFilter.getCreatedBy());
}
if (dimensionFilter.getDomainId() != null) {
dimensionDOExample.getOredCriteria().get(0).andDomainIdEqualTo(dimensionFilter.getDomainId());
if (CollectionUtils.isNotEmpty(dimensionFilter.getDomainIds())) {
dimensionDOExample.getOredCriteria().get(0).andDomainIdIn(dimensionFilter.getDomainIds());
}
if (dimensionFilter.getSensitiveLevel() != null) {
dimensionDOExample.getOredCriteria().get(0).andSensitiveLevelEqualTo(dimensionFilter.getSensitiveLevel());

View File

@@ -74,33 +74,7 @@ public class MetricRepositoryImpl implements MetricRepository {
@Override
public List<MetricDO> getMetric(MetricFilter metricFilter) {
MetricDOExample metricDOExample = new MetricDOExample();
metricDOExample.createCriteria();
if (metricFilter.getId() != null) {
metricDOExample.getOredCriteria().get(0).andIdEqualTo(metricFilter.getId());
}
if (metricFilter.getName() != null) {
metricDOExample.getOredCriteria().get(0).andNameLike("%" + metricFilter.getName() + "%");
}
if (metricFilter.getBizName() != null) {
metricDOExample.getOredCriteria().get(0).andBizNameLike("%" + metricFilter.getBizName() + "%");
}
if (metricFilter.getCreatedBy() != null) {
metricDOExample.getOredCriteria().get(0).andCreatedByEqualTo(metricFilter.getCreatedBy());
}
if (metricFilter.getDomainId() != null) {
metricDOExample.getOredCriteria().get(0).andDomainIdEqualTo(metricFilter.getDomainId());
}
if (metricFilter.getSensitiveLevel() != null) {
metricDOExample.getOredCriteria().get(0).andSensitiveLevelEqualTo(metricFilter.getSensitiveLevel());
}
if (metricFilter.getStatus() != null) {
metricDOExample.getOredCriteria().get(0).andStatusEqualTo(metricFilter.getStatus());
}
if (StringUtils.isNotBlank(metricFilter.getType())) {
metricDOExample.getOredCriteria().get(0).andTypeEqualTo(metricFilter.getType());
}
return metricDOMapper.selectByExampleWithBLOBs(metricDOExample);
return metricDOCustomMapper.query(metricFilter);
}
@Override

View File

@@ -97,4 +97,29 @@
</foreach>
</update>
<select id="query" resultMap="ResultMapWithBLOBs">
select *
from s2_metric
where 1=1
<if test="type != null and type != ''">
and type = #{type}
</if>
<if test="name != null and name != ''">
and ( id like CONCAT('%',#{name , jdbcType=VARCHAR},'%') or
name like CONCAT('%',#{name , jdbcType=VARCHAR},'%') or
biz_name like CONCAT('%',#{name , jdbcType=VARCHAR},'%') or
description like CONCAT('%',#{name , jdbcType=VARCHAR},'%') )
</if>
<if test="sensitiveLevel != null">
and sensitive_level = #{sensitiveLevel}
</if>
<if test="domainIds != null and domainIds.size >0">
and domain_id in
<foreach collection="domainIds" index="index" item="domain" open="(" close=")"
separator=",">
#{domain}
</foreach>
</if>
</select>
</mapper>