diff --git a/Modules/Company/CompanyManageImpl.py b/Modules/Company/CompanyManageImpl.py index 1af82c6..e370ab7 100644 --- a/Modules/Company/CompanyManageImpl.py +++ b/Modules/Company/CompanyManageImpl.py @@ -1,7 +1,8 @@ from DBHelper.MongoHelperInstance import DB_GUA from Modules.Common.CommonUtils import CommonUtils from Modules.Company.CompanyObject import GuaranteeInfo -from Utils.CommonUtil import trans_fields_name, sub_dict, get_attr +from Utils.CommonUtil import trans_fields_name, sub_dict, get_attr, make_multistage_update_body +from Utils.ErrorUtil import APIReturnError class CompanyManageImpl(object): @@ -80,7 +81,7 @@ class CompanyManageImpl(object): return result @staticmethod - def financial_data(**kwargs): + def get_financial_data(**kwargs): items = DB_GUA.find_all_data( "企业数据", @@ -122,7 +123,28 @@ class CompanyManageImpl(object): return result @staticmethod - def guarantee_info(**kwargs): + def edit_financial_data(**kwargs): + cid = kwargs['cid'] + report_date = kwargs['report_date'] + update_data = kwargs['update_data'] + + update_body = make_multistage_update_body(update_data) + + if update_body is None: + raise APIReturnError("输入格式错误", 202) + + if type(list(update_body.values())[0]) not in [float, type(None)]: + raise APIReturnError("输入格式错误", 202) + + DB_GUA.update_single_data( + "企业数据", + "财务数据", + {"企业ID": cid, "报告期": report_date}, + update_body + ) + + @staticmethod + def get_guarantee_info(**kwargs): items = DB_GUA.find_all_data( "企业数据", diff --git a/Modules/Company/CompanyRoutes.py b/Modules/Company/CompanyRoutes.py index 8b75174..797e9a3 100644 --- a/Modules/Company/CompanyRoutes.py +++ b/Modules/Company/CompanyRoutes.py @@ -137,21 +137,27 @@ def basic_data_route(**kwargs): return {"info": e.__str__()}, e.status_code -@company_route.route('/financial_data', methods=['GET']) +@company_route.route('/financial_data', methods=['GET', 'POST']) @verify_token def financial_data_route(**kwargs): """财务数据""" try: - RouteParamsCheck(request.args, ["cid"]).required() - - cid = request.args["cid"] - - impl = CompanyManageImpl() - - result = impl.financial_data(cid=cid) - - return {"info": "财务数据", "result": result}, 200 + if request.method == 'GET': + RouteParamsCheck(request.args, ["cid"]).required() + cid = request.args["cid"] + impl = CompanyManageImpl() + result = impl.get_financial_data(cid=cid) + return {"info": "财务数据", "result": result}, 200 + if request.method == 'POST': + RouteParamsCheck(request.args, ["cid", "report_date"]).required() + RouteParamsCheck(request.json, ["update_data"]).required() + cid = request.args["cid"] + report_date = request.args["report_date"] + update_data = request.json["update_data"] + impl = CompanyManageImpl() + impl.edit_financial_data(cid=cid, report_date=report_date, update_data=update_data) + return {"info": "财务数据", "result": "修改成功"}, 200 except APIReturnError as e: return {"info": e.__str__()}, e.status_code @@ -168,7 +174,7 @@ def guarantee_info_route(**kwargs): RouteParamsCheck(request.args, ["cid"]).required() cid = request.args["cid"] impl = CompanyManageImpl() - result = impl.guarantee_info(cid=cid) + result = impl.get_guarantee_info(cid=cid) return {"info": "担保信息", "result": result}, 200 if request.method == "POST": diff --git a/Modules/Reports/ReportDataModel.py b/Modules/Reports/ReportDataModel.py index 338e1ff..5cd97b8 100644 --- a/Modules/Reports/ReportDataModel.py +++ b/Modules/Reports/ReportDataModel.py @@ -1,9 +1,25 @@ 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 @@ -22,6 +38,69 @@ class ReportDataModel(object): # 报告模板 tempo = get_yaml(file_rel_path='/Reports/static/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() @@ -82,4 +161,15 @@ class ReportDataModel(object): 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}')) diff --git a/Utils/CommonUtil.py b/Utils/CommonUtil.py index 4cece12..eb7996b 100644 --- a/Utils/CommonUtil.py +++ b/Utils/CommonUtil.py @@ -71,3 +71,43 @@ def get_yaml(**kwargs): file_abs_path = os.path.abspath(abs_path_root + '/Modules/' + file_rel_path) doc_yaml = open(file_abs_path, 'r', encoding="utf-8").read() return yaml.full_load(doc_yaml) + + +def make_multistage_update_body(input_dict): + + def get_dict_keys(_dict_): + if isinstance(_dict_, dict): + for key in _dict_.keys(): + if isinstance(_dict_[key], dict): + get_dict_keys(_dict_[key]) + update_keys.append(key) + return update_keys + + def get_dict_value(data, keys): + keys_list = keys.split('.') + if isinstance(data, dict): + for key in keys_list: + values = data.get(key) + data = values + return data + + try: + update_key = '' + update_keys = [] + + get_dict_keys(input_dict) + update_keys.reverse() + floor = len(update_keys) + + for i in range(floor): + if i == floor - 1: + update_key = update_key + update_keys[i] + else: + update_key = update_key + update_keys[i] + '.' + + update_value = get_dict_value(input_dict, update_key) + + return {update_key: update_value} + + except Exception: + return None