mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-14 22:25:19 +00:00
add tagTest and pot TagCustomMapper.xml (#833)
This commit is contained in:
@@ -72,7 +72,8 @@ public class TagMetaServiceImpl implements TagMetaService {
|
||||
|
||||
@Override
|
||||
public TagResp create(TagReq tagReq, User user) {
|
||||
checkExit(tagReq);
|
||||
checkExist(tagReq);
|
||||
checkTagObject(tagReq);
|
||||
TagDO tagDO = convert(tagReq);
|
||||
Date date = new Date();
|
||||
tagDO.setId(null);
|
||||
@@ -81,7 +82,7 @@ public class TagMetaServiceImpl implements TagMetaService {
|
||||
tagDO.setUpdatedBy(user.getName());
|
||||
tagDO.setUpdatedAt(date);
|
||||
tagRepository.create(tagDO);
|
||||
return convert2Resp(tagDO);
|
||||
return getTag(tagDO.getId(), user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,6 +109,10 @@ public class TagMetaServiceImpl implements TagMetaService {
|
||||
public TagResp getTag(Long id, User user) {
|
||||
TagDO tagDO = tagRepository.getTagById(id);
|
||||
TagResp tagResp = convert2Resp(tagDO);
|
||||
List<TagResp> tagRespList = Arrays.asList(tagResp);
|
||||
fillModelInfo(tagRespList);
|
||||
fillDomainInfo(tagRespList);
|
||||
tagResp = tagRespList.get(0);
|
||||
tagResp = fillTagObjectInfo(tagResp, user);
|
||||
tagResp = fillCollectAndAdminInfo(tagResp, user);
|
||||
return tagResp;
|
||||
@@ -190,6 +195,7 @@ public class TagMetaServiceImpl implements TagMetaService {
|
||||
private TagResp convert2Resp(TagDO tagDO) {
|
||||
TagResp tagResp = new TagResp();
|
||||
BeanUtils.copyProperties(tagDO, tagResp);
|
||||
tagResp.setTagDefineType(tagDO.getType());
|
||||
if (TagDefineType.METRIC.name().equalsIgnoreCase(tagDO.getType())) {
|
||||
MetricResp metric = metricService.getMetric(tagDO.getItemId());
|
||||
tagResp.setBizName(metric.getBizName());
|
||||
@@ -279,13 +285,6 @@ public class TagMetaServiceImpl implements TagMetaService {
|
||||
return dimensions.size();
|
||||
}
|
||||
|
||||
private TagResp fillModelInfo(TagResp tagResp) {
|
||||
ModelResp model = modelService.getModel(tagResp.getModelId());
|
||||
tagResp.setModelName(model.getName());
|
||||
tagResp.setDomainId(model.getDomainId());
|
||||
return tagResp;
|
||||
}
|
||||
|
||||
private void fillModelInfo(List<TagResp> tagRespList) {
|
||||
Map<Long, ModelResp> modelIdAndRespMap = modelService.getModelMap();
|
||||
tagRespList.stream().forEach(tagResp -> {
|
||||
@@ -303,6 +302,8 @@ public class TagMetaServiceImpl implements TagMetaService {
|
||||
.map(CollectDO::getCollectId).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(collectIds) && collectIds.contains(tagResp.getId())) {
|
||||
tagResp.setIsCollect(true);
|
||||
} else {
|
||||
tagResp.setIsCollect(false);
|
||||
}
|
||||
List<TagResp> tagRespList = Arrays.asList(tagResp);
|
||||
fillAdminRes(tagRespList, user);
|
||||
@@ -324,7 +325,7 @@ public class TagMetaServiceImpl implements TagMetaService {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkExit(TagReq tagReq) {
|
||||
private void checkExist(TagReq tagReq) {
|
||||
TagFilter tagFilter = new TagFilter();
|
||||
tagFilter.setTagDefineType(tagReq.getTagDefineType());
|
||||
if (Objects.nonNull(tagReq.getItemId())) {
|
||||
@@ -337,6 +338,25 @@ public class TagMetaServiceImpl implements TagMetaService {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkTagObject(TagReq tagReq) {
|
||||
if (TagDefineType.DIMENSION.equals(tagReq.getTagDefineType())) {
|
||||
DimensionResp dimension = dimensionService.getDimension(tagReq.getItemId());
|
||||
ModelResp model = modelService.getModel(dimension.getModelId());
|
||||
if (Objects.isNull(model.getTagObjectId())) {
|
||||
throw new RuntimeException(String.format("this dimension:{} is not supported to create tag",
|
||||
tagReq.getItemId()));
|
||||
}
|
||||
}
|
||||
if (TagDefineType.METRIC.equals(tagReq.getTagDefineType())) {
|
||||
MetricResp metric = metricService.getMetric(tagReq.getItemId());
|
||||
ModelResp model = modelService.getModel(metric.getModelId());
|
||||
if (Objects.isNull(model.getTagObjectId())) {
|
||||
throw new RuntimeException(String.format("this metric:{} is not supported to create tag",
|
||||
tagReq.getItemId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TagDO convert(TagReq tagReq) {
|
||||
TagDO tagDO = new TagDO();
|
||||
BeanUtils.copyProperties(tagReq, tagDO);
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<result column="model_name" jdbcType="VARCHAR" property="modelName" />
|
||||
<result column="tag_object_id" jdbcType="BIGINT" property="tagObjectId" />
|
||||
<result column="tag_object_name" jdbcType="VARCHAR" property="tagObjectName" />
|
||||
<result column="tag_define_type" jdbcType="VARCHAR" property="tagDefineType" />
|
||||
<result column="type" jdbcType="VARCHAR" property="tagDefineType" />
|
||||
<result column="item_id" jdbcType="VARCHAR" property="itemId" />
|
||||
<result column="name" jdbcType="VARCHAR" property="name" />
|
||||
<result column="biz_name" jdbcType="VARCHAR" property="bizName" />
|
||||
@@ -45,28 +45,28 @@
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="tagDefineType != null">
|
||||
and tag_define_type = #{tagDefineType}
|
||||
and type = #{tagDefineType}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="queryTagRespList" resultMap="TagResp">
|
||||
select * from (
|
||||
select s2_tag.id as id, s2_dimension.model_id as model_id, 'DIMENSION' as tag_define_type, s2_dimension.id as item_id,
|
||||
select s2_tag.id as id, s2_dimension.model_id as model_id, 'DIMENSION' as type, s2_dimension.id as item_id,
|
||||
s2_dimension.name as name, s2_dimension.biz_name as biz_name, s2_dimension.description as description, s2_tag.updated_at as updated_at
|
||||
from s2_tag join s2_dimension
|
||||
on s2_tag.item_id = s2_dimension.id
|
||||
where s2_dimension.status=1
|
||||
where s2_dimension.status=1 and s2_tag.type='DIMENSION'
|
||||
union
|
||||
select s2_tag.id as id, s2_metric.model_id as model_id, 'METRIC' as tag_define_type, s2_metric.id as item_id,
|
||||
select s2_tag.id as id, s2_metric.model_id as model_id, 'METRIC' as type, s2_metric.id as item_id,
|
||||
s2_metric.name as name, s2_metric.biz_name as biz_name, s2_metric.description as description, s2_tag.updated_at as updated_at
|
||||
from s2_tag join s2_metric
|
||||
on s2_tag.item_id = s2_metric.id
|
||||
where s2_metric.status=1
|
||||
where s2_metric.status=1 and s2_tag.type='METRIC'
|
||||
)t
|
||||
<where>
|
||||
<if test="tagDefineType != null">
|
||||
and tag_define_type = #{tagDefineType}
|
||||
and type = #{tagDefineType}
|
||||
</if>
|
||||
<if test="itemIds != null and itemIds.size >0">
|
||||
and item_id in
|
||||
|
||||
Reference in New Issue
Block a user