efad9db2 by chenyao

更新财务报表的三个报表的处理,dict为空,则excel中sheet不创建

1 parent b859310a
......@@ -98,6 +98,7 @@ RES_SHEET_HEADER = ('页码', '图片序号', '检测图片序号', '结果')
RES_SUCCESS = '识别成功'
RES_SUCCESS_OTHER = '识别成功(其他类)'
RES_SUCCESS_EMPTY = '识别成功(空数据)'
RES_SUCCESS_FINANCIAL_STATEMENT = '识别成功(财务报表类)'
RES_FAILED = '识别失败'
RES_FAILED_1 = '识别失败(阶段1)'
RES_FAILED_2 = '识别失败(阶段2)'
......
......@@ -1725,7 +1725,7 @@ class Command(BaseCommand, LoggerMixin):
contract_result = {}
contract_result_compare = {}
# 添加财报三个报表的处理
financial_statement_dict = {"code": {}, "stamp": {}}
financial_statement_dict = {}
res_list = []
interest_keyword = Keywords.objects.filter(
type=KeywordsType.INTEREST.value, on_off=True).values_list('keyword', flat=True)
......@@ -1756,6 +1756,14 @@ class Command(BaseCommand, LoggerMixin):
self.log_base, img_path))
continue
elif classify in consts.FINANCIAL_STATEMENT_CLASSIFY_LIST:
# 添加到 res_list 中
res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_FINANCIAL_STATEMENT))
# 只要分类为财报三个报表的,就在 financial_statement_dict 中添加对应的 code 和 stamp 两个dict
if "code" not in financial_statement_dict:
financial_statement_dict["code"] = {}
if "stamp" not in financial_statement_dict:
financial_statement_dict["stamp"] = {}
financial_statement_table_name = None
if classify == 97:
financial_statement_table_name = "balance_sheet"
......@@ -2057,7 +2065,9 @@ class Command(BaseCommand, LoggerMixin):
license_summary[consts.BS_CLASSIFY] = bs_rebuild
# 比对
if len(license_summary) > 0 and doc.document_scheme != consts.DOC_SCHEME_LIST[2]:
if len(license_summary) > 0:
if doc.document_scheme != consts.DOC_SCHEME_LIST[2]:
# if len(license_summary) > 0 and doc.document_scheme != consts.DOC_SCHEME_LIST[2]:
try:
is_ca = True if doc.document_scheme == consts.DOC_SCHEME_LIST[0] else False
# 更新OCR累计识别结果表
......@@ -2097,6 +2107,22 @@ class Command(BaseCommand, LoggerMixin):
else:
self.online_log.info('{0} [comparison info send success] [task={1}] '
'[res_id={2}]'.format(self.log_base, task_str, res_obj.id))
else:
# license_summary 为空
self.online_log.info('{0} [task={1}] [no license_summary]'.format(self.log_base, task_str))
try:
is_ca = True if doc.document_scheme == consts.DOC_SCHEME_LIST[0] else False
# 更新OCR累计识别结果表
if business_type == consts.HIL_PREFIX:
result_class = HILOCRResult if is_ca else HILSEOCRResult
res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict)
else:
result_class = AFCOCRResult if is_ca else AFCSEOCRResult
res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict)
except Exception as e:
self.online_log.error(
'{0} [process error (ocr result save)] [task={1}] [error={2}]'.format(
self.log_base, task_str, traceback.format_exc()))
# DDA处理
if do_dda:
......@@ -2451,6 +2477,8 @@ def atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge,task
res_obj = result_class()
res_obj.application_id = doc.application_id
self.online_log.info('{0} [res_obj is None application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id))
if res_obj is not None:
if financial_statement_dict:
res_obj.fs_ocr = json.dumps([financial_statement_dict])
for classify, field in consts.RESULT_MAPPING.items():
if not hasattr(res_obj, field):
......@@ -2485,6 +2513,8 @@ def atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, tas
res_obj = result_class()
res_obj.application_id = doc.application_id
self.online_log.info('{0} [res_obj is None application_id={1} doc_id={2}]'.format(self.log_base, doc.application_id,doc.id))
if res_obj is not None:
if financial_statement_dict:
res_obj.fs_ocr = json.dumps([financial_statement_dict])
for classify, field in consts.RESULT_MAPPING.items():
if not hasattr(res_obj, field):
......
......@@ -829,6 +829,10 @@ class BSWorkbook(Workbook):
def financial_rebuild(self, financial_statement_dict):
# 如果 financial_statement_dict 为空,则不创建表
if not financial_statement_dict:
return
# 如果 financial_statement_dict 不为空,则创建表
ws = self.create_sheet(consts.FINANCIAL_SHEET_NAME)
for fin_key, fin_value in financial_statement_dict.items():
table_str = "识别码"
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!