文件路由
This commit is contained in:
parent
d33a43089e
commit
6c6cd03e91
|
@ -17,23 +17,13 @@ class TFSEFileImpl(FECRFile):
|
|||
|
||||
def get_pdf(self):
|
||||
|
||||
file_type_map = {
|
||||
"cc_report": "综信报告",
|
||||
"cc_certificate": "综信证书",
|
||||
"esg_report": "ESG报告",
|
||||
"esg_certificate": "ESG证书"
|
||||
}
|
||||
file_stream = self.db.find_file(
|
||||
"文件",
|
||||
self.file_bucket,
|
||||
self.file_id
|
||||
)
|
||||
|
||||
try:
|
||||
file_stream = self.db.find_file(
|
||||
"文件",
|
||||
file_type_map[self.file_type],
|
||||
self.file_id
|
||||
)
|
||||
|
||||
if file_stream:
|
||||
self.file_body = Response(file_stream, content_type='application/pdf')
|
||||
else:
|
||||
self.file_body = None
|
||||
except Exception:
|
||||
if file_stream:
|
||||
self.file_body = Response(file_stream, content_type='application/pdf')
|
||||
else:
|
||||
self.file_body = None
|
||||
|
|
|
@ -8,12 +8,12 @@ class FECRFile(SpecObject):
|
|||
"""文件类"""
|
||||
|
||||
file_id = ValidateAttr(field='file_id', type=str)
|
||||
file_type = ValidateAttr(field='file_type', type=str)
|
||||
file_bucket = ValidateAttr(field='file_bucket', in_list=["综信报告", "综信证书", "ESG报告", "ESG证书"])
|
||||
file_body = ValidateAttr(field='file_body', type=Response, default=None)
|
||||
|
||||
fields_map = {
|
||||
"file_id": "文件ID",
|
||||
"file_type": "文件类型",
|
||||
"file_bucket": "文件桶",
|
||||
"file_body": "文件体"
|
||||
}
|
||||
|
||||
|
|
|
@ -7,13 +7,58 @@ from Utils.AuthUtil import verify_token, verify_report_view_auth
|
|||
file_route = Blueprint('file', __name__)
|
||||
|
||||
|
||||
@file_route.route('/pdf', methods=['GET'])
|
||||
@file_route.route('/get_cc_rating_report', methods=['GET'])
|
||||
@verify_token
|
||||
# @verify_report_view_auth
|
||||
@verify_report_view_auth
|
||||
def get_file(**kwargs):
|
||||
"""获取pdf文件"""
|
||||
"""获取综信报告"""
|
||||
impl = TFSEFileImpl()
|
||||
impl.file_type = request.args.get('file_type')
|
||||
impl.file_bucket = '综信报告'
|
||||
impl.file_id = request.args.get('file_id')
|
||||
impl.get_pdf()
|
||||
if impl.file_body:
|
||||
return impl.dict_to_return()
|
||||
else:
|
||||
return {"info": "文件不存在"}, 200
|
||||
|
||||
|
||||
@file_route.route('/get_cc_rating_certificate', methods=['GET'])
|
||||
@verify_token
|
||||
@verify_report_view_auth
|
||||
def get_file(**kwargs):
|
||||
"""获取综信证书"""
|
||||
impl = TFSEFileImpl()
|
||||
impl.file_bucket = '综信证书'
|
||||
impl.file_id = request.args.get('file_id')
|
||||
impl.get_pdf()
|
||||
if impl.file_body:
|
||||
return impl.dict_to_return()
|
||||
else:
|
||||
return {"info": "文件不存在"}, 200
|
||||
|
||||
|
||||
@file_route.route('/get_esg_rating_report', methods=['GET'])
|
||||
@verify_token
|
||||
@verify_report_view_auth
|
||||
def get_file(**kwargs):
|
||||
"""获取ESG评价报告"""
|
||||
impl = TFSEFileImpl()
|
||||
impl.file_bucket = 'ESG报告'
|
||||
impl.file_id = request.args.get('file_id')
|
||||
impl.get_pdf()
|
||||
if impl.file_body:
|
||||
return impl.dict_to_return()
|
||||
else:
|
||||
return {"info": "文件不存在"}, 200
|
||||
|
||||
|
||||
@file_route.route('/get_esg_rating_certificate', methods=['GET'])
|
||||
@verify_token
|
||||
@verify_report_view_auth
|
||||
def get_file(**kwargs):
|
||||
"""获取ESG评价证书"""
|
||||
impl = TFSEFileImpl()
|
||||
impl.file_bucket = 'ESG证书'
|
||||
impl.file_id = request.args.get('file_id')
|
||||
impl.get_pdf()
|
||||
if impl.file_body:
|
||||
|
|
|
@ -73,9 +73,7 @@ def check_block(func):
|
|||
|
||||
|
||||
def verify_report_view_auth(func):
|
||||
"""
|
||||
检查是否具有报告查看权限
|
||||
"""
|
||||
"""检查是否具有报告查看权限"""
|
||||
|
||||
db = MongoHelper("tfse_v0.21")
|
||||
|
||||
|
@ -86,13 +84,13 @@ def verify_report_view_auth(func):
|
|||
|
||||
records = db.find_all_data(
|
||||
"企业数据",
|
||||
"评级记录",
|
||||
"评价记录",
|
||||
{"企业ID": kwargs['cid']},
|
||||
["报告fid", "证书fid"]
|
||||
)
|
||||
|
||||
if not records:
|
||||
return {"info": "文件不存在"}, 200
|
||||
return {"info": "没有文件记录"}, 200
|
||||
|
||||
file_id_pool = list()
|
||||
for record in records:
|
||||
|
@ -102,7 +100,7 @@ def verify_report_view_auth(func):
|
|||
file_id_pool = list(filter(None, file_id_pool))
|
||||
|
||||
if file_id not in file_id_pool:
|
||||
return {"info": "无访问权限"}, 200
|
||||
return {"info": "没有访问权限"}, 200
|
||||
|
||||
return func(*args, **kwargs)
|
||||
return internal
|
||||
|
|
Loading…
Reference in New Issue