Commit af71c51a by dong

fix20221229

parent 21c6e641
...@@ -1673,7 +1673,7 @@ def add_edit_money_arrive(): ...@@ -1673,7 +1673,7 @@ def add_edit_money_arrive():
current_app.logger.error(e) current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库异常,新增失败!") return jsonify(code=RET.DBERR, msg="数据库异常,新增失败!")
if not money_arrive_list: if not money_arrive_list:
return jsonify(code=RET.NODATA, msg='无有效数据!') return jsonify(code=RET.DBERR, msg='无有效数据!')
return jsonify(code=RET.OK, msg='新增成功!') return jsonify(code=RET.OK, msg='新增成功!')
......
...@@ -149,6 +149,7 @@ def get_data4(district_li, current_year): ...@@ -149,6 +149,7 @@ def get_data4(district_li, current_year):
for district in district_li: for district in district_li:
project_obj = MoneyArrive.query.filter( project_obj = MoneyArrive.query.filter(
MoneyArrive.data_time.like('%{}%'.format(str(current_year))), MoneyArrive.data_time.like('%{}%'.format(str(current_year))),
MoneyArrive.is_delete == 0,
MoneyArrive.district_name.like('%{}%'.format(str(district))) if district != '全市' else text('') MoneyArrive.district_name.like('%{}%'.format(str(district))) if district != '全市' else text('')
).first() ).first()
if not project_obj: if not project_obj:
...@@ -551,6 +552,7 @@ def export_jc_data1(data_time, path, pro_path): ...@@ -551,6 +552,7 @@ def export_jc_data1(data_time, path, pro_path):
# 固定资产投资项目资金到位额(亿元) # 固定资产投资项目资金到位额(亿元)
project_obj = MoneyArrive.query.filter( project_obj = MoneyArrive.query.filter(
MoneyArrive.data_time == data_time, MoneyArrive.data_time == data_time,
MoneyArrive.is_delete == 0,
MoneyArrive.district_name.like('%{}%'.format(str(district))) if district != '全市' else text('') MoneyArrive.district_name.like('%{}%'.format(str(district))) if district != '全市' else text('')
).first() ).first()
if not project_obj: if not project_obj:
...@@ -1302,12 +1304,13 @@ def get_data(): ...@@ -1302,12 +1304,13 @@ def get_data():
# 区县 # 区县
data.update({"district": district}) data.update({"district": district})
# 固定资产投资项目资金到位额(亿元) # 固定资产投资项目资金到位额(亿元)
money_obj_li = MoneyArrive.query.all() money_obj_li = MoneyArrive.query.filter_by(is_delete=0).all()
max_id = max([money_obj.id for money_obj in money_obj_li]) max_id = max([money_obj.id for money_obj in money_obj_li])
data_time_obj = MoneyArrive.query.get(max_id) data_time_obj = MoneyArrive.query.get(max_id)
data_time = data_time_obj.data_time data_time = data_time_obj.data_time
project_obj = MoneyArrive.query.filter( project_obj = MoneyArrive.query.filter(
MoneyArrive.data_time == data_time, MoneyArrive.data_time == data_time,
MoneyArrive.is_delete == 0,
MoneyArrive.district_name.like('%{}%'.format(str(district))) if district != '全市' else text('') MoneyArrive.district_name.like('%{}%'.format(str(district))) if district != '全市' else text('')
).first() ).first()
if not project_obj: if not project_obj:
......
import re # import re
from flask import request, jsonify, current_app # from flask import request, jsonify, current_app
from apps.manage import api_power # from apps.manage import api_power
from apps.models import * # from apps.models import *
from apps.util import login_required, verify_btoken # from apps.util import login_required, verify_btoken
from apps.utils.response_code import RET # from apps.utils.response_code import RET
#
#
# 新增角色 # # 新增角色
@api_power.route("/addRole", methods=["POST"]) # @api_power.route("/addRole", methods=["POST"])
@login_required # @login_required
def add_role(): # def add_role():
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # return jsonify(code=RET.ROLEERR, msg="暂无权限")
req_dict = request.get_json() # req_dict = request.get_json()
role_name = req_dict.get("role_name") # 职位名称(角色) # role_name = req_dict.get("role_name") # 职位名称(角色)
rolev = req_dict.get("rolev") # 权值 0层级123, 1调度,2审核,3删除,4审核/上报,5新增/编辑 ,300001" # rolev = req_dict.get("rolev") # 权值 0层级123, 1调度,2审核,3删除,4审核/上报,5新增/编辑 ,300001"
info = req_dict.get("info") # 职位功能(角色) # info = req_dict.get("info") # 职位功能(角色)
#
# 校验参数完整性 # # 校验参数完整性
if not all([role_name, rolev, info]): # if not all([role_name, rolev, info]):
return jsonify(code=RET.PARAMERR, msg="参数不完整") # return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
try: # try:
role = Role.query.filter_by(role_name=role_name).first() # role = Role.query.filter_by(role_name=role_name).first()
if role: # if role:
return jsonify(code=RET.DATAEXIST, msg="角色名已存在") # return jsonify(code=RET.DATAEXIST, msg="角色名已存在")
role = Role.query.filter_by(role=rolev).first() # role = Role.query.filter_by(role=rolev).first()
if role: # if role:
return jsonify(code=RET.DATAEXIST, msg="权限配置已存在,角色:{}".format(role.role_name)) # return jsonify(code=RET.DATAEXIST, msg="权限配置已存在,角色:{}".format(role.role_name))
#
role = Role(role_name=role_name, role=rolev, info=info) # role = Role(role_name=role_name, role=rolev, info=info)
db.session.add(role) # db.session.add(role)
db.session.commit() # db.session.commit()
return jsonify(code=RET.OK, msg="添加成功") # 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="数据库查询错误")
#
#
# 获取角色列表 # # 获取角色列表
@api_power.route("/roles", methods=["GET"]) # @api_power.route("/roles", methods=["GET"])
@login_required # @login_required
def roles(): # def roles():
try: # try:
roles = Role.query.all() # roles = Role.query.all()
data = [{"id": role.id, # data = [{"id": role.id,
"name": role.role_name, # "name": role.role_name,
"rolev": role.role, # "rolev": role.role,
"info": role.info} for role in roles] # "info": role.info} for role in roles]
#
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)
return jsonify(code=RET.DBERR, msg="数据库查询错误") # return jsonify(code=RET.DBERR, msg="数据库查询错误")
#
#
# 获取角色信息 # # 获取角色信息
@api_power.route("/getRole", methods=["POST"]) # @api_power.route("/getRole", methods=["POST"])
@login_required # @login_required
def roleinfo(): # def roleinfo():
req_dict = request.get_json() # req_dict = request.get_json()
_id = req_dict.get("id") # 角色id # _id = req_dict.get("id") # 角色id
# 校验参数完整性 # # 校验参数完整性
if not all([_id]): # if not all([_id]):
return jsonify(code=RET.PARAMERR, msg="参数不完整") # return jsonify(code=RET.PARAMERR, msg="参数不完整")
try: # try:
role = Role.query.get(_id) # role = Role.query.get(_id)
data = {"id": role.id, # data = {"id": role.id,
"name": role.role_name, # "name": role.role_name,
"rolev": role.role, # "rolev": role.role,
"info": role.info} # "info": role.info}
#
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)
return jsonify(code=RET.DBERR, msg="数据库查询错误") # return jsonify(code=RET.DBERR, msg="数据库查询错误")
#
#
# 角色编辑 # # 角色编辑
@api_power.route("/updateRole", methods=["POST"]) # @api_power.route("/updateRole", methods=["POST"])
@login_required # @login_required
def update_role(): # def update_role():
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # 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
role_name = req_dict.get("role_name") # 职位名称(角色) # role_name = req_dict.get("role_name") # 职位名称(角色)
rolev = req_dict.get("rolev") # 权值 1调度,2审核,3删除,4审核/上报,5新增/编辑 "00001" # rolev = req_dict.get("rolev") # 权值 1调度,2审核,3删除,4审核/上报,5新增/编辑 "00001"
info = req_dict.get("info") # 职位功能(角色) # info = req_dict.get("info") # 职位功能(角色)
#
# 校验参数完整性 # # 校验参数完整性
if not all([_id, role_name, rolev, info]): # if not all([_id, role_name, rolev, info]):
return jsonify(code=RET.PARAMERR, msg="参数不完整") # return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
try: # try:
me = Role.query.get(_id) # me = Role.query.get(_id)
if me.role_name != role_name: # if me.role_name != role_name:
role = Role.query.filter_by(role_name=role_name).first() # role = Role.query.filter_by(role_name=role_name).first()
if role: # if role:
return jsonify(code=RET.DATAEXIST, msg="角色名已存在") # return jsonify(code=RET.DATAEXIST, msg="角色名已存在")
if me.role != rolev: # if me.role != rolev:
role = Role.query.filter_by(role=rolev).first() # role = Role.query.filter_by(role=rolev).first()
if role: # if role:
return jsonify(code=RET.DATAEXIST, msg="权限配置已存在,角色:{}".format(role.role_name)) # return jsonify(code=RET.DATAEXIST, msg="权限配置已存在,角色:{}".format(role.role_name))
me.role_name = role_name # me.role_name = role_name
me.role = rolev # me.role = rolev
me.info = info # me.info = info
db.session.commit() # db.session.commit()
return jsonify(code=RET.OK, msg="添加成功") # 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="数据库查询错误")
#
#
# 删除角色 # # 删除角色
@api_power.route("/deleteRole", methods=["POST"]) # @api_power.route("/deleteRole", methods=["POST"])
@login_required # @login_required
def delete_role(): # def delete_role():
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # 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
#
# 校验参数完整性 # # 校验参数完整性
if not all([_id]): # if not all([_id]):
return jsonify(code=RET.PARAMERR, msg="参数不完整") # return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
try: # try:
me = Role.query.get(_id) # me = Role.query.get(_id)
if len(me.users) != 0: # if len(me.users) != 0:
return jsonify(code=RET.DATAEXIST, msg="当前角色存在用户使用,请查证并清除后再操作") # return jsonify(code=RET.DATAEXIST, msg="当前角色存在用户使用,请查证并清除后再操作")
db.session.delete(me) # db.session.delete(me)
db.session.commit() # db.session.commit()
return jsonify(code=RET.OK, msg="删除成功") # 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="数据库查询错误")
#
#
# 新添管理员账号 # # 新添管理员账号
@api_power.route("/addManager", methods=["POST"]) # @api_power.route("/addManager", methods=["POST"])
@login_required # @login_required
def add_manager(): # def add_manager():
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # return jsonify(code=RET.ROLEERR, msg="暂无权限")
req_dict = request.get_json() # req_dict = request.get_json()
account = req_dict.get("account") # 账户 # account = req_dict.get("account") # 账户
password = req_dict.get("password") # 密码 # password = req_dict.get("password") # 密码
role = req_dict.get("role") # 角色 1超级管理员,2系统运维员 # role = req_dict.get("role") # 角色 1超级管理员,2系统运维员
#
# 校验参数完整性 # # 校验参数完整性
if not all([account, password, role]): # if not all([account, password, role]):
return jsonify(code=RET.PARAMERR, msg="参数不完整") # return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# 用户名唯一(字母开头,长度4-15) # # 用户名唯一(字母开头,长度4-15)
try: # try:
patten = "^[a-zA-Z][\w]*[\w]*$" # patten = "^[a-zA-Z][\w]*[\w]*$"
if re.match(patten, account) and re.match(patten, account).string == account: # if re.match(patten, account) and re.match(patten, account).string == account:
user = Bstage.query.filter_by(name=account).first() # user = Bstage.query.filter_by(name=account).first()
if user: # if user:
return jsonify(code=RET.DATAEXIST, msg="用户名已存在") # return jsonify(code=RET.DATAEXIST, msg="用户名已存在")
else: # else:
return jsonify(code=RET.DATAERR, msg="用户名格式错误1") # return jsonify(code=RET.DATAERR, msg="用户名格式错误1")
except Exception as e: # except Exception as e:
current_app.logger.error(e) # current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="用户名格式错误2") # return jsonify(code=RET.DBERR, msg="用户名格式错误2")
#
try: # try:
me = Bstage(name=account, role=role) # me = Bstage(name=account, role=role)
me.password = password # me.password = password
db.session.add(me) # db.session.add(me)
db.session.commit() # db.session.commit()
return jsonify(code=RET.OK, msg="添加成功") # 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="数据库操作错误")
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 *
from apps.util import login_required, verify_btoken # from apps.util import login_required, verify_btoken
from apps.utils.response_code import RET # from apps.utils.response_code import RET
#
#
# 导航目录列表 # # 导航目录列表
@api_power.route('/listField', methods=['GET']) # @api_power.route('/listField', methods=['GET'])
@login_required # @login_required
def list_fields(): # def list_fields():
'''导航目录列表''' # '''导航目录列表'''
try: # try:
field = Industry.query.all() # field = Industry.query.all()
data = [{"id": i.id, # data = [{"id": i.id,
"name": i.name, # "name": i.name,
"statu": i.statu, # 启用状态1启用,2禁用 # "statu": i.statu, # 启用状态1启用,2禁用
"cate": "一级产业" if i.fid == 0 else "二级产业"} for i in field] # "cate": "一级产业" if i.fid == 0 else "二级产业"} for i in field]
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="获取成功", data=data) # return jsonify(code=RET.OK, msg="获取成功", data=data)
#
#
# 导航信息编辑 # # 导航信息编辑
@api_power.route('/modifyFields', methods=['POST']) # @api_power.route('/modifyFields', methods=['POST'])
@login_required # @login_required
def modify_fields(): # def modify_fields():
'''导航信息修改''' # '''导航信息修改'''
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # 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
name = req_dict.get("newname") # 行业新名字 # name = req_dict.get("newname") # 行业新名字
#
try: # try:
field = Industry.query.get(_id) # field = Industry.query.get(_id)
field.name = name # field.name = name
db.session.commit() # db.session.commit()
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="修改成功") # return jsonify(code=RET.OK, msg="修改成功")
#
#
# 导航状态修改 # # 导航状态修改
@api_power.route('/fieldStatu', methods=['POST']) # @api_power.route('/fieldStatu', methods=['POST'])
@login_required # @login_required
def field_statu(): # def field_statu():
'''导航信息修改''' # '''导航信息修改'''
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # 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
statu = req_dict.get("statu") # 状态值1启用,2禁用 # statu = req_dict.get("statu") # 状态值1启用,2禁用
#
try: # try:
field = Industry.query.get(_id) # field = Industry.query.get(_id)
if statu == 1: # if statu == 1:
field.statu = 2 # field.statu = 2
else: # else:
field.statu = 1 # field.statu = 1
db.session.commit() # db.session.commit()
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="修改成功") # return jsonify(code=RET.OK, msg="修改成功")
#
#
'''导航一''' # '''导航一'''
#
#
# 产业发展图谱目录列表 # # 产业发展图谱目录列表
@api_power.route('/listPropertyty', methods=['GET']) # @api_power.route('/listPropertyty', methods=['GET'])
@login_required # @login_required
def list_propertyty(): # def list_propertyty():
'''产业发展图谱目录列表''' # '''产业发展图谱目录列表'''
try: # try:
field = Propertyty.query.all() # field = Propertyty.query.all()
data = [{"id": i.id, # data = [{"id": i.id,
"name": i.name, # "name": i.name,
"statu": i.statu, # 状态 1启动,2禁用 # "statu": i.statu, # 状态 1启动,2禁用
"cate": "企业类型" if i.sid == 1 else "企业资质" if i.sid == 2 else "上市状态" if i.sid == 3 # "cate": "企业类型" if i.sid == 1 else "企业资质" if i.sid == 2 else "上市状态" if i.sid == 3
else "融资轮次"} for i in field] # else "融资轮次"} for i in field]
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="获取成功", data=data) # return jsonify(code=RET.OK, msg="获取成功", data=data)
#
#
# 产业发展图谱目录信息编辑 # # 产业发展图谱目录信息编辑
@api_power.route('/modifyPropertyty', methods=['POST']) # @api_power.route('/modifyPropertyty', methods=['POST'])
@login_required # @login_required
def modify_propertyty(): # def modify_propertyty():
'''产业发展图谱目录信息编辑''' # '''产业发展图谱目录信息编辑'''
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # 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
name = req_dict.get("newname") # 行业新名字 # name = req_dict.get("newname") # 行业新名字
#
try: # try:
propertyty = Propertyty.query.get(_id) # propertyty = Propertyty.query.get(_id)
propertyty.name = name # propertyty.name = name
db.session.commit() # db.session.commit()
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="修改成功") # return jsonify(code=RET.OK, msg="修改成功")
#
#
# 产业发展图谱导航状态修改 # # 产业发展图谱导航状态修改
@api_power.route('/propertytyStatu', methods=['POST']) # @api_power.route('/propertytyStatu', methods=['POST'])
@login_required # @login_required
def propertyty_statu(): # def propertyty_statu():
'''产业发展图谱导航状态修改''' # '''产业发展图谱导航状态修改'''
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # 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
statu = req_dict.get("statu") # 状态值1启用,2禁用 # statu = req_dict.get("statu") # 状态值1启用,2禁用
#
try: # try:
propertyty = Propertyty.query.get(_id) # propertyty = Propertyty.query.get(_id)
if statu == 1: # if statu == 1:
propertyty.statu = 2 # propertyty.statu = 2
else: # else:
propertyty.statu = 1 # propertyty.statu = 1
db.session.commit() # db.session.commit()
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="修改成功") # return jsonify(code=RET.OK, msg="修改成功")
#
#
'''导航二''' # '''导航二'''
#
#
# 产业招商地图360企业画像目录列表 # # 产业招商地图360企业画像目录列表
@api_power.route('/listProperty', methods=['GET']) # @api_power.route('/listProperty', methods=['GET'])
@login_required # @login_required
def list_property(): # def list_property():
'''产业发展图谱目录列表''' # '''产业发展图谱目录列表'''
try: # try:
propert = Property.query.all() # propert = Property.query.all()
data = [{"id": i.id, # data = [{"id": i.id,
"name": i.name, # "name": i.name,
"statu": i.statu, # 状态 1启动,2禁用 # "statu": i.statu, # 状态 1启动,2禁用
"cate": "企业类型" if i.sid == 1 else "企业资质" if i.sid == 2 else "上市状态" if i.sid == 3 # "cate": "企业类型" if i.sid == 1 else "企业资质" if i.sid == 2 else "上市状态" if i.sid == 3
else "融资轮次"} for i in propert] # else "融资轮次"} for i in propert]
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="获取成功", data=data) # return jsonify(code=RET.OK, msg="获取成功", data=data)
#
#
# 产业招商地图360企业画像目录信息编辑 # # 产业招商地图360企业画像目录信息编辑
@api_power.route('/modifyProperty', methods=['POST']) # @api_power.route('/modifyProperty', methods=['POST'])
@login_required # @login_required
def modify_property(): # def modify_property():
'''产业招商地图360企业画像目录信息编辑''' # '''产业招商地图360企业画像目录信息编辑'''
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # 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
name = req_dict.get("newname") # 行业新名字 # name = req_dict.get("newname") # 行业新名字
#
try: # try:
propert = Property.query.get(_id) # propert = Property.query.get(_id)
propert.name = name # propert.name = name
db.session.commit() # db.session.commit()
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="修改成功") # return jsonify(code=RET.OK, msg="修改成功")
#
#
# 产业招商地图360企业画像目录状态修改 # # 产业招商地图360企业画像目录状态修改
@api_power.route('/propertyStatu', methods=['POST']) # @api_power.route('/propertyStatu', methods=['POST'])
@login_required # @login_required
def property_statu(): # def property_statu():
'''产业招商地图360企业画像目录状态修改''' # '''产业招商地图360企业画像目录状态修改'''
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # 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
statu = req_dict.get("statu") # 状态值1启用,2禁用 # statu = req_dict.get("statu") # 状态值1启用,2禁用
#
try: # try:
propert = Property.query.get(_id) # propert = Property.query.get(_id)
if statu == 1: # if statu == 1:
propert.statu = 2 # propert.statu = 2
else: # else:
propert.statu = 1 # propert.statu = 1
db.session.commit() # db.session.commit()
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="修改成功") # return jsonify(code=RET.OK, msg="修改成功")
#
#
'''导航三''' # '''导航三'''
#
#
# 招商资源管理目录列表 # # 招商资源管理目录列表
@api_power.route('/listAttract', methods=['GET']) # @api_power.route('/listAttract', methods=['GET'])
@login_required # @login_required
def list_atract(): # def list_atract():
'''招商资源管理目录列表''' # '''招商资源管理目录列表'''
try: # try:
attract = Attract.query.all() # attract = Attract.query.all()
data = [{"id": i.id, # data = [{"id": i.id,
"name": i.name, # "name": i.name,
"statu": i.statu, # 状态 1启动,2禁用 # "statu": i.statu, # 状态 1启动,2禁用
"cate": "行业选择" if i.sid == 1 else "项目阶段" if i.sid == 2 else "项目级别"} for i in attract] # "cate": "行业选择" if i.sid == 1 else "项目阶段" if i.sid == 2 else "项目级别"} for i in attract]
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="获取成功", data=data) # return jsonify(code=RET.OK, msg="获取成功", data=data)
#
#
# 招商资源管理目录信息编辑 # # 招商资源管理目录信息编辑
@api_power.route('/modifyAttract', methods=['POST']) # @api_power.route('/modifyAttract', methods=['POST'])
@login_required # @login_required
def modify_attract(): # def modify_attract():
'''招商资源管理目录信息编辑''' # '''招商资源管理目录信息编辑'''
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # 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
name = req_dict.get("newname") # 行业新名字 # name = req_dict.get("newname") # 行业新名字
#
try: # try:
attract = Attract.query.get(_id) # attract = Attract.query.get(_id)
attract.name = name # attract.name = name
db.session.commit() # db.session.commit()
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="修改成功") # return jsonify(code=RET.OK, msg="修改成功")
#
#
# 招商资源管理目录状态修改 # # 招商资源管理目录状态修改
@api_power.route('/attractStatu', methods=['POST']) # @api_power.route('/attractStatu', methods=['POST'])
@login_required # @login_required
def attract_statu(): # def attract_statu():
'''产业发展图谱导航状态修改''' # '''产业发展图谱导航状态修改'''
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # 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
statu = req_dict.get("statu") # 状态值1启用,2禁用 # statu = req_dict.get("statu") # 状态值1启用,2禁用
#
try: # try:
attract = Attract.query.get(_id) # attract = Attract.query.get(_id)
if statu == 1: # if statu == 1:
attract.statu = 2 # attract.statu = 2
else: # else:
attract.statu = 1 # attract.statu = 1
db.session.commit() # db.session.commit()
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="修改成功") # return jsonify(code=RET.OK, msg="修改成功")
#
#
'''导航四''' # '''导航四'''
#
#
# 园区信息目录列表 # # 园区信息目录列表
@api_power.route('/listZone', methods=['GET']) # @api_power.route('/listZone', methods=['GET'])
@login_required # @login_required
def list_zone(): # def list_zone():
'''招商资源管理目录列表''' # '''招商资源管理目录列表'''
try: # try:
zone = Zone.query.all() # zone = Zone.query.all()
data = [{"id": i.id, # data = [{"id": i.id,
"name": i.name, # "name": i.name,
"statu": i.statu, # 状态 1启动,2禁用 # "statu": i.statu, # 状态 1启动,2禁用
"cate": "园区类别" if i.sid == 1 else "园区级别"} for i in zone] # "cate": "园区类别" if i.sid == 1 else "园区级别"} for i in zone]
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="获取成功", data=data) # return jsonify(code=RET.OK, msg="获取成功", data=data)
#
#
# 园区信息目录信息编辑 # # 园区信息目录信息编辑
@api_power.route('/modifyZone', methods=['POST']) # @api_power.route('/modifyZone', methods=['POST'])
@login_required # @login_required
def modify_zone(): # def modify_zone():
'''园区信息目录信息编辑''' # '''园区信息目录信息编辑'''
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # 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
name = req_dict.get("newname") # 行业新名字 # name = req_dict.get("newname") # 行业新名字
#
try: # try:
zone = Zone.query.get(_id) # zone = Zone.query.get(_id)
zone.name = name # zone.name = name
db.session.commit() # db.session.commit()
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="修改成功") # return jsonify(code=RET.OK, msg="修改成功")
#
#
# 园区信息目录状态修改 # # 园区信息目录状态修改
@api_power.route('/zoneStatu', methods=['POST']) # @api_power.route('/zoneStatu', methods=['POST'])
@login_required # @login_required
def zone_statu(): # def zone_statu():
'''园区信息目录状态修改''' # '''园区信息目录状态修改'''
token = request.headers["token"] # token = request.headers["token"]
user = verify_btoken(token) # user = verify_btoken(token)
user_role = user.role # 用户角色 # user_role = user.role # 用户角色
if user_role != 1: # if user_role != 1:
return jsonify(code=RET.ROLEERR, msg="暂无权限") # 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
statu = req_dict.get("statu") # 状态值1启用,2禁用 # statu = req_dict.get("statu") # 状态值1启用,2禁用
#
try: # try:
zone = Zone.query.get(_id) # zone = Zone.query.get(_id)
if statu == 1: # if statu == 1:
zone.statu = 2 # zone.statu = 2
else: # else:
zone.statu = 1 # zone.statu = 1
db.session.commit() # db.session.commit()
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="修改成功") # return jsonify(code=RET.OK, msg="修改成功")
import time # import time
from datetime import datetime # from datetime import datetime
#
from flask import request, jsonify, current_app, g # from flask import request, jsonify, current_app, g
from apps.manage import api_power # from apps.manage import api_power
from apps.models import * # from apps.models import *
from apps.utils.response_code import RET # from apps.utils.response_code import RET
from apps.util import login_required, verify_token # from apps.util import login_required, verify_token
#
#
# 新增机构组织 # # 新增机构组织
@api_power.route("/AddOrg", methods=["POST"]) # @api_power.route("/AddOrg", methods=["POST"])
@login_required
def add_org():
'''
不得重名
'''
token = request.headers["token"]
user = verify_token(token)
user_id = user.id
user_name = User.query.get(id=user_id).name
req_dict = request.get_json()
org_name = req_dict.get("name") # 机构名称
# forg = req_dict.get("forg") # 上级机构 id
charge = req_dict.get("charge") # 机构负责人
charge_phone = req_dict.get("charge_phone") # 负责人电话
# sublist = req_dict.get("sublist") # 统筹机构id list["1","2"...]
# 校验参数完整性
if not all([org_name]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
gover = GovOrganization.query.filter_by(name=org_name).first()
if gover: # 机构名相同,提示其错误
return jsonify(code=RET.DBERR, msg="机构名重复")
goverment = GovOrganization(name=org_name) # 创建机构
if charge:
goverment.charge = charge
if charge_phone:
goverment.charge_phone = charge_phone
if user_name:
goverment.add_person = user_name
add_time = datetime.now()
goverment.add_time = add_time
db.session.add(goverment) # 添加到数据库
# if forg: # 如果有上级机构,就让上级机构统筹新增机构
# fgover = Government.query.get(forg)
# fgover.followed.append(goverment)
# for ctr in sublist: # 如果有统筹机构,就让新增机构统筹
# sgover = Government.query.get(ctr)
# goverment.followed.append(sgover)
db.session.commit() # 提交数据库
return jsonify(code=RET.OK, msg="添加成功")
except Exception as e:
# 操作失败,回滚数据库
db.session.rollback()
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库操作错误")
# 查询添加过的机构信息
@api_power.route("/GetOrg", methods=["GET"])
@login_required
def get_org():
try:
org = GovOrganization.query.all()
data = [{"id": i.id, "name": i.name, "pnums": i.pnums,
"charge": i.charge, "charge_phone": i.charge_phone,
"add_person": i.add_person, "add_time": i.add_time,
"edit_person": i.edit_person, "edit_time": i.edit_time}
for i in org]
return jsonify(code=RET.OK, msg="查询成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 新增下级部门(ok)
@api_power.route("/AddSubDepartment", methods=["POST"])
@login_required
def add_sub_department():
token = request.headers["token"]
user = verify_token(token)
user_id = user.id
user_name = User.query.get(id=user_id).name
req_dict = request.get_json()
id = req_dict.get("id") # 当前机构或者部门id
# cate = req_dict.get("cate") # 分类标识,1机构,2部门
name = req_dict.get("name") # 部门或组名称
# pnums = req_dict.get("pnums") # 人数
charge = req_dict.get("charge") # 机构负责人
charge_phone = req_dict.get("charge_phone") # 负责人电话
# 校验参数完整性
# if not all([_id, cate, name]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
if not all([id, name]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
# if cate == 1: # 增加部门
sec = GovDepartment.query.filter_by(name=name, goverment_org_id=id).first()
if sec: # 一个机构下部门名不能重复
return jsonify(code=RET.DATAERR, msg="部门名重复")
gov_organization = GovOrganization.query.get(id)
gov_department = GovDepartment(name=name, goverment_org_id=id)
# if pnums:
# gov_department.pnums = pnums
if charge:
gov_department.charge = charge
if charge_phone:
gov_department.charge_phone = charge_phone
if user_name:
gov_department.add_person = user_name
add_time = datetime.now()
gov_department.add_time = add_time
db.session.add(gov_department) # 添加部门
gov_organization.government_departments.append(gov_department) # 外键关系添加
db.session.commit() # 数据库提交
# if cate == 2: # 增加组
# gro = Group.query.filter_by(name=name, gov_department_id=_id).first()
# if gro: # 一个部门下组名不能重复
# return jsonify(code=RET.DATAERR, msg="组名重复")
# gov_department = Section.query.get(_id)
# group = Group(name=name, section_id=_id)
# if pnums:
# group.pnums = pnums
# if charge:
# group.charge = charge
# if charge_phone:
# group.charge_phone = charge_phone
# db.session.add(group) # 添加组
# section.groups.append(group) # 添加关系
# db.session.commit() # 提交
# if cate == 3:
# return jsonify(code=RET.OK, msg="暂无下级机构,请勿继续添加")
return jsonify(code=RET.OK, msg="添加成功")
except Exception as e:
# 操作失败,数据回滚
db.session.rollback()
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库操作错误")
# 获取上级或下级统筹机构 (ok)
@api_power.route("/uadOrg", methods=["GET"])
@login_required
def uad_org():
try:
gover = Government.query.all()
data = [{"label": i.name, "value": i.id} for i in gover]
return jsonify(code=RET.OK, msg="查询成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 获取上级机构后的统筹机构 (ok)
@api_power.route("/downOrg", methods=["POST"])
@login_required
def down_org():
req_dict = request.get_json()
_id = req_dict.get("id") # 机构名称
try:
if _id:
gover = Government.query.all()
data = [{"label": i.name, "value": i.id} for i in gover if i.id != _id]
return jsonify(code=RET.OK, msg="查询成功", data=data)
else:
gover = Government.query.all()
data = [{"label": i.name, "value": i.id} for i in gover]
return jsonify(code=RET.OK, msg="查询成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 组织架构管理,获取机构单位数据(ok)
@api_power.route("/organization", methods=["POST"])
@login_required
def organization():
req_dict = request.get_json()
page = req_dict.get("page")
perpage = req_dict.get("perpage")
# 校验参数完整性
if not all([page, perpage]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
# goverment = Government.query.paginate(page, perpage).items
goverment = Government.query.all()
size = Government.query.count()
df = [{"id": gover.id,
"name": gover.name,
"pnums": gover.pnums if gover.pnums else 0,
"charge": gover.charge if gover.charge else "-",
"charge_phone": gover.charge_phone if gover.charge_phone else "-",
"cate": 1} for gover in goverment]
data = {"df": df, "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="数据库查询错误", data=[])
# 组织架构获取部门和组(Ok)
@api_power.route("/sectionGroup", methods=["POST"])
@login_required
def section_group():
req_dict = request.get_json()
_id = req_dict.get("id") # 当前机构或者部门的id
cate = req_dict.get("cate") # 分类标识,1机构,2部门
# 校验参数完整性
if not all([_id, cate]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
if cate == 1: # 查询当前机构下的部门
goverment = Government.query.get(_id)
sections = goverment.sections # 查询当前机构下的部门list
data = [{"id": sec.id,
"name": sec.name,
"pnums": sec.pnums if sec.pnums else 0,
"charge": sec.charge if sec.charge else "-",
"charge_phone": sec.charge_phone if sec.charge_phone else "-",
"cate": 2} for sec in sections]
return jsonify(code=RET.OK, msg="查找成功", data=data)
if cate == 2: # 查询当前部门下的组
section = Section.query.get(_id)
groups = section.groups # 查询当前部门下的组list
data = [{"id": group.id,
"name": group.name,
"pnums": group.pnums if group.pnums else 0,
"charge": group.charge if group.charge else "-",
"charge_phone": group.charge_phone if group.charge_phone else "-",
"cate": 3} for group in groups]
return jsonify(code=RET.OK, msg="查找成功", data=data)
return jsonify(code=RET.OK, msg="暂无下级信息", data=[])
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误", data=[])
# 删除组织机构或者部门和组(需要先删除人员)--------OK
@api_power.route("/deleteOrg", methods=["POST"])
@login_required
def deleteorg():
req_dict = request.get_json()
_id = req_dict.get("id") # 待删除的,部门、机构、组、id
cate = req_dict.get("cate") # 待删除数据的类别 1政府,2部门,3组
# 校验参数完整性
if not all([_id, cate]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
if cate == 1: # 删除机构
gover = Government.query.get(_id) # 当前机构对象
section = gover.sections # 当前机构下的部门对象列表
if len(section) > 0: # 有部门就需要先删除部门
return jsonify(code=RET.REQERR, msg="当前机构有部门存在,请清除后再操作")
unums = User.query.filter_by(unit=gover.name, status=1).count() # 当前机构下通过审核人员
if unums > 0: # 当前部门有人,先到机构详情,进行人员的删除
return jsonify(code=RET.REQERR, msg="当前机构有人员存在,请清除后再操作")
db.session.delete(gover) # 无人无部门,删除
db.session.commit() # 提交
return jsonify(code=RET.OK, msg="删除成功")
if cate == 2: # 删除部门
section = Section.query.get(_id)
gover = section.goverment # 部门所属的机构
group = section.groups # 当前部门的组对象list
if len(group) > 0: # 如果有组先删除组
return jsonify(code=RET.REQERR, msg="当前部门有组存在,请清除后再操作")
unums = User.query.filter_by(unit=gover.name, section=section.name, status=1).count() # # 已经通过审核的人数
if unums > 0: # 当前部门有人,先到部门详情,进行部门人员的删除
return jsonify(code=RET.REQERR, msg="当前部门有人员存在,请清除后再操作")
gover.sections.remove(section) # 当前部门没有人,没有组,删除部门之前需要先删除与之相关的机构关系
db.session.delete(section) # 删除
db.session.commit() # 提交
return jsonify(code=RET.OK, msg="删除成功")
if cate == 3: # 删除组
group = Group.query.get(_id) # 当前组信息
section = group.section # 组属于的部门,单个对象
gover = section.goverment # 部门属于的机构,单个对象
unums = User.query.filter_by(unit=gover.name, section=section.name, group=group.name,
status=1).count() # 已经通过审核的人数
if unums > 0: # 当前组有人,先到组详情,进行组员的删除
return jsonify(code=RET.REQERR, msg="当前组有人员存在,请清除后再操作")
section.groups.remove(group) # 当前组没有人,删除组之前需要先删除与之相关的部门关系
db.session.delete(group) # 删除
db.session.commit() # 提交
return jsonify(code=RET.OK, msg="删除成功")
else:
return jsonify(code=RET.DATAERR, msg="参数错误")
except Exception as e:
# 操作失败,回滚数据库
db.session.rollback()
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库操作失败")
''''''
# 获取机构,部门或者组详情()
@api_power.route("/orgDetail", methods=["POST"])
@login_required
def org_detail():
req_dict = request.get_json()
_id = req_dict.get("id") # id
cate = req_dict.get("cate") # 1机构,2部门,3组
# 校验参数完整性
if not all([_id, cate]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
if cate == 1: # 政府机构详情
goverment = Government.query.get(_id)
# 政府信息
data = {"id": goverment.id,
"name": goverment.name, # 机构名
"charge": goverment.charge if goverment.charge else "-", # 主管
"phone": goverment.charge_phone if goverment.charge_phone else "-", # 电话
"pnums": goverment.pnums if goverment.pnums else 0, # 机构人数
"secnums": len(goverment.sections), # 部门数
"func": goverment.function if goverment.function else "", # 政府职能
"cate": cate}
return jsonify(code=RET.OK, msg="查询成功", data=data)
if cate == 2: # 部门详情
section = Section.query.get(_id)
# 政府信息
data = {"id": section.id,
"name": section.name, # 机构名
"charge": section.charge if section.charge else "-", # 主管
"phone": section.charge_phone if section.charge_phone else "-", # 电话
"pnums": section.pnums if section.pnums else 0, # 机构人数
"secnums": len(section.groups), # 组数
"func": section.function if section.function else "", # 部门职能
"cate": cate}
return jsonify(code=RET.OK, msg="查询成功", data=data)
if cate == 3: # 组详情
group = Group.query.get(_id)
# 政府信息
data = {"id": group.id,
"name": group.name, # 机构名
"charge": group.charge if group.charge else "-", # 主管
"phone": group.charge_phone if group.charge_phone else "-", # 电话
"pnums": group.pnums if group.pnums else 0, # 机构人数
"secnums": "-",
"func": group.function if group.function else "", # 部门职能
"cate": cate}
return jsonify(code=RET.OK, msg="查询成功", data=data)
return jsonify(code=RET.OK, msg="参数错误")
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库操作错误")
# 编辑机构,部门或者组详情
@api_power.route("/editDetail", methods=["POST"])
@login_required
def edit_detail():
req_dict = request.get_json()
_id = req_dict.get("id") # 部门id
cate = req_dict.get("cate") # 1机构,2部门,3组
name = req_dict.get("name") # 1机构,2部门,3组 的名称
charge = req_dict.get("charge") # 局内领导
charge_phone = req_dict.get("charge_phone") # 联系方式
func = req_dict.get("func") # 部门职能
pnums = str(req_dict.get("pnums")) # 人数
secnums = str(req_dict.get("secnums")) # 部门组人数
# 校验参数完整性
if not all([_id, name, charge, charge_phone, pnums, secnums]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
if cate == 1: # 机构
gover = Government.query.filter_by(name=name).filter(Government.id != _id).first()
if gover:
return jsonify(code=RET.DBERR, msg="机构名不可重复")
gover = Government.query.get(_id)
gover.name = name
gover.charge = charge
gover.charge_phone = charge_phone
gover.function = func
gover.pnums = pnums
gover.secnums = secnums
db.session.commit()
return jsonify(code=RET.OK, msg="修改成功")
if cate == 2: # 部门
section = Section.query.get(_id) # 当前部门
gover_id = section.goverment_id # 当前部门的机构id
sec = Section.query.filter_by(name=name, goverment_id=gover_id).filter(Section.id != _id).first()
if sec: # 当前机构下此部门名已存在
return jsonify(code=RET.DBERR, msg="部门名不可重复")
section.name = name
section.charge = charge
section.charge_phone = charge_phone
section.function = func
section.pnums = pnums
section.secnums = secnums
db.session.commit()
return jsonify(code=RET.OK, msg="修改成功")
if cate == 3: # 组
group = Group.query.get(_id) # 当前组
sec_id = group.section_id # 当前组的部门id
gro = Group.query.filter_by(name=name, section_id=sec_id).filter(Group.id != _id).first()
if gro: # 当前部门下此组名已存在
return jsonify(code=RET.DBERR, msg="组名不可重复")
group.name = name
group.charge = charge
group.charge_phone = charge_phone
group.function = func
group.pnums = pnums
group.secnums = secnums
db.session.commit()
return jsonify(code=RET.OK, msg="修改成功")
return jsonify(code=RET.DATAERR, msg="cate参数错误")
except Exception as e:
# 操作失败,回滚数据库
db.session.rollback()
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库操作错误")
# 获取机构,部门或者组的人员
@api_power.route("/orgStaff", methods=["POST"])
@login_required
def org_staff():
req_dict = request.get_json()
_id = req_dict.get("id") # 部门id
cate = req_dict.get("cate") # 1机构,2部门,3组
# 校验参数完整性
if not all([_id, cate]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
if cate == 1: # 政府机构详情
goverment = Government.query.get(_id)
# 人员列表
staff = User.query.filter_by(status=1, unit=goverment.name).filter(
User.role_id.isnot(None)).all() # 通过审核的员工列表
staff = [{"id": i.id,
"name": i.real_name,
"position": i.position,
"section": i.section} for i in staff]
return jsonify(code=RET.OK, msg="查询成功", data=staff)
if cate == 2: # 部门详情
section = Section.query.get(_id)
# 人员列表
staff = User.query.filter_by(status=1, unit=section.goverment.name, section=section.name).filter(
User.role_id.isnot(None)).all() # 通过审核的员工列表
staff = [{"id": i.id,
"name": i.real_name,
"position": i.position,
"section": i.section} for i in staff]
return jsonify(code=RET.OK, msg="查询成功", data=staff)
if cate == 3: # 组详情
group = Group.query.get(_id)
# 人员列表
staff = User.query.filter_by(status=1, unit=group.section.goverment.name, section=group.section.name,
group=group.name).filter(User.role_id.isnot(None)).all() # 通过审核的员工列表
staff = [{"id": i.id,
"name": i.real_name,
"position": i.position,
"section": i.section} for i in staff]
return jsonify(code=RET.OK, msg="查询成功", data=staff)
else:
return jsonify(code=RET.OK, msg="参数错误")
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库操作错误")
# 机构部门或这组的待新增人员列表-------------------?
@api_power.route("/listOfStaff", methods=["POST"])
# @login_required # @login_required
def list_Staff(): # def add_org():
req_dict = request.get_json() # '''
_id = req_dict.get("id") # 当前机构id # 不得重名
cate = req_dict.get("cate") # 1机构 2部门 3组 # '''
# token = request.headers["token"]
# 校验参数完整性 # user = verify_token(token)
if not all([_id]): # user_id = user.id
return jsonify(code=RET.PARAMERR, msg="参数不完整") # user_name = User.query.get(id=user_id).name
try: # req_dict = request.get_json()
if cate == 1: # 政府 # org_name = req_dict.get("name") # 机构名称
gover = Government.query.get(_id) # # forg = req_dict.get("forg") # 上级机构 id
if gover: # charge = req_dict.get("charge") # 机构负责人
name = gover.name # charge_phone = req_dict.get("charge_phone") # 负责人电话
user = User.query.filter_by(unit=name).filter(User.role_id.isnot(None)).all() # # sublist = req_dict.get("sublist") # 统筹机构id list["1","2"...]
data = [{"id": i.id, #
"real_name": i.real_name if i.real_name else i.id} for i in user] # # 校验参数完整性
return jsonify(code=RET.OK, msg="查询成功", data=data) # if not all([org_name]):
else: # return jsonify(code=RET.PARAMERR, msg="参数不完整")
return jsonify(code=RET.DATAERR, msg="参数错误") # try:
if cate == 2: # 部门 # gover = GovOrganization.query.filter_by(name=org_name).first()
section = Section.query.get(_id) # if gover: # 机构名相同,提示其错误
if section: # return jsonify(code=RET.DBERR, msg="机构名重复")
gover = section.goverment #
user = User.query.filter_by(unit=gover.name).filter(User.role_id.isnot(None)).all() # goverment = GovOrganization(name=org_name) # 创建机构
data = [{"id": i.id, # if charge:
"real_name": i.real_name if i.real_name else i.id} for i in user] # goverment.charge = charge
return jsonify(code=RET.OK, msg="查询成功", data=data) # if charge_phone:
else: # goverment.charge_phone = charge_phone
return jsonify(code=RET.DATAERR, msg="参数错误") # if user_name:
if cate == 3: # 组 # goverment.add_person = user_name
group = Group.query.get(_id) # add_time = datetime.now()
if group: # goverment.add_time = add_time
section = group.section # db.session.add(goverment) # 添加到数据库
gover = section.goverment #
user = User.query.filter_by(unit=gover.name).filter(User.role_id.isnot(None)).all() # # if forg: # 如果有上级机构,就让上级机构统筹新增机构
data = [{"id": i.id, # # fgover = Government.query.get(forg)
"real_name": i.real_name if i.real_name else i.id} for i in user] # # fgover.followed.append(goverment)
return jsonify(code=RET.OK, msg="查询成功", data=data) # # for ctr in sublist: # 如果有统筹机构,就让新增机构统筹
else: # # sgover = Government.query.get(ctr)
return jsonify(code=RET.DATAERR, msg="参数错误") # # goverment.followed.append(sgover)
return jsonify(code=RET.DATAERR, msg="参数错误") # db.session.commit() # 提交数据库
except Exception as e: # return jsonify(code=RET.OK, msg="添加成功")
current_app.logger.error(e) # except Exception as e:
return jsonify(code=RET.DBERR, msg="数据库查询错误") # # 操作失败,回滚数据库
# db.session.rollback()
# current_app.logger.error(e)
# 机构部门或这组的人员 新增(人员部门调度) # return jsonify(code=RET.DBERR, msg="数据库操作错误")
@api_power.route("/addStaffOrg", methods=["POST"]) #
#
# # 查询添加过的机构信息
# @api_power.route("/GetOrg", methods=["GET"])
# @login_required # @login_required
def add_staff(): # def get_org():
req_dict = request.get_json() # try:
_id = req_dict.get("id") # 部门机构组id # org = GovOrganization.query.all()
cate = req_dict.get("cate") # 1政府,2部门,3组 # data = [{"id": i.id, "name": i.name, "pnums": i.pnums,
uid = req_dict.get("uid") # 员工id # "charge": i.charge, "charge_phone": i.charge_phone,
level = req_dict.get("level") # 职级(角色id) # "add_person": i.add_person, "add_time": i.add_time,
position = req_dict.get("position") # 职务,文本框随意填 # "edit_person": i.edit_person, "edit_time": i.edit_time}
# for i in org]
# 校验参数完整性 # return jsonify(code=RET.OK, msg="查询成功", data=data)
if not all([_id, level, position]): # except Exception as e:
return jsonify(code=RET.PARAMERR, msg="参数不完整") # current_app.logger.error(e)
try: # return jsonify(code=RET.DBERR, msg="数据库查询错误")
user = User.query.get(uid) #
if user: #
if cate == 1: # 政府机构 # # 新增下级部门(ok)
user.section = Government.query.get(_id).name # @api_power.route("/AddSubDepartment", methods=["POST"])
# 删除原有角色 # @login_required
role = Role.query.get(user.role_id) # def add_sub_department():
role.users.remove(user) # token = request.headers["token"]
# 添加新角色 # user = verify_token(token)
role = Role.query.get(level) # user_id = user.id
role.users.append(user) # user_name = User.query.get(id=user_id).name
# req_dict = request.get_json()
user.position = position # id = req_dict.get("id") # 当前机构或者部门id
db.session.commit() # # cate = req_dict.get("cate") # 分类标识,1机构,2部门
return jsonify(code=RET.OK, msg="添加成功") # name = req_dict.get("name") # 部门或组名称
if cate == 2: # 部门调度 # # pnums = req_dict.get("pnums") # 人数
user.section = Section.query.get(_id).name # charge = req_dict.get("charge") # 机构负责人
# 删除原有角色 # charge_phone = req_dict.get("charge_phone") # 负责人电话
role = Role.query.get(user.role_id) #
role.users.remove(user) # # 校验参数完整性
# 添加新角色 # # if not all([_id, cate, name]):
role = Role.query.get(level) # # return jsonify(code=RET.PARAMERR, msg="参数不完整")
role.users.append(user) # if not all([id, name]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
user.position = position #
db.session.commit() # try:
return jsonify(code=RET.OK, msg="添加成功") # # if cate == 1: # 增加部门
if cate == 3: # 组调度 # sec = GovDepartment.query.filter_by(name=name, goverment_org_id=id).first()
user.group = Group.query.get(_id).name # if sec: # 一个机构下部门名不能重复
# 删除原有角色 # return jsonify(code=RET.DATAERR, msg="部门名重复")
role = Role.query.get(user.role_id) # gov_organization = GovOrganization.query.get(id)
role.users.remove(user) # gov_department = GovDepartment(name=name, goverment_org_id=id)
# 添加新角色 # # if pnums:
role = Role.query.get(level) # # gov_department.pnums = pnums
role.users.append(user) # if charge:
# gov_department.charge = charge
user.position = position # if charge_phone:
db.session.commit() # gov_department.charge_phone = charge_phone
return jsonify(code=RET.OK, msg="添加成功") # if user_name:
# gov_department.add_person = user_name
return jsonify(code=RET.DATAERR, msg="参数错误") # add_time = datetime.now()
else: # gov_department.add_time = add_time
return jsonify(code=RET.DATAERR, msg="参数错误") # db.session.add(gov_department) # 添加部门
except Exception as e: # gov_organization.government_departments.append(gov_department) # 外键关系添加
# 操作失败,回滚数据库 # db.session.commit() # 数据库提交
db.session.rollback() # # if cate == 2: # 增加组
current_app.logger.error(e) # # gro = Group.query.filter_by(name=name, gov_department_id=_id).first()
return jsonify(code=RET.DBERR, msg="数据库操作错误") # # if gro: # 一个部门下组名不能重复
# # return jsonify(code=RET.DATAERR, msg="组名重复")
# # gov_department = Section.query.get(_id)
# # 测试 # # group = Group(name=name, section_id=_id)
# @api_power.route("/cs", methods=["get"]) # # if pnums:
# def ces(): # # group.pnums = pnums
# gover = Government.query.get(18) # # if charge:
# section = Section.query.get(37) # # group.charge = charge
# print(gover,section) # # if charge_phone:
# # section.goverment.remove(gover) # # group.charge_phone = charge_phone
# gover.sections.remove(section) # # db.session.add(group) # 添加组
# db.session.commit() # # section.groups.append(group) # 添加关系
# return "ok" # # db.session.commit() # 提交
'''''' # # if cate == 3:
# # return jsonify(code=RET.OK, msg="暂无下级机构,请勿继续添加")
# return jsonify(code=RET.OK, msg="添加成功")
# 机构部门或这组的人员 删除(人员失去组,机构项目) # except Exception as e:
@api_power.route("/deleteStaffOrg", methods=["POST"]) # # 操作失败,数据回滚
@login_required # db.session.rollback()
def delete_staff(): # current_app.logger.error(e)
req_dict = request.get_json() # return jsonify(code=RET.DBERR, msg="数据库操作错误")
uid = req_dict.get("uid") # 员工id #
cate = req_dict.get("cate") # 1政府,2部门,3组 #
_id = req_dict.get("id") # 机构部门组id #
# level = req_dict.get("level") # 职级 #
# position = req_dict.get("position") # 职务 # # 获取上级或下级统筹机构 (ok)
# @api_power.route("/uadOrg", methods=["GET"])
# 校验参数完整性 # @login_required
if not all([uid, cate, _id]): # def uad_org():
return jsonify(code=RET.PARAMERR, msg="参数不完整") # try:
try: # gover = Government.query.all()
user = User.query.get(uid) # data = [{"label": i.name, "value": i.id} for i in gover]
if user: # return jsonify(code=RET.OK, msg="查询成功", data=data)
if cate == 1: # 政府机构 # except Exception as e:
role = Role.query.get(user.role_id) # current_app.logger.error(e)
role.users.remove(user) # return jsonify(code=RET.DBERR, msg="数据库查询错误")
user.unit = "" # 机构 #
user.position = "" # 职位 #
user.section = "" # 部门 # # 获取上级机构后的统筹机构 (ok)
user.group = "" # 组 # @api_power.route("/downOrg", methods=["POST"])
user.level = "" # 级别 # @login_required
user.leader = "" # 领导者 # def down_org():
user.password = "" # 密码 # req_dict = request.get_json()
db.session.commit() # _id = req_dict.get("id") # 机构名称
return jsonify(code=RET.OK, msg="删除成功") # try:
if cate == 2: # 部们 # if _id:
role = Role.query.get(user.role_id) # gover = Government.query.all()
# user.role_id = "" # data = [{"label": i.name, "value": i.id} for i in gover if i.id != _id]
role.users.remove(user) # return jsonify(code=RET.OK, msg="查询成功", data=data)
user.position = "" # else:
user.section = "" # gover = Government.query.all()
user.group = "" # data = [{"label": i.name, "value": i.id} for i in gover]
user.level = "" # return jsonify(code=RET.OK, msg="查询成功", data=data)
# user.role_id = "" # except Exception as e:
db.session.commit() # current_app.logger.error(e)
return jsonify(code=RET.OK, msg="删除成功") # return jsonify(code=RET.DBERR, msg="数据库查询错误")
if cate == 3: # 组调度 #
user.group = "" #
db.session.commit() # # 组织架构管理,获取机构单位数据(ok)
return jsonify(code=RET.OK, msg="删除成功") # @api_power.route("/organization", methods=["POST"])
return jsonify(code=RET.DATAERR, msg="参数错误") # @login_required
else: # def organization():
return jsonify(code=RET.DATAERR, msg="参数错误") # req_dict = request.get_json()
except Exception as e: # page = req_dict.get("page")
# 操作失败,回滚数据库 # perpage = req_dict.get("perpage")
db.session.rollback() # # 校验参数完整性
current_app.logger.error(e) # if not all([page, perpage]):
return jsonify(code=RET.DBERR, msg="数据库操作错误") # return jsonify(code=RET.PARAMERR, msg="参数不完整")
# try:
# # goverment = Government.query.paginate(page, perpage).items
# 获取统筹机构列表 # goverment = Government.query.all()
@api_power.route("/orgCtrl", methods=["POST"]) # size = Government.query.count()
@login_required # df = [{"id": gover.id,
def org_ctrl(): # "name": gover.name,
req_dict = request.get_json() # "pnums": gover.pnums if gover.pnums else 0,
_id = req_dict.get("id") # 机构id # "charge": gover.charge if gover.charge else "-",
cate = req_dict.get("cate") # 1政府,2部门,3组 # "charge_phone": gover.charge_phone if gover.charge_phone else "-",
# "cate": 1} for gover in goverment]
# 校验参数完整性 # data = {"df": df, "size": size}
if not all([_id, cate]): # return jsonify(code=RET.OK, msg="查找成功", data=data)
return jsonify(code=RET.PARAMERR, msg="参数不完整") # except Exception as e:
try: # current_app.logger.error(e)
if cate == 1: # 政府机构详情 # return jsonify(code=RET.DBERR, msg="数据库查询错误", data=[])
goverment = Government.query.get(_id) #
# 统筹机构列表 #
ctrl = goverment.followed # # 组织架构获取部门和组(Ok)
bkpm = [{"id": j.id, # @api_power.route("/sectionGroup", methods=["POST"])
"name": j.name, # @login_required
"charge": j.charge if j.charge else "-", # def section_group():
"phone": j.charge_phone if j.charge_phone else "-"} for j in ctrl] # req_dict = request.get_json()
return jsonify(code=RET.OK, msg="查询成功", data=bkpm) # _id = req_dict.get("id") # 当前机构或者部门的id
# cate = req_dict.get("cate") # 分类标识,1机构,2部门
return jsonify(code=RET.OK, msg="参数错误") #
except Exception as e: # # 校验参数完整性
current_app.logger.error(e) # if not all([_id, cate]):
return jsonify(code=RET.DBERR, msg="数据库操作错误") # return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# try:
# 获取待新增统筹机构列表 # if cate == 1: # 查询当前机构下的部门
@api_power.route("/getCtrl", methods=["POST"]) # goverment = Government.query.get(_id)
@login_required # sections = goverment.sections # 查询当前机构下的部门list
def get_ctrl(): # data = [{"id": sec.id,
req_dict = request.get_json() # "name": sec.name,
_id = req_dict.get("id") # "pnums": sec.pnums if sec.pnums else 0,
# "charge": sec.charge if sec.charge else "-",
# 校验参数完整性 # "charge_phone": sec.charge_phone if sec.charge_phone else "-",
if not all([_id]): # "cate": 2} for sec in sections]
return jsonify(code=RET.PARAMERR, msg="参数不完整") # return jsonify(code=RET.OK, msg="查找成功", data=data)
try: # if cate == 2: # 查询当前部门下的组
goverment = Government.query.get(_id) # section = Section.query.get(_id)
folllowedids = {i.id for i in goverment.followed} # 已经被管制的 # groups = section.groups # 查询当前部门下的组list
folllowedids.add(_id) # 添加自己 # data = [{"id": group.id,
all_ids = {i.id for i in Government.query.filter_by().all()} # 全部机构id # "name": group.name,
options = list(all_ids - folllowedids) # 未被当前机构统筹的机构id列表 # "pnums": group.pnums if group.pnums else 0,
# "charge": group.charge if group.charge else "-",
goverments = Government.query.filter(Government.id.in_(options)).all() # "charge_phone": group.charge_phone if group.charge_phone else "-",
data = [{"id": i.id, # "cate": 3} for group in groups]
"name": i.name} for i in goverments] # return jsonify(code=RET.OK, msg="查找成功", data=data)
# return jsonify(code=RET.OK, msg="暂无下级信息", 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) # return jsonify(code=RET.DBERR, msg="数据库查询错误", data=[])
return jsonify(code=RET.DBERR, msg="添加失败") #
#
# # 删除组织机构或者部门和组(需要先删除人员)--------OK
# 机构详情页添加统筹机构 # @api_power.route("/deleteOrg", methods=["POST"])
@api_power.route("/addBeCtrl", methods=["POST"]) # @login_required
@login_required # def deleteorg():
def add_bectrl(): # req_dict = request.get_json()
req_dict = request.get_json() # _id = req_dict.get("id") # 待删除的,部门、机构、组、id
_id = req_dict.get("id") # cate = req_dict.get("cate") # 待删除数据的类别 1政府,2部门,3组
ids = req_dict.get("ids") #
# # 校验参数完整性
# 校验参数完整性 # if not all([_id, cate]):
if not all([_id, ids]): # return jsonify(code=RET.PARAMERR, msg="参数不完整")
return jsonify(code=RET.PARAMERR, msg="参数不完整") #
try: # try:
goverment = Government.query.get(_id) # if cate == 1: # 删除机构
folllowedids = {i.id for i in goverment.followed} # gover = Government.query.get(_id) # 当前机构对象
ids = set(ids) # section = gover.sections # 当前机构下的部门对象列表
for id in (ids - folllowedids): # if len(section) > 0: # 有部门就需要先删除部门
gover = Government.query.get(id) # return jsonify(code=RET.REQERR, msg="当前机构有部门存在,请清除后再操作")
goverment.followed.append(gover) # unums = User.query.filter_by(unit=gover.name, status=1).count() # 当前机构下通过审核人员
db.session.commit() # if unums > 0: # 当前部门有人,先到机构详情,进行人员的删除
return jsonify(code=RET.OK, msg="添加成功") # return jsonify(code=RET.REQERR, msg="当前机构有人员存在,请清除后再操作")
except Exception as e: # db.session.delete(gover) # 无人无部门,删除
# 操作失败,回滚数据库 # db.session.commit() # 提交
db.session.rollback() # return jsonify(code=RET.OK, msg="删除成功")
current_app.logger.error(e) # if cate == 2: # 删除部门
return jsonify(code=RET.DBERR, msg="添加失败") # section = Section.query.get(_id)
# gover = section.goverment # 部门所属的机构
# group = section.groups # 当前部门的组对象list
# 机构详情页删除统筹机构 # if len(group) > 0: # 如果有组先删除组
@api_power.route("/deleteCtrl", methods=["POST"]) # return jsonify(code=RET.REQERR, msg="当前部门有组存在,请清除后再操作")
@login_required # unums = User.query.filter_by(unit=gover.name, section=section.name, status=1).count() # # 已经通过审核的人数
def delete_bectrl(): # if unums > 0: # 当前部门有人,先到部门详情,进行部门人员的删除
req_dict = request.get_json() # return jsonify(code=RET.REQERR, msg="当前部门有人员存在,请清除后再操作")
_id = req_dict.get("id") # gover.sections.remove(section) # 当前部门没有人,没有组,删除部门之前需要先删除与之相关的机构关系
bectrl_id = req_dict.get("bectrl_id") # db.session.delete(section) # 删除
# db.session.commit() # 提交
# 校验参数完整性 # return jsonify(code=RET.OK, msg="删除成功")
if not all([_id, bectrl_id]): # if cate == 3: # 删除组
return jsonify(code=RET.PARAMERR, msg="参数不完整") # group = Group.query.get(_id) # 当前组信息
try: # section = group.section # 组属于的部门,单个对象
goverment = Government.query.get(_id) # gover = section.goverment # 部门属于的机构,单个对象
begoverment = Government.query.get(bectrl_id) # unums = User.query.filter_by(unit=gover.name, section=section.name, group=group.name,
goverment.followed.remove(begoverment) # status=1).count() # 已经通过审核的人数
db.session.commit() # if unums > 0: # 当前组有人,先到组详情,进行组员的删除
# return jsonify(code=RET.REQERR, msg="当前组有人员存在,请清除后再操作")
return jsonify(code=RET.OK, msg="删除成功") # section.groups.remove(group) # 当前组没有人,删除组之前需要先删除与之相关的部门关系
except Exception as e: # db.session.delete(group) # 删除
# 操作失败,回滚数据库 # db.session.commit() # 提交
db.session.rollback() # return jsonify(code=RET.OK, msg="删除成功")
current_app.logger.error(e) # else:
return jsonify(code=RET.DBERR, msg="数据库操作失败") # return jsonify(code=RET.DATAERR, msg="参数错误")
# except Exception as e:
# # 操作失败,回滚数据库
# db.session.rollback()
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库操作失败")
#
#
# ''''''
#
#
# # 获取机构,部门或者组详情()
# @api_power.route("/orgDetail", methods=["POST"])
# @login_required
# def org_detail():
# req_dict = request.get_json()
# _id = req_dict.get("id") # id
# cate = req_dict.get("cate") # 1机构,2部门,3组
#
# # 校验参数完整性
# if not all([_id, cate]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# try:
# if cate == 1: # 政府机构详情
# goverment = Government.query.get(_id)
# # 政府信息
# data = {"id": goverment.id,
# "name": goverment.name, # 机构名
# "charge": goverment.charge if goverment.charge else "-", # 主管
# "phone": goverment.charge_phone if goverment.charge_phone else "-", # 电话
# "pnums": goverment.pnums if goverment.pnums else 0, # 机构人数
# "secnums": len(goverment.sections), # 部门数
# "func": goverment.function if goverment.function else "", # 政府职能
# "cate": cate}
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# if cate == 2: # 部门详情
# section = Section.query.get(_id)
# # 政府信息
# data = {"id": section.id,
# "name": section.name, # 机构名
# "charge": section.charge if section.charge else "-", # 主管
# "phone": section.charge_phone if section.charge_phone else "-", # 电话
# "pnums": section.pnums if section.pnums else 0, # 机构人数
# "secnums": len(section.groups), # 组数
# "func": section.function if section.function else "", # 部门职能
# "cate": cate}
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# if cate == 3: # 组详情
# group = Group.query.get(_id)
# # 政府信息
# data = {"id": group.id,
# "name": group.name, # 机构名
# "charge": group.charge if group.charge else "-", # 主管
# "phone": group.charge_phone if group.charge_phone else "-", # 电话
# "pnums": group.pnums if group.pnums else 0, # 机构人数
# "secnums": "-",
# "func": group.function if group.function else "", # 部门职能
# "cate": cate}
# return jsonify(code=RET.OK, msg="查询成功", data=data)
#
# return jsonify(code=RET.OK, msg="参数错误")
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库操作错误")
#
#
# # 编辑机构,部门或者组详情
# @api_power.route("/editDetail", methods=["POST"])
# @login_required
# def edit_detail():
# req_dict = request.get_json()
# _id = req_dict.get("id") # 部门id
# cate = req_dict.get("cate") # 1机构,2部门,3组
# name = req_dict.get("name") # 1机构,2部门,3组 的名称
# charge = req_dict.get("charge") # 局内领导
# charge_phone = req_dict.get("charge_phone") # 联系方式
# func = req_dict.get("func") # 部门职能
# pnums = str(req_dict.get("pnums")) # 人数
# secnums = str(req_dict.get("secnums")) # 部门组人数
#
# # 校验参数完整性
# if not all([_id, name, charge, charge_phone, pnums, secnums]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# try:
# if cate == 1: # 机构
# gover = Government.query.filter_by(name=name).filter(Government.id != _id).first()
# if gover:
# return jsonify(code=RET.DBERR, msg="机构名不可重复")
# gover = Government.query.get(_id)
# gover.name = name
# gover.charge = charge
# gover.charge_phone = charge_phone
# gover.function = func
# gover.pnums = pnums
# gover.secnums = secnums
# db.session.commit()
# return jsonify(code=RET.OK, msg="修改成功")
# if cate == 2: # 部门
# section = Section.query.get(_id) # 当前部门
# gover_id = section.goverment_id # 当前部门的机构id
# sec = Section.query.filter_by(name=name, goverment_id=gover_id).filter(Section.id != _id).first()
# if sec: # 当前机构下此部门名已存在
# return jsonify(code=RET.DBERR, msg="部门名不可重复")
# section.name = name
# section.charge = charge
# section.charge_phone = charge_phone
# section.function = func
# section.pnums = pnums
# section.secnums = secnums
# db.session.commit()
# return jsonify(code=RET.OK, msg="修改成功")
# if cate == 3: # 组
# group = Group.query.get(_id) # 当前组
# sec_id = group.section_id # 当前组的部门id
# gro = Group.query.filter_by(name=name, section_id=sec_id).filter(Group.id != _id).first()
# if gro: # 当前部门下此组名已存在
# return jsonify(code=RET.DBERR, msg="组名不可重复")
# group.name = name
# group.charge = charge
# group.charge_phone = charge_phone
# group.function = func
# group.pnums = pnums
# group.secnums = secnums
# db.session.commit()
# return jsonify(code=RET.OK, msg="修改成功")
# return jsonify(code=RET.DATAERR, msg="cate参数错误")
# except Exception as e:
# # 操作失败,回滚数据库
# db.session.rollback()
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库操作错误")
#
#
# # 获取机构,部门或者组的人员
# @api_power.route("/orgStaff", methods=["POST"])
# @login_required
# def org_staff():
# req_dict = request.get_json()
# _id = req_dict.get("id") # 部门id
# cate = req_dict.get("cate") # 1机构,2部门,3组
#
# # 校验参数完整性
# if not all([_id, cate]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# try:
# if cate == 1: # 政府机构详情
# goverment = Government.query.get(_id)
# # 人员列表
# staff = User.query.filter_by(status=1, unit=goverment.name).filter(
# User.role_id.isnot(None)).all() # 通过审核的员工列表
# staff = [{"id": i.id,
# "name": i.real_name,
# "position": i.position,
# "section": i.section} for i in staff]
# return jsonify(code=RET.OK, msg="查询成功", data=staff)
# if cate == 2: # 部门详情
# section = Section.query.get(_id)
# # 人员列表
# staff = User.query.filter_by(status=1, unit=section.goverment.name, section=section.name).filter(
# User.role_id.isnot(None)).all() # 通过审核的员工列表
# staff = [{"id": i.id,
# "name": i.real_name,
# "position": i.position,
# "section": i.section} for i in staff]
# return jsonify(code=RET.OK, msg="查询成功", data=staff)
# if cate == 3: # 组详情
# group = Group.query.get(_id)
# # 人员列表
# staff = User.query.filter_by(status=1, unit=group.section.goverment.name, section=group.section.name,
# group=group.name).filter(User.role_id.isnot(None)).all() # 通过审核的员工列表
# staff = [{"id": i.id,
# "name": i.real_name,
# "position": i.position,
# "section": i.section} for i in staff]
# return jsonify(code=RET.OK, msg="查询成功", data=staff)
# else:
# return jsonify(code=RET.OK, msg="参数错误")
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库操作错误")
#
#
# # 机构部门或这组的待新增人员列表-------------------?
# @api_power.route("/listOfStaff", methods=["POST"])
# # @login_required
# def list_Staff():
# req_dict = request.get_json()
# _id = req_dict.get("id") # 当前机构id
# cate = req_dict.get("cate") # 1机构 2部门 3组
#
# # 校验参数完整性
# if not all([_id]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
# try:
# if cate == 1: # 政府
# gover = Government.query.get(_id)
# if gover:
# name = gover.name
# user = User.query.filter_by(unit=name).filter(User.role_id.isnot(None)).all()
# data = [{"id": i.id,
# "real_name": i.real_name if i.real_name else i.id} for i in user]
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# else:
# return jsonify(code=RET.DATAERR, msg="参数错误")
# if cate == 2: # 部门
# section = Section.query.get(_id)
# if section:
# gover = section.goverment
# user = User.query.filter_by(unit=gover.name).filter(User.role_id.isnot(None)).all()
# data = [{"id": i.id,
# "real_name": i.real_name if i.real_name else i.id} for i in user]
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# else:
# return jsonify(code=RET.DATAERR, msg="参数错误")
# if cate == 3: # 组
# group = Group.query.get(_id)
# if group:
# section = group.section
# gover = section.goverment
# user = User.query.filter_by(unit=gover.name).filter(User.role_id.isnot(None)).all()
# data = [{"id": i.id,
# "real_name": i.real_name if i.real_name else i.id} for i in user]
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# else:
# return jsonify(code=RET.DATAERR, msg="参数错误")
# return jsonify(code=RET.DATAERR, msg="参数错误")
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库查询错误")
#
#
# # 机构部门或这组的人员 新增(人员部门调度)
# @api_power.route("/addStaffOrg", methods=["POST"])
# # @login_required
# def add_staff():
# req_dict = request.get_json()
# _id = req_dict.get("id") # 部门机构组id
# cate = req_dict.get("cate") # 1政府,2部门,3组
# uid = req_dict.get("uid") # 员工id
# level = req_dict.get("level") # 职级(角色id)
# position = req_dict.get("position") # 职务,文本框随意填
#
# # 校验参数完整性
# if not all([_id, level, position]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
# try:
# user = User.query.get(uid)
# if user:
# if cate == 1: # 政府机构
# user.section = Government.query.get(_id).name
# # 删除原有角色
# role = Role.query.get(user.role_id)
# role.users.remove(user)
# # 添加新角色
# role = Role.query.get(level)
# role.users.append(user)
#
# user.position = position
# db.session.commit()
# return jsonify(code=RET.OK, msg="添加成功")
# if cate == 2: # 部门调度
# user.section = Section.query.get(_id).name
# # 删除原有角色
# role = Role.query.get(user.role_id)
# role.users.remove(user)
# # 添加新角色
# role = Role.query.get(level)
# role.users.append(user)
#
# user.position = position
# db.session.commit()
# return jsonify(code=RET.OK, msg="添加成功")
# if cate == 3: # 组调度
# user.group = Group.query.get(_id).name
# # 删除原有角色
# role = Role.query.get(user.role_id)
# role.users.remove(user)
# # 添加新角色
# role = Role.query.get(level)
# role.users.append(user)
#
# user.position = position
# db.session.commit()
# return jsonify(code=RET.OK, msg="添加成功")
#
# return jsonify(code=RET.DATAERR, msg="参数错误")
# else:
# return jsonify(code=RET.DATAERR, msg="参数错误")
# except Exception as e:
# # 操作失败,回滚数据库
# db.session.rollback()
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库操作错误")
#
#
# # # 测试
# # @api_power.route("/cs", methods=["get"])
# # def ces():
# # gover = Government.query.get(18)
# # section = Section.query.get(37)
# # print(gover,section)
# # # section.goverment.remove(gover)
# # gover.sections.remove(section)
# # db.session.commit()
# # return "ok"
# ''''''
#
#
# # 机构部门或这组的人员 删除(人员失去组,机构项目)
# @api_power.route("/deleteStaffOrg", methods=["POST"])
# @login_required
# def delete_staff():
# req_dict = request.get_json()
# uid = req_dict.get("uid") # 员工id
# cate = req_dict.get("cate") # 1政府,2部门,3组
# _id = req_dict.get("id") # 机构部门组id
# # level = req_dict.get("level") # 职级
# # position = req_dict.get("position") # 职务
#
# # 校验参数完整性
# if not all([uid, cate, _id]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
# try:
# user = User.query.get(uid)
# if user:
# if cate == 1: # 政府机构
# role = Role.query.get(user.role_id)
# role.users.remove(user)
# user.unit = "" # 机构
# user.position = "" # 职位
# user.section = "" # 部门
# user.group = "" # 组
# user.level = "" # 级别
# user.leader = "" # 领导者
# user.password = "" # 密码
# db.session.commit()
# return jsonify(code=RET.OK, msg="删除成功")
# if cate == 2: # 部们
# role = Role.query.get(user.role_id)
# # user.role_id = ""
# role.users.remove(user)
# user.position = ""
# user.section = ""
# user.group = ""
# user.level = ""
# # user.role_id = ""
# db.session.commit()
# return jsonify(code=RET.OK, msg="删除成功")
# if cate == 3: # 组调度
# user.group = ""
# db.session.commit()
# return jsonify(code=RET.OK, msg="删除成功")
# return jsonify(code=RET.DATAERR, msg="参数错误")
# else:
# return jsonify(code=RET.DATAERR, msg="参数错误")
# except Exception as e:
# # 操作失败,回滚数据库
# db.session.rollback()
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库操作错误")
#
#
# # 获取统筹机构列表
# @api_power.route("/orgCtrl", methods=["POST"])
# @login_required
# def org_ctrl():
# req_dict = request.get_json()
# _id = req_dict.get("id") # 机构id
# cate = req_dict.get("cate") # 1政府,2部门,3组
#
# # 校验参数完整性
# if not all([_id, cate]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
# try:
# if cate == 1: # 政府机构详情
# goverment = Government.query.get(_id)
# # 统筹机构列表
# ctrl = goverment.followed
# bkpm = [{"id": j.id,
# "name": j.name,
# "charge": j.charge if j.charge else "-",
# "phone": j.charge_phone if j.charge_phone else "-"} for j in ctrl]
# return jsonify(code=RET.OK, msg="查询成功", data=bkpm)
#
# return jsonify(code=RET.OK, msg="参数错误")
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库操作错误")
#
#
# # 获取待新增统筹机构列表
# @api_power.route("/getCtrl", methods=["POST"])
# @login_required
# def get_ctrl():
# req_dict = request.get_json()
# _id = req_dict.get("id")
#
# # 校验参数完整性
# if not all([_id]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
# try:
# goverment = Government.query.get(_id)
# folllowedids = {i.id for i in goverment.followed} # 已经被管制的
# folllowedids.add(_id) # 添加自己
# all_ids = {i.id for i in Government.query.filter_by().all()} # 全部机构id
# options = list(all_ids - folllowedids) # 未被当前机构统筹的机构id列表
#
# goverments = Government.query.filter(Government.id.in_(options)).all()
# data = [{"id": i.id,
# "name": i.name} for i in goverments]
#
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="添加失败")
#
#
# # 机构详情页添加统筹机构
# @api_power.route("/addBeCtrl", methods=["POST"])
# @login_required
# def add_bectrl():
# req_dict = request.get_json()
# _id = req_dict.get("id")
# ids = req_dict.get("ids")
#
# # 校验参数完整性
# if not all([_id, ids]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
# try:
# goverment = Government.query.get(_id)
# folllowedids = {i.id for i in goverment.followed}
# ids = set(ids)
# for id in (ids - folllowedids):
# gover = Government.query.get(id)
# goverment.followed.append(gover)
# db.session.commit()
# return jsonify(code=RET.OK, msg="添加成功")
# except Exception as e:
# # 操作失败,回滚数据库
# db.session.rollback()
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="添加失败")
#
#
# # 机构详情页删除统筹机构
# @api_power.route("/deleteCtrl", methods=["POST"])
# @login_required
# def delete_bectrl():
# req_dict = request.get_json()
# _id = req_dict.get("id")
# bectrl_id = req_dict.get("bectrl_id")
#
# # 校验参数完整性
# if not all([_id, bectrl_id]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
# try:
# goverment = Government.query.get(_id)
# begoverment = Government.query.get(bectrl_id)
# goverment.followed.remove(begoverment)
# db.session.commit()
#
# return jsonify(code=RET.OK, msg="删除成功")
# except Exception as e:
# # 操作失败,回滚数据库
# db.session.rollback()
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库操作失败")
...@@ -7,92 +7,10 @@ from apps.utils.response_code import RET ...@@ -7,92 +7,10 @@ from apps.utils.response_code import RET
from apps.util import login_required from apps.util import login_required
# 外部访客列表 """局内用户"""
@api_power.route("/userListOfExternal", methods=["POST"])
@login_required
def user_list_external():
req_dict = request.get_json()
page = req_dict.get("page")
perpage = req_dict.get("perpage")
# key = req_dict.get("key") # 查询条件
# 校验参数完整性
if not all([page, perpage]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
user = User.query.filter_by(flag=1)
result = user.paginate(page, perpage).items
size = user.count()
df = [{"id": i.id,
"real_name": i.real_name if i.real_name else "-",
"mobile": i.mobile if i.mobile else "-",
"create_time": str(i.create_time) if i.create_time else "-",
} for i in result]
data = {"df": df, "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_power.route("/updateStatus", methods=["POST"])
@login_required
def update_status():
req_dict = request.get_json()
_id = req_dict.get("id")
status = req_dict.get("status") # 0禁止,1在用
# 校验参数完整性
if not all([_id]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
user = User.query.get(_id)
if status == 1:
user.status = 1
else:
user.status = 0
db.session.commit()
return jsonify(code=RET.OK, msg="修改成功")
except Exception as e:
# 操作失败,操作返回
db.session.rollback()
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库操作错误")
# 局内用户筛选条件
@api_power.route("/manage/fields", methods=["GET"])
def manage_field():
''''''
try:
gover = Government.query.all()
data = {"status": [{"label": "通过", "value": 1}, {"label": "在审", "value": 2}, {"label": "驳回", "value": 3}],
"goverment": [{"label": i.name, "value": i.id} for i in gover]}
return jsonify(code=RET.OK, msg="查询成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库操作错误")
# 局内用户账号列表
# 局内用户筛选条件2, 根据机构获取部门
@api_power.route("/manage/fieldt", methods=["POST"])
def manage_fielt():
''''''
req_dict = request.get_json()
_id = req_dict.get("id") # 机构id
try:
gover = Government.query.get(_id)
section = gover.sections
data = [{"label": i.name, "value": i.id} for i in section]
return jsonify(code=RET.OK, msg="查询成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库操作错误")
# 局内用户列表
@api_power.route("/userListOfInside", methods=["POST"]) @api_power.route("/userListOfInside", methods=["POST"])
# @login_required # @login_required
def user_list_inside(): def user_list_inside():
...@@ -131,9 +49,10 @@ def user_list_inside(): ...@@ -131,9 +49,10 @@ def user_list_inside():
"position": i.position if i.position else "-", "position": i.position if i.position else "-",
"unit": i.belong_organization if i.belong_organization else "-", "unit": i.belong_organization if i.belong_organization else "-",
"section": i.belong_department if i.belong_department else "-", "section": i.belong_department if i.belong_department else "-",
"role": "部门负责人" if i.role_id == 1 else # "role": "部门负责人" if i.role_id == 1 else
"局领导" if i.role_id == 2 else # "局领导" if i.role_id == 2 else
"办事员工" if i.role_id == 3 else "-", # "办事员工" if i.role_id == 3 else "-",
"role": i.role
} for i in result] } for i in result]
data = {"df": df, "size": size} data = {"df": df, "size": size}
return jsonify(code=RET.OK, msg="查询成功", data=data) return jsonify(code=RET.OK, msg="查询成功", data=data)
...@@ -142,7 +61,7 @@ def user_list_inside(): ...@@ -142,7 +61,7 @@ def user_list_inside():
return jsonify(code=RET.DBERR, msg="数据库查询错误") return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 局内用户信息 # 局内用户---用户信息展示
@api_power.route("/userInsideInfo", methods=["POST"]) @api_power.route("/userInsideInfo", methods=["POST"])
@login_required @login_required
def user_inside_info(): def user_inside_info():
...@@ -155,9 +74,11 @@ def user_inside_info(): ...@@ -155,9 +74,11 @@ def user_inside_info():
data = {"id": i.id, data = {"id": i.id,
"real_name": i.real_name if i.real_name else "-", "real_name": i.real_name if i.real_name else "-",
"position": i.position if i.position else "-", "position": i.position if i.position else "-",
"role": "部门负责人" if i.role_id == 1 else # "role_id": i.role_id,
"局领导" if i.role_id == 2 else # "role": "部门负责人" if i.role_id == 1 else
"办事员工" if i.role_id == 3 else "-", # 角色 # "局领导" if i.role_id == 2 else
# "办事员工" if i.role_id == 3 else "-", # 角色
"role": i.role,
"unit": i.belong_organization, # 机构 "unit": i.belong_organization, # 机构
"section": i.belong_department, # 部门 "section": i.belong_department, # 部门
"mobile": i.mobile if i.mobile else "-" "mobile": i.mobile if i.mobile else "-"
...@@ -169,7 +90,33 @@ def user_inside_info(): ...@@ -169,7 +90,33 @@ def user_inside_info():
return jsonify(code=RET.DBERR, msg="数据库查询错误") return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 局内用户编辑 # 局内用户---用户账号状态编辑(通过,在审,驳回)
@api_power.route("/updateAccount", methods=["POST"])
@login_required
def update_account():
req_dict = request.get_json()
_id = req_dict.get("id")
status = req_dict.get("status") # 1通过,2在审,3驳回
# 校验参数完整性
if not all([_id, status]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
user = User.query.get(_id)
if not user.role and status == 1: # 没有角色,想通过
return jsonify(code=RET.DATAERR, msg="请先在编辑,为用户添加职级角色")
user.status = status
db.session.commit()
dict_zh = {1: "通过", 2: "在审", 3: "驳回"}
data = dict_zh[status]
return jsonify(code=RET.OK, msg="修改成功", info=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 局内用户---用户账号详情信息编辑
@api_power.route("/updateUser", methods=["POST"]) @api_power.route("/updateUser", methods=["POST"])
@login_required @login_required
def update_user(): def update_user():
...@@ -179,46 +126,29 @@ def update_user(): ...@@ -179,46 +126,29 @@ def update_user():
position = req_dict.get("position") # 职务 position = req_dict.get("position") # 职务
unit = req_dict.get("unit") # 机构 unit = req_dict.get("unit") # 机构
section = req_dict.get("section") # 部门 section = req_dict.get("section") # 部门
role_id = req_dict.get("role_id") # 角色id 必选 # role_id = req_dict.get("role_id") # 角色id 必选
role = req_dict.get("role") # 角色 超级管理员/管理员/开发人员/工作人员
mobile = req_dict.get("mobile") mobile = req_dict.get("mobile")
leader = req_dict.get("leader") # 领导
password = req_dict.get("password") password = req_dict.get("password")
password1 = req_dict.get("password1") password1 = req_dict.get("password1")
# 用户名唯一(字母开头,长度4-15)
# try:
# patten = "^[a-zA-Z][\w]*[\w]*$"
# if re.match(patten, name) and re.match(patten, name).string == name:
# user = User.query.filter_by(name=name).filter(User.id != _id).first()
# if user:
# return jsonify(code=RET.DATAEXIST, msg="用户名已存在")
# else:
# return jsonify(code=RET.DATAERR, msg="用户名格式错误")
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="用户名格式错误")
# 校验参数完整性 # 校验参数完整性
if not all([_id, real_name, position, role_id, leader, mobile]): if not all([_id, real_name, position, role, mobile]):
return jsonify(code=RET.PARAMERR, msg="请选择必填项") return jsonify(code=RET.PARAMERR, msg="请选择必填项")
try: try:
role = Role.query.get(role_id) # role_obj = Role.query.get(role_id)
user = User.query.get(_id) user = User.query.get(_id)
user.real_name = real_name if position:
user.position = position user.position = position
user.level = role.role_name
if unit: if unit:
user.unit = Government.query.get(unit).name user.unit = Government.query.get(unit).name
if section: if section:
user.section = Section.query.get(section).name user.section = Section.query.get(section).name
user.leader = leader if mobile:
user.mobile = mobile user.mobile = mobile
# user.sex = sex if real_name:
# user.age = age user.real_name = real_name
# if email:
# user.email = email
user.name = real_name
if password and not password1: if password and not password1:
return jsonify(code=RET.PARAMERR, msg="请填写确认密码!") return jsonify(code=RET.PARAMERR, msg="请填写确认密码!")
if password1 and not password: if password1 and not password:
...@@ -228,7 +158,7 @@ def update_user(): ...@@ -228,7 +158,7 @@ def update_user():
return jsonify(code=RET.PARAMERR, msg="密码和确认密码不一致!") return jsonify(code=RET.PARAMERR, msg="密码和确认密码不一致!")
user.password = password user.password = password
role.users.append(user) # role_obj.users.append(user)
db.session.commit() db.session.commit()
return jsonify(code=RET.OK, msg="修改成功") return jsonify(code=RET.OK, msg="修改成功")
except Exception as e: except Exception as e:
...@@ -244,33 +174,29 @@ def add_user(): ...@@ -244,33 +174,29 @@ def add_user():
real_name = req_dict.get("real_name") # 真实姓名 real_name = req_dict.get("real_name") # 真实姓名
position = req_dict.get("position") # 职务 position = req_dict.get("position") # 职务
level = req_dict.get("level") # 职级 id (角色id)
unit = req_dict.get("unit") # 机构id unit = req_dict.get("unit") # 机构id
section = req_dict.get("section") # 部门id section = req_dict.get("section") # 部门id
leader = req_dict.get("leader") # ? level = req_dict.get("level") # 角色
mobile = req_dict.get("mobile") mobile = req_dict.get("mobile") # 手机号
sex = req_dict.get("sex") # 1男2女 password = req_dict.get("password") # 密码
age = req_dict.get("age") password1 = req_dict.get("password1") # 确认密码
email = req_dict.get("email")
name = req_dict.get("name")
password = req_dict.get("password")
# 校验参数完整性 # 校验参数完整性
if not all([real_name, position, unit, mobile, sex, name, password]): if not all([real_name, position, unit, mobile, password]):
return jsonify(code=RET.PARAMERR, msg="参数不完整") return jsonify(code=RET.PARAMERR, msg="参数不完整")
# 用户名唯一(字母开头,长度4-15) # 用户名唯一(字母开头,长度4-15)
try: # try:
patten = "^[a-zA-Z][\w]*[\w]*$" # patten = "^[a-zA-Z][\w]*[\w]*$"
if re.match(patten, name) and re.match(patten, name).string == name: # if re.match(patten, name) and re.match(patten, name).string == name:
user = User.query.filter_by(name=name).first() # user = User.query.filter_by(name=name).first()
if user: # if user:
return jsonify(code=RET.DATAEXIST, msg="用户名已存在") # return jsonify(code=RET.DATAEXIST, msg="用户名已存在")
else: # else:
return jsonify(code=RET.DATAERR, msg="用户名格式错误,请填入以字母开头的数字和字母组合") # return jsonify(code=RET.DATAERR, 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="用户名格式错误")
# 判断手机号 # 判断手机号
try: try:
...@@ -284,16 +210,12 @@ def add_user(): ...@@ -284,16 +210,12 @@ def add_user():
try: try:
role = Role.query.get(level) role = Role.query.get(level)
govername = Government.query.get(unit) # 获取机构name govername = Government.query.get(unit) # 获取机构name
user = User(real_name=real_name, age=age, sex=sex, mobile=mobile, unit=govername.name, position=position, user = User(real_name=real_name, mobile=mobile, unit=govername.name, position=position,
name=name, flag=2, status=1, level=role.role_name) flag=2, status=1, level=role.role_name)
user.password = password user.password = password
if section: # 部门id if section: # 部门id
secname = Section.query.get(section).name # 获取部门名 secname = Section.query.get(section).name # 获取部门名
user.section = secname user.section = secname
if leader: # 领导
user.leader = leader
if email: # 邮箱
user.email = email
db.session.add(user) db.session.add(user)
role.users.append(user) role.users.append(user)
db.session.commit() db.session.commit()
...@@ -303,64 +225,163 @@ def add_user(): ...@@ -303,64 +225,163 @@ def add_user():
return jsonify(code=RET.DBERR, msg="数据库错误") return jsonify(code=RET.DBERR, msg="数据库错误")
# 编辑状态 """外部访客"""
@api_power.route("/updateAccount", methods=["POST"])
# 外部访客列表
@api_power.route("/userListOfExternal", methods=["POST"])
@login_required @login_required
def update_account(): def user_list_external():
req_dict = request.get_json() req_dict = request.get_json()
_id = req_dict.get("id") page = req_dict.get("page")
status = req_dict.get("status") # 1通过,2在审,3驳回 perpage = req_dict.get("perpage")
# key = req_dict.get("key") # 查询条件
# 校验参数完整性 # 校验参数完整性
if not all([_id, status]): if not all([page, perpage]):
return jsonify(code=RET.PARAMERR, msg="参数不完整") return jsonify(code=RET.PARAMERR, msg="参数不完整")
try: try:
user = User.query.get(_id) user = User.query.filter_by(flag=1)
if not user.role and status == 1: # 没有角色,想通过 result = user.paginate(page, perpage).items
return jsonify(code=RET.DATAERR, msg="请先在编辑,为用户添加职级角色") size = user.count()
df = [{"id": i.id,
user.status = status "real_name": i.real_name if i.real_name else "-",
db.session.commit() "mobile": i.mobile if i.mobile else "-",
dict_zh = {1: "通过", 2: "在审", 3: "驳回"} "create_time": str(i.create_time) if i.create_time else "-",
data = dict_zh[status] } for i in result]
return jsonify(code=RET.OK, msg="修改成功", info=data) data = {"df": df, "size": size}
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)
return jsonify(code=RET.DBERR, msg="数据库查询错误") return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 删除用户(批量删除,单个删除) # 外部访客状态修改(禁用、启用)
@api_power.route("/deleteUser", methods=["POST"]) @api_power.route("/updateStatus", methods=["POST"])
@login_required @login_required
def delete_user(): def update_status():
req_dict = request.get_json() req_dict = request.get_json()
ids = req_dict.get("id") # list[1,2,3] _id = req_dict.get("id")
status = req_dict.get("status") # 0禁止,1在用
# 校验参数完整性 # 校验参数完整性
if not all([ids]): if not all([_id]):
return jsonify(code=RET.PARAMERR, msg="参数不完整") return jsonify(code=RET.PARAMERR, msg="参数不完整")
try: try:
for i in ids: user = User.query.get(_id)
user = User.query.get(i) if status == 1:
db.session.delete(user) user.status = 1
else:
user.status = 0
db.session.commit() db.session.commit()
return jsonify(code=RET.OK, msg="删除成功") return jsonify(code=RET.OK, msg="修改成功")
except Exception as e: except Exception as e:
# 操作失败,操作返回
db.session.rollback() db.session.rollback()
current_app.logger.error(e) current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="删除失败") return jsonify(code=RET.DBERR, msg="数据库操作错误")
# 职级(角色)列表获取
@api_power.route("/getRole", methods=["GET"])
@login_required
def get_role():
try:
roles = Role.query.all()
data = [{"value": role.id,
"label": role.role_name} for role in roles]
return jsonify(code=RET.OK, msg="查询成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库操作错误")
# # 局内用户筛选条件
# @api_power.route("/manage/fields", methods=["GET"])
# def manage_field():
# ''''''
# try:
# gover = Government.query.all()
# data = {"status": [{"label": "通过", "value": 1}, {"label": "在审", "value": 2}, {"label": "驳回", "value": 3}],
# "goverment": [{"label": i.name, "value": i.id} for i in gover]}
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库操作错误")
#
#
# # 局内用户筛选条件2, 根据机构获取部门
# @api_power.route("/manage/fieldt", methods=["POST"])
# def manage_fielt():
# ''''''
# req_dict = request.get_json()
# _id = req_dict.get("id") # 机构id
# try:
# gover = Government.query.get(_id)
# section = gover.sections
# data = [{"label": i.name, "value": i.id} for i in section]
#
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库操作错误")
#
#
#
#
#
#
#
#
#
#
#
# # 删除用户(批量删除,单个删除)
# @api_power.route("/deleteUser", methods=["POST"])
# @login_required
# def delete_user():
# req_dict = request.get_json()
# ids = req_dict.get("id") # list[1,2,3]
#
# # 校验参数完整性
# if not all([ids]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
# try:
# for i in ids:
# user = User.query.get(i)
# db.session.delete(user)
# db.session.commit()
# return jsonify(code=RET.OK, msg="删除成功")
# except Exception as e:
# db.session.rollback()
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="删除失败")
#
#
# # 职级(角色)列表获取
# @api_power.route("/getRole", methods=["GET"])
# @login_required
# def get_role():
# try:
# roles = Role.query.all()
#
# data = [{"value": role.id,
# "label": role.role_name} for role in roles]
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库操作错误")
...@@ -17,6 +17,16 @@ class BaseModel: ...@@ -17,6 +17,16 @@ class BaseModel:
comment='更新时间') # 记录的更新时间 comment='更新时间') # 记录的更新时间
# 招商驾驶舱开工项目产业分布数据
class IndustryDistribute(db.Model):
__tablename_ = "industry_distribute"
__table_args__ = ({'comment': '招商驾驶舱开工项目产业分布数据'}) # 添加表注释
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键id')
industry_name = db.Column(db.String(20), comment='行业名称')
industry_num = db.Column(db.Integer, comment='个数')
investment_volume = db.Column(db.Float, comment='投资额(亿元)')
# 全国企业 # 全国企业
class Enterprise(db.Model): class Enterprise(db.Model):
__tablename__ = "enterprise" __tablename__ = "enterprise"
...@@ -909,43 +919,24 @@ class User(BaseModel, db.Model): ...@@ -909,43 +919,24 @@ class User(BaseModel, db.Model):
# 基本信息 # 基本信息
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='用户编号') id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='用户编号')
name = db.Column(db.String(32), unique=True, comment='用户名') name = db.Column(db.String(32), unique=True, comment='用户名')
role_id = db.Column(db.Integer, comment='角色id ')
password_hash = db.Column(db.String(128), comment='加密的密码') password_hash = db.Column(db.String(128), comment='加密的密码')
real_name = db.Column(db.String(32), comment='姓名') real_name = db.Column(db.String(32), comment='姓名')
age = db.Column(db.Integer, comment='年龄')
sex = db.Column(db.Integer, comment='性别,男1女2')
mobile = db.Column(db.String(11), unique=True, comment='手机号') mobile = db.Column(db.String(11), unique=True, comment='手机号')
email = db.Column(db.String(20), comment='邮箱')
# 个人中心的信息
function = db.Column(db.Text, comment='工作职能 ---个人中心')
flag = db.Column(db.Integer, comment='普通1,政府2') flag = db.Column(db.Integer, comment='普通1,政府2')
status = db.Column(db.Integer, comment='0禁止,1通过,2再审,3驳回') status = db.Column(db.Integer, comment='0禁止,1通过,2再审,3驳回')
# status = db.Column(db.Integer, comment='通过1,在审2,驳回3')
# bused = db.Column(db.Integer) # 账户有无组织
# 政府信息 # 政府信息
position = db.Column(db.String(30), comment='现任职务(职务)') position = db.Column(db.String(30), comment='职务')
belong_organization = db.Column(db.String(30), comment='现任工作机构、单位(政府机构,局)') belong_organization = db.Column(db.String(30), comment='单位')
is_organization_manager = db.Column(db.Integer, comment='是否是机构负责人') belong_department = db.Column(db.String(30), comment='部门')
charge_organization = db.Column(db.String(30), comment='是机构负责人的话,所负责的机构')
belong_department = db.Column(db.String(30), comment='所在部门(部门)')
is_department_manager = db.Column(db.Integer, comment='是否是部门负责人')
# charge_department = db.Column(db.String(30)) # 是部门负责人的话,所负责的部门
group = db.Column(db.String(30), comment='所在组') group = db.Column(db.String(30), comment='所在组')
level = db.Column(db.String(30), comment='职级(职级) 跟role_id对应')
leader = db.Column(db.String(32), comment='领导(直属领导)') leader = db.Column(db.String(32), comment='领导(直属领导)')
# 微信 # 三方登陆唯一标识
# 三方登陆唯一标识
# 微信
vxopenid = db.Column(db.String(128), unique=True, comment='微信openid') vxopenid = db.Column(db.String(128), unique=True, comment='微信openid')
vxunionid = db.Column(db.String(128), unique=True, comment='微信unionid') vxunionid = db.Column(db.String(128), unique=True, comment='微信unionid')
# 角色(职级配置) # 角色(职级配置)
role_id = db.Column(db.Integer, db.ForeignKey("role.id"), comment='角色id') # role_id = db.Column(db.Integer, db.ForeignKey("role.id"), comment='角色id')
role = db.relationship("Role", backref=db.backref("users")) # role = db.relationship("Role", backref=db.backref("users"))
# # 钉钉
# ddopenid = db.Column(db.String(128)) # 钉钉openid
# ddunionid = db.Column(db.String(128)) # 钉钉unionid
# dddingid = db.Column(db.String(128)) # 钉钉dingid
# 用户关注行业(图谱) # 用户关注行业(图谱)
industry = db.relationship("Industry", secondary="user_industry", backref=db.backref('bindustry')) industry = db.relationship("Industry", secondary="user_industry", backref=db.backref('bindustry'))
# 用户关注太原企业 # 用户关注太原企业
...@@ -1374,7 +1365,7 @@ class MoneyArrive(db.Model): ...@@ -1374,7 +1365,7 @@ class MoneyArrive(db.Model):
upload_unit = db.Column(db.String(30), comment='上传部门') upload_unit = db.Column(db.String(30), comment='上传部门')
upload_people = db.Column(db.String(30), comment='上传人') upload_people = db.Column(db.String(30), comment='上传人')
district_name = db.Column(db.String(30), comment='区县名称') district_name = db.Column(db.String(30), comment='区县名称')
arrive_money = db.Column(db.Float, comment='固定资产投资项目资金到位额') arrive_money = db.Column(db.Float, comment='固定资产投资项目资金到位额')
"""以下为202212月改版后需求""" """以下为202212月改版后需求"""
...@@ -1721,3 +1712,5 @@ class IndustryChain(db.Model): ...@@ -1721,3 +1712,5 @@ 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(关联与哪个产业环节')
...@@ -116,12 +116,12 @@ def show_all(): ...@@ -116,12 +116,12 @@ def show_all():
# carrier_obj = CarrierBuild.query.order_by(CarrierBuild.upload_time.desc()) # carrier_obj = CarrierBuild.query.order_by(CarrierBuild.upload_time.desc())
carrier_obj = '' carrier_obj = ''
if role_id == 1: # if role_id == 1:
carrier_obj = CarrierBuild.query.filter_by(CarrierBuild.upload_people_id == user_id) # carrier_obj = CarrierBuild.query.filter_by(CarrierBuild.upload_people_id == user_id)
if role_id == 2: # if role_id == 2:
carrier_obj = CarrierBuild.query.filter_by(CarrierBuild.upload_people_belong == belong_unit) # carrier_obj = CarrierBuild.query.filter_by(CarrierBuild.upload_people_belong == belong_unit)
if role_id == 3: # if role_id == 3:
carrier_obj = CarrierBuild.query.filter_by(CarrierBuild.audit_status == 1) # carrier_obj = CarrierBuild.query.filter_by(CarrierBuild.audit_status == 1)
carrier_obj = carrier_obj.order_by(CarrierBuild.upload_time.desc()) carrier_obj = carrier_obj.order_by(CarrierBuild.upload_time.desc())
carrier_obj_list = carrier_obj.paginate(page, per_page).items carrier_obj_list = carrier_obj.paginate(page, per_page).items
print(carrier_obj_list) print(carrier_obj_list)
...@@ -206,34 +206,34 @@ def show_all(): ...@@ -206,34 +206,34 @@ def show_all():
# 设置前端页面访问权限 # 设置前端页面访问权限
@api_address.route("/FontPermission", methods=["POST"]) # @api_address.route("/FontPermission", methods=["POST"])
def font_permission(): # def font_permission():
try: # try:
token = request.headers['token'] # token = request.headers['token']
user = verify_token(token) # user = verify_token(token)
user_id = user.id # user_id = user.id
except Exception as e: # except Exception as e:
current_app.logger.error(e) # current_app.logger.error(e)
return jsonify(code=RET.SESSIONERR, msg="token过期,请重新登录!") # return jsonify(code=RET.SESSIONERR, msg="token过期,请重新登录!")
if not all([user, user_id]): # if not all([user, user_id]):
return jsonify(code=RET.PARAMERR, msg="参数不能为空!") # return jsonify(code=RET.PARAMERR, msg="参数不能为空!")
#
try: # try:
user = User.query.get(user_id) # user = User.query.get(user_id)
result = user.role_id # result = user.role_id
print(result) # print(result)
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="数据库错误")
#
if int(result) == 1: # if int(result) == 1:
return jsonify(code=RET.OK, data={"role_id": result, "msg": " 我是局级领导(可以看到载体资源库所有页面,以及所有下级人员提交的内容)。"}) # return jsonify(code=RET.OK, data={"role_id": result, "msg": " 我是局级领导(可以看到载体资源库所有页面,以及所有下级人员提交的内容)。"})
if int(result) == 2: # if int(result) == 2:
return jsonify(code=RET.OK, data={"role_id": result, "msg": " 我是部长(可以看到载体资源库的数据填报页面,以及该部门所有办事员提交的内容。)。"}) # return jsonify(code=RET.OK, data={"role_id": result, "msg": " 我是部长(可以看到载体资源库的数据填报页面,以及该部门所有办事员提交的内容。)。"})
if int(result) == 3: # if int(result) == 3:
return jsonify(code=RET.OK, data={"role_id": result, "msg": " 我是办事员(可以看到载体资源库的数据填报页面,只能看到我自己提交的内容。)。"}) # return jsonify(code=RET.OK, data={"role_id": result, "msg": " 我是办事员(可以看到载体资源库的数据填报页面,只能看到我自己提交的内容。)。"})
else: # else:
return jsonify(code=RET.OK, data={"role_id": result, "msg": "无任何权限"}) # return jsonify(code=RET.OK, data={"role_id": result, "msg": "无任何权限"})
# 下载模板 # 下载模板
...@@ -1124,12 +1124,12 @@ def batch_audit(): ...@@ -1124,12 +1124,12 @@ def batch_audit():
current_app.logger.error(e) current_app.logger.error(e)
return jsonify(code=RET.SESSIONERR, msg="进行{}操作时用户信息校验失败,请重新登陆后尝试!".format(action_name)) return jsonify(code=RET.SESSIONERR, msg="进行{}操作时用户信息校验失败,请重新登陆后尝试!".format(action_name))
if role_id == 3: # 办事员没有审核功能 # if role_id == 3: # 办事员没有审核功能
return jsonify(code=RET.THIRDERR, msg="办事员没有审核功能。") # return jsonify(code=RET.THIRDERR, msg="办事员没有审核功能。")
if role_id == 2 and audit_flag == 3: # 市直部门各区县领导没有驳回权限 # if role_id == 2 and audit_flag == 3: # 市直部门各区县领导没有驳回权限
return jsonify(code=RET.THIRDERR, msg="市直部门各区县负责人没有驳回权限。") # return jsonify(code=RET.THIRDERR, msg="市直部门各区县负责人没有驳回权限。")
if role_id == 1 and audit_flag in [1, 2, 4]: # 局领导只能驳回 # if role_id == 1 and audit_flag in [1, 2, 4]: # 局领导只能驳回
return jsonify(code=RET.THIRDERR, msg="市直部门各区县领导局领导只有驳回权限。") # return jsonify(code=RET.THIRDERR, msg="市直部门各区县领导局领导只有驳回权限。")
audit_name = '' audit_name = ''
......
...@@ -20,6 +20,30 @@ from apps import db, constants, redis_store ...@@ -20,6 +20,30 @@ from apps import db, constants, redis_store
from apps.util import verify_token from apps.util import verify_token
# 招商驾驶舱开工项目产业分布数据
@api_attract.route("/IndustryDistribute", methods=["POST"])
def industry_distribute():
req_dic = request.get_json()
flag = req_dic['flag']
try:
indu_obj_list = IndustryDistribute.query.all()
if flag == 1:
data_dic = [{
"industry_name": i.industry_name,
"industry_num": i.industry_num,
} for i in indu_obj_list]
if flag == 2:
data_dic = [{
"industry_name": i.industry_name,
"investment_volume": i.investment_volume,
} for i in indu_obj_list]
return jsonify(code=RET.OK, data=data_dic, msg='查询成功!')
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
# 数据通报 # 数据通报
@api_attract.route("/DataNotification", methods=["GET"]) @api_attract.route("/DataNotification", methods=["GET"])
def data_notification(): def data_notification():
...@@ -979,7 +1003,6 @@ def enterprise_detail(): ...@@ -979,7 +1003,6 @@ def enterprise_detail():
return jsonify(code=RET.OK, msg="获取成功", data=data) return jsonify(code=RET.OK, msg="获取成功", data=data)
# # 删除缓存 # # 删除缓存
# @api_attract.route("/deleteX", methods=["GET"]) # @api_attract.route("/deleteX", methods=["GET"])
# def deleteX(): # def deleteX():
......
from flask import Blueprint # from flask import Blueprint
#
#
api_mobile = Blueprint("api_mobile", __name__) # api_mobile = Blueprint("api_mobile", __name__)
#
from . import view_atlas # from . import view_atlas
from . import view_user # from . import view_user
from . import mobile_attract # from . import mobile_attract
from . import mobile_360 # from . import mobile_360
from . import mobile_collect # from . import mobile_collect
from . import mobile_item # from . import mobile_item
from . import mobile_choose # from . import mobile_choose
from . import mobile_homepage # from . import mobile_homepage
import os # import os
import json # import json
from elasticsearch import Elasticsearch # from elasticsearch import Elasticsearch
from flask import request, jsonify, current_app # from flask import request, jsonify, current_app
from apps.models import * # from apps.models import *
from apps.view_mobile import api_mobile # from apps.view_mobile import api_mobile
from apps.util import login_required, verify_token # from apps.util import login_required, verify_token
from apps.utils.response_code import RET # from apps.utils.response_code import RET
#
#
def body_qualificat(s, j): # def body_qualificat(s, j):
body = { # body = {
"query": { # "query": {
"bool": { # "bool": {
"must": {"match": # "must": {"match":
{"{}": "{}".format(s, j)} # {"{}": "{}".format(s, j)}
} # }
} # }
} # }
} # }
return body # return body
#
#
def body_type(s): # def body_type(s):
body = { # body = {
"query": { # "query": {
"bool": { # "bool": {
"must": {"match": # "must": {"match":
{"entypeid": "{}".format(s)} # {"entypeid": "{}".format(s)}
} # }
} # }
} # }
} # }
return body # return body
#
#
def create_body(page, page_size, args_query, args_date, args_term): # def create_body(page, page_size, args_query, args_date, args_term):
''' # '''
#
:param page: # :param page:
:param page_size: # :param page_size:
:param args_query: # :param args_query:
:param args_date: # :param args_date:
:param args_term: # :param args_term:
:return: # :return:
''' # '''
#
body = { # body = {
"query": { # "query": {
"bool": { # "bool": {
"filter": { # "filter": {
"range": { # "range": {
"build_date": { # "build_date": {
} # }
} # }
}, # },
"must": [ # "must": [
{"multi_match": { # {"multi_match": {
"query": "{}".format(args_query["query"]), # "query": "{}".format(args_query["query"]),
"type": "best_fields", # "type": "best_fields",
"fields": [ # "fields": [
"product^1.0", # "product^1.0",
"company_name^1.0", # "company_name^1.0",
"industry^1.0" # "industry^1.0"
], # ],
"tie_breaker": 0.3 # "tie_breaker": 0.3
} # }
}, # },
] # ]
} # }
}, # },
"from": page, # "from": page,
"size": page_size, # "size": page_size,
"sort": [], # "sort": [],
"aggs": {}, # "aggs": {},
"_source": [ # "_source": [
# 'all_info', # # 'all_info',
'industry', 'build_date', 'register_money_nums', 'product', # 'industry', 'build_date', 'register_money_nums', 'product',
'company_name', "mysql_id" # 'company_name', "mysql_id"
], # ],
"highlight": { # "highlight": {
"fields": { # "fields": {
"product": {"type": "plain"}, # "product": {"type": "plain"},
"company_name": {"type": "plain"}, # "company_name": {"type": "plain"},
"industry": {"type": "plain"} # "industry": {"type": "plain"}
} # }
} # }
} # }
#
if args_date: # if args_date:
body["query"]["bool"]["filter"]["range"]["build_date"]["gte"] = args_date["build_date"][0] # body["query"]["bool"]["filter"]["range"]["build_date"]["gte"] = args_date["build_date"][0]
body["query"]["bool"]["filter"]["range"]["build_date"]["lte"] = args_date["build_date"][1] # body["query"]["bool"]["filter"]["range"]["build_date"]["lte"] = args_date["build_date"][1]
#
for k, v in args_term.items(): # for k, v in args_term.items():
body["query"]["bool"]["must"].append({"term": {"{}".format(k): "{}".format(v)}}) # body["query"]["bool"]["must"].append({"term": {"{}".format(k): "{}".format(v)}})
#
return body # return body
#
#
# 360企业画像两个静态表 # # 360企业画像两个静态表
#
def openDists(): # def openDists():
upload_path = os.path.dirname(os.path.dirname(__file__)) + "/utils/json/city.json" # upload_path = os.path.dirname(os.path.dirname(__file__)) + "/utils/json/city.json"
with open(upload_path, encoding="utf-8") as f: # with open(upload_path, encoding="utf-8") as f:
data = json.load(f) # data = json.load(f)
#
return data # return data
#
#
# 地域层级数据分级获取 # # 地域层级数据分级获取
@api_mobile.route('/mobileGetRegion', methods=['GET']) # @api_mobile.route('/mobileGetRegion', methods=['GET'])
def mobile_get_region(): # def mobile_get_region():
try: # try:
data = openDists() # data = openDists()
if len(data) > 0: # if len(data) > 0:
return jsonify(code=200, msg="查找成功", data=data) # return jsonify(code=200, msg="查找成功", data=data)
else: # else:
return jsonify(code=201, msg="暂时没有数据") # return jsonify(code=201, 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="查找错误")
#
#
@api_mobile.route('/mobileField', methods=['GET']) # @api_mobile.route('/mobileField', methods=['GET'])
# # @login_required
# def mobile_field():
# '''
# 全国企业条件选择导航获取
# :return:
# '''
# try:
# property = Property.query.filter_by(statu=1)
# typy = property.filter_by(sid=1, statu=1).all()
# qualificat = property.filter_by(sid=2, statu=1).all()
# quoted = property.filter_by(sid=3, statu=1).all()
# financ = property.filter_by(sid=4, statu=1).all()
# # options: [{ value: "选项1", label: "无数据" },{ value: "选项2", label: "3333" }],
# data = {"entype": [{"name": "请选择", "id": ""}] + [{"name": i.name, "id": i.nid} for i in typy],
# "qualificat": [{"name": "请选择", "id": ""}] + [{"name": i.name, "id": i.nid} for i in qualificat],
# "quoted": [{"name": "请选择", "id": ""}] + [{"name": i.name, "id": i.nid} for i in quoted],
# "financ": [{"name": "请选择", "id": ""}] + [{"name": i.name, "id": i.nid} for i in financ],
# "buildate": [{"name": "请选择", "id": ""}] + [{"name": "1-3年", "id": 1}, {"name": "3-5年", "id": 2},
# {"name": "5-8年", "id": 3}, {"name": "8-10年", "id": 4},
# {"name": "10-15年", "id": 5}, {"name": "15年以上", "id": 6}],
# "capital": [{"name": "请选择", "id": ""}] + [{"name": "100万以内", "id": 1}, {"name": "100万-500万", "id": 2},
# {"name": "500万-1000万", "id": 3},
# {"name": "1000万-5000万", "id": 4},
# {"name": "1000万-1亿", "id": 5}, {"name": "1亿以上", "id": 6}]
# }
#
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库查询错误")
# return jsonify(code=RET.OK, msg="获取成功", options=data)
#
#
# # 搜索接口
# @api_mobile.route("/mobileSearch", methods=["POST"])
# @login_required # @login_required
def mobile_field(): # def mobile_search():
''' # req_dict = request.get_json()
全国企业条件选择导航获取 #
:return: # token = request.headers["token"]
''' # user = verify_token(token)
try: # user_id = user.id
property = Property.query.filter_by(statu=1) # # ##es的查询,。。。。
typy = property.filter_by(sid=1, statu=1).all() # # user_id = 2
qualificat = property.filter_by(sid=2, statu=1).all() # qualificat = req_dict.get("qualificat")
quoted = property.filter_by(sid=3, statu=1).all() # entypeid = req_dict.get("entypeid")
financ = property.filter_by(sid=4, statu=1).all() # area = req_dict.get("area")
# options: [{ value: "选项1", label: "无数据" },{ value: "选项2", label: "3333" }], # province = None
data = {"entype": [{"name": "请选择", "id": ""}] + [{"name": i.name, "id": i.nid} for i in typy], # city = None
"qualificat": [{"name": "请选择", "id": ""}] + [{"name": i.name, "id": i.nid} for i in qualificat], # district = None
"quoted": [{"name": "请选择", "id": ""}] + [{"name": i.name, "id": i.nid} for i in quoted], # if area:
"financ": [{"name": "请选择", "id": ""}] + [{"name": i.name, "id": i.nid} for i in financ], # province = area[0]
"buildate": [{"name": "请选择", "id": ""}] + [{"name": "1-3年", "id": 1}, {"name": "3-5年", "id": 2}, # city = area[1]
{"name": "5-8年", "id": 3}, {"name": "8-10年", "id": 4}, # district = area[2]
{"name": "10-15年", "id": 5}, {"name": "15年以上", "id": 6}], # capital_id = req_dict.get("capital_id")
"capital": [{"name": "请选择", "id": ""}] + [{"name": "100万以内", "id": 1}, {"name": "100万-500万", "id": 2}, # public_id = req_dict.get("public_id")
{"name": "500万-1000万", "id": 3}, # financ_id = req_dict.get("financ_id")
{"name": "1000万-5000万", "id": 4}, # yearid = req_dict.get("yearid")
{"name": "1000万-1亿", "id": 5}, {"name": "1亿以上", "id": 6}] # print(yearid)
} # company = req_dict.get("company")
#
except Exception as e: # args_query = dict()
current_app.logger.error(e) # args_date = dict()
return jsonify(code=RET.DBERR, msg="数据库查询错误") # args_term = dict()
return jsonify(code=RET.OK, msg="获取成功", options=data) #
# # #每页个数
# per_page = req_dict.get("per_page")
# 搜索接口 # page = req_dict.get("page")
@api_mobile.route("/mobileSearch", methods=["POST"]) # if not req_dict.get("per_page"):
@login_required # per_page = 10
def mobile_search(): # per_page = int(per_page)
req_dict = request.get_json() # # 页数
# if not page:
token = request.headers["token"] # page = 1
user = verify_token(token) # page = int(page)
user_id = user.id # page = (page - 1) * per_page
# ##es的查询,。。。。 # args_query["query"] = "公司"
# user_id = 2 # # 搜索框
qualificat = req_dict.get("qualificat") # if company:
entypeid = req_dict.get("entypeid") # args_query["query"] = company
area = req_dict.get("area") #
province = None # try:
city = None # user = User.query.get(user_id)
district = None # b = []
if area: # if user.searchlist:
province = area[0] # for j in user.searchlist:
city = area[1] # b.append(j.history)
district = area[2] # if company in b:
capital_id = req_dict.get("capital_id") # user.searchlist.remove(user.searchlist[b.index(company)])
public_id = req_dict.get("public_id") # if len(b) > 5:
financ_id = req_dict.get("financ_id") # user.searchlist.remove(user.searchlist[0])
yearid = req_dict.get("yearid") # search = SearchList(history=company)
print(yearid) # db.session.add(search)
company = req_dict.get("company") # user.searchlist.append(search)
# db.session.commit()
args_query = dict() # except Exception as e:
args_date = dict() # db.session.rollback()
args_term = dict() # current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库错误")
# #每页个数 #
per_page = req_dict.get("per_page") # # 公司类型
page = req_dict.get("page") # if entypeid:
if not req_dict.get("per_page"): # args_term['entypeid'] = entypeid
per_page = 10 #
per_page = int(per_page) # # 注册资本
# 页数 # if capital_id:
if not page: # args_term['capital_id'] = capital_id
page = 1 #
page = int(page) # # 上市状态
page = (page - 1) * per_page # if public_id:
args_query["query"] = "公司" # args_term['public_id'] = public_id
# 搜索框 #
if company: # # 省
args_query["query"] = company # if province:
# args_term['province'] = province
try: #
user = User.query.get(user_id) # # 市
b = [] # if city:
if user.searchlist: # args_term['city'] = city
for j in user.searchlist: #
b.append(j.history) # # 区
if company in b: # if district:
user.searchlist.remove(user.searchlist[b.index(company)]) # args_term['district'] = district
if len(b) > 5: #
user.searchlist.remove(user.searchlist[0]) # # 公司资质
search = SearchList(history=company) # if qualificat:
db.session.add(search) #
user.searchlist.append(search) # if qualificat == 1:
db.session.commit() # args_term['high_new'] = 1
except Exception as e: #
db.session.rollback() # if qualificat == 2:
current_app.logger.error(e) # args_term['tbe'] = 1
return jsonify(code=RET.DBERR, msg="数据库错误") #
# if qualificat == 3:
# 公司类型 # args_term['quoted_company'] = 1
if entypeid: #
args_term['entypeid'] = entypeid # if qualificat == 4:
# args_term['isfive'] = 1
# 注册资本 #
if capital_id: # if qualificat == 5:
args_term['capital_id'] = capital_id # args_term['unicorn'] = 1
#
# 上市状态 # if qualificat == 6:
if public_id: # args_term['dengl'] = 1
args_term['public_id'] = public_id #
# # 成立时间
# 省 # if yearid:
if province: # args_term['yearid'] = yearid
args_term['province'] = province #
# if financ_id:
# 市 # args_term['financ_id'] = financ_id
if city: #
args_term['city'] = city # body = create_body(page, per_page, args_query, args_date, args_term)
# if not company:
# 区 # del body["query"]["bool"]["must"][0]
if district: #
args_term['district'] = district # try:
# es = Elasticsearch([{'host': '39.100.39.50', 'port': 9200}])
# 公司资质 #
if qualificat: # data = es.search(index="ty_360", body=body)
# data_list = []
if qualificat == 1: #
args_term['high_new'] = 1 # # 数据的列表添加进去
# for i in data["hits"]['hits']:
if qualificat == 2: #
args_term['tbe'] = 1 # if company:
# # 判断高亮,然后添加
if qualificat == 3: # data_list.append({
args_term['quoted_company'] = 1 # "company": i["highlight"]["company_name"][0] if "company_name" in i["highlight"] else i["_source"][
# "company_name"],
if qualificat == 4: # "product": i["highlight"]["product"][0] if "product" in i["highlight"] else i["_source"]["product"],
args_term['isfive'] = 1 # "industry": i["highlight"]["industry"][0] if "industry" in i["highlight"] else i["_source"][
# "industry"],
if qualificat == 5: # "money": "{}万元".format(i["_source"]["register_money_nums"]),
args_term['unicorn'] = 1 # "createtime": i["_source"]["build_date"],
# "id": i["_source"]["mysql_id"],
if qualificat == 6: # "choice": 2
args_term['dengl'] = 1 # })
# else:
# 成立时间 # data_list.append({
if yearid: # "company": i["_source"]["company_name"],
args_term['yearid'] = yearid # "product": i["_source"]["product"],
# "industry": i["_source"]["industry"],
if financ_id: # "money": "{}万元".format(i["_source"]["register_money_nums"]),
args_term['financ_id'] = financ_id # "createtime": i["_source"]["build_date"],
# "id": i["_source"]["mysql_id"],
body = create_body(page, per_page, args_query, args_date, args_term) # "choice": 2,
if not company: # })
del body["query"]["bool"]["must"][0] # except Exception as e:
# current_app.logger.error(e)
try: # return jsonify(code=RET.DBERR, msg="es数据库错误")
es = Elasticsearch([{'host': '39.100.39.50', 'port': 9200}]) # data = {
# "data": data_list
data = es.search(index="ty_360", body=body) # }
data_list = [] # return jsonify(code=RET.OK, msg="查找成功", data=data)
#
# 数据的列表添加进去 #
for i in data["hits"]['hits']: # # 搜索历史接口
# @api_mobile.route("/mobileSearchList", methods=["GET"])
if company: # @login_required
# 判断高亮,然后添加 # def mobile_search_list():
data_list.append({ # token = request.headers["token"]
"company": i["highlight"]["company_name"][0] if "company_name" in i["highlight"] else i["_source"][ # user = verify_token(token)
"company_name"], # user_id = user.id
"product": i["highlight"]["product"][0] if "product" in i["highlight"] else i["_source"]["product"], # # user_id = 2
"industry": i["highlight"]["industry"][0] if "industry" in i["highlight"] else i["_source"][ # try:
"industry"], # user = User.query.get(user_id)
"money": "{}万元".format(i["_source"]["register_money_nums"]), # data = {
"createtime": i["_source"]["build_date"], # "search": [i.history for i in user.searchlist]
"id": i["_source"]["mysql_id"], # }
"choice": 2 # data["search"] = data["search"][::-1]
}) # return jsonify(code=RET.OK, msg="查询成功", data=data)
else: # except Exception as e:
data_list.append({ # current_app.logger.error(e)
"company": i["_source"]["company_name"], # return jsonify(code=RET.DBERR, msg="数据库错误")
"product": i["_source"]["product"], #
"industry": i["_source"]["industry"], #
"money": "{}万元".format(i["_source"]["register_money_nums"]), # # 删除搜索历史接口
"createtime": i["_source"]["build_date"], # @api_mobile.route("/deleteSearchlist", methods=["GET"])
"id": i["_source"]["mysql_id"], # @login_required
"choice": 2, # def delete_search_list():
}) # token = request.headers["token"]
except Exception as e: # user = verify_token(token)
current_app.logger.error(e) # user_id = user.id
return jsonify(code=RET.DBERR, msg="es数据库错误") # # user_id = 2
data = { # try:
"data": data_list # user = User.query.get(user_id)
} # for i in user.searchlist:
return jsonify(code=RET.OK, msg="查找成功", data=data) # user.searchlist.remove(i)
# db.session.commit()
# return jsonify(code=RET.OK, msg="查询成功")
# 搜索历史接口 # except Exception as e:
@api_mobile.route("/mobileSearchList", methods=["GET"]) # db.session.rollback()
@login_required # current_app.logger.error(e)
def mobile_search_list(): # return jsonify(code=RET.DBERR, msg="数据库错误")
token = request.headers["token"]
user = verify_token(token)
user_id = user.id
# user_id = 2
try:
user = User.query.get(user_id)
data = {
"search": [i.history for i in user.searchlist]
}
data["search"] = data["search"][::-1]
return jsonify(code=RET.OK, msg="查询成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
# 删除搜索历史接口
@api_mobile.route("/deleteSearchlist", methods=["GET"])
@login_required
def delete_search_list():
token = request.headers["token"]
user = verify_token(token)
user_id = user.id
# user_id = 2
try:
user = User.query.get(user_id)
for i in user.searchlist:
user.searchlist.remove(i)
db.session.commit()
return jsonify(code=RET.OK, msg="查询成功")
except Exception as e:
db.session.rollback()
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
from flask import request, jsonify, session, current_app # from flask import request, jsonify, session, current_app
from sqlalchemy import func, desc, or_ # from sqlalchemy import func, desc, or_
from apps.models import * # from apps.models import *
from apps.view_mobile import api_mobile # from apps.view_mobile import api_mobile
from apps.utils.response_code import RET # from apps.utils.response_code import RET
#
#
@api_mobile.route("/attractMenu", methods=["POST"]) # @api_mobile.route("/attractMenu", methods=["POST"])
def attract_menu(): # def attract_menu():
req_dict = request.get_json() # req_dict = request.get_json()
district = req_dict.get("district") # district = req_dict.get("district")
print(district) # print(district)
if not district or district == "太原市": # if not district or district == "太原市":
district = None # district = None
#
if district == None: # if district == None:
#
try: # try:
company = Company.query.filter_by(city="太原市") # company = Company.query.filter_by(city="太原市")
data = City.query.filter_by().first() # data = City.query.filter_by().first()
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="数据库错误")
else: # else:
try: # try:
company = Company.query.filter(or_(Company.district == district, Company.induzone == district), # company = Company.query.filter(or_(Company.district == district, Company.induzone == district),
Company.city == "太原市") # Company.city == "太原市")
data = City.query.filter_by(area=district).first() # data = City.query.filter_by(area=district).first()
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="数据库错误")
#
try: # try:
count_all = company.count() # count_all = company.count()
#
zczb = db.session.query(func.sum(Company.capital_nums)).filter().all() # zczb = db.session.query(func.sum(Company.capital_nums)).filter().all()
t_c5 = company.filter_by(isfive="1").count() # t_c5 = company.filter_by(isfive="1").count()
ssqy = company.filter_by(quoted_company="1").count() # ssqy = company.filter_by(quoted_company="1").count()
gmys = company.filter_by(scale="1").count() # gmys = company.filter_by(scale="1").count()
zjtx = company.filter_by(zjtg="1").count() # zjtx = company.filter_by(zjtg="1").count()
gxjs = company.filter_by(high_new="1").count() # gxjs = company.filter_by(high_new="1").count()
kjzx = company.filter_by(tbe="1").count() # kjzx = company.filter_by(tbe="1").count()
#
zczb = zczb[0][0] # zczb = zczb[0][0]
college = College.query.filter_by() # college = College.query.filter_by()
scientific = Scientific.query.filter_by().count() # scientific = Scientific.query.filter_by().count()
lab = Lab.query.filter_by().count() # lab = Lab.query.filter_by().count()
college_211 = college.filter_by(cateid=1).count() # college_211 = college.filter_by(cateid=1).count()
college_master = college.filter_by(cateid=2).count() # college_master = college.filter_by(cateid=2).count()
college_associate = college.filter_by(cateid=3).count() # college_associate = college.filter_by(cateid=3).count()
#
if district: # if district:
zczb = db.session.query(func.sum(Company.capital_nums)). \ # zczb = db.session.query(func.sum(Company.capital_nums)). \
filter(or_(Company.district == district, Company.induzone == district)).all() # filter(or_(Company.district == district, Company.induzone == district)).all()
zczb = zczb[0][0] # zczb = zczb[0][0]
# print(zczb) # # print(zczb)
college = College.query.filter(or_(College.admin == district, College.developarea == district)) # college = College.query.filter(or_(College.admin == district, College.developarea == district))
scientific = Scientific.query.filter( # scientific = Scientific.query.filter(
or_(Scientific.admin == district, Scientific.developarea == district)).count() # or_(Scientific.admin == district, Scientific.developarea == district)).count()
lab = Lab.query.filter(or_(Lab.admin == district, Lab.developarea == district)).count() # lab = Lab.query.filter(or_(Lab.admin == district, Lab.developarea == district)).count()
college_211 = college.filter_by(cateid=1).count() # college_211 = college.filter_by(cateid=1).count()
college_master = college.filter_by(cateid=2).count() # college_master = college.filter_by(cateid=2).count()
college_associate = college.filter_by(cateid=3).count() # college_associate = college.filter_by(cateid=3).count()
#
table_data = [ # table_data = [
{"name": "优质企业", "nums": count_all}, # {"name": "优质企业", "nums": count_all},
{"name": "注册资本", "nums": "{}亿元".format(round(zczb / 10000, 2)) if zczb else "-"}, # {"name": "注册资本", "nums": "{}亿元".format(round(zczb / 10000, 2)) if zczb else "-"},
{"name": "500强企业", "nums": t_c5}, # {"name": "500强企业", "nums": t_c5},
{"name": "上市企业", "nums": ssqy}, # {"name": "上市企业", "nums": ssqy},
{"name": "规模以上企业", "nums": gmys}, # {"name": "规模以上企业", "nums": gmys},
{"name": "山西专精特新企业数", "nums": zjtx}, # {"name": "山西专精特新企业数", "nums": zjtx},
{"name": "高新技术企业", "nums": gxjs}, # {"name": "高新技术企业", "nums": gxjs},
{"name": "科技型中小企业数", "nums": kjzx}, # {"name": "科技型中小企业数", "nums": kjzx},
{"name": "高等院校", "nums": college_master + college_211}, # {"name": "高等院校", "nums": college_master + college_211},
{"name": "高职专科", "nums": college_associate}, # {"name": "高职专科", "nums": college_associate},
{"name": "科研机构", "nums": scientific}, # {"name": "科研机构", "nums": scientific},
{"name": "创新平台", "nums": lab} # {"name": "创新平台", "nums": lab}
] # ]
#
city_data = [ # city_data = [
{"nums": "{}亿元".format(round(data.GDP / 10000, 2)) if data.GDP else "-", "name": "GDP"}, # {"nums": "{}亿元".format(round(data.GDP / 10000, 2)) if data.GDP else "-", "name": "GDP"},
{"nums": "{}亿元".format(round(data.investment / 10000, 2)) if data.investment else "-", "name": "固定资产投资"}, # {"nums": "{}亿元".format(round(data.investment / 10000, 2)) if data.investment else "-", "name": "固定资产投资"},
{"nums": "{}亿元".format(round(data.retail / 10000, 2)) if data.retail else "-", "name": "社会消费零售额"}, # {"nums": "{}亿元".format(round(data.retail / 10000, 2)) if data.retail else "-", "name": "社会消费零售额"},
{"nums": "{}亿元".format(round(data.public / 10000, 2)) if data.public else "-", "name": "一般公共预算支出"} # {"nums": "{}亿元".format(round(data.public / 10000, 2)) if data.public else "-", "name": "一般公共预算支出"}
] # ]
#
data = { # data = {
"table_data": table_data, # "table_data": table_data,
"city_data": city_data, # "city_data": city_data,
} # }
#
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)
return jsonify(code=RET.DBERR, msg="数据库错误") # return jsonify(code=RET.DBERR, msg="数据库错误")
#
#
# 政策和重点项目 --- 重点项目需要改名称 # # 政策和重点项目 --- 重点项目需要改名称
@api_mobile.route("/attractPropol", methods=["POST"]) # @api_mobile.route("/attractPropol", methods=["POST"])
def attract_propol(): # def attract_propol():
req_dict = request.get_json() # req_dict = request.get_json()
district = req_dict.get("district") # 县区 # district = req_dict.get("district") # 县区
project = Project.query.filter_by() # project = Project.query.filter_by()
policy = InduPolicy.query.filter_by() # policy = InduPolicy.query.filter_by()
try: # try:
if district and district != "太原市": # if district and district != "太原市":
project = Project.query.filter_by(district=district) # project = Project.query.filter_by(district=district)
policy = InduPolicy.query.filter_by(district=district) # policy = InduPolicy.query.filter_by(district=district)
#
data_project = [{"name": i.name, "id": i.id} for i in project.all()] # data_project = [{"name": i.name, "id": i.id} for i in project.all()]
data_policy = [{"name": i.name, "id": i.id} for i in policy.all()] # data_policy = [{"name": i.name, "id": i.id} for i in policy.all()]
data = { # data = {
"project": data_project, # "project": data_project,
"policy": data_policy, # "policy": data_policy,
#
} # }
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)
return jsonify(code=RET.DATAERR, msg="数据库错误") # return jsonify(code=RET.DATAERR, msg="数据库错误")
#
#
# 获取重点企业的详情,详情页 # # 获取重点企业的详情,详情页
@api_mobile.route("/attractKeyProject", methods=["POST"]) # @api_mobile.route("/attractKeyProject", methods=["POST"])
def attract_keyproject(): # def attract_keyproject():
req_dic = request.get_json() # req_dic = request.get_json()
id = req_dic.get("id") # id = req_dic.get("id")
if not id: # if not id:
return jsonify(code=RET.PARAMERR, msg="参数不完整") # return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
try: # try:
project = Project.query.get(id) # project = Project.query.get(id)
data = { # data = {
"name": project.name, # "name": project.name,
"district": project.district, # "district": project.district,
"type": project.type, # "type": project.type,
"money": project.money, # "money": project.money,
"background": project.background, # "background": project.background,
"content": project.content, # "content": project.content,
"way": project.way, # "way": project.way,
"company": project.company, # "company": project.company,
"contact": project.contact, # "contact": project.contact,
"email": project.email # "email": project.email
} # }
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)
return jsonify(code=RET.DBERR, msg="数据库错误") # return jsonify(code=RET.DBERR, msg="数据库错误")
#
#
# 工程图表两个 # # 工程图表两个
@api_mobile.route("/attractProject", methods=["POST"]) # @api_mobile.route("/attractProject", methods=["POST"])
def attract_project(): # def attract_project():
req_dict = request.get_json() # req_dict = request.get_json()
district = req_dict.get("district") # district = req_dict.get("district")
try: # try:
list1 = NewProject.query.filter_by(district="太原市").all() # list1 = NewProject.query.filter_by(district="太原市").all()
project_industry = [] # project_industry = []
for i in list1: # for i in list1:
ss = NewProject.query.filter_by(type=i.type).first() # ss = NewProject.query.filter_by(type=i.type).first()
project_industry.append({"name": ss.type, # project_industry.append({"name": ss.type,
"number": ss.number, # "number": ss.number,
"money": ss.money}) # "money": ss.money})
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="数据库错误")
#
data = { # data = {
"project_industry": project_industry, # "project_industry": project_industry,
} # }
return jsonify(code=RET.OK, msg="获取成功", data=data) # return jsonify(code=RET.OK, msg="获取成功", data=data)
from flask import current_app, request, jsonify # from flask import current_app, request, jsonify
from apps.models import * # from apps.models import *
from apps.utils.response_code import RET # from apps.utils.response_code import RET
from apps.view_mobile import api_mobile # from apps.view_mobile import api_mobile
import pymysql # import pymysql
#
#
def judge_number(s): # def judge_number(s):
if "." in str(s): # if "." in str(s):
d = s.split(".") # d = s.split(".")
if len(d) == 2: # if len(d) == 2:
for i in d: # for i in d:
if i.isdigit(): # if i.isdigit():
pass # pass
else: # else:
return False # return False
return True # return True
return False # return False
else: # else:
return str(s).isdigit() # return str(s).isdigit()
#
#
# 选址评估,选择建议 # # 选址评估,选择建议
@api_mobile.route("/chooseAdvice", methods=["POST"]) # @api_mobile.route("/chooseAdvice", methods=["POST"])
def choose_advice(): # def choose_advice():
req_dict = request.get_json() # req_dict = request.get_json()
#
company = req_dict.get("company") # company = req_dict.get("company")
industry = req_dict.get("industry") # industry = req_dict.get("industry")
revenue = req_dict.get("revenue") # revenue = req_dict.get("revenue")
tax = req_dict.get("tax") # tax = req_dict.get("tax")
product = req_dict.get("product") # product = req_dict.get("product")
budget = req_dict.get('budget') # budget = req_dict.get('budget')
address = req_dict.get("address") # address = req_dict.get("address")
preference = req_dict.get("preference") # preference = req_dict.get("preference")
if not all([company, industry, revenue, tax, product, budget, preference]): # if not all([company, industry, revenue, tax, product, budget, preference]):
return jsonify(code=RET.DATAERR, msg="数据不全") # return jsonify(code=RET.DATAERR, msg="数据不全")
for i in range(0, 3): # for i in range(0, 3):
if not judge_number([revenue, tax, budget][i]): # if not judge_number([revenue, tax, budget][i]):
return jsonify(code=RET.DATAERR, msg=["营收应该为数字", "税收应该为数字", "预算应该为数字"][i]) # return jsonify(code=RET.DATAERR, msg=["营收应该为数字", "税收应该为数字", "预算应该为数字"][i])
list_zone = [] # list_zone = []
if address and address != "太原市": # if address and address != "太原市":
list_zone.append("(region='{}'or development_zone = '{}')".format(address, address)) # list_zone.append("(region='{}'or development_zone = '{}')".format(address, address))
#
list_zone.append(" (f_type is Null or f_type = {}) ".format(industry)) # list_zone.append(" (f_type is Null or f_type = {}) ".format(industry))
list_zone.append("IFNULL(induzone.tax,0)<={}".format(tax)) # list_zone.append("IFNULL(induzone.tax,0)<={}".format(tax))
list_zone.append("IFNULL(induzone.invest_power,0)<={}".format(budget)) # list_zone.append("IFNULL(induzone.invest_power,0)<={}".format(budget))
list_zone = " and ".join(list_zone) # list_zone = " and ".join(list_zone)
#
sum_list = [] # sum_list = []
if preference[5] != "false": # 地区经济发展 ---GDP的打分 # if preference[5] != "false": # 地区经济发展 ---GDP的打分
sum_list.append("IFNULL(induzone.gdp_point,0)") # sum_list.append("IFNULL(induzone.gdp_point,0)")
#
if preference[1] != "false": # 产业聚集度 --- 产业的打分 # if preference[1] != "false": # 产业聚集度 --- 产业的打分
# sum_list.append("IFNULL(company_industry_point,0)") # # sum_list.append("IFNULL(company_industry_point,0)")
sum_list.append("IFNULL(company_industry_point.point,0)") # sum_list.append("IFNULL(company_industry_point.point,0)")
#
if preference[0] != "false": # 征服扶持力度 --- 政策数的打分 # if preference[0] != "false": # 征服扶持力度 --- 政策数的打分
sum_list.append("IFNULL(induzone.policy_point,0)") # sum_list.append("IFNULL(induzone.policy_point,0)")
#
if preference[3] != "false": # 生活配套 -------水电打分 # if preference[3] != "false": # 生活配套 -------水电打分
sum_list.append("IFNULL(induzone.warter_point,0)") # sum_list.append("IFNULL(induzone.warter_point,0)")
#
# if preference[2] : # 交通 -----交通打分 # # if preference[2] : # 交通 -----交通打分
# sum_list.append("IFNULL(induzone.electricity_point,0)") # # sum_list.append("IFNULL(induzone.electricity_point,0)")
#
if preference[4] != "false": # 园区配套服务 ----园区的学校,商业街,宾馆打分 # if preference[4] != "false": # 园区配套服务 ----园区的学校,商业街,宾馆打分
sum_list.append("IFNULL(induzone.mall_point,0)") # sum_list.append("IFNULL(induzone.mall_point,0)")
sum_list.append("IFNULL(induzone.hotel_point,0)") # sum_list.append("IFNULL(induzone.hotel_point,0)")
sum_list.append("IFNULL(induzone.school_point,0)") # sum_list.append("IFNULL(induzone.school_point,0)")
#
# 拼接where请求 # # 拼接where请求
if list_zone: # if list_zone:
list_zone = "where " + list_zone # list_zone = "where " + list_zone
#
# 拼接排序请求 # # 拼接排序请求
sum_list = " + ".join(sum_list) # sum_list = " + ".join(sum_list)
if sum_list: # if sum_list:
sum_list = " order by " + sum_list + " desc" # sum_list = " order by " + sum_list + " desc"
# sql语句 # # sql语句
sql = "select * from induzone " \ # sql = "select * from induzone " \
"LEFT OUTER JOIN company_industry_point on induzone.name = company_industry_point.district " \ # "LEFT OUTER JOIN company_industry_point on induzone.name = company_industry_point.district " \
+ list_zone + sum_list # + list_zone + sum_list
try: # try:
conn = pymysql.connect(host='39.100.39.50', # conn = pymysql.connect(host='39.100.39.50',
user='root', # user='root',
password='Root@2020', # password='Root@2020',
db='indutyty', # db='indutyty',
charset='utf8') # charset='utf8')
#
cursor = conn.cursor() # cursor = conn.cursor()
# print(sql) # # print(sql)
data_num = cursor.execute(sql) # data_num = cursor.execute(sql)
data_list = cursor.fetchall() # data_list = cursor.fetchall()
#
# print(sql) # # print(sql)
if data_num > 3: # if data_num > 3:
data_list = data_list[0:3] # data_list = data_list[0:3]
#
data = [{"id": i[0], # data = [{"id": i[0],
"name": i[1], # "name": i[1],
"charge": i[9] if i[9] else "-", # "charge": i[9] if i[9] else "-",
"phone": i[10] if i[10] else "-", # "phone": i[10] if i[10] else "-",
"jwd": {"lng": i[13], "lat": i[14]}} for i in data_list] # "jwd": {"lng": i[13], "lat": i[14]}} for i in data_list]
# 没有查询结果的查找 # # 没有查询结果的查找
if not data_list: # if not data_list:
data = [{"name": "对不起,没有找到合适的园区!"}] # data = [{"name": "对不起,没有找到合适的园区!"}]
cursor.close() # cursor.close()
conn.close() # conn.close()
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)
return jsonify(code=RET.DBERR, msg="数据库错误") # return jsonify(code=RET.DBERR, msg="数据库错误")
#
#
# 地图的处理 # # 地图的处理
@api_mobile.route("/chooseMap", methods=["POST"]) # @api_mobile.route("/chooseMap", methods=["POST"])
def choose_map(): # def choose_map():
req_dict = request.get_json() # req_dict = request.get_json()
district = req_dict.get("district") # district = req_dict.get("district")
#
try: # try:
if not district: # if not district:
# 获取所有的园区值 # # 获取所有的园区值
district_list = Induzone.query.filter_by().all() # district_list = Induzone.query.filter_by().all()
data = [{"name": j.name, "jwd": {"lat": j.lat, "lng": j.lng}} for j in district_list] # data = [{"name": j.name, "jwd": {"lat": j.lat, "lng": j.lng}} for j in district_list]
return jsonify(code=RET.OK, msg="查找成功", data=data) # return jsonify(code=RET.OK, msg="查找成功", data=data)
district_list = Induzone.query.filter_by(region=district) # district_list = Induzone.query.filter_by(region=district)
data = [{"name": i.name, "jwd": {"lat": i.lat, "lng": i.lng}} for i in district_list] # data = [{"name": i.name, "jwd": {"lat": i.lat, "lng": i.lng}} for i in district_list]
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)
return jsonify(code=RET.DBERR, msg="数据库错误") # return jsonify(code=RET.DBERR, msg="数据库错误")
#
#
# 获取下拉列表 # # 获取下拉列表
@api_mobile.route("/chooseDownList", methods=["GET"]) # @api_mobile.route("/chooseDownList", methods=["GET"])
def choose_downlist(): # def choose_downlist():
try: # try:
industry = Industry.query.filter_by(statu=1).all() # industry = Industry.query.filter_by(statu=1).all()
data = [{ # data = [{
"name": i.name, # "name": i.name,
"id": i.nid, # "id": i.nid,
} for i in industry] # } for i in industry]
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="查找成功", data=data) # return jsonify(code=RET.OK, msg="查找成功", data=data)
import re # import re
import random # import random
import threading # import threading
from flask import jsonify, request, current_app # from flask import jsonify, request, current_app
from flask_mail import Mail, Message # from flask_mail import Mail, Message
from apps import redis_store, creat_app # from apps import redis_store, creat_app
from apps.view_mobile import api_mobile # from apps.view_mobile import api_mobile
from apps.models import * # from apps.models import *
from apps.utils.response_code import RET # from apps.utils.response_code import RET
from apps.util import login_required,verify_token # from apps.util import login_required,verify_token
from apps.utils.send_phone_info import send_code_new # from apps.utils.send_phone_info import send_code_new
#
@api_mobile.route("/mobilceCollect",methods = ["POST"]) # @api_mobile.route("/mobilceCollect",methods = ["POST"])
#@login_required # #@login_required
def mobile_collect_com(): # def mobile_collect_com():
#
# token = request.headers["token"] # # token = request.headers["token"]
# user = verify_token(token) # # user = verify_token(token)
# user_id = user.id # # user_id = user.id
user_id = 3 # user_id = 3
req_dict = request.get_json() # req_dict = request.get_json()
page = req_dict.get("page") # page = req_dict.get("page")
per_page = req_dict.get("per_page") # per_page = req_dict.get("per_page")
classify = req_dict.get("classify") # classify = req_dict.get("classify")
choice = req_dict.get("choice") # choice = req_dict.get("choice")
if not page: # if not page:
page = 1 # page = 1
#
if not per_page: # if not per_page:
per_page = 10 # per_page = 10
#
if not all([classify,choice]): # if not all([classify,choice]):
return jsonify(code = RET.PARAMERR,msg= "数据不全") # return jsonify(code = RET.PARAMERR,msg= "数据不全")
#
# 判断是企业还是行业关注,企业1,行业0 # # 判断是企业还是行业关注,企业1,行业0
if classify == 1: # if classify == 1:
company = [] # company = []
try: # try:
user = User.query.get(user_id) # user = User.query.get(user_id)
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="数据库错误")
if choice == "2": # if choice == "2":
try: # try:
maxnum = len(user.enterprise) # maxnum = len(user.enterprise)
company_list = user.enterprise[(page - 1) * per_page:page * per_page] # company_list = user.enterprise[(page - 1) * per_page:page * per_page]
for i in company_list: # for i in company_list:
create_time = UserEnterprise.query.filter_by(enterprise_id=i.id, user_id=user_id).first() # create_time = UserEnterprise.query.filter_by(enterprise_id=i.id, user_id=user_id).first()
company.append({ # company.append({
"id": i.id, # "id": i.id,
"company_name": i.company_name, # "company_name": i.company_name,
"create_time": create_time.create_time.strftime('%Y-%m-%d'), # "create_time": create_time.create_time.strftime('%Y-%m-%d'),
"build_date": i.build_date.strftime("%Y-%m-%d") if i.build_date else "-", # "build_date": i.build_date.strftime("%Y-%m-%d") if i.build_date else "-",
"legal":i.legal if i.legal else "-", # "legal":i.legal if i.legal else "-",
"money":"{}万元".format(i.capital_nums) if i.capital_nums else "-" # "money":"{}万元".format(i.capital_nums) if i.capital_nums else "-"
}) # })
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="数据库错误")
#
data = { # data = {
"ob_list": company, # "ob_list": company,
"maxnum": maxnum # "maxnum": maxnum
} # }
return jsonify(code=RET.OK, msg="查找成功", data=data) # return jsonify(code=RET.OK, msg="查找成功", data=data)
else: # else:
maxnum = len(user.company) # maxnum = len(user.company)
company_list = user.company[(page - 1) * per_page:page * per_page] # company_list = user.company[(page - 1) * per_page:page * per_page]
try: # try:
for i in company_list: # for i in company_list:
create_time = UserCompany.query.filter_by(company_id=i.id, user_id=user_id).first() # create_time = UserCompany.query.filter_by(company_id=i.id, user_id=user_id).first()
company.append({ # company.append({
"id": i.id, # "id": i.id,
"company_name": i.company_name, # "company_name": i.company_name,
"create_time": create_time.create_time.strftime('%Y-%m-%d'), # "create_time": create_time.create_time.strftime('%Y-%m-%d'),
"build_date": i.build_date.strftime("%Y-%m-%d") if i.build_date else "-", # "build_date": i.build_date.strftime("%Y-%m-%d") if i.build_date else "-",
"legal":i.legal if i.legal else "-", # "legal":i.legal if i.legal else "-",
"money":"{}万元".format(i.capital_nums) if i.capital_nums else "-" # "money":"{}万元".format(i.capital_nums) if i.capital_nums else "-"
}) # })
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="数据库错误")
#
data = { # data = {
"ob_list": company, # "ob_list": company,
"maxnum": maxnum # "maxnum": maxnum
} # }
return jsonify(code=RET.OK, msg="查找成功", data=data) # return jsonify(code=RET.OK, msg="查找成功", data=data)
# 行业 # # 行业
try: # try:
user = User.query.get(user_id) # user = User.query.get(user_id)
maxnum = len(user.industry) # maxnum = len(user.industry)
industry = [] # industry = []
industry_list = user.industry[(page - 1) * per_page:page * per_page] # industry_list = user.industry[(page - 1) * per_page:page * per_page]
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="数据库错误")
#
try: # try:
for i in industry_list: # for i in industry_list:
# 查询关注时间 # # 查询关注时间
indu = UserIndustry.query.filter_by(industry_id=i.id, user_id=user_id).first() # indu = UserIndustry.query.filter_by(industry_id=i.id, user_id=user_id).first()
industry.append({ # industry.append({
"id": i.id, # "id": i.id,
"industry_name": i.name, # "industry_name": i.name,
"create_time": indu.create_time.strftime("%Y-%m-%d"), # "create_time": indu.create_time.strftime("%Y-%m-%d"),
"count": i.entities if i.entities else 0 # "count": i.entities if i.entities else 0
}) # })
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="数据库错误")
#
data = { # data = {
"ob_list": industry, # "ob_list": industry,
"maxnum": maxnum # "maxnum": maxnum
} # }
return jsonify(code=200, msg="查找成功", data=data) # return jsonify(code=200, msg="查找成功", data=data)
#
#
#
#取消收藏 # #取消收藏
@api_mobile.route("/mobileDelete", methods=["POST"]) # @api_mobile.route("/mobileDelete", methods=["POST"])
@login_required # @login_required
def mobile_delete(): # def mobile_delete():
token = request.headers["token"] # token = request.headers["token"]
user = verify_token(token) # user = verify_token(token)
user_id = user.id # user_id = user.id
#
req_dict = request.get_json() # req_dict = request.get_json()
#
id = req_dict.get("id") # id = req_dict.get("id")
classify = req_dict.get("classify") # classify = req_dict.get("classify")
choice = req_dict.get("choice") # choice = req_dict.get("choice")
#print(id,classify,choice) # #print(id,classify,choice)
if not all([id,classify,choice]): # if not all([id,classify,choice]):
return jsonify(code=RET.PARAMERR, msg="数据不全") # return jsonify(code=RET.PARAMERR, msg="数据不全")
#
# id = g.id # # id = g.id
#
if classify == 1: # if classify == 1:
if choice == "2": # if choice == "2":
# 删除全国数据 # # 删除全国数据
#pass # #pass
try: # try:
company_user = UserEnterprise.query.filter_by(enterprise_id=id, user_id=user_id).first() # company_user = UserEnterprise.query.filter_by(enterprise_id=id, user_id=user_id).first()
db.session.delete(company_user) # db.session.delete(company_user)
db.session.commit() # db.session.commit()
return jsonify(code = RET.OK,msg = "取关成功") # 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="数据库错误")
else: # else:
try: # try:
company_user = UserCompany.query.filter_by(company_id=id, user_id=user_id).first() # company_user = UserCompany.query.filter_by(company_id=id, user_id=user_id).first()
db.session.delete(company_user) # db.session.delete(company_user)
db.session.commit() # db.session.commit()
return jsonify(code = RET.OK,msg = "取关成功") # 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="数据库错误")
# 删除企业数据 # # 删除企业数据
try: # try:
industry_user = UserIndustry.query.filter_by(industry_id=id, user_id=user_id).first() # industry_user = UserIndustry.query.filter_by(industry_id=id, user_id=user_id).first()
db.session.delete(industry_user) # db.session.delete(industry_user)
db.session.commit() # db.session.commit()
return jsonify(code=RET.OK, msg="取关成功") # 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 = "数据库错误")
\ No newline at end of file \ No newline at end of file
import os # import os
import json # import json
from elasticsearch import Elasticsearch # from elasticsearch import Elasticsearch
from flask import request, jsonify, current_app # from flask import request, jsonify, current_app
from apps.models import * # from apps.models import *
from apps.view_mobile import api_mobile # from apps.view_mobile import api_mobile
from apps.util import login_required, verify_token # from apps.util import login_required, verify_token
from apps.utils.response_code import RET # from apps.utils.response_code import RET
#
def create_body(page, page_size, args_query, args_date, args_term): # def create_body(page, page_size, args_query, args_date, args_term):
''' # '''
#
:param page: # :param page:
:param page_size: # :param page_size:
:param args_query: # :param args_query:
:param args_date: # :param args_date:
:param args_term: # :param args_term:
:return: # :return:
''' # '''
#
body = { # body = {
"query": { # "query": {
"bool": { # "bool": {
"filter": { # "filter": {
"range": { # "range": {
"build_date": { # "build_date": {
} # }
} # }
}, # },
"must": [ # "must": [
{"multi_match": { # {"multi_match": {
"query": "{}".format(args_query["query"]), # "query": "{}".format(args_query["query"]),
"type": "best_fields", # "type": "best_fields",
"fields": [ # "fields": [
"product^1.0", # "product^1.0",
"company_name^1.0", # "company_name^1.0",
"industry^1.0" # "industry^1.0"
], # ],
"tie_breaker": 0.3 # "tie_breaker": 0.3
} # }
}, # },
] # ]
} # }
}, # },
"from": page, # "from": page,
"size": page_size, # "size": page_size,
"sort": [], # "sort": [],
"aggs": {}, # "aggs": {},
"_source": [ # "_source": [
#'all_info', # #'all_info',
'industry', 'build_date', 'register_money_nums', 'product', # 'industry', 'build_date', 'register_money_nums', 'product',
'company_name',"mysql_id" # 'company_name',"mysql_id"
], # ],
"highlight": { # "highlight": {
"fields": { # "fields": {
"product": {"type": "plain"}, # "product": {"type": "plain"},
"company_name": {"type": "plain"}, # "company_name": {"type": "plain"},
"industry": {"type": "plain"} # "industry": {"type": "plain"}
} # }
} # }
} # }
#
if args_date: # if args_date:
body["query"]["bool"]["filter"]["range"]["build_date"]["gte"] = args_date["build_date"][0] # body["query"]["bool"]["filter"]["range"]["build_date"]["gte"] = args_date["build_date"][0]
body["query"]["bool"]["filter"]["range"]["build_date"]["lte"] = args_date["build_date"][1] # body["query"]["bool"]["filter"]["range"]["build_date"]["lte"] = args_date["build_date"][1]
#
for k, v in args_term.items(): # for k, v in args_term.items():
body["query"]["bool"]["must"].append({"term": {"{}".format(k): "{}".format(v)}}) # body["query"]["bool"]["must"].append({"term": {"{}".format(k): "{}".format(v)}})
#
return body # return body
#
#
#
#搜索接口 # #搜索接口
@api_mobile.route("/mobileSearchTy", methods=["POST"]) # @api_mobile.route("/mobileSearchTy", methods=["POST"])
@login_required # @login_required
def mobile_search_ty(): # def mobile_search_ty():
req_dict = request.get_json() # req_dict = request.get_json()
#
token = request.headers["token"] # token = request.headers["token"]
user = verify_token(token) # user = verify_token(token)
user_id = user.id # user_id = user.id
#
company = req_dict.get("company") # company = req_dict.get("company")
if not company: # if not company:
return jsonify(code = RET.PARAMERR,msg = "数据库错误") # return jsonify(code = RET.PARAMERR,msg = "数据库错误")
args_query = dict() # args_query = dict()
args_date = dict() # args_date = dict()
args_term = dict() # args_term = dict()
#
# #每页个数 # # #每页个数
per_page = req_dict.get("per_page") # per_page = req_dict.get("per_page")
page = req_dict.get("page") # page = req_dict.get("page")
if not req_dict.get("per_page"): # if not req_dict.get("per_page"):
per_page = 10 # per_page = 10
per_page = int(per_page) # per_page = int(per_page)
# 页数 # # 页数
if not page: # if not page:
page = 1 # page = 1
page = int(page) # page = int(page)
args_query["query"] = company # args_query["query"] = company
#
try: # try:
user = User.query.get(user_id) # user = User.query.get(user_id)
b = [] # b = []
if user.searchlist: # if user.searchlist:
for j in user.searchlist: # for j in user.searchlist:
b.append(j.history) # b.append(j.history)
if company in b: # if company in b:
user.searchlist.remove(user.searchlist[b.index(company)]) # user.searchlist.remove(user.searchlist[b.index(company)])
if len(b) > 5: # if len(b) > 5:
user.searchlist.remove(user.searchlist[0]) # user.searchlist.remove(user.searchlist[0])
search = SearchList(history=company) # search = SearchList(history=company)
db.session.add(search) # db.session.add(search)
user.searchlist.append(search) # user.searchlist.append(search)
db.session.commit() # db.session.commit()
except Exception as e: # except Exception as e:
db.session.rollback() # db.session.rollback()
current_app.logger.error(e) # current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误") # return jsonify(code=RET.DBERR, msg="数据库错误")
#
body = create_body(page, per_page, args_query, args_date, args_term) # body = create_body(page, per_page, args_query, args_date, args_term)
#
try: # try:
es = Elasticsearch([{'host': '39.100.39.50', 'port': 9200}]) # es = Elasticsearch([{'host': '39.100.39.50', 'port': 9200}])
data = es.search(index="ty_com", body=body) # data = es.search(index="ty_com", body=body)
data_list = [] # data_list = []
#
#数据的列表添加进去 # #数据的列表添加进去
for i in data["hits"]['hits']: # for i in data["hits"]['hits']:
#
if company: # if company:
# 判断高亮,然后添加 # # 判断高亮,然后添加
data_list.append({ # data_list.append({
"company": i["highlight"]["company_name"][0] if "company_name" in i["highlight"] else i["_source"]["company_name"], # "company": i["highlight"]["company_name"][0] if "company_name" in i["highlight"] else i["_source"]["company_name"],
"product": i["highlight"]["product"][0] if "product" in i["highlight"] else i["_source"]["product"], # "product": i["highlight"]["product"][0] if "product" in i["highlight"] else i["_source"]["product"],
"industry": i["highlight"]["industry"][0] if "industry" in i["highlight"] else i["_source"]["industry"], # "industry": i["highlight"]["industry"][0] if "industry" in i["highlight"] else i["_source"]["industry"],
"money": "{}万元".format( i["_source"]["register_money_nums"]), # "money": "{}万元".format( i["_source"]["register_money_nums"]),
"createtime": i["_source"]["build_date"], # "createtime": i["_source"]["build_date"],
"id": i["_source"]["mysql_id"], # "id": i["_source"]["mysql_id"],
"choice": 1 # "choice": 1
}) # })
else: # else:
data_list.append({ # data_list.append({
"company": i["_source"]["company_name"], # "company": i["_source"]["company_name"],
"product": i["_source"]["product"], # "product": i["_source"]["product"],
"industry": i["_source"]["industry"], # "industry": i["_source"]["industry"],
"money": "{}万元".format(i["_source"]["register_money_nums"]), # "money": "{}万元".format(i["_source"]["register_money_nums"]),
"createtime": i["_source"]["build_date"], # "createtime": i["_source"]["build_date"],
"id": i["_source"]["mysql_id"], # "id": i["_source"]["mysql_id"],
"choice":1, # "choice":1,
}) # })
except Exception as e: # except Exception as e:
current_app.logger.error(e) # current_app.logger.error(e)
return jsonify(code = RET.DBERR,msg= "es数据库错误") # return jsonify(code = RET.DBERR,msg= "es数据库错误")
data = { # data = {
"data": data_list # "data": data_list
} # }
return jsonify(code=RET.OK, msg="查找成功", data=data) # return jsonify(code=RET.OK, msg="查找成功", data=data)
#
#
#
import os # import os
import time # import time
import datetime # import datetime
import re # import re
import pandas as pd # import pandas as pd
from flask import jsonify, request, current_app # from flask import jsonify, request, current_app
from sqlalchemy import or_, and_, desc # from sqlalchemy import or_, and_, desc
from apps.models import * # from apps.models import *
from apps.util import login_required,verify_token # from apps.util import login_required,verify_token
from apps.view_mobile import api_mobile # from apps.view_mobile import api_mobile
from apps.utils.response_code import RET # from apps.utils.response_code import RET
from dateutil.relativedelta import relativedelta # from dateutil.relativedelta import relativedelta
#
def get_year_month(year,month): # def get_year_month(year,month):
year = int(year) # year = int(year)
month = int(month) # month = int(month)
if month == 12: # if month == 12:
year += 1 # year += 1
month = 1 # month = 1
else: # else:
year = year # year = year
month += 1 # month += 1
return year,month # return year,month
#
def get_ininvest_id(x): # def get_ininvest_id(x):
x = int(x) # x = int(x)
if x < 0: # if x < 0:
return 0 # return 0
if x <= 1: # if x <= 1:
return 1 # return 1
if x <= 10: # if x <= 10:
return 2 # return 2
if x <= 50: # if x <= 50:
return 3 # return 3
if x < 100: # if x < 100:
return 4 # return 4
return 5 # return 5
#
#
# 招商资源管理 # # 招商资源管理
# 新增项目详情页的下拉列表 # # 新增项目详情页的下拉列表
@api_mobile.route("/mobileInList", methods=["GET"]) # @api_mobile.route("/mobileInList", methods=["GET"])
# # @login_required
# def mobile_in_list():
#
# # token = request.headers["token"]
# # user = verify_token(token)
# # user_id = user.id
# user_id = 3
# try:
# user = User.query.get(user_id)
# role = user.flag
# if role != 2:
# return jsonify(code = RET.ROLEERR,msg = "无权限查看此内容")
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库错误")
#
# try:
# attract = Attract.query.filter_by(statu=1)
# industry_list = attract.filter_by(sid=1).all() # 行业表
# stage_list = attract.filter_by(sid=2).all() # 项目阶段表
# invest = [{"name":"请选择","id":""},{"name":"1亿元以下","id":1},{"name":"1-10亿元","id":2},
# {"name":"10-50亿元","id":3},{"name":"50-100亿元","id":4},
# {"name":"100亿元以上","id":5}]
# unit = user.unit # 操作人的机构
# government = Government.query.filter_by(name = unit).first()
# section_list = government.sections
# industry = [{"name": i.name, "industry_id": i.nid} for i in industry_list]
# industry = [{"name":"请选择","industry_id":""}] + industry
# stage = [{"name": i.name, "stage_id": i.nid} for i in stage_list]
# stage = [{"name":"请选择","stage_id":""}]+stage
# section = [{"name": i.name, "section_id": i.id} for i in section_list]
# section = [{"name":"请选择","section_id":""}] + section
# data = {
# "industry": industry,
# "stage": stage,
# "invest":invest,
# "section":section
# }
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库错误")
#
# # 招商资源管理页面的详情页
# @api_mobile.route("/mobileInItem", methods=["POST"])
# # @login_required
# def mobile_in_item():
#
# # token = request.headers["token"]
# # user = verify_token(token)
# # user_id = user.id
# user_id = 3
# try:
# user = User.query.get(user_id)
# unit = user.unit # 用户所在的部门
# role = user.flag
# if role != 2:
# return jsonify(code=RET.ROLEERR, msg="无权限查看此内容")
# role = user.role.role
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库错误")
#
# req_dic = request.get_json()
# page = req_dic.get("page") # 页数
# perpage = req_dic.get("perpage") # 每页个数
# stage_id = req_dic.get("stage_id") # 项目进展
# indu_id = req_dic.get("indu_id") # 行业
# invest_id = req_dic.get("invest_id") # 投资
# section = req_dic.get("section") # 部门
# search = req_dic.get("search") # 搜索栏搜索的值
# #order = req_dic.get("order") # 按照投资额的顺序 #1为顺序,2为倒序
# if search:
# try:
# user = User.query.get(user_id)
# b = []
# print(user.searchitem)
# if user.searchitem:
# for j in user.searchitem:
# b.append(j.history)
# if search in b:
# user.searchitem.remove(user.searchitem[b.index(search)])
# if len(b) > 5:
# user.searchitem.remove(user.searchitem[0])
# sear = SearchItem(history=search)
# db.session.add(sear)
# user.searchitem.append(sear)
# db.session.commit()
# except Exception as e:
# db.session.rollback()
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg='数据库错误')
# # 获取当前账号的权限制
# try:
# item = Item.query.filter_by()
# if role[0] == "1":
# item = item.filter_by(unit=unit)
#
# # 权限查找
# if role[0] == "2": # 部级
# item = item.filter_by(section=user.section)
#
# if role[0] == "3": # 个人
# item = item.filter(or_(Item.share.like("%--" + str(user_id) + "--%"), Item.user_id == user_id))
#
# if not page:
# page = 1
#
# if not perpage:
# perpage = 10
#
# if stage_id:
# item = item.filter_by(stage_id=stage_id)
#
# if indu_id:
# item = item.filter_by(indu_id=indu_id)
#
# if invest_id:
# item = item.filter_by(invest_id=invest_id)
#
# if section:
# if section != "请选择":
# item = item.filter_by(section=section)
#
# if search:
# item = item.filter(or_(Item.company_name.like("%" + search + "%")
# , Item.name.like("%" + search + "%")))
#
# # if order == 2:
# # item = item.order_by(desc("invest"))
# # else:
# # item = item.order_by("invest")
# item = item.order_by(desc("id"))
#
# maxnum = len(item.all())
# item = item.paginate(page, perpage).items
#
# data_list = []
# #status_list = ["", "未上报", "已上报", "已驳回", "已通过"]
# for i in item:
# # status = i.status
# # if not i.status:
# # status = 0
# data_list.append(
# {
# "id": i.id,
# "company_name": i.company_name,
# "name": i.name,
# #"product": i.product,
# #"industry": i.industry,
# #"invest": i.invest,
# #"section": i.section,
# "stage": i.stage,
# "unit":i.unit,
# "link": i.link,
# #"status": status_list[int(status)]
# }
# )
# data = {"data_list": data_list, "maxnum": maxnum}
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库错误")
#
#
# # 招商资源管理
# # 新增项目详情页的下拉列表
# @api_mobile.route("/mobileUpList", methods=["GET"])
# # @login_required
# def mobile_up_list():
#
# # token = request.headers["token"]
# # user = verify_token(token)
# # user_id = user.id
# user_id = 3
# try:
# user = User.query.get(user_id)
# role = user.flag
# if role != 2:
# return jsonify(code=RET.ROLEERR, msg="无权限查看此内容")
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库错误")
# try:
# attract = Attract.query.filter_by(statu=1)
# industry_list = attract.filter_by(sid=1).all()
# stage_list = attract.filter_by(sid=2).all() # 项目阶段
# unit = Government.query.filter_by().all()
# industry = [{"name": i.name, "indu_id": i.nid} for i in industry_list] # 项目行业
# industry = [{"name": "请选择", "indu_id": ""}] + industry
# stage = [{"name": i.name, "stage_id": i.nid} for i in stage_list] # 项目阶段
# stage = [{"name": "请选择", "stage_id": ""}] + stage
# unit = [{"name": i.name, "unit_id": i.id} for i in unit] # 报送单位
# unit = [{"name": "请选择", "unit_id": ""}] + unit
# invest = [{"invest": "请选择", "invest_id": ""}, {"invest": "1亿元以下", "invest_id": 1},
# {"invest": "1-10亿", "invest_id": 2},
# {"invest": "10-50亿", "invest_id": 3}, {"invest": "50-100亿", "invest_id": 4},
# {"invest": "100亿以上", "invest_id": 5}] # 投资额
# data = {
# "industry": industry,
# "stage": stage,
# "unit": unit,
# "invest": invest
# }
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库错误")
#
#
# @api_mobile.route("/mobileUpItem", methods=["POST"])
# @login_required # @login_required
def mobile_in_list(): # def mobile_up_item():
#
# token = request.headers["token"] # token = request.headers["token"]
# user = verify_token(token) # user = verify_token(token)
# user_id = user.id # user_id = user.id
user_id = 3 # try:
try: # user = User.query.get(user_id)
user = User.query.get(user_id) # role = user.flag
role = user.flag # if role != 2:
if role != 2: # return jsonify(code=RET.ROLEERR, msg="无权限查看此内容")
return jsonify(code = RET.ROLEERR,msg = "无权限查看此内容") # unit = user.unit
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="数据库错误")
# #user_id = 3
try: # req_dic = request.get_json()
attract = Attract.query.filter_by(statu=1) #
industry_list = attract.filter_by(sid=1).all() # 行业表 # indu_id = req_dic.get("indu_id") # 行业,
stage_list = attract.filter_by(sid=2).all() # 项目阶段表 # invest_id = req_dic.get("invest_id") # 投资额ID
invest = [{"name":"请选择","id":""},{"name":"1亿元以下","id":1},{"name":"1-10亿元","id":2}, # evolve_id = req_dic.get("stage_id") # 项目进度
{"name":"10-50亿元","id":3},{"name":"50-100亿元","id":4}, # unit_name = req_dic.get("unit") # 报送单位
{"name":"100亿元以上","id":5}] # way_id = req_dic.get("way_id") # 查看方式
unit = user.unit # 操作人的机构 # search = req_dic.get("search") # 搜索框
government = Government.query.filter_by(name = unit).first() # order = str(req_dic.get("order")) # 顺序 1-正序,2-倒序
section_list = government.sections # page = req_dic.get("page") # 页数
industry = [{"name": i.name, "industry_id": i.nid} for i in industry_list] # perpage = req_dic.get("perpage") # 每页个数
industry = [{"name":"请选择","industry_id":""}] + industry # if search:
stage = [{"name": i.name, "stage_id": i.nid} for i in stage_list] # try:
stage = [{"name":"请选择","stage_id":""}]+stage # user = User.query.get(user_id)
section = [{"name": i.name, "section_id": i.id} for i in section_list] # b = []
section = [{"name":"请选择","section_id":""}] + section # if user.searchitem:
data = { # for j in user.searchitem:
"industry": industry, # b.append(j.history)
"stage": stage, # if search in b:
"invest":invest, # user.searchitem.remove(user.searchitem[b.index(search)])
"section":section # if len(b) > 5:
} # user.searchitem.remove(user.searchitem[0])
return jsonify(code=RET.OK, msg="查询成功", data=data) # sear = SearchItem(history=search)
except Exception as e: # db.session.add(sear)
current_app.logger.error(e) # user.searchitem.append(sear)
return jsonify(code=RET.DBERR, msg="数据库错误") # db.session.commit()
# except Exception as e:
# 招商资源管理页面的详情页 # db.session.rollback()
@api_mobile.route("/mobileInItem", methods=["POST"]) # current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg='数据库错误')
#
# try:
# item = Item.query.filter_by(unit_up=unit)
#
# if not page:
# page = 1
#
# if not perpage:
# perpage = 10
#
# if indu_id:
# item = item.filter_by(indu_id=indu_id)
#
# if invest_id:
# item = item.filter_by(invest_id=invest_id)
#
# if evolve_id:
# item = item.filter_by(stage_id=evolve_id)
#
# if unit_name:
# if unit_name != "请选择":
# item = item.filter_by(unit=unit_name)
#
# # 进行中项目
# if way_id == 1:
# # 数据可能需要改
# item = item.filter(and_(Item.stage_id != 5, Item.stage_id != 10))
# # 投促局调度的项目
# if way_id == 2:
# item = item.filter_by(belong=1)
# # 搜索,模糊查询
# if search:
# item = item.filter(or_(Item.company_name.like('%' + search + "%"), Item.name.like('%' + search + "%")))
# # 排序
# item = item.order_by(desc(Item.id))
# if order:
# if order == "2":
# item = item.order_by(desc(Item.invest))
# else:
# item = item.order_by(Item.invest)
#
# maxnum = len(item.all())
# item = item.paginate(page, perpage).items
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code = RET.DBERR,msg = "数据库错误")
# # for j in government_list:
# # new_item = item.filter_by(unit_up = j.name).order_by(desc(Item.id)).all()
# #status_list = ["", "未上报", "已上报", "已驳回", "已通过"]
# data_list = []
# for i in item:
# # status = i.status
# # if not i.status:
# # status = 0
# data_list.append({
# "item_id":i.id,
# "name": i.name,
# "company": i.company_name,
# #"product": i.product,
# #"industry": i.industry,
# #"invest": i.invest,
# "stage": i.stage,
# "unit": i.unit,
# "link": i.link,
# #"status":status_list[int(status)]
# })
# data = {"data_list": data_list, "maxnum": maxnum}
# return jsonify(code=RET.OK, msg="查找成功", data=data)
#
#
# @api_mobile.route("/mobiledetailsItem", methods=["POST"])
# @login_required # @login_required
def mobile_in_item(): # def mobile_details_item():
#
# token = request.headers["token"] # token = request.headers["token"]
# user = verify_token(token) # user = verify_token(token)
# user_id = user.id # user_id = user.id
user_id = 3 # # user_id = 3
try: # try:
user = User.query.get(user_id) # user = User.query.get(user_id)
unit = user.unit # 用户所在的部门 # role = user.flag
role = user.flag # if role != 2:
if role != 2: # return jsonify(code=RET.ROLEERR, msg="无权限查看此内容")
return jsonify(code=RET.ROLEERR, msg="无权限查看此内容") # except Exception as e:
role = user.role.role # current_app.logger.error(e)
except Exception as e: # return jsonify(code=RET.DBERR, msg="数据库错误")
current_app.logger.error(e) #
return jsonify(code=RET.DBERR, msg="数据库错误") # req_dic = request.get_json()
# item_id = req_dic.get("item_id")
req_dic = request.get_json() #
page = req_dic.get("page") # 页数 # if not item_id:
perpage = req_dic.get("perpage") # 每页个数 # return jsonify(code=RET.DATAERR, msg="缺少必要的参数")
stage_id = req_dic.get("stage_id") # 项目进展 #
indu_id = req_dic.get("indu_id") # 行业 # try:
invest_id = req_dic.get("invest_id") # 投资 # item = Item.query.get(item_id)
section = req_dic.get("section") # 部门 # if not item:
search = req_dic.get("search") # 搜索栏搜索的值 # return jsonify(code=RET.DATAERR, msg="不存在这样的项目")
#order = req_dic.get("order") # 按照投资额的顺序 #1为顺序,2为倒序 #
if search: # data = {
try: # "build_date": item.build_date.strftime('%Y-%m-%d'),
user = User.query.get(user_id) # "company_name": item.company_name,
b = [] # "admin": item.admin,
print(user.searchitem) # "mobile": item.mobile,
if user.searchitem: # "email": item.email,
for j in user.searchitem: # "name": item.name,
b.append(j.history) # "store": item.store.strftime('%Y-%m-%d'),
if search in b: # "product": item.product,
user.searchitem.remove(user.searchitem[b.index(search)]) # "industry": item.industry,
if len(b) > 5: # "invest": item.invest,
user.searchitem.remove(user.searchitem[0]) # "area": item.area,
sear = SearchItem(history=search) # "value": item.value,
db.session.add(sear) # "tax": item.tax,
user.searchitem.append(sear) # "unit":item.unit,
db.session.commit() # "link": item.link,
except Exception as e: # "link_mobile": item.link_mobile,
db.session.rollback() # "email": item.email,
current_app.logger.error(e) # # "level": item.level,
return jsonify(code=RET.DBERR, msg='数据库错误') # # "stage": item.stage,
# 获取当前账号的权限制 # "main_introduce": item.main_introduce if item.main_introduce else "-",
try: # "invest_introduce": item.invest_introduce if item.invest_introduce else "-",
item = Item.query.filter_by() # "build_introduce": item.build_introduce if item.build_introduce else "-",
if role[0] == "1": # "encomy": item.encomy if item.encomy else "-",
item = item.filter_by(unit=unit) # "policy": item.policy if item.policy else "-",
# "question": item.question if item.question else "-",
# 权限查找 # }
if role[0] == "2": # 部级 # return jsonify(code=RET.OK, msg="查找成功", data=data)
item = item.filter_by(section=user.section) # except Exception as e:
# current_app.logger.error(e)
if role[0] == "3": # 个人 # return jsonify(code=RET.DBERR, msg="数据库错误")
item = item.filter(or_(Item.share.like("%--" + str(user_id) + "--%"), Item.user_id == user_id)) #
# #搜索历史接口
if not page: # @api_mobile.route("/mobileSearchItem",methods = ["GET"])
page = 1
if not perpage:
perpage = 10
if stage_id:
item = item.filter_by(stage_id=stage_id)
if indu_id:
item = item.filter_by(indu_id=indu_id)
if invest_id:
item = item.filter_by(invest_id=invest_id)
if section:
if section != "请选择":
item = item.filter_by(section=section)
if search:
item = item.filter(or_(Item.company_name.like("%" + search + "%")
, Item.name.like("%" + search + "%")))
# if order == 2:
# item = item.order_by(desc("invest"))
# else:
# item = item.order_by("invest")
item = item.order_by(desc("id"))
maxnum = len(item.all())
item = item.paginate(page, perpage).items
data_list = []
#status_list = ["", "未上报", "已上报", "已驳回", "已通过"]
for i in item:
# status = i.status
# if not i.status:
# status = 0
data_list.append(
{
"id": i.id,
"company_name": i.company_name,
"name": i.name,
#"product": i.product,
#"industry": i.industry,
#"invest": i.invest,
#"section": i.section,
"stage": i.stage,
"unit":i.unit,
"link": i.link,
#"status": status_list[int(status)]
}
)
data = {"data_list": data_list, "maxnum": maxnum}
return jsonify(code=RET.OK, msg="查询成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
# 招商资源管理
# 新增项目详情页的下拉列表
@api_mobile.route("/mobileUpList", methods=["GET"])
# @login_required # @login_required
def mobile_up_list(): # def mobile_search_item():
# token = request.headers["token"]
# token = request.headers["token"] # user = verify_token(token)
# user = verify_token(token) # user_id = user.id
# user_id = user.id # try:
user_id = 3 # user = User.query.get(user_id)
try: # data = {
user = User.query.get(user_id) # "search":[i.history for i in user.searchitem]
role = user.flag # }
if role != 2: # data["search"] = data["search"][::-1]
return jsonify(code=RET.ROLEERR, msg="无权限查看此内容") # 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)
return jsonify(code=RET.DBERR, msg="数据库错误") # return jsonify(code=RET.DBERR, msg="数据库错误")
try: #
attract = Attract.query.filter_by(statu=1) # #搜索历史接口
industry_list = attract.filter_by(sid=1).all() # @api_mobile.route("/deleteSearchItem",methods = ["GET"])
stage_list = attract.filter_by(sid=2).all() # 项目阶段
unit = Government.query.filter_by().all()
industry = [{"name": i.name, "indu_id": i.nid} for i in industry_list] # 项目行业
industry = [{"name": "请选择", "indu_id": ""}] + industry
stage = [{"name": i.name, "stage_id": i.nid} for i in stage_list] # 项目阶段
stage = [{"name": "请选择", "stage_id": ""}] + stage
unit = [{"name": i.name, "unit_id": i.id} for i in unit] # 报送单位
unit = [{"name": "请选择", "unit_id": ""}] + unit
invest = [{"invest": "请选择", "invest_id": ""}, {"invest": "1亿元以下", "invest_id": 1},
{"invest": "1-10亿", "invest_id": 2},
{"invest": "10-50亿", "invest_id": 3}, {"invest": "50-100亿", "invest_id": 4},
{"invest": "100亿以上", "invest_id": 5}] # 投资额
data = {
"industry": industry,
"stage": stage,
"unit": unit,
"invest": invest
}
return jsonify(code=RET.OK, msg="查询成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
@api_mobile.route("/mobileUpItem", methods=["POST"])
@login_required
def mobile_up_item():
token = request.headers["token"]
user = verify_token(token)
user_id = user.id
try:
user = User.query.get(user_id)
role = user.flag
if role != 2:
return jsonify(code=RET.ROLEERR, msg="无权限查看此内容")
unit = user.unit
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
#user_id = 3
req_dic = request.get_json()
indu_id = req_dic.get("indu_id") # 行业,
invest_id = req_dic.get("invest_id") # 投资额ID
evolve_id = req_dic.get("stage_id") # 项目进度
unit_name = req_dic.get("unit") # 报送单位
way_id = req_dic.get("way_id") # 查看方式
search = req_dic.get("search") # 搜索框
order = str(req_dic.get("order")) # 顺序 1-正序,2-倒序
page = req_dic.get("page") # 页数
perpage = req_dic.get("perpage") # 每页个数
if search:
try:
user = User.query.get(user_id)
b = []
if user.searchitem:
for j in user.searchitem:
b.append(j.history)
if search in b:
user.searchitem.remove(user.searchitem[b.index(search)])
if len(b) > 5:
user.searchitem.remove(user.searchitem[0])
sear = SearchItem(history=search)
db.session.add(sear)
user.searchitem.append(sear)
db.session.commit()
except Exception as e:
db.session.rollback()
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg='数据库错误')
try:
item = Item.query.filter_by(unit_up=unit)
if not page:
page = 1
if not perpage:
perpage = 10
if indu_id:
item = item.filter_by(indu_id=indu_id)
if invest_id:
item = item.filter_by(invest_id=invest_id)
if evolve_id:
item = item.filter_by(stage_id=evolve_id)
if unit_name:
if unit_name != "请选择":
item = item.filter_by(unit=unit_name)
# 进行中项目
if way_id == 1:
# 数据可能需要改
item = item.filter(and_(Item.stage_id != 5, Item.stage_id != 10))
# 投促局调度的项目
if way_id == 2:
item = item.filter_by(belong=1)
# 搜索,模糊查询
if search:
item = item.filter(or_(Item.company_name.like('%' + search + "%"), Item.name.like('%' + search + "%")))
# 排序
item = item.order_by(desc(Item.id))
if order:
if order == "2":
item = item.order_by(desc(Item.invest))
else:
item = item.order_by(Item.invest)
maxnum = len(item.all())
item = item.paginate(page, perpage).items
except Exception as e:
current_app.logger.error(e)
return jsonify(code = RET.DBERR,msg = "数据库错误")
# for j in government_list:
# new_item = item.filter_by(unit_up = j.name).order_by(desc(Item.id)).all()
#status_list = ["", "未上报", "已上报", "已驳回", "已通过"]
data_list = []
for i in item:
# status = i.status
# if not i.status:
# status = 0
data_list.append({
"item_id":i.id,
"name": i.name,
"company": i.company_name,
#"product": i.product,
#"industry": i.industry,
#"invest": i.invest,
"stage": i.stage,
"unit": i.unit,
"link": i.link,
#"status":status_list[int(status)]
})
data = {"data_list": data_list, "maxnum": maxnum}
return jsonify(code=RET.OK, msg="查找成功", data=data)
@api_mobile.route("/mobiledetailsItem", methods=["POST"])
@login_required
def mobile_details_item():
token = request.headers["token"]
user = verify_token(token)
user_id = user.id
# user_id = 3
try:
user = User.query.get(user_id)
role = user.flag
if role != 2:
return jsonify(code=RET.ROLEERR, msg="无权限查看此内容")
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
req_dic = request.get_json()
item_id = req_dic.get("item_id")
if not item_id:
return jsonify(code=RET.DATAERR, msg="缺少必要的参数")
try:
item = Item.query.get(item_id)
if not item:
return jsonify(code=RET.DATAERR, msg="不存在这样的项目")
data = {
"build_date": item.build_date.strftime('%Y-%m-%d'),
"company_name": item.company_name,
"admin": item.admin,
"mobile": item.mobile,
"email": item.email,
"name": item.name,
"store": item.store.strftime('%Y-%m-%d'),
"product": item.product,
"industry": item.industry,
"invest": item.invest,
"area": item.area,
"value": item.value,
"tax": item.tax,
"unit":item.unit,
"link": item.link,
"link_mobile": item.link_mobile,
"email": item.email,
# "level": item.level,
# "stage": item.stage,
"main_introduce": item.main_introduce if item.main_introduce else "-",
"invest_introduce": item.invest_introduce if item.invest_introduce else "-",
"build_introduce": item.build_introduce if item.build_introduce else "-",
"encomy": item.encomy if item.encomy else "-",
"policy": item.policy if item.policy else "-",
"question": item.question if item.question else "-",
}
return jsonify(code=RET.OK, msg="查找成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
#搜索历史接口
@api_mobile.route("/mobileSearchItem",methods = ["GET"])
@login_required
def mobile_search_item():
token = request.headers["token"]
user = verify_token(token)
user_id = user.id
try:
user = User.query.get(user_id)
data = {
"search":[i.history for i in user.searchitem]
}
data["search"] = data["search"][::-1]
return jsonify(code = RET.OK,msg = "查询成功",data = data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
#搜索历史接口
@api_mobile.route("/deleteSearchItem",methods = ["GET"])
@login_required
def delete_search_item():
token = request.headers["token"]
user = verify_token(token)
user_id = user.id
try:
user = User.query.get(user_id)
for i in user.searchitem:
user.searchitem.remove(i)
db.session.commit()
return jsonify(code = RET.OK,msg = "删除成功")
except Exception as e:
db.session.rollback()
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
# 获取机构的部门和人员
@api_mobile.route("/getSectionPeople", methods=["GET"])
# @login_required # @login_required
def get_section_people(): # def delete_search_item():
# token = request.headers["token"]
# token = request.headers["token"] # user = verify_token(token)
# user = verify_token(token) # user_id = user.id
# user_id = user.id # try:
user_id = 3 # user = User.query.get(user_id)
try: # for i in user.searchitem:
user = User.query.get(user_id) # user.searchitem.remove(i)
unit = user.unit # db.session.commit()
government = Government.query.filter_by(name = unit).first() # return jsonify(code = RET.OK,msg = "删除成功")
data = [] # except Exception as e:
# db.session.rollback()
for i in government.sections: # current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库错误")
person = [{"name":"请选择","id":""}] #
section = User.query.filter(and_(User.unit == government.name, # # 获取机构的部门和人员
User.section == i.name,User.id != user_id)).all() # @api_mobile.route("/getSectionPeople", methods=["GET"])
# # @login_required
for j in section: # def get_section_people():
person.append({"name": j.name, "id": j.id}) #
data.append({"person": person, "name": i.name, "section_id": i.id}) # # token = request.headers["token"]
data = [{"section_id":"","name":"请选择","person":[{"name":"请选择","id":""}]}] + data # # user = verify_token(token)
return jsonify(code=RET.OK, msg="查找成功", data=data) # # user_id = user.id
except Exception as e: # user_id = 3
current_app.logger.error(e) # try:
return jsonify(code=RET.DBERR, msg="数据库错误") # user = User.query.get(user_id)
# unit = user.unit
# government = Government.query.filter_by(name = unit).first()
#机构统筹的机构 # data = []
@api_mobile.route("/UnitUnit",methods = ["GET"]) #
# for i in government.sections:
#
# person = [{"name":"请选择","id":""}]
# section = User.query.filter(and_(User.unit == government.name,
# User.section == i.name,User.id != user_id)).all()
#
# for j in section:
# person.append({"name": j.name, "id": j.id})
# data.append({"person": person, "name": i.name, "section_id": i.id})
# data = [{"section_id":"","name":"请选择","person":[{"name":"请选择","id":""}]}] + 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_mobile.route("/UnitUnit",methods = ["GET"])
# # @login_required
# def unit_unit():
# # token = request.headers["token"]
# # user = verify_token(token)
# # user_id = user.id
# user_id = 3
# try:
# user = User.query.get(user_id)
# unit_name = user.unit
# unit = Government.query.filter_by(name = unit_name).first()
# data = [{"name":i.name,"unit_id":i.id}for i in unit.followed]
# data = [{"name":"请选择","unit_id":""}] + 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_mobile.route("/stageInTable", methods=["POST"])
# # @login_required
# def stage_in_table():
#
# # token = request.headers["token"]
# # user = verify_token(token)
# # user_id = user.id
# user_id = 3
# try:
# user = User.query.get(user_id)
# role = user.flag
# if role != 2:
# return jsonify(code=RET.ROLEERR, msg="无权限查看此内容")
# unit = user.unit
# _section = user.section
# role = user.role.role
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code = RET.DBERR,msg = "数据库错误")
#
# req_dic = request.get_json()
# year_begin = req_dic.get("year_begin")
# month_begin = req_dic.get("month_begin")
# year_end = req_dic.get("year_end")
# month_end = req_dic.get("month_end")
# stage_id = req_dic.get("stage_id")
# indu_id = req_dic.get("indu_id")
# section = req_dic.get("section")
# user_id = req_dic.get("user_id")
#
# if not all([year_begin, month_begin, year_end, month_end]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
# year_begin = year_begin[:-1]
# month_begin = month_begin[:-1]
# (year_end, month_end) = get_year_month(year_end[:-1], month_end[:-1])
#
# date_begin = time.strptime("{}-{}-01".format(year_begin,month_begin), '%Y-%m-%d')
# date_end = time.strptime("{}-{}-01".format(year_end,month_end), '%Y-%m-%d') # - relativedelta(months=-1)
# try:
# if role[0] == "1":
# item = Item.query.filter(and_(Item.unit == unit, Item.store >= date_begin, Item.store < date_end))
# if role[0] == "2":
# item = Item.query.filter(and_(Item.unit == unit,Item.section == _section, Item.store >= date_begin, Item.store < date_end))
# if role[0] == "3":
# item = Item.query.filter(and_(Item.user_id == user_id, Item.store >= date_begin, Item.store < date_end))
# item_user = User.query.filter_by(unit = unit)
# item_evolve = Attract.query.filter_by(statu = 1,sid = 2)
# item_industry = Attract.query.filter_by(statu = 1,sid = 1)
# if stage_id:
# item = item.filter_by(stage_id=stage_id)
# item_evolve = Attract.query.filter_by(nid = stage_id)
# if indu_id:
# item = item.filter_by(industry=indu_id)
# item_industry = item_industry.filter_by(nid = indu_id)
# if section:
# if section != "请选择":
# item = item.filter_by(section=section)
# item_user = item_user.filter_by(section = section)
# if user_id:
# item = item.filter_by(user_id=user_id)
# item_user = item_user.filter_by(section=section,id = user_id)
# item_evolve = set(item_evolve.with_entities(Attract.nid).all())
# item_evolve = list(item_evolve)
# item_evolve.sort()
# stage = [{
# "name": Attract.query.filter_by(nid=i[0],sid = 2).first().name,"value" :item.filter_by(stage_id=i[0]).count()
# } for i in item_evolve]
#
# item_user = set(item_user.with_entities(User.id).all())
# user = [{
# "name":User.query.get(i[0]).real_name,"value":item.filter_by(user_id=i[0]).count(),
# } for i in item_user]
#
# item_industry = set(item_industry.with_entities(Attract.nid).all())
# industry = [{
# "name" :Attract.query.filter_by(nid=i[0], sid=1).first().name,"value": item.filter_by(indu_id=i[0]).count()
# } for i in item_industry]
# data = {
# "stage": stage,
# "user": user,
# "industry": industry
# }
# return jsonify(code=RET.OK, msg="查找成功", data=data)
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库错误")
#
#
# # 招商进度管理统计图查看(机构统筹机构)
# @api_mobile.route("/stageOutTable", methods=["POST"])
# @login_required # @login_required
def unit_unit(): # def stage_out_table():
# token = request.headers["token"] #
# user = verify_token(token) # token = request.headers["token"]
# user_id = user.id # user = verify_token(token)
user_id = 3 # user_id = user.id
try: #
user = User.query.get(user_id) # try:
unit_name = user.unit # user = User.query.get(user_id)
unit = Government.query.filter_by(name = unit_name).first() # unit = user.unit
data = [{"name":i.name,"unit_id":i.id}for i in unit.followed] # role = user.flag
data = [{"name":"请选择","unit_id":""}] + data # if role != 2:
return jsonify(code = RET.OK,msg = "查找成功",data = data) # return jsonify(code=RET.ROLEERR, 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="数据库错误")
# req_dic = request.get_json()
# 招商进度管理统计图查看(机构内部) # year_begin = req_dic.get("year_begin")
@api_mobile.route("/stageInTable", methods=["POST"]) # month_begin = req_dic.get("month_begin")
# @login_required # year_end = req_dic.get("year_end")
def stage_in_table(): # month_end = req_dic.get("month_end")
# unit_name = req_dic.get("unit_name")
# token = request.headers["token"] # stage_id = req_dic.get("stage_id")
# user = verify_token(token) # indu_id = req_dic.get("indu_id")
# user_id = user.id #
user_id = 3 #
try: # if not all([year_begin, month_begin, year_end, month_end]):
user = User.query.get(user_id) # return jsonify(code=RET.PARAMERR, msg="参数不完整")
role = user.flag # year_begin = year_begin[:-1]
if role != 2: # month_begin = month_begin[:-1]
return jsonify(code=RET.ROLEERR, msg="无权限查看此内容") # (year_end, month_end) = get_year_month(year_end[:-1], month_end[:-1])
unit = user.unit #
_section = user.section # date_begin = time.strptime("{}-{}-01".format(year_begin, month_begin), '%Y-%m-%d')
role = user.role.role # date_end = time.strptime("{}-{}-01".format(year_end, month_end), '%Y-%m-%d') # - relativedelta(months=-1)
except Exception as e: # try:
current_app.logger.error(e) # item = Item.query.filter(and_(Item.store >= date_begin, Item.store < date_end,Item.unit_up == unit))
return jsonify(code = RET.DBERR,msg = "数据库错误") # government = Government.query.filter_by(name=unit).first()
# foller_name = [i.name for i in government.followed]
req_dic = request.get_json() # item = item.filter(Item.unit.in_(foller_name))
year_begin = req_dic.get("year_begin") # item_user = item.filter(Item.unit.in_(foller_name))
month_begin = req_dic.get("month_begin") # item_evolve = Attract.query.filter_by(statu=1, sid=2)
year_end = req_dic.get("year_end") # item_industry = Attract.query.filter_by(statu=1, sid=1)
month_end = req_dic.get("month_end") #
stage_id = req_dic.get("stage_id") # if stage_id:
indu_id = req_dic.get("indu_id") # item = item.filter_by(stage_id=stage_id)
section = req_dic.get("section") # item_evolve = Attract.query.filter_by(nid=stage_id)
user_id = req_dic.get("user_id") #
# if indu_id:
if not all([year_begin, month_begin, year_end, month_end]): # item = item.filter_by(industry=indu_id)
return jsonify(code=RET.PARAMERR, msg="参数不完整") # item_industry = item_industry.filter_by(nid=indu_id)
year_begin = year_begin[:-1] #
month_begin = month_begin[:-1] # if unit_name:
(year_end, month_end) = get_year_month(year_end[:-1], month_end[:-1]) # if unit_name != "请选择":
# item = item.filter_by(unit=unit_name)
date_begin = time.strptime("{}-{}-01".format(year_begin,month_begin), '%Y-%m-%d') # item_user = item_user.filter_by(unit=unit_name)
date_end = time.strptime("{}-{}-01".format(year_end,month_end), '%Y-%m-%d') # - relativedelta(months=-1) #
try: # item_evolve = set(item_evolve.filter_by(statu = 1,sid = 2).with_entities(Attract.nid).all())
if role[0] == "1": # item_evolve = list(item_evolve)
item = Item.query.filter(and_(Item.unit == unit, Item.store >= date_begin, Item.store < date_end)) # item_evolve.sort()
if role[0] == "2": #
item = Item.query.filter(and_(Item.unit == unit,Item.section == _section, Item.store >= date_begin, Item.store < date_end)) # stage = [{
if role[0] == "3": # "name":Attract.query.filter_by(nid=i[0],sid = 2).first().name,"value":item.filter_by(stage_id=i[0]).count()
item = Item.query.filter(and_(Item.user_id == user_id, Item.store >= date_begin, Item.store < date_end)) # } for i in item_evolve]
item_user = User.query.filter_by(unit = unit) #
item_evolve = Attract.query.filter_by(statu = 1,sid = 2) # item_user = set(item_user.with_entities(Item.unit).all())
item_industry = Attract.query.filter_by(statu = 1,sid = 1) # unit = [{
if stage_id: # "name":i[0],"value": item.filter_by(unit=i[0]).count()
item = item.filter_by(stage_id=stage_id) # } for i in item_user]
item_evolve = Attract.query.filter_by(nid = stage_id) #
if indu_id: # item_industry = set(item_industry.with_entities(Attract.nid).all())
item = item.filter_by(industry=indu_id) # industry = [{
item_industry = item_industry.filter_by(nid = indu_id) # "name":Attract.query.filter_by(nid=i[0], sid=1).first().name,"value": item.filter_by(indu_id=i[0]).count()
if section: # } for i in item_industry]
if section != "请选择": # data = {
item = item.filter_by(section=section) # "stage": stage,
item_user = item_user.filter_by(section = section) # "unit": unit,
if user_id: # "industry": industry
item = item.filter_by(user_id=user_id) # }
item_user = item_user.filter_by(section=section,id = user_id) # return jsonify(code=RET.OK, msg="查找成功", data=data)
item_evolve = set(item_evolve.with_entities(Attract.nid).all()) # except Exception as e:
item_evolve = list(item_evolve) # current_app.logger.error(e)
item_evolve.sort() # return jsonify(code=RET.DBERR, msg="数据库错误")
stage = [{ #
"name": Attract.query.filter_by(nid=i[0],sid = 2).first().name,"value" :item.filter_by(stage_id=i[0]).count()
} for i in item_evolve]
item_user = set(item_user.with_entities(User.id).all())
user = [{
"name":User.query.get(i[0]).real_name,"value":item.filter_by(user_id=i[0]).count(),
} for i in item_user]
item_industry = set(item_industry.with_entities(Attract.nid).all())
industry = [{
"name" :Attract.query.filter_by(nid=i[0], sid=1).first().name,"value": item.filter_by(indu_id=i[0]).count()
} for i in item_industry]
data = {
"stage": stage,
"user": user,
"industry": industry
}
return jsonify(code=RET.OK, msg="查找成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
# 招商进度管理统计图查看(机构统筹机构)
@api_mobile.route("/stageOutTable", methods=["POST"])
@login_required
def stage_out_table():
token = request.headers["token"]
user = verify_token(token)
user_id = user.id
try:
user = User.query.get(user_id)
unit = user.unit
role = user.flag
if role != 2:
return jsonify(code=RET.ROLEERR, msg="无权限查看此内容")
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
req_dic = request.get_json()
year_begin = req_dic.get("year_begin")
month_begin = req_dic.get("month_begin")
year_end = req_dic.get("year_end")
month_end = req_dic.get("month_end")
unit_name = req_dic.get("unit_name")
stage_id = req_dic.get("stage_id")
indu_id = req_dic.get("indu_id")
if not all([year_begin, month_begin, year_end, month_end]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
year_begin = year_begin[:-1]
month_begin = month_begin[:-1]
(year_end, month_end) = get_year_month(year_end[:-1], month_end[:-1])
date_begin = time.strptime("{}-{}-01".format(year_begin, month_begin), '%Y-%m-%d')
date_end = time.strptime("{}-{}-01".format(year_end, month_end), '%Y-%m-%d') # - relativedelta(months=-1)
try:
item = Item.query.filter(and_(Item.store >= date_begin, Item.store < date_end,Item.unit_up == unit))
government = Government.query.filter_by(name=unit).first()
foller_name = [i.name for i in government.followed]
item = item.filter(Item.unit.in_(foller_name))
item_user = item.filter(Item.unit.in_(foller_name))
item_evolve = Attract.query.filter_by(statu=1, sid=2)
item_industry = Attract.query.filter_by(statu=1, sid=1)
if stage_id:
item = item.filter_by(stage_id=stage_id)
item_evolve = Attract.query.filter_by(nid=stage_id)
if indu_id:
item = item.filter_by(industry=indu_id)
item_industry = item_industry.filter_by(nid=indu_id)
if unit_name:
if unit_name != "请选择":
item = item.filter_by(unit=unit_name)
item_user = item_user.filter_by(unit=unit_name)
item_evolve = set(item_evolve.filter_by(statu = 1,sid = 2).with_entities(Attract.nid).all())
item_evolve = list(item_evolve)
item_evolve.sort()
stage = [{
"name":Attract.query.filter_by(nid=i[0],sid = 2).first().name,"value":item.filter_by(stage_id=i[0]).count()
} for i in item_evolve]
item_user = set(item_user.with_entities(Item.unit).all())
unit = [{
"name":i[0],"value": item.filter_by(unit=i[0]).count()
} for i in item_user]
item_industry = set(item_industry.with_entities(Attract.nid).all())
industry = [{
"name":Attract.query.filter_by(nid=i[0], sid=1).first().name,"value": item.filter_by(indu_id=i[0]).count()
} for i in item_industry]
data = {
"stage": stage,
"unit": unit,
"industry": industry
}
return jsonify(code=RET.OK, msg="查找成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库错误")
from flask import current_app, request, jsonify # from flask import current_app, request, jsonify
from apps.view_mobile import api_mobile # from apps.view_mobile import api_mobile
from sqlalchemy import extract, or_, and_ # from sqlalchemy import extract, or_, and_
from sqlalchemy.sql import func # from sqlalchemy.sql import func
from apps.models import * # from apps.models import *
from apps.util import login_required, verify_token # from apps.util import login_required, verify_token
from apps.utils.response_code import RET # from apps.utils.response_code import RET
from datetime import datetime, timedelta # from datetime import datetime, timedelta
import datetime # import datetime
#
#
# 太原市企业列表 # # 太原市企业列表
@api_mobile.route('/tycompany', methods=['POST']) # @api_mobile.route('/tycompany', methods=['POST'])
@login_required
def enterprise():
'''太原市企业列表'''
# 获取用户id
token = request.headers["token"]
user = verify_token(token)
user_id = user.id # 用户id
# user_id = 5 # 用户id
req_dict = request.get_json()
inid = req_dict.get("inid") # 行业id
cate = req_dict.get("cate") # 行业等级,(高端设备等五个为"1",子行业为"2")
page = req_dict.get("page") # 分页页码
perpage = req_dict.get("perpage") # 分页大小
entype = req_dict.get("entype") # 企业类型id
qualificat = req_dict.get("qualificat") # 企业资质id
capital = req_dict.get("capital") # 注册资本id
quoted = req_dict.get("quoted") # 上市板块
district = req_dict.get("district") # 太原市下区县
yearid = req_dict.get("yearid") # 成立时间年限id
roundid = req_dict.get("roundid") # 融资轮次id(天使/种子,1)(PreA/A+,2)(PreB/B+,3)(C轮以上,4)(收并购,5)(战略投资,6)(其他,7)
# 校验参数完整性
if not all([page, perpage]):
return jsonify(code=RET.PARAMERR, msg="参数不完整")
try:
if cate == "1":
company = Company.query.filter_by(f_type=inid, city="太原市")
else:
company = Company.query.filter_by(c_type=inid, city="太原市")
# 企业类型
if entype:
company = company.filter_by(entypeid=entype)
# 企业资质
if qualificat:
if qualificat == 1:
company = company.filter_by(high_new=1)
if qualificat == 2:
company = company.filter_by(tbe=1)
if qualificat == 3:
company = company.filter_by(quoted_company=1)
if qualificat == 4:
company = company.filter_by(sxonhun=1)
if qualificat == 5:
company = company.filter_by(isfive=1)
if qualificat == 6:
company = company.filter_by(unicorn=1)
if qualificat == 7:
company = company.filter_by(dengl=1)
if qualificat == 8:
company = company.filter_by(zjtg=1)
if qualificat == 9:
company = company.filter_by(scale=1)
if qualificat == 10:
company = company.filter_by(serve=1)
# 注册资本
if capital:
company = company.filter_by(capital_id=capital)
# 上市板块
if quoted:
company = company.filter_by(public_id=quoted)
# 区域选择
if district:
company = company.filter_by(district=district)
# 成立时间id
if yearid:
company = company.filter_by(yearid=yearid)
# 融资轮次
if roundid:
company = company.filter_by(roundid=roundid)
size = company.count()
companys = company.order_by(Company.hots.desc()).paginate(page, perpage).items # 企业热度倒序
user = User.query.get(user_id) # 获取关注列表
if user:
company_ids = [coms.id for coms in user.company]
else:
company_ids = []
df = [{"id": com.id,
"company_name": com.company_name,
"legal": com.legal if com.legal else "",
"capital": com.capital if com.capital else "",
"build_date": str(com.build_date)[:10] if com.build_date else "",
"collect": "1" if com.id in company_ids else "2", # 关注状态码1关注,2未关注
"choice": "1" # 1太原企业,2全国企业
} for com in companys]
data = {"size": size, "df": df}
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="参数错误")
return jsonify(code=RET.OK, msg="获取成功", data=data)
# 全国企业列表
@api_mobile.route('/view_map/enterprise', methods=['POST'])
# @login_required # @login_required
def att_enterprise(): # def enterprise():
''' # '''太原市企业列表'''
太原市企业列表 # # 获取用户id
:return: # token = request.headers["token"]
''' # user = verify_token(token)
req_dict = request.get_json() # user_id = user.id # 用户id
inid = req_dict.get("inid") # 行业id # # user_id = 5 # 用户id
page = req_dict.get("page") # 分页页码 #
perpage = req_dict.get("perpage") # 分页大小 # req_dict = request.get_json()
# inid = req_dict.get("inid") # 行业id
entype = req_dict.get("entype") # 企业类型id # cate = req_dict.get("cate") # 行业等级,(高端设备等五个为"1",子行业为"2")
qualificat = req_dict.get("qualificat") # 企业资质id # page = req_dict.get("page") # 分页页码
capital = req_dict.get("capital") # 注册资本id # perpage = req_dict.get("perpage") # 分页大小
quoted = req_dict.get("quoted") # 上市板块 #
area = req_dict.get("area") # ["省","市","区"] # entype = req_dict.get("entype") # 企业类型id
province = area[0] # qualificat = req_dict.get("qualificat") # 企业资质id
city = area[1] # capital = req_dict.get("capital") # 注册资本id
district = area[2] # quoted = req_dict.get("quoted") # 上市板块
yearid = req_dict.get("yearid") # 成立时间年限id # district = req_dict.get("district") # 太原市下区县
roundid = req_dict.get("roundid") # 融资轮次id(天使/种子,1)(PreA/A+,2)(PreB/B+,3)(C轮以上,4)(收并购,5)(战略投资,6)(其他,7) # yearid = req_dict.get("yearid") # 成立时间年限id
# roundid = req_dict.get("roundid") # 融资轮次id(天使/种子,1)(PreA/A+,2)(PreB/B+,3)(C轮以上,4)(收并购,5)(战略投资,6)(其他,7)
# 校验参数完整性 #
if not all([page, perpage]): # # 校验参数完整性
return jsonify(code=RET.PARAMERR, msg="参数不完整") # if not all([page, perpage]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
try: #
if inid: # 子行业分类 # try:
enterprise = Enterprise.query.filter_by(c_type=inid) # if cate == "1":
else: # company = Company.query.filter_by(f_type=inid, city="太原市")
enterprise = Enterprise.query.filter_by() # else:
# 企业类型 # company = Company.query.filter_by(c_type=inid, city="太原市")
if entype: # # 企业类型
enterprise = enterprise.filter_by(entypeid=entype) # if entype:
# 企业资质 # company = company.filter_by(entypeid=entype)
if qualificat: # # 企业资质
if qualificat == 1: # if qualificat:
enterprise = enterprise.filter_by(high_new=1) # if qualificat == 1:
if qualificat == 2: # company = company.filter_by(high_new=1)
enterprise = enterprise.filter_by(tbe=1) # if qualificat == 2:
if qualificat == 3: # company = company.filter_by(tbe=1)
enterprise = enterprise.filter_by(quoted_company=1) # if qualificat == 3:
if qualificat == 4: # company = company.filter_by(quoted_company=1)
enterprise = enterprise.filter_by(isfive=1) # if qualificat == 4:
if qualificat == 5: # company = company.filter_by(sxonhun=1)
enterprise = enterprise.filter_by(unicorn=1) # if qualificat == 5:
if qualificat == 6: # company = company.filter_by(isfive=1)
enterprise = enterprise.filter_by(dengl=1) # if qualificat == 6:
# company = company.filter_by(unicorn=1)
# 注册资本 # if qualificat == 7:
if capital: # company = company.filter_by(dengl=1)
enterprise = enterprise.filter_by(capital_id=capital) # if qualificat == 8:
# 上市板块 # company = company.filter_by(zjtg=1)
if quoted: # if qualificat == 9:
enterprise = enterprise.filter_by(public_id=quoted) # company = company.filter_by(scale=1)
# 区域选择 # if qualificat == 10:
if province: # company = company.filter_by(serve=1)
enterprise = enterprise.filter_by(province=province) # # 注册资本
if city: # if capital:
enterprise = enterprise.filter_by(city=city) # company = company.filter_by(capital_id=capital)
if district: # # 上市板块
enterprise = enterprise.filter_by(district=district) # if quoted:
# 成立时间id # company = company.filter_by(public_id=quoted)
if yearid: # # 区域选择
enterprise = enterprise.filter_by(yearid=yearid) # if district:
# 融资轮次 # company = company.filter_by(district=district)
if roundid: # # 成立时间id
enterprise = enterprise.filter_by(roundid=roundid) # if yearid:
# company = company.filter_by(yearid=yearid)
size = enterprise.count() # # 融资轮次
enterprise = enterprise.order_by(Enterprise.hots.desc()).paginate(page, perpage).items # 企业热度倒序 # if roundid:
# company = company.filter_by(roundid=roundid)
df = [{"id": com.id, #
"company_name": com.company_name, # 企业名称 # size = company.count()
"status": com.status if com.status else "", # 企业状态 # companys = company.order_by(Company.hots.desc()).paginate(page, perpage).items # 企业热度倒序
"legal": com.legal if com.legal else "", # 法人 #
"capital": com.capital if com.capital else "", # 注册资本 # user = User.query.get(user_id) # 获取关注列表
"build_date": str(com.build_date)[:10] if com.build_date else "", # 时间 # if user:
"telephone": str(com.telephone) if com.telephone else "", # 电话 # company_ids = [coms.id for coms in user.company]
"address": str(com.address) if com.address else "", # 地址 # else:
"lng":com.lng if com.lng else "", # company_ids = []
"lat":com.lat if com.lat else "", #
# "collect": "1" if com.id in company_ids else "2", # 关注状态码1关注,2未关注 # df = [{"id": com.id,
"choice": "2" # 1太原企业,2全国企业 # "company_name": com.company_name,
} for com in enterprise] # "legal": com.legal if com.legal else "",
# "capital": com.capital if com.capital else "",
data = {"size": size, "df": df} # "build_date": str(com.build_date)[:10] if com.build_date else "",
except Exception as e: # "collect": "1" if com.id in company_ids else "2", # 关注状态码1关注,2未关注
current_app.logger.error(e) # "choice": "1" # 1太原企业,2全国企业
return jsonify(code=RET.DBERR, msg="数据库查询错误") # } for com in companys]
# data = {"size": size, "df": df}
return jsonify(code=RET.OK, msg="获取成功", data=data) # except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="参数错误")
# ty+全国企业信息详情 #
@api_mobile.route('/companyDetail', methods=['POST']) # return jsonify(code=RET.OK, msg="获取成功", data=data)
@login_required #
def company_detail(): #
''' # # 全国企业列表
企业信息详情 # @api_mobile.route('/view_map/enterprise', methods=['POST'])
:return: # # @login_required
''' # def att_enterprise():
# 获取用户id # '''
token = request.headers["token"] # 太原市企业列表
user = verify_token(token) # :return:
user_id = user.id # 用户id # '''
# user_id = 5 # req_dict = request.get_json()
# inid = req_dict.get("inid") # 行业id
req_dict = request.get_json() # page = req_dict.get("page") # 分页页码
_id = req_dict.get("id") # 企业id # perpage = req_dict.get("perpage") # 分页大小
choice = req_dict.get("choice") # 企业选择 #
# entype = req_dict.get("entype") # 企业类型id
# 校验参数完整性 # qualificat = req_dict.get("qualificat") # 企业资质id
if not all([_id, choice]): # capital = req_dict.get("capital") # 注册资本id
return jsonify(code=RET.PARAMERR, msg="参数不完整") # quoted = req_dict.get("quoted") # 上市板块
# area = req_dict.get("area") # ["省","市","区"]
try: # province = area[0]
if choice == "1": # city = area[1]
company = Company.query.get(_id) # district = area[2]
user = User.query.get(user_id) # 获取关注列表 # yearid = req_dict.get("yearid") # 成立时间年限id
if user: # roundid = req_dict.get("roundid") # 融资轮次id(天使/种子,1)(PreA/A+,2)(PreB/B+,3)(C轮以上,4)(收并购,5)(战略投资,6)(其他,7)
company_ids = [coms.id for coms in user.company] #
else: # # 校验参数完整性
company_ids = [] # if not all([page, perpage]):
if company: # return jsonify(code=RET.PARAMERR, msg="参数不完整")
province = company.province if company.province else "" #
city = company.city if company.city else "" # try:
if city == province: # if inid: # 子行业分类
city = '' # enterprise = Enterprise.query.filter_by(c_type=inid)
district = company.district if company.district else "" # else:
data = {"id": company.id, # enterprise = Enterprise.query.filter_by()
"company_name": company.company_name, # # 企业类型
"legal": company.legal if company.legal else "", # 法人 # if entype:
"status": company.status if company.status else "", # 状态 # enterprise = enterprise.filter_by(entypeid=entype)
"build_date": str(company.build_date)[:10] if company.build_date else "", # 成立日期 # # 企业资质
"capital": company.capital if company.capital else "", # 注册资本 # if qualificat:
"telephone": company.telephone if company.telephone else "", # 电话 # if qualificat == 1:
"address": company.address if company.address else "", # 地址 # enterprise = enterprise.filter_by(high_new=1)
"location": province + city + district, # if qualificat == 2:
# enterprise = enterprise.filter_by(tbe=1)
"email": company.email if company.email else "-", # 邮箱 # if qualificat == 3:
# "web_site": company.web_site if company.web_site else "-", # 网址 # enterprise = enterprise.filter_by(quoted_company=1)
"company_info": company.company_info if company.company_info else "", # 简介 # if qualificat == 4:
"social_code": company.social_code if company.social_code else "", # 社会统一信用代码 # enterprise = enterprise.filter_by(isfive=1)
"tax_code": company.tax_code if company.tax_code else "", # 纳税人识别号 # if qualificat == 5:
"register_code": company.register_code if company.register_code else "", # 注册号 # enterprise = enterprise.filter_by(unicorn=1)
"company_code": company.company_code if company.company_code else "", # 组织机构代码 # if qualificat == 6:
"bao": company.bao_num if company.bao_num else 0, # 组织机构代码 # enterprise = enterprise.filter_by(dengl=1)
"entype": company.entype if company.entype else "", # 企业类型 #
"industry": company.company_industry if company.company_industry else "", # 所属行业 # # 注册资本
"scope": company.business_scope if company.business_scope else "", # 经营范围 # if capital:
"taking": company.takingn if company.takingn else "", # 营收 # enterprise = enterprise.filter_by(capital_id=capital)
"jwd": {"lng": company.lng if company.lng else "-", # # 上市板块
"lat": company.lat if company.lat else "-"}, # if quoted:
# "high_new": "高新技术企业" if company.high_new else "-", # enterprise = enterprise.filter_by(public_id=quoted)
"collect": "1" if company.id in company_ids else "2", # 关注状态码1关注,2未关注 # # 区域选择
"choice": "1" # 1太原企业,2全国企业 # if province:
} # enterprise = enterprise.filter_by(province=province)
else: # if city:
return jsonify(code=RET.NODATA, msg="查无数据") # enterprise = enterprise.filter_by(city=city)
return jsonify(code=RET.OK, msg="获取成功", data=data) # if district:
else: # enterprise = enterprise.filter_by(district=district)
enterprise = Enterprise.query.get(_id) # # 成立时间id
user = User.query.get(user_id) # 获取关注列表 # if yearid:
if user: # enterprise = enterprise.filter_by(yearid=yearid)
company_ids = [coms.id for coms in user.enterprise] # # 融资轮次
else: # if roundid:
company_ids = [] # enterprise = enterprise.filter_by(roundid=roundid)
if enterprise: #
data = {"id": enterprise.id, # size = enterprise.count()
"company_name": enterprise.company_name, # enterprise = enterprise.order_by(Enterprise.hots.desc()).paginate(page, perpage).items # 企业热度倒序
"legal": enterprise.legal if enterprise.legal else "", # 法人 #
"status": enterprise.status if enterprise.status else "", # 状态 # df = [{"id": com.id,
"build_date": str(enterprise.build_date)[:10] if enterprise.build_date else "", # 成立日期 # "company_name": com.company_name, # 企业名称
"capital": enterprise.capital if enterprise.capital else "", # 注册资本 # "status": com.status if com.status else "", # 企业状态
"telephone": enterprise.telephone if enterprise.telephone else "", # 电话 # "legal": com.legal if com.legal else "", # 法人
"address": enterprise.address if enterprise.address else "", # 地址 # "capital": com.capital if com.capital else "", # 注册资本
"email": enterprise.email if enterprise.email else "-", # 邮箱 # "build_date": str(com.build_date)[:10] if com.build_date else "", # 时间
# "web_site": company.web_site if company.web_site else "-", # 网址 # "telephone": str(com.telephone) if com.telephone else "", # 电话
"company_info": enterprise.company_info if enterprise.company_info else "", # 简介 # "address": str(com.address) if com.address else "", # 地址
"social_code": enterprise.social_code if enterprise.social_code else "", # 社会统一信用代码 # "lng":com.lng if com.lng else "",
"tax_code": enterprise.tax_code if enterprise.tax_code else "", # 纳税人识别号 # "lat":com.lat if com.lat else "",
"register_code": enterprise.register_code if enterprise.register_code else "", # 注册号 # # "collect": "1" if com.id in company_ids else "2", # 关注状态码1关注,2未关注
"company_code": enterprise.company_code if enterprise.company_code else "", # 组织机构代码 # "choice": "2" # 1太原企业,2全国企业
"bao": enterprise.bao_num if enterprise.bao_num else 0, # 组织机构代码 # } for com in enterprise]
"entype": enterprise.entype if enterprise.entype else "", # 企业类型 #
"industry": enterprise.company_industry if enterprise.company_industry else "", # 所属行业 # data = {"size": size, "df": df}
"scope": enterprise.business_scope if enterprise.business_scope else "", # 经营范围 # except Exception as e:
"taking": enterprise.takingn if enterprise.takingn else "", # 营收 # current_app.logger.error(e)
"jwd": {"lng": enterprise.lng if enterprise.lng else "-", # return jsonify(code=RET.DBERR, msg="数据库查询错误")
"lat": enterprise.lat if enterprise.lat else "-"}, #
# "high_new": "高新技术企业" if company.high_new else "-", # return jsonify(code=RET.OK, msg="获取成功", data=data)
"collect": "1" if enterprise.id in company_ids else "2", # 关注状态码1关注,2未关注 #
"choice": "2" # 1太原企业,2全国企业 #
} # # ty+全国企业信息详情
else: # @api_mobile.route('/companyDetail', methods=['POST'])
return jsonify(code=RET.NODATA, msg="查无数据")
return jsonify(code=RET.OK, msg="获取成功", data=data)
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误")
# 太原市创新资源机构列表(高等院校和告高职转告合并,高职专高作为第二分类,合并两个表)
@api_mobile.route('/innovate/orgs', methods=['POST'])
# @login_required # @login_required
def orgs(): # def company_detail():
'''创新资源机构列表''' # '''
req_dict = request.get_json() # 企业信息详情
inid = req_dict.get("inid") # 行业id # :return:
cate = req_dict.get("cate") # 行业等级,(高端设备等五个为"1",子行业为"2") # '''
# # 获取用户id
cateone = req_dict.get("cateone") # 机构类型id. 高等院校1,科研机构2,创新平台3,产业服务平台4 # token = request.headers["token"]
catetwo = req_dict.get("catetwo") # 机构类型2 id # user = verify_token(token)
# user_id = user.id # 用户id
page = req_dict.get("page") # 分页页码 # # user_id = 5
perpage = req_dict.get("perpage") # 分页大小 #
# req_dict = request.get_json()
# 校验参数完整性 # _id = req_dict.get("id") # 企业id
if not all([cateone, page, perpage]): # choice = req_dict.get("choice") # 企业选择
return jsonify(code=RET.PARAMERR, msg="创新资源机构一类参数不完整") #
# # 校验参数完整性
if (inid and not cate) or (cate and not inid): # if not all([_id, choice]):
return jsonify(code=RET.PARAMERR, msg="行业参数不完整") # return jsonify(code=RET.PARAMERR, msg="参数不完整")
# if cate and not inid: #
# return jsonify(code=RET.PARAMERR, msg="行业参数不完整") # try:
# if choice == "1":
if cateone == 1: # 高等院校 # company = Company.query.get(_id)
try: # user = User.query.get(user_id) # 获取关注列表
if inid: # if user:
name = Industry.query.filter_by(nid=inid).first().oname # company_ids = [coms.id for coms in user.company]
if cate == "1": # else:
college = College.query.filter(College.navigator.like("%{}%".format(name))) # company_ids = []
else: # if company:
college = College.query.filter(College.navigat.like("%{}%".format(name))) # province = company.province if company.province else ""
else: # city = company.city if company.city else ""
college = College.query.filter_by() # if city == province:
if catetwo: # city = ''
college = college.filter_by(cateid=catetwo) # district = company.district if company.district else ""
# data = {"id": company.id,
size = college.count() # "company_name": company.company_name,
college = college.paginate(page, perpage).items # "legal": company.legal if company.legal else "", # 法人
# "status": company.status if company.status else "", # 状态
data = {"df": [{"id": i.id, # "build_date": str(company.build_date)[:10] if company.build_date else "", # 成立日期
"name": i.name, # "capital": company.capital if company.capital else "", # 注册资本
"nature": i.nature if i.nature else "-", # 办学性质 # "telephone": company.telephone if company.telephone else "", # 电话
"build_date": i.buildate if i.buildate else "-", # 时间 # "address": company.address if company.address else "", # 地址
"clas": i.clas if i.clas else "-", # 类别 # "location": province + city + district,
"cateone": cateone} for i in college], #
"size": size} # "email": company.email if company.email else "-", # 邮箱
return jsonify(code=RET.OK, msg="查询成功", data=data) # # "web_site": company.web_site if company.web_site else "-", # 网址
except Exception as e: # "company_info": company.company_info if company.company_info else "", # 简介
current_app.logger.error(e) # "social_code": company.social_code if company.social_code else "", # 社会统一信用代码
return jsonify(code=RET.DATAERR, msg="参数错误") # "tax_code": company.tax_code if company.tax_code else "", # 纳税人识别号
elif cateone == 2: # 科研机构 # "register_code": company.register_code if company.register_code else "", # 注册号
if inid: # "company_code": company.company_code if company.company_code else "", # 组织机构代码
name = Industry.query.filter_by(nid=inid).first().oname # "bao": company.bao_num if company.bao_num else 0, # 组织机构代码
if cate == "1": # "entype": company.entype if company.entype else "", # 企业类型
scientific = Scientific.query.filter(Scientific.navigator.like("%{}%".format(name))) # "industry": company.company_industry if company.company_industry else "", # 所属行业
else: # "scope": company.business_scope if company.business_scope else "", # 经营范围
scientific = Scientific.query.filter(Scientific.navigat.like("%{}%".format(name))) # "taking": company.takingn if company.takingn else "", # 营收
else: # "jwd": {"lng": company.lng if company.lng else "-",
scientific = Scientific.query.filter_by() # "lat": company.lat if company.lat else "-"},
size = scientific.count() # # "high_new": "高新技术企业" if company.high_new else "-",
scientific = scientific.paginate(page, perpage).items # "collect": "1" if company.id in company_ids else "2", # 关注状态码1关注,2未关注
data = {"df": [{"id": i.id, # "choice": "1" # 1太原企业,2全国企业
"name": i.name, # }
"telephone": str(i.telephone) if i.telephone else "-", # 电话 # else:
"address": i.address if i.address else "-", # 地址 # return jsonify(code=RET.NODATA, msg="查无数据")
"cateone": cateone} for i in scientific], # return jsonify(code=RET.OK, msg="获取成功", data=data)
"size": size} # else:
return jsonify(code=RET.OK, msg="查询成功", data=data) # enterprise = Enterprise.query.get(_id)
elif cateone == 3: # 创新平台3 # user = User.query.get(user_id) # 获取关注列表
if inid: # if user:
name = Industry.query.filter_by(nid=inid).first().oname # company_ids = [coms.id for coms in user.enterprise]
if cate == "1": # else:
lab = Lab.query.filter(Lab.navigator.like("%{}%".format(name))) # company_ids = []
else: # if enterprise:
lab = Lab.query.filter(Lab.navigat.like("%{}%".format(name))) # data = {"id": enterprise.id,
else: # "company_name": enterprise.company_name,
lab = Lab.query.filter_by() # "legal": enterprise.legal if enterprise.legal else "", # 法人
if catetwo: # "status": enterprise.status if enterprise.status else "", # 状态
lab = lab.filter_by(cateid=catetwo) # "build_date": str(enterprise.build_date)[:10] if enterprise.build_date else "", # 成立日期
# "capital": enterprise.capital if enterprise.capital else "", # 注册资本
size = lab.count() # "telephone": enterprise.telephone if enterprise.telephone else "", # 电话
lab = lab.paginate(page, perpage).items # "address": enterprise.address if enterprise.address else "", # 地址
data = {"df": [{"id": i.id, # "email": enterprise.email if enterprise.email else "-", # 邮箱
"name": i.name, # # "web_site": company.web_site if company.web_site else "-", # 网址
# "cate": i.cate, # "company_info": enterprise.company_info if enterprise.company_info else "", # 简介
"address": i.address if i.address else "-", # 地址 # "social_code": enterprise.social_code if enterprise.social_code else "", # 社会统一信用代码
"cateone": cateone} for i in lab], # "tax_code": enterprise.tax_code if enterprise.tax_code else "", # 纳税人识别号
"size": size} # "register_code": enterprise.register_code if enterprise.register_code else "", # 注册号
return jsonify(code=RET.OK, msg="查询成功", data=data) # "company_code": enterprise.company_code if enterprise.company_code else "", # 组织机构代码
elif cateone == 4: # 产业服务平台 # "bao": enterprise.bao_num if enterprise.bao_num else 0, # 组织机构代码
if inid: # "entype": enterprise.entype if enterprise.entype else "", # 企业类型
name = Industry.query.filter_by(nid=inid).first().oname # "industry": enterprise.company_industry if enterprise.company_industry else "", # 所属行业
if cate == "1": # "scope": enterprise.business_scope if enterprise.business_scope else "", # 经营范围
platform = Platform.query.filter(Platform.navigator.like("%{}%".format(name))) # "taking": enterprise.takingn if enterprise.takingn else "", # 营收
else: # "jwd": {"lng": enterprise.lng if enterprise.lng else "-",
platform = Platform.query.filter(Platform.navigat.like("%{}%".format(name))) # "lat": enterprise.lat if enterprise.lat else "-"},
else: # # "high_new": "高新技术企业" if company.high_new else "-",
platform = Platform.query.filter_by() # "collect": "1" if enterprise.id in company_ids else "2", # 关注状态码1关注,2未关注
if catetwo: # "choice": "2" # 1太原企业,2全国企业
platform = platform.filter_by(cateid=catetwo) # }
# else:
size = platform.count() # return jsonify(code=RET.NODATA, msg="查无数据")
platform = platform.paginate(page, perpage).items # return jsonify(code=RET.OK, msg="获取成功", data=data)
data = {"df": [{"id": i.id, # except Exception as e:
"name": i.name, # current_app.logger.error(e)
# "cate": cateone, # return jsonify(code=RET.DBERR, msg="数据库查询错误")
"address": i.address if i.address else "-", # 地址 #
"cateone": cateone} for i in platform], #
"size": size} # # 太原市创新资源机构列表(高等院校和告高职转告合并,高职专高作为第二分类,合并两个表)
return jsonify(code=RET.OK, msg="查询成功", data=data) # @api_mobile.route('/innovate/orgs', methods=['POST'])
# # @login_required
else: # def orgs():
return jsonify(code=RET.PARAMERR, msg="参数错误") # '''创新资源机构列表'''
# req_dict = request.get_json()
# inid = req_dict.get("inid") # 行业id
# 太原园区列表 # cate = req_dict.get("cate") # 行业等级,(高端设备等五个为"1",子行业为"2")
@api_mobile.route('/carrier/garden', methods=['POST']) #
# cateone = req_dict.get("cateone") # 机构类型id. 高等院校1,科研机构2,创新平台3,产业服务平台4
# catetwo = req_dict.get("catetwo") # 机构类型2 id
#
# page = req_dict.get("page") # 分页页码
# perpage = req_dict.get("perpage") # 分页大小
#
# # 校验参数完整性
# if not all([cateone, page, perpage]):
# return jsonify(code=RET.PARAMERR, msg="创新资源机构一类参数不完整")
#
# if (inid and not cate) or (cate and not inid):
# return jsonify(code=RET.PARAMERR, msg="行业参数不完整")
# # if cate and not inid:
# # return jsonify(code=RET.PARAMERR, msg="行业参数不完整")
#
# if cateone == 1: # 高等院校
# try:
# if inid:
# name = Industry.query.filter_by(nid=inid).first().oname
# if cate == "1":
# college = College.query.filter(College.navigator.like("%{}%".format(name)))
# else:
# college = College.query.filter(College.navigat.like("%{}%".format(name)))
# else:
# college = College.query.filter_by()
# if catetwo:
# college = college.filter_by(cateid=catetwo)
#
# size = college.count()
# college = college.paginate(page, perpage).items
#
# data = {"df": [{"id": i.id,
# "name": i.name,
# "nature": i.nature if i.nature else "-", # 办学性质
# "build_date": i.buildate if i.buildate else "-", # 时间
# "clas": i.clas if i.clas else "-", # 类别
# "cateone": cateone} for i in college],
# "size": size}
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DATAERR, msg="参数错误")
# elif cateone == 2: # 科研机构
# if inid:
# name = Industry.query.filter_by(nid=inid).first().oname
# if cate == "1":
# scientific = Scientific.query.filter(Scientific.navigator.like("%{}%".format(name)))
# else:
# scientific = Scientific.query.filter(Scientific.navigat.like("%{}%".format(name)))
# else:
# scientific = Scientific.query.filter_by()
# size = scientific.count()
# scientific = scientific.paginate(page, perpage).items
# data = {"df": [{"id": i.id,
# "name": i.name,
# "telephone": str(i.telephone) if i.telephone else "-", # 电话
# "address": i.address if i.address else "-", # 地址
# "cateone": cateone} for i in scientific],
# "size": size}
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# elif cateone == 3: # 创新平台3
# if inid:
# name = Industry.query.filter_by(nid=inid).first().oname
# if cate == "1":
# lab = Lab.query.filter(Lab.navigator.like("%{}%".format(name)))
# else:
# lab = Lab.query.filter(Lab.navigat.like("%{}%".format(name)))
# else:
# lab = Lab.query.filter_by()
# if catetwo:
# lab = lab.filter_by(cateid=catetwo)
#
# size = lab.count()
# lab = lab.paginate(page, perpage).items
# data = {"df": [{"id": i.id,
# "name": i.name,
# # "cate": i.cate,
# "address": i.address if i.address else "-", # 地址
# "cateone": cateone} for i in lab],
# "size": size}
# return jsonify(code=RET.OK, msg="查询成功", data=data)
# elif cateone == 4: # 产业服务平台
# if inid:
# name = Industry.query.filter_by(nid=inid).first().oname
# if cate == "1":
# platform = Platform.query.filter(Platform.navigator.like("%{}%".format(name)))
# else:
# platform = Platform.query.filter(Platform.navigat.like("%{}%".format(name)))
# else:
# platform = Platform.query.filter_by()
# if catetwo:
# platform = platform.filter_by(cateid=catetwo)
#
# size = platform.count()
# platform = platform.paginate(page, perpage).items
# data = {"df": [{"id": i.id,
# "name": i.name,
# # "cate": cateone,
# "address": i.address if i.address else "-", # 地址
# "cateone": cateone} for i in platform],
# "size": size}
# return jsonify(code=RET.OK, msg="查询成功", data=data)
#
# else:
# return jsonify(code=RET.PARAMERR, msg="参数错误")
#
#
# # 太原园区列表
# @api_mobile.route('/carrier/garden', methods=['POST'])
# # @login_required
# def garden():
# '''创新资源机构列表'''
# req_dict = request.get_json()
# inid = req_dict.get("inid") # 行业id
# cate = req_dict.get("cate") # 行业等级,(高端设备等五个为"1",子行业为"2")
#
# page = req_dict.get("page") # 分页页码
# perpage = req_dict.get("perpage") # 分页大小
#
# keyword = req_dict.get("keyword") # 搜索园区姓名
# level = req_dict.get("level") # 园区级别
#
# # 校验参数完整性
# if not all([page, perpage]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# try:
# if inid:
# name = Industry.query.filter_by(nid=inid).first().oname # 获取导航对应的真名
# if cate == "1":
# induzone = Induzone.query.filter(Induzone.navigator.like("%{}%".format(name)))
# else:
# induzone = Induzone.query.filter(Induzone.navigat.like("%{}%".format(name)))
# else:
# induzone = Induzone.query.filter_by()
# if keyword:
# induzone = induzone.filter(Induzone.name.like("%{}%".format(keyword))) # 查询词
# if level:
# induzone = induzone.filter_by(level=level) # 园区级别筛选
#
# size = induzone.count() # 分页总数
# induzone = induzone.paginate(page, perpage).items
#
# data = {"garden": [{"id": i.id,
# "name": i.name,
# "level": i.level if i.level else "-", # 级别
# # "cate": i.cate, # 园区类型
# "area": i.area if i.area else "-", # 面基
# "cluster": i.cluster if i.cluster else "" # 集群
# } for i in induzone],
# "size": size}
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库查询错误")
#
# return jsonify(code=RET.OK, msg="查询成功", data=data)
#
#
# # 雷达监测页企业数量趋势统计
# @api_mobile.route('/view_radar/tendency', methods=['POST'])
# @login_required # @login_required
def garden(): # def tendency():
'''创新资源机构列表''' # '''雷达监测页企业数量统计'''
req_dict = request.get_json() # req_dict = request.get_json()
inid = req_dict.get("inid") # 行业id # inid = req_dict.get("inid") # 行业id
cate = req_dict.get("cate") # 行业等级,(高端设备等五个为"1",子行业为"2") # area = req_dict.get("area") # [省,市,区]
# province = area[0]
page = req_dict.get("page") # 分页页码 # city = area[1]
perpage = req_dict.get("perpage") # 分页大小 # district = area[2]
# product = req_dict.get("product") # 企业产品
keyword = req_dict.get("keyword") # 搜索园区姓名 # sone = req_dict.get("sone") # 选择1,1企业个数,2注册资本
level = req_dict.get("level") # 园区级别 # stwo = req_dict.get("stwo") # 选择2, 1年度,2季度,3月度
# sthr = req_dict.get("sthr") # 选择3, 1新增量,2累积量
# 校验参数完整性 #
if not all([page, perpage]): # # 校验参数完整性
return jsonify(code=RET.PARAMERR, msg="参数不完整") # if not all([area, sone, stwo, sthr]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
try: #
if inid: # try:
name = Industry.query.filter_by(nid=inid).first().oname # 获取导航对应的真名 # if inid:
if cate == "1": # enterprise = Enterprise.query.filter_by(c_type=inid)
induzone = Induzone.query.filter(Induzone.navigator.like("%{}%".format(name))) # else:
else: # enterprise = Enterprise.query.filter_by()
induzone = Induzone.query.filter(Induzone.navigat.like("%{}%".format(name))) #
else: # if province:
induzone = Induzone.query.filter_by() # enterprise = enterprise.filter_by(province=province)
if keyword: # if city:
induzone = induzone.filter(Induzone.name.like("%{}%".format(keyword))) # 查询词 # enterprise = enterprise.filter_by(city=city)
if level: # if district:
induzone = induzone.filter_by(level=level) # 园区级别筛选 # enterprise = enterprise.filter_by(district=district)
# if product:
size = induzone.count() # 分页总数 # # 有可能会变成模糊查询
induzone = induzone.paginate(page, perpage).items # enterprise = enterprise.filter(Enterprise.product_all.like("%{}%".format(product)))
# # company = company.filter_by(product_all=product)
data = {"garden": [{"id": i.id, #
"name": i.name, # yearn = datetime.datetime.now().year + 1 # 现在年份
"level": i.level if i.level else "-", # 级别 # scope = [i for i in range(1980, yearn, 5)] # 年份范围
# "cate": i.cate, # 园区类型 # months = [(1, 3), (4, 6), (7, 9), (10, 12)] # 季度
"area": i.area if i.area else "-", # 面基 # data = list()
"cluster": i.cluster if i.cluster else "" # 集群 # if sthr == 1: # 新增量
} for i in induzone], # if stwo == 1: # 年度,1980-2020
"size": size} # for year in scope:
except Exception as e: # result = enterprise.filter(extract("year", Enterprise.build_date) == year)
current_app.logger.error(e) # if sone == 1: # 企业个数
return jsonify(code=RET.DBERR, msg="数据库查询错误") # nums = result.count()
# # data[year] = nums
return jsonify(code=RET.OK, msg="查询成功", data=data) # data.append({"lable": year, "value": nums})
# else: # 注册资本
# cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
# 雷达监测页企业数量趋势统计 # # data[year] = round(cnums, 2) if cnums else 0
@api_mobile.route('/view_radar/tendency', methods=['POST']) # data.append({"lable": year, "value": round(cnums, 2) if cnums else 0})
@login_required # elif stwo == 2: # 2020年季度
def tendency(): # for jd in range(len(months)):
'''雷达监测页企业数量统计''' # result = enterprise.filter(and_(extract("year", Enterprise.build_date) == (yearn - 1),
req_dict = request.get_json() # extract("month", Enterprise.build_date).between(months[jd][0],
inid = req_dict.get("inid") # 行业id # months[jd][1])))
area = req_dict.get("area") # [省,市,区] # if sone == 1: # 企业个数
province = area[0] # nums = result.count()
city = area[1] # # data[(jd + 1)] = nums
district = area[2] # data.append({"lable": (jd + 1), "value": nums})
product = req_dict.get("product") # 企业产品 # else: # 注册资本
sone = req_dict.get("sone") # 选择1,1企业个数,2注册资本 # cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
stwo = req_dict.get("stwo") # 选择2, 1年度,2季度,3月度 # # data[(jd + 1)] = round(cnums, 2) if cnums else 0
sthr = req_dict.get("sthr") # 选择3, 1新增量,2累积量 # data.append({"lable": (jd + 1), "value": round(cnums, 2) if cnums else 0})
# elif stwo == 3: # 2020年月度
# 校验参数完整性 # for m in range(1, 13):
if not all([area, sone, stwo, sthr]): # result = enterprise.filter(and_(extract("year", Enterprise.build_date) == (yearn - 1),
return jsonify(code=RET.PARAMERR, msg="参数不完整") # extract("month", Enterprise.build_date) == m))
# if sone == 1: # 企业个数
try: # nums = result.count()
if inid: # # data[m] = nums
enterprise = Enterprise.query.filter_by(c_type=inid) # data.append({"lable": m, "value": nums})
else: # else: # 注册资本
enterprise = Enterprise.query.filter_by() # cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
# # data[m] = round(cnums, 2) if cnums else 0
if province: # data.append({"lable": m, "value": round(cnums, 2) if cnums else 0})
enterprise = enterprise.filter_by(province=province) # elif sthr == 2: # 累积量
if city: # if stwo == 1: # 年度,1980-2020
enterprise = enterprise.filter_by(city=city) # for year in scope:
if district: # result = enterprise.filter(extract("year", Enterprise.build_date) <= year)
enterprise = enterprise.filter_by(district=district) # if sone == 1: # 企业个数
if product: # nums = result.count()
# 有可能会变成模糊查询 # # data[year] = nums
enterprise = enterprise.filter(Enterprise.product_all.like("%{}%".format(product))) # data.append({"lable": year, "value": nums})
# company = company.filter_by(product_all=product) # else: # 注册资本
# cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
yearn = datetime.datetime.now().year + 1 # 现在年份 # # data[year] = round(cnums, 2) if cnums else 0
scope = [i for i in range(1980, yearn, 5)] # 年份范围 # data.append({"lable": year, "value": round(cnums, 2) if cnums else 0})
months = [(1, 3), (4, 6), (7, 9), (10, 12)] # 季度 # elif stwo == 2: # 2020年季度
data = list() # for jd in range(len(months)):
if sthr == 1: # 新增量 # result = enterprise.filter(and_(extract("year", Enterprise.build_date) == (yearn - 1),
if stwo == 1: # 年度,1980-2020 # extract("month", Enterprise.build_date) <= months[jd][1]))
for year in scope: # if sone == 1: # 企业个数
result = enterprise.filter(extract("year", Enterprise.build_date) == year) # nums = result.count()
if sone == 1: # 企业个数 # # data[(jd + 1)] = nums
nums = result.count() # data.append({"lable": (jd + 1), "value": nums})
# data[year] = nums # else: # 注册资本
data.append({"lable": year, "value": nums}) # cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
else: # 注册资本 # # data[(jd + 1)] = round(cnums, 2) if cnums else 0
cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar() # data.append({"lable": (jd + 1), "value": round(cnums, 2) if cnums else 0})
# data[year] = round(cnums, 2) if cnums else 0 # elif stwo == 3: # 2020年月度
data.append({"lable": year, "value": round(cnums, 2) if cnums else 0}) # for m in range(1, 13):
elif stwo == 2: # 2020年季度 # result = enterprise.filter(and_(extract("year", Enterprise.build_date) == (yearn - 1),
for jd in range(len(months)): # extract("month", Enterprise.build_date) <= m))
result = enterprise.filter(and_(extract("year", Enterprise.build_date) == (yearn - 1), # if sone == 1: # 企业个数
extract("month", Enterprise.build_date).between(months[jd][0], # nums = result.count()
months[jd][1]))) # # data[m] = nums
if sone == 1: # 企业个数 # data.append({"lable": m, "value": nums})
nums = result.count() # else: # 注册资本
# data[(jd + 1)] = nums # cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar()
data.append({"lable": (jd + 1), "value": nums}) # data.append({"lable": m, "value": round(cnums, 2) if cnums else 0})
else: # 注册资本 # # data[m] = round(cnums, 2) if cnums else 0
cnums = result.with_entities(func.sum(Enterprise.capital_nums)).scalar() # else:
# data[(jd + 1)] = round(cnums, 2) if cnums else 0 # return jsonify(code=RET.DATAERR, msg="参数错误")
data.append({"lable": (jd + 1), "value": round(cnums, 2) if cnums else 0}) #
elif stwo == 3: # 2020年月度 # except Exception as e:
for m in range(1, 13): # current_app.logger.error(e)
result = enterprise.filter(and_(extract("year", Enterprise.build_date) == (yearn - 1), # return jsonify(code=RET.DBERR, msg="数据库查询错误")
extract("month", Enterprise.build_date) == m)) #
if sone == 1: # 企业个数 # return jsonify(code=RET.OK, msg="获取成功", data=data)
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
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: # 注册资本
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年季度
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年月度
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})
# data[m] = round(cnums, 2) if cnums else 0
else:
return jsonify(code=RET.DATAERR, msg="参数错误")
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="数据库查询错误")
return jsonify(code=RET.OK, msg="获取成功", data=data)
from flask import current_app, request, jsonify # from flask import current_app, request, jsonify
from apps.view_mobile import api_mobile # from apps.view_mobile import api_mobile
from sqlalchemy import extract, or_, and_ # from sqlalchemy import extract, or_, and_
from sqlalchemy.sql import func # from sqlalchemy.sql import func
from apps.models import * # from apps.models import *
from apps.util import login_required, verify_token # from apps.util import login_required, verify_token
from apps.utils.response_code import RET # from apps.utils.response_code import RET
from datetime import datetime, timedelta # from datetime import datetime, timedelta
import re # import re
from apps import db, constants, redis_store # from apps import db, constants, redis_store
#
#
# 手机端个人中心信息获取 # # 手机端个人中心信息获取
@api_mobile.route('/userInfo', methods=['GET']) # @api_mobile.route('/userInfo', methods=['GET'])
@login_required
def user_info():
# 获取用户id
token = request.headers["token"]
user = verify_token(token)
user_id = user.id # 用户id
# user_id = 5 # 用户id
try:
user = User.query.get(user_id)
if user:
data = {"id": user.id,
"name": user.name if user.name else "-", # 用户名
"mobile": user.mobile, # 手机号
"unit": user.unit if user.unit else "", # 机构
"section": user.section if user.section else "", # 部门
"position": user.position if user.position else "", # 职务
"sex": user.sex if user.sex else "", # 性别,1男2女
"email": user.email if user.email else "" # 邮箱
}
return jsonify(code=RET.OK, msg="查询成功", data=data)
return jsonify(code=RET.SESSIONERR, msg="无法获取信息")
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="参数错误")
# 手机端个人中心用户名修改
@api_mobile.route('/editName', methods=['POST'])
# @login_required # @login_required
def edit_name(): # def user_info():
# 获取用户id # # 获取用户id
# token = request.headers["token"] # token = request.headers["token"]
# user = verify_token(token) # user = verify_token(token)
# user_id = user.id # 用户id # user_id = user.id # 用户id
# user_id = 5 # 用户id # # user_id = 5 # 用户id
req_dict = request.get_json() #
uname = req_dict.get("uname") # 用户名 # try:
user_id = req_dict.get("id") # 用户id # user = User.query.get(user_id)
# 校验参数完整性 # if user:
if not all([uname]): # data = {"id": user.id,
return jsonify(code=RET.PARAMERR, msg="参数不完整") # "name": user.name if user.name else "-", # 用户名
# "mobile": user.mobile, # 手机号
# 用户名唯一(字母开头,长度4-15) # "unit": user.unit if user.unit else "", # 机构
try: # "section": user.section if user.section else "", # 部门
patten = "^[a-zA-Z][\w]*[\w]*$" # "position": user.position if user.position else "", # 职务
if re.match(patten, uname) and re.match(patten, uname).string == uname: # "sex": user.sex if user.sex else "", # 性别,1男2女
user = User.query.filter_by(name=uname).filter(User.id != user_id).first() # "email": user.email if user.email else "" # 邮箱
if user: # }
return jsonify(code=RET.DATAEXIST, msg="用户名已存在") # return jsonify(code=RET.OK, msg="查询成功", data=data)
else: # return jsonify(code=RET.SESSIONERR, msg="无法获取信息")
return jsonify(code=RET.DATAERR, 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="用户名格式错误") #
#
try: # # 手机端个人中心用户名修改
user = User.query.get(user_id) # @api_mobile.route('/editName', methods=['POST'])
user.name = uname # # @login_required
db.session.commit() # def edit_name():
# # 获取用户id
return jsonify(code=RET.OK, msg="修改成功") # # token = request.headers["token"]
except Exception as e: # # user = verify_token(token)
current_app.logger.error(e) # # user_id = user.id # 用户id
return jsonify(code=RET.DBERR, msg="参数错误") # # user_id = 5 # 用户id
# req_dict = request.get_json()
# uname = req_dict.get("uname") # 用户名
# 修改手机号 # user_id = req_dict.get("id") # 用户id
@api_mobile.route("/editPhone", methods=["POST"]) # # 校验参数完整性
# @login_required # if not all([uname]):
def edit_phone(): # return jsonify(code=RET.PARAMERR, msg="参数不完整")
# token = request.headers["token"] #
# user = verify_token(token) # # 用户名唯一(字母开头,长度4-15)
# user_id = user.id # try:
# user_id = 5 # patten = "^[a-zA-Z][\w]*[\w]*$"
# if re.match(patten, uname) and re.match(patten, uname).string == uname:
req_dict = request.get_json() # user = User.query.filter_by(name=uname).filter(User.id != user_id).first()
user_id = req_dict.get("user_id") # if user:
mobile = req_dict.get("mobile") # return jsonify(code=RET.DATAEXIST, msg="用户名已存在")
sms_code = req_dict.get("sms_code") # else:
# 校验参数完整性 # return jsonify(code=RET.DATAERR, msg="用户名格式错误,字母开头")
if not all([mobile, mobile]): # except Exception as e:
return jsonify(code=RET.PARAMERR, msg="参数不完整") # current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="用户名格式错误")
# 校验手机号格式 #
if not re.match(r'^1[3456789]\d{9}$', mobile): # try:
return jsonify(code=RET.PARAMERR, msg="手机号格式错误") # user = User.query.get(user_id)
# user.name = uname
# 判断短信验证码是否失效 # db.session.commit()
if not redis_store: #
return jsonify(code=RET.NODATA, msg="短信验证码失效") # return jsonify(code=RET.OK, msg="修改成功")
# 获取短信验证码 # except Exception as e:
try: # current_app.logger.error(e)
real_sms_code = redis_store.get('sms_code_{}'.format(mobile)).decode() # return jsonify(code=RET.DBERR, msg="参数错误")
# real_sms_code = "123456" #
except Exception as e: #
current_app.logger.error(e) # # 修改手机号
return jsonify(code=RET.DBERR, msg="redis数据库异常") # @api_mobile.route("/editPhone", methods=["POST"])
# # @login_required
# 判断用户填写短信验证码是否一致 # def edit_phone():
if real_sms_code != sms_code: # # token = request.headers["token"]
# if "123456" != sms_code: # # user = verify_token(token)
return jsonify(code=RET.DATAERR, msg="短信验证码错误") # # user_id = user.id
# # user_id = 5
# 删除redis中的短信验证码,防止重复校验 #
try: # req_dict = request.get_json()
redis_store.delete("sms_code_{}".format(mobile)) # user_id = req_dict.get("user_id")
except Exception as e: # mobile = req_dict.get("mobile")
current_app.logger.error(e) # sms_code = req_dict.get("sms_code")
# # 校验参数完整性
# 获取用户 # if not all([mobile, mobile]):
try: # return jsonify(code=RET.PARAMERR, msg="参数不完整")
user = User.query.filter_by(mobile=mobile).first() #
except Exception as e: # # 校验手机号格式
current_app.logger.error(e) # if not re.match(r'^1[3456789]\d{9}$', mobile):
return jsonify(code=RET.DBERR, msg="获取用户信息失败") # return jsonify(code=RET.PARAMERR, msg="手机号格式错误")
#
if user: # # 判断短信验证码是否失效
return jsonify(code=RET.DATAEXIST, msg="手机号已被注册") # if not redis_store:
# return jsonify(code=RET.NODATA, msg="短信验证码失效")
# 修改手机号 # # 获取短信验证码
try: # try:
user = User.query.get(user_id) # real_sms_code = redis_store.get('sms_code_{}'.format(mobile)).decode()
user.mobile = mobile # # real_sms_code = "123456"
db.session.commit() # except Exception as e:
return jsonify(code=RET.OK, msg="修改成功") # current_app.logger.error(e)
except Exception as e: # return jsonify(code=RET.DBERR, msg="redis数据库异常")
current_app.logger.error(e) #
return jsonify(code=RET.DBERR, msg="数据库错误") # # 判断用户填写短信验证码是否一致
# if real_sms_code != sms_code:
# # if "123456" != sms_code:
# 手机端个人中心性别修改 # return jsonify(code=RET.DATAERR, msg="短信验证码错误")
@api_mobile.route('/editSex', methods=['POST']) #
# @login_required # # 删除redis中的短信验证码,防止重复校验
def edit_sex(): # try:
# 获取用户id # redis_store.delete("sms_code_{}".format(mobile))
# token = request.headers["token"] # except Exception as e:
# user = verify_token(token) # current_app.logger.error(e)
# user_id = user.id # 用户id #
# user_id = 5 # 用户id # # 获取用户
req_dict = request.get_json() # try:
user_id = req_dict.get("id") # 用户id # user = User.query.filter_by(mobile=mobile).first()
sex = req_dict.get("sex") # 男1女2 # except Exception as e:
# 校验参数完整性 # current_app.logger.error(e)
if not all([sex]): # return jsonify(code=RET.DBERR, msg="获取用户信息失败")
return jsonify(code=RET.PARAMERR, msg="参数不完整") #
# if user:
try: # return jsonify(code=RET.DATAEXIST, msg="手机号已被注册")
user = User.query.get(user_id) #
user.sex = sex # # 修改手机号
db.session.commit() # try:
return jsonify(code=RET.OK, msg="修改成功") # user = User.query.get(user_id)
except Exception as e: # user.mobile = mobile
current_app.logger.error(e) # db.session.commit()
return jsonify(code=RET.DBERR, msg="参数错误") # return jsonify(code=RET.OK, msg="修改成功")
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库错误")
#
#
# # 手机端个人中心性别修改
# @api_mobile.route('/editSex', methods=['POST'])
# # @login_required
# def edit_sex():
# # 获取用户id
# # token = request.headers["token"]
# # user = verify_token(token)
# # user_id = user.id # 用户id
# # user_id = 5 # 用户id
# req_dict = request.get_json()
# user_id = req_dict.get("id") # 用户id
# sex = req_dict.get("sex") # 男1女2
# # 校验参数完整性
# if not all([sex]):
# return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# try:
# user = User.query.get(user_id)
# user.sex = sex
# db.session.commit()
# return jsonify(code=RET.OK, msg="修改成功")
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="参数错误")
...@@ -597,8 +597,8 @@ def detail(): ...@@ -597,8 +597,8 @@ def detail():
data = { data = {
"flag": user.flag, "flag": user.flag,
"real_name": user_info.real_name, # 名字 "real_name": user_info.real_name, # 名字
"age": user_info.age, # 年龄 # "age": user_info.age, # 年龄
"sex": user_info.sex, # 性别 # "sex": user_info.sex, # 性别
"mobile": user_info.mobile, # 手机号 "mobile": user_info.mobile, # 手机号
# "username": user_info.name, # 用户名 # "username": user_info.name, # 用户名
# "email": user_info.email, # 邮箱 # "email": user_info.email, # 邮箱
...@@ -792,8 +792,8 @@ def fix_user_info(): ...@@ -792,8 +792,8 @@ def fix_user_info():
return jsonify(code=RET.SESSIONERR, msg='个人信息校验失败,请重新登录!') return jsonify(code=RET.SESSIONERR, msg='个人信息校验失败,请重新登录!')
req_dict = request.get_json() req_dict = request.get_json()
real_name = req_dict.get("real_name") real_name = req_dict.get("real_name")
age = req_dict.get("age") # age = req_dict.get("age")
sex = req_dict.get("sex") # sex = req_dict.get("sex")
# name = req_dict.get("name") # name = req_dict.get("name")
position = req_dict.get("position") position = req_dict.get("position")
...@@ -812,11 +812,11 @@ def fix_user_info(): ...@@ -812,11 +812,11 @@ def fix_user_info():
if belong_department: if belong_department:
user_information.belong_department = belong_department user_information.belong_department = belong_department
# 年龄 # 年龄
if age: # if age:
user_information.age = age # user_information.age = age
# 性别 1 - 男 2 - 女 # # 性别 1 - 男 2 - 女
if sex: # if sex:
user_information.sex = sex # user_information.sex = sex
# 职务 # 职务
if position: if position:
user_information.position = position user_information.position = position
......
...@@ -46,105 +46,105 @@ def user_code(): ...@@ -46,105 +46,105 @@ def user_code():
# 异步邮箱发送信息 # 异步邮箱发送信息
def send_async_email(mail, app, msg): # def send_async_email(mail, app, msg):
with app.app_context(): # with app.app_context():
mail.send(msg) # mail.send(msg)
# 给邮箱发验证码 # 给邮箱发验证码
@api_user.route("/email_code", methods=["POST"]) # @api_user.route("/email_code", methods=["POST"])
def send_email_code(): # def send_email_code():
''' # '''
向邮箱送验证码 # 向邮箱送验证码
:return: # :return:
''' # '''
# 获取请求参数,转化字典 # # 获取请求参数,转化字典
req_dict = request.get_json() # req_dict = request.get_json()
email = req_dict.get('email') # 邮箱号 # email = req_dict.get('email') # 邮箱号
#
# 校验参数完整性 # # 校验参数完整性
if not all([email]): # if not all([email]):
return jsonify(code=RET.PARAMERR, msg="参数不完整") # return jsonify(code=RET.PARAMERR, msg="参数不完整")
#
# 校验邮箱格式 # # 校验邮箱格式
if not re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email): # if not re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email):
return jsonify(code=RET.PARAMERR, msg="邮箱格式错误") # return jsonify(code=RET.PARAMERR, msg="邮箱格式错误")
#
# print(email) # # print(email)
# app = creat_app('product') # # app = creat_app('product')
app = creat_app('develop') # app = creat_app('develop')
mail = Mail(app) # mail = Mail(app)
sms_code = "%06d" % random.randint(0, 999999) # sms_code = "%06d" % random.randint(0, 999999)
#
msg = Message("中研认知产业链在线,欢迎您!", recipients=[email]) # msg = Message("中研认知产业链在线,欢迎您!", recipients=[email])
msg.body = "【中研认知产业链在线】您的验证码为:{},您正在进行邮箱绑定,如非本人操作,请忽略本邮件!".format(sms_code) # msg.body = "【中研认知产业链在线】您的验证码为:{},您正在进行邮箱绑定,如非本人操作,请忽略本邮件!".format(sms_code)
thread = threading.Thread(target=send_async_email, args=(mail, app, msg)) # thread = threading.Thread(target=send_async_email, args=(mail, app, msg))
thread.start() # thread.start()
#
try: # try:
redis_store.setex("sms_code_%s" % email, constants.SMS_CODE_REDIS_EXPIRES, sms_code) # redis_store.setex("sms_code_%s" % email, constants.SMS_CODE_REDIS_EXPIRES, sms_code)
# 保存发送给这个邮箱号的记录,防止用户在60s内再次出发发送短信的操作 # # 保存发送给这个邮箱号的记录,防止用户在60s内再次出发发送短信的操作
redis_store.setex("send_sms_code_%s" % email, constants.SEND_SMS_CODE_INTERVAL, 60) # redis_store.setex("send_sms_code_%s" % email, constants.SEND_SMS_CODE_INTERVAL, 60)
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="保存验证码异常")
print(redis_store.get('sms_code_{}'.format(email))) # print(redis_store.get('sms_code_{}'.format(email)))
return jsonify(code=RET.OK, msg="发送成功") # return jsonify(code=RET.OK, msg="发送成功")
@api_user.route("/changeEmail", methods=["POST"])
@login_required
def change_email():
token = request.headers["token"]
user = verify_token(token)
user_id = user.id
req_dic = request.get_json()
email = req_dic.get("email")
email_code = req_dic.get("email_code")
try:
user_information = User.query.get(user_id)
if not all([email, email_code]):
return jsonify(code=RET.PARAMERR, msg="参数不全")
if email:
user_information.email = email
if not email_code:
return jsonify(code=RET.NODATA, msg="验证码不能为空")
if not re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$",
user_information.email):
return jsonify(code=RET.PARAMERR, msg="邮箱格式错误")
# 获取邮箱验证码
try:
real_sms_code = redis_store.get('sms_code_{}'.format(user_information.email)).decode()
except Exception as e:
current_app.logger.error(e)
return jsonify(code=RET.DBERR, msg="redis数据库异常")
# 判断邮箱验证码是否失效
if not redis_store:
return jsonify(code=RET.NODATA, msg="短信验证码失效")
# 删除redis中的邮箱验证码,防止重复校验 # @api_user.route("/changeEmail", methods=["POST"])
try: # @login_required
redis_store.delete("sms_code_{}".format(user_information.email)) # def change_email():
except Exception as e: # token = request.headers["token"]
current_app.logger.error(e) # user = verify_token(token)
return jsonify(code=RET.DBERR, msg="redis数据库异常") # user_id = user.id
# 判断用户填写短信验证码是否一致 #
if real_sms_code != email_code: # req_dic = request.get_json()
return jsonify(code=RET.DATAERR, msg="邮箱验证码错误") # email = req_dic.get("email")
db.session.commit() # email_code = req_dic.get("email_code")
return jsonify(code=RET.OK, msg="更改成功") # try:
except Exception as e: # user_information = User.query.get(user_id)
current_app.logger.error(e) #
return jsonify(code=RET.DBERR, msg="数据库错误") # if not all([email, email_code]):
# return jsonify(code=RET.PARAMERR, msg="参数不全")
# if email:
# user_information.email = email
#
# if not email_code:
# return jsonify(code=RET.NODATA, msg="验证码不能为空")
#
# if not re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$",
# user_information.email):
# return jsonify(code=RET.PARAMERR, msg="邮箱格式错误")
#
# # 获取邮箱验证码
# try:
# real_sms_code = redis_store.get('sms_code_{}'.format(user_information.email)).decode()
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="redis数据库异常")
#
# # 判断邮箱验证码是否失效
# if not redis_store:
# return jsonify(code=RET.NODATA, msg="短信验证码失效")
#
# # 删除redis中的邮箱验证码,防止重复校验
# try:
# redis_store.delete("sms_code_{}".format(user_information.email))
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="redis数据库异常")
# # 判断用户填写短信验证码是否一致
# if real_sms_code != email_code:
# return jsonify(code=RET.DATAERR, msg="邮箱验证码错误")
# db.session.commit()
# return jsonify(code=RET.OK, msg="更改成功")
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="数据库错误")
# @api_user.route("/detail", methods=["GET"]) # @api_user.route("/detail", methods=["GET"])
......
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