更新财务报表的三个报表的处理,dict为空,则excel中sheet不创建
Showing
3 changed files
with
65 additions
and
30 deletions
... | @@ -98,6 +98,7 @@ RES_SHEET_HEADER = ('页码', '图片序号', '检测图片序号', '结果') | ... | @@ -98,6 +98,7 @@ RES_SHEET_HEADER = ('页码', '图片序号', '检测图片序号', '结果') |
98 | RES_SUCCESS = '识别成功' | 98 | RES_SUCCESS = '识别成功' |
99 | RES_SUCCESS_OTHER = '识别成功(其他类)' | 99 | RES_SUCCESS_OTHER = '识别成功(其他类)' |
100 | RES_SUCCESS_EMPTY = '识别成功(空数据)' | 100 | RES_SUCCESS_EMPTY = '识别成功(空数据)' |
101 | RES_SUCCESS_FINANCIAL_STATEMENT = '识别成功(财务报表类)' | ||
101 | RES_FAILED = '识别失败' | 102 | RES_FAILED = '识别失败' |
102 | RES_FAILED_1 = '识别失败(阶段1)' | 103 | RES_FAILED_1 = '识别失败(阶段1)' |
103 | RES_FAILED_2 = '识别失败(阶段2)' | 104 | RES_FAILED_2 = '识别失败(阶段2)' | ... | ... |
... | @@ -1725,7 +1725,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -1725,7 +1725,7 @@ class Command(BaseCommand, LoggerMixin): |
1725 | contract_result = {} | 1725 | contract_result = {} |
1726 | contract_result_compare = {} | 1726 | contract_result_compare = {} |
1727 | # 添加财报三个报表的处理 | 1727 | # 添加财报三个报表的处理 |
1728 | financial_statement_dict = {"code": {}, "stamp": {}} | 1728 | financial_statement_dict = {} |
1729 | res_list = [] | 1729 | res_list = [] |
1730 | interest_keyword = Keywords.objects.filter( | 1730 | interest_keyword = Keywords.objects.filter( |
1731 | 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) |
... | @@ -1756,6 +1756,14 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -1756,6 +1756,14 @@ class Command(BaseCommand, LoggerMixin): |
1756 | self.log_base, img_path)) | 1756 | self.log_base, img_path)) |
1757 | continue | 1757 | continue |
1758 | elif classify in consts.FINANCIAL_STATEMENT_CLASSIFY_LIST: | 1758 | elif classify in consts.FINANCIAL_STATEMENT_CLASSIFY_LIST: |
1759 | # 添加到 res_list 中 | ||
1760 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_FINANCIAL_STATEMENT)) | ||
1761 | # 只要分类为财报三个报表的,就在 financial_statement_dict 中添加对应的 code 和 stamp 两个dict | ||
1762 | if "code" not in financial_statement_dict: | ||
1763 | financial_statement_dict["code"] = {} | ||
1764 | if "stamp" not in financial_statement_dict: | ||
1765 | financial_statement_dict["stamp"] = {} | ||
1766 | |||
1759 | financial_statement_table_name = None | 1767 | financial_statement_table_name = None |
1760 | if classify == 97: | 1768 | if classify == 97: |
1761 | financial_statement_table_name = "balance_sheet" | 1769 | financial_statement_table_name = "balance_sheet" |
... | @@ -2057,7 +2065,51 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -2057,7 +2065,51 @@ class Command(BaseCommand, LoggerMixin): |
2057 | license_summary[consts.BS_CLASSIFY] = bs_rebuild | 2065 | license_summary[consts.BS_CLASSIFY] = bs_rebuild |
2058 | 2066 | ||
2059 | # 比对 | 2067 | # 比对 |
2060 | if len(license_summary) > 0 and doc.document_scheme != consts.DOC_SCHEME_LIST[2]: | 2068 | if len(license_summary) > 0: |
2069 | if doc.document_scheme != consts.DOC_SCHEME_LIST[2]: | ||
2070 | # if len(license_summary) > 0 and doc.document_scheme != consts.DOC_SCHEME_LIST[2]: | ||
2071 | try: | ||
2072 | is_ca = True if doc.document_scheme == consts.DOC_SCHEME_LIST[0] else False | ||
2073 | # 更新OCR累计识别结果表 | ||
2074 | if business_type == consts.HIL_PREFIX: | ||
2075 | 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) | ||
2077 | else: | ||
2078 | 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) | ||
2080 | |||
2081 | except Exception as e: | ||
2082 | self.online_log.error( | ||
2083 | '{0} [process error (ocr result save)] [task={1}] [error={2}]'.format( | ||
2084 | self.log_base, task_str, traceback.format_exc())) | ||
2085 | else: | ||
2086 | self.online_log.info('{0} [ocr result save success] [task={1}] [res_id={2}]'.format( | ||
2087 | self.log_base, task_str, res_obj.id)) | ||
2088 | # 触发比对 | ||
2089 | try: | ||
2090 | # 是否fsm | ||
2091 | cms_status_class = HILCmsStatusInfo if business_type in consts.HIL_SET else AFCCmsStatusInfo | ||
2092 | cms_status_info = cms_status_class.objects.filter(application_id=doc.application_id).first() | ||
2093 | is_fsm = cms_status_info is not None and cms_status_info.is_fsm == 1 | ||
2094 | self.online_log.info('{0} [isfsm] [task={1}] [true or false={2}]'.format( | ||
2095 | self.log_base, task_str, is_fsm)) | ||
2096 | if is_fsm: | ||
2097 | fsm_compare.apply_async((doc.application_id, business_type, None, res_obj.id, is_ca, True), | ||
2098 | queue='queue_compare') | ||
2099 | else: | ||
2100 | # pass | ||
2101 | compare.apply_async((doc.application_id, business_type, None, res_obj.id, | ||
2102 | is_ca, True), queue='queue_compare') | ||
2103 | except Exception as e: | ||
2104 | self.online_log.error( | ||
2105 | '{0} [process error (comparison info send)] [task={1}] [error={2}]'.format( | ||
2106 | self.log_base, task_str, traceback.format_exc())) | ||
2107 | else: | ||
2108 | self.online_log.info('{0} [comparison info send success] [task={1}] ' | ||
2109 | '[res_id={2}]'.format(self.log_base, task_str, res_obj.id)) | ||
2110 | else: | ||
2111 | # license_summary 为空 | ||
2112 | self.online_log.info('{0} [task={1}] [no license_summary]'.format(self.log_base, task_str)) | ||
2061 | try: | 2113 | try: |
2062 | is_ca = True if doc.document_scheme == consts.DOC_SCHEME_LIST[0] else False | 2114 | is_ca = True if doc.document_scheme == consts.DOC_SCHEME_LIST[0] else False |
2063 | # 更新OCR累计识别结果表 | 2115 | # 更新OCR累计识别结果表 |
... | @@ -2067,36 +2119,10 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -2067,36 +2119,10 @@ class Command(BaseCommand, LoggerMixin): |
2067 | else: | 2119 | else: |
2068 | result_class = AFCOCRResult if is_ca else AFCSEOCRResult | 2120 | result_class = AFCOCRResult if is_ca else AFCSEOCRResult |
2069 | res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict) | 2121 | res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict) |
2070 | |||
2071 | except Exception as e: | 2122 | except Exception as e: |
2072 | self.online_log.error( | 2123 | self.online_log.error( |
2073 | '{0} [process error (ocr result save)] [task={1}] [error={2}]'.format( | 2124 | '{0} [process error (ocr result save)] [task={1}] [error={2}]'.format( |
2074 | self.log_base, task_str, traceback.format_exc())) | 2125 | self.log_base, task_str, traceback.format_exc())) |
2075 | else: | ||
2076 | self.online_log.info('{0} [ocr result save success] [task={1}] [res_id={2}]'.format( | ||
2077 | self.log_base, task_str, res_obj.id)) | ||
2078 | # 触发比对 | ||
2079 | try: | ||
2080 | # 是否fsm | ||
2081 | cms_status_class = HILCmsStatusInfo if business_type in consts.HIL_SET else AFCCmsStatusInfo | ||
2082 | cms_status_info = cms_status_class.objects.filter(application_id=doc.application_id).first() | ||
2083 | is_fsm = cms_status_info is not None and cms_status_info.is_fsm == 1 | ||
2084 | self.online_log.info('{0} [isfsm] [task={1}] [true or false={2}]'.format( | ||
2085 | self.log_base, task_str, is_fsm)) | ||
2086 | if is_fsm: | ||
2087 | fsm_compare.apply_async((doc.application_id, business_type, None, res_obj.id, is_ca, True), | ||
2088 | queue='queue_compare') | ||
2089 | else: | ||
2090 | # pass | ||
2091 | compare.apply_async((doc.application_id, business_type, None, res_obj.id, | ||
2092 | is_ca, True), queue='queue_compare') | ||
2093 | except Exception as e: | ||
2094 | self.online_log.error( | ||
2095 | '{0} [process error (comparison info send)] [task={1}] [error={2}]'.format( | ||
2096 | self.log_base, task_str, traceback.format_exc())) | ||
2097 | else: | ||
2098 | self.online_log.info('{0} [comparison info send success] [task={1}] ' | ||
2099 | '[res_id={2}]'.format(self.log_base, task_str, res_obj.id)) | ||
2100 | 2126 | ||
2101 | # DDA处理 | 2127 | # DDA处理 |
2102 | if do_dda: | 2128 | if do_dda: |
... | @@ -2451,7 +2477,9 @@ def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task | ... | @@ -2451,7 +2477,9 @@ def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task |
2451 | res_obj = result_class() | 2477 | res_obj = result_class() |
2452 | res_obj.application_id = doc.application_id | 2478 | res_obj.application_id = doc.application_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)) | 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)) |
2454 | res_obj.fs_ocr = json.dumps([financial_statement_dict]) | 2480 | if res_obj is not None: |
2481 | if financial_statement_dict: | ||
2482 | res_obj.fs_ocr = json.dumps([financial_statement_dict]) | ||
2455 | for classify, field in consts.RESULT_MAPPING.items(): | 2483 | for classify, field in consts.RESULT_MAPPING.items(): |
2456 | if not hasattr(res_obj, field): | 2484 | if not hasattr(res_obj, field): |
2457 | continue | 2485 | continue |
... | @@ -2485,7 +2513,9 @@ def atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, tas | ... | @@ -2485,7 +2513,9 @@ def atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, tas |
2485 | res_obj = result_class() | 2513 | res_obj = result_class() |
2486 | res_obj.application_id = doc.application_id | 2514 | res_obj.application_id = doc.application_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)) | 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)) |
2488 | res_obj.fs_ocr = json.dumps([financial_statement_dict]) | 2516 | if res_obj is not None: |
2517 | if financial_statement_dict: | ||
2518 | res_obj.fs_ocr = json.dumps([financial_statement_dict]) | ||
2489 | for classify, field in consts.RESULT_MAPPING.items(): | 2519 | for classify, field in consts.RESULT_MAPPING.items(): |
2490 | if not hasattr(res_obj, field): | 2520 | if not hasattr(res_obj, field): |
2491 | continue | 2521 | continue | ... | ... |
... | @@ -829,6 +829,10 @@ class BSWorkbook(Workbook): | ... | @@ -829,6 +829,10 @@ class BSWorkbook(Workbook): |
829 | 829 | ||
830 | 830 | ||
831 | def financial_rebuild(self, financial_statement_dict): | 831 | def financial_rebuild(self, financial_statement_dict): |
832 | # 如果 financial_statement_dict 为空,则不创建表 | ||
833 | if not financial_statement_dict: | ||
834 | return | ||
835 | # 如果 financial_statement_dict 不为空,则创建表 | ||
832 | ws = self.create_sheet(consts.FINANCIAL_SHEET_NAME) | 836 | ws = self.create_sheet(consts.FINANCIAL_SHEET_NAME) |
833 | for fin_key, fin_value in financial_statement_dict.items(): | 837 | for fin_key, fin_value in financial_statement_dict.items(): |
834 | table_str = "识别码" | 838 | table_str = "识别码" | ... | ... |
-
Please register or sign in to post a comment