Commit c14ed130 by dong

fix20230105

parent 7cabc8a3
import time
import oss2
from flask import current_app, request, jsonify from flask import current_app, request, jsonify
from apps.manage import api_power from apps.manage import api_power
from apps.models import * from apps.models import *
...@@ -5,16 +8,38 @@ from apps.util import login_required, verify_btoken ...@@ -5,16 +8,38 @@ from apps.util import login_required, verify_btoken
from apps.utils.response_code import RET from apps.utils.response_code import RET
def upload_daily_picture(file_name, file):
try:
access_key_id = "LTAI4Fkgi7DUf6jCVW3KNGwT"
access_key_secret = "ynr6TWWNOnpALn3YUICUaXwpp9w4er"
auth = oss2.Auth(access_key_id, access_key_secret)
bucket_name = "zysf-store"
endpoint = "oss-cn-beijing.aliyuncs.com"
bucket = oss2.Bucket(auth, endpoint, bucket_name)
# file_name = file_name.split('.')
# time_stamp = '{0:%Y%m%d%H%M%S}'.format(datetime.now())
# file_name = file_name[0] + time_stamp + '.' + file_name[1]
# file_name = file_name[0] + '.' + file_name[1]
bucket.put_object('晋城招商图谱平台/产业大类图标/' + file_name, file)
icon_url = "https://{}.{}/{}".format(bucket_name, endpoint, '/晋城招商图谱平台/产业大类图标/' + file_name)
time.sleep(1)
return icon_url
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.THIRDERR, msg='第三方系统(阿里云oss存储)出错!')
# 产业名称列表 # 产业名称列表
@api_power.route('/listField', methods=['GET']) @api_power.route('/ChainList', methods=['GET'])
@login_required @login_required
def list_fields(): def chain_list():
try: try:
field = IndustryChain.query.filter_by(industry_type=0).all() field = IndustryChain.query.filter_by(industry_type=0).all()
data = [{"id": i.id, data = [{"id": i.id,
"name": i.industry_name, "name": i.industry_name,
"status": i.status, # 启用状态1启用,2禁用 "status": i.status, # 启用状态1启用,2禁用
# "cate": "一级产业" if i.fid == 0 else "二级产业" "icon": i.icon_url,
"icon1": i.icon_url1
} for i in field] } for i in field]
except Exception as e: except Exception as e:
current_app.logger.error(e) current_app.logger.error(e)
...@@ -22,34 +47,76 @@ def list_fields(): ...@@ -22,34 +47,76 @@ def list_fields():
return jsonify(code=RET.OK, msg="获取成功", data=data) return jsonify(code=RET.OK, msg="获取成功", data=data)
# 产业名称编辑 # 产业详情信息
@api_power.route('/modifyFields', methods=['POST']) @api_power.route('/ChainDetail', methods=['POST'])
@login_required @login_required
def modify_fields(): def chain_detail():
# req_dict = request.get_json() req_dict = request.get_json()
_id = request.get('id') # 行业id _id = req_dict.get('id') # 行业id
name = request.get("newname") # 行业新名字 try:
chain_obj = IndustryChain.query.get(_id)
data = {"id": chain_obj.id,
"name": chain_obj.industry_name,
"status": chain_obj.status, # 启用状态1启用,2禁用
"icon": chain_obj.icon_url,
"icon1": chain_obj.icon_url1
}
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据异常")
return jsonify(code=RET.OK, msg="获取成功", data=data)
# 产业名称新增或修改
@api_power.route('/AddEditChain', methods=['POST'])
@login_required
def add_edit_chain():
_id = request.form['id']
industry_name = request.form['industry_name']
icon_url = ''
icon_url1 = ''
try: try:
field = IndustryChain.query.get(_id) icon = request.files['icon']
field.industry_name = name file_name = icon.filename
db.session.commit() icon_url = upload_daily_picture(file_name, icon)
except Exception as e:
pass
try:
icon1 = request.files['icon1']
file_name1 = icon1.filename
icon_url1 = upload_daily_picture(file_name1, icon1)
except Exception as e:
pass
try:
chain_obj = IndustryChain.query.get(_id)
if chain_obj:
chain_obj.industry_name = industry_name
if icon_url:
chain_obj.icon_url = icon_url
if icon_url1:
chain_obj.icon_url1 = icon_url1
db.session.commit()
return jsonify(code=RET.OK, msg="修改成功")
else:
chain_obj = IndustryChain(industry_name=industry_name,
icon_url=icon_url,
icon_url1=icon_url1,
status=1,
industry_type=0)
db.session.add(chain_obj)
db.session.commit()
return jsonify(code=RET.OK, msg="新增成功")
except Exception as e: except Exception as e:
current_app.logger.error(e) current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据异常") return jsonify(code=RET.DBERR, msg="数据异常")
return jsonify(code=RET.OK, msg="修改成功")
# 产业状态修改 # 产业状态修改
@api_power.route('/fieldStatus', methods=['POST']) @api_power.route('/ChainStatus', methods=['POST'])
@login_required @login_required
def field_statu(): def chain_status():
# token = request.headers["token"]
# user = verify_btoken(token)
# user_role = user.role # 用户角色
# if user_role != 1:
# return jsonify(code=RET.ROLEERR, msg="暂无权限")
req_dict = request.get_json() req_dict = request.get_json()
_id = req_dict.get('id') # 行业id _id = req_dict.get('id') # 行业id
status = req_dict.get("status") # 状态值1启用,2禁用 status = req_dict.get("status") # 状态值1启用,2禁用
......
...@@ -514,6 +514,7 @@ class City(BaseModel, db.Model): ...@@ -514,6 +514,7 @@ class City(BaseModel, db.Model):
in_out = db.Column(db.Float, doc='进出口总额', comment='进出口总额') # 进出口总额 in_out = db.Column(db.Float, doc='进出口总额', comment='进出口总额') # 进出口总额
info = db.Column(db.Text, doc='基本信息', comment='基本信息') # 基本信息 info = db.Column(db.Text, doc='基本信息', comment='基本信息') # 基本信息
question = db.Column(db.Text, doc='标注', comment='标注') # 标注 question = db.Column(db.Text, doc='标注', comment='标注') # 标注
flag = db.Column(db.Integer, comment='数据标识 1整年数据,2阶段数据') # 人口
# 招商驾驶舱-各区县视频 # 招商驾驶舱-各区县视频
...@@ -1726,6 +1727,8 @@ class IndustryChain(db.Model): ...@@ -1726,6 +1727,8 @@ class IndustryChain(db.Model):
__table_args__ = ({'comment': '新版产业链数据数据表'}) # 添加表注释 __table_args__ = ({'comment': '新版产业链数据数据表'}) # 添加表注释
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键id') id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键id')
industry_name = db.Column(db.String(20), comment='行业名称') industry_name = db.Column(db.String(20), comment='行业名称')
icon_url = db.Column(db.String(255), comment='未选中时行业图标')
icon_url1 = db.Column(db.String(255), comment='选中时行业图标')
status = db.Column(db.Integer, doc='启用状态1启用,2禁用', comment='启用状态1启用,2禁用') # 启用状态1启用,2禁用 status = db.Column(db.Integer, doc='启用状态1启用,2禁用', comment='启用状态1启用,2禁用') # 启用状态1启用,2禁用
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(关联与哪个产业环节')
......
...@@ -76,32 +76,8 @@ def find_up_thr(name_query, relation): ...@@ -76,32 +76,8 @@ def find_up_thr(name_query, relation):
@api_atlas.route('/industry/cluster', methods=['GET']) @api_atlas.route('/industry/cluster', methods=['GET'])
def get_cluster(): def get_cluster():
try: try:
# cluster_obj = IndustryChain.query.filter_by(industry_type=0, cluster_obj = IndustryChain.query.filter_by(industry_type=0, status=1).all()
# status=1).all() data = [{"id": i.id, 'name': i.industry_name, "icon": i.icon_url, "icon1": i.icon_url1} for i in cluster_obj]
cluster_obj = Industry.query.all()
# data = {
# "cluster": [
# {"id": i.nid, 'industry_level': 1,
# 'name': i.name,
# "subNodeList": [
# {'id': j.nid,
# 'industry_level': 2,
# "name": j.name
# } for j in Industry.query.filter_by(fid=i.nid)
# ]} for i in cluster_obj]
# }
data = {
"cluster": [
{"id": i.nid, 'industry_level': 1,
'name': i.name,
"subNodeList": [
{'id': j.nid,
'industry_level': 2,
"name": j.name
} for j in Industry.query.filter_by(fid=i.nid)
]} for i in cluster_obj]
}
return jsonify(code=RET.OK, msg='产业集群名称获取成功!', data=data) return jsonify(code=RET.OK, msg='产业集群名称获取成功!', data=data)
except Exception as e: except Exception as e:
current_app.logger.error(e) current_app.logger.error(e)
......
...@@ -98,27 +98,27 @@ def data_notification(): ...@@ -98,27 +98,27 @@ def data_notification():
return jsonify(code=RET.DBERR, msg="数据库错误") return jsonify(code=RET.DBERR, msg="数据库错误")
def get_jjzb(district, year): def get_jjzb(district, flag):
'''经济指标数据''' '''经济指标数据'''
year1 = datetime.now().year - 1 # year1 = datetime.now().year - 1
year2 = datetime.now().year # year2 = datetime.now().year
#
years = '' # years = ''
if year == year1: # if year == year1:
years = str(year) + '年' # years = str(year) + '年'
if year == year2: # if year == year2:
month = datetime.now().month # month = datetime.now().month
if month == 1: # if month == 1:
years = str(year) + '年' + str(month) + '月' # years = str(year) + '年' + str(month) + '月'
else: # else:
years = str(year) + '年1-' + str(month) + '月' # years = str(year) + '年1-' + str(month) + '月'
# years = '2022年1-11月' # years = '2022年1-10月'
try: try:
if not district or district == '晋城市': if not district or district == '晋城市':
datas = City.query.filter_by(area='晋城市', year=year).first() datas = City.query.filter_by(area='晋城市', flag=flag).first()
else: else:
datas = City.query.filter_by(area=district, year=year).first() datas = City.query.filter_by(area=district, flag=flag).first()
df_dic = '' df_dic = ''
if datas: if datas:
df_dic = {"GDP": '%.2f亿元' % (datas.GDP / 10000) if datas.GDP else "-亿元", # 地区生产总值 df_dic = {"GDP": '%.2f亿元' % (datas.GDP / 10000) if datas.GDP else "-亿元", # 地区生产总值
...@@ -130,7 +130,7 @@ def get_jjzb(district, year): ...@@ -130,7 +130,7 @@ def get_jjzb(district, year):
"people_out": '%.2f元' % datas.people_out if datas.people_out else "-元", # 居民人均可支配收入 "people_out": '%.2f元' % datas.people_out if datas.people_out else "-元", # 居民人均可支配收入
"people_per": '%.2f' % datas.people_per if datas.people_per else "-", "people_per": '%.2f' % datas.people_per if datas.people_per else "-",
"question": datas.question, "question": datas.question,
"year": years "year": str(datas.year) + '年' if flag == 1 else datas.question
} # 居民消费价格指数 } # 居民消费价格指数
else: else:
df_dic = {"GDP": '', # 地区生产总值 df_dic = {"GDP": '', # 地区生产总值
...@@ -142,7 +142,7 @@ def get_jjzb(district, year): ...@@ -142,7 +142,7 @@ def get_jjzb(district, year):
"people_out": '', # 居民人均可支配收入 "people_out": '', # 居民人均可支配收入
"people_per": '', "people_per": '',
"question": '', "question": '',
"year": years "year": str(datas.year) + '年' if flag == 1 else datas.question
} # 居民消费价格指数 } # 居民消费价格指数
return df_dic return df_dic
except Exception as e: except Exception as e:
...@@ -188,7 +188,8 @@ def menu(): ...@@ -188,7 +188,8 @@ def menu():
t_c5 = company.filter_by(isfive="1").count() # 500强 t_c5 = company.filter_by(isfive="1").count() # 500强
ssqy = company.filter_by(quoted_company="1").count() # 上市 ssqy = company.filter_by(quoted_company="1").count() # 上市
if district != "晋城市": if district != "晋城市":
gmys = Company.query.filter(Company.induzone == district_dict[district]).filter_by( gmys = Company.query.filter(
Company.induzone == district_dict[district]).filter_by(
scale="1").count() # 规模(2-5) 622 scale="1").count() # 规模(2-5) 622
else: else:
gmys = Company.query.filter_by(scale="1").count() gmys = Company.query.filter_by(scale="1").count()
...@@ -214,10 +215,14 @@ def menu(): ...@@ -214,10 +215,14 @@ def menu():
} }
# 2. 左上角获取经济指标数据 # 2. 左上角获取经济指标数据
year = datetime.now().year - 1 # year = datetime.now().year - 1
jjzb_data = get_jjzb(district, year) # jjzb_data = get_jjzb(district, year)
year = datetime.now().year # year = datetime.now().year
jjzb_data1 = get_jjzb(district, year) # jjzb_data1 = get_jjzb(district, year)
jjzb_data = get_jjzb(district, 1)
jjzb_data1 = get_jjzb(district, 2)
# 3. 产业结构分布饼状图数据统计 # 3. 产业结构分布饼状图数据统计
count_all = company.count() count_all = company.count()
if count_all == 0: if count_all == 0:
......
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