update ESG证书

This commit is contained in:
P3ngSaM 2022-02-28 17:03:36 +08:00
parent 8976f11a89
commit 1a63d750d4
5 changed files with 122 additions and 15 deletions

View File

@ -22,6 +22,9 @@ class CertificateGenerator:
def gen_cover(self):
self.doc.drawImage(get_pic_path(pic_name='certificate_02.jpg'), 0, 0, 600, 850)
def gen_esg_cover(self):
self.doc.drawImage(get_pic_path(pic_name='certificate_esg.jpg'), 0, 0, 600, 850)
def gen_text(self):
self.doc.setFont('SourceHanSerifCN-Bold', 20)
margin = (Width - len(self.text_data['企业名称']) * 19) / 2
@ -37,12 +40,41 @@ class CertificateGenerator:
self.doc.setFont('SIMSUN', 10)
self.doc.drawString(4.6 * inch, 260, '有效日期:{}'.format(self.text_data['有效日期']))
def gen_esg_text(self):
# 企业名称
self.doc.setFont('SourceHanSerifCN-Bold', 20)
margin = (Width - len(self.text_data['企业名称']) * 19) / 2
self.doc.drawString(margin, 450, self.text_data['企业名称'])
# 统一社会信用代码
self.doc.setFont('SIMSUN', 12, leading=5)
self.doc.drawString(2.8 * inch, 433, '统一社会信用代码:{}'.format(self.text_data['统一社会信用代码']))
# ESG得分
self.doc.setFont('SIMSUN', 12, leading=5)
self.doc.setFillColor('#B79249')
self.doc.drawString(5.35 * inch, 357, '{}'.format(self.text_data['ESG得分']))
# 评价等级
self.doc.setFont('SourceHanSerifCN-Bold', 35)
self.doc.drawString(3.2 * inch, 285, '{}级企业'.format(self.text_data['评价等级']))
# 证书编号
self.doc.setFont('SIMSUN', 10)
self.doc.setFillColor('black')
self.doc.drawString(1.28 * inch, 260, '证书编号:{}'.format(self.text_data['证书编号']))
# 有效日期
self.doc.setFont('SIMSUN', 10)
self.doc.drawString(4.6 * inch, 260, '有效日期:{}'.format(self.text_data['有效日期']))
def gen(self):
self.gen_cover()
self.gen_text()
self.doc.showPage()
self.doc.save()
def gen_esg(self):
self.gen_esg_cover()
self.gen_esg_text()
self.doc.showPage()
self.doc.save()
if __name__ == '__main__':
data = {

View File

@ -32,6 +32,22 @@ def upload_pdf(name):
return False
def upload_esg_pdf(name):
"""
根据名称保存该企业证书
"""
try:
path = get_gen_report_path(name=name)
database = '评价'
collection = 'ESG评价证书'
fs = GridFS(client[database], collection)
content = open(path, 'rb').read()
pdf_id = fs.put(content, content_type='application/pdf', filename=name)
return str(pdf_id)
except Exception:
return False
def download_pdf(pdf_id):
"""
根据pdf_id查询pdf文件

View File

@ -7,7 +7,7 @@ from flask import Blueprint, request
from Certificate.PdfCertificate import CertificateGenerator
from Certificate.scripts.common import get_certificate_data
from Certificate.scripts.path_tool import get_gen_report_path
from Certificate.db import upload_pdf
from Certificate.db import upload_pdf, upload_esg_pdf
from common.scripts import verify_token
certificate_route = Blueprint('certificate', __name__)
@ -17,11 +17,12 @@ certificate_route = Blueprint('certificate', __name__)
@verify_token
def gen_certificate():
"""
描述
生成综合信用评价证书
Parameters:
company str 企业名称
cid str 企业ID
rid str 评价ID
type str 证书类型
Returns:
result: 证书FileID
"""
@ -37,7 +38,10 @@ def gen_certificate():
# 生成PDF报告文件以时间戳命名临时存储
certificate_file_name = '{}_{}.pdf'.format(req_body['company'], datetime.datetime.now().strftime('%Y%m%d'))
pdf_report = CertificateGenerator(name=certificate_file_name, text_data=param)
pdf_report.gen()
if len(param) > 5:
pdf_report.gen_esg()
else:
pdf_report.gen()
return certificate_file_name
@ -50,7 +54,10 @@ def gen_certificate():
res: 处理成功返回报告FileID处理失败返回False
"""
# 保存PDF报告文件删除临时存储的报告
file_id = upload_pdf(param)
if len(text_data) > 5:
file_id = upload_esg_pdf(param)
else:
file_id = upload_pdf(param)
certificate_path = get_gen_report_path(name=param)
os.remove(certificate_path)

View File

@ -14,19 +14,53 @@ def get_certificate_data(param):
Returns:
result: dict 证书所需数据
"""
# 企业基本信息
data_01 = find_tfse_db(db="企业", col="公司基本信息", query={'企业ID': param['cid']})[0]
# 评价结果
data_02 = find_tfse_db(db="评价", col="评价结果", query={"评价ID": param['rid']})[0]
def general():
"""
获取综合信用评价证书所需数据
Parameters:
-
Returns:
result: dict 证书所需数据
"""
# 企业基本信息
data_01 = find_tfse_db(db="企业", col="公司基本信息", query={'企业ID': param['cid']})[0]
# 评价结果
data_02 = find_tfse_db(db="评价", col="评价结果", query={"评价ID": param['rid']})[0]
info = dict()
info['企业名称'] = param['company']
info['统一社会信用代码'] = data_01['工商信息']['纳税人识别号']
info['企业级别'] = data_02['信用等级']
info['证书编号'] = generate_number()
info['有效日期'] = effective_date()
return info
info = dict()
info['企业名称'] = param['company']
info['统一社会信用代码'] = data_01['工商信息']['纳税人识别号']
info['企业级别'] = data_02['信用等级']
info['证书编号'] = generate_number()
info['有效日期'] = effective_date()
def esg():
"""
获取esg评价证书所需数据
Parameters:
-
Returns:
result: dict 证书所需数据
"""
# 企业基本信息
data_01 = find_tfse_db(db="企业", col="公司基本信息", query={'企业ID': param['cid']})[0]
# 评价结果
data_02 = find_tfse_db(db="评价", col="ESG评价结果", query={"评价ID": param['rid']})[0]
info = dict()
info['企业名称'] = param['company']
info['统一社会信用代码'] = data_01['工商信息']['纳税人识别号']
info['ESG得分'] = data_02['ESG得分']
info['评价等级'] = data_02['评价等级']
info['证书编号'] = generate_esg_number()
info['有效日期'] = effective_date()
return info
return info
if 'type' in param:
result = esg()
else:
result = general()
return result
def generate_number():
@ -47,6 +81,24 @@ def generate_number():
return number
def generate_esg_number():
"""
生成esg证书编号
Parameters:
-
Returns:
result: 证书编号
"""
project_type = 'ESG'
project_number = '02'
project_time = str(datetime.now().strftime('%Y%m%d%H%M'))
project_code = generate_code(project_type, project_number, project_time)
number = project_type + project_number + project_time + project_code
return number
def generate_code(param1, param2, param3):
"""
生成校验码4

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB