5fbb652c by 周伟奇

Merge branch 'feature/contract' into feature/0611

2 parents a84f1276 fe23c4f5
...@@ -1002,6 +1002,10 @@ JYPZ_FIELD_ORDER = (("type", "标题"), ...@@ -1002,6 +1002,10 @@ JYPZ_FIELD_ORDER = (("type", "标题"),
1002 ("stamp_signature_seller", "出卖方签字/盖章"), 1002 ("stamp_signature_seller", "出卖方签字/盖章"),
1003 ("stamp_signature_agent", "经销商签字/盖章"),) 1003 ("stamp_signature_agent", "经销商签字/盖章"),)
1004 1004
1005 # 合同
1006 CONTRACT_CN_NAME = '合同'
1007 CONTRACT_CLASSIFY = 41
1008
1005 SUCCESS_CODE_SET = {'0', 0} 1009 SUCCESS_CODE_SET = {'0', 0}
1006 1010
1007 FIELD_ORDER_MAP = { 1011 FIELD_ORDER_MAP = {
...@@ -1628,4 +1632,4 @@ CA_COMPARE_FIELD = { ...@@ -1628,4 +1632,4 @@ CA_COMPARE_FIELD = {
1628 DL_EN: (DL_OCR_FIELD, CA_DL_COMPARE_LOGIC, False), 1632 DL_EN: (DL_OCR_FIELD, CA_DL_COMPARE_LOGIC, False),
1629 } 1633 }
1630 1634
1631 1635 CONTRACT_SHEET_NAME = '合同'
......
...@@ -207,6 +207,45 @@ class Command(BaseCommand, LoggerMixin): ...@@ -207,6 +207,45 @@ class Command(BaseCommand, LoggerMixin):
207 else: 207 else:
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):
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
248
210 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):
211 # 类别:'0'身份证, '1'居住证 250 # 类别:'0'身份证, '1'居住证
212 license_data = ocr_data.get('data') 251 license_data = ocr_data.get('data')
...@@ -820,6 +859,7 @@ class Command(BaseCommand, LoggerMixin): ...@@ -820,6 +859,7 @@ class Command(BaseCommand, LoggerMixin):
820 bs_summary = {} 859 bs_summary = {}
821 unknown_summary = {} 860 unknown_summary = {}
822 license_summary = {} 861 license_summary = {}
862 contract_result = {}
823 res_list = [] 863 res_list = []
824 interest_keyword = Keywords.objects.filter( 864 interest_keyword = Keywords.objects.filter(
825 type=KeywordsType.INTEREST.value, on_off=True).values_list('keyword', flat=True) 865 type=KeywordsType.INTEREST.value, on_off=True).values_list('keyword', flat=True)
...@@ -907,6 +947,9 @@ class Command(BaseCommand, LoggerMixin): ...@@ -907,6 +947,9 @@ class Command(BaseCommand, LoggerMixin):
907 res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) 947 res_list.append((pno, ino, part_idx, consts.RES_FAILED_2))
908 self.online_log.warn( 948 self.online_log.warn(
909 '{0} [ocr_2 failed] [img_path={1}]'.format(self.log_base, img_path)) 949 '{0} [ocr_2 failed] [img_path={1}]'.format(self.log_base, img_path))
950 elif classify == consts.CONTRACT_CLASSIFY:
951 self.contract_process(ocr_data, contract_result, res_list, pno, ino,
952 part_idx, img_path)
910 else: # 流水处理 953 else: # 流水处理
911 bs_classify_set.add(classify) 954 bs_classify_set.add(classify)
912 self.bs_process(wb, ocr_data, bs_summary, unknown_summary, classify, res_list, pno, ino, part_idx) 955 self.bs_process(wb, ocr_data, bs_summary, unknown_summary, classify, res_list, pno, ino, part_idx)
...@@ -936,9 +979,9 @@ class Command(BaseCommand, LoggerMixin): ...@@ -936,9 +979,9 @@ class Command(BaseCommand, LoggerMixin):
936 979
937 # 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))
938 981
939 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}] '
940 '[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,
941 license_summary, res_list)) 984 contract_result, license_summary, res_list))
942 985
943 except Exception as e: 986 except Exception as e:
944 987
...@@ -959,7 +1002,7 @@ class Command(BaseCommand, LoggerMixin): ...@@ -959,7 +1002,7 @@ class Command(BaseCommand, LoggerMixin):
959 # 重构Excel文件 1002 # 重构Excel文件
960 # src_excel_path = os.path.join(doc_data_path, 'src.xlsx') 1003 # src_excel_path = os.path.join(doc_data_path, 'src.xlsx')
961 # wb.save(src_excel_path) 1004 # wb.save(src_excel_path)
962 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)
963 wb.save(excel_path) 1006 wb.save(excel_path)
964 1007
965 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!