dda part 2
Showing
4 changed files
with
342 additions
and
45 deletions
| ... | @@ -1204,6 +1204,7 @@ DDA_IC_ID = 'customer_id' | ... | @@ -1204,6 +1204,7 @@ DDA_IC_ID = 'customer_id' |
| 1204 | DDA_BC_NAME = 'account_name' | 1204 | DDA_BC_NAME = 'account_name' |
| 1205 | DDA_BC_ID = 'account_id' | 1205 | DDA_BC_ID = 'account_id' |
| 1206 | DDA_IMG_PATH = 'img_path' | 1206 | DDA_IMG_PATH = 'img_path' |
| 1207 | DDA_PRO = 'pro' | ||
| 1207 | 1208 | ||
| 1208 | 1209 | ||
| 1209 | DDA_MAPPING = [ | 1210 | DDA_MAPPING = [ | ... | ... |
| ... | @@ -23,7 +23,7 @@ from apps.doc.ocr.edms import EDMS, rh | ... | @@ -23,7 +23,7 @@ from apps.doc.ocr.edms import EDMS, rh |
| 23 | from apps.doc.named_enum import KeywordsType | 23 | from apps.doc.named_enum import KeywordsType |
| 24 | from apps.doc.exceptions import EDMSException, OCR1Exception, OCR2Exception, OCR4Exception | 24 | from apps.doc.exceptions import EDMSException, OCR1Exception, OCR2Exception, OCR4Exception |
| 25 | from apps.doc.ocr.wb import BSWorkbook | 25 | from apps.doc.ocr.wb import BSWorkbook |
| 26 | from apps.doc.models import DocStatus, HILDoc, AFCDoc, Keywords, HILOCRResult, AFCOCRResult | 26 | from apps.doc.models import DocStatus, HILDoc, AFCDoc, Keywords, HILOCRResult, AFCOCRResult, DDARecords, IDBCRecords |
| 27 | from celery_compare.tasks import compare | 27 | from celery_compare.tasks import compare |
| 28 | 28 | ||
| 29 | 29 | ||
| ... | @@ -43,6 +43,10 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -43,6 +43,10 @@ class Command(BaseCommand, LoggerMixin): |
| 43 | self.img_queue_size = int(conf.IMG_QUEUE_SIZE) | 43 | self.img_queue_size = int(conf.IMG_QUEUE_SIZE) |
| 44 | # 数据目录 | 44 | # 数据目录 |
| 45 | self.data_dir = conf.DATA_DIR | 45 | self.data_dir = conf.DATA_DIR |
| 46 | # DDA目录 | ||
| 47 | self.dda_dir = os.path.join(self.data_dir, 'HIL', 'DDA') | ||
| 48 | self.dda_complete_dir = os.path.join(self.dda_dir, 'complete') | ||
| 49 | self.dda_wanting_dir = os.path.join(self.dda_dir, 'wanting') | ||
| 46 | # ocr相关 | 50 | # ocr相关 |
| 47 | self.ocr_1_urls = conf.get_namespace('OCR_URL_1_') | 51 | self.ocr_1_urls = conf.get_namespace('OCR_URL_1_') |
| 48 | self.ocr_url_2 = conf.OCR_URL_2 | 52 | self.ocr_url_2 = conf.OCR_URL_2 |
| ... | @@ -189,7 +193,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -189,7 +193,7 @@ class Command(BaseCommand, LoggerMixin): |
| 189 | else: | 193 | else: |
| 190 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY)) | 194 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY)) |
| 191 | 195 | ||
| 192 | def license1_process(self, ocr_data, license_summary, classify, res_list, pno, ino, part_idx, img_path, is_hil, hil_id_bc_mapping): | 196 | def license1_process(self, ocr_data, license_summary, classify, res_list, pno, ino, part_idx, img_path, do_dda, dda_id_bc_mapping): |
| 193 | # 类别:'0'身份证, '1'居住证 | 197 | # 类别:'0'身份证, '1'居住证 |
| 194 | license_data = ocr_data.get('data') | 198 | license_data = ocr_data.get('data') |
| 195 | if not license_data: | 199 | if not license_data: |
| ... | @@ -197,12 +201,14 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -197,12 +201,14 @@ class Command(BaseCommand, LoggerMixin): |
| 197 | return | 201 | return |
| 198 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) | 202 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) |
| 199 | if classify == consts.DDA_CLASSIFY: # DDA处理 | 203 | if classify == consts.DDA_CLASSIFY: # DDA处理 |
| 204 | pro = ocr_data.get('confidence') | ||
| 200 | dda_ocr_result = { | 205 | dda_ocr_result = { |
| 201 | consts.DDA_IC_NAME: license_data.get('result', {}).get(consts.DDA_IC_NAME, {}).get('words', ''), | 206 | consts.DDA_IC_NAME: license_data.get('result', {}).get(consts.DDA_IC_NAME, {}).get('words', ''), |
| 202 | consts.DDA_IC_ID: license_data.get('result', {}).get(consts.DDA_IC_ID, {}).get('words', ''), | 207 | consts.DDA_IC_ID: license_data.get('result', {}).get(consts.DDA_IC_ID, {}).get('words', ''), |
| 203 | consts.DDA_BC_NAME: license_data.get('result', {}).get(consts.DDA_BC_NAME, {}).get('words', ''), | 208 | consts.DDA_BC_NAME: license_data.get('result', {}).get(consts.DDA_BC_NAME, {}).get('words', ''), |
| 204 | consts.DDA_BC_ID: license_data.get('result', {}).get(consts.DDA_BC_ID, {}).get('words', ''), | 209 | consts.DDA_BC_ID: license_data.get('result', {}).get(consts.DDA_BC_ID, {}).get('words', ''), |
| 205 | consts.DDA_IMG_PATH: img_path | 210 | consts.DDA_IMG_PATH: img_path, |
| 211 | consts.DDA_PRO: pro | ||
| 206 | } | 212 | } |
| 207 | license_summary.setdefault(classify, []).append(dda_ocr_result) | 213 | license_summary.setdefault(classify, []).append(dda_ocr_result) |
| 208 | 214 | ||
| ... | @@ -290,17 +296,14 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -290,17 +296,14 @@ class Command(BaseCommand, LoggerMixin): |
| 290 | 296 | ||
| 291 | id_card_dict[consts.IC_TURE_OR_FALSE] = consts.IC_RES_MAPPING.get(card_type) | 297 | id_card_dict[consts.IC_TURE_OR_FALSE] = consts.IC_RES_MAPPING.get(card_type) |
| 292 | finally: | 298 | finally: |
| 293 | if is_hil: | 299 | if do_dda and isinstance(id_card_dict.get(consts.IC_KEY_FIELD[0]), str) and isinstance(id_card_dict.get(consts.IC_KEY_FIELD[1]), str): |
| 294 | for key in consts.IC_KEY_FIELD: | 300 | ic_name = id_card_dict[consts.IC_KEY_FIELD[0]].strip() |
| 295 | if not isinstance(id_card_dict.get(key), str): | 301 | ic_id = id_card_dict[consts.IC_KEY_FIELD[1]].strip() |
| 296 | break | 302 | if len(ic_name) > 0 and ic_id > 0: |
| 297 | value = id_card_dict[key].strip() | 303 | dda_id_bc_mapping.setdefault(consts.IC_FIELD, []).append((ic_name, ic_id, img_path)) |
| 298 | if len(value) > 0: | ||
| 299 | hil_id_bc_mapping.setdefault(consts.IC_FIELD, dict()).setdefault( | ||
| 300 | value, set()).add(img_path) | ||
| 301 | license_summary.setdefault(classify, []).extend(license_data) | 304 | license_summary.setdefault(classify, []).extend(license_data) |
| 302 | 305 | ||
| 303 | def license2_process(self, ocr_res_2, license_summary, pid, classify, res_list, pno, ino, part_idx, img_path, is_hil, hil_id_bc_mapping): | 306 | def license2_process(self, ocr_res_2, license_summary, pid, classify, res_list, pno, ino, part_idx, img_path, do_dda, dda_id_bc_mapping): |
| 304 | if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET: | 307 | if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET: |
| 305 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) | 308 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) |
| 306 | if pid == consts.BC_PID: | 309 | if pid == consts.BC_PID: |
| ... | @@ -309,11 +312,10 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -309,11 +312,10 @@ class Command(BaseCommand, LoggerMixin): |
| 309 | # for en_key, chn_key in consts.BC_FIELD: | 312 | # for en_key, chn_key in consts.BC_FIELD: |
| 310 | # res_dict[chn_key] = ocr_res_2.get(en_key, '') | 313 | # res_dict[chn_key] = ocr_res_2.get(en_key, '') |
| 311 | license_summary.setdefault(classify, []).append(ocr_res_2) | 314 | license_summary.setdefault(classify, []).append(ocr_res_2) |
| 312 | if is_hil and isinstance(ocr_res_2.get(consts.BC_KEY_FIELD), str): | 315 | if do_dda and isinstance(ocr_res_2.get(consts.BC_KEY_FIELD), str): |
| 313 | value = ocr_res_2[consts.BC_KEY_FIELD].strip() | 316 | bc_no = ocr_res_2[consts.BC_KEY_FIELD].strip() |
| 314 | if len(value) > 0: | 317 | if len(bc_no) > 0: |
| 315 | hil_id_bc_mapping.setdefault(consts.BC_FIELD, dict()).setdefault( | 318 | dda_id_bc_mapping.setdefault(consts.BC_FIELD, []).append((bc_no, img_path)) |
| 316 | value, set()).add(img_path) | ||
| 317 | else: | 319 | else: |
| 318 | # 营业执照等 | 320 | # 营业执照等 |
| 319 | for result_dict in ocr_res_2.get('ResultList', []): | 321 | for result_dict in ocr_res_2.get('ResultList', []): |
| ... | @@ -723,13 +725,14 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -723,13 +725,14 @@ class Command(BaseCommand, LoggerMixin): |
| 723 | doc_id = int(doc_id_str) | 725 | doc_id = int(doc_id_str) |
| 724 | doc_class = HILDoc if business_type == consts.HIL_PREFIX else AFCDoc | 726 | doc_class = HILDoc if business_type == consts.HIL_PREFIX else AFCDoc |
| 725 | is_hil = True if business_type == consts.HIL_PREFIX else False | 727 | is_hil = True if business_type == consts.HIL_PREFIX else False |
| 726 | hil_id_bc_mapping = dict() | 728 | dda_id_bc_mapping = dict() |
| 727 | 729 | ||
| 728 | doc_data_path = os.path.join(self.data_dir, business_type, consts.TMP_DIR_NAME, doc_id_str) | 730 | doc_data_path = os.path.join(self.data_dir, business_type, consts.TMP_DIR_NAME, doc_id_str) |
| 729 | excel_path = os.path.join(doc_data_path, '{0}.xlsx'.format(doc_id_str)) | 731 | excel_path = os.path.join(doc_data_path, '{0}.xlsx'.format(doc_id_str)) |
| 730 | 732 | ||
| 731 | try: | 733 | try: |
| 732 | doc = doc_class.objects.filter(id=doc_id).first() | 734 | doc = doc_class.objects.filter(id=doc_id).first() |
| 735 | do_dda = is_hil and doc.document_scheme == consts.DOC_SCHEME_LIST[1] | ||
| 733 | except Exception as e: | 736 | except Exception as e: |
| 734 | self.online_log.error('{0} [process error (db filter)] [task={1}] [error={2}]'.format( | 737 | self.online_log.error('{0} [process error (db filter)] [task={1}] [error={2}]'.format( |
| 735 | self.log_base, task_str, traceback.format_exc())) | 738 | self.log_base, task_str, traceback.format_exc())) |
| ... | @@ -771,7 +774,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -771,7 +774,7 @@ class Command(BaseCommand, LoggerMixin): |
| 771 | continue | 774 | continue |
| 772 | elif classify in consts.LICENSE_CLASSIFY_SET_1: # 证件1 | 775 | elif classify in consts.LICENSE_CLASSIFY_SET_1: # 证件1 |
| 773 | self.license1_process(ocr_data, license_summary, classify, res_list, pno, | 776 | self.license1_process(ocr_data, license_summary, classify, res_list, pno, |
| 774 | ino, part_idx, img_path, is_hil, hil_id_bc_mapping) | 777 | ino, part_idx, img_path, do_dda, dda_id_bc_mapping) |
| 775 | elif classify in consts.LICENSE_CLASSIFY_SET_2: # 证件2 | 778 | elif classify in consts.LICENSE_CLASSIFY_SET_2: # 证件2 |
| 776 | pid, _, _, _, _, _ = consts.LICENSE_CLASSIFY_MAPPING.get(classify) | 779 | pid, _, _, _, _, _ = consts.LICENSE_CLASSIFY_MAPPING.get(classify) |
| 777 | file_data = ocr_data.get('section_img') | 780 | file_data = ocr_data.get('section_img') |
| ... | @@ -818,7 +821,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -818,7 +821,7 @@ class Command(BaseCommand, LoggerMixin): |
| 818 | ocr_2_res['Name'] = name | 821 | ocr_2_res['Name'] = name |
| 819 | self.license2_process(ocr_2_res, license_summary, pid, classify, | 822 | self.license2_process(ocr_2_res, license_summary, pid, classify, |
| 820 | res_list, pno, ino, part_idx, img_path, | 823 | res_list, pno, ino, part_idx, img_path, |
| 821 | is_hil, hil_id_bc_mapping) | 824 | do_dda, dda_id_bc_mapping) |
| 822 | break | 825 | break |
| 823 | else: | 826 | else: |
| 824 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) | 827 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) |
| ... | @@ -921,31 +924,6 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -921,31 +924,6 @@ class Command(BaseCommand, LoggerMixin): |
| 921 | finally: | 924 | finally: |
| 922 | # TODO 识别结果存一张表,方便跑报表 | 925 | # TODO 识别结果存一张表,方便跑报表 |
| 923 | 926 | ||
| 924 | # DDA处理 | ||
| 925 | if is_hil: | ||
| 926 | try: | ||
| 927 | # 获取需要保存图片的集合 | ||
| 928 | hil_dda_save_img_list = [] | ||
| 929 | dda_res_list = license_summary.get(consts.DDA_CLASSIFY, []) | ||
| 930 | self.online_log.info('{0} [DDA process] [DDA_info={1}]'.format(self.log_base, dda_res_list)) | ||
| 931 | |||
| 932 | for dda_idx, dda_res in enumerate(dda_res_list): | ||
| 933 | save_img_dict = { | ||
| 934 | consts.DDA_FIELD: dda_res.get(consts.DDA_IMG_PATH) | ||
| 935 | } | ||
| 936 | for dda_field, license_field in consts.DDA_MAPPING: | ||
| 937 | target_str = dda_res.get(dda_field, '') | ||
| 938 | save_img_dict.setdefault(license_field, set()).update( | ||
| 939 | hil_id_bc_mapping.get(license_field, dict()).get(target_str, set())) | ||
| 940 | hil_dda_save_img_list.append(save_img_dict) | ||
| 941 | self.online_log.info('{0} [DDA process] [ic&bc_info={1}]'.format(self.log_base, hil_id_bc_mapping)) | ||
| 942 | self.online_log.info('{0} [DDA process] [img_path={1}]'.format(self.log_base, hil_dda_save_img_list)) | ||
| 943 | except Exception as e: | ||
| 944 | pass | ||
| 945 | # 保存图片 | ||
| 946 | # 数据库记录 | ||
| 947 | # report记录 | ||
| 948 | |||
| 949 | # CA比对 | 927 | # CA比对 |
| 950 | if doc.document_scheme == consts.DOC_SCHEME_LIST[0]: | 928 | if doc.document_scheme == consts.DOC_SCHEME_LIST[0]: |
| 951 | try: | 929 | try: |
| ... | @@ -995,6 +973,208 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -995,6 +973,208 @@ class Command(BaseCommand, LoggerMixin): |
| 995 | else: | 973 | else: |
| 996 | self.online_log.info('{0} [comparison info send success] [task={1}] ' | 974 | self.online_log.info('{0} [comparison info send success] [task={1}] ' |
| 997 | '[res_id={2}]'.format(self.log_base, task_str, res_obj.id)) | 975 | '[res_id={2}]'.format(self.log_base, task_str, res_obj.id)) |
| 976 | |||
| 977 | # DDA处理 | ||
| 978 | if do_dda: | ||
| 979 | # 入库 | ||
| 980 | try: | ||
| 981 | dda_record = DDARecords.objects.filter( | ||
| 982 | application_id=doc.application_id).first() | ||
| 983 | if dda_record is None: | ||
| 984 | dda_record = DDARecords(application_id=doc.application_id) | ||
| 985 | except Exception as e: | ||
| 986 | self.online_log.error('{0} [process error (dda db get)] [task={1}] ' | ||
| 987 | '[error={2}]'.format(self.log_base, task_str, | ||
| 988 | traceback.format_exc())) | ||
| 989 | else: | ||
| 990 | try: | ||
| 991 | if not dda_record.all_found: | ||
| 992 | found_time = timezone.now() | ||
| 993 | move_img_path_dict = dict() | ||
| 994 | ic_res_list = dda_id_bc_mapping.get(consts.IC_FIELD, []) | ||
| 995 | bc_res_list = dda_id_bc_mapping.get(consts.BC_FIELD, []) | ||
| 996 | self.online_log.info('{0} [dda process] [task={1}] [ic={2}] ' | ||
| 997 | '[bc={3}]'.format(self.log_base, task_str, ic_res_list, | ||
| 998 | bc_res_list)) | ||
| 999 | |||
| 1000 | if not dda_record.is_dda_found: | ||
| 1001 | try: | ||
| 1002 | # DDA过滤,获取有效DDA | ||
| 1003 | best_dda_res = None | ||
| 1004 | dda_res_list = license_summary.get(consts.DDA_CLASSIFY, []) | ||
| 1005 | if len(dda_res_list) > 0: | ||
| 1006 | dda_res_list.sort(key=lambda x: x.get(consts.DDA_PRO, 0), | ||
| 1007 | reverse=True) | ||
| 1008 | tmp_best_dda_res = dda_res_list[0] | ||
| 1009 | if tmp_best_dda_res.get(consts.DDA_PRO, 0) >= 0.6: | ||
| 1010 | best_dda_res = tmp_best_dda_res | ||
| 1011 | self.online_log.info( | ||
| 1012 | '{0} [dda process] [task={1}] [dda={2}]'.format( | ||
| 1013 | self.log_base, task_str, dda_res_list)) | ||
| 1014 | except Exception as e: | ||
| 1015 | best_dda_res = None | ||
| 1016 | |||
| 1017 | dda_record.is_dda_found = False if best_dda_res is None else True | ||
| 1018 | |||
| 1019 | if dda_record.is_dda_found: | ||
| 1020 | dda_path = best_dda_res.get(consts.DDA_IMG_PATH, '') | ||
| 1021 | customer_name = best_dda_res.get(consts.DDA_IC_NAME, '') | ||
| 1022 | customer_id = best_dda_res.get(consts.DDA_IC_ID, '') | ||
| 1023 | account_id = best_dda_res.get(consts.DDA_BC_ID, '') | ||
| 1024 | dda_record.dda_path = dda_path | ||
| 1025 | dda_record.dda_found_time = found_time | ||
| 1026 | dda_record.customer_name = customer_name | ||
| 1027 | dda_record.customer_id = customer_id | ||
| 1028 | dda_record.account_id = account_id | ||
| 1029 | # move | ||
| 1030 | move_img_path_dict.setdefault(consts.DDA_FIELD, set()).add(dda_path) | ||
| 1031 | |||
| 1032 | if dda_record.is_dda_found: | ||
| 1033 | |||
| 1034 | try: | ||
| 1035 | if not dda_record.is_id_found: | ||
| 1036 | for ic_name, ic_id, ic_img_path in ic_res_list: | ||
| 1037 | if ic_id == dda_record.customer_id \ | ||
| 1038 | or ic_name == dda_record.customer_name: | ||
| 1039 | dda_record.is_id_found = True | ||
| 1040 | dda_record.id_path = ic_img_path | ||
| 1041 | dda_record.id_found_time = found_time | ||
| 1042 | move_img_path_dict.setdefault(consts.IC_FIELD, set()).add( | ||
| 1043 | ic_img_path) | ||
| 1044 | break | ||
| 1045 | else: | ||
| 1046 | id_record = IDBCRecords.objects.filter( | ||
| 1047 | application_id=doc.application_id, | ||
| 1048 | target_id=dda_record.customer_id, | ||
| 1049 | is_id=True).first() | ||
| 1050 | |||
| 1051 | if id_record is None: | ||
| 1052 | id_record = IDBCRecords.objects.filter( | ||
| 1053 | application_id=doc.application_id, | ||
| 1054 | target_name=dda_record.customer_name, | ||
| 1055 | is_id=True).first() | ||
| 1056 | |||
| 1057 | if id_record is not None: | ||
| 1058 | dda_record.is_id_found = True | ||
| 1059 | dda_record.id_path = id_record.file_path | ||
| 1060 | dda_record.id_found_time = id_record.create_time | ||
| 1061 | move_img_path_dict.setdefault(consts.IC_FIELD, set()).add( | ||
| 1062 | id_record.file_path) | ||
| 1063 | except Exception as e: | ||
| 1064 | self.online_log.error( | ||
| 1065 | '{0} [process error (dda id process)] [task={1}] ' | ||
| 1066 | '[error={2}]'.format(self.log_base, task_str, | ||
| 1067 | traceback.format_exc())) | ||
| 1068 | |||
| 1069 | try: | ||
| 1070 | if not dda_record.is_bc_found: | ||
| 1071 | for bc_no, bc_img_path in bc_res_list: | ||
| 1072 | if bc_no == dda_record.account_id: | ||
| 1073 | dda_record.is_bc_found = True | ||
| 1074 | dda_record.bc_path = bc_img_path | ||
| 1075 | dda_record.bc_found_time = found_time | ||
| 1076 | move_img_path_dict.setdefault(consts.BC_FIELD, set()).add( | ||
| 1077 | bc_img_path) | ||
| 1078 | break | ||
| 1079 | else: | ||
| 1080 | bc_record = IDBCRecords.objects.filter( | ||
| 1081 | application_id=doc.application_id, | ||
| 1082 | target_id=dda_record.account_id, | ||
| 1083 | is_id=False).first() | ||
| 1084 | |||
| 1085 | if bc_record is not None: | ||
| 1086 | dda_record.is_bc_found = True | ||
| 1087 | dda_record.bc_path = bc_record.file_path | ||
| 1088 | dda_record.bc_found_time = bc_record.create_time | ||
| 1089 | move_img_path_dict.setdefault(consts.BC_FIELD, set()).add( | ||
| 1090 | bc_record.file_path) | ||
| 1091 | except Exception as e: | ||
| 1092 | self.online_log.error( | ||
| 1093 | '{0} [process error (dda bc process)] [task={1}] ' | ||
| 1094 | '[error={2}]'.format(self.log_base, task_str, | ||
| 1095 | traceback.format_exc())) | ||
| 1096 | |||
| 1097 | if dda_record.is_dda_found and dda_record.is_id_found and dda_record.is_bc_found: | ||
| 1098 | dda_record.all_found = True | ||
| 1099 | dda_record.save() | ||
| 1100 | |||
| 1101 | # 图片移动 | ||
| 1102 | try: | ||
| 1103 | if len(move_img_path_dict) > 0: | ||
| 1104 | self.online_log.info( | ||
| 1105 | '{0} [dda process] [task={1}] [move_img_path={2}]'.format( | ||
| 1106 | self.log_base, task_str, move_img_path_dict)) | ||
| 1107 | |||
| 1108 | wanting_dir = os.path.join(self.dda_wanting_dir, doc.application_id) | ||
| 1109 | wanting_dir_exists = os.path.isdir(wanting_dir) | ||
| 1110 | if dda_record.all_found: | ||
| 1111 | target_dir = os.path.join(self.dda_complete_dir, doc.application_id) | ||
| 1112 | if wanting_dir_exists: | ||
| 1113 | shutil.move(wanting_dir, target_dir) | ||
| 1114 | else: | ||
| 1115 | os.makedirs(target_dir, exist_ok=True) | ||
| 1116 | else: | ||
| 1117 | target_dir = wanting_dir | ||
| 1118 | if not wanting_dir_exists: | ||
| 1119 | os.makedirs(target_dir, exist_ok=True) | ||
| 1120 | |||
| 1121 | for prefix, path_set in move_img_path_dict.items(): | ||
| 1122 | for idx, path in enumerate(path_set): | ||
| 1123 | if os.path.isfile(path): | ||
| 1124 | file_name = '{0}_{1}{2}'.format( | ||
| 1125 | prefix, idx, os.path.splitext(path)[-1]) | ||
| 1126 | target_path = os.path.join(target_dir, file_name) | ||
| 1127 | shutil.copyfile(path, target_path) | ||
| 1128 | else: | ||
| 1129 | self.online_log.warn( | ||
| 1130 | '{0} [dda process] [img path empty] [task={1}] ' | ||
| 1131 | '[path={2}]'.format(self.log_base, task_str, path)) | ||
| 1132 | except Exception as e: | ||
| 1133 | self.online_log.error( | ||
| 1134 | '{0} [process error (dda img move)] [task={1}] ' | ||
| 1135 | '[error={2}]'.format(self.log_base, task_str, | ||
| 1136 | traceback.format_exc())) | ||
| 1137 | |||
| 1138 | # id & bc 入库 | ||
| 1139 | try: | ||
| 1140 | if not dda_record.is_dda_found: | ||
| 1141 | ic_set = set() | ||
| 1142 | bc_set = set() | ||
| 1143 | for ic_name, ic_id, ic_img_path in ic_res_list: | ||
| 1144 | query_str = '{0}{1}'.format(ic_name, ic_id) | ||
| 1145 | if query_str in ic_set: | ||
| 1146 | continue | ||
| 1147 | ic_set.add(query_str) | ||
| 1148 | IDBCRecords.objects.create( | ||
| 1149 | application_id=doc.application_id, | ||
| 1150 | target_name=ic_name, | ||
| 1151 | target_id=ic_id, | ||
| 1152 | is_id=True, | ||
| 1153 | file_path=ic_img_path | ||
| 1154 | ) | ||
| 1155 | for bc_no, bc_img_path in bc_res_list: | ||
| 1156 | if bc_no in bc_set: | ||
| 1157 | continue | ||
| 1158 | bc_set.add(bc_no) | ||
| 1159 | IDBCRecords.objects.create( | ||
| 1160 | application_id=doc.application_id, | ||
| 1161 | target_id=bc_no, | ||
| 1162 | is_id=False, | ||
| 1163 | file_path=bc_img_path | ||
| 1164 | ) | ||
| 1165 | except Exception as e: | ||
| 1166 | self.online_log.error( | ||
| 1167 | '{0} [process error (dda id&bc db save)] [task={1}] ' | ||
| 1168 | '[error={2}]'.format(self.log_base, task_str, | ||
| 1169 | traceback.format_exc())) | ||
| 1170 | |||
| 1171 | # TODO report | ||
| 1172 | |||
| 1173 | except Exception as e: | ||
| 1174 | self.online_log.error('{0} [process error (dda process)] [task={1}] ' | ||
| 1175 | '[error={2}]'.format(self.log_base, task_str, | ||
| 1176 | traceback.format_exc())) | ||
| 1177 | |||
| 998 | finally: | 1178 | finally: |
| 999 | try: | 1179 | try: |
| 1000 | img_save_path = os.path.join(doc_data_path, 'img') | 1180 | img_save_path = os.path.join(doc_data_path, 'img') | ... | ... |
| ... | @@ -267,3 +267,52 @@ class HILOCRResult(models.Model): | ... | @@ -267,3 +267,52 @@ class HILOCRResult(models.Model): |
| 267 | managed = False | 267 | managed = False |
| 268 | db_table = 'hil_ocr_result' | 268 | db_table = 'hil_ocr_result' |
| 269 | 269 | ||
| 270 | |||
| 271 | # DDA ID & BC ----> HIL SE 专有 | ||
| 272 | class DDARecords(models.Model): | ||
| 273 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | ||
| 274 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 | ||
| 275 | |||
| 276 | is_dda_found = models.BooleanField(default=False, verbose_name="DDA是否找到") | ||
| 277 | is_id_found = models.BooleanField(default=False, verbose_name="身份证是否找到") | ||
| 278 | is_bc_found = models.BooleanField(default=False, verbose_name="银行卡是否找到") | ||
| 279 | all_found = models.BooleanField(default=False, verbose_name="是否全找到") | ||
| 280 | |||
| 281 | dda_path = models.CharField(null=True, max_length=1024, verbose_name="DDA图片路径") | ||
| 282 | id_path = models.CharField(null=True, max_length=1024, verbose_name="身份证图片路径") | ||
| 283 | bc_path = models.CharField(null=True, max_length=1024, verbose_name="银行卡图片路径") | ||
| 284 | |||
| 285 | customer_name = models.CharField(null=True, max_length=1024, verbose_name="DDA身份证姓名") | ||
| 286 | customer_id = models.CharField(null=True, max_length=1024, verbose_name="DDA身份证号码") | ||
| 287 | account_id = models.CharField(null=True, max_length=1024, verbose_name="DDA银行卡号") | ||
| 288 | |||
| 289 | dda_found_time = models.DateTimeField(null=True, verbose_name='DDA时间') | ||
| 290 | id_found_time = models.DateTimeField(null=True, verbose_name='身份证时间') | ||
| 291 | bc_found_time = models.DateTimeField(null=True, verbose_name='银行卡时间') | ||
| 292 | |||
| 293 | update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') # 索引 | ||
| 294 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') # 索引 | ||
| 295 | |||
| 296 | class Meta: | ||
| 297 | managed = False | ||
| 298 | db_table = 'dda_records' | ||
| 299 | |||
| 300 | |||
| 301 | class IDBCRecords(models.Model): | ||
| 302 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | ||
| 303 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 | ||
| 304 | |||
| 305 | target_name = models.CharField(null=True, max_length=1024, verbose_name="DDA身份证姓名") # 与申请号联合索引 | ||
| 306 | target_id = models.CharField(max_length=1024, verbose_name="DDA身份证号码or银行卡号") # 与申请号联合索引 | ||
| 307 | |||
| 308 | is_id = models.BooleanField(default=True, verbose_name="身份证or银行卡") | ||
| 309 | |||
| 310 | file_path = models.CharField(max_length=1024, verbose_name="图片路径") | ||
| 311 | |||
| 312 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | ||
| 313 | |||
| 314 | class Meta: | ||
| 315 | managed = False | ||
| 316 | db_table = 'idbc_records' | ||
| 317 | |||
| 318 | ... | ... |
src/common/tools/mssql_script4.py
0 → 100644
| 1 | import pyodbc | ||
| 2 | |||
| 3 | hil_sql = """ | ||
| 4 | create table dda_records | ||
| 5 | ( | ||
| 6 | id bigint identity | ||
| 7 | primary key, | ||
| 8 | application_id nvarchar(64) not null, | ||
| 9 | is_dda_found bit default 0 not null, | ||
| 10 | is_id_found bit default 0 not null, | ||
| 11 | is_bc_found bit default 0 not null, | ||
| 12 | all_found bit default 0 not null, | ||
| 13 | dda_path nvarchar(1024), | ||
| 14 | id_path nvarchar(1024), | ||
| 15 | bc_path nvarchar(1024), | ||
| 16 | customer_name nvarchar(1024), | ||
| 17 | customer_id nvarchar(1024), | ||
| 18 | account_id nvarchar(1024), | ||
| 19 | dda_found_time datetime, | ||
| 20 | id_found_time datetime, | ||
| 21 | bc_found_time datetime, | ||
| 22 | update_time datetime not null, | ||
| 23 | create_time datetime not null, | ||
| 24 | ); | ||
| 25 | |||
| 26 | create index dda_records_application_id_index | ||
| 27 | on dda_records (application_id); | ||
| 28 | |||
| 29 | create index dda_records_update_time_index | ||
| 30 | on dda_records (update_time); | ||
| 31 | |||
| 32 | create index dda_records_create_time_index | ||
| 33 | on dda_records (create_time); | ||
| 34 | |||
| 35 | create table idbc_records | ||
| 36 | ( | ||
| 37 | id bigint identity | ||
| 38 | primary key, | ||
| 39 | application_id nvarchar(64) not null, | ||
| 40 | target_name nvarchar(1024), | ||
| 41 | target_id nvarchar(1024) not null, | ||
| 42 | is_id bit default 1 not null, | ||
| 43 | file_path nvarchar(1024) not null, | ||
| 44 | create_time datetime not null, | ||
| 45 | ); | ||
| 46 | |||
| 47 | create index idbc_records_application_id_index | ||
| 48 | on idbc_records (application_id); | ||
| 49 | |||
| 50 | create index idbc_records_application_id_target_name_index | ||
| 51 | on idbc_records (application_id, target_name); | ||
| 52 | |||
| 53 | create index idbc_records_application_id_target_id_index | ||
| 54 | on idbc_records (application_id, target_id); | ||
| 55 | """ | ||
| 56 | |||
| 57 | hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | ||
| 58 | hil_cursor = hil_cnxn.cursor() | ||
| 59 | hil_cursor.execute(hil_sql) | ||
| 60 | hil_cursor.close() | ||
| 61 | hil_cnxn.close() | ||
| 62 | |||
| 63 | # afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | ||
| 64 | # afc_cursor = afc_cnxn.cursor() | ||
| 65 | # afc_cursor.execute(afc_sql) | ||
| 66 | # afc_cursor.close() | ||
| 67 | # afc_cnxn.close() | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment