数据质量规则配置目录树1
parent
8351997ee6
commit
4b33d46b79
|
@ -25,6 +25,7 @@ import java.util.List;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class QualityConfigController {
|
public class QualityConfigController {
|
||||||
private final QualityConfigService qualityConfigService;
|
private final QualityConfigService qualityConfigService;
|
||||||
|
|
||||||
@GetMapping("page")
|
@GetMapping("page")
|
||||||
@Operation(summary = "分页")
|
@Operation(summary = "分页")
|
||||||
public Result<PageResult<QualityConfigVo>> page(@Valid QualityConfigQuery query){
|
public Result<PageResult<QualityConfigVo>> page(@Valid QualityConfigQuery query){
|
||||||
|
|
|
@ -1,232 +1,12 @@
|
||||||
package net.srt.service.impl;
|
package net.srt.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import io.swagger.v3.oas.annotations.servers.Server;
|
||||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
||||||
import io.minio.messages.Metadata;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
|
||||||
import net.srt.api.module.data.governance.constant.BuiltInMetamodel;
|
|
||||||
import net.srt.convert.MetadataConvert;
|
|
||||||
import net.srt.dao.MetadataDao;
|
import net.srt.dao.MetadataDao;
|
||||||
import net.srt.dao.MetadataPropertyDao;
|
|
||||||
import net.srt.dao.MetamodelDao;
|
|
||||||
import net.srt.entity.MetadataEntity;
|
import net.srt.entity.MetadataEntity;
|
||||||
import net.srt.entity.MetadataPropertyEntity;
|
|
||||||
import net.srt.framework.common.cache.bean.Neo4jInfo;
|
|
||||||
import net.srt.framework.common.exception.ServerException;
|
|
||||||
import net.srt.framework.common.utils.BeanUtil;
|
|
||||||
import net.srt.framework.common.utils.BuildTreeUtils;
|
|
||||||
import net.srt.framework.common.utils.Result;
|
|
||||||
import net.srt.framework.common.utils.TreeNodeVo;
|
|
||||||
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
|
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
|
||||||
import net.srt.framework.security.cache.TokenStoreCache;
|
|
||||||
import net.srt.service.MetadataService;
|
import net.srt.service.MetadataService;
|
||||||
import net.srt.vo.MetadataVo;
|
@Server
|
||||||
import net.srt.vo.MetamodelPropertyVO;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: srt_cloud
|
|
||||||
* @BelongsPackage: net.srt.service.impl
|
|
||||||
* @Author: jpz
|
|
||||||
* @CreateTime: 2023/12/24 14:38
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class MetadataServiceimpl extends BaseServiceImpl<MetadataDao, MetadataEntity>implements MetadataService {
|
public class MetadataServiceImpl extends BaseServiceImpl<MetadataDao, MetadataEntity> implements MetadataService {
|
||||||
private final MetamodelDao metamodelDao;
|
|
||||||
private final MetadataPropertyDao metadataPropertyDao;
|
|
||||||
private final TokenStoreCache tokenStoreCache;
|
|
||||||
@Override
|
|
||||||
public List<TreeNodeVo> listByPatenId(Long parentId) {
|
|
||||||
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
|
||||||
wrapper.eq(MetadataEntity::getParentId,parentId).orderByAsc(MetadataEntity::getOrderNo);
|
|
||||||
dataScopeWithOrgId(wrapper);
|
|
||||||
List<MetadataEntity> list = baseMapper.selectList(wrapper);
|
|
||||||
return BeanUtil.copyListProperties(list,TreeNodeVo::new,(oldItm,newItm)->{
|
|
||||||
newItm.setLabel(oldItm.getName());
|
|
||||||
newItm.setValue(oldItm.getId());
|
|
||||||
newItm.setLeaf(BuiltInMetamodel.COLUMN.getId().equals(oldItm.getMetamodelId()));
|
|
||||||
newItm.setDisabled(!BuiltInMetamodel.COLUMN.getId().equals(oldItm.getMetamodelId()));
|
|
||||||
if (newItm.getPath().contains("/")){
|
|
||||||
newItm.setParentPath(newItm.getPath().substring(0,newItm.getPath().lastIndexOf("/")));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<TreeNodeVo> listFloder() {
|
|
||||||
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
|
||||||
wrapper.eq(MetadataEntity::getIfLeaf,1).orderByAsc(MetadataEntity::getOrderNo).orderByAsc(MetadataEntity::getId);
|
|
||||||
dataScopeWithOrgId(wrapper);
|
|
||||||
List<MetadataEntity> list = baseMapper.selectList(wrapper);
|
|
||||||
List<TreeNodeVo> treeNodeVos=BeanUtil.copyListProperties(list,TreeNodeVo::new,(oldItm,newItm)->{
|
|
||||||
newItm.setLabel(oldItm.getName());
|
|
||||||
newItm.setValue(oldItm.getId());
|
|
||||||
if (newItm.getPath().contains("/")){
|
|
||||||
newItm.setParentPath(newItm.getPath().substring(0,newItm.getPath().lastIndexOf("/")));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return BuildTreeUtils.buildTree(treeNodeVos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<TreeNodeVo> listDb() {
|
|
||||||
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
|
||||||
wrapper.in(MetadataEntity::getMetamodelId,BuiltInMetamodel.SCHEMA.getId(),BuiltInMetamodel.TABLE.getId())
|
|
||||||
.or().isNull(MetadataEntity::getMetamodelId)
|
|
||||||
.orderByAsc(MetadataEntity::getOrderNo);
|
|
||||||
dataScopeWithOrgId(wrapper);
|
|
||||||
List<MetadataEntity> list = baseMapper.selectList(wrapper);
|
|
||||||
List<TreeNodeVo> treeNodeVos=BeanUtil.copyListProperties(list,TreeNodeVo::new,(oldItm,newItm)->{
|
|
||||||
newItm.setLabel(oldItm.getName());
|
|
||||||
newItm.setValue(oldItm.getId());
|
|
||||||
if (newItm.getPath().contains("/")){
|
|
||||||
newItm.setParentPath(newItm.getPath().substring(0,newItm.getPath().lastIndexOf("/")));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return BuildTreeUtils.buildTree(treeNodeVos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<TreeNodeVo> listKeyword(String keyword) {
|
|
||||||
if (StringUtil.isBlank(keyword)){
|
|
||||||
return listByPatenId(0L);
|
|
||||||
}
|
|
||||||
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
|
||||||
wrapper.like(MetadataEntity::getName,keyword).or().like(MetadataEntity::getCode,keyword).orderByAsc(MetadataEntity::getOrderNo);
|
|
||||||
ArrayList<MetadataEntity> arrayList = new ArrayList<>();
|
|
||||||
//递归获取父级
|
|
||||||
for (MetadataEntity metadataEntity : arrayList) {
|
|
||||||
recursionAddParent(metadataEntity,arrayList);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MetadataVo get(Long id) {
|
|
||||||
MetadataEntity metadataEntity = getById(id);
|
|
||||||
MetadataVo metadataVo = MetadataConvert.INSTANCE.convert(metadataEntity);
|
|
||||||
//获取元数据属性信息
|
|
||||||
metadataVo.setProperties(metadataPropertyDao.listPropertyById(id,metadataVo.getMetamodelId()));
|
|
||||||
return metadataVo;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(MetadataVo vo) {
|
|
||||||
MetadataEntity entity=MetadataConvert.INSTANCE.convert(vo);
|
|
||||||
entity.setProjectId(getProjectId());
|
|
||||||
entity.setPath(recursionPath(entity, null));
|
|
||||||
buildField(entity);
|
|
||||||
MetadataEntity metadataEntity=baseMapper.selectById(vo.getParentId());
|
|
||||||
if (metadataEntity!=null){
|
|
||||||
entity.setDbType(metadataEntity.getDbType());
|
|
||||||
entity.setDatasourceId(metadataEntity.getDatasourceId());
|
|
||||||
entity.setCollectTaskId(metadataEntity.getCollectTaskId());
|
|
||||||
}
|
|
||||||
baseMapper.insert(entity);
|
|
||||||
buildProperties(entity,vo.getProperties());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(MetadataVo vo) {
|
|
||||||
MetadataEntity entity=MetadataConvert.INSTANCE.convert(vo);
|
|
||||||
entity.setProjectId(getProjectId());
|
|
||||||
entity.setPath(recursionPath(entity,null));
|
|
||||||
buildField(entity);
|
|
||||||
updateById(entity);
|
|
||||||
buildProperties(entity,vo.getProperties());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void delete(Long id) {
|
|
||||||
//判断是否有子节点
|
|
||||||
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
|
||||||
wrapper.eq(MetadataEntity::getParentId,id).last("limit 1");
|
|
||||||
if (baseMapper.selectOne(wrapper)!=null){
|
|
||||||
throw new ServerException("存在子节点,不可以进行删除");
|
|
||||||
}
|
|
||||||
removeById(id);
|
|
||||||
//删除属性
|
|
||||||
LambdaQueryWrapper<MetadataPropertyEntity> wrapper1 = new LambdaQueryWrapper<>();
|
|
||||||
wrapper1.eq(MetadataPropertyEntity::getMetadataId,id);
|
|
||||||
metadataPropertyDao.delete(wrapper1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateNeo4j(Neo4jInfo neo4jInfo) {
|
|
||||||
tokenStoreCache.saveNeo4jInfo(getProjectId(),neo4jInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Neo4jInfo getNeo4j() {
|
|
||||||
return tokenStoreCache.getNeo4jInfo(getProjectId());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buildProperties(MetadataEntity entity, List<MetamodelPropertyVO> properties) {
|
|
||||||
if (!CollectionUtils.isEmpty(properties)){
|
|
||||||
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
|
||||||
wrapper.eq(MetadataEntity::getMetamodelId,entity.getId());
|
|
||||||
for (MetamodelPropertyVO property : properties) {
|
|
||||||
MetadataPropertyEntity metadataPropertyEntity = new MetadataPropertyEntity();
|
|
||||||
metadataPropertyEntity.setMetamodelPropertyId(property.getId());
|
|
||||||
metadataPropertyEntity.setMetadataId(entity.getId());
|
|
||||||
metadataPropertyEntity.setProperty(property.getValue());
|
|
||||||
metadataPropertyEntity.setProjectId(entity.getProjectId());
|
|
||||||
if (property.getMetadataPropertyId()!=null){
|
|
||||||
metadataPropertyEntity.setId(property.getMetadataPropertyId());
|
|
||||||
metadataPropertyDao.updateById(metadataPropertyEntity);
|
|
||||||
}else {
|
|
||||||
metadataPropertyDao.insert(metadataPropertyEntity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buildField(MetadataEntity entity) {
|
|
||||||
if (entity.getMetamodelId() != null) {
|
|
||||||
entity.setIcon(metamodelDao.selectById(entity.getMetamodelId()).getIcon());
|
|
||||||
}
|
|
||||||
if (entity.getIfLeaf() == 1 && entity.getMetamodelId() == null) {
|
|
||||||
entity.setIcon("/src/assets/folder.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String recursionPath(MetadataEntity entity, String path) {
|
|
||||||
if (StringUtil.isBlank(path)) {
|
|
||||||
path = entity.getName();
|
|
||||||
}
|
|
||||||
if (entity.getParentId() != 0) {
|
|
||||||
MetadataEntity parent = getById(entity.getParentId());
|
|
||||||
path = parent.getName() + "/" + path;
|
|
||||||
return recursionPath(parent, path);
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void recursionAddParent(MetadataEntity metadataEntity, ArrayList<MetadataEntity> arrayList) {
|
|
||||||
if (arrayList.stream().noneMatch(item->metadataEntity.getId().equals(item.getId()))){
|
|
||||||
//添加自己
|
|
||||||
arrayList.add(metadataEntity);
|
|
||||||
}
|
|
||||||
//如果不是顶级
|
|
||||||
if (metadataEntity.getProjectId()!=0){
|
|
||||||
//获取父级,继续递归
|
|
||||||
MetadataEntity parent = getById(metadataEntity.getParentId());
|
|
||||||
recursionAddParent(parent,arrayList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue