Commit 8541f928 by dong

fix20220303

parent 3b26c391
...@@ -8,10 +8,10 @@ from apps.utils.neo4j_conn import conn_neo4j ...@@ -8,10 +8,10 @@ from apps.utils.neo4j_conn import conn_neo4j
from ..models import Enterprise from ..models import Enterprise
from py2neo import Graph from py2neo import Graph
# graph = conn_neo4j() graph = conn_neo4j()
graph1 = Graph("http://39.100.39.50:7475", username="neo4j", password="century-english-almanac-havana-golf-9040") # 太原的neo4j,测试是借用
# graph1 = Graph("http://39.100.39.50:7475", username="neo4j",
# password="century-english-almanac-havana-golf-9040") # 太原的neo4j,测试是借用
def deleteDuplicate(li): def deleteDuplicate(li):
...@@ -32,7 +32,8 @@ def check(name): ...@@ -32,7 +32,8 @@ def check(name):
:return: :return:
''' '''
Cypher = "match (n)-[r]->(m) WHERE m.name='{}' or n.name='{}' return r.type".format(name, name) Cypher = "match (n)-[r]->(m) WHERE m.name='{}' or n.name='{}' return r.type".format(name, name)
res = graph1.run(Cypher).data() # res = graph1.run(Cypher).data()
res = graph.run(Cypher).data()
res = list(set([i["r.type"] for i in res])) res = list(set([i["r.type"] for i in res]))
if res.__contains__("上游行业") or res.__contains__("下游行业"): if res.__contains__("上游行业") or res.__contains__("下游行业"):
return True return True
...@@ -137,7 +138,8 @@ def findCenterProducts(product_name): ...@@ -137,7 +138,8 @@ def findCenterProducts(product_name):
else: else:
sql = "match (n)-[r]->(m) WHERE m.name='{}' return n.name,r.type".format(product_name) sql = "match (n)-[r]->(m) WHERE m.name='{}' return n.name,r.type".format(product_name)
# print(sql) # print(sql)
res = graph1.run(sql).data() # res = graph1.run(sql).data()
res = graph.run(sql).data()
final_result = [] # 最终产品集 final_result = [] # 最终产品集
for i in res: for i in res:
if check(i["n.name"]): # 判断是否有上下游关系(添加到最终产品集) if check(i["n.name"]): # 判断是否有上下游关系(添加到最终产品集)
...@@ -182,7 +184,8 @@ def findUpDownCompany(name_query, name): # 对中间产品进行上下游产品 ...@@ -182,7 +184,8 @@ def findUpDownCompany(name_query, name): # 对中间产品进行上下游产品
"match (n) -[r:`下游行业`]->(m) WHERE m.name='{}' return n.name as bname,r.type,m.name as sname ".format( "match (n) -[r:`下游行业`]->(m) WHERE m.name='{}' return n.name as bname,r.type,m.name as sname ".format(
name, name, name, name) name, name, name, name)
res_product = graph1.run(sql_all).data() # res_product = graph1.run(sql_all).data()
res_product = graph.run(sql_all).data()
res_product = trans_formet(name, res_product) res_product = trans_formet(name, res_product)
nodes = [] nodes = []
links = [] links = []
...@@ -244,7 +247,8 @@ def findUDP(product_name): # 对中间产品进行上下游产品查询 ...@@ -244,7 +247,8 @@ def findUDP(product_name): # 对中间产品进行上下游产品查询
"match (n) -[r:`上游行业`]->(m) WHERE n.name='{}' return n.name as bname,r.type,m.name as sname UNION " \ "match (n) -[r:`上游行业`]->(m) WHERE n.name='{}' return n.name as bname,r.type,m.name as sname UNION " \
"match (n) -[r:`下游行业`]->(m) WHERE m.name='{}' return n.name as bname,r.type,m.name as sname ".format( "match (n) -[r:`下游行业`]->(m) WHERE m.name='{}' return n.name as bname,r.type,m.name as sname ".format(
product_name, product_name, product_name, product_name) product_name, product_name, product_name, product_name)
res_product = graph1.run(sql_all).data() # res_product = graph1.run(sql_all).data()
res_product = graph.run(sql_all).data()
res_product = trans_formet(product_name, res_product) res_product = trans_formet(product_name, res_product)
products = list() products = list()
for i in res_product: for i in res_product:
...@@ -358,8 +362,8 @@ def get_semic_map(): ...@@ -358,8 +362,8 @@ def get_semic_map():
# print("直接产品:", products) # print("直接产品:", products)
# 2、查询上下游产品 # 2、查询上下游产品
products_center = list() products_center = list()
# for product_name in products: for product_name in products:
for product_name in ['地铁运营', '轨道交通装备']: # for product_name in ['地铁运营', '轨道交通装备']:
products_center.extend(findCenterProducts(product_name)) # 查找中间产品 products_center.extend(findCenterProducts(product_name)) # 查找中间产品
products_uad = list() products_uad = list()
for product_name in products_center: for product_name in products_center:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment