Commit 5c5ddeab by 赵宇

添加产业赞赏雷达接口

parent 672251b1
......@@ -90,7 +90,7 @@ def creat_app(config_name):
from apps.view_attract import api_attract # 招商驾驶舱
# from apps.user_pc import api_user
from apps.atlas import api_atlas
# from apps.radar import api_radar
from apps.radar import api_radar
# from apps.attract import api_att
# from apps.view_360 import api_portraits
# from apps.view_choose_address import api_address
......@@ -99,7 +99,7 @@ def creat_app(config_name):
# from apps.view_mobile import api_mobile
# app.register_blueprint(api_user, url_prefix='/api/user')
# app.register_blueprint(api_radar, url_prefix='/api/radar')
app.register_blueprint(api_radar, url_prefix='/api/radar')
app.register_blueprint(api_atlas, url_prefix='/api/atlas')
# app.register_blueprint(api_att, url_prefix='/api/att')
#
......
......@@ -399,13 +399,6 @@ def industry_zaiti():
return jsonify(code=RET.OK, msg="数据查询成功", data=data)
except Exception as e:
current_app.logger.error(e)
# else:
# name = '煤层气' # 默认页面为煤层气的数据
# try:
# data = get_data(name, 1, 1, page, perpage)
# return jsonify(code=RET.OK, msg="数据查询成功", data=data)
# except Exception as e:
# current_app.logger.error(e)
# 产业政策
......@@ -537,19 +530,6 @@ def get_zaiti_detail_data():
id = req_dict.get('id')
cate_id = req_dict.get('cate_id') # 1为行政区,2为园区,3为土地,4为楼宇,5为厂房
print(cate_id)
# if cate_id == 1:
# try:
# induzone = Induzone.query.filter_by(id=id).first()
# data = {
# "district": induzone.district,
# "cate": induzone.cate,
# "area": induzone.area,
# "address": induzone.address,
# "cluster": induzone.cluster
# }
# return jsonify(code=RET.OK, msg='行政区详情查询成功!', data=data)
# except Exception as e:
# current_app.logger.error(e)
if cate_id in [1, 2]:
try:
......@@ -560,7 +540,6 @@ def get_zaiti_detail_data():
"area": induzone.area,
"address": induzone.address,
"cluster": induzone.cluster,
"name": induzone.name, # 名称
# "district": induzone.district, # 所属地区
"phone": induzone.phone, # 电话
......
......@@ -925,6 +925,37 @@ class ZaitiFactory(db.Model):
navigator = db.Column(db.String(10))
navigat = db.Column(db.String(20))
# 雷达评估页行业在不同地区的测评分数
class EvaluationNodeData(db.Model):
__tablename_ = "evaluation_data"
__table_args__ = ({'comment': '产业招商雷达-产业评估'}) # 添加表注释
id = db.Column(db.Integer, primary_key=True, autoincrement=True, doc='主键id', comment='主键id')
c_type = db.Column(db.Integer, index=True, doc='行业id', comment='行业id') # 行业id
province = db.Column(db.String(32), index=True, doc='省份', comment='省份') # 省份
city = db.Column(db.String(32), index=True, doc='城市', comment='城市') # 城市
district = db.Column(db.String(32), index=True, doc='区域', comment='区域') # 区域
product = db.Column(db.String(32), index=True, doc='产品名', comment='产品名') # 产品名
score = db.Column(db.Integer, doc='综合分', comment='综合分') # 综合分
# # 创新资源-双创平台
# class Platform(db.Model):
# __tablename_ = "platform"
......@@ -1063,19 +1094,7 @@ class ZaitiFactory(db.Model):
# general = db.Column(db.Integer) # 综合分
#
#
# # 雷达评估页行业在不同地区的测评分数
# class EvaluationNodeData(db.Model):
# __tablename_ = "evaluationnodedata"
#
# id = db.Column(db.Integer, primary_key=True, autoincrement=True)
# c_type = db.Column(db.Integer, index=True) # 行业id
#
# province = db.Column(db.String(32), index=True) # 省份
# city = db.Column(db.String(32), index=True) # 城市
# district = db.Column(db.String(32), index=True) # 区域
#
# product = db.Column(db.String(32), index=True) # 产品名
# score = db.Column(db.Integer) # 综合分
#
#
# # 查找历史表
......
......@@ -13,391 +13,205 @@ import datetime
from apps import db, constants, redis_store
from apps.utils.neo4j_conn import conn_neo4j
graph = conn_neo4j()
'''
1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
解决办法:删除ONLY_FULL_GROUP_BY
# 具体类型企业列表查询
@api_radar.route("/enterList", methods=["POST"])
def newList():
'''查看企业列表——外加详情'''
req_dict = request.get_json()
inid = req_dict.get("inid") # 行业id
area = req_dict.get("area") # [省,市,区]
if len(area) == 3:
province = area[0]
city = area[1]
district = area[2]
else:
province = ""
city = ""
district = ""
product = req_dict.get("product") # 企业产品
select = req_dict.get("select") # 企业列表选择 1234567 瞪羚-高新-科技型中小企业-上市-融资-独角兽-全部
page = req_dict.get("page")
perpage = req_dict.get("perpage")
name = req_dict.get("name")
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
if not all([inid, select, page, perpage]):
return jsonify(code=RET.PARAMERR, msg="参数错误")
try:
if inid:
enterprise = Enterprise.query.filter_by(c_type=inid)
else:
enterprise = Enterprise.query.filter_by()
if province:
enterprise = enterprise.filter_by(province=province)
if city:
enterprise = enterprise.filter_by(city=city)
if district:
enterprise = enterprise.filter_by(district=district)
if product:
# 有可能会变成模糊查询
enterprise = enterprise.filter(Enterprise.product_all.like("%{}%".format(product)))
if name:
# 有可能会变成模糊查询
enterprise = enterprise.filter(Enterprise.company_name.like("%{}%".format(name)))
if select == "1": # 瞪羚
remind = "瞪羚企业"
enterprise = enterprise.filter_by(dengl="1")
elif select == "2": # 高新
remind = "高新技术企业"
enterprise = enterprise.filter_by(high_new="1")
elif select == "3": # 科技型中小企业
remind = "科技型中小企业"
enterprise = enterprise.filter_by(tbe="1")
elif select == "4": # 上市
remind = "上市企业"
enterprise = enterprise.filter_by(quoted_company="1")
elif select == "5": # 融资
remind = "融资企业"
enterprise = enterprise.filter_by(fianacing="1")
elif select == "6": # 独角兽
remind = "独角兽企业"
enterprise = enterprise.filter_by(unicorn="1")
else:
remind = ""
enterprise = enterprise
size = enterprise.count()
enters = enterprise.paginate(page, perpage).items
enter = [{"id": i.id,
"name": i.company_name,
"industry": i.company_industry if i.company_industry else "-", # 行业
"build_date": str(i.build_date)[:10] if i.build_date else "-", # 时间
"capital": i.capital if i.capital else "-", # 注册资本
} for i in enters]
/*
修改my.ini:
sql_mode=NO_ENGINE_SUBSTITUTION
*/
SELECT @@GLOBAL.SQL_mode;
SET @@GLOBAL.sql_mode=
'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
SET @@GLOBAL.sql_mode="NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION";
data = {"remind": remind, "enter": enter, "size": size}
'''
return jsonify(code=RET.OK, msg="查找成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
graph = conn_neo4j()
# 雷达监测页企业数量统计
@api_radar.route('/radar/enums', methods=['POST'])
# 产业分析-趋势预判
@api_radar.route('/radar/IdusTendency', methods=['POST'])
# @login_required
def radar_enums():
'''雷达监测页企业数量统计'''
req_dict = request.get_json()
inid = req_dict.get("inid") # 行业id
area = req_dict.get("area") # [省,市,区]
province = area[0]
city = area[1]
district = area[2]
product = req_dict.get("product") # 企业产品
# 校验参数完整性
if not all([inid]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
name_query = "radar" + str(inid) + str("".join(area)) + str(product)
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 inid:
enterprise = Enterprise.query.filter_by(c_type=inid)
else:
enterprise = Enterprise.query.filter_by()
if province:
enterprise = enterprise.filter_by(province=province)
if city:
enterprise = enterprise.filter_by(city=city)
if district:
enterprise = enterprise.filter_by(district=district)
if product:
# 有可能会变成模糊查询
enterprise = enterprise.filter(Enterprise.product_all.like("%{}%".format(product)))
nums_all = enterprise.count() # 企业总数
nums_dengl = enterprise.filter_by(dengl="1").count() # 瞪羚企业
nums_hignew = enterprise.filter_by(high_new="1").count() # 高新技术企业
nums_tbe = enterprise.filter_by(tbe="1").count() # 科技型中小企业
nums_quoted = enterprise.filter_by(quoted_company="1").count() # 上市企业
nums_financ = enterprise.filter_by(fianacing="1").count() # 有融资小企业
nums_unicorn = enterprise.filter_by(unicorn="1").count() # 独角兽企业
nums_capital = round(
float(enterprise.with_entities(func.sum(Enterprise.capital_nums)).scalar() if enterprise.with_entities(
func.sum(Enterprise.capital_nums)).scalar() else 0) / 10000, 2) # 注册资本(亿元)
nums_bao = enterprise.with_entities(func.sum(Enterprise.bao_num)).scalar() if enterprise.with_entities(
func.sum(Enterprise.bao_num)).scalar() else 0 # 就业人数
nums_patent = enterprise.with_entities(func.sum(Enterprise.num_patent)).scalar() if enterprise.with_entities(
func.sum(Enterprise.num_patent)).scalar() else 0 # 授权发明专利
data = {"nums_all": float(nums_all), "nums_capital": float(nums_capital), "nums_bao": float(nums_bao),
"nums_patent": float(nums_patent),
"nums_dengl": float(nums_dengl), "nums_hignew": float(nums_hignew), "nums_tbe": float(nums_tbe),
"nums_quoted": float(nums_quoted),
"nums_financ": float(nums_financ), "nums_unicorn": float(nums_unicorn), # "info": info
}
# redis缓存
redis_store.setex(name_query, 30 * 24 * 3600, json.dumps(data))
# redis_store.set(name_query, json.dumps(data))
# redis_store.expire(name_query, 30 * 24 * 3600)
print("redis")
return jsonify(code=RET.OK, msg="获取成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 雷达监测页企业数量趋势统计
@api_radar.route('/radar/tendency', methods=['POST'])
@login_required
def tendency():
'''雷达监测页企业数量统计'''
req_dict = request.get_json()
inid = req_dict.get("inid") # 行业id
area = req_dict.get("area") # [省,市,区]
province = area[0]
city = area[1]
district = area[2]
product = req_dict.get("product") # 企业产品
sone = req_dict.get("sone") # 选择1,1企业个数,2注册资本
stwo = req_dict.get("stwo") # 选择2, 1年度,2季度,3月度
sthr = req_dict.get("sthr") # 选择3, 1新增量,2累积量
select_time = req_dict.get("select_time") # 选择2, 1年度,2季度,3月度
select_method = req_dict.get("select_method") # 选择3, 1新增量,2累积量
# 校验参数完整性
if not all([area, sone, stwo, sthr]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
# if not all([area, sone, select_time, select_method]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
name_query = "tendency" + str(inid) + str("".join(area)) + str(product) + str(sone) + str(stwo) + str(sthr)
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)
# name_query = "tendency" + str(inid) + str("".join(area)) + str(product) + str(sone) + str(select_time) + str(select_method)
# 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 inid:
enterprise = Enterprise.query.filter_by(c_type=inid)
else:
enterprise = Enterprise.query.filter_by()
if province:
enterprise = enterprise.filter_by(province=province)
if city:
enterprise = enterprise.filter_by(city=city)
if district:
enterprise = enterprise.filter_by(district=district)
if product:
# 有可能会变成模糊查询
enterprise = enterprise.filter(Enterprise.product_all.like("%{}%".format(product)))
# company = company.filter_by(product_all=product)
# yearn = datetime.datetime.now().year + 1 # 现在年份 固定成21
yearn = 2021 # 现在年份 固定成21
scope = [i for i in range(1980, yearn)] # 年份范围
months = [(1, 3), (4, 6), (7, 9), (10, 12)] # 季度
data = list()
if sthr == 1: # 新增量
if stwo == 1: # 年度,1980-2020
company_num_data = list()
register_capital_data = list()
company_num_name = ''
register_capital_name = ''
if select_method == 1: # 新增量
if select_time == 1: # 年度,1980-2020
company_num_name = '新增量年度企业个数'
register_capital_name = '新增量年度注册资本'
for year in scope:
result = enterprise.filter(extract("year", Enterprise.build_date) == year)
if sone == 1: # 企业个数
# 企业个数
nums = result.count()
# data[year] = nums
data.append({"lable": year, "value": nums})
else: # 注册资本
company_num_data.append({"label": year, "value": nums})
# 注册资本
cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
# data[year] = round(cnums, 2) if cnums else 0
data.append({"lable": year, "value": round(cnums, 2) if cnums else 0})
elif stwo == 2: # 2020年季度(修改为5年季度)
register_capital_data.append({"label": year, "value": round(cnums, 2) if cnums else 0})
elif select_time == 2: # 2020年季度(修改为5年季度)
company_num_name = '新增量季度企业个数'
register_capital_name = '新增量季度注册资本'
for yea in range(2016, 2021):
for jd in range(len(months)):
result = enterprise.filter(and_(extract("year", Enterprise.build_date) == yea,
extract("month", Enterprise.build_date).between(months[jd][0],
months[jd][1])))
if sone == 1: # 企业个数
# 企业个数
nums = result.count()
data.append({"lable": str(yea) + "-" + str(jd + 1), "value": nums})
else: # 注册资本
company_num_data.append({"label": str(yea) + "-" + str(jd + 1), "value": nums})
# 注册资本
cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
# data[(jd + 1)] = round(cnums, 2) if cnums else 0
data.append(
{"lable": str(yea) + "-" + str(jd + 1), "value": round(cnums, 2) if cnums else 0})
# for jd in range(len(months)):
# result = enterprise.filter(and_(extract("year", Enterprise.build_date) == (yearn - 1),
# extract("month", Enterprise.build_date).between(months[jd][0],
# months[jd][1])))
# if sone == 1: # 企业个数
# nums = result.count()
# # data[(jd + 1)] = nums
# data.append({"lable": (jd + 1), "value": nums})
# else: # 注册资本
# cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
# # data[(jd + 1)] = round(cnums, 2) if cnums else 0
# data.append({"lable": (jd + 1), "value": round(cnums, 2) if cnums else 0})
elif stwo == 3: # 2020年月度(改为3年月度)
register_capital_data.append(
{"label": str(yea) + "-" + str(jd + 1), "value": round(cnums, 2) if cnums else 0})
elif select_time == 3: # 2020年月度(改为3年月度)
company_num_name = '新增量月度企业个数'
register_capital_name = '新增量月度注册资本'
for yea in range(2018, 2021):
for m in range(2, 14, 2):
result = enterprise.filter(and_(extract("year", Enterprise.build_date) == yea,
extract("month", Enterprise.build_date) == m))
if sone == 1: # 企业个数
# 企业个数
nums = result.count()
# data[m] = nums
data.append({"lable": str(yea) + "-" + str(m).rjust(2, "0"), "value": nums})
else: # 注册资本
company_num_data.append({"label": str(yea) + "-" + str(m).rjust(2, "0"), "value": nums})
# 注册资本
cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
# data[m] = round(cnums, 2) if cnums else 0
data.append({"lable": str(yea) + "-" + str(m).rjust(2, "0"),
register_capital_data.append({"label": str(yea) + "-" + str(m).rjust(2, "0"),
"value": round(cnums, 2) if cnums else 0})
# for m in range(1, 13):
# result = enterprise.filter(and_(extract("year", Enterprise.build_date) == (yearn - 1),
# extract("month", Enterprise.build_date) == m))
# if sone == 1: # 企业个数
# nums = result.count()
# # data[m] = nums
# data.append({"lable": m, "value": nums})
# else: # 注册资本
# cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
# # data[m] = round(cnums, 2) if cnums else 0
# data.append({"lable": m, "value": round(cnums, 2) if cnums else 0})
elif sthr == 2: # 累积量
if stwo == 1: # 年度,1980-2020
elif select_method == 2: # 累积量
if select_time == 1: # 年度,1980-2020
company_num_name = '累积量年度企业个数'
register_capital_name = '累积量年度注册资本'
for year in scope:
result = enterprise.filter(extract("year", Enterprise.build_date) <= year)
if sone == 1: # 企业个数
# 企业个数
nums = result.count()
# data[year] = nums
data.append({"lable": year, "value": nums})
else: # 注册资本
company_num_data.append({"label": year, "value": nums})
# 注册资本
cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
# data[year] = round(cnums, 2) if cnums else 0
data.append({"lable": year, "value": round(cnums, 2) if cnums else 0})
elif stwo == 2: # 2020年季度
register_capital_data.append({"label": year, "value": round(cnums, 2) if cnums else 0})
elif select_time == 2: # 2020年季度
company_num_name = '累积量季度企业个数'
register_capital_name = '累积量季度注册资本'
for yea in range(2016, 2021):
for jd in range(len(months)):
result = enterprise.filter(and_(extract("year", Enterprise.build_date) == yea,
extract("month", Enterprise.build_date) <= months[jd][1]))
if sone == 1: # 企业个数
# 企业个数
nums = result.count()
# data[(jd + 1)] = nums
data.append({"lable": str(yea) + "-" + str(jd + 1), "value": nums})
else: # 注册资本
company_num_data.append({"label": str(yea) + "-" + str(jd + 1), "value": nums})
# 注册资本
cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
# data[(jd + 1)] = round(cnums, 2) if cnums else 0
data.append(
{"lable": str(yea) + "-" + str(jd + 1), "value": round(cnums, 2) if cnums else 0})
# for jd in range(len(months)):
# result = enterprise.filter(and_(extract("year", Enterprise.build_date) == (yearn - 1),
# extract("month", Enterprise.build_date) <= months[jd][1]))
# if sone == 1: # 企业个数
# nums = result.count()
# # data[(jd + 1)] = nums
# data.append({"lable": (jd + 1), "value": nums})
# else: # 注册资本
# cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
# # data[(jd + 1)] = round(cnums, 2) if cnums else 0
# data.append({"lable": (jd + 1), "value": round(cnums, 2) if cnums else 0})
elif stwo == 3: # 2020年月度
register_capital_data.append(
{"label": str(yea) + "-" + str(jd + 1), "value": round(cnums, 2) if cnums else 0})
elif select_time == 3: # 2020年月度
company_num_name = '累积量月度企业个数'
register_capital_name = '累积量月度注册资本'
for yea in range(2018, 2021):
for m in range(2, 14, 2):
result = enterprise.filter(and_(extract("year", Enterprise.build_date) == yea,
extract("month", Enterprise.build_date) <= m))
if sone == 1: # 企业个数
# 企业个数
nums = result.count()
# data[m] = nums
data.append({"lable": str(yea) + "-" + str(m).rjust(2, "0"), "value": nums})
else: # 注册资本
company_num_data.append({"label": str(yea) + "-" + str(m).rjust(2, "0"), "value": nums})
# 注册资本
cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
data.append({"lable": str(yea) + "-" + str(m).rjust(2, "0"),
register_capital_data.append({"label": str(yea) + "-" + str(m).rjust(2, "0"),
"value": round(cnums, 2) if cnums else 0})
# for m in range(1, 13):
# result = enterprise.filter(and_(extract("year", Enterprise.build_date) == (yearn - 1),
# extract("month", Enterprise.build_date) <= m))
# if sone == 1: # 企业个数
# nums = result.count()
# # data[m] = nums
# data.append({"lable": m, "value": nums})
# else: # 注册资本
# cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
# data.append({"lable": m, "value": round(cnums, 2) if cnums else 0})
else:
return jsonify(code=RET.DATAERR, msg="参数错误")
# redis缓存
redis_store.setex(name_query, 30 * 24 * 3600, json.dumps(data))
# redis_store.setex(name_query, 30 * 24 * 3600, json.dumps(data))
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误")
return jsonify(code=RET.OK, msg="获取成功", data=data)
# 雷达监测页企业top10
'''
1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
解决办法:删除ONLY_FULL_GROUP_BY
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
# data_dic = {
# "company_num": company_num_data.insert(0, company_num_name),
# "register_capital": register_capital_data.insert(0, register_capital_name),
# }
data_dic = {
"company_num": company_num_data,
"company_num_name": company_num_name,
/*
修改my.ini:
sql_mode=NO_ENGINE_SUBSTITUTION
*/
SELECT @@GLOBAL.SQL_mode;
SET @@GLOBAL.sql_mode=
'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
SET @@GLOBAL.sql_mode="NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION";
"register_capital": register_capital_data,
"register_capital_name": register_capital_name,
'''
}
return jsonify(code=RET.OK, msg="获取成功", data=data_dic)
@api_radar.route('/radar/topt', methods=['POST'])
# 产业分析-top10榜单数据接口
@api_radar.route('/radar/IdusTopTen', methods=['POST'])
# @login_required
def topt():
'''雷达监测页企业top10'''
req_dict = request.get_json()
inid = req_dict.get("inid") # 行业id
area = req_dict.get("area") # [省,市,区]
province = area[0]
city = area[1]
district = area[2]
# area = req_dict.get("area") # [省,市,区]
# province = area[0]
# city = area[1]
# district = area[2]
product = req_dict.get("product") # 企业产品
select = req_dict.get("select") # 1--上市 2--专利数量 3--500强
# 校验参数完整性
if not all([area]):
# if not all([area]):
if not all([inid]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
if inid:
enterprise = Enterprise.query.filter_by(c_type=int(inid))
else:
enterprise = Enterprise.query.filter_by()
# enterprise = Enterprise.query.filter_by(c_type=inid)
if province:
enterprise = enterprise.filter_by(province=province)
if city:
enterprise = enterprise.filter_by(city=city)
if district:
enterprise = enterprise.filter_by(district=district)
# if inid:
# enterprise = Enterprise.query.filter_by(c_type=int(inid))
# else:
# enterprise = Enterprise.query.filter_by()
# 默认为第一个产业相关,煤层气开发储运利用,产业集群不联动
enterprise = Enterprise.query.filter_by(c_type=inid)
# if province:
# enterprise = enterprise.filter_by(province=province)
# if city:
# enterprise = enterprise.filter_by(city=city)
# if district:
# enterprise = enterprise.filter_by(district=district)
if product:
# 有可能会变成模糊查询
enterprise = enterprise.filter(Enterprise.product_all.like("%{}%".format(product)))
......@@ -412,7 +226,9 @@ def topt():
# print(company[0].takingn)
sums = float(company[0].takingn if company[0].takingn else 1)
data = [
{"company_name": item.company_name,
{
"id": item.id,
"company_name": item.company_name,
"sum_money": str(int((float(item.takingn) if item.takingn else 0) / 10)) + '万元',
"h_sum": str((int(float(item.takingn) if item.takingn else 0) / sums) * 100)[:5] + "%"
} for item in company]
......@@ -425,10 +241,14 @@ def topt():
Enterprise.num_patent.desc()).limit(10).all()
if company:
sums = float(company[0].num_patent if company[0].num_patent else 1)
print(sums)
data = [
{"company_name": item.company_name,
{
"id": item.id,
"company_name": item.company_name,
"sum_money": str(int(int(item.num_patent if item.num_patent else 0) / 10)) + '个',
"h_sum": str((int(float(item.num_patent if item.num_patent else 0)) / sums) * 100)[:5] + "%"
"h_sum": str((int(float(item.num_patent if item.num_patent else 0)) / sums) * 100)[
:5] + "%"
} for item in company
]
return jsonify(code=RET.OK, msg="获取成功", data=data)
......@@ -441,7 +261,9 @@ def topt():
# print(company[0].takingn)
sums = float(company[0].takingn if company[0].takingn else 1)
data = [
{"company_name": item.company_name,
{
"id": item.id,
"company_name": item.company_name,
"sum_money": str(int((float(item.takingn) if item.takingn else 0) / 10)) + '万元',
"h_sum": str((int(float(item.takingn) if item.takingn else 0) / sums) * 100)[:5] + "%"
} for item in company]
......@@ -468,206 +290,40 @@ def topt():
return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 雷达监测页企业属性分布统计
@api_radar.route('/radar/distribute', methods=['POST'])
# @login_required
def distribute():
'''雷达监测页企业属性分布统计'''
req_dict = request.get_json()
inid = req_dict.get("inid") # 行业id
area = req_dict.get("area") # [省,市,区]
province = area[0]
city = area[1]
district = area[2]
product = req_dict.get("product") # 企业产品
# 校验参数完整性
if not all([area]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
if inid:
enterprise = Enterprise.query.filter_by(c_type=inid)
else:
enterprise = Enterprise.query.filter_by()
if province:
enterprise = enterprise.filter_by(province=province)
if city:
enterprise = enterprise.filter_by(city=city)
if district:
enterprise = enterprise.filter_by(district=district)
if product:
# 有可能会变成模糊查询
enterprise = enterprise.filter(Enterprise.product_all.like("%{}%".format(product)))
# 企业类型
types = enterprise.with_entities(Enterprise.entype).distinct().all()
types = [item[0] for item in types if item[0]]
data_1 = list()
for i in types:
c_num = enterprise.filter_by(entype=i).count()
data_1.append({"name": i, "value": c_num})
# data_1 = {k: round(v / sum(data_1.values()), 2) for k, v in data_1.items()}
# 币种,不能为空
types = enterprise.with_entities(Enterprise.money_type).distinct().all()
types = [item[0] for item in types if item[0]]
data_2 = list()
for i in types:
c_num = enterprise.filter_by(money_type=i).count()
data_2.append({"name": i, "value": c_num})
# data_2 = {k: round(v / sum(data_2.values()), 2) for k, v in data_2.items()}
# data_2 = {'人民币': 0.02, "None": 0.97, '美元': 0.01} # 正式数据不能为空,None不能以变量出现
# 成立时间分布yearid
types = enterprise.with_entities(Enterprise.yearid).distinct().all()
types = [item[0] for item in types if item[0]]
data_3 = list()
dic_year = {1: "1-3年", 2: "3-5年", 3: "5-8年", 4: "8-10年", 5: "10-15年", 6: "15年以上"}
for i in types:
if i in dic_year:
c_num = enterprise.filter_by(yearid=i).count()
data_3.append({"name": dic_year[i], "value": c_num})
# data_3 = {k: round(v / sum(data_3.values()), 2) for k, v in data_3.items()}
# 注册资本大小分布
types = enterprise.with_entities(Enterprise.capital_id).distinct().all()
types = [item[0] for item in types if item[0]]
data_4 = list()
dic_capital = {1: "100万以内", 2: "100-500万", 3: "500-1000万", 4: "1000-5000万", 5: "5000万-1亿", 6: "1亿以上"}
for i in types:
if i in dic_capital:
c_num = enterprise.filter_by(capital_id=i).count()
data_4.append({"name": dic_capital[i], "value": c_num})
# data_4 = {k: round(v / sum(data_4.values()), 2) for k, v in data_4.items()}
# 上市板块
plates = enterprise.with_entities(Enterprise.public_sector).distinct().all()
# types = [item[0] for item in types if item[0]]
data_5 = list()
for i in plates:
if i[0] == "空" or i[0] is None:
continue
c_num = enterprise.filter_by(public_sector=i[0]).count()
data_5.append({"name": i[0], "value": c_num})
# data_5 = {k: round(v / sum(data_5.values()), 2) for k, v in data_5.items()}
# 融资轮次分布(按融资轮次)
rounds = enterprise.with_entities(Enterprise.fianacing_rounds).distinct().all()
data_6 = list()
for i in rounds:
if i[0] == "空" or i[0] is None:
continue
c_num = enterprise.filter_by(fianacing_rounds=i[0]).count()
data_6.append({"name": i[0], "value": c_num})
# data_6 = {k: round(v / sum(data_6.values()), 2) for k, v in data_6.items()}
data = {"entype": data_1, # 企业类型
"currency": data_2, # 币种
"time_distribute": data_3, # 成立时间分布
"capital": data_4, # 注册资本分部
"sector": data_5, # 上市板块
"rounds": data_6} # 融资轮次
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误")
return jsonify(code=RET.OK, msg="获取成功", data=data)
# 雷达评估页行业地区分数评估
@api_radar.route('/radar/evaluation', methods=['POST'])
# @login_required
def evaluation():
'''雷达监测页企业属性分布统计'''
req_dict = request.get_json()
inid = req_dict.get("inid") # 二级行业id
area = req_dict.get("area") # [省,市,区]
province = area[0]
city = area[1]
district = area[2]
# 校验参数完整性
if not all([inid, area]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
edata = EvaluationData.query.filter_by(c_type=inid)
if province and not city:
edata = edata.filter_by(province=province).filter(EvaluationData.city.is_(None))
if province and city and not district:
edata = edata.filter_by(province=province, city=city).filter(EvaluationData.district.is_(None))
if province and city and district:
edata = edata.filter_by(province=province, city=city, district=district)
edata = edata.first()
if edata:
data = {"development": edata.development, # 发育度
"contribute": edata.contribute, # 贡献度
"innovate": edata.innovate, # 创新力
"growup": edata.growup, # 成长性
"capital": edata.capital, # 资本力
"general": edata.general} # 综合分
return jsonify(code=RET.OK, msg="获取成功", data=data)
else:
data = {"development": 0,
"contribute": 0,
"innovate": 0,
"growup": 0,
"capital": 0,
"general": 0}
return jsonify(code=RET.NODATA, msg="无数据", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 雷达评估页行业地区优势薄弱缺失三环节数据
@api_radar.route('/radar/prolink', methods=['POST'])
# 产业评估-优势薄弱缺失三环节
@api_radar.route('/radar/ThreeLink', methods=['POST'])
# @login_required
def prolink():
'''雷达监测页企业属性分布统计'''
req_dict = request.get_json()
inid = req_dict.get("inid") # 行业id
area = req_dict.get("area") # [省,市,区]
province = area[0]
city = area[1]
district = area[2]
# area = req_dict.get("area") # [省,市,区]
# province = area[0]
# city = area[1]
# district = area[2]
link_type = req_dict.get("link_type") # 缺失环节1,薄弱环节2,优势环节3
page = req_dict.get("page") # page
perpage = req_dict.get("perpage") # perpage
# 校验参数完整性
if not all([inid, area, page, perpage]):
if not all([inid, page, perpage]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
edata = EvaluationNodeData.query.filter_by(c_type=inid)
if not province:
edata = edata.filter(EvaluationNodeData.province.is_(None)).filter(
EvaluationNodeData.city.is_(None)).filter(EvaluationNodeData.district.is_(None))
if province and not city:
edata = edata.filter_by(province=province).filter(EvaluationNodeData.city.is_(None)).filter(
EvaluationNodeData.district.is_(None))
if province and city and not district:
edata = edata.filter_by(province=province, city=city).filter(EvaluationNodeData.district.is_(None))
if province and city and district:
edata = edata.filter_by(province=province, city=city, district=district)
edata = edata.filter_by(province="山西省", city="晋城市")
edata = edata.all()
if edata:
num = [math.ceil(i.score) if i.score else 0 for i in edata]
num.sort()
num = [i for i in num if i > 0]
cent = num[int(len(num) * 0.5)]
deletion = len([item for item in edata if item.score == 0])
bedness = len([item for item in edata if item.score > 0 and item.score <= cent])
goodness = len([item for item in edata if item.score > cent])
deletion = len([item for item in edata if item.score == 0]) # 缺失环节
bedness = len([item for item in edata if item.score > 0 and item.score <= cent]) # 薄弱环节
goodness = len([item for item in edata if item.score > cent]) # 优势环节
res = {
"deletion": deletion,
......@@ -694,16 +350,8 @@ def prolink():
return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 产品描述及推荐
@api_radar.route('/randerSelect', methods=['GET'])
# @login_required
def rander_select():
data = [{"label": "太原", "value": "太原"}, {"label": "其它", "value": "其它"}]
return jsonify(code=RET.OK, msg="查询成功", data=data)
# 产品描述及推荐
@api_radar.route('/recommond', methods=['POST'])
# 产业评估-根据具体环节的细分产业获取相关企业
@api_radar.route('/GetLinkEnterprise', methods=['POST'])
# @login_required
def recommond():
'''
......@@ -714,271 +362,548 @@ def recommond():
name = req_dict.get("name") # 产品名
page = req_dict.get("page")
perpage = req_dict.get("perpage")
select = req_dict.get("select") # 企业地址选择
# select = req_dict.get("select") # 企业地址选择
# 校验参数完整性
if not all([name]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
# 产品描述
# product = ProductInfo.query.filter_by(name=name).first()
# info = product.info if product and product.info else "暂无详情"
enterprise = Enterprise.query.filter(Enterprise.product_all.like("%{}%".format(name)))
# print(enterprise.count())
# company = Company.query.filter_by()
# 不在太原市
if select == "太原":
enterprise = enterprise.filter(Enterprise.city == "太原市") # .order_by(Enterprise.hots.desc())
else:
enterprise = enterprise.filter(Enterprise.city != "太原市") # .order_by(Enterprise.hots.desc())
# 参保人数
# enterprise = enterprise.filter(Enterprise.bao_num >= 5)
# 500强(分组排序)
# enterprise = enterprise.group_by(Enterprise.isfive).order_by(Enterprise.isfive.desc())
# print(enterprise.count())
size = enterprise.count()
enterprise = enterprise.order_by(Enterprise.c_type, Enterprise.hots.desc()).paginate(page,
perpage).items # # 企业热度倒序
df = []
ent_data = []
for com in enterprise:
df.append({"id": com.id,
ent_data.append({"id": com.id,
"company_name": com.company_name,
"capital": com.capital if com.capital else "-",
"buildate": str(com.build_date)[:10] if com.build_date else "-",
"status": com.status if com.status else "-",
"hots": com.hots})
data = {"df": df, "info": "暂无详情", "size": size}
"city": com.city,
"district": com.district,
"build_date": str(com.build_date)[:10] if com.build_date else "-", # 时间
"legal": com.legal,
"capital_nums": com.capital_nums,
"entype": com.entype,
"high_new": "高新企业" if com.high_new == "1" else "",
"tbe": "" if com.tbe == "1" else "",
"fianacing": "融资企业" if com.fianacing == "1" else "",
"quoted_company": "上市企业" if com.quoted_company == "1" else "",
"dengl": "瞪羚企业" if com.dengl == "1" else "",
"unicorn": "独角兽企业" if com.unicorn == "1" else "",
"isfive": "500强企业" if com.isfive == "1" else "",
"address": com.address,
"telephone": com.telephone
})
data = {"ent_data": ent_data, "size": size}
return jsonify(code=RET.OK, msg="查询成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误")
'''新增暂不考虑'''
# 优质企业-各资质企业数量
@api_radar.route('/radar/GoodEnterpriseNum', methods=['POST'])
# @login_required
def radar_enums():
'''雷达监测页企业数量统计'''
req_dict = request.get_json()
inid = req_dict.get("inid") # 行业id
# 校验参数完整性
if not all([inid]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
# 创建body
def create_body(args_query, args_term):
body = {
"query": {
"bool": {
"must": [{"multi_match": {"query": "{}".format(args_query["query"]), # match_phrase来实现完全匹配查询。
"type": "phrase",
"fields": [
"product"
],
"slop": 0,
}
},
]
}
},
"from": 0,
"size": 10,
"sort": [],
"aggs": {},
"_source": ['company_name'],
try:
# name_query = "radar" + str(inid) + str("".join(area)) + str(product)
# 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)
}
enterprise = Enterprise.query.filter_by(c_type=inid)
for k, v in args_term.items():
body["query"]["bool"]["must"].append({"term": {"{}".format(k): "{}".format(v)}})
num_isfive = enterprise.filter_by(isfive="1").count() # 500强企业
nums_quoted = enterprise.filter_by(quoted_company="1").count() # 上市企业
nums_financ = enterprise.filter_by(fianacing="1").count() # 有融资小企业
nums_hignew = enterprise.filter_by(high_new="1").count() # 高新技术企业
nums_tbe = enterprise.filter_by(tbe="1").count() # 科技型中小企业
nums_dengl = enterprise.filter_by(dengl="1").count() # 瞪羚企业
nums_unicorn = enterprise.filter_by(unicorn="1").count() # 独角兽企业
return body
data = {
"num_isfive": num_isfive,
"nums_dengl": nums_dengl, "nums_hignew": nums_hignew, "nums_tbe": nums_tbe,
"nums_quoted": nums_quoted,
"nums_financ": nums_financ, "nums_unicorn": nums_unicorn, # "info": info
}
# redis缓存
# redis_store.setex(name_query, 30 * 24 * 3600, json.dumps(data))
# redis_store.set(name_query, json.dumps(data))
# redis_store.expire(name_query, 30 * 24 * 3600)
# print("redis")
return jsonify(code=RET.OK, msg="获取成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 通过节点判断优势薄弱和缺失,1优势、2薄弱、3缺失
def get_waa(pname_two, inid, area):
province = area[0]
city = area[1]
district = area[2]
try:
edata = EvaluationNodeData.query.filter_by(c_type=inid)
if not province:
edata = edata.filter(EvaluationNodeData.province.is_(None)).filter(
EvaluationNodeData.city.is_(None)).filter(EvaluationNodeData.district.is_(None))
if province and not city:
edata = edata.filter_by(province=province).filter(EvaluationNodeData.city.is_(None)).filter(
EvaluationNodeData.district.is_(None))
if province and city and not district:
edata = edata.filter_by(province=province, city=city).filter(EvaluationNodeData.district.is_(None))
if province and city and district:
edata = edata.filter_by(province=province, city=city, district=district)
edata = edata.all()
# 优质企业-具体资质企业列表查询
@api_radar.route("/ZizhiEnterList", methods=["POST"])
def newList():
'''查看企业列表——外加详情'''
req_dict = request.get_json()
inid = req_dict.get("inid") # 行业id
select = req_dict.get("select") # 企业列表选择 1234567 500强-上市-融资-高新-科技型中小企业--瞪羚-独角兽
page = req_dict.get("page")
perpage = req_dict.get("perpage")
if edata:
num = [math.ceil(i.score) if i.score else 0 for i in edata]
num.sort()
num = [i for i in num if i > 0]
cent = num[int(len(num) * 0.5)]
youshi = [item.product for item in edata if item.score > cent] # 优势
queshi = [item.product for item in edata if item.score == 0] # 缺失
weak = [item.product for item in edata if item.score > 0 and item.score <= cent] # 薄弱
else:
youshi = [] # 优势
queshi = [] # 缺失
weak = [] # 薄弱
if pname_two in youshi:
return 1
if pname_two in weak:
return 2
if pname_two in queshi:
return 3
except Exception as e:
current_app.logger.error(e)
return 2
if not all([inid, select, page, perpage]):
return jsonify(code=RET.PARAMERR, msg="参数错误")
try:
enterprise = Enterprise.query.filter_by(c_type=inid)
remind = ''
if select == 1:
remind = "500强企业"
enterprise = enterprise.filter_by(isfive="1")
elif select == 2: # 上市
remind = "上市企业"
enterprise = enterprise.filter_by(quoted_company="1")
elif select == 3: # 融资
remind = "融资企业"
enterprise = enterprise.filter_by(fianacing="1")
elif select == 4: # 高新
remind = "高新技术企业"
enterprise = enterprise.filter_by(high_new="1")
elif select == 5: # 科技型中小企业
remind = "科技型中小企业"
enterprise = enterprise.filter_by(tbe="1")
elif select == 6: # 瞪羚
remind = "瞪羚企业"
enterprise = enterprise.filter_by(dengl="1")
elif select == 7: # 独角兽
remind = "独角兽企业"
enterprise = enterprise.filter_by(unicorn="1")
# 通过es全匹配查询三级
def find_thr_by_es(inid, name_query, relation, area):
if relation == "中游行业":
relation_c = "下位产品"
else:
relation_c = relation
args_term = dict() # 省市区条件
if area[0]:
args_term['province'] = area[0]
if area[1]:
args_term['city'] = area[1]
if area[2]:
args_term['district'] = area[2]
args_term['c_type'] = inid # 指定二级企业分类
url = "http://127.0.0.1:9200/ty_cur/_search"
sql_01 = "match (n) -[r:`{}`]->(m) WHERE n.name='{}' return n.name,r.type,m.name".format(relation_c, name_query)
res_zero = graph.run(sql_01).data()
res_one = list(set([i["m.name"] for i in list(res_zero)])) # 不重复的一级节点
data = {"clickable": False,
"node": "{}".format(relation[:2]),
"level": 1,
"subNodeList": [],
# "count": cnums
}
size = enterprise.count()
enters = enterprise.paginate(page, perpage).items
enter = [{
"id": i.id,
"company_name": i.company_name,
"city": i.city,
"district": i.district,
"build_date": str(i.build_date)[:10] if i.build_date else "-", # 时间
"legal": i.legal,
"capital_nums": i.capital_nums,
"entype": i.entype,
"zizhi": remind,
# "high_new": "高新企业" if i.high_new == "1" else "",
# "tbe": "" if i.tbe == "1" else "",
# "fianacing": "融资企业" if i.fianacing == "1" else "",
# "quoted_company": "上市企业" if i.quoted_company == "1" else "",
# "dengl": "瞪羚企业" if i.dengl == "1" else "",
# "unicorn": "独角兽企业" if i.unicorn == "1" else "",
# "isfive": "500强企业" if i.isfive == "1" else "",
"address": i.address,
"telephone": i.telephone
} for i in enters]
for it in res_one:
pname_one = it
# es全匹配查询企业数量
args_query = dict() # 产品
args_query["query"] = pname_one
body = create_body(args_query, args_term)
result_es = json.loads(requests.post(url=url, json=body).text)
erjicount = int(result_es["hits"]["total"])
node_one = {"clickable": True,
"node": "{}".format(pname_one),
"level": 2,
"count": erjicount,
"subNodeList": []
}
sql_02 = "match (n) -[r]->(m) WHERE n.name='{}' return n.name,r.type,m.name".format(pname_one)
result = graph.run(sql_02).data()
result = list(set([i["m.name"] for i in list(result)])) # 不重复的二级节点
for item in result:
pname_two = item
# es全匹配查询企业数量
args_query = dict() # 产品
args_query["query"] = pname_two
body = create_body(args_query, args_term)
result_es = json.loads(requests.post(url=url, json=body).text)
count2 = int(result_es["hits"]["total"])
# 二级节点
node_two = {"clickable": True,
"node": "{}".format(pname_two),
"level": 3,
"count": count2,
"subNodeList": [],
"waa": get_waa(pname_two, inid, area) # 1优势、2薄弱、3缺失
}
sql_03 = "match (n) -[r]->(m) WHERE n.name='{}' return n.name,r.type,m.name".format(pname_two)
result3 = graph.run(sql_03).data()
result3 = list(set([i["m.name"] for i in list(result3)])) # 不重复的三级节点
for itm in result3:
pname_thr = itm
args_query = dict() # 产品
args_query["query"] = pname_thr
body = create_body(args_query, args_term)
result_es = json.loads(requests.post(url=url, json=body).text)
count3 = int(result_es["hits"]["total"])
# 三级
node_thr = {"clickable": True,
"node": "{}".format(pname_thr),
"level": 4,
"count": count3,
"subNodeList": []
}
node_two["subNodeList"].append(node_thr)
node_one["subNodeList"].append(node_two)
data["subNodeList"].append(node_one)
data = {"remind": remind, "enter": enter, "size": size}
return data
return jsonify(code=RET.OK, msg="查找成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
# 行业产品公司数量(链图)
@api_radar.route('/attract/chain', methods=['POST'])
# @login_required
def attract_chain():
'''行业id->行业链标题-》上中下游-》查询数值'''
req_dict = request.get_json()
inid = req_dict.get("inid") # 二级行业id(二级行业显示链图)
area = req_dict.get("area") # ["","",""] 省市区
# 校验参数完整性
if not all([inid]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
name_query = "radar" + str(inid) + str("".join(area))
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(nid=inid).first().oname
ptp = {"轨道交通": "轨道交通装备",
"新能源汽车": "新能源汽车整车制造",
"智能煤机": "智能煤机",
"数控机床及机器人": "数控机床及机器人",
"通用航空": "通用航空",
"智能电网": "智能电网",
"氢能": "氢能",
"碳基新材料": "碳基新材料",
"金属新材料": "金属新材料",
"煤化工新材料": "煤化工新材料",
"生物基新材料": "生物基新材料",
"信息技术应用创新": "信息创新技术",
"网络安全": "网络安全",
"云计算": "云计算产业",
"大数据及人工智能": "大数据及人工智能",
"物联网": "物联网",
"康养产业": "康养产业",
"生物制药": "生物制药",
"现代物流": "现代物流",
"现代金融": "现代金融",
"半导体及光电子": "半导体",
"节能环保": "节能环保"
}
if industryName in ptp:
industryName = ptp[industryName]
result = {
"industryChain": industryName,
"nodeList": [find_thr_by_es(inid, industryName, "上游行业", area),
find_thr_by_es(inid, industryName, "中游行业", area),
find_thr_by_es(inid, industryName, "下游行业", area)]
}
# 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_radar.route('/randerSelect', methods=['GET'])
# # @login_required
# def rander_select():
# data = [{"label": "太原", "value": "太原"}, {"label": "其它", "value": "其它"}]
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# # 创建body
# def create_body(args_query, args_term):
# body = {
# "query": {
# "bool": {
# "must": [{"multi_match": {"query": "{}".format(args_query["query"]), # match_phrase来实现完全匹配查询。
# "type": "phrase",
# "fields": [
# "product"
# ],
# "slop": 0,
# }
# },
# ]
# }
# },
# "from": 0,
# "size": 10,
# "sort": [],
# "aggs": {},
# "_source": ['company_name'],
#
# }
#
# for k, v in args_term.items():
# body["query"]["bool"]["must"].append({"term": {"{}".format(k): "{}".format(v)}})
#
# return body
#
#
# # 通过节点判断优势薄弱和缺失,1优势、2薄弱、3缺失
# def get_waa(pname_two, inid, area):
# province = area[0]
# city = area[1]
# district = area[2]
#
# try:
# edata = EvaluationNodeData.query.filter_by(c_type=inid)
# if not province:
# edata = edata.filter(EvaluationNodeData.province.is_(None)).filter(
# EvaluationNodeData.city.is_(None)).filter(EvaluationNodeData.district.is_(None))
# if province and not city:
# edata = edata.filter_by(province=province).filter(EvaluationNodeData.city.is_(None)).filter(
# EvaluationNodeData.district.is_(None))
# if province and city and not district:
# edata = edata.filter_by(province=province, city=city).filter(EvaluationNodeData.district.is_(None))
# if province and city and district:
# edata = edata.filter_by(province=province, city=city, district=district)
# edata = edata.all()
#
# if edata:
# num = [math.ceil(i.score) if i.score else 0 for i in edata]
# num.sort()
# num = [i for i in num if i > 0]
# cent = num[int(len(num) * 0.5)]
# youshi = [item.product for item in edata if item.score > cent] # 优势
# queshi = [item.product for item in edata if item.score == 0] # 缺失
# weak = [item.product for item in edata if item.score > 0 and item.score <= cent] # 薄弱
# else:
# youshi = [] # 优势
# queshi = [] # 缺失
# weak = [] # 薄弱
# if pname_two in youshi:
# return 1
# if pname_two in weak:
# return 2
# if pname_two in queshi:
# return 3
# except Exception as e:
# current_app.logger.error(e)
# return 2
#
#
# # 通过es全匹配查询三级
# def find_thr_by_es(inid, name_query, relation, area):
# if relation == "中游行业":
# relation_c = "下位产品"
# else:
# relation_c = relation
#
# args_term = dict() # 省市区条件
# if area[0]:
# args_term['province'] = area[0]
# if area[1]:
# args_term['city'] = area[1]
# if area[2]:
# args_term['district'] = area[2]
# args_term['c_type'] = inid # 指定二级企业分类
# url = "http://127.0.0.1:9200/ty_cur/_search"
#
# sql_01 = "match (n) -[r:`{}`]->(m) WHERE n.name='{}' return n.name,r.type,m.name".format(relation_c, name_query)
# res_zero = graph.run(sql_01).data()
# res_one = list(set([i["m.name"] for i in list(res_zero)])) # 不重复的一级节点
# data = {"clickable": False,
# "node": "{}".format(relation[:2]),
# "level": 1,
# "subNodeList": [],
# # "count": cnums
# }
#
# for it in res_one:
# pname_one = it
#
# # es全匹配查询企业数量
# args_query = dict() # 产品
# args_query["query"] = pname_one
# body = create_body(args_query, args_term)
# result_es = json.loads(requests.post(url=url, json=body).text)
# erjicount = int(result_es["hits"]["total"])
#
# node_one = {"clickable": True,
# "node": "{}".format(pname_one),
# "level": 2,
# "count": erjicount,
# "subNodeList": []
# }
# sql_02 = "match (n) -[r]->(m) WHERE n.name='{}' return n.name,r.type,m.name".format(pname_one)
# result = graph.run(sql_02).data()
# result = list(set([i["m.name"] for i in list(result)])) # 不重复的二级节点
# for item in result:
# pname_two = item
# # es全匹配查询企业数量
# args_query = dict() # 产品
# args_query["query"] = pname_two
# body = create_body(args_query, args_term)
# result_es = json.loads(requests.post(url=url, json=body).text)
# count2 = int(result_es["hits"]["total"])
# # 二级节点
# node_two = {"clickable": True,
# "node": "{}".format(pname_two),
# "level": 3,
# "count": count2,
# "subNodeList": [],
# "waa": get_waa(pname_two, inid, area) # 1优势、2薄弱、3缺失
# }
# sql_03 = "match (n) -[r]->(m) WHERE n.name='{}' return n.name,r.type,m.name".format(pname_two)
# result3 = graph.run(sql_03).data()
# result3 = list(set([i["m.name"] for i in list(result3)])) # 不重复的三级节点
# for itm in result3:
# pname_thr = itm
# args_query = dict() # 产品
# args_query["query"] = pname_thr
# body = create_body(args_query, args_term)
# result_es = json.loads(requests.post(url=url, json=body).text)
# count3 = int(result_es["hits"]["total"])
# # 三级
# node_thr = {"clickable": True,
# "node": "{}".format(pname_thr),
# "level": 4,
# "count": count3,
# "subNodeList": []
# }
# node_two["subNodeList"].append(node_thr)
# node_one["subNodeList"].append(node_two)
# data["subNodeList"].append(node_one)
#
# return data
#
#
# # 行业产品公司数量(链图)
# @api_radar.route('/attract/chain', methods=['POST'])
# # @login_required
# def attract_chain():
# '''行业id->行业链标题-》上中下游-》查询数值'''
# req_dict = request.get_json()
# inid = req_dict.get("inid") # 二级行业id(二级行业显示链图)
# area = req_dict.get("area") # ["","",""] 省市区
#
# # 校验参数完整性
# if not all([inid]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# try:
# name_query = "radar" + str(inid) + str("".join(area))
# 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(nid=inid).first().oname
# ptp = {"轨道交通": "轨道交通装备",
# "新能源汽车": "新能源汽车整车制造",
# "智能煤机": "智能煤机",
# "数控机床及机器人": "数控机床及机器人",
#
# "通用航空": "通用航空",
# "智能电网": "智能电网",
# "氢能": "氢能",
# "碳基新材料": "碳基新材料",
#
# "金属新材料": "金属新材料",
# "煤化工新材料": "煤化工新材料",
# "生物基新材料": "生物基新材料",
# "信息技术应用创新": "信息创新技术",
#
# "网络安全": "网络安全",
# "云计算": "云计算产业",
# "大数据及人工智能": "大数据及人工智能",
# "物联网": "物联网",
#
# "康养产业": "康养产业",
# "生物制药": "生物制药",
# "现代物流": "现代物流",
# "现代金融": "现代金融",
#
# "半导体及光电子": "半导体",
# "节能环保": "节能环保"
# }
# if industryName in ptp:
# industryName = ptp[industryName]
# result = {
# "industryChain": industryName,
# "nodeList": [find_thr_by_es(inid, industryName, "上游行业", area),
# find_thr_by_es(inid, industryName, "中游行业", area),
# find_thr_by_es(inid, industryName, "下游行业", area)]
# }
# # 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_radar.route('/radar/distribute', methods=['POST'])
# # @login_required
# def distribute():
# '''雷达监测页企业属性分布统计'''
# req_dict = request.get_json()
# inid = req_dict.get("inid") # 行业id
# area = req_dict.get("area") # [省,市,区]
# province = area[0]
# city = area[1]
# district = area[2]
# product = req_dict.get("product") # 企业产品
#
# # 校验参数完整性
# if not all([area]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# try:
# if inid:
# enterprise = Enterprise.query.filter_by(c_type=inid)
# else:
# enterprise = Enterprise.query.filter_by()
#
# if province:
# enterprise = enterprise.filter_by(province=province)
# if city:
# enterprise = enterprise.filter_by(city=city)
# if district:
# enterprise = enterprise.filter_by(district=district)
#
# if product:
# # 有可能会变成模糊查询
# enterprise = enterprise.filter(Enterprise.product_all.like("%{}%".format(product)))
#
# # 企业类型
#
# types = enterprise.with_entities(Enterprise.entype).distinct().all()
# types = [item[0] for item in types if item[0]]
# data_1 = list()
# for i in types:
# c_num = enterprise.filter_by(entype=i).count()
# data_1.append({"name": i, "value": c_num})
# # data_1 = {k: round(v / sum(data_1.values()), 2) for k, v in data_1.items()}
#
# # 币种,不能为空
# types = enterprise.with_entities(Enterprise.money_type).distinct().all()
# types = [item[0] for item in types if item[0]]
# data_2 = list()
# for i in types:
# c_num = enterprise.filter_by(money_type=i).count()
# data_2.append({"name": i, "value": c_num})
# # data_2 = {k: round(v / sum(data_2.values()), 2) for k, v in data_2.items()}
# # data_2 = {'人民币': 0.02, "None": 0.97, '美元': 0.01} # 正式数据不能为空,None不能以变量出现
#
# # 成立时间分布yearid
# types = enterprise.with_entities(Enterprise.yearid).distinct().all()
# types = [item[0] for item in types if item[0]]
# data_3 = list()
# dic_year = {1: "1-3年", 2: "3-5年", 3: "5-8年", 4: "8-10年", 5: "10-15年", 6: "15年以上"}
# for i in types:
# if i in dic_year:
# c_num = enterprise.filter_by(yearid=i).count()
# data_3.append({"name": dic_year[i], "value": c_num})
# # data_3 = {k: round(v / sum(data_3.values()), 2) for k, v in data_3.items()}
#
# # 注册资本大小分布
# types = enterprise.with_entities(Enterprise.capital_id).distinct().all()
# types = [item[0] for item in types if item[0]]
# data_4 = list()
# dic_capital = {1: "100万以内", 2: "100-500万", 3: "500-1000万", 4: "1000-5000万", 5: "5000万-1亿", 6: "1亿以上"}
# for i in types:
# if i in dic_capital:
# c_num = enterprise.filter_by(capital_id=i).count()
# data_4.append({"name": dic_capital[i], "value": c_num})
# # data_4 = {k: round(v / sum(data_4.values()), 2) for k, v in data_4.items()}
#
# # 上市板块
# plates = enterprise.with_entities(Enterprise.public_sector).distinct().all()
# # types = [item[0] for item in types if item[0]]
# data_5 = list()
# for i in plates:
# if i[0] == "空" or i[0] is None:
# continue
# c_num = enterprise.filter_by(public_sector=i[0]).count()
# data_5.append({"name": i[0], "value": c_num})
# # data_5 = {k: round(v / sum(data_5.values()), 2) for k, v in data_5.items()}
#
# # 融资轮次分布(按融资轮次)
# rounds = enterprise.with_entities(Enterprise.fianacing_rounds).distinct().all()
# data_6 = list()
# for i in rounds:
# if i[0] == "空" or i[0] is None:
# continue
# c_num = enterprise.filter_by(fianacing_rounds=i[0]).count()
# data_6.append({"name": i[0], "value": c_num})
# # data_6 = {k: round(v / sum(data_6.values()), 2) for k, v in data_6.items()}
#
# data = {"entype": data_1, # 企业类型
# "currency": data_2, # 币种
# "time_distribute": data_3, # 成立时间分布
# "capital": data_4, # 注册资本分部
# "sector": data_5, # 上市板块
# "rounds": data_6} # 融资轮次
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库查询错误")
#
# return jsonify(code=RET.OK, msg="获取成功", data=data)
#
#
# # 雷达评估页行业地区分数评估
# @api_radar.route('/radar/evaluation', methods=['POST'])
# # @login_required
# def evaluation():
# '''雷达监测页企业属性分布统计'''
# req_dict = request.get_json()
# inid = req_dict.get("inid") # 二级行业id
# area = req_dict.get("area") # [省,市,区]
# province = area[0]
# city = area[1]
# district = area[2]
#
# # 校验参数完整性
# if not all([inid, area]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# try:
# edata = EvaluationData.query.filter_by(c_type=inid)
# if province and not city:
# edata = edata.filter_by(province=province).filter(EvaluationData.city.is_(None))
# if province and city and not district:
# edata = edata.filter_by(province=province, city=city).filter(EvaluationData.district.is_(None))
# if province and city and district:
# edata = edata.filter_by(province=province, city=city, district=district)
# edata = edata.first()
# if edata:
# data = {"development": edata.development, # 发育度
# "contribute": edata.contribute, # 贡献度
# "innovate": edata.innovate, # 创新力
# "growup": edata.growup, # 成长性
# "capital": edata.capital, # 资本力
# "general": edata.general} # 综合分
# return jsonify(code=RET.OK, msg="获取成功", data=data)
# else:
# data = {"development": 0,
# "contribute": 0,
# "innovate": 0,
# "growup": 0,
# "capital": 0,
# "general": 0}
# return jsonify(code=RET.NODATA, msg="无数据", data=data)
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库查询错误")
......@@ -2,8 +2,8 @@ from py2neo import Graph
def conn_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:7474", username="neo4j", password="123456") # 本地neo4j
# graph = Graph("http://localhost:7476", username="neo4j", password="123456") # 上传到50服务器前需更改
# graph = Graph("http://39.100.39.50:7476/", username="neo4j", password="123456") # 测试50服务器上的neo4j时使用
return graph
......
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