Commit 430a5bb0 by dong

fix202302013

parent 78db3f05
...@@ -39,6 +39,7 @@ class IndustryChain(db.Model): ...@@ -39,6 +39,7 @@ class IndustryChain(db.Model):
industry_type = db.Column(db.Integer, comment='行业类型(0是产业集群,1是上游行业,2是中游行业,3是下游行业)') industry_type = db.Column(db.Integer, comment='行业类型(0是产业集群,1是上游行业,2是中游行业,3是下游行业)')
relate_id = db.Column(db.Integer, comment='关系id(关联与哪个产业环节') relate_id = db.Column(db.Integer, comment='关系id(关联与哪个产业环节')
enterprise = db.relationship('Enterprise', backref=db.backref('enterprise')) enterprise = db.relationship('Enterprise', backref=db.backref('enterprise'))
enterprise_num = db.Column(db.Integer, comment='相关全企业表数量')
# 全国企业 # 全国企业
......
...@@ -115,23 +115,27 @@ def get_count(industry_id, chain_name, flag): ...@@ -115,23 +115,27 @@ def get_count(industry_id, chain_name, flag):
"煤化工", "新材料", "绿色建材", "医药", "丝麻纺织服装", "煤化工", "新材料", "绿色建材", "医药", "丝麻纺织服装",
"现代服务业", "数字经济", "文化旅游"]: "现代服务业", "数字经济", "文化旅游"]:
company_count = Company.query.filter( company_count = Company.query.filter(
Company.product_all.like('%{}%'.format(chain_name)), # Company.product_all.like('%{}%'.format(chain_name)),
Company.c_type == industry_id, Company.c_type == industry_id
).count() ).count()
else: else:
company_count = Company.query.filter( company_count = Company.query.filter(
Company.product_all.like('%{}%'.format(chain_name))).count() Company.product_all.like('%{}%'.format(chain_name)),
Company.c_type == industry_id,
).count()
if flag == 2: # 全国 if flag == 2: # 全国
if chain_name in ["钢铁", "光机电", "煤层气", "装备制造", "铸造", if chain_name in ["钢铁", "光机电", "煤层气", "装备制造", "铸造",
"煤化工", "新材料", "绿色建材", "医药", "丝麻纺织服装", "煤化工", "新材料", "绿色建材", "医药", "丝麻纺织服装",
"现代服务业", "数字经济", "文化旅游"]: "现代服务业", "数字经济", "文化旅游"]:
company_count = Enterprise.query.filter( company_count = Enterprise.query.filter(
Enterprise.product_all.like('%{}%'.format(chain_name)), # Enterprise.product_all.like('%{}%'.format(chain_name)),
Enterprise.c_type == industry_id, Enterprise.c_type == industry_id
).count() ).count()
else: else:
company_count = Enterprise.query.filter( company_count = Enterprise.query.filter(
Enterprise.product_all.like('%{}%'.format(chain_name))).count() Enterprise.product_all.like('%{}%'.format(chain_name)),
Enterprise.c_type == industry_id,
).count()
return company_count return company_count
......
import sys
import threading import threading
from time import sleep
from flask import app from flask import app
from apps.models import IndustryChain, Enterprise from apps.models import IndustryChain, Enterprise
from manager import app from manager import app
from apps import db from apps import db
# def jindu(enterprise_list_num):
# for i in range(1, enterprise_list_num):
# print("\r", end="")
# print("进度: {}%: ".format(i), "▓" * (i // 2), end="")
# sys.stdout.flush()
# sleep(0.05)
def handle(): def handle():
with app.app_context(): with app.app_context():
industry_obj_list = IndustryChain.query.all() industry_obj_list = IndustryChain.query.all()
...@@ -12,9 +23,9 @@ def handle(): ...@@ -12,9 +23,9 @@ def handle():
# 读取industry_chain数据表的产业名称 # 读取industry_chain数据表的产业名称
num = 0 num = 0
for industry_obj in industry_obj_list: for industry_obj in industry_obj_list:
# 清空原有关联企业 # # 清空原有关联企业
industry_obj.enterprise = [] # industry_obj.enterprise = []
db.session.commit() # db.session.commit()
industry_name = industry_obj.industry_name industry_name = industry_obj.industry_name
industry_id = industry_obj.id industry_id = industry_obj.id
...@@ -24,6 +35,7 @@ def handle(): ...@@ -24,6 +35,7 @@ def handle():
"现代服务业", "数字经济", "文化旅游"]: "现代服务业", "数字经济", "文化旅游"]:
print("正在查询【{}】的相关企业......".format(industry_name)) print("正在查询【{}】的相关企业......".format(industry_name))
enterprise_list = Enterprise.query.filter(Enterprise.c_type == industry_id).all() enterprise_list = Enterprise.query.filter(Enterprise.c_type == industry_id).all()
else: else:
print("正在查询【{}】的相关企业......".format(industry_name)) print("正在查询【{}】的相关企业......".format(industry_name))
...@@ -31,20 +43,52 @@ def handle(): ...@@ -31,20 +43,52 @@ def handle():
Enterprise.c_type == industry_id).all() Enterprise.c_type == industry_id).all()
if not enterprise_list: if not enterprise_list:
continue continue
# 清空原有关联企业
enterprise_list_num = len(enterprise_list)
industry_obj.enterprise_num = enterprise_list_num
industry_obj.enterprise = []
db.session.commit()
# enterprise_num = 0 enterprise_num = 0
for enterprise_obj in enterprise_list: for enterprise_obj in enterprise_list:
industry_obj.enterprise.append(enterprise_obj) industry_obj.enterprise.append(enterprise_obj)
# enterprise_num += 1 enterprise_num += 1
enterprise_list_num -= 1
if enterprise_num >= 500:
db.session.commit()
enterprise_num = 0
continue
elif enterprise_list_num == 0 and enterprise_num == 400:
db.session.commit()
enterprise_num = 0
continue
elif enterprise_list_num == 0 and enterprise_num == 300:
db.session.commit()
enterprise_num = 0
continue
elif enterprise_list_num == 0 and enterprise_num == 200:
db.session.commit()
enterprise_num = 0
continue
elif enterprise_list_num == 0 and enterprise_num == 100:
db.session.commit()
enterprise_num = 0
continue
else:
pass
db.session.commit()
# continue
print("产业链【{}】已完成".format(industry_name))
continue
# enterprise_num += 1
# enterprise_rate = str(enterprise_num / len(enterprise_list) * 100) + '%' # enterprise_rate = str(enterprise_num / len(enterprise_list) * 100) + '%'
# print("需要添加【{}】的企业外键一共{}个,已完成{}".format(industry_name, len(enterprise_list), enterprise_rate)) # print("需要添加【{}】的企业外键一共{}个,已完成{}".format(industry_name, len(enterprise_list), enterprise_rate))
db.session.commit()
continue
# db.session.commit() # db.session.commit()
num += 1 # num += 1
# print("产业链【{}】已完成,全部产业链已完成".format(industry_name) + str(num / 775 * 100) + '%') # print("产业链【{}】已完成,全部产业链已完成".format(industry_name) + str(num / 775 * 100) + '%')
print("产业链【{}】已完成".format(industry_name)) # print("产业链【{}】已完成".format(industry_name))
if __name__ == '__main__': if __name__ == '__main__':
......
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