176 lines
5.8 KiB
Python
176 lines
5.8 KiB
Python
import time
|
|
|
|
from DBHelper.MongoHelperInstance import DB_GUA
|
|
from Modules.Reports.ReportDataObj import ReportDataObj, Chapter, Section, Content
|
|
from Utils.CommonUtil import get_yaml
|
|
|
|
|
|
class Paragraph(object):
|
|
|
|
@staticmethod
|
|
def p_rank_result_1(**kwargs):
|
|
credit_rank = DB_GUA.find_single_column(
|
|
"评级数据",
|
|
"得分级别",
|
|
{"评级ID": kwargs["rid"]},
|
|
"信用级别"
|
|
)
|
|
tempo = kwargs["tempo"]
|
|
tempo = tempo.format(get_credit_rank=credit_rank)
|
|
return tempo
|
|
|
|
|
|
class ReportDataModel(object):
|
|
|
|
# 工商信息 business_data_source
|
|
bds = {}
|
|
# 财务数据 financial_data_source
|
|
fds = {}
|
|
# 经营数据 operating_data_source
|
|
ods = {}
|
|
# 风险数据 risk_data_source
|
|
rds = {}
|
|
# 财务指标 financial_indicators_data_source
|
|
fids = {}
|
|
# 打分评级数据 score_and_rank_data_source
|
|
srds = {}
|
|
|
|
# 报告模板
|
|
tempo = get_yaml(file_rel_path='/Reports/static/template/report_template.yaml')
|
|
|
|
def make_report_data(self, **kwargs):
|
|
|
|
report_data = ReportDataObj()
|
|
|
|
report_data.cid = kwargs['cid']
|
|
report_data.rid = kwargs['rid']
|
|
report_data.name = kwargs['name']
|
|
report_data.year = kwargs['year']
|
|
report_data.industry = kwargs['industry']
|
|
report_data.title = kwargs['title']
|
|
report_data.generate_date = time.strftime("%Y-%m-%d", time.localtime())
|
|
report_data.content = list()
|
|
|
|
chapter_titles = list(self.tempo.keys())
|
|
|
|
for chapter_title in chapter_titles:
|
|
|
|
chapter = Chapter()
|
|
|
|
chapter.title = chapter_title
|
|
chapter.content = list()
|
|
|
|
for section_title in self.tempo[chapter_title]:
|
|
|
|
section = Section()
|
|
|
|
section.title = section_title
|
|
section.content = list()
|
|
|
|
for content_item in self.tempo[chapter_title][section_title]:
|
|
|
|
content_type = list(content_item.keys()).__getitem__(0)
|
|
|
|
if content_type == '段落':
|
|
|
|
content = Content()
|
|
p_func = content_item['段落']['方法']
|
|
p_tempo = content_item['段落']['模板']
|
|
section.content.append(content)
|
|
|
|
elif content_type == '表格':
|
|
|
|
if content_item['表格'].__contains__('表头'):
|
|
content = Content()
|
|
content.table_name = content_item['表格']['表头']
|
|
section.content.append(content)
|
|
|
|
if content_item['表格'].__contains__('示例'):
|
|
content = Content()
|
|
content.table_data = content_item['表格']['示例']
|
|
section.content.append(content)
|
|
|
|
if content_item['表格'].__contains__('注释'):
|
|
content = Content()
|
|
content.comment = content_item['表格']['注释']
|
|
section.content.append(content)
|
|
|
|
chapter.content.append(section)
|
|
|
|
report_data.content.append(chapter)
|
|
|
|
return report_data.fields_toggle(fields=["content"])
|
|
|
|
def mock_report_data(self, **kwargs):
|
|
|
|
report_data = ReportDataObj()
|
|
|
|
report_data.cid = kwargs['cid']
|
|
report_data.rid = kwargs['rid']
|
|
report_data.name = kwargs['name']
|
|
report_data.year = kwargs['year']
|
|
report_data.industry = kwargs['industry']
|
|
report_data.title = kwargs['title']
|
|
report_data.generate_date = time.strftime("%Y-%m-%d", time.localtime())
|
|
report_data.content = list()
|
|
|
|
chapter_titles = list(self.tempo.keys())
|
|
|
|
for chapter_title in chapter_titles:
|
|
|
|
chapter = Chapter()
|
|
|
|
chapter.title = chapter_title
|
|
chapter.content = list()
|
|
|
|
for section_title in self.tempo[chapter_title]:
|
|
|
|
section = Section()
|
|
|
|
section.title = section_title
|
|
section.content = list()
|
|
|
|
for content_item in self.tempo[chapter_title][section_title]:
|
|
|
|
content_type = list(content_item.keys()).__getitem__(0)
|
|
|
|
if content_type == '段落':
|
|
|
|
content = Content()
|
|
content.paragraph = content_item['段落']['示例']
|
|
section.content.append(content)
|
|
|
|
elif content_type == '表格':
|
|
|
|
if content_item['表格'].__contains__('表头'):
|
|
content = Content()
|
|
content.table_name = content_item['表格']['表头']
|
|
section.content.append(content)
|
|
|
|
if content_item['表格'].__contains__('示例'):
|
|
content = Content()
|
|
content.table_data = content_item['表格']['示例']
|
|
section.content.append(content)
|
|
|
|
if content_item['表格'].__contains__('注释'):
|
|
content = Content()
|
|
content.comment = content_item['表格']['注释']
|
|
section.content.append(content)
|
|
|
|
chapter.content.append(section)
|
|
|
|
report_data.content.append(chapter)
|
|
|
|
DB_GUA.upsert_single_data(
|
|
"评级数据",
|
|
"报告数据",
|
|
{"评级ID": report_data.rid},
|
|
report_data.fields_toggle()
|
|
)
|
|
|
|
return report_data.fields_toggle(fields=["content"])
|
|
|
|
|
|
# if __name__ == '__main__':
|
|
# print(eval('Paragraph.p_rank_result_1')(rid="ZZO2qV0Q", tempo='主体信用评价等级: {get_credit_rank}'))
|