fe23c4f5 by 周伟奇

add contract

1 parent 73c957c3
...@@ -1603,4 +1603,4 @@ CA_COMPARE_FIELD = { ...@@ -1603,4 +1603,4 @@ CA_COMPARE_FIELD = {
1603 DL_EN: (DL_OCR_FIELD, CA_DL_COMPARE_LOGIC, False), 1603 DL_EN: (DL_OCR_FIELD, CA_DL_COMPARE_LOGIC, False),
1604 } 1604 }
1605 1605
1606 1606 CONTRACT_SHEET_NAME = '合同'
......
...@@ -208,7 +208,43 @@ class Command(BaseCommand, LoggerMixin): ...@@ -208,7 +208,43 @@ class Command(BaseCommand, LoggerMixin):
208 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY)) 208 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY))
209 209
210 def contract_process(self, ocr_data, contract_result, res_list, pno, ino, part_idx, img_path): 210 def contract_process(self, ocr_data, contract_result, res_list, pno, ino, part_idx, img_path):
211 pass 211 contract_dict = ocr_data.get('data')
212 if not contract_dict or 'page_num' not in contract_dict or 'page_info' not in contract_dict:
213 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY))
214 return
215 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS))
216 page_num = contract_dict.get('page_num')
217 rebuild_page_info = []
218 text_key = 'words'
219 for key, value in contract_dict.get('page_info', {}).items():
220 if value is None:
221 rebuild_page_info.append((key, ))
222 elif text_key in value:
223 if value[text_key] is None:
224 rebuild_page_info.append((key,))
225 elif isinstance(value[text_key], str):
226 rebuild_page_info.append((key, value[text_key]))
227 elif isinstance(value[text_key], list):
228 rebuild_page_info.append((key,))
229 for row_list in value[text_key]:
230 rebuild_page_info.append(row_list)
231 else:
232 rebuild_page_info.append((key,))
233 for sub_key, sub_value in value.items():
234 if sub_value is None:
235 rebuild_page_info.append((sub_key,))
236 elif text_key in sub_value:
237 if sub_value[text_key] is None:
238 rebuild_page_info.append((sub_key,))
239 elif isinstance(sub_value[text_key], str):
240 rebuild_page_info.append((sub_key, sub_value[text_key]))
241 elif isinstance(sub_value[text_key], list):
242 rebuild_page_info.append((sub_key,))
243 for row_list in sub_value[text_key]:
244 rebuild_page_info.append(row_list)
245
246 contract_result.setdefault(page_num, []).append(rebuild_page_info)
247
212 248
213 def license1_process(self, ocr_data, license_summary, classify, res_list, pno, ino, part_idx, img_path, do_dda, dda_id_bc_mapping): 249 def license1_process(self, ocr_data, license_summary, classify, res_list, pno, ino, part_idx, img_path, do_dda, dda_id_bc_mapping):
214 # 类别:'0'身份证, '1'居住证 250 # 类别:'0'身份证, '1'居住证
...@@ -943,9 +979,9 @@ class Command(BaseCommand, LoggerMixin): ...@@ -943,9 +979,9 @@ class Command(BaseCommand, LoggerMixin):
943 979
944 # self.bs_log.info('[task={0}] [bs_summary={1}]'.format(task_str, merged_bs_summary)) 980 # self.bs_log.info('[task={0}] [bs_summary={1}]'.format(task_str, merged_bs_summary))
945 981
946 self.online_log.info('{0} [task={1}] [merged_bs_summary={2}] [license_summary={3}] ' 982 self.online_log.info('{0} [task={1}] [merged_bs_summary={2}] [license_summary={3}] [contract={4}] '
947 '[res_list={4}]'.format(self.log_base, task_str, merged_bs_summary, 983 '[res_list={5}]'.format(self.log_base, task_str, merged_bs_summary,
948 license_summary, res_list)) 984 contract_result, license_summary, res_list))
949 985
950 except Exception as e: 986 except Exception as e:
951 987
...@@ -966,7 +1002,7 @@ class Command(BaseCommand, LoggerMixin): ...@@ -966,7 +1002,7 @@ class Command(BaseCommand, LoggerMixin):
966 # 重构Excel文件 1002 # 重构Excel文件
967 # src_excel_path = os.path.join(doc_data_path, 'src.xlsx') 1003 # src_excel_path = os.path.join(doc_data_path, 'src.xlsx')
968 # wb.save(src_excel_path) 1004 # wb.save(src_excel_path)
969 count_list = wb.rebuild(merged_bs_summary, license_summary, res_list, doc.document_scheme) 1005 count_list = wb.rebuild(merged_bs_summary, license_summary, res_list, doc.document_scheme, contract_result)
970 wb.save(excel_path) 1006 wb.save(excel_path)
971 1007
972 except Exception as e: 1008 except Exception as e:
......
...@@ -702,6 +702,17 @@ class BSWorkbook(Workbook): ...@@ -702,6 +702,17 @@ class BSWorkbook(Workbook):
702 if field_str is not None: 702 if field_str is not None:
703 count_list.append((field_str, count)) 703 count_list.append((field_str, count))
704 704
705 def contract_rebuild(self, contract_result):
706 if len(contract_result) == 0:
707 return
708 ws = self.create_sheet(consts.CONTRACT_SHEET_NAME)
709 for page_num, info_list in contract_result:
710 ws.append('page {0}'.format(page_num))
711 for info in info_list:
712 for row in info:
713 ws.append(row)
714 ws.append((None, ))
715
705 @staticmethod 716 @staticmethod
706 def remove_yuan(amount_key_set, key, src_str): 717 def remove_yuan(amount_key_set, key, src_str):
707 if key in amount_key_set and isinstance(src_str, str): 718 if key in amount_key_set and isinstance(src_str, str):
...@@ -801,12 +812,13 @@ class BSWorkbook(Workbook): ...@@ -801,12 +812,13 @@ class BSWorkbook(Workbook):
801 if len(self.sheetnames) > 1: 812 if len(self.sheetnames) > 1:
802 self.remove(self.get_sheet_by_name('Sheet')) 813 self.remove(self.get_sheet_by_name('Sheet'))
803 814
804 def rebuild(self, bs_summary, license_summary, res_list, document_scheme): 815 def rebuild(self, bs_summary, license_summary, res_list, document_scheme, contract_result):
805 res_count_tuple = self.res_sheet(res_list) 816 res_count_tuple = self.res_sheet(res_list)
806 817
807 count_list = [(consts.MODEL_FIELD_BS, len(bs_summary))] 818 count_list = [(consts.MODEL_FIELD_BS, len(bs_summary))]
808 if document_scheme == consts.DOC_SCHEME_LIST[1]: 819 if document_scheme == consts.DOC_SCHEME_LIST[1]:
809 self.license_rebuild(license_summary, document_scheme, count_list) 820 self.license_rebuild(license_summary, document_scheme, count_list)
821 self.contract_rebuild(contract_result)
810 self.bs_rebuild(bs_summary, res_count_tuple) 822 self.bs_rebuild(bs_summary, res_count_tuple)
811 else: 823 else:
812 self.bs_rebuild(bs_summary, res_count_tuple) 824 self.bs_rebuild(bs_summary, res_count_tuple)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!