|
@@ -31,17 +31,17 @@ def calculate_model_level(id):
|
|
|
根据child关系计算数据模型当前的level并自动保存
|
|
|
|
|
|
Args:
|
|
|
- id: 数据模型的节点ID(字符串)
|
|
|
+ id: 数据模型的节点ID(整数)
|
|
|
|
|
|
Returns:
|
|
|
None
|
|
|
"""
|
|
|
- # 确保id是字符串类型
|
|
|
- node_id = str(id) if id is not None else None
|
|
|
+ # 确保id是整数类型
|
|
|
+ node_id = int(id) if id is not None else None
|
|
|
|
|
|
cql = """
|
|
|
MATCH (start_node:data_model)
|
|
|
- WHERE elementId(start_node) = $nodeId
|
|
|
+ WHERE id(start_node) = $nodeId
|
|
|
CALL {
|
|
|
WITH start_node
|
|
|
OPTIONAL MATCH path = (start_node)-[:child*]->(end_node)
|
|
@@ -59,7 +59,7 @@ def calculate_model_level(id):
|
|
|
# 更新level属性
|
|
|
update_query = """
|
|
|
MATCH (n:data_model)
|
|
|
- WHERE elementId(n) = $nodeId
|
|
|
+ WHERE id(n) = $nodeId
|
|
|
SET n.level = $level
|
|
|
RETURN n
|
|
|
"""
|
|
@@ -342,243 +342,120 @@ def handle_no_meta_data_model(id_lists, receiver, data_model_node):
|
|
|
)
|
|
|
|
|
|
|
|
|
-# 定义查询数据模型详情的Cypher查询
|
|
|
-def type_cql_query():
|
|
|
- """
|
|
|
- 构建获取数据模型详情的Cypher查询
|
|
|
-
|
|
|
- Returns:
|
|
|
- 查询语句
|
|
|
- """
|
|
|
- query = """
|
|
|
- MATCH (n:data_model)
|
|
|
- WHERE elementId(n) = $nodeId
|
|
|
- // 获取元数据节点, 数据模型
|
|
|
- WITH n
|
|
|
- OPTIONAL MATCH (n)-[:connection]->(a:meta_node)
|
|
|
- // 获取数据标准
|
|
|
- OPTIONAL MATCH (n)-[:clean_model]-(d:data_standard)-[:clean_model]->(a)
|
|
|
- // 获取数据标签
|
|
|
- OPTIONAL MATCH (n)-[:label]->(la:data_label)
|
|
|
- // 获取子节点关系
|
|
|
- OPTIONAL MATCH (n)-[:child]->(child_node:data_model)
|
|
|
- // 收集元数据信息,注意ma变量未定义,需要修复
|
|
|
- OPTIONAL MATCH (a)-[:master_data]->(ma:master_data)
|
|
|
- WITH n, a, d, la, collect(DISTINCT {id: elementId(child_node), name: child_node.name}) AS childrenId, ma
|
|
|
- // 收集元数据信息并排序
|
|
|
- WITH n, collect(DISTINCT {
|
|
|
- id: elementId(a),
|
|
|
- name: COALESCE(a.name, ""),
|
|
|
- en_name: COALESCE(a.en_name, ""),
|
|
|
- data_type: COALESCE(a.data_type, ""),
|
|
|
- master_data: CASE
|
|
|
- WHEN ma IS NOT NULL THEN {id: elementId(ma), name: COALESCE(ma.name, "")}
|
|
|
- ELSE NULL
|
|
|
- END,
|
|
|
- data_standard: CASE
|
|
|
- WHEN d IS NOT NULL THEN {id: elementId(d), name: COALESCE(d.name, "")}
|
|
|
- ELSE NULL
|
|
|
- END
|
|
|
- }) AS meta_ids,
|
|
|
- properties(n) AS properties,
|
|
|
- CASE
|
|
|
- WHEN la IS NOT NULL THEN {id: elementId(la), name: COALESCE(la.name, "")}
|
|
|
- ELSE NULL
|
|
|
- END AS tag,
|
|
|
- childrenId
|
|
|
- // 对 meta_ids 进行排序
|
|
|
- UNWIND meta_ids AS meta_id
|
|
|
- WITH n, tag, properties, childrenId, meta_id
|
|
|
- ORDER BY meta_id.id
|
|
|
- WITH n, tag, properties, childrenId, collect(meta_id) AS sorted_meta_ids
|
|
|
- // 构建结果集
|
|
|
- WITH [{data_resource: null, resource_id: null, meta_ids: sorted_meta_ids}] AS resources,
|
|
|
- elementId(n) as nodeid, tag, properties, n, childrenId
|
|
|
- UNWIND resources as resource
|
|
|
- WITH nodeid, collect(resource) as results, tag, properties, n, childrenId
|
|
|
- // 合并结果集
|
|
|
- RETURN results, tag, properties, childrenId
|
|
|
- """
|
|
|
-
|
|
|
- return query
|
|
|
-
|
|
|
-
|
|
|
-# 数据模型编辑接口
|
|
|
+# 数据模型-详情接口
|
|
|
def handle_id_model(id):
|
|
|
"""
|
|
|
- 获取数据模型详情
|
|
|
+ 处理数据模型详情请求,查询指定ID的数据模型节点的完整信息
|
|
|
|
|
|
Args:
|
|
|
- id: 数据模型ID (字符串)
|
|
|
+ id: 数据模型节点ID
|
|
|
|
|
|
Returns:
|
|
|
- 数据模型详情
|
|
|
- """
|
|
|
- # 获取数据模型的名称,元数据名称,对应选中的数据资源名称
|
|
|
- query = type_cql_query()
|
|
|
-
|
|
|
- # 确保id参数为字符串类型并进行日志输出
|
|
|
- node_id = str(id) if id is not None else None
|
|
|
- print(f"Querying data model with elementId: {node_id}")
|
|
|
-
|
|
|
- with connect_graph().session() as session:
|
|
|
- try:
|
|
|
- result = session.run(query, nodeId=node_id)
|
|
|
- data_ = result.data()
|
|
|
- print(f"Query result: {data_}")
|
|
|
-
|
|
|
- if not data_:
|
|
|
- print(f"No data found for elementId: {node_id}")
|
|
|
- return {"data_model": {}}
|
|
|
-
|
|
|
- res_list = []
|
|
|
- properties = {}
|
|
|
-
|
|
|
- for record in data_:
|
|
|
- if 'results' in record:
|
|
|
- res_list = record['results']
|
|
|
- if 'properties' in record:
|
|
|
- properties = record['properties']
|
|
|
- if 'tag' in record and record['tag'] is not None:
|
|
|
- properties['tag'] = record['tag']
|
|
|
- if 'childrenId' in record and record['childrenId'] is not None:
|
|
|
- properties['childrenId'] = record['childrenId']
|
|
|
-
|
|
|
- # 处理id值,确保是字符串格式
|
|
|
- if 'id' in properties and properties['id'] is not None:
|
|
|
- properties['id'] = str(properties['id'])
|
|
|
-
|
|
|
- # 处理tag中的id
|
|
|
- if 'tag' in properties and properties['tag'] is not None and 'id' in properties['tag']:
|
|
|
- properties['tag']['id'] = str(properties['tag']['id'])
|
|
|
-
|
|
|
- # 处理childrenId列表中的id
|
|
|
- if 'childrenId' in properties and properties['childrenId']:
|
|
|
- for child in properties['childrenId']:
|
|
|
- if 'id' in child:
|
|
|
- child['id'] = str(child['id'])
|
|
|
-
|
|
|
- properties.pop('id_list', None)
|
|
|
- if 'tag' not in properties:
|
|
|
- properties['tag'] = None
|
|
|
- if 'describe' not in properties:
|
|
|
- properties['describe'] = None
|
|
|
-
|
|
|
- # 处理结果中的id值为字符串
|
|
|
- if res_list:
|
|
|
- for res in res_list:
|
|
|
- if 'resource_id' in res and res['resource_id'] is not None:
|
|
|
- res['resource_id'] = str(res['resource_id'])
|
|
|
- if 'meta_ids' in res:
|
|
|
- for meta in res['meta_ids']:
|
|
|
- if 'id' in meta:
|
|
|
- meta['id'] = str(meta['id'])
|
|
|
- if 'data_standard' in meta and meta['data_standard'] and 'id' in meta['data_standard']:
|
|
|
- meta['data_standard']['id'] = str(meta['data_standard']['id'])
|
|
|
- if 'master_data' in meta and meta['master_data'] and 'id' in meta['master_data']:
|
|
|
- meta['master_data']['id'] = str(meta['master_data']['id'])
|
|
|
-
|
|
|
- res_dict = {"resource_selected": res_list}
|
|
|
- merged_dict = {**res_dict, **properties}
|
|
|
- response_data = {"data_model": merged_dict}
|
|
|
-
|
|
|
- return response_data
|
|
|
- except Exception as e:
|
|
|
- print(f"Error in handle_id_model: {str(e)}")
|
|
|
- import traceback
|
|
|
- traceback.print_exc()
|
|
|
- return {"data_model": {}}
|
|
|
-
|
|
|
-
|
|
|
-# 数据模型详情
|
|
|
-'''
|
|
|
-def handle_id_model(model_id):
|
|
|
- """
|
|
|
- 获取数据模型详情
|
|
|
-
|
|
|
- Args:
|
|
|
- model_id: 数据模型ID
|
|
|
-
|
|
|
- Returns:
|
|
|
- 数据模型详情
|
|
|
- """
|
|
|
- model_detail_query = """
|
|
|
- MATCH (n:data_model) WHERE id(n) = $model_id
|
|
|
- RETURN n
|
|
|
- """
|
|
|
-
|
|
|
- with connect_graph().session() as session:
|
|
|
- model_detail_result = session.run(model_detail_query, model_id=model_id).data()
|
|
|
-
|
|
|
- if not model_detail_result:
|
|
|
- return None
|
|
|
-
|
|
|
- model_detail = model_detail_result[0]['n']
|
|
|
- model_info = dict(model_detail)
|
|
|
- model_info['id'] = model_id
|
|
|
-
|
|
|
- # 获取data_model节点连接的resource节点
|
|
|
- resource_query = """
|
|
|
- MATCH (n:data_model)-[:resource]->(r:data_resource) WHERE id(n) = $model_id
|
|
|
- RETURN r
|
|
|
- """
|
|
|
- resource_result = session.run(resource_query, model_id=model_id).data()
|
|
|
- resources = []
|
|
|
-
|
|
|
- for item in resource_result:
|
|
|
- if 'r' in item and hasattr(item['r'], 'id'):
|
|
|
- resource = dict(item['r'])
|
|
|
- resource['id'] = item['r'].id
|
|
|
- resources.append(resource)
|
|
|
-
|
|
|
- model_info['resources'] = resources
|
|
|
-
|
|
|
- # 获取data_model节点连接的component节点
|
|
|
- component_query = """
|
|
|
- MATCH (n:data_model)-[:component]->(m:meta_node) WHERE id(n) = $model_id
|
|
|
- RETURN m
|
|
|
- """
|
|
|
- component_result = session.run(component_query, model_id=model_id).data()
|
|
|
- components = []
|
|
|
-
|
|
|
- for item in component_result:
|
|
|
- if 'm' in item and hasattr(item['m'], 'id'):
|
|
|
- component = dict(item['m'])
|
|
|
- component['id'] = item['m'].id
|
|
|
- components.append(component)
|
|
|
-
|
|
|
- model_info['components'] = components
|
|
|
-
|
|
|
- # 获取data_model节点连接的use节点
|
|
|
- use_query = """
|
|
|
- MATCH (n:data_model)-[:use]->(u:data_model) WHERE id(n) = $model_id
|
|
|
- RETURN u
|
|
|
- """
|
|
|
- use_result = session.run(use_query, model_id=model_id).data()
|
|
|
- uses = []
|
|
|
-
|
|
|
- for item in use_result:
|
|
|
- if 'u' in item and hasattr(item['u'], 'id'):
|
|
|
- use = dict(item['u'])
|
|
|
- use['id'] = item['u'].id
|
|
|
- uses.append(use)
|
|
|
-
|
|
|
- model_info['uses'] = uses
|
|
|
-
|
|
|
- # 获取data_model节点连接的标签
|
|
|
- tag_query = """
|
|
|
- MATCH (n:data_model)-[:label]->(t:data_label) WHERE id(n) = $model_id
|
|
|
- RETURN t
|
|
|
+ dict: 包含数据模型完整详情信息的字典
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ # 确保id是整数类型
|
|
|
+ node_id = int(id) if id is not None else None
|
|
|
+
|
|
|
+ logging.info(f"查询数据模型详情,ID: {node_id}")
|
|
|
+
|
|
|
+ # 构建Cypher查询 - 查询模型基本信息和关联节点
|
|
|
+ cql = """
|
|
|
+ MATCH (n:data_model)
|
|
|
+ WHERE id(n) = $nodeId
|
|
|
+
|
|
|
+ // 获取与模型关联的资源节点
|
|
|
+ OPTIONAL MATCH (n)-[:resource]->(resource:data_resource)
|
|
|
+
|
|
|
+ // 获取与模型关联的数据源节点
|
|
|
+ OPTIONAL MATCH (n)-[:use]->(source:data_source)
|
|
|
+
|
|
|
+ // 获取模型的标签
|
|
|
+ OPTIONAL MATCH (n)-[:label]->(tag:data_label)
|
|
|
+
|
|
|
+ // 获取模型的下级节点(子节点)
|
|
|
+ OPTIONAL MATCH (n)-[:child]->(child:data_model)
|
|
|
+
|
|
|
+ // 获取模型关联的元数据节点
|
|
|
+ OPTIONAL MATCH (n)-[:component]->(meta:meta_node)
|
|
|
+
|
|
|
+ // 收集所有关联节点信息
|
|
|
+ WITH n,
|
|
|
+ collect(DISTINCT resource) AS resources,
|
|
|
+ collect(DISTINCT source) AS sources,
|
|
|
+ tag,
|
|
|
+ collect(DISTINCT {id: id(child), name: child.name, en_name: child.en_name}) AS children,
|
|
|
+ collect(DISTINCT meta) AS meta_nodes
|
|
|
+
|
|
|
+ RETURN {
|
|
|
+ // 基本信息
|
|
|
+ id: id(n),
|
|
|
+ name: n.name,
|
|
|
+ en_name: n.en_name,
|
|
|
+ // 标签信息从tag变量中获取
|
|
|
+ label: tag.name,
|
|
|
+ time: n.time,
|
|
|
+ description: n.description,
|
|
|
+ category: n.category,
|
|
|
+ level: n.level,
|
|
|
+
|
|
|
+ // 标签信息
|
|
|
+ tag: CASE
|
|
|
+ WHEN tag IS NOT NULL THEN {id: id(tag), name: tag.name}
|
|
|
+ ELSE null
|
|
|
+ END,
|
|
|
+
|
|
|
+ // 关联的资源列表
|
|
|
+ resources: [resource IN resources WHERE resource IS NOT NULL | {
|
|
|
+ id: id(resource),
|
|
|
+ name: resource.name,
|
|
|
+ en_name: resource.en_name,
|
|
|
+ description: resource.description
|
|
|
+ }],
|
|
|
+
|
|
|
+ // 关联的数据源列表
|
|
|
+ sources: [source IN sources WHERE source IS NOT NULL | {
|
|
|
+ id: id(source),
|
|
|
+ name: source.name,
|
|
|
+ en_name: source.en_name
|
|
|
+ }],
|
|
|
+
|
|
|
+ // 子节点列表
|
|
|
+ children: children,
|
|
|
+
|
|
|
+ // 元数据列表
|
|
|
+ meta_nodes: [meta IN meta_nodes WHERE meta IS NOT NULL | {
|
|
|
+ id: id(meta),
|
|
|
+ name: meta.name,
|
|
|
+ en_name: meta.en_name,
|
|
|
+ data_type: meta.data_type
|
|
|
+ }],
|
|
|
+
|
|
|
+ // 原始属性
|
|
|
+ properties: properties(n)
|
|
|
+ } AS result
|
|
|
"""
|
|
|
- tag_result = session.run(tag_query, model_id=model_id).data()
|
|
|
-
|
|
|
- if tag_result and 't' in tag_result[0] and hasattr(tag_result[0]['t'], 'id'):
|
|
|
- tag = dict(tag_result[0]['t'])
|
|
|
- tag['id'] = tag_result[0]['t'].id
|
|
|
- model_info['tag'] = tag
|
|
|
|
|
|
- return model_info
|
|
|
-'''
|
|
|
+ with connect_graph().session() as session:
|
|
|
+ result = session.run(cql, nodeId=node_id)
|
|
|
+
|
|
|
+ # 处理查询结果
|
|
|
+ record = result.single()
|
|
|
+ logging.info(f"获得查询结果---------->>>{record}")
|
|
|
+
|
|
|
+ # 直接检查record是否存在,而不是检查"result"键
|
|
|
+ if record:
|
|
|
+ # 已经包含"result"键,直接获取其值
|
|
|
+ data_model = record["result"]
|
|
|
+ logging.info(f"成功获取数据模型详情,ID: {node_id}")
|
|
|
+ return data_model
|
|
|
+ else:
|
|
|
+ logging.warning(f"未找到ID为 {node_id} 的数据模型")
|
|
|
+ return {}
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ logging.error(f"获取数据模型详情出错: {str(e)}", exc_info=True)
|
|
|
+ return {}
|
|
|
|
|
|
|
|
|
# 数据模型列表
|
|
@@ -588,424 +465,497 @@ def model_list(skip_count, page_size, en_name_filter=None, name_filter=None,
|
|
|
获取数据模型列表
|
|
|
|
|
|
Args:
|
|
|
- skip_count: 跳过的记录数量
|
|
|
- page_size: 每页记录数量
|
|
|
+ skip_count: 跳过的数量
|
|
|
+ page_size: 页面大小
|
|
|
en_name_filter: 英文名称过滤条件
|
|
|
name_filter: 名称过滤条件
|
|
|
- category: 分类过滤条件
|
|
|
+ category: 类别过滤条件
|
|
|
tag: 标签过滤条件
|
|
|
- level: 级别过滤条件
|
|
|
+ level: 层级过滤条件
|
|
|
|
|
|
Returns:
|
|
|
- tuple: (数据列表, 总记录数)
|
|
|
- """
|
|
|
- # 构建查询条件
|
|
|
- params = {}
|
|
|
- match_clause = "MATCH (n:data_model)"
|
|
|
- where_clause = []
|
|
|
-
|
|
|
- if tag:
|
|
|
- match_clause = "MATCH (n:data_model)-[:label]->(t:data_label)"
|
|
|
- where_clause.append("elementId(t) = $tag")
|
|
|
- params['tag'] = str(tag)
|
|
|
-
|
|
|
- if name_filter:
|
|
|
- where_clause.append("n.name =~ $name_filter")
|
|
|
- params['name_filter'] = f"(?i).*{name_filter}.*"
|
|
|
-
|
|
|
- if en_name_filter:
|
|
|
- where_clause.append("n.en_name =~ $en_name_filter")
|
|
|
- params['en_name_filter'] = f"(?i).*{en_name_filter}.*"
|
|
|
-
|
|
|
- if category:
|
|
|
- where_clause.append("n.category = $category")
|
|
|
- params['category'] = category
|
|
|
-
|
|
|
- if level:
|
|
|
- where_clause.append("n.level = $level")
|
|
|
- params['level'] = level
|
|
|
-
|
|
|
- # 转换为字符串形式
|
|
|
- where_str = " AND ".join(where_clause)
|
|
|
- if where_str:
|
|
|
- where_str = "WHERE " + where_str
|
|
|
-
|
|
|
- # 获取数据总数
|
|
|
- count_query = f"""
|
|
|
- {match_clause}
|
|
|
- {where_str}
|
|
|
- RETURN count(n) as count
|
|
|
+ tuple: (数据模型列表, 总数量)
|
|
|
"""
|
|
|
-
|
|
|
- # 使用正确的session方式执行查询
|
|
|
- driver = connect_graph()
|
|
|
- if not driver:
|
|
|
- return [], 0
|
|
|
-
|
|
|
- with driver.session() as session:
|
|
|
- count_result = session.run(count_query, **params)
|
|
|
- count = count_result.single()["count"]
|
|
|
+ try:
|
|
|
+ # 构建where子句
|
|
|
+ where_clause = []
|
|
|
+ params = {}
|
|
|
+
|
|
|
+ if name_filter is not None:
|
|
|
+ where_clause.append("n.name =~ $name")
|
|
|
+ params['name'] = f".*{name_filter}.*"
|
|
|
|
|
|
- # 获取分页数据
|
|
|
- params['skip'] = skip_count
|
|
|
- params['limit'] = page_size
|
|
|
+ if en_name_filter is not None:
|
|
|
+ where_clause.append("n.en_name =~ $en_name")
|
|
|
+ params['en_name'] = f".*{en_name_filter}.*"
|
|
|
+
|
|
|
+ if category is not None:
|
|
|
+ where_clause.append("n.category = $category")
|
|
|
+ params['category'] = category
|
|
|
+
|
|
|
+ if level is not None:
|
|
|
+ where_clause.append("n.level = $level")
|
|
|
+ params['level'] = level
|
|
|
+
|
|
|
+ if tag is not None:
|
|
|
+ where_clause.append("id(t) = $tag")
|
|
|
+ params['tag'] = tag
|
|
|
+
|
|
|
+ # 处理where子句
|
|
|
+ where_str = " AND ".join(where_clause)
|
|
|
+ if where_str:
|
|
|
+ where_str = f"WHERE {where_str}"
|
|
|
|
|
|
- data_query = f"""
|
|
|
- {match_clause}
|
|
|
- {where_str}
|
|
|
- OPTIONAL MATCH (n)-[:label]->(t:data_label)
|
|
|
- WITH n, t
|
|
|
- OPTIONAL MATCH (n)-[:component]->(m:meta_node)
|
|
|
- RETURN
|
|
|
- elementId(n) as id,
|
|
|
- n.name as name,
|
|
|
- n.en_name as en_name,
|
|
|
- n.category as category,
|
|
|
- n.description as description,
|
|
|
+ # 构建查询
|
|
|
+ with connect_graph().session() as session:
|
|
|
+ # 计算总数量
|
|
|
+ count_query = f"""
|
|
|
+ MATCH (n:data_model)
|
|
|
+ OPTIONAL MATCH (n)-[:label]->(t)
|
|
|
+ {where_str}
|
|
|
+ RETURN COUNT(DISTINCT n) AS count
|
|
|
+ """
|
|
|
+ count_result = session.run(count_query, **params)
|
|
|
+ count_record = count_result.single()
|
|
|
+ total = count_record['count'] if count_record else 0
|
|
|
+
|
|
|
+ # 查询数据
|
|
|
+ query = f"""
|
|
|
+ MATCH (n:data_model)
|
|
|
+ OPTIONAL MATCH (n)-[:label]->(t)
|
|
|
+ {where_str}
|
|
|
+ RETURN DISTINCT
|
|
|
+ id(n) as id,
|
|
|
+ n.name as name,
|
|
|
+ n.en_name as en_name,
|
|
|
n.time as time,
|
|
|
+ n.description as description,
|
|
|
n.level as level,
|
|
|
- t.name as tag_name,
|
|
|
- elementId(t) as tag_id,
|
|
|
- count(m) as component_count
|
|
|
- ORDER BY n.time DESC
|
|
|
- SKIP $skip
|
|
|
- LIMIT $limit
|
|
|
- """
|
|
|
-
|
|
|
- result = session.run(data_query, **params)
|
|
|
- data = result.data()
|
|
|
-
|
|
|
- # 确保结果中的ID是字符串格式
|
|
|
- for item in data:
|
|
|
- if 'id' in item:
|
|
|
- item['id'] = str(item['id'])
|
|
|
- if 'tag_id' in item and item['tag_id'] is not None:
|
|
|
- item['tag_id'] = str(item['tag_id'])
|
|
|
-
|
|
|
- return data, count
|
|
|
+ id(t) as tag_id,
|
|
|
+ t.name as tag_name
|
|
|
+ ORDER BY n.time DESC
|
|
|
+ SKIP $skip
|
|
|
+ LIMIT $limit
|
|
|
+ """
|
|
|
+
|
|
|
+ result = session.run(query, skip=skip_count, limit=page_size, **params)
|
|
|
+
|
|
|
+ # 处理结果
|
|
|
+ data = []
|
|
|
+ for record in result:
|
|
|
+ item = {
|
|
|
+ "id": record['id'],
|
|
|
+ "name": record['name'],
|
|
|
+ "en_name": record['en_name'],
|
|
|
+ "time": record['time'],
|
|
|
+ "description": record['description'],
|
|
|
+ "level": record['level'],
|
|
|
+ "tag": {"id": record['tag_id'], "name": record['tag_name']} if record['tag_id'] is not None else None
|
|
|
+ }
|
|
|
+ data.append(item)
|
|
|
+
|
|
|
+ return data, total
|
|
|
+ except Exception as e:
|
|
|
+ print(f"Error in model_list: {str(e)}")
|
|
|
+ import traceback
|
|
|
+ traceback.print_exc()
|
|
|
+ return [], 0
|
|
|
|
|
|
|
|
|
# 有血缘关系的数据资源列表
|
|
|
def model_resource_list(skip_count, page_size, name_filter=None, id=None,
|
|
|
category=None, time=None):
|
|
|
"""
|
|
|
- 获取有血缘关系的数据资源列表
|
|
|
+ 获取数据模型相关的数据资源列表
|
|
|
|
|
|
Args:
|
|
|
- skip_count: 跳过的记录数量
|
|
|
- page_size: 每页记录数量
|
|
|
+ skip_count: 跳过的数量
|
|
|
+ page_size: 页面大小
|
|
|
name_filter: 名称过滤条件
|
|
|
- id: 数据资源ID
|
|
|
- category: 分类过滤条件
|
|
|
+ id: 数据模型ID
|
|
|
+ category: 类别过滤条件
|
|
|
time: 时间过滤条件
|
|
|
|
|
|
Returns:
|
|
|
- tuple: (数据列表, 总记录数)
|
|
|
- """
|
|
|
- # 构建查询条件
|
|
|
- params = {'id': id}
|
|
|
- where_clause = []
|
|
|
-
|
|
|
- if name_filter:
|
|
|
- where_clause.append("n.name =~ $name_filter")
|
|
|
- params['name_filter'] = f"(?i).*{name_filter}.*"
|
|
|
-
|
|
|
- if category:
|
|
|
- where_clause.append("n.category = $category")
|
|
|
- params['category'] = category
|
|
|
-
|
|
|
- if time:
|
|
|
- where_clause.append("n.time >= $time")
|
|
|
- params['time'] = time
|
|
|
-
|
|
|
- # 转换为字符串形式
|
|
|
- where_str = " AND ".join(where_clause)
|
|
|
- if where_str:
|
|
|
- where_str = "WHERE " + where_str
|
|
|
-
|
|
|
- # 获取数据总数
|
|
|
- count_query = f"""
|
|
|
- MATCH (search:data_resource) WHERE id(search) = $id
|
|
|
- MATCH (search)-[:connection]->(mn:meta_node)<-[:connection]-(n:data_resource)
|
|
|
- {where_str}
|
|
|
- RETURN count(DISTINCT n) as count
|
|
|
- """
|
|
|
-
|
|
|
- # 使用正确的session方式执行查询
|
|
|
- driver = connect_graph()
|
|
|
- if not driver:
|
|
|
- return [], 0
|
|
|
-
|
|
|
- with driver.session() as session:
|
|
|
- count_result = session.run(count_query, **params)
|
|
|
- count = count_result.single()["count"]
|
|
|
-
|
|
|
- # 获取分页数据
|
|
|
- params['skip'] = skip_count
|
|
|
- params['limit'] = page_size
|
|
|
-
|
|
|
- data_query = f"""
|
|
|
- MATCH (search:data_resource) WHERE id(search) = $id
|
|
|
- MATCH (search)-[:connection]->(mn:meta_node)<-[:connection]-(n:data_resource)
|
|
|
- {where_str}
|
|
|
- WITH DISTINCT n, mn
|
|
|
- RETURN
|
|
|
- id(n) as id,
|
|
|
- n.name as name,
|
|
|
- n.en_name as en_name,
|
|
|
- n.category as category,
|
|
|
- n.description as description,
|
|
|
- n.time as time,
|
|
|
- collect({{id: id(mn), name: mn.name}}) as common_meta
|
|
|
- ORDER BY n.time DESC
|
|
|
- SKIP $skip
|
|
|
- LIMIT $limit
|
|
|
+ tuple: (数据资源列表, 总数量)
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ # 构建基础查询
|
|
|
+ base_query = """
|
|
|
+ MATCH (n:data_model)
|
|
|
+ WHERE id(n) = $nodeId
|
|
|
+ MATCH (n)-[:children]->(m:data_resource)
|
|
|
"""
|
|
|
|
|
|
- result = session.run(data_query, **params)
|
|
|
- data = result.data()
|
|
|
+ # 计算总数量
|
|
|
+ count_query = base_query + """
|
|
|
+ RETURN COUNT(m) as count
|
|
|
+ """
|
|
|
|
|
|
- return data, count
|
|
|
+ with connect_graph().session() as session:
|
|
|
+ # 执行计数查询
|
|
|
+ count_result = session.run(count_query, nodeId=id)
|
|
|
+ count_record = count_result.single()
|
|
|
+ total = count_record['count'] if count_record else 0
|
|
|
+
|
|
|
+ # 使用分页和筛选条件构建主查询
|
|
|
+ main_query = base_query + """
|
|
|
+ MATCH (m)-[:label]->(l)
|
|
|
+ WHERE id(n) = $nodeId and labels(m) <> ['meta_node']
|
|
|
+ RETURN m.name as name,
|
|
|
+ m.en_name as en_name,
|
|
|
+ id(m) as id,
|
|
|
+ l.name as label,
|
|
|
+ m.time as time,
|
|
|
+ m.description as description,
|
|
|
+ m.category as category
|
|
|
+ ORDER BY m.time DESC
|
|
|
+ SKIP $skip LIMIT $limit
|
|
|
+ """
|
|
|
+
|
|
|
+ # 执行主查询
|
|
|
+ result = session.run(main_query, nodeId=id, skip=skip_count, limit=page_size)
|
|
|
+
|
|
|
+ # 处理结果
|
|
|
+ data = []
|
|
|
+ for record in result:
|
|
|
+ item = {
|
|
|
+ "name": record['name'],
|
|
|
+ "en_name": record['en_name'],
|
|
|
+ "id": record['id'],
|
|
|
+ "label": record['label'],
|
|
|
+ "time": record['time'],
|
|
|
+ "description": record['description'],
|
|
|
+ "category": record['category']
|
|
|
+ }
|
|
|
+ data.append(item)
|
|
|
+
|
|
|
+ return data, total
|
|
|
+ except Exception as e:
|
|
|
+ print(f"Error in model_resource_list: {str(e)}")
|
|
|
+ import traceback
|
|
|
+ traceback.print_exc()
|
|
|
+ return [], 0
|
|
|
|
|
|
|
|
|
# 数据模型血缘图谱
|
|
|
def model_kinship_graph(nodeid, meta=False):
|
|
|
"""
|
|
|
- 获取数据模型血缘图谱
|
|
|
+ 生成数据模型的血缘关系图谱
|
|
|
|
|
|
Args:
|
|
|
- nodeid: 节点ID(字符串)
|
|
|
- meta: 是否返回元数据
|
|
|
+ nodeid: 节点ID
|
|
|
+ meta: 是否包含元数据
|
|
|
|
|
|
Returns:
|
|
|
- 图谱数据
|
|
|
+ dict: 包含节点和连线信息的图谱数据
|
|
|
"""
|
|
|
- # 确保nodeid是字符串类型
|
|
|
- node_id = str(nodeid) if nodeid is not None else None
|
|
|
+ result = {}
|
|
|
|
|
|
- if meta:
|
|
|
- query = """
|
|
|
- MATCH p = (n:data_model)-[r:component|resource*..3]-(m)
|
|
|
- WHERE elementId(n) = $nodeId
|
|
|
- WITH p, relationships(p) as rels
|
|
|
- RETURN p
|
|
|
- limit 300
|
|
|
+ with connect_graph().session() as session:
|
|
|
+ # 查询起始模型节点
|
|
|
+ start_node_query = """
|
|
|
+ MATCH (n:data_model)
|
|
|
+ WHERE id(n) = $nodeId
|
|
|
+ RETURN n.name as name, n.en_name as en_name
|
|
|
"""
|
|
|
- else:
|
|
|
- query = """
|
|
|
- MATCH p = (n:data_model)-[r:resource*..3]-(m)
|
|
|
- WHERE elementId(n) = $nodeId and labels(m) <> ['meta_node']
|
|
|
- WITH p, relationships(p) as rels
|
|
|
- RETURN p
|
|
|
- limit 300
|
|
|
+
|
|
|
+ start_result = session.run(start_node_query, nodeId=nodeid)
|
|
|
+ start_record = start_result.single()
|
|
|
+
|
|
|
+ if not start_record:
|
|
|
+ return {"nodes": [], "lines": []}
|
|
|
+
|
|
|
+ # 查询与模型关联的数据资源
|
|
|
+ resource_query = """
|
|
|
+ MATCH (n:data_model)
|
|
|
+ WHERE id(n) = $nodeId
|
|
|
+ MATCH p = (n)-[:children]->(resource:data_resource)
|
|
|
+ RETURN resource
|
|
|
"""
|
|
|
-
|
|
|
- # 使用正确的session方式执行查询
|
|
|
- driver = connect_graph()
|
|
|
- if not driver:
|
|
|
- return {"nodes": [], "edges": []}
|
|
|
|
|
|
- with driver.session() as session:
|
|
|
- result = session.run(query, nodeId=node_id)
|
|
|
+ resource_result = session.run(resource_query, nodeId=nodeid)
|
|
|
|
|
|
- nodes = set()
|
|
|
- relationships = set()
|
|
|
- nodes_by_id = {}
|
|
|
+ nodes = [{"id": str(nodeid), "text": start_record['name'], "type": "model"}]
|
|
|
+ lines = []
|
|
|
|
|
|
- for record in result:
|
|
|
- path = record["p"]
|
|
|
+ # 处理资源节点
|
|
|
+ for record in resource_result:
|
|
|
+ if 'resource' in record:
|
|
|
+ resource = record['resource']
|
|
|
+ resource_id = str(resource.id)
|
|
|
+ resource_name = resource.get('name', '')
|
|
|
+ resource_en_name = resource.get('en_name', '')
|
|
|
+
|
|
|
+ # 创建资源节点
|
|
|
+ resource_node = {
|
|
|
+ "id": resource_id,
|
|
|
+ "text": resource_name,
|
|
|
+ "type": "resource"
|
|
|
+ }
|
|
|
+ nodes.append(resource_node)
|
|
|
+
|
|
|
+ # 创建资源到模型的关系
|
|
|
+ line = {
|
|
|
+ "from": str(nodeid),
|
|
|
+ "to": resource_id,
|
|
|
+ "text": "resource"
|
|
|
+ }
|
|
|
+ lines.append(line)
|
|
|
+
|
|
|
+ # 处理元数据节点
|
|
|
+ if meta:
|
|
|
+ meta_query = """
|
|
|
+ MATCH (n:data_model)
|
|
|
+ WHERE id(n) = $nodeId and labels(m) <> ['meta_node']
|
|
|
+ MATCH p = (n)-[:meta]->(meta:meta_node)
|
|
|
+ RETURN meta
|
|
|
+ """
|
|
|
+ meta_result = session.run(meta_query, nodeId=nodeid)
|
|
|
|
|
|
- for node in path.nodes:
|
|
|
- node_id_str = str(node.element_id) if hasattr(node, 'element_id') else str(node.id)
|
|
|
- if node_id_str not in nodes:
|
|
|
- node_type = list(node.labels)[0].split('_')[1]
|
|
|
- node_data = {
|
|
|
- "id": node_id_str,
|
|
|
- "text": node.get("name", ""),
|
|
|
- "type": node_type
|
|
|
+ for record in meta_result:
|
|
|
+ if 'meta' in record:
|
|
|
+ meta_node = record['meta']
|
|
|
+ meta_id = str(meta.id)
|
|
|
+ meta_name = meta.get('name', '')
|
|
|
+ meta_en_name = meta.get('en_name', '')
|
|
|
+
|
|
|
+ # 创建元数据节点
|
|
|
+ meta_node = {
|
|
|
+ "id": meta_id,
|
|
|
+ "text": meta_name,
|
|
|
+ "type": "meta"
|
|
|
}
|
|
|
+ nodes.append(meta_node)
|
|
|
|
|
|
- nodes.add(node_id_str)
|
|
|
- nodes_by_id[node_id_str] = node_data
|
|
|
-
|
|
|
- for rel in path.relationships:
|
|
|
- start_id = str(rel.start_node.element_id) if hasattr(rel.start_node, 'element_id') else str(rel.start_node.id)
|
|
|
- end_id = str(rel.end_node.element_id) if hasattr(rel.end_node, 'element_id') else str(rel.end_node.id)
|
|
|
- relationship_id = f"{start_id}-{end_id}"
|
|
|
- if relationship_id not in relationships:
|
|
|
- relationship_data = {
|
|
|
- "from": start_id,
|
|
|
- "to": end_id,
|
|
|
- "text": type(rel).__name__
|
|
|
+ # 创建模型到元数据的标签关系
|
|
|
+ tag_line = {
|
|
|
+ "from": str(nodeid),
|
|
|
+ "to": meta_id,
|
|
|
+ "text": "component"
|
|
|
}
|
|
|
- relationships.add(relationship_id)
|
|
|
-
|
|
|
- # 转换为所需格式
|
|
|
- return {
|
|
|
- "nodes": list(nodes_by_id.values()),
|
|
|
- "edges": [{"from": rel.split("-")[0], "to": rel.split("-")[1], "text": ""}
|
|
|
- for rel in relationships]
|
|
|
+ lines.append(tag_line)
|
|
|
+
|
|
|
+ # 构建结果
|
|
|
+ result = {
|
|
|
+ "nodes": nodes,
|
|
|
+ "lines": lines
|
|
|
}
|
|
|
+ return result
|
|
|
|
|
|
|
|
|
# 数据模型影响图谱
|
|
|
def model_impact_graph(nodeid, meta=False):
|
|
|
"""
|
|
|
- 获取数据模型影响图谱
|
|
|
+ 生成数据模型的影响关系图谱
|
|
|
|
|
|
Args:
|
|
|
- nodeid: 节点ID(字符串)
|
|
|
- meta: 是否返回元数据
|
|
|
+ nodeid: 节点ID
|
|
|
+ meta: 是否包含元数据
|
|
|
|
|
|
Returns:
|
|
|
- 图谱数据
|
|
|
+ dict: 包含节点和连线信息的图谱数据
|
|
|
"""
|
|
|
- # 确保nodeid是字符串类型
|
|
|
- node_id = str(nodeid) if nodeid is not None else None
|
|
|
+ result = {}
|
|
|
|
|
|
- if meta:
|
|
|
- query = """
|
|
|
- MATCH p = (n:data_model)-[r:use*..3]-(m)
|
|
|
- WHERE elementId(n) = $nodeId
|
|
|
- WITH p, relationships(p) as rels
|
|
|
- RETURN p
|
|
|
- limit 300
|
|
|
+ with connect_graph().session() as session:
|
|
|
+ # 查询起始模型节点
|
|
|
+ start_node_query = """
|
|
|
+ MATCH (n:data_model)
|
|
|
+ WHERE id(n) = $nodeId
|
|
|
+ RETURN n.name as name, n.en_name as en_name
|
|
|
"""
|
|
|
- else:
|
|
|
- query = """
|
|
|
- MATCH p = (n:data_model)-[r:use*..3]-(m)
|
|
|
- WHERE elementId(n) = $nodeId
|
|
|
- WITH p, relationships(p) as rels
|
|
|
- RETURN p
|
|
|
- limit 300
|
|
|
+
|
|
|
+ start_result = session.run(start_node_query, nodeId=nodeid)
|
|
|
+ start_record = start_result.single()
|
|
|
+
|
|
|
+ if not start_record:
|
|
|
+ return {"nodes": [], "lines": []}
|
|
|
+
|
|
|
+ # 查询影响模型的数据资源
|
|
|
+ resource_query = """
|
|
|
+ MATCH (n:data_model)
|
|
|
+ WHERE id(n) = $nodeId
|
|
|
+ MATCH p = (n)-[:children]->(resource:data_resource)
|
|
|
+ RETURN resource
|
|
|
"""
|
|
|
-
|
|
|
- # 使用正确的session方式执行查询
|
|
|
- driver = connect_graph()
|
|
|
- if not driver:
|
|
|
- return {"nodes": [], "edges": []}
|
|
|
|
|
|
- with driver.session() as session:
|
|
|
- result = session.run(query, nodeId=node_id)
|
|
|
+ resource_result = session.run(resource_query, nodeId=nodeid)
|
|
|
|
|
|
- nodes = set()
|
|
|
- relationships = set()
|
|
|
- nodes_by_id = {}
|
|
|
+ nodes = [{"id": str(nodeid), "text": start_record['name'], "type": "model"}]
|
|
|
+ lines = []
|
|
|
|
|
|
- for record in result:
|
|
|
- path = record["p"]
|
|
|
+ # 处理资源节点
|
|
|
+ for record in resource_result:
|
|
|
+ if 'resource' in record:
|
|
|
+ resource = record['resource']
|
|
|
+ resource_id = str(resource.id)
|
|
|
+ resource_name = resource.get('name', '')
|
|
|
+ resource_en_name = resource.get('en_name', '')
|
|
|
+
|
|
|
+ # 创建资源节点
|
|
|
+ resource_node = {
|
|
|
+ "id": resource_id,
|
|
|
+ "text": resource_name,
|
|
|
+ "type": "resource"
|
|
|
+ }
|
|
|
+ nodes.append(resource_node)
|
|
|
+
|
|
|
+ # 创建资源到模型的关系
|
|
|
+ line = {
|
|
|
+ "from": str(nodeid),
|
|
|
+ "to": resource_id,
|
|
|
+ "text": "resource"
|
|
|
+ }
|
|
|
+ lines.append(line)
|
|
|
+
|
|
|
+ # 处理元数据节点
|
|
|
+ if meta:
|
|
|
+ meta_query = """
|
|
|
+ MATCH (n:data_model)
|
|
|
+ WHERE id(n) = $nodeId and labels(m) <> ['meta_node']
|
|
|
+ MATCH p = (n)-[:meta]->(meta:meta_node)
|
|
|
+ RETURN meta
|
|
|
+ """
|
|
|
+ meta_result = session.run(meta_query, nodeId=nodeid)
|
|
|
|
|
|
- for node in path.nodes:
|
|
|
- node_id_str = str(node.element_id) if hasattr(node, 'element_id') else str(node.id)
|
|
|
- if node_id_str not in nodes:
|
|
|
- node_type = list(node.labels)[0].split('_')[1]
|
|
|
- node_data = {
|
|
|
- "id": node_id_str,
|
|
|
- "text": node.get("name", ""),
|
|
|
- "type": node_type
|
|
|
+ for record in meta_result:
|
|
|
+ if 'meta' in record:
|
|
|
+ meta_node = record['meta']
|
|
|
+ meta_id = str(meta.id)
|
|
|
+ meta_name = meta.get('name', '')
|
|
|
+ meta_en_name = meta.get('en_name', '')
|
|
|
+
|
|
|
+ # 创建元数据节点
|
|
|
+ meta_node = {
|
|
|
+ "id": meta_id,
|
|
|
+ "text": meta_name,
|
|
|
+ "type": "meta"
|
|
|
}
|
|
|
+ nodes.append(meta_node)
|
|
|
|
|
|
- nodes.add(node_id_str)
|
|
|
- nodes_by_id[node_id_str] = node_data
|
|
|
-
|
|
|
- for rel in path.relationships:
|
|
|
- start_id = str(rel.start_node.element_id) if hasattr(rel.start_node, 'element_id') else str(rel.start_node.id)
|
|
|
- end_id = str(rel.end_node.element_id) if hasattr(rel.end_node, 'element_id') else str(rel.end_node.id)
|
|
|
- relationship_id = f"{start_id}-{end_id}"
|
|
|
- if relationship_id not in relationships:
|
|
|
- relationship_data = {
|
|
|
- "from": start_id,
|
|
|
- "to": end_id,
|
|
|
- "text": type(rel).__name__
|
|
|
+ # 创建模型到元数据的标签关系
|
|
|
+ tag_line = {
|
|
|
+ "from": str(nodeid),
|
|
|
+ "to": meta_id,
|
|
|
+ "text": "component"
|
|
|
}
|
|
|
- relationships.add(relationship_id)
|
|
|
-
|
|
|
- # 转换为所需格式
|
|
|
- return {
|
|
|
- "nodes": list(nodes_by_id.values()),
|
|
|
- "edges": [{"from": rel.split("-")[0], "to": rel.split("-")[1], "text": ""}
|
|
|
- for rel in relationships]
|
|
|
+ lines.append(tag_line)
|
|
|
+
|
|
|
+ # 构建结果
|
|
|
+ result = {
|
|
|
+ "nodes": nodes,
|
|
|
+ "lines": lines
|
|
|
}
|
|
|
+ return result
|
|
|
|
|
|
|
|
|
# 数据模型全部图谱
|
|
|
def model_all_graph(nodeid, meta=False):
|
|
|
"""
|
|
|
- 获取数据模型全部图谱
|
|
|
+ 生成数据模型的所有关系图谱
|
|
|
|
|
|
Args:
|
|
|
- nodeid: 节点ID(字符串)
|
|
|
- meta: 是否返回元数据
|
|
|
+ nodeid: 节点ID
|
|
|
+ meta: 是否包含元数据
|
|
|
|
|
|
Returns:
|
|
|
- 图谱数据
|
|
|
+ dict: 包含节点和连线信息的图谱数据
|
|
|
"""
|
|
|
- # 确保nodeid是字符串类型
|
|
|
- node_id = str(nodeid) if nodeid is not None else None
|
|
|
+ result = {}
|
|
|
|
|
|
- if meta:
|
|
|
- query = """
|
|
|
- MATCH p = (n:data_model)-[r*..3]-(m)
|
|
|
- WHERE elementId(n) = $nodeId
|
|
|
- WITH p, relationships(p) as rels
|
|
|
- RETURN p
|
|
|
- limit 300
|
|
|
+ with connect_graph().session() as session:
|
|
|
+ # 查询起始模型节点
|
|
|
+ start_node_query = """
|
|
|
+ MATCH (n:data_model)
|
|
|
+ WHERE id(n) = $nodeId
|
|
|
+ RETURN n.name as name, n.en_name as en_name
|
|
|
"""
|
|
|
- else:
|
|
|
- query = """
|
|
|
- MATCH p = (n:data_model)-[r*..3]-(m)
|
|
|
- WHERE elementId(n) = $nodeId and labels(m) <> ['meta_node']
|
|
|
- WITH p, relationships(p) as rels
|
|
|
- RETURN p
|
|
|
- limit 300
|
|
|
+
|
|
|
+ start_result = session.run(start_node_query, nodeId=nodeid)
|
|
|
+ start_record = start_result.single()
|
|
|
+
|
|
|
+ if not start_record:
|
|
|
+ return {"nodes": [], "lines": []}
|
|
|
+
|
|
|
+ # 查询与模型关联的数据资源
|
|
|
+ resource_query = """
|
|
|
+ MATCH (n:data_model)
|
|
|
+ WHERE id(n) = $nodeId
|
|
|
+ MATCH p = (n)-[:children]->(resource:data_resource)
|
|
|
+ RETURN resource
|
|
|
"""
|
|
|
-
|
|
|
- # 使用正确的session方式执行查询
|
|
|
- driver = connect_graph()
|
|
|
- if not driver:
|
|
|
- return {"nodes": [], "edges": []}
|
|
|
|
|
|
- with driver.session() as session:
|
|
|
- result = session.run(query, nodeId=node_id)
|
|
|
+ resource_result = session.run(resource_query, nodeId=nodeid)
|
|
|
|
|
|
- nodes = set()
|
|
|
- relationships = set()
|
|
|
- nodes_by_id = {}
|
|
|
+ # 查询与模型关联的元数据
|
|
|
+ meta_query = """
|
|
|
+ MATCH (n:data_model)
|
|
|
+ WHERE id(n) = $nodeId and labels(m) <> ['meta_node']
|
|
|
+ MATCH p = (n)-[:meta]->(meta:meta_node)
|
|
|
+ RETURN meta
|
|
|
+ """
|
|
|
+
|
|
|
+ nodes = [{"id": str(nodeid), "text": start_record['name'], "type": "model"}]
|
|
|
+ lines = []
|
|
|
|
|
|
- for record in result:
|
|
|
- path = record["p"]
|
|
|
+ # 处理资源节点
|
|
|
+ for record in resource_result:
|
|
|
+ if 'resource' in record:
|
|
|
+ resource = record['resource']
|
|
|
+ resource_id = str(resource.id)
|
|
|
+ resource_name = resource.get('name', '')
|
|
|
+ resource_en_name = resource.get('en_name', '')
|
|
|
+
|
|
|
+ # 创建资源节点
|
|
|
+ resource_node = {
|
|
|
+ "id": resource_id,
|
|
|
+ "text": resource_name,
|
|
|
+ "type": "resource"
|
|
|
+ }
|
|
|
+ nodes.append(resource_node)
|
|
|
+
|
|
|
+ # 创建资源到模型的关系
|
|
|
+ line = {
|
|
|
+ "from": str(nodeid),
|
|
|
+ "to": resource_id,
|
|
|
+ "text": "resource"
|
|
|
+ }
|
|
|
+ lines.append(line)
|
|
|
+
|
|
|
+ # 处理元数据节点
|
|
|
+ if meta:
|
|
|
+ meta_result = session.run(meta_query, nodeId=nodeid)
|
|
|
|
|
|
- for node in path.nodes:
|
|
|
- node_id_str = str(node.element_id) if hasattr(node, 'element_id') else str(node.id)
|
|
|
- if node_id_str not in nodes:
|
|
|
- node_type = list(node.labels)[0].split('_')[1]
|
|
|
- node_data = {
|
|
|
- "id": node_id_str,
|
|
|
- "text": node.get("name", ""),
|
|
|
- "type": node_type
|
|
|
+ for record in meta_result:
|
|
|
+ if 'meta' in record:
|
|
|
+ meta_node = record['meta']
|
|
|
+ meta_id = str(meta.id)
|
|
|
+ meta_name = meta.get('name', '')
|
|
|
+ meta_en_name = meta.get('en_name', '')
|
|
|
+
|
|
|
+ # 创建元数据节点
|
|
|
+ meta_node = {
|
|
|
+ "id": meta_id,
|
|
|
+ "text": meta_name,
|
|
|
+ "type": "meta"
|
|
|
}
|
|
|
+ nodes.append(meta_node)
|
|
|
|
|
|
- nodes.add(node_id_str)
|
|
|
- nodes_by_id[node_id_str] = node_data
|
|
|
-
|
|
|
- for rel in path.relationships:
|
|
|
- start_id = str(rel.start_node.element_id) if hasattr(rel.start_node, 'element_id') else str(rel.start_node.id)
|
|
|
- end_id = str(rel.end_node.element_id) if hasattr(rel.end_node, 'element_id') else str(rel.end_node.id)
|
|
|
- relationship_id = f"{start_id}-{end_id}"
|
|
|
- if relationship_id not in relationships:
|
|
|
- relationship_data = {
|
|
|
- "from": start_id,
|
|
|
- "to": end_id,
|
|
|
- "text": type(rel).__name__
|
|
|
+ # 创建模型到元数据的标签关系
|
|
|
+ tag_line = {
|
|
|
+ "from": str(nodeid),
|
|
|
+ "to": meta_id,
|
|
|
+ "text": "component"
|
|
|
}
|
|
|
- relationships.add(relationship_id)
|
|
|
-
|
|
|
- # 转换为所需格式
|
|
|
- return {
|
|
|
- "nodes": list(nodes_by_id.values()),
|
|
|
- "edges": [{"from": rel.split("-")[0], "to": rel.split("-")[1], "text": ""}
|
|
|
- for rel in relationships]
|
|
|
+ lines.append(tag_line)
|
|
|
+
|
|
|
+ # 构建结果
|
|
|
+ result = {
|
|
|
+ "nodes": nodes,
|
|
|
+ "lines": lines
|
|
|
}
|
|
|
+ return result
|
|
|
|
|
|
|
|
|
# 更新数据模型
|