From da082a1a40fddf33ba398960f5cad38ea0691b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=9D=E5=B7=9D?= Date: Thu, 13 Jan 2022 14:14:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=AF=84=E4=BB=B7=E8=AF=81=E4=B9=A6=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file/TfseFile.py | 5 ++++- file/routes.py | 16 ++++++++++++++++ file/scripts.py | 12 ++++++++++++ input/scripts.py | 28 ++++++++++++++++++++++++---- 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/file/TfseFile.py b/file/TfseFile.py index 878ddc7..7e3aa3a 100644 --- a/file/TfseFile.py +++ b/file/TfseFile.py @@ -1,4 +1,4 @@ -from file.scripts import company_general_rating_report_by_fid +from file.scripts import company_general_rating_report_by_fid, company_general_rating_certification_by_fid class TfseFile: @@ -8,3 +8,6 @@ class TfseFile: def get_general_report(self): return company_general_rating_report_by_fid(self.fid) + + def get_general_certification(self): + return company_general_rating_certification_by_fid(self.fid) diff --git a/file/routes.py b/file/routes.py index 0eb458c..339aee9 100644 --- a/file/routes.py +++ b/file/routes.py @@ -20,3 +20,19 @@ def get_company_report(**kwargs): tfse_file.fid = request.args.get('file_id') response = Response(tfse_file.get_general_report(), content_type='application/pdf') return response + + +@file_route.route('/get_certification', methods=['GET']) +@verify_token +def get_certification_route(**kwargs): + """ + 查看公司评价结果证书 + Parameters: + - + Returns: + response pdf二进制文件流 + """ + tfse_file = TfseFile() + tfse_file.fid = request.args.get('file_id') + response = Response(tfse_file.get_general_report(), content_type='application/pdf') + return response diff --git a/file/scripts.py b/file/scripts.py index 4c4f5b0..ae57b09 100644 --- a/file/scripts.py +++ b/file/scripts.py @@ -11,3 +11,15 @@ def company_general_rating_report_by_fid(fid): """ filestream = find_file('综合信用报告', fid) return filestream + + +def company_general_rating_certification_by_fid(fid): + """ + 根据fid返回文件 + Args: + fid: + Returns: + filestream + """ + filestream = find_file('评价证书', fid) + return filestream diff --git a/input/scripts.py b/input/scripts.py index 67455a5..b70d411 100644 --- a/input/scripts.py +++ b/input/scripts.py @@ -82,11 +82,12 @@ def rating_records_by_cid(cid): records: 企业的评价记录 """ report_link = '/file/get_company_report?file_id={}' + certification_link = "/file/get_certification?file_id={}" records = find_rating_records({"企业ID": cid}) for record in records: if records is not None: record['报告'] = report_link.format(record['报告fid']) if record['报告fid'] is not None else None - record['证书'] = record['证书fid'] + record['证书'] = certification_link.format(record['证书fid']) if record['证书fid'] is not None else None record.pop('企业ID') record.pop('报告fid') record.pop('证书fid') @@ -269,7 +270,23 @@ def exec_general_rating_scripts(cid): # 生成证书 def gen_certified(): - pass + url = "http://139.9.249.34:51012/tfse_rating/certificate/generate_certificate" + token = "X0gSlC!YE8jmr2jJr&ilcjS83j!tsoh5" + headers = {'token': token, "Content-Type": "application/json;charset=UTF-8"} + data = { + "company": rating_inputs['企业名称'], + "cid": rating_inputs['企业ID'], + "rid": rating_inputs['评价ID'] + } + res = requests.post(url, headers=headers, data=json.dumps(data)) + if res.status_code == 200: + update_data = { + "证书fid": json.loads(res.text)['result']['FileID'] + } + update_rating_records({"评价ID": rid}, update_data) + return True + else: + return False # 生成企业主页数据 def company_index(): @@ -289,10 +306,13 @@ def exec_general_rating_scripts(cid): return False, "打分失败" if not gen_report(): - return False, "生成综合信用评价报告失败" + return False, "生成报告失败" + + if not gen_certified(): + return False, "生成证书失败" if not company_index(): - return False, "准备企业主页数据失败" + return False, "准备主页数据失败" update_rating_records({"评价ID": rid}, {"进行状态": "完成"})