Merge branch 'test_ps' into 'master'

update 优化处理报告数据方法(制造业)

See merge request root/tfse_rating!5
This commit is contained in:
彭森 2022-04-01 07:06:43 +00:00
commit fef9680ab6
8 changed files with 688 additions and 622 deletions

View File

@ -226,5 +226,6 @@ class RatingModel:
"""
for item in self.financial_indicators:
item['企业ID'] = self.cid
item['评价ID'] = self.eid
item['企业名称'] = self.company
update_data('综信评价数据', '财指结果', {"企业ID": self.cid, "年报期": item['年报期']}, item)

View File

@ -49,15 +49,3 @@ class ReportModel:
return handle_manufacturing_content(self.doc, self.data)
elif industry == '信息技术业':
return handle_information_content(self.doc, self.data)
if __name__ == '__main__':
with open('../Report/static/test/report_data.json', 'r', encoding='utf-8') as f:
data = json.load(f)
with open('../Report/static/ReportTemplates/制造业.json', 'r', encoding='utf-8') as f:
doc = json.load(f)
model = ReportModel(data, doc)
text_model = model.report_values()
report_file_name = '{}_{}.pdf'.format(data['企业名称'], int(time.time()))
pdf_report = ReportGenerator(name=report_file_name, text_model=text_model)
pdf_report.gen_report()

View File

@ -6,8 +6,8 @@ import requests
from flask import Blueprint, request
from Report.PdfReport import ReportGenerator
from Report.ReportModel import ReportModel
from Report.db import update_data, upload_report_pdf
from Report.scripts.content_processing import handle_report_content
from Report.scripts.esg_contents import handle_esg_report_data
from Report.scripts.path_tool import get_gen_report_path
from common.scripts import verify_token, read_json_file
@ -83,7 +83,8 @@ def report_pdf():
report_template = read_json_file('/Report/static/ReportTemplates/{}.json'.format(prepare_report_data['data']['行业选择'][0])) # 根据行业获取报告模板
# 生成报告数据,保存报告数据
text_model = ReportModel(prepare_report_data['data'], report_template).report_values()
# text_model = ReportModel(prepare_report_data['data'], report_template).report_values()
text_model = handle_report_content(report_template, prepare_report_data['data'])
save_report_result = save_report_data({"评价ID": text_model['评价ID']}, text_model, text_model['企业名称'])
if save_report_result is not False:

View File

@ -0,0 +1,349 @@
import datetime
import json
def handle_report_content(param1, param2):
"""
制造业报告内容处理
Parameters:
param1: 报告模板
param2: 数据模板
Returns:
result: 报告结果
"""
def handle_paragraph_01(param):
"""
摘要
Parameters:
param: 摘要部分报告内容
Returns:
result: 处理好的报告内容
"""
data = param2['报告模板'][0]['摘要']
def handle_part_01():
"""
评价结果
"""
param[0]['小节内容'][0]['段落'] = param[0]['小节内容'][0]['段落'].format(**data['评价结果'][0])
param[0]['小节内容'][1]['段落'] = param[0]['小节内容'][1]['段落'].format(**data['评价结果'][1])
def handle_part_02():
"""
主要财务数据
"""
param[1]['小节内容'][2]['表格'] = data['主要财务数据']
def handle_part_03():
"""
评价观点
"""
param[2]['小节内容'][0]['段落'] = param[2]['小节内容'][0]['段落'].format(**data['评价观点'][0])
param[2]['小节内容'][1]['段落'] = param[2]['小节内容'][1]['段落'].format(**data['评价观点'][1])
param[2]['小节内容'][2]['段落'] = param[2]['小节内容'][2]['段落'].format(**data['评价观点'][2])
param[2]['小节内容'][3]['段落'] = param[2]['小节内容'][3]['段落'].format(**data['评价观点'][3])
def handle_part_04():
"""
关注
"""
param[3]['小节内容'][0]['段落'] = param[3]['小节内容'][0]['段落'].format(**data['关注'][0])
param[3]['小节内容'][1]['段落'] = param[3]['小节内容'][1]['段落'].format(**data['关注'][1])
param[3]['小节内容'][2]['段落'] = param[3]['小节内容'][2]['段落'].format(**data['关注'][2])
# 调用子方法
handle_part_01()
handle_part_02()
handle_part_03()
handle_part_04()
return param
def handle_paragraph_02(param):
"""
公司概况
Parameters:
param: 公司概况部分报告内容
Returns:
result: 处理好的报告内容
"""
data = param2['报告模板'][1]['一、公司概况']
def handle_part_01():
"""
公司背景
"""
param[0]['小节内容'][0]['段落'] = param[0]['小节内容'][0]['段落'].format(**data['公司背景'][0])
param[0]['小节内容'][1]['段落'] = param[0]['小节内容'][1]['段落'].format(**data['公司背景'][1])
def handle_part_02():
"""
股东实力
股东分为企业和自然人如果股东为企业显示前两段为自然人只显示最后一段
"""
# 判断返回的数据长度为2是企业为1是自然人
if len(data['股东实力']) == 1:
param[1]['小节内容'][2]['段落'] = param[1]['小节内容'][2]['段落'].format(**data['股东实力'][0])
# 删除前两段描述语句
del param[1]['小节内容'][0]
del param[1]['小节内容'][0]
else:
# 删除末尾语句
del param[1]['小节内容'][2]
param[1]['小节内容'][0]['段落'] = param[1]['小节内容'][0]['段落'].format(**data['股东实力'][0])
param[1]['小节内容'][1]['段落'] = param[1]['小节内容'][1]['段落'].format(**data['股东实力'][1])
def handle_part_03():
"""
对外投资
分为两种情况一种是有对外投资数据则只处理第一段和第四段其他描述语句保留
另一种是没有对外投资数据只显示返回的一句描述语句其他描述语句删除
"""
if len(data['对外投资']) == 1:
param[2]['小节内容'] = list()
describe = dict()
describe['段落'] = data['对外投资'][0]['describe']
param[2]['小节内容'].append(describe)
else:
param[2]['小节内容'][0]['段落'] = param[2]['小节内容'][0]['段落'].format(**data['对外投资'][0])
param[2]['小节内容'][3]['表格'] = data['对外投资'][1]
def handle_part_04():
"""
业务状况
"""
pass
def handle_part_05():
"""
进出口权
"""
param[4]['小节内容'][0]['段落'] = param[4]['小节内容'][0]['段落'].format(**data['进出口权'][0])
def handle_part_06():
"""
知识产权
"""
param[5]['小节内容'][0]['段落'] = param[5]['小节内容'][0]['段落'].format(**data['知识产权'][0])
param[5]['小节内容'][1]['段落'] = param[5]['小节内容'][1]['段落'].format(**data['知识产权'][1])
param[5]['小节内容'][2]['段落'] = param[5]['小节内容'][2]['段落'].format(**data['知识产权'][2])
def handle_part_07():
"""
荣誉资质
荣誉资质共六段如果返回数据长度为1则此企业没有荣誉资质只显示最后一段话
如果长度大于1则先处理第一段和第二段第一段中返回字段存在无则删除此段
"""
if len(data['资质荣誉']) == 1:
param[6]['小节内容'] = list()
describe = dict()
describe['段落'] = '经查询,公司无技术、产品品质或品牌等方面的荣誉资质。'
param[6]['小节内容'].append(describe)
else:
# 处理第一段
if data['资质荣誉'][0]['Qualification'] == '':
del param[6]['小节内容'][0]
# 处理第二段因为第一段内容被删除第二段的索引变为0
param[6]['小节内容'][0]['段落'] = param[6]['小节内容'][0]['段落'].format(**data['资质荣誉'][1])
else:
param[6]['小节内容'][0]['段落'] = param[6]['小节内容'][0]['段落'].format(**data['资质荣誉'][0])
param[6]['小节内容'][1]['段落'] = param[6]['小节内容'][1]['段落'].format(**data['资质荣誉'][1])
# 处理表格段
param[6]['小节内容'][-2]['表格'] = data['资质荣誉'][2]
# 调用子方法
handle_part_01()
handle_part_02()
handle_part_03()
handle_part_04()
handle_part_05()
handle_part_06()
handle_part_07()
return param
def handle_paragraph_03(param):
"""
ESG评价
Parameters:
param: ESG评价部分报告内容
Returns:
result: 处理好的报告内容
"""
data = param2['报告模板'][2]['二、ESG评价']
def handle_part_01():
"""
环境治理
"""
param[0]['小节内容'][0]['段落'] = param[0]['小节内容'][0]['段落'].format(**data['环境治理'][0])
param[0]['小节内容'][1]['段落'] = param[0]['小节内容'][1]['段落'].format(**data['环境治理'][1])
def handle_part_02():
"""
社会责任
"""
param[1]['小节内容'][0]['段落'] = param[1]['小节内容'][0]['段落'].format(**data['社会责任'][0])
def handle_part_03():
"""
公司治理
"""
param[2]['小节内容'][0]['段落'] = param[2]['小节内容'][0]['段落'].format(**data['公司治理'][0])
# 调用子方法
handle_part_01()
handle_part_02()
handle_part_03()
return param
def handle_paragraph_04(param):
"""
财务分析
Parameters:
param: 财务分析部分报告内容
Returns:
result: 处理好的报告内容
"""
data = param2['报告模板'][3]['三、财务分析']
def handle_part_01():
"""
盈利能力
"""
param[0]['小节内容'][1]['段落'] = param[0]['小节内容'][1]['段落'].format(**data['盈利能力'][1])
def handle_part_02():
"""
资产质量
"""
param[1]['小节内容'][2]['段落'] = param[1]['小节内容'][2]['段落'].format(**data['资产质量'][2])
def handle_part_03():
"""
债务风险
"""
param[2]['小节内容'][1]['段落'] = param[2]['小节内容'][1]['段落'].format(**data['债务风险'][1])
def handle_part_04():
"""
成长能力
"""
param[3]['小节内容'][1]['段落'] = param[3]['小节内容'][1]['段落'].format(**data['成长能力'][1])
# 调用子方法
handle_part_01()
handle_part_02()
handle_part_03()
handle_part_04()
return param
def handle_paragraph_05(param):
"""
企业风险
Parameters:
param: 企业风险部分报告内容
Returns:
result: 处理好的报告内容
"""
data = param2['报告模板'][4]['四、企业风险']
def handle_part_01():
"""
合规风险
"""
param[0]['小节内容'][0]['段落'] = param[0]['小节内容'][0]['段落'].format(**data['合规风险'][0])
def handle_part_02():
"""
经营风险
"""
param[1]['小节内容'][0]['段落'] = param[1]['小节内容'][0]['段落'].format(**data['经营风险'][0])
def handle_part_03():
"""
关联风险
"""
param[2]['小节内容'][0]['段落'] = param[2]['小节内容'][0]['段落'].format(**data['关联风险'][0])
# 调用子方法
handle_part_01()
handle_part_02()
handle_part_03()
return param
def handle_paragraph_06(param):
"""
评级结论
Parameters:
param: 评级结论部分报告内容
Returns:
result: 处理好的报告内容
"""
data = param2['报告模板'][5]['五、评级结论']
def handle_part_01():
"""
结论
"""
param[0]['小节内容'][0]['段落'] = param[0]['小节内容'][0]['段落'].format(**data['结论'][0])
param[0]['小节内容'][1]['段落'] = param[0]['小节内容'][1]['段落'].format(**data['结论'][1])
param[0]['小节内容'][2]['段落'] = param[0]['小节内容'][2]['段落'].format(**data['结论'][2])
# 调用子方法
handle_part_01()
return param
def handle_paragraph_07(param):
"""
评级结论
Parameters:
param: 评级结论部分报告内容
Returns:
result: 处理好的报告内容
"""
data = param2['报告模板'][6]['附录']
def handle_part_01():
"""
附录一
"""
param[0]['小节内容'][1]['表格'] = data['附录一']
# 调用子方法
handle_part_01()
return param
# Returns
param1['评价ID'] = param2['评价ID']
param1['企业ID'] = param2['企业ID']
param1['企业名称'] = param2['企业名称']
param1['评价年度'] = param2['评价年度']
param1['行业选择'] = param2['行业选择']
param1['生成日期'] = datetime.datetime.now().strftime("%Y-%m-%d")
for index in range(len(param1['报告内容'])):
if param1['报告内容'][index]['章节'] == '摘要':
param1['报告内容'][index]['章节内容'] = handle_paragraph_01(param1['报告内容'][index]['章节内容'])
elif param1['报告内容'][index]['章节'] == '一、公司概况':
param1['报告内容'][index]['章节内容'] = handle_paragraph_02(param1['报告内容'][index]['章节内容'])
elif param1['报告内容'][index]['章节'] == '二、ESG评价':
param1['报告内容'][index]['章节内容'] = handle_paragraph_03(param1['报告内容'][index]['章节内容'])
elif param1['报告内容'][index]['章节'] == '三、财务分析':
param1['报告内容'][index]['章节内容'] = handle_paragraph_04(param1['报告内容'][index]['章节内容'])
elif param1['报告内容'][index]['章节'] == '四、企业风险':
param1['报告内容'][index]['章节内容'] = handle_paragraph_05(param1['报告内容'][index]['章节内容'])
elif param1['报告内容'][index]['章节'] == '五、评级结论':
param1['报告内容'][index]['章节内容'] = handle_paragraph_06(param1['报告内容'][index]['章节内容'])
elif param1['报告内容'][index]['章节'] == '附录':
param1['报告内容'][index]['章节内容'] = handle_paragraph_07(param1['报告内容'][index]['章节内容'])
return param1
if __name__ == '__main__':
with open('../static/test/report_data.json', 'r', encoding='utf-8') as f:
r_data = json.load(f)
with open('../static/ReportTemplates/制造业.json', 'r', encoding='utf-8') as f:
doc = json.load(f)
handle_report_content(doc, r_data)

View File

@ -1,103 +1,3 @@
def handle_manufacturing_content(param1, param2):
"""
制造业报告内容处理
Parameters:
param1: 报告模板
param2: 数据模板
Returns:
result: 报告结果
"""
report_content = param1['报告内容']
report_data = param2['报告模板']
for num in range(len(report_content)):
p_value = report_content[num]['章节']
p_num = len(report_content[num]['章节内容'])
for c_num in range(p_num):
section = report_content[num]['章节内容'][c_num]['小节']
# 主要财务数据为表格
if section == '主要财务数据':
report_content[num]['章节内容'][c_num]['小节内容'][2]['表格'] = report_data[num][p_value]['主要财务数据']
# 判断股东实力部分如果返回数据长度为1则为自然人段落长度为2为企业段落
elif section == '股东实力':
if len(report_data[num][p_value][section]) == 1:
p = report_content[num]['章节内容'][c_num]['小节内容'][2]['段落']
d = report_data[num][p_value][section][0]
report_content[num]['章节内容'][c_num]['小节内容'][2]['段落'] = p.format(**d)
del report_content[num]['章节内容'][c_num]['小节内容'][0]
del report_content[num]['章节内容'][c_num]['小节内容'][0]
else:
del report_content[num]['章节内容'][c_num]['小节内容'][2]
content_num = len(report_content[num]['章节内容'][c_num]['小节内容'])
for cn in range(content_num):
# 段落内容
p = report_content[num]['章节内容'][c_num]['小节内容'][cn]['段落']
d = report_data[num][p_value][section][cn]
report_content[num]['章节内容'][c_num]['小节内容'][cn]['段落'] = p.format(**d)
# 对外投资段落中,只需要处理第一段和第四段,其余都是表格描述语句
elif section == '对外投资':
# 判断对外投资是否有数据
if len(report_data[num][p_value][section]) == 1:
d_0 = report_data[num][p_value][section][0]['describe']
report_content[num]['章节内容'][c_num]['小节内容'] = list()
insert_p = dict()
insert_p['段落'] = d_0
report_content[num]['章节内容'][c_num]['小节内容'].append(insert_p)
else:
# 处理段落1
p_0 = report_content[num]['章节内容'][c_num]['小节内容'][0]['段落']
d_0 = report_data[num][p_value][section][0]
report_content[num]['章节内容'][c_num]['小节内容'][0]['段落'] = p_0.format(**d_0)
# 处理段落4-表格
report_content[num]['章节内容'][c_num]['小节内容'][3]['表格'] = report_data[num][p_value][section][1]
elif section == '资质荣誉':
# 如果资质荣誉无数据只显示第三段,有数据则删除第三段
if len(report_data[num][p_value][section]) == 1:
report_content[num]['章节内容'][c_num]['小节内容'] = list()
insert_dict = dict()
insert_dict['段落'] = '经查询,公司无技术、产品品质或品牌等方面的荣誉资质。'
report_content[num]['章节内容'][c_num]['小节内容'].append(insert_dict)
else:
# 第一段数据
p_0 = report_content[num]['章节内容'][c_num]['小节内容'][0]['段落']
d_0 = report_data[num][p_value][section][0]
report_content[num]['章节内容'][c_num]['小节内容'][0]['段落'] = p_0.format(**d_0)
# 第二段数据
p_1 = report_content[num]['章节内容'][c_num]['小节内容'][1]['段落']
d_1 = report_data[num][p_value][section][1]
report_content[num]['章节内容'][c_num]['小节内容'][1]['段落'] = p_1.format(**d_1)
# 第五段数据(表格)
report_content[num]['章节内容'][c_num]['小节内容'][4]['表格'] = report_data[num][p_value][section][2]
# 再判断第一段和第二段数据是否为空,为空则删除
if report_data[num][p_value][section][0]['Qualification'] == '':
del report_content[num]['章节内容'][c_num]['小节内容'][0]
# 处理段落2之前需判断段落1是否被删除删除索引都会随之变化
if len(report_content[num]['章节内容'][c_num]['小节内容']) == 7:
# 处理段落2,判断是否有认证资质,有则显示这一段,没有则删除
if report_data[num][p_value][section][1]['Qualification_number'] < 1:
del report_content[num]['章节内容'][c_num]['小节内容'][1]
else:
if report_data[num][p_value][section][1]['Qualification_number'] < 1:
del report_content[num]['章节内容'][c_num]['小节内容'][0]
length = len(report_content[num]['章节内容'][c_num]['小节内容']) - 1
del report_content[num]['章节内容'][c_num]['小节内容'][length]
elif section == '附录2 有关指标的计算公式' or section == '附录3 数字化综合信用等级评价级别释义':
continue
elif section == '附录1 主要数据及指标':
report_content[num]['章节内容'][c_num]['小节内容'][1]['表格'] = report_data[num][p_value]['附录一']
else:
content_num = len(report_content[num]['章节内容'][c_num]['小节内容'])
for cn in range(content_num):
# 段落内容
p = report_content[num]['章节内容'][c_num]['小节内容'][cn]['段落']
d = report_data[num][p_value][section][cn]
if d is None:
continue
else:
report_content[num]['章节内容'][c_num]['小节内容'][cn]['段落'] = p.format(**d)
return report_content
def handle_information_content(param1, param2):
"""
信息技术业报告内容处理
@ -202,3 +102,4 @@ def handle_information_content(param1, param2):
return report_content

View File

@ -326,9 +326,6 @@
},
{
"注释": "数据来源:远东资信整理"
},
{
"段落": "经查询,公司无技术、产品品质或品牌等方面的荣誉资质。"
}
]
}

View File

@ -324,9 +324,6 @@
},
{
"注释": "数据来源:远东资信整理"
},
{
"段落": "经查询,公司无技术、产品品质或品牌等方面的荣誉资质。"
}
]
}

File diff suppressed because it is too large Load Diff