7b915143 by chenyao

添加4659-财务报表开发的三个表的识别,情况说明并未开发完成

1 parent 0a08bff7
...@@ -2533,3 +2533,8 @@ FSM_ACTIVITED_STATUS = { ...@@ -2533,3 +2533,8 @@ FSM_ACTIVITED_STATUS = {
2533 "APIPP": "Activated-Invoice Passed-PT Doc Required", 2533 "APIPP": "Activated-Invoice Passed-PT Doc Required",
2534 "APARD": "Activated-Review done", 2534 "APARD": "Activated-Review done",
2535 } 2535 }
2536
2537 # 财务报表分类标签
2538 FINANCIAL_STATEMENT_CLASSIFY_LIST = [97, 98, 99]
2539 # 财务报表sheet名称
2540 FINANCIAL_SHEET_NAME = "财务报表"
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -1724,6 +1724,8 @@ class Command(BaseCommand, LoggerMixin): ...@@ -1724,6 +1724,8 @@ class Command(BaseCommand, LoggerMixin):
1724 license_summary = {} 1724 license_summary = {}
1725 contract_result = {} 1725 contract_result = {}
1726 contract_result_compare = {} 1726 contract_result_compare = {}
1727 # 添加财报三个报表的处理
1728 financial_statement_dict = {"code": {}, "stamp": {}}
1727 res_list = [] 1729 res_list = []
1728 interest_keyword = Keywords.objects.filter( 1730 interest_keyword = Keywords.objects.filter(
1729 type=KeywordsType.INTEREST.value, on_off=True).values_list('keyword', flat=True) 1731 type=KeywordsType.INTEREST.value, on_off=True).values_list('keyword', flat=True)
...@@ -1753,6 +1755,21 @@ class Command(BaseCommand, LoggerMixin): ...@@ -1753,6 +1755,21 @@ class Command(BaseCommand, LoggerMixin):
1753 self.online_log.warn('{0} [ocr_1 res error] [img={1}]'.format( 1755 self.online_log.warn('{0} [ocr_1 res error] [img={1}]'.format(
1754 self.log_base, img_path)) 1756 self.log_base, img_path))
1755 continue 1757 continue
1758 elif classify in consts.FINANCIAL_STATEMENT_CLASSIFY_LIST:
1759 financial_statement_table_name = None
1760 if classify == 97:
1761 financial_statement_table_name = "balance_sheet"
1762 elif classify == 98:
1763 financial_statement_table_name = "income_statement"
1764 elif classify == 99:
1765 financial_statement_table_name = "cash_flow_statement"
1766 if financial_statement_table_name is not None:
1767 if "id_code" in ocr_data:
1768 id_code = ocr_data.get("id_code", "")
1769 financial_statement_dict["code"][financial_statement_table_name] = id_code
1770 if "stamp" in ocr_data:
1771 stamp = ocr_data.get("stamp", "")
1772 financial_statement_dict["stamp"][financial_statement_table_name] = stamp
1756 elif classify in consts.OTHER_CLASSIFY_SET: # 其他类 1773 elif classify in consts.OTHER_CLASSIFY_SET: # 其他类
1757 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_OTHER)) 1774 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_OTHER))
1758 continue 1775 continue
...@@ -1939,7 +1956,7 @@ class Command(BaseCommand, LoggerMixin): ...@@ -1939,7 +1956,7 @@ class Command(BaseCommand, LoggerMixin):
1939 # src_excel_path = os.path.join(doc_data_path, 'src.xlsx') 1956 # src_excel_path = os.path.join(doc_data_path, 'src.xlsx')
1940 # wb.save(src_excel_path) 1957 # wb.save(src_excel_path)
1941 #need_follow表示在上传edms时文件名是否要添加"关注"两字 1958 #need_follow表示在上传edms时文件名是否要添加"关注"两字
1942 count_list, need_follow = wb.rebuild(merged_bs_summary, license_summary, res_list, doc.document_scheme, contract_result, doc.metadata) 1959 count_list, need_follow = wb.rebuild(merged_bs_summary, license_summary, res_list, doc.document_scheme, contract_result, doc.metadata, financial_statement_dict)
1943 wb.save(excel_path) 1960 wb.save(excel_path)
1944 1961
1945 except Exception as e: 1962 except Exception as e:
...@@ -2046,10 +2063,10 @@ class Command(BaseCommand, LoggerMixin): ...@@ -2046,10 +2063,10 @@ class Command(BaseCommand, LoggerMixin):
2046 # 更新OCR累计识别结果表 2063 # 更新OCR累计识别结果表
2047 if business_type == consts.HIL_PREFIX: 2064 if business_type == consts.HIL_PREFIX:
2048 result_class = HILOCRResult if is_ca else HILSEOCRResult 2065 result_class = HILOCRResult if is_ca else HILSEOCRResult
2049 res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str) 2066 res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict)
2050 else: 2067 else:
2051 result_class = AFCOCRResult if is_ca else AFCSEOCRResult 2068 result_class = AFCOCRResult if is_ca else AFCSEOCRResult
2052 res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str) 2069 res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict)
2053 2070
2054 except Exception as e: 2071 except Exception as e:
2055 self.online_log.error( 2072 self.online_log.error(
...@@ -2426,7 +2443,7 @@ class Command(BaseCommand, LoggerMixin): ...@@ -2426,7 +2443,7 @@ class Command(BaseCommand, LoggerMixin):
2426 self.online_log.info('{0} [stop safely]'.format(self.log_base)) 2443 self.online_log.info('{0} [stop safely]'.format(self.log_base))
2427 2444
2428 @transaction.atomic 2445 @transaction.atomic
2429 def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task_str): 2446 def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task_str, financial_statement_dict):
2430 with transaction.atomic('afc'): 2447 with transaction.atomic('afc'):
2431 res_obj = result_class.objects.using('afc').select_for_update().filter(application_id=doc.application_id).first() 2448 res_obj = result_class.objects.using('afc').select_for_update().filter(application_id=doc.application_id).first()
2432 self.online_log.info('{0} [sql lock AFC application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id)) 2449 self.online_log.info('{0} [sql lock AFC application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id))
...@@ -2434,6 +2451,7 @@ def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task ...@@ -2434,6 +2451,7 @@ def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task
2434 res_obj = result_class() 2451 res_obj = result_class()
2435 res_obj.application_id = doc.application_id 2452 res_obj.application_id = doc.application_id
2436 self.online_log.info('{0} [res_obj is None application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id)) 2453 self.online_log.info('{0} [res_obj is None application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id))
2454 res_obj.fs_ocr = [financial_statement_dict]
2437 for classify, field in consts.RESULT_MAPPING.items(): 2455 for classify, field in consts.RESULT_MAPPING.items():
2438 if not hasattr(res_obj, field): 2456 if not hasattr(res_obj, field):
2439 continue 2457 continue
...@@ -2459,7 +2477,7 @@ def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task ...@@ -2459,7 +2477,7 @@ def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task
2459 return res_obj 2477 return res_obj
2460 2478
2461 @transaction.atomic 2479 @transaction.atomic
2462 def atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str): 2480 def atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict):
2463 with transaction.atomic('default'): 2481 with transaction.atomic('default'):
2464 res_obj = result_class.objects.using('default').select_for_update().filter(application_id=doc.application_id).first() 2482 res_obj = result_class.objects.using('default').select_for_update().filter(application_id=doc.application_id).first()
2465 self.online_log.info('{0} [sql lock HIL application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id)) 2483 self.online_log.info('{0} [sql lock HIL application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id))
...@@ -2467,6 +2485,7 @@ def atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, tas ...@@ -2467,6 +2485,7 @@ def atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, tas
2467 res_obj = result_class() 2485 res_obj = result_class()
2468 res_obj.application_id = doc.application_id 2486 res_obj.application_id = doc.application_id
2469 self.online_log.info('{0} [res_obj is None application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id)) 2487 self.online_log.info('{0} [res_obj is None application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id))
2488 res_obj.fs_ocr = [financial_statement_dict]
2470 for classify, field in consts.RESULT_MAPPING.items(): 2489 for classify, field in consts.RESULT_MAPPING.items():
2471 if not hasattr(res_obj, field): 2490 if not hasattr(res_obj, field):
2472 continue 2491 continue
......
...@@ -827,6 +827,28 @@ class BSWorkbook(Workbook): ...@@ -827,6 +827,28 @@ class BSWorkbook(Workbook):
827 ws.append(row) 827 ws.append(row)
828 ws.append((None, )) 828 ws.append((None, ))
829 829
830
831 def financial_rebuild(self, financial_statement_dict):
832 ws = self.create_sheet(consts.FINANCIAL_SHEET_NAME)
833 for fin_key, fin_value in financial_statement_dict.items():
834 table_str = "识别码"
835 if fin_key == "code":
836 table_str = "识别码"
837 elif fin_key == "stamp":
838 table_str = "印章"
839
840 for table_key, table_value in fin_value.items():
841 if table_key == "balance_sheet":
842 row = ["资产负债表" + table_str, str(table_value)]
843 ws.append(row)
844 elif table_key == "income_statement":
845 row = ["利润表" + table_str, str(table_value)]
846 ws.append(row)
847 elif table_key == "cash_flow_statement":
848 row = ["现金流量表" + table_str, str(table_value)]
849 ws.append(row)
850
851
830 @staticmethod 852 @staticmethod
831 def remove_yuan(amount_key_set, key, src_str): 853 def remove_yuan(amount_key_set, key, src_str):
832 if key in amount_key_set and isinstance(src_str, str): 854 if key in amount_key_set and isinstance(src_str, str):
...@@ -926,7 +948,7 @@ class BSWorkbook(Workbook): ...@@ -926,7 +948,7 @@ class BSWorkbook(Workbook):
926 if len(self.sheetnames) > 1: 948 if len(self.sheetnames) > 1:
927 self.remove(self.get_sheet_by_name('Sheet')) 949 self.remove(self.get_sheet_by_name('Sheet'))
928 950
929 def rebuild(self, bs_summary, license_summary, res_list, document_scheme, contract_result, metadata): 951 def rebuild(self, bs_summary, license_summary, res_list, document_scheme, contract_result, metadata, financial_statement_dict):
930 res_count_tuple = self.res_sheet(res_list) 952 res_count_tuple = self.res_sheet(res_list)
931 953
932 count_list = [(consts.MODEL_FIELD_BS, len(bs_summary))] 954 count_list = [(consts.MODEL_FIELD_BS, len(bs_summary))]
...@@ -934,10 +956,12 @@ class BSWorkbook(Workbook): ...@@ -934,10 +956,12 @@ class BSWorkbook(Workbook):
934 self.license_rebuild(license_summary, document_scheme, count_list) 956 self.license_rebuild(license_summary, document_scheme, count_list)
935 self.contract_rebuild(contract_result) 957 self.contract_rebuild(contract_result)
936 self.bs_rebuild(bs_summary, res_count_tuple, metadata) 958 self.bs_rebuild(bs_summary, res_count_tuple, metadata)
959 self.financial_rebuild(financial_statement_dict)
937 else: 960 else:
938 self.bs_rebuild(bs_summary, res_count_tuple, metadata) 961 self.bs_rebuild(bs_summary, res_count_tuple, metadata)
939 self.license_rebuild(license_summary, document_scheme, count_list) 962 self.license_rebuild(license_summary, document_scheme, count_list)
940 self.contract_rebuild(contract_result, True) 963 self.contract_rebuild(contract_result, True)
964 self.financial_rebuild(financial_statement_dict)
941 self.move_res_sheet() 965 self.move_res_sheet()
942 self.remove_base_sheet() 966 self.remove_base_sheet()
943 return count_list, self.need_follow 967 return count_list, self.need_follow
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!