guarantee-admin-api-v0.2/Modules/Reports/ReportDataModel.py

86 lines
2.8 KiB
Python

import time
from Modules.Reports.ReportDataObj import ReportDataObj, Chapter, Section, Content
from Utils.CommonUtil import get_yaml
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/report_template.yaml')
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)
return report_data.fields_toggle(fields=["content"])