Commit 6eb6e279 by dong

fix

parent 9627c9a6
# # # -*- coding:utf-8 -*-
# import threading
# from apps.models import IndustryChain1, Enterprise
# from apps.models import IndustryChain, Enterprise
# from manager import app
# from apps import db
#
#
# """
# IndustryChain1或者Enterprise数据表更新后,
# 计算产业环节相关企业的数量并填充到IndustryChain1的enterprise_num字段中。
# IndustryChain或者Enterprise数据表更新后,
# 计算产业环节相关企业的数量并填充到IndustryChain的enterprise_num字段中。
# """
#
#
# def handle():
# with app.app_context():
# industry_obj_list = IndustryChain1.query.all()
# industry_obj_list = IndustryChain.query.all()
# print(industry_obj_list)
# # 读取industry_chain数据表的产业名称
# for industry_obj in industry_obj_list:
......@@ -27,7 +27,7 @@
# continue
#
# else:
# indu_obj_li = IndustryChain1.query.filter(IndustryChain1.relate_id == indu_id).all()
# indu_obj_li = IndustryChain.query.filter(IndustryChain.relate_id == indu_id).all()
# for indu_obj in indu_obj_li:
# indu_name = indu_obj.industry_name
# print("正在查询【{}】的相关企业......".format(indu_name))
......@@ -59,29 +59,29 @@
# # -*- coding:utf-8 -*-
import threading
from apps.models import IndustryChain1, Enterprise
from apps.models import IndustryChain, Enterprise
from manager import app
from apps import db
"""
IndustryChain1或者Enterprise数据表更新后,
计算产业环节相关企业去重后的数量并填充到IndustryChain1的enterprise_num字段中。
IndustryChain或者Enterprise数据表更新后,
计算产业环节相关企业去重后的数量并填充到IndustryChain的enterprise_num字段中。
"""
def get_product_li(product, chain_id):
res_two_li = []
res_three_li = []
product_id = IndustryChain1.query.filter_by(industry_name=product, chain_id=chain_id).first().id
product_id = IndustryChain.query.filter_by(industry_name=product, chain_id=chain_id).first().id
product_li = [{"chain_name": product, "chain_name_id": product_id}]
chain_one_obj_list = IndustryChain1.query.filter_by(relate_id=product_id, chain_id=chain_id).all()
chain_one_obj_list = IndustryChain.query.filter_by(relate_id=product_id, chain_id=chain_id).all()
res_one_li = [{"chain_name": chain_one_obj.industry_name,
"chain_name_id": chain_one_obj.id
} for chain_one_obj in chain_one_obj_list]
for res_one in res_one_li:
chain_two_obj_list = IndustryChain1.query.filter_by(relate_id=res_one["chain_name_id"]).all()
chain_two_obj_list = IndustryChain.query.filter_by(relate_id=res_one["chain_name_id"]).all()
res_two = [{"chain_name": chain_one_obj.industry_name,
"chain_name_id": chain_one_obj.id
} for chain_one_obj in chain_two_obj_list]
......@@ -89,7 +89,7 @@ def get_product_li(product, chain_id):
res_one_li.extend(res_two)
for res_two in res_two_li:
chain_three_obj_list = IndustryChain1.query.filter_by(relate_id=res_two["chain_name_id"]).all()
chain_three_obj_list = IndustryChain.query.filter_by(relate_id=res_two["chain_name_id"]).all()
res_three = [{"chain_name": chain_one_obj.industry_name,
"chain_name_id": chain_one_obj.id
} for chain_one_obj in chain_three_obj_list]
......@@ -97,7 +97,7 @@ def get_product_li(product, chain_id):
res_one_li.extend(res_three)
# print(res_one_li)
for res_three in res_three_li:
chain_four_obj_list = IndustryChain1.query.filter_by(relate_id=res_three["chain_name_id"]).all()
chain_four_obj_list = IndustryChain.query.filter_by(relate_id=res_three["chain_name_id"]).all()
res_four = [{"chain_name": chain_one_obj.industry_name,
"chain_name_id": chain_one_obj.id
} for chain_one_obj in chain_four_obj_list]
......@@ -108,19 +108,17 @@ def get_product_li(product, chain_id):
def handle():
with app.app_context():
industry_obj_list = IndustryChain1.query.all()
# industry_obj_list = IndustryChain1.query.filter(IndustryChain1.id == 604).all()
industry_obj_list = IndustryChain.query.all()
# industry_obj_list = IndustryChain.query.filter(IndustryChain.id == 604).all()
# print(industry_obj_list)
# 读取industry_chain数据表的产业名称
for industry_obj in industry_obj_list:
industry_name = industry_obj.industry_name
# 读取全国企业表,模糊匹配product_all字段
if industry_name in ["钢铁", "光机电", "煤层气", "装备制造", "铸造",
"煤化工", "新材料", "绿色建材", "医药", "丝麻纺织服装",
"现代服务业", "数字经济", "文化旅游"]:
if industry_name in ["生活用纸", "文化旅游", "轨道交通装备", "新材料", "生物医药健康",
"教育和体育", "现代商贸物流", "食品加工", "电力电气"]:
continue
else:
chain_id = industry_obj.chain_id
indu_obj_li = get_product_li(industry_name, chain_id)
......
......@@ -92,86 +92,86 @@ def get_cluster():
# 获取新表的产业集群名称
@api_atlas.route('/IndustryCluster', methods=['POST'])
# @login_required
def industry_cluster():
'''
行业id->行业链标题-》上中下游-》查询数值
:return:
'''
req_dict = request.get_json()
# inid = req_dict.get("inid") # 二级行业id(二级行业显示链图)
industry_name = req_dict['industry_name'] # 二级行业id(二级行业显示链图)
# 校验参数完整性
if not all([industry_name]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
# name_query = "jc" + str(inid) + str(district)
# if redis_store.get(name_query) is not None:
# data = json.loads(redis_store.get(name_query))
# return jsonify(code=RET.OK, msg="获取成功", data=data)
# 行业使用名
# industryName = Industry.query.filter_by(oname=industry_name).first().oname
# ptp = neo4j_dict()
# if industryName in ptp:
# industryName = ptp[industryName]
result = {
"industryChain": industry_name,
"nodeList": [find_up_thr(industry_name, "上游行业"),
find_up_thr(industry_name, "中游行业"),
find_up_thr(industry_name, "下游行业")]
}
# redis缓存
# redis_store.set(name_query, json.dumps(result))
# redis_store.expire(name_query, 30 * 24 * 3600)
# print("redis")
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据异常")
return jsonify(code=RET.OK, msg="获取成功", data=result)
# @api_atlas.route('/IndustryCluster', methods=['POST'])
# # @login_required
# def industry_cluster():
# req_dic = request.get_json()
# industry_name = req_dic['industry_name']
# flag = req_dic['flag']
# '''
# 行业id->行业链标题-》上中下游-》查询数值
# :return:
# '''
# req_dict = request.get_json()
# # inid = req_dict.get("inid") # 二级行业id(二级行业显示链图)
# industry_name = req_dict['industry_name'] # 二级行业id(二级行业显示链图)
#
# # 校验参数完整性
# if not all([industry_name]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# try:
# industry_obj = IndustryChain.query.filter_by(industry_name=industry_name).first()
# industry_id = industry_obj.id
# chain_id = industry_obj.chain_id
# # name_query = "jc" + str(inid) + str(district)
# # if redis_store.get(name_query) is not None:
# # data = json.loads(redis_store.get(name_query))
# # return jsonify(code=RET.OK, msg="获取成功", data=data)
#
# if flag == 2:
# # 查询redis
# result = redis_store.get('chain_id_{}'.format(industry_id))
# if result:
# return jsonify(code=RET.OK, msg="获取成功", data=json.loads(result))
# # 行业使用名
# # industryName = Industry.query.filter_by(oname=industry_name).first().oname
# # ptp = neo4j_dict()
# # if industryName in ptp:
# # industryName = ptp[industryName]
# result = {
# "industryChain": industry_name,
# "nodeList": [find_up_thr1(chain_id, 1, industry_id, flag),
# find_up_thr1(chain_id, 2, industry_id, flag),
# find_up_thr1(chain_id, 3, industry_id, flag)]
# "nodeList": [find_up_thr(industry_name, "上游行业"),
# find_up_thr(industry_name, "中游行业"),
# find_up_thr(industry_name, "下游行业")]
# }
# # redis缓存
# # redis_store.set(name_query, json.dumps(result))
# # redis_store.expire(name_query, 30 * 24 * 3600)
# # print("redis")
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据异常")
# if flag == 2:
# try:
# redis_store.setex("chain_id_%s" % industry_id, constants.INDUSTRY_ENTERPRISE_REDIS_EXPIRES,
# json.dumps(result))
# # 保存发送给这个手机号的记录,防止用户在60s内再次出发发送短信的操作
# # redis_store.setex("send_sms_code_%s" % mobile, constants.SEND_SMS_CODE_INTERVAL, 1)
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="保存产业/企业数量信息异常")
#
# return jsonify(code=RET.OK, msg="获取成功", data=result)
@api_atlas.route('/IndustryCluster', methods=['POST'])
def industry_cluster():
req_dic = request.get_json()
industry_name = req_dic['industry_name']
flag = req_dic['flag']
try:
industry_obj = IndustryChain.query.filter_by(industry_name=industry_name).first()
industry_id = industry_obj.id
chain_id = industry_obj.chain_id
if flag == 2:
# 查询redis
result = redis_store.get('chain_id_{}'.format(industry_id))
if result:
return jsonify(code=RET.OK, msg="获取成功", data=json.loads(result))
result = {
"industryChain": industry_name,
"nodeList": [find_up_thr1(chain_id, 1, industry_id, flag),
find_up_thr1(chain_id, 2, industry_id, flag),
find_up_thr1(chain_id, 3, industry_id, flag)]
}
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据异常")
if flag == 2:
try:
redis_store.setex("chain_id_%s" % industry_id, constants.INDUSTRY_ENTERPRISE_REDIS_EXPIRES,
json.dumps(result))
# 保存发送给这个手机号的记录,防止用户在60s内再次出发发送短信的操作
# redis_store.setex("send_sms_code_%s" % mobile, constants.SEND_SMS_CODE_INTERVAL, 1)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="保存产业/企业数量信息异常")
return jsonify(code=RET.OK, msg="获取成功", data=result)
def get_count(chain_id, industry_id, chain_name, flag):
company_count = ''
id_list = []
......@@ -1104,29 +1104,29 @@ def industry_enterprise():
Company.chain_master == '1' if aptitude == '链主企业' else text(''),
)
# if product:
# # 点击上级环节,展示本级所有企业
# product_li = get_product_li(product, inid)
# company1 = []
# for product in product_li:
# company2 = company.filter(
# Company.c_type == inid,
# Company.product_all.like("%{}%".format(product))
# ).all()
# company1 += company2
# company1 = set(company1)
# size = len(company1)
# company1 = sorted(company1, key=lambda x: x.hots, reverse=True) # 排序
# companys = company1[(page - 1) * perpage:page * perpage] # 分页
# else:
# size = company.count()
# companys = company.order_by(Company.hots.desc()).paginate(page, perpage).items # 企业热度倒序
if product:
company = Company.query.filter(
Company.product_all.like('%{}%'.format(product))
)
size = company.count()
companys = company.order_by(Company.hots.desc()).paginate(page, perpage).items # 企业热度倒序
# 点击上级环节,展示本级所有企业
product_li = get_product_li(product, inid)
company1 = []
for product in product_li:
company2 = company.filter(
Company.c_type == inid,
Company.product_all.like("%{}%".format(product))
).all()
company1 += company2
company1 = set(company1)
size = len(company1)
company1 = sorted(company1, key=lambda x: x.hots, reverse=True) # 排序
companys = company1[(page - 1) * perpage:page * perpage] # 分页
else:
size = company.count()
companys = company.order_by(Company.hots.desc()).paginate(page, perpage).items # 企业热度倒序
# if product:
# company = Company.query.filter(
# Company.product_all.like('%{}%'.format(product))
# )
# size = company.count()
# companys = company.order_by(Company.hots.desc()).paginate(page, perpage).items # 企业热度倒序
df = [{"id": i.id,
"company_name": i.company_name,
......
......@@ -419,10 +419,10 @@ def search_enterprise():
def get_enterprise_num(product, inid):
# indu_obj_li = get_product_li(product, inid)
indu_obj_li = get_product_li(product, inid)
# total_enterprise_num = 0
indu_obj_li = []
indu_obj_li.append(product)
# indu_obj_li = []
# indu_obj_li.append(product)
company = []
for indu_name in indu_obj_li:
# indu_name = indu_obj.industry_name
......
......@@ -1220,64 +1220,51 @@ def radar_enums():
company = []
if product:
# 有可能会变成模糊查询
# enterprise = enterprise.filter(or_(
# Enterprise.product_all.like("%{}%".format(product)),
# Enterprise.product_all1.like("%{}%".format(product)),
# Enterprise.product_all2.like("%{}%".format(product))
# ))
# indu_obj_li = get_product_li(product, inid)
# for indu_name in indu_obj_li:
# # indu_name = indu_obj.industry_name
# # print("正在查询【{}】的相关企业......".format(indu_name))
# company1 = Enterprise.query.filter(
# Enterprise.c_type == inid,
# Enterprise.product_all.like("%{}%".format(indu_name))
# ).all()
# company += company1
# # print(company1)
# company2 = Enterprise.query.filter(
# Enterprise.c_type1 == inid,
# Enterprise.product_all1.like("%{}%".format(indu_name))
# ).all()
# company += company2
# # print(company2)
# company3 = Enterprise.query.filter(
# Enterprise.c_type2 == inid,
# Enterprise.product_all2.like("%{}%".format(indu_name))
# ).all()
# company += company3
# # print("产品【{}】已完成, 共有{}家相关企业。".format(indu_name, len(company1 + company2 + company3)))
#
# company = list(set(company))
# size = len(company)
# indu_obj_li = get_product_li(product, inid)
# for indu_name in indu_obj_li:
# indu_name = indu_obj.industry_name
indu_obj_li = get_product_li(product, inid)
for indu_name in indu_obj_li:
# indu_name = indu_obj.industry_name
# print("正在查询【{}】的相关企业......".format(indu_name))
# indu_obj = Industry.query.get(inid)
# indu_name = indu_obj.name
company1 = Enterprise.query.filter(
Enterprise.c_type == inid,
Enterprise.product_all.like("%{}%".format(product))
).all()
company += company1
# print(company1)
company2 = Enterprise.query.filter(
Enterprise.c_type1 == inid,
Enterprise.product_all1.like("%{}%".format(product))
).all()
company += company2
# print(company2)
company3 = Enterprise.query.filter(
Enterprise.c_type2 == inid,
Enterprise.product_all2.like("%{}%".format(product))
).all()
company += company3
company1 = Enterprise.query.filter(
Enterprise.c_type == inid,
Enterprise.product_all.like("%{}%".format(indu_name))
).all()
company += company1
# print(company1)
company2 = Enterprise.query.filter(
Enterprise.c_type1 == inid,
Enterprise.product_all1.like("%{}%".format(indu_name))
).all()
company += company2
# print(company2)
company3 = Enterprise.query.filter(
Enterprise.c_type2 == inid,
Enterprise.product_all2.like("%{}%".format(indu_name))
).all()
company += company3
# print("产品【{}】已完成, 共有{}家相关企业。".format(indu_name, len(company1 + company2 + company3)))
company = list(set(company))
size = len(company)
# company1 = Enterprise.query.filter(
# Enterprise.c_type == inid,
# Enterprise.product_all.like("%{}%".format(product))
# ).all()
# company += company1
# # print(company1)
# company2 = Enterprise.query.filter(
# Enterprise.c_type1 == inid,
# Enterprise.product_all1.like("%{}%".format(product))
# ).all()
# company += company2
# # print(company2)
# company3 = Enterprise.query.filter(
# Enterprise.c_type2 == inid,
# Enterprise.product_all2.like("%{}%".format(product))
# ).all()
# company += company3
#
# company = list(set(company))
# size = len(company)
nums_all = size if size else enterprise.count() # 企业总数
......@@ -1507,55 +1494,48 @@ def newList1():
enterprise = enterprise.filter_by(district=district)
company = []
if product:
# enterprise = enterprise.filter(or_(
# Enterprise.product_all.like("%{}%".format(product)),
# Enterprise.product_all1.like("%{}%".format(product)),
indu_obj_li = get_product_li(product, inid)
for indu_name in indu_obj_li:
# indu_name = indu_obj.industry_name
# print("正在查询【{}】的相关企业......".format(indu_name))
company1 = Enterprise.query.filter(
Enterprise.c_type == inid,
Enterprise.product_all.like("%{}%".format(indu_name))
).all()
company += company1
# print(company1)
company2 = Enterprise.query.filter(
Enterprise.c_type1 == inid,
Enterprise.product_all1.like("%{}%".format(indu_name))
).all()
company += company2
# print(company2)
company3 = Enterprise.query.filter(
Enterprise.c_type2 == inid,
Enterprise.product_all2.like("%{}%".format(indu_name))
).all()
company += company3
company = set(company)
# company1 = Enterprise.query.filter(
# Enterprise.c_type == inid,
# Enterprise.product_all.like("%{}%".format(product))
# ).all()
# company += company1
# # print(company1)
# company2 = Enterprise.query.filter(
# Enterprise.c_type1 == inid,
# Enterprise.product_all1.like("%{}%".format(product))
# ).all()
# company += company2
# # print(company2)
# company3 = Enterprise.query.filter(
# Enterprise.c_type2 == inid,
# Enterprise.product_all2.like("%{}%".format(product))
# ))
# indu_obj_li = get_product_li(product, inid)
# for indu_name in indu_obj_li:
# # indu_name = indu_obj.industry_name
# # print("正在查询【{}】的相关企业......".format(indu_name))
# company1 = Enterprise.query.filter(
# Enterprise.c_type == inid,
# Enterprise.product_all.like("%{}%".format(indu_name))
# ).all()
# company += company1
# # print(company1)
# company2 = Enterprise.query.filter(
# Enterprise.c_type1 == inid,
# Enterprise.product_all1.like("%{}%".format(indu_name))
# ).all()
# company += company2
# # print(company2)
# company3 = Enterprise.query.filter(
# Enterprise.c_type2 == inid,
# Enterprise.product_all2.like("%{}%".format(indu_name))
# ).all()
# company += company3
# ).all()
# company += company3
# company = set(company)
# indu_obj = Industry.query.get(inid)
# indu_name = indu_obj.name
company1 = Enterprise.query.filter(
Enterprise.c_type == inid,
Enterprise.product_all.like("%{}%".format(product))
).all()
company += company1
# print(company1)
company2 = Enterprise.query.filter(
Enterprise.c_type1 == inid,
Enterprise.product_all1.like("%{}%".format(product))
).all()
company += company2
# print(company2)
company3 = Enterprise.query.filter(
Enterprise.c_type2 == inid,
Enterprise.product_all2.like("%{}%".format(product))
).all()
company += company3
company = set(company)
if name:
enterprise = enterprise.filter(Enterprise.company_name.like("%{}%".format(name)))
if select == "1": # 瞪羚
......
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