mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-13 04:57:28 +00:00
Dev 0.9 (#774)
This commit is contained in:
@@ -4,6 +4,7 @@ public enum TypeEnums {
|
||||
|
||||
METRIC,
|
||||
DIMENSION,
|
||||
TAG,
|
||||
DOMAIN,
|
||||
ENTITY,
|
||||
VIEW,
|
||||
|
||||
@@ -16,6 +16,10 @@ public class TagResp extends SchemaItem {
|
||||
|
||||
private String type;
|
||||
|
||||
private Boolean isCollect;
|
||||
|
||||
private boolean hasAdminRes;
|
||||
|
||||
private Map<String, Object> ext = new HashMap<>();
|
||||
|
||||
private TagDefineType tagDefineType = TagDefineType.FIELD;
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.tencent.supersonic.headless.core.file;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@@ -17,9 +19,9 @@ import java.util.List;
|
||||
@Slf4j
|
||||
@Component
|
||||
public class FileHandlerImpl implements FileHandler {
|
||||
public static final String FILE_SPILT = File.separator;
|
||||
|
||||
private final LocalFileConfig localFileConfig;
|
||||
|
||||
public FileHandlerImpl(LocalFileConfig localFileConfig) {
|
||||
this.localFileConfig = localFileConfig;
|
||||
}
|
||||
@@ -31,8 +33,8 @@ public class FileHandlerImpl implements FileHandler {
|
||||
createDir(dictDirectoryBackup);
|
||||
}
|
||||
|
||||
String source = localFileConfig.getDictDirectoryLatest() + "/" + fileName;
|
||||
String target = dictDirectoryBackup + "/" + fileName;
|
||||
String source = localFileConfig.getDictDirectoryLatest() + FILE_SPILT + fileName;
|
||||
String target = dictDirectoryBackup + FILE_SPILT + fileName;
|
||||
Path sourcePath = Paths.get(source);
|
||||
Path targetPath = Paths.get(target);
|
||||
try {
|
||||
@@ -88,7 +90,7 @@ public class FileHandlerImpl implements FileHandler {
|
||||
if (!existPath(dictDirectoryLatest)) {
|
||||
createDir(dictDirectoryLatest);
|
||||
}
|
||||
String filePath = dictDirectoryLatest + "/" + fileName;
|
||||
String filePath = dictDirectoryLatest + FILE_SPILT + fileName;
|
||||
if (existPath(filePath)) {
|
||||
backupFile(fileName);
|
||||
}
|
||||
@@ -117,7 +119,7 @@ public class FileHandlerImpl implements FileHandler {
|
||||
@Override
|
||||
public Boolean deleteDictFile(String fileName) {
|
||||
backupFile(fileName);
|
||||
deleteFile(localFileConfig.getDictDirectoryLatest() + "/" + fileName);
|
||||
deleteFile(localFileConfig.getDictDirectoryLatest() + FILE_SPILT + fileName);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.tencent.supersonic.headless.core.file;
|
||||
|
||||
import com.tencent.supersonic.headless.core.knowledge.helper.HanlpHelper;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@Slf4j
|
||||
@@ -18,16 +21,21 @@ public class LocalFileConfig {
|
||||
private String dictDirectoryBackup;
|
||||
|
||||
public String getDictDirectoryLatest() {
|
||||
return getResourceDir() + dictDirectoryLatest;
|
||||
return getDictDirectoryPrefixDir() + dictDirectoryLatest;
|
||||
}
|
||||
|
||||
public String getDictDirectoryBackup() {
|
||||
return getResourceDir() + dictDirectoryBackup;
|
||||
return getDictDirectoryPrefixDir() + dictDirectoryBackup;
|
||||
}
|
||||
|
||||
private String getResourceDir() {
|
||||
//return hanlpPropertiesPath = HanlpHelper.getHanlpPropertiesPath();
|
||||
return ClassLoader.getSystemClassLoader().getResource("").getPath();
|
||||
private String getDictDirectoryPrefixDir() {
|
||||
try {
|
||||
return HanlpHelper.getHanlpPropertiesPath();
|
||||
} catch (FileNotFoundException e) {
|
||||
log.warn("getDictDirectoryPrefixDir error: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
public class SysTimeDimensionBuilder {
|
||||
|
||||
public static void addSysTimeDimension(List<Dim> dims, DbAdaptor engineAdaptor) {
|
||||
log.info("addSysTimeDimension before:{}, engineAdaptor:{}", dims, engineAdaptor);
|
||||
log.debug("addSysTimeDimension before:{}, engineAdaptor:{}", dims, engineAdaptor);
|
||||
Dim timeDim = getTimeDim(dims);
|
||||
if (timeDim == null) {
|
||||
timeDim = Dim.getDefault();
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.tencent.supersonic.headless.server.pojo;
|
||||
|
||||
|
||||
import com.tencent.supersonic.headless.api.pojo.request.PageSchemaItemReq;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TagFilterPage extends PageSchemaItemReq {
|
||||
private String type;
|
||||
private List<Integer> statusList;
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.tencent.supersonic.headless.server.rest;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.TagReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.TagResp;
|
||||
import com.tencent.supersonic.headless.server.pojo.TagFilterPage;
|
||||
import com.tencent.supersonic.headless.server.service.TagService;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -56,4 +58,12 @@ public class TagController {
|
||||
return tagService.getTag(id);
|
||||
}
|
||||
|
||||
@PostMapping("/queryTag")
|
||||
public PageInfo<TagResp> queryPage(@RequestBody TagFilterPage tagFilterPage,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) throws Exception {
|
||||
User user = UserHolder.findUser(request, response);
|
||||
return tagService.queryPage(tagFilterPage, user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.tencent.supersonic.headless.server.service;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.TagReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.TagResp;
|
||||
import com.tencent.supersonic.headless.server.pojo.TagFilter;
|
||||
import com.tencent.supersonic.headless.server.pojo.TagFilterPage;
|
||||
import java.util.List;
|
||||
|
||||
public interface TagService {
|
||||
@@ -17,4 +19,7 @@ public interface TagService {
|
||||
TagResp getTag(Long id);
|
||||
|
||||
List<TagResp> query(TagFilter tagFilter);
|
||||
|
||||
PageInfo<TagResp> queryPage(TagFilterPage tagFilterPage, User user);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,27 @@
|
||||
package com.tencent.supersonic.headless.server.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.enums.AuthType;
|
||||
import com.tencent.supersonic.common.pojo.enums.StatusEnum;
|
||||
import com.tencent.supersonic.common.pojo.enums.TypeEnums;
|
||||
import com.tencent.supersonic.common.pojo.exception.InvalidArgumentException;
|
||||
import com.tencent.supersonic.headless.api.pojo.TagDefineParams;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.TagDefineType;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.TagReq;
|
||||
|
||||
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.TagDO;
|
||||
import com.tencent.supersonic.headless.server.persistence.repository.TagRepository;
|
||||
import com.tencent.supersonic.headless.server.pojo.TagFilter;
|
||||
import com.tencent.supersonic.headless.server.pojo.TagFilterPage;
|
||||
import com.tencent.supersonic.headless.server.service.CollectService;
|
||||
import com.tencent.supersonic.headless.server.service.ModelService;
|
||||
import com.tencent.supersonic.headless.server.service.TagService;
|
||||
import com.tencent.supersonic.headless.server.utils.NameCheckUtils;
|
||||
import java.util.ArrayList;
|
||||
@@ -19,6 +30,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
@@ -31,9 +43,14 @@ import org.springframework.stereotype.Service;
|
||||
public class TagServiceImpl implements TagService {
|
||||
|
||||
private final TagRepository tagRepository;
|
||||
private final ModelService modelService;
|
||||
private final CollectService collectService;
|
||||
|
||||
public TagServiceImpl(TagRepository tagRepository) {
|
||||
public TagServiceImpl(TagRepository tagRepository, ModelService modelService,
|
||||
CollectService collectService) {
|
||||
this.tagRepository = tagRepository;
|
||||
this.modelService = modelService;
|
||||
this.collectService = collectService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,10 +115,74 @@ public class TagServiceImpl implements TagService {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<TagResp> queryPage(TagFilterPage tagFilterPage, User user) {
|
||||
TagFilter tagFilter = new TagFilter();
|
||||
BeanUtils.copyProperties(tagFilterPage, tagFilter);
|
||||
List<ModelResp> modelRespList = modelService.getAllModelByDomainIds(tagFilterPage.getDomainIds());
|
||||
List<Long> modelIds = modelRespList.stream().map(ModelResp::getId).collect(Collectors.toList());
|
||||
tagFilterPage.getModelIds().addAll(modelIds);
|
||||
tagFilter.setModelIds(tagFilterPage.getModelIds());
|
||||
|
||||
List<CollectDO> collectList = collectService.getCollectList(user.getName())
|
||||
.stream().filter(collectDO -> TypeEnums.TAG.name().equalsIgnoreCase(collectDO.getType()))
|
||||
.collect(Collectors.toList());
|
||||
List<Long> collectIds = collectList.stream().map(CollectDO::getCollectId).collect(Collectors.toList());
|
||||
if (tagFilterPage.isHasCollect()) {
|
||||
if (CollectionUtils.isEmpty(collectIds)) {
|
||||
tagFilter.setIds(Lists.newArrayList(-1L));
|
||||
} else {
|
||||
tagFilter.setIds(collectIds);
|
||||
}
|
||||
}
|
||||
|
||||
PageInfo<TagDO> tagDOPageInfo = PageHelper.startPage(tagFilterPage.getCurrent(),
|
||||
tagFilterPage.getPageSize())
|
||||
.doSelectPageInfo(() -> query(tagFilter));
|
||||
PageInfo<TagResp> pageInfo = new PageInfo<>();
|
||||
BeanUtils.copyProperties(tagDOPageInfo, pageInfo);
|
||||
List<TagResp> tagRespList = convertList(tagDOPageInfo.getList(), collectIds);
|
||||
fillAdminRes(tagRespList, user);
|
||||
pageInfo.setList(tagRespList);
|
||||
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
private void fillAdminRes(List<TagResp> tagRespList, User user) {
|
||||
List<ModelResp> modelRespList = modelService.getModelListWithAuth(user, null, AuthType.ADMIN);
|
||||
if (CollectionUtils.isEmpty(modelRespList)) {
|
||||
return;
|
||||
}
|
||||
Set<Long> modelIdSet = modelRespList.stream().map(ModelResp::getId).collect(Collectors.toSet());
|
||||
for (TagResp tagResp : tagRespList) {
|
||||
if (modelIdSet.contains(tagResp.getModelId())) {
|
||||
tagResp.setHasAdminRes(true);
|
||||
} else {
|
||||
tagResp.setHasAdminRes(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<TagResp> convertList(List<TagDO> tagDOList, List<Long> collectIds) {
|
||||
List<TagResp> tagRespList = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(tagDOList)) {
|
||||
tagDOList.stream().forEach(tagDO -> {
|
||||
TagResp tagResp = convert(tagDO);
|
||||
if (CollectionUtils.isNotEmpty(collectIds) && collectIds.contains(tagDO.getId())) {
|
||||
tagResp.setIsCollect(true);
|
||||
} else {
|
||||
tagResp.setIsCollect(false);
|
||||
}
|
||||
tagRespList.add(tagResp);
|
||||
});
|
||||
}
|
||||
return tagRespList;
|
||||
}
|
||||
|
||||
private void checkExit(TagReq tagReq) {
|
||||
TagFilter tagFilter = new TagFilter();
|
||||
tagFilter.setModelIds(Arrays.asList(tagReq.getModelId()));
|
||||
//tagFilter.setStatusList(Arrays.asList(StatusEnum.ONLINE.getCode(),StatusEnum.OFFLINE.getCode()));
|
||||
|
||||
List<TagResp> tagResps = query(tagFilter);
|
||||
if (!CollectionUtils.isEmpty(tagResps)) {
|
||||
Long bizNameSameCount = tagResps.stream().filter(tagResp -> !tagResp.getId().equals(tagReq.getId()))
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
and ( id like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
|
||||
name like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
|
||||
biz_name like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
|
||||
description like CONCAT('%',#{key , jdbcType=VARCHAR},'%')
|
||||
description like CONCAT('%',#{key , jdbcType=VARCHAR},'%'))
|
||||
</if>
|
||||
<if test="id != null">
|
||||
and id like CONCAT('%',#{id , jdbcType=VARCHAR},'%')
|
||||
|
||||
@@ -57,7 +57,7 @@ public class PluginRecognizeTest extends BasePluginTest {
|
||||
QueryFilter queryFilter = new QueryFilter();
|
||||
queryFilter.setElementID(2L);
|
||||
queryFilter.setValue("alice");
|
||||
queryRequest.setModelId(1L);
|
||||
// queryRequest.setModelId(1L);
|
||||
queryFilters.getFilters().add(queryFilter);
|
||||
queryRequest.setQueryFilters(queryFilters);
|
||||
|
||||
|
||||
@@ -530,3 +530,23 @@ CREATE TABLE IF NOT EXISTS `s2_view` (
|
||||
`admin` varchar(3000) DEFAULT NULL,
|
||||
`admin_org` varchar(3000) DEFAULT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `s2_tag` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`model_id` INT NOT NULL ,
|
||||
`name` varchar(255) NOT NULL ,
|
||||
`biz_name` varchar(255) NOT NULL ,
|
||||
`description` varchar(500) DEFAULT NULL ,
|
||||
`status` INT NOT NULL ,
|
||||
`sensitive_level` INT NOT NULL ,
|
||||
`type` varchar(50) NOT NULL , -- ATOMIC, DERIVED
|
||||
`define_type` varchar(50) NOT NULL, -- FIELD, DIMENSION
|
||||
`type_params` LONGVARCHAR DEFAULT NULL ,
|
||||
`created_at` TIMESTAMP NOT NULL ,
|
||||
`created_by` varchar(100) NOT NULL ,
|
||||
`updated_at` TIMESTAMP DEFAULT NULL ,
|
||||
`updated_by` varchar(100) DEFAULT NULL ,
|
||||
`ext` LONGVARCHAR DEFAULT NULL ,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
COMMENT ON TABLE s2_tag IS 'tag information';
|
||||
Reference in New Issue
Block a user