添加财报情况说明的内容存储到数据库和生成到Excel中
Showing
3 changed files
with
64 additions
and
9 deletions
... | @@ -2538,4 +2538,9 @@ FSM_ACTIVITED_STATUS = { | ... | @@ -2538,4 +2538,9 @@ FSM_ACTIVITED_STATUS = { |
2538 | # 财务报表分类标签 | 2538 | # 财务报表分类标签 |
2539 | FINANCIAL_STATEMENT_CLASSIFY_LIST = [97, 98, 99] | 2539 | FINANCIAL_STATEMENT_CLASSIFY_LIST = [97, 98, 99] |
2540 | # 财务报表sheet名称 | 2540 | # 财务报表sheet名称 |
2541 | FINANCIAL_SHEET_NAME = "财务报表" | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
2541 | FINANCIAL_SHEET_NAME = "财务报表" | ||
2542 | |||
2543 | # 财报情况说明分类标签 | ||
2544 | FINANCIAL_EXPLANATION_CLASSIFY_LIST = [100] | ||
2545 | # 财报情况说明sheet名称 | ||
2546 | FINANCIAL_EXPLANATION_SHEET_NAME = "财报情况说明" | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -1726,6 +1726,8 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -1726,6 +1726,8 @@ class Command(BaseCommand, LoggerMixin): |
1726 | contract_result_compare = {} | 1726 | contract_result_compare = {} |
1727 | # 添加财报三个报表的处理 | 1727 | # 添加财报三个报表的处理 |
1728 | financial_statement_dict = {} | 1728 | financial_statement_dict = {} |
1729 | # 添加财报情况说明的处理 | ||
1730 | financial_explanation_dict = {} | ||
1729 | res_list = [] | 1731 | res_list = [] |
1730 | interest_keyword = Keywords.objects.filter( | 1732 | interest_keyword = Keywords.objects.filter( |
1731 | type=KeywordsType.INTEREST.value, on_off=True).values_list('keyword', flat=True) | 1733 | type=KeywordsType.INTEREST.value, on_off=True).values_list('keyword', flat=True) |
... | @@ -1778,6 +1780,21 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -1778,6 +1780,21 @@ class Command(BaseCommand, LoggerMixin): |
1778 | if "stamp" in ocr_data: | 1780 | if "stamp" in ocr_data: |
1779 | stamp = ocr_data.get("stamp", "") | 1781 | stamp = ocr_data.get("stamp", "") |
1780 | financial_statement_dict["stamp"][financial_statement_table_name] = stamp | 1782 | financial_statement_dict["stamp"][financial_statement_table_name] = stamp |
1783 | elif classify in consts.FINANCIAL_EXPLANATION_CLASSIFY_LIST: | ||
1784 | # 添加到 res_list 中 | ||
1785 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_FINANCIAL_STATEMENT)) | ||
1786 | # 只要分类为财报情况说明的,就在 financial_explanation_dict 中添加对应的 title 和 stamp 两个dict | ||
1787 | if "title" not in financial_explanation_dict: | ||
1788 | financial_explanation_dict["title"] = {} | ||
1789 | if "stamp" not in financial_explanation_dict: | ||
1790 | financial_explanation_dict["stamp"] = {} | ||
1791 | |||
1792 | if "title" in ocr_data: | ||
1793 | title = ocr_data.get("title", "") | ||
1794 | financial_explanation_dict["title"] = title | ||
1795 | if "stamp" in ocr_data: | ||
1796 | stamp = ocr_data.get("stamp", "") | ||
1797 | financial_explanation_dict["stamp"] = stamp | ||
1781 | elif classify in consts.OTHER_CLASSIFY_SET: # 其他类 | 1798 | elif classify in consts.OTHER_CLASSIFY_SET: # 其他类 |
1782 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_OTHER)) | 1799 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_OTHER)) |
1783 | continue | 1800 | continue |
... | @@ -1964,7 +1981,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -1964,7 +1981,7 @@ class Command(BaseCommand, LoggerMixin): |
1964 | # src_excel_path = os.path.join(doc_data_path, 'src.xlsx') | 1981 | # src_excel_path = os.path.join(doc_data_path, 'src.xlsx') |
1965 | # wb.save(src_excel_path) | 1982 | # wb.save(src_excel_path) |
1966 | #need_follow表示在上传edms时文件名是否要添加"关注"两字 | 1983 | #need_follow表示在上传edms时文件名是否要添加"关注"两字 |
1967 | count_list, need_follow = wb.rebuild(merged_bs_summary, license_summary, res_list, doc.document_scheme, contract_result, doc.metadata, financial_statement_dict) | 1984 | count_list, need_follow = wb.rebuild(merged_bs_summary, license_summary, res_list, doc.document_scheme, contract_result, doc.metadata, financial_statement_dict, financial_explanation_dict) |
1968 | wb.save(excel_path) | 1985 | wb.save(excel_path) |
1969 | 1986 | ||
1970 | except Exception as e: | 1987 | except Exception as e: |
... | @@ -2073,10 +2090,10 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -2073,10 +2090,10 @@ class Command(BaseCommand, LoggerMixin): |
2073 | # 更新OCR累计识别结果表 | 2090 | # 更新OCR累计识别结果表 |
2074 | if business_type == consts.HIL_PREFIX: | 2091 | if business_type == consts.HIL_PREFIX: |
2075 | result_class = HILOCRResult if is_ca else HILSEOCRResult | 2092 | result_class = HILOCRResult if is_ca else HILSEOCRResult |
2076 | res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict) | 2093 | res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) |
2077 | else: | 2094 | else: |
2078 | result_class = AFCOCRResult if is_ca else AFCSEOCRResult | 2095 | result_class = AFCOCRResult if is_ca else AFCSEOCRResult |
2079 | res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict) | 2096 | res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) |
2080 | 2097 | ||
2081 | except Exception as e: | 2098 | except Exception as e: |
2082 | self.online_log.error( | 2099 | self.online_log.error( |
... | @@ -2115,10 +2132,10 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -2115,10 +2132,10 @@ class Command(BaseCommand, LoggerMixin): |
2115 | # 更新OCR累计识别结果表 | 2132 | # 更新OCR累计识别结果表 |
2116 | if business_type == consts.HIL_PREFIX: | 2133 | if business_type == consts.HIL_PREFIX: |
2117 | result_class = HILOCRResult if is_ca else HILSEOCRResult | 2134 | result_class = HILOCRResult if is_ca else HILSEOCRResult |
2118 | res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict) | 2135 | res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) |
2119 | else: | 2136 | else: |
2120 | result_class = AFCOCRResult if is_ca else AFCSEOCRResult | 2137 | result_class = AFCOCRResult if is_ca else AFCSEOCRResult |
2121 | res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict) | 2138 | res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) |
2122 | except Exception as e: | 2139 | except Exception as e: |
2123 | self.online_log.error( | 2140 | self.online_log.error( |
2124 | '{0} [process error (ocr result save)] [task={1}] [error={2}]'.format( | 2141 | '{0} [process error (ocr result save)] [task={1}] [error={2}]'.format( |
... | @@ -2469,7 +2486,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -2469,7 +2486,7 @@ class Command(BaseCommand, LoggerMixin): |
2469 | self.online_log.info('{0} [stop safely]'.format(self.log_base)) | 2486 | self.online_log.info('{0} [stop safely]'.format(self.log_base)) |
2470 | 2487 | ||
2471 | @transaction.atomic | 2488 | @transaction.atomic |
2472 | def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task_str, financial_statement_dict): | 2489 | def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task_str, financial_statement_dict, financial_explanation_dict): |
2473 | with transaction.atomic('afc'): | 2490 | with transaction.atomic('afc'): |
2474 | res_obj = result_class.objects.using('afc').select_for_update().filter(application_id=doc.application_id).first() | 2491 | res_obj = result_class.objects.using('afc').select_for_update().filter(application_id=doc.application_id).first() |
2475 | self.online_log.info('{0} [sql lock AFC application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id)) | 2492 | self.online_log.info('{0} [sql lock AFC application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id)) |
... | @@ -2477,9 +2494,14 @@ def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task | ... | @@ -2477,9 +2494,14 @@ def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task |
2477 | res_obj = result_class() | 2494 | res_obj = result_class() |
2478 | res_obj.application_id = doc.application_id | 2495 | res_obj.application_id = doc.application_id |
2479 | self.online_log.info('{0} [res_obj is None application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id)) | 2496 | self.online_log.info('{0} [res_obj is None application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id)) |
2497 | # 财务报表存入数据库 | ||
2480 | if res_obj is not None: | 2498 | if res_obj is not None: |
2481 | if financial_statement_dict: | 2499 | if financial_statement_dict: |
2482 | res_obj.fs_ocr = json.dumps([financial_statement_dict]) | 2500 | res_obj.fs_ocr = json.dumps([financial_statement_dict]) |
2501 | # 财报情况说明存入数据库 | ||
2502 | if res_obj is not None: | ||
2503 | if financial_explanation_dict: | ||
2504 | res_obj.fss_ocr = json.dumps([financial_explanation_dict]) | ||
2483 | for classify, field in consts.RESULT_MAPPING.items(): | 2505 | for classify, field in consts.RESULT_MAPPING.items(): |
2484 | if not hasattr(res_obj, field): | 2506 | if not hasattr(res_obj, field): |
2485 | continue | 2507 | continue |
... | @@ -2505,7 +2527,7 @@ def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task | ... | @@ -2505,7 +2527,7 @@ def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task |
2505 | return res_obj | 2527 | return res_obj |
2506 | 2528 | ||
2507 | @transaction.atomic | 2529 | @transaction.atomic |
2508 | def atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict): | 2530 | def atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict): |
2509 | with transaction.atomic('default'): | 2531 | with transaction.atomic('default'): |
2510 | res_obj = result_class.objects.using('default').select_for_update().filter(application_id=doc.application_id).first() | 2532 | res_obj = result_class.objects.using('default').select_for_update().filter(application_id=doc.application_id).first() |
2511 | self.online_log.info('{0} [sql lock HIL application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id)) | 2533 | self.online_log.info('{0} [sql lock HIL application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id)) |
... | @@ -2513,9 +2535,14 @@ def atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, tas | ... | @@ -2513,9 +2535,14 @@ def atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, tas |
2513 | res_obj = result_class() | 2535 | res_obj = result_class() |
2514 | res_obj.application_id = doc.application_id | 2536 | res_obj.application_id = doc.application_id |
2515 | self.online_log.info('{0} [res_obj is None application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id)) | 2537 | self.online_log.info('{0} [res_obj is None application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id)) |
2538 | # 财务报表三个表存入数据库 | ||
2516 | if res_obj is not None: | 2539 | if res_obj is not None: |
2517 | if financial_statement_dict: | 2540 | if financial_statement_dict: |
2518 | res_obj.fs_ocr = json.dumps([financial_statement_dict]) | 2541 | res_obj.fs_ocr = json.dumps([financial_statement_dict]) |
2542 | # 财报情况说明存入数据库 | ||
2543 | if res_obj is not None: | ||
2544 | if financial_explanation_dict: | ||
2545 | res_obj.fss_ocr = json.dumps([financial_explanation_dict]) | ||
2519 | for classify, field in consts.RESULT_MAPPING.items(): | 2546 | for classify, field in consts.RESULT_MAPPING.items(): |
2520 | if not hasattr(res_obj, field): | 2547 | if not hasattr(res_obj, field): |
2521 | continue | 2548 | continue | ... | ... |
... | @@ -853,6 +853,27 @@ class BSWorkbook(Workbook): | ... | @@ -853,6 +853,27 @@ class BSWorkbook(Workbook): |
853 | ws.append(row) | 853 | ws.append(row) |
854 | 854 | ||
855 | 855 | ||
856 | def financial_explanation_rebuild(self, financial_explanation_dict): | ||
857 | """ | ||
858 | Desc: | ||
859 | 重构财报情况说明sheet | ||
860 | """ | ||
861 | # 如果 financial_explanation_dict 为空,则不创建sheet | ||
862 | if not financial_explanation_dict: | ||
863 | return | ||
864 | # 如果 financial_explanation_dict 不为空, 则创建sheet | ||
865 | ws = self.create_sheet(consts.FINANCIAL_EXPLANATION_SHEET_NAME) | ||
866 | for fin_key, fin_value in financial_explanation_dict.items(): | ||
867 | table_str = "公司名称" | ||
868 | if fin_key == "title": | ||
869 | table_str = "公司名称" | ||
870 | elif fin_key == "stamp": | ||
871 | table_str = "印章" | ||
872 | |||
873 | row = ["财报情况说明" + table_str, str(fin_value)] | ||
874 | ws.append(row) | ||
875 | |||
876 | |||
856 | @staticmethod | 877 | @staticmethod |
857 | def remove_yuan(amount_key_set, key, src_str): | 878 | def remove_yuan(amount_key_set, key, src_str): |
858 | if key in amount_key_set and isinstance(src_str, str): | 879 | if key in amount_key_set and isinstance(src_str, str): |
... | @@ -952,7 +973,7 @@ class BSWorkbook(Workbook): | ... | @@ -952,7 +973,7 @@ class BSWorkbook(Workbook): |
952 | if len(self.sheetnames) > 1: | 973 | if len(self.sheetnames) > 1: |
953 | self.remove(self.get_sheet_by_name('Sheet')) | 974 | self.remove(self.get_sheet_by_name('Sheet')) |
954 | 975 | ||
955 | def rebuild(self, bs_summary, license_summary, res_list, document_scheme, contract_result, metadata, financial_statement_dict): | 976 | def rebuild(self, bs_summary, license_summary, res_list, document_scheme, contract_result, metadata, financial_statement_dict, financial_explanation_dict): |
956 | res_count_tuple = self.res_sheet(res_list) | 977 | res_count_tuple = self.res_sheet(res_list) |
957 | 978 | ||
958 | count_list = [(consts.MODEL_FIELD_BS, len(bs_summary))] | 979 | count_list = [(consts.MODEL_FIELD_BS, len(bs_summary))] |
... | @@ -961,11 +982,13 @@ class BSWorkbook(Workbook): | ... | @@ -961,11 +982,13 @@ class BSWorkbook(Workbook): |
961 | self.contract_rebuild(contract_result) | 982 | self.contract_rebuild(contract_result) |
962 | self.bs_rebuild(bs_summary, res_count_tuple, metadata) | 983 | self.bs_rebuild(bs_summary, res_count_tuple, metadata) |
963 | self.financial_rebuild(financial_statement_dict) | 984 | self.financial_rebuild(financial_statement_dict) |
985 | self.financial_explanation_rebuild(financial_explanation_dict) | ||
964 | else: | 986 | else: |
965 | self.bs_rebuild(bs_summary, res_count_tuple, metadata) | 987 | self.bs_rebuild(bs_summary, res_count_tuple, metadata) |
966 | self.license_rebuild(license_summary, document_scheme, count_list) | 988 | self.license_rebuild(license_summary, document_scheme, count_list) |
967 | self.contract_rebuild(contract_result, True) | 989 | self.contract_rebuild(contract_result, True) |
968 | self.financial_rebuild(financial_statement_dict) | 990 | self.financial_rebuild(financial_statement_dict) |
991 | self.financial_explanation_rebuild(financial_explanation_dict) | ||
969 | self.move_res_sheet() | 992 | self.move_res_sheet() |
970 | self.remove_base_sheet() | 993 | self.remove_base_sheet() |
971 | return count_list, self.need_follow | 994 | return count_list, self.need_follow | ... | ... |
-
Please register or sign in to post a comment