Commit c9fd26b6 by 赵宇

fix20220224

parent 18fabc6a
...@@ -4,23 +4,32 @@ from py2neo import Graph ...@@ -4,23 +4,32 @@ from py2neo import Graph
def conn_neo4j(): def conn_neo4j():
# graph = Graph("http://localhost:7474", username="neo4j", password="123456") # 本地neo4j # graph = Graph("http://localhost:7474", username="neo4j", password="123456") # 本地neo4j
graph = Graph("http://localhost:7476", username="neo4j", password="123456") # 上传到50服务器前需更改 graph = Graph("http://localhost:7476", username="neo4j", password="123456") # 上传到50服务器前需更改
# graph = Graph("http://39.100.39.50:7476/", username="neo4j", password="123456") # 测试50服务器上的neo4j时使用 # graph = Graph("http://39.100.39.50:7476", username="neo4j", password="123456") # 测试50服务器上的neo4j时使用
# graph = Graph("http://39.100.39.50:7475", username="neo4j", password="century-english-almanac-havana-golf-9040") # 太原的neo4j,测试是借用
return graph return graph
def neo4j_dict(): def neo4j_dict():
ptp = {"煤层气开采储运利用": "煤层气开采储运利用", ptp = {
"光机电": "光机电", "煤炭": "煤炭",
"光学镜头": "光学镜头", "钢铁铸造": "钢铁铸造",
"硬质合金": "硬质合金", "光通讯": "光通讯",
"工业机器人": "工业机器人", "光学镜头": "光学镜头",
"碳基新材料": "碳基新材料", "硬质合金": "硬质合金",
"现代煤化工": "现代煤化工", "工业机器人": "工业机器人",
"铸管铸件": "铸管铸件", "煤层气开采储运利用": "煤层气开采储运利用",
"高端装备": "高端装备", "文旅康养": "文旅康养",
"文旅康养": "文旅康养", "现代服务": "现代服务",
"生物医药": "生物医药", "数字经济": "数字经济",
"数字经济": "数字经济", "生物医药": "生物医药",
"陶瓷": "陶瓷", "陶瓷": "陶瓷",
} "绿色食品": "绿色食品",
"光机电": "光机电",
"碳基新材料": "碳基新材料",
"现代煤化工": "现代煤化工",
"铸管铸件": "铸管铸件",
"高端装备": "高端装备",
}
return ptp return ptp
...@@ -119,18 +119,18 @@ def trans_formet(name, list_data): ...@@ -119,18 +119,18 @@ def trans_formet(name, list_data):
return list_data return list_data
def findCenterProducts(name): def findCenterProducts(product_name):
''' '''
查找中间产品 查找中间产品
查询当前产品往上直到有上下游关系,并返回产品实体名称和关系名称的列表 查询当前产品往上直到有上下游关系,并返回产品实体名称和关系名称的列表
:param name: 产品名 :param name: 产品名
:return: :return:
''' '''
if check(name): # 直接关联上下游 if check(product_name): # 直接关联上下游
res = [name] res = [product_name]
return res return res
else: else:
sql = "match (n)-[r]->(m) WHERE m.name='{}' return n.name,r.type".format(name) sql = "match (n)-[r]->(m) WHERE m.name='{}' return n.name,r.type".format(product_name)
# print(sql) # print(sql)
res = graph.run(sql).data() res = graph.run(sql).data()
final_result = [] # 最终产品集 final_result = [] # 最终产品集
...@@ -185,7 +185,8 @@ def findUpDownCompany(name_query, name): # 对中间产品进行上下游产品 ...@@ -185,7 +185,8 @@ def findUpDownCompany(name_query, name): # 对中间产品进行上下游产品
# links.append({"from": "a", "to": "{}".format(item), "text": "产品"}) # links.append({"from": "a", "to": "{}".format(item), "text": "产品"})
for i in res_product: for i in res_product:
if offer_company(i["target"]): # 判断是否有供应商 if offer_company(i["target"]): # 判断是否有供应商
nodes.append({"id": "{}".format(i["target"]), "name": "{}↓".format(i["target"]), "category": "3"}) nodes.append({"data": {"category": "3", "real_name": i["target"]}, "id": "{}".format(i["target"]),
"name": "{}↓".format(i["target"]), "category": "3"})
links.append( links.append(
{"from": "{}".format(name_query), "to": "{}".format(i["target"]), "text": "{}".format(i["relation"])}) {"from": "{}".format(name_query), "to": "{}".format(i["target"]), "text": "{}".format(i["relation"])})
# if i["relation"] == "上游行业": # if i["relation"] == "上游行业":
...@@ -205,7 +206,8 @@ def findUpDownCompany(name_query, name): # 对中间产品进行上下游产品 ...@@ -205,7 +206,8 @@ def findUpDownCompany(name_query, name): # 对中间产品进行上下游产品
# nodes.append({"name": "{}↓".format(i["target"]), "category": 4, "name_query": "{}".format(i["target"]), "isclick": 0}) # nodes.append({"name": "{}↓".format(i["target"]), "category": 4, "name_query": "{}".format(i["target"]), "isclick": 0})
# links.append({"source": "{}↓".format(name_query), "target": "{}↓".format(i["target"]), "name": "{}".format(i["relation"])}) # links.append({"source": "{}↓".format(name_query), "target": "{}↓".format(i["target"]), "name": "{}".format(i["relation"])})
else: else:
nodes.append({"id": "{}".format(i["target"]), "name": "{}".format(i["target"]), "category": "3"}) nodes.append({"data": {"category": "3", "real_name": i["target"]}, "id": "{}".format(i["target"]),
"name": "{}".format(i["target"]), "category": "3"})
links.append( links.append(
{"from": "{}".format(name_query), "to": "{}".format(i["target"]), "text": "{}".format(i["relation"])}) {"from": "{}".format(name_query), "to": "{}".format(i["target"]), "text": "{}".format(i["relation"])})
# if i["relation"] == "上游行业": # if i["relation"] == "上游行业":
...@@ -226,7 +228,7 @@ def findUpDownCompany(name_query, name): # 对中间产品进行上下游产品 ...@@ -226,7 +228,7 @@ def findUpDownCompany(name_query, name): # 对中间产品进行上下游产品
return nodes, links return nodes, links
def findUDP(name): # 对中间产品进行上下游产品查询 def findUDP(product_name): # 对中间产品进行上下游产品查询
''' '''
:param name_query: 要查询的产品 :param name_query: 要查询的产品
:param name: 中间产品 :param name: 中间产品
...@@ -236,9 +238,9 @@ def findUDP(name): # 对中间产品进行上下游产品查询 ...@@ -236,9 +238,9 @@ def findUDP(name): # 对中间产品进行上下游产品查询
"match (n) -[r:`上游行业`]->(m) WHERE m.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 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 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(
name, name, name, name) product_name, product_name, product_name, product_name)
res_product = graph.run(sql_all).data() res_product = graph.run(sql_all).data()
res_product = trans_formet(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:
products.append(i["target"]) products.append(i["target"])
...@@ -252,7 +254,9 @@ def find_zero(): ...@@ -252,7 +254,9 @@ def find_zero():
get_data = request.get_json() get_data = request.get_json()
name = get_data.get('company_name') name = get_data.get('company_name')
result = { result = {
"nodes": [{"id": "a", "name": "{}↓".format(name), "category": "1"}],
"nodes": [
{"data": {"category": "1", "real_name": name}, "id": "a", "name": "{}↓".format(name), "category": "1"}],
"links": [], "links": [],
"rootId": 'a' "rootId": 'a'
} }
...@@ -261,6 +265,7 @@ def find_zero(): ...@@ -261,6 +265,7 @@ def find_zero():
current_app.logger.error(e) current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据异常", data={}) return jsonify(code=RET.DBERR, msg="数据异常", data={})
# 获取供应链图谱 查询企业的产品接口 # 获取供应链图谱 查询企业的产品接口
@api_atlas.route("/SupplyChain/FindNext", methods=['POST']) @api_atlas.route("/SupplyChain/FindNext", methods=['POST'])
def find_next(): def find_next():
...@@ -271,7 +276,6 @@ def find_next(): ...@@ -271,7 +276,6 @@ def find_next():
# 检查参数的完整性 # 检查参数的完整性
if not all([name, category]): if not all([name, category]):
return jsonify(code=RET.DATAERR, msg="参数不完整") return jsonify(code=RET.DATAERR, msg="参数不完整")
try: try:
if category == "1": # 查询企业的产品 if category == "1": # 查询企业的产品
url = "http://39.100.39.50:9200/jc_supply_chain/_search" # 产品对企业 url = "http://39.100.39.50:9200/jc_supply_chain/_search" # 产品对企业
...@@ -285,7 +289,9 @@ def find_next(): ...@@ -285,7 +289,9 @@ def find_next():
result = dict() result = dict()
products = list(set(res)) products = list(set(res))
for item in products: for item in products:
nodes.append({"id": "{}".format(item), "name": "{}↓".format(item), "category": "2"}) # nodes.append({"id": "{}".format(item), "name": "{}↓".format(item), "category": "2"})
nodes.append({"data": {"category": "2", "real_name": item}, "id": "{}".format(item),
"name": "{}↓".format(item), "category": "2"})
links.append({"from": "a", "to": "{}".format(item), "text": "产品"}) links.append({"from": "a", "to": "{}".format(item), "text": "产品"})
result["nodes"] = nodes result["nodes"] = nodes
result["links"] = links result["links"] = links
...@@ -319,7 +325,8 @@ def find_next(): ...@@ -319,7 +325,8 @@ def find_next():
result = dict() result = dict()
products = list(set(res)) products = list(set(res))
for item in products: for item in products:
nodes.append({"id": "{}".format(item), "name": "{}".format(item), "category": "4"}) nodes.append({"data": {"category": "4", "real_name": item}, "id": "{}".format(item),
"name": "{}".format(item), "category": "4"})
links.append({"from": "{}".format(name), "to": "{}".format(item), "text": "{}".format("供应商企业")}) links.append({"from": "{}".format(name), "to": "{}".format(item), "text": "{}".format("供应商企业")})
result["nodes"] = nodes result["nodes"] = nodes
result["links"] = links result["links"] = links
...@@ -346,11 +353,12 @@ def get_semic_map(): ...@@ -346,11 +353,12 @@ def get_semic_map():
# print("直接产品:", products) # print("直接产品:", products)
# 2、查询上下游产品 # 2、查询上下游产品
products_center = list() products_center = list()
for i in products: # for product_name in products:
products_center.extend(findCenterProducts(i)) for product_name in ['地铁运营', '轨道交通装备']:
products_center.extend(findCenterProducts(product_name)) # 查找中间产品
products_uad = list() products_uad = list()
for j in products_center: for product_name in products_center:
products_uad.extend(findUDP(j)) products_uad.extend(findUDP(product_name)) # 对中间产品进行上下游产品查询
products_uad = list(set(products_uad)) products_uad = list(set(products_uad))
# print("中间产品:", products_uad) # print("中间产品:", products_uad)
......
...@@ -393,6 +393,7 @@ def radar_enums(): ...@@ -393,6 +393,7 @@ def radar_enums():
# return jsonify(code=RET.OK, msg="获取成功", data=data) # return jsonify(code=RET.OK, msg="获取成功", data=data)
enterprise = Enterprise.query.filter_by(c_type=inid) enterprise = Enterprise.query.filter_by(c_type=inid)
num_all = enterprise.count()
# 企业列表选择 1234567 500强企业-上市企业-高新技术企业-专精特新企业-独角兽企业--瞪羚企业-科技型中小企业 # 企业列表选择 1234567 500强企业-上市企业-高新技术企业-专精特新企业-独角兽企业--瞪羚企业-科技型中小企业
num_isfive = enterprise.filter_by(isfive="1").count() # 500强企业 num_isfive = enterprise.filter_by(isfive="1").count() # 500强企业
nums_quoted = enterprise.filter_by(quoted_company="1").count() # 上市企业 nums_quoted = enterprise.filter_by(quoted_company="1").count() # 上市企业
...@@ -403,6 +404,7 @@ def radar_enums(): ...@@ -403,6 +404,7 @@ def radar_enums():
nums_tbe = enterprise.filter_by(tbe="1").count() # 科技型中小企业 nums_tbe = enterprise.filter_by(tbe="1").count() # 科技型中小企业
data = { data = {
"num_all": num_all,
"num_isfive": num_isfive, "num_isfive": num_isfive,
"nums_quoted": nums_quoted, "nums_quoted": nums_quoted,
"nums_hignew": nums_hignew, "nums_hignew": nums_hignew,
......
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