|
@@ -58,16 +58,52 @@ def data_model_save():
|
|
|
receiver = request.get_json()
|
|
receiver = request.get_json()
|
|
|
data_model = receiver['name_zh']
|
|
data_model = receiver['name_zh']
|
|
|
id_list = receiver['id_list']
|
|
id_list = receiver['id_list']
|
|
|
|
|
+ data_source = receiver.get('data_source') # 获取data_source节点ID
|
|
|
|
|
+
|
|
|
# resource_id和meta_id构成json格式
|
|
# resource_id和meta_id构成json格式
|
|
|
result = json.dumps(id_list, ensure_ascii=False)
|
|
result = json.dumps(id_list, ensure_ascii=False)
|
|
|
try:
|
|
try:
|
|
|
- # 从DDL中选取保存数据模型
|
|
|
|
|
|
|
+ # 从DDL中选取保存数据模型(支持data_source参数)
|
|
|
result_list = [receiver['name_en']]
|
|
result_list = [receiver['name_en']]
|
|
|
id, data_model_node = model_functions.handle_data_model(data_model, result_list, result, receiver)
|
|
id, data_model_node = model_functions.handle_data_model(data_model, result_list, result, receiver)
|
|
|
model_functions.handle_no_meta_data_model(id_list, receiver, data_model_node)
|
|
model_functions.handle_no_meta_data_model(id_list, receiver, data_model_node)
|
|
|
model_functions.calculate_model_level(id)
|
|
model_functions.calculate_model_level(id)
|
|
|
|
|
|
|
|
- res = success({}, "success")
|
|
|
|
|
|
|
+ # 查询节点的实际属性(data_model_node 可能只是整数ID)
|
|
|
|
|
+ from app.services.neo4j_driver import neo4j_driver
|
|
|
|
|
+ with neo4j_driver.get_session() as session:
|
|
|
|
|
+ node_query = """
|
|
|
|
|
+ MATCH (n:DataModel) WHERE id(n) = $node_id
|
|
|
|
|
+ RETURN n.name_zh as name_zh, n.name_en as name_en, n.description as description,
|
|
|
|
|
+ n.category as category, n.create_time as create_time, n.level as level,
|
|
|
|
|
+ n.tag as tag, n.leader as leader, n.origin as origin, n.frequency as frequency,
|
|
|
|
|
+ n.organization as organization, n.data_sensitivity as data_sensitivity, n.status as status
|
|
|
|
|
+ """
|
|
|
|
|
+ node_result = session.run(node_query, node_id=int(id))
|
|
|
|
|
+ node_record = node_result.single()
|
|
|
|
|
+
|
|
|
|
|
+ # 构建响应数据 - data_model包装格式
|
|
|
|
|
+ response_data = {
|
|
|
|
|
+ "data_model": {
|
|
|
|
|
+ "id": id,
|
|
|
|
|
+ "name_zh": node_record['name_zh'] if node_record else None,
|
|
|
|
|
+ "name_en": node_record['name_en'] if node_record else None,
|
|
|
|
|
+ "description": node_record['description'] if node_record else None,
|
|
|
|
|
+ "category": node_record['category'] if node_record else None,
|
|
|
|
|
+ "create_time": node_record['create_time'] if node_record else None,
|
|
|
|
|
+ "level": node_record['level'] if node_record else None,
|
|
|
|
|
+ "tag": node_record['tag'] if node_record else None,
|
|
|
|
|
+ "leader": node_record['leader'] if node_record else None,
|
|
|
|
|
+ "origin": node_record['origin'] if node_record else None,
|
|
|
|
|
+ "frequency": node_record['frequency'] if node_record else None,
|
|
|
|
|
+ "organization": node_record['organization'] if node_record else None,
|
|
|
|
|
+ "data_sensitivity": node_record['data_sensitivity'] if node_record else None,
|
|
|
|
|
+ "status": node_record['status'] if node_record else None,
|
|
|
|
|
+ "data_source": data_source # 数据源节点ID
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ res = success(response_data, "success")
|
|
|
return json.dumps(res, ensure_ascii=False, cls=MyEncoder)
|
|
return json.dumps(res, ensure_ascii=False, cls=MyEncoder)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -83,9 +119,12 @@ def data_model_search():
|
|
|
receiver = request.get_json()
|
|
receiver = request.get_json()
|
|
|
data_model = receiver['name_zh']
|
|
data_model = receiver['name_zh']
|
|
|
id_list = receiver['id_list']
|
|
id_list = receiver['id_list']
|
|
|
|
|
+ data_source = receiver.get('data_source') # 获取data_source节点ID
|
|
|
|
|
+
|
|
|
# resource_id和meta_id构成json格式
|
|
# resource_id和meta_id构成json格式
|
|
|
result = json.dumps(id_list, ensure_ascii=False)
|
|
result = json.dumps(id_list, ensure_ascii=False)
|
|
|
try:
|
|
try:
|
|
|
|
|
+ # 从数据资源中选取保存数据模型(支持data_source参数)
|
|
|
from app.core.meta_data import translate_and_parse
|
|
from app.core.meta_data import translate_and_parse
|
|
|
result_list = translate_and_parse(data_model)
|
|
result_list = translate_and_parse(data_model)
|
|
|
id, data_model_node = model_functions.handle_data_model(data_model, result_list, result, receiver)
|
|
id, data_model_node = model_functions.handle_data_model(data_model, result_list, result, receiver)
|
|
@@ -93,7 +132,41 @@ def data_model_search():
|
|
|
model_functions.resource_handle_meta_data_model(id_list, id)
|
|
model_functions.resource_handle_meta_data_model(id_list, id)
|
|
|
model_functions.calculate_model_level(id)
|
|
model_functions.calculate_model_level(id)
|
|
|
|
|
|
|
|
- res = success({}, "success")
|
|
|
|
|
|
|
+ # 查询节点的实际属性(data_model_node 可能只是整数ID)
|
|
|
|
|
+ from app.services.neo4j_driver import neo4j_driver
|
|
|
|
|
+ with neo4j_driver.get_session() as session:
|
|
|
|
|
+ node_query = """
|
|
|
|
|
+ MATCH (n:DataModel) WHERE id(n) = $node_id
|
|
|
|
|
+ RETURN n.name_zh as name_zh, n.name_en as name_en, n.description as description,
|
|
|
|
|
+ n.category as category, n.create_time as create_time, n.level as level,
|
|
|
|
|
+ n.tag as tag, n.leader as leader, n.origin as origin, n.frequency as frequency,
|
|
|
|
|
+ n.organization as organization, n.data_sensitivity as data_sensitivity, n.status as status
|
|
|
|
|
+ """
|
|
|
|
|
+ node_result = session.run(node_query, node_id=int(id))
|
|
|
|
|
+ node_record = node_result.single()
|
|
|
|
|
+
|
|
|
|
|
+ # 构建响应数据 - data_model包装格式
|
|
|
|
|
+ response_data = {
|
|
|
|
|
+ "data_model": {
|
|
|
|
|
+ "id": id,
|
|
|
|
|
+ "name_zh": node_record['name_zh'] if node_record else None,
|
|
|
|
|
+ "name_en": node_record['name_en'] if node_record else None,
|
|
|
|
|
+ "description": node_record['description'] if node_record else None,
|
|
|
|
|
+ "category": node_record['category'] if node_record else None,
|
|
|
|
|
+ "create_time": node_record['create_time'] if node_record else None,
|
|
|
|
|
+ "level": node_record['level'] if node_record else None,
|
|
|
|
|
+ "tag": node_record['tag'] if node_record else None,
|
|
|
|
|
+ "leader": node_record['leader'] if node_record else None,
|
|
|
|
|
+ "origin": node_record['origin'] if node_record else None,
|
|
|
|
|
+ "frequency": node_record['frequency'] if node_record else None,
|
|
|
|
|
+ "organization": node_record['organization'] if node_record else None,
|
|
|
|
|
+ "data_sensitivity": node_record['data_sensitivity'] if node_record else None,
|
|
|
|
|
+ "status": node_record['status'] if node_record else None,
|
|
|
|
|
+ "data_source": data_source # 数据源节点ID
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ res = success(response_data, "success")
|
|
|
return json.dumps(res, ensure_ascii=False, cls=MyEncoder)
|
|
return json.dumps(res, ensure_ascii=False, cls=MyEncoder)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -108,32 +181,51 @@ def data_model_model_add():
|
|
|
receiver = request.get_json()
|
|
receiver = request.get_json()
|
|
|
data_model = receiver['name_zh']
|
|
data_model = receiver['name_zh']
|
|
|
id_list = receiver['id_list']
|
|
id_list = receiver['id_list']
|
|
|
|
|
+ data_source = receiver.get('data_source') # 获取data_source节点ID
|
|
|
|
|
+
|
|
|
# model_id和meta_id构成json格式
|
|
# model_id和meta_id构成json格式
|
|
|
result = json.dumps(id_list, ensure_ascii=False)
|
|
result = json.dumps(id_list, ensure_ascii=False)
|
|
|
try:
|
|
try:
|
|
|
|
|
+ # 从数据模型中选取保存数据模型
|
|
|
|
|
+ # handle_data_model 已经处理了 data_source 关系创建(支持 int/dict/string 格式)
|
|
|
from app.core.meta_data import translate_and_parse
|
|
from app.core.meta_data import translate_and_parse
|
|
|
result_list = translate_and_parse(data_model)
|
|
result_list = translate_and_parse(data_model)
|
|
|
node_id, data_model_node = model_functions.handle_data_model(data_model, result_list, result, receiver)
|
|
node_id, data_model_node = model_functions.handle_data_model(data_model, result_list, result, receiver)
|
|
|
model_functions.model_handle_meta_data_model(id_list, node_id)
|
|
model_functions.model_handle_meta_data_model(id_list, node_id)
|
|
|
model_functions.calculate_model_level(node_id)
|
|
model_functions.calculate_model_level(node_id)
|
|
|
|
|
|
|
|
- # 构建响应数据
|
|
|
|
|
|
|
+ # 查询节点的实际属性(data_model_node 可能只是整数ID)
|
|
|
|
|
+ from app.services.neo4j_driver import neo4j_driver
|
|
|
|
|
+ with neo4j_driver.get_session() as session:
|
|
|
|
|
+ node_query = """
|
|
|
|
|
+ MATCH (n:DataModel) WHERE id(n) = $node_id
|
|
|
|
|
+ RETURN n.name_zh as name_zh, n.name_en as name_en, n.description as description,
|
|
|
|
|
+ n.category as category, n.create_time as create_time, n.level as level,
|
|
|
|
|
+ n.tag as tag, n.leader as leader, n.origin as origin, n.frequency as frequency,
|
|
|
|
|
+ n.organization as organization, n.data_sensitivity as data_sensitivity, n.status as status
|
|
|
|
|
+ """
|
|
|
|
|
+ node_result = session.run(node_query, node_id=int(node_id))
|
|
|
|
|
+ node_record = node_result.single()
|
|
|
|
|
+
|
|
|
|
|
+ # 构建响应数据 - data_model包装格式
|
|
|
response_data = {
|
|
response_data = {
|
|
|
- "id": node_id,
|
|
|
|
|
- "name_zh": data_model_node.get('name_zh'),
|
|
|
|
|
- "name_en": data_model_node.get('name_en'),
|
|
|
|
|
- "description": data_model_node.get('description'),
|
|
|
|
|
- "category": data_model_node.get('category'),
|
|
|
|
|
- "time": data_model_node.get('time'),
|
|
|
|
|
- "level": data_model_node.get('level'),
|
|
|
|
|
- "tag": data_model_node.get('tag'),
|
|
|
|
|
- "childrenId": data_model_node.get('childrenId', []),
|
|
|
|
|
- "leader": data_model_node.get('leader'),
|
|
|
|
|
- "origin": data_model_node.get('origin'),
|
|
|
|
|
- "frequency": data_model_node.get('frequency'),
|
|
|
|
|
- "organization": data_model_node.get('organization'),
|
|
|
|
|
- "data_sensitivity": data_model_node.get('data_sensitivity'),
|
|
|
|
|
- "status": data_model_node.get('status')
|
|
|
|
|
|
|
+ "data_model": {
|
|
|
|
|
+ "id": node_id,
|
|
|
|
|
+ "name_zh": node_record['name_zh'] if node_record else None,
|
|
|
|
|
+ "name_en": node_record['name_en'] if node_record else None,
|
|
|
|
|
+ "description": node_record['description'] if node_record else None,
|
|
|
|
|
+ "category": node_record['category'] if node_record else None,
|
|
|
|
|
+ "create_time": node_record['create_time'] if node_record else None,
|
|
|
|
|
+ "level": node_record['level'] if node_record else None,
|
|
|
|
|
+ "tag": node_record['tag'] if node_record else None,
|
|
|
|
|
+ "leader": node_record['leader'] if node_record else None,
|
|
|
|
|
+ "origin": node_record['origin'] if node_record else None,
|
|
|
|
|
+ "frequency": node_record['frequency'] if node_record else None,
|
|
|
|
|
+ "organization": node_record['organization'] if node_record else None,
|
|
|
|
|
+ "data_sensitivity": node_record['data_sensitivity'] if node_record else None,
|
|
|
|
|
+ "status": node_record['status'] if node_record else None,
|
|
|
|
|
+ "data_source": data_source # 数据源节点ID,与name_zh在同一级别
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
res = success(response_data, "success")
|
|
res = success(response_data, "success")
|
|
@@ -154,7 +246,49 @@ def data_model_detail():
|
|
|
id = receiver.get('id')
|
|
id = receiver.get('id')
|
|
|
print(f"Received id from frontend: {id}")
|
|
print(f"Received id from frontend: {id}")
|
|
|
|
|
|
|
|
- response_data = model_functions.handle_id_model(id)
|
|
|
|
|
|
|
+ result_data = model_functions.handle_id_model(id)
|
|
|
|
|
+
|
|
|
|
|
+ # handle_id_model 返回的数据格式是 {"data_model": {...}}
|
|
|
|
|
+ # 提取内部的 data_model 数据
|
|
|
|
|
+ model_data = result_data.get("data_model", {})
|
|
|
|
|
+
|
|
|
|
|
+ # 查询关联的数据源信息
|
|
|
|
|
+ from app.services.neo4j_driver import neo4j_driver
|
|
|
|
|
+ data_source_id = None
|
|
|
|
|
+ try:
|
|
|
|
|
+ model_id = int(id)
|
|
|
|
|
+ with neo4j_driver.get_session() as session:
|
|
|
|
|
+ # 查询数据模型关联的数据源节点
|
|
|
|
|
+ ds_cypher = """
|
|
|
|
|
+ MATCH (m:DataModel)-[:COME_FROM]->(ds:DataSource)
|
|
|
|
|
+ WHERE id(m) = $model_id
|
|
|
|
|
+ RETURN id(ds) as ds_id
|
|
|
|
|
+ """
|
|
|
|
|
+ ds_result = session.run(ds_cypher, model_id=model_id)
|
|
|
|
|
+ ds_record = ds_result.single()
|
|
|
|
|
+
|
|
|
|
|
+ if ds_record:
|
|
|
|
|
+ # 如果存在数据源关联,只返回ID
|
|
|
|
|
+ data_source_id = ds_record['ds_id']
|
|
|
|
|
+ logger.info(f"找到数据模型关联的数据源: model_id={model_id}, data_source_id={data_source_id}")
|
|
|
|
|
+ else:
|
|
|
|
|
+ logger.info(f"数据模型未关联数据源: model_id={model_id}")
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ # 数据源查询失败不应该影响主流程
|
|
|
|
|
+ logger.error(f"查询数据源关联失败(不中断主流程): {str(e)}")
|
|
|
|
|
+
|
|
|
|
|
+ # 删除 childrenId 字段(如果存在)
|
|
|
|
|
+ if 'childrenId' in model_data:
|
|
|
|
|
+ del model_data['childrenId']
|
|
|
|
|
+
|
|
|
|
|
+ # 添加 data_source 字段
|
|
|
|
|
+ model_data['data_source'] = data_source_id
|
|
|
|
|
+
|
|
|
|
|
+ # 构建响应数据 - data_model包装格式
|
|
|
|
|
+ response_data = {
|
|
|
|
|
+ "data_model": model_data
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
res = success(response_data, "success")
|
|
res = success(response_data, "success")
|
|
|
return json.dumps(res, ensure_ascii=False, cls=MyEncoder)
|
|
return json.dumps(res, ensure_ascii=False, cls=MyEncoder)
|
|
|
|
|
|