From 6c6cd03e91e0552c16f5a205d920f7d24fc2786a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=9D=E5=B7=9D?= Date: Fri, 29 Apr 2022 11:27:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Implements/Others/TFSEFileImpl.py | 26 +++++---------- ObjectsCommon/Others/FECRFile.py | 4 +-- Routes/Other/TFSEFileRoute.py | 53 ++++++++++++++++++++++++++++--- Utils/AuthUtil.py | 10 +++--- 4 files changed, 63 insertions(+), 30 deletions(-) diff --git a/Implements/Others/TFSEFileImpl.py b/Implements/Others/TFSEFileImpl.py index ca81b13..e4a5565 100644 --- a/Implements/Others/TFSEFileImpl.py +++ b/Implements/Others/TFSEFileImpl.py @@ -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 diff --git a/ObjectsCommon/Others/FECRFile.py b/ObjectsCommon/Others/FECRFile.py index f4a37fd..2130600 100644 --- a/ObjectsCommon/Others/FECRFile.py +++ b/ObjectsCommon/Others/FECRFile.py @@ -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": "文件体" } diff --git a/Routes/Other/TFSEFileRoute.py b/Routes/Other/TFSEFileRoute.py index 3ac685e..15f2daf 100644 --- a/Routes/Other/TFSEFileRoute.py +++ b/Routes/Other/TFSEFileRoute.py @@ -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: diff --git a/Utils/AuthUtil.py b/Utils/AuthUtil.py index 267a041..7a2c22f 100644 --- a/Utils/AuthUtil.py +++ b/Utils/AuthUtil.py @@ -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