merge fix
Showing
5 changed files
with
409 additions
and
13 deletions
| ... | @@ -520,7 +520,7 @@ OTHER_TUPLE = (None, None, None, None, None, None, None, None, None, None, None, | ... | @@ -520,7 +520,7 @@ OTHER_TUPLE = (None, None, None, None, None, None, None, None, None, None, None, |
| 520 | # "35":"针式打印-部分格线-竖版-邮储银行", | 520 | # "35":"针式打印-部分格线-竖版-邮储银行", |
| 521 | # "36":"针式打印-部分格线-竖版-邮储银行-绿卡", | 521 | # "36":"针式打印-部分格线-竖版-邮储银行-绿卡", |
| 522 | 522 | ||
| 523 | # "38":"普通打印-无格线-农业银行-整数-特殊", | 523 | # "50":"普通打印-无格线-农业银行-整数-特殊", |
| 524 | 524 | ||
| 525 | CLASSIFY_LIST = [ | 525 | CLASSIFY_LIST = [ |
| 526 | ('其他', OTHER_TUPLE), | 526 | ('其他', OTHER_TUPLE), |
| ... | @@ -563,6 +563,18 @@ CLASSIFY_LIST = [ | ... | @@ -563,6 +563,18 @@ CLASSIFY_LIST = [ |
| 563 | ('针式打印-部分格线-竖版-邮储银行', (2, None, 5, 6, None, 4, None, 7, None, None, None, None, None)), | 563 | ('针式打印-部分格线-竖版-邮储银行', (2, None, 5, 6, None, 4, None, 7, None, None, None, None, None)), |
| 564 | ('针式打印-部分格线-竖版-邮储银行-绿卡', (2, None, 5, 6, None, 4, None, 7, None, None, None, None, None)), | 564 | ('针式打印-部分格线-竖版-邮储银行-绿卡', (2, None, 5, 6, None, 4, None, 7, None, None, None, None, None)), |
| 565 | ('其他', OTHER_TUPLE), | 565 | ('其他', OTHER_TUPLE), |
| 566 | ('其他', OTHER_TUPLE), | ||
| 567 | ('其他', OTHER_TUPLE), | ||
| 568 | ('其他', OTHER_TUPLE), | ||
| 569 | ('其他', OTHER_TUPLE), | ||
| 570 | ('其他', OTHER_TUPLE), | ||
| 571 | ('其他', OTHER_TUPLE), | ||
| 572 | ('其他', OTHER_TUPLE), | ||
| 573 | ('其他', OTHER_TUPLE), | ||
| 574 | ('其他', OTHER_TUPLE), | ||
| 575 | ('其他', OTHER_TUPLE), | ||
| 576 | ('其他', OTHER_TUPLE), | ||
| 577 | ('其他', OTHER_TUPLE), | ||
| 566 | 578 | ||
| 567 | ('普通打印-无格线-农业银行-整数-特殊', (1, None, 3, 4, None, 2, None, 5, None, None, None, None, None)), | 579 | ('普通打印-无格线-农业银行-整数-特殊', (1, None, 3, 4, None, 2, None, 5, None, None, None, None, None)), |
| 568 | ] | 580 | ] |
| ... | @@ -608,6 +620,18 @@ CLASSIFY_HEADER_LIST = [ | ... | @@ -608,6 +620,18 @@ CLASSIFY_HEADER_LIST = [ |
| 608 | ('序号', '交易日期', '交易渠道', '摘要', '交易金额', '账户余额', '对方账号/卡号/汇票号', '原子账号', '交易机构名称'), | 620 | ('序号', '交易日期', '交易渠道', '摘要', '交易金额', '账户余额', '对方账号/卡号/汇票号', '原子账号', '交易机构名称'), |
| 609 | ('序号', '交易日期', '交易渠道', '摘要', '交易金额', '账户余额', '对方账号/卡号/汇票号', '原子账号', '交易机构名称'), | 621 | ('序号', '交易日期', '交易渠道', '摘要', '交易金额', '账户余额', '对方账号/卡号/汇票号', '原子账号', '交易机构名称'), |
| 610 | OTHER_TUPLE, | 622 | OTHER_TUPLE, |
| 623 | OTHER_TUPLE, | ||
| 624 | OTHER_TUPLE, | ||
| 625 | OTHER_TUPLE, | ||
| 626 | OTHER_TUPLE, | ||
| 627 | OTHER_TUPLE, | ||
| 628 | OTHER_TUPLE, | ||
| 629 | OTHER_TUPLE, | ||
| 630 | OTHER_TUPLE, | ||
| 631 | OTHER_TUPLE, | ||
| 632 | OTHER_TUPLE, | ||
| 633 | OTHER_TUPLE, | ||
| 634 | OTHER_TUPLE, | ||
| 611 | 635 | ||
| 612 | ('交易日期', '摘要/附言', '交易金额', '账户余额', '对方账号和户名'), | 636 | ('交易日期', '摘要/附言', '交易金额', '账户余额', '对方账号和户名'), |
| 613 | ] | 637 | ] |
| ... | @@ -812,7 +836,7 @@ MVI_FIELD_ORDER = (('发票代码', '发票代码'), | ... | @@ -812,7 +836,7 @@ MVI_FIELD_ORDER = (('发票代码', '发票代码'), |
| 812 | ('主管税务机关及代码', '主管税务机关及代码'), | 836 | ('主管税务机关及代码', '主管税务机关及代码'), |
| 813 | ('吨位', '吨位'), | 837 | ('吨位', '吨位'), |
| 814 | ('限乘人数', '限乘人数'),) | 838 | ('限乘人数', '限乘人数'),) |
| 815 | IC_PID = VAT_PID = VATS_PID = MVC_PID = MVI_PID = None | 839 | IC_PID = VAT_PID = VATS_PID = MVC_PID = MVI_PID = RP_PID = None |
| 816 | 840 | ||
| 817 | # 营业执照 | 841 | # 营业执照 |
| 818 | BL_CN_NAME = '营业执照' | 842 | BL_CN_NAME = '营业执照' |
| ... | @@ -916,6 +940,10 @@ BC_FIELD_ORDER = (('BankName', '发卡行名称'), | ... | @@ -916,6 +940,10 @@ BC_FIELD_ORDER = (('BankName', '发卡行名称'), |
| 916 | ('CardType', '银行卡类型'), | 940 | ('CardType', '银行卡类型'), |
| 917 | ('Name', '持卡人姓名'),) | 941 | ('Name', '持卡人姓名'),) |
| 918 | 942 | ||
| 943 | # DDA | ||
| 944 | DDA_CN_NAME = 'DDA' | ||
| 945 | DDA_CLASSIFY = 38 | ||
| 946 | |||
| 919 | SUCCESS_CODE_SET = {'0', 0} | 947 | SUCCESS_CODE_SET = {'0', 0} |
| 920 | 948 | ||
| 921 | FIELD_ORDER_MAP = { | 949 | FIELD_ORDER_MAP = { |
| ... | @@ -941,7 +969,7 @@ MODEL_FIELD_VAT = 'vat_count' | ... | @@ -941,7 +969,7 @@ MODEL_FIELD_VAT = 'vat_count' |
| 941 | 969 | ||
| 942 | LICENSE_ORDER = ((MVI_CLASSIFY, (MVI_PID, MVI_CN_NAME, MVI_FIELD_ORDER, False, False, MODEL_FIELD_MVI)), | 970 | LICENSE_ORDER = ((MVI_CLASSIFY, (MVI_PID, MVI_CN_NAME, MVI_FIELD_ORDER, False, False, MODEL_FIELD_MVI)), |
| 943 | (IC_CLASSIFY, (IC_PID, IC_CN_NAME, None, True, False, MODEL_FIELD_IC)), | 971 | (IC_CLASSIFY, (IC_PID, IC_CN_NAME, None, True, False, MODEL_FIELD_IC)), |
| 944 | (RP_CLASSIFY, (None, RP_CN_NAME, None, True, False, MODEL_FIELD_RP)), | 972 | (RP_CLASSIFY, (RP_PID, RP_CN_NAME, None, True, False, MODEL_FIELD_RP)), |
| 945 | (BC_CLASSIFY, (BC_PID, BC_CN_NAME, BC_FIELD_ORDER, False, False, MODEL_FIELD_BC)), | 973 | (BC_CLASSIFY, (BC_PID, BC_CN_NAME, BC_FIELD_ORDER, False, False, MODEL_FIELD_BC)), |
| 946 | (BL_CLASSIFY, (BL_PID, BL_CN_NAME, BL_FIELD_ORDER, False, False, MODEL_FIELD_BL)), | 974 | (BL_CLASSIFY, (BL_PID, BL_CN_NAME, BL_FIELD_ORDER, False, False, MODEL_FIELD_BL)), |
| 947 | (UCI_CLASSIFY, (UCI_PID, UCI_CN_NAME, UCI_FIELD_ORDER, False, False, MODEL_FIELD_UCI)), | 975 | (UCI_CLASSIFY, (UCI_PID, UCI_CN_NAME, UCI_FIELD_ORDER, False, False, MODEL_FIELD_UCI)), |
| ... | @@ -960,12 +988,12 @@ FOLDER_LICENSE_ORDER = ((MVI_CLASSIFY, (MVI_PID, MVI_CN_NAME, MVI_FIELD_ORDER, F | ... | @@ -960,12 +988,12 @@ FOLDER_LICENSE_ORDER = ((MVI_CLASSIFY, (MVI_PID, MVI_CN_NAME, MVI_FIELD_ORDER, F |
| 960 | LICENSE_CLASSIFY_MAPPING = dict(LICENSE_ORDER) | 988 | LICENSE_CLASSIFY_MAPPING = dict(LICENSE_ORDER) |
| 961 | 989 | ||
| 962 | OTHER_CLASSIFY_SET = {OTHER_CLASSIFY} | 990 | OTHER_CLASSIFY_SET = {OTHER_CLASSIFY} |
| 963 | LICENSE_CLASSIFY_SET_1 = {IC_CLASSIFY, VAT_CLASSIFY, MVC_CLASSIFY, MVI_CLASSIFY, UCI_CLASSIFY} | 991 | LICENSE_CLASSIFY_SET_1 = {IC_CLASSIFY, VAT_CLASSIFY, MVC_CLASSIFY, MVI_CLASSIFY, UCI_CLASSIFY, DDA_CLASSIFY} |
| 964 | LICENSE_CLASSIFY_SET_2 = {BL_CLASSIFY, EEP_CLASSIFY, DL_CLASSIFY, PP_CLASSIFY, BC_CLASSIFY} | 992 | LICENSE_CLASSIFY_SET_2 = {BL_CLASSIFY, EEP_CLASSIFY, DL_CLASSIFY, PP_CLASSIFY, BC_CLASSIFY} |
| 965 | 993 | ||
| 966 | NYYH_CLASSIFY = {17, 18} | 994 | NYYH_CLASSIFY = {17, 18} |
| 967 | NYZS_CLASSIFY = 18 | 995 | NYZS_CLASSIFY = 18 |
| 968 | SPECIAL_NYZS_CLASSIFY = 38 | 996 | SPECIAL_NYZS_CLASSIFY = 50 |
| 969 | MS_CLASSIFY = 21 | 997 | MS_CLASSIFY = 21 |
| 970 | MS_ERROR_COL = (5, 6) | 998 | MS_ERROR_COL = (5, 6) |
| 971 | WECHART_CLASSIFY = 12 | 999 | WECHART_CLASSIFY = 12 |
| ... | @@ -1168,5 +1196,25 @@ CO_ORDER = ('customerType', 'customerChineseName', 'legalRepName', 'idNum', 'bus | ... | @@ -1168,5 +1196,25 @@ CO_ORDER = ('customerType', 'customerChineseName', 'legalRepName', 'idNum', 'bus |
| 1168 | PREFIX_MVC = 'GB' | 1196 | PREFIX_MVC = 'GB' |
| 1169 | PREFIX_DL = 'DL' | 1197 | PREFIX_DL = 'DL' |
| 1170 | 1198 | ||
| 1199 | # --------------- DDA 保存图片 -------------------- | ||
| 1200 | DDA_FIELD = 'DDA' | ||
| 1201 | IC_FIELD = 'ID' | ||
| 1202 | BC_FIELD = 'BC' | ||
| 1203 | |||
| 1204 | IC_KEY_FIELD = ('姓名', '公民身份号码') | ||
| 1205 | BC_KEY_FIELD = 'CardNum' | ||
| 1171 | 1206 | ||
| 1207 | DDA_IC_NAME = 'customer_name' | ||
| 1208 | DDA_IC_ID = 'customer_id' | ||
| 1209 | DDA_BC_NAME = 'account_name' | ||
| 1210 | DDA_BC_ID = 'account_id' | ||
| 1211 | DDA_IMG_PATH = 'img_path' | ||
| 1212 | DDA_PRO = 'pro' | ||
| 1213 | |||
| 1214 | |||
| 1215 | DDA_MAPPING = [ | ||
| 1216 | (DDA_IC_NAME, IC_FIELD), | ||
| 1217 | (DDA_IC_ID, IC_FIELD), | ||
| 1218 | (DDA_BC_ID, BC_FIELD), | ||
| 1219 | ] | ||
| 1172 | 1220 | ... | ... |
| ... | @@ -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, FailureReason, WorkflowName, ProcessName, RequestTeam, RequestTrigger | 23 | from apps.doc.named_enum import KeywordsType, FailureReason, WorkflowName, ProcessName, RequestTeam, RequestTrigger |
| 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, HILOCRReport, AFCOCRReport | 26 | from apps.doc.models import DocStatus, HILDoc, AFCDoc, Keywords, HILOCRResult, AFCOCRResult, HILOCRReport, AFCOCRReport, 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', 'SF5-CL-S-1', '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,13 +193,25 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -189,13 +193,25 @@ 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): | 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: |
| 196 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY)) | 200 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY)) |
| 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)) |
| 203 | if classify == consts.DDA_CLASSIFY: # DDA处理 | ||
| 204 | pro = ocr_data.get('confidence') | ||
| 205 | dda_ocr_result = { | ||
| 206 | consts.DDA_IC_NAME: license_data.get('result', {}).get(consts.DDA_IC_NAME, {}).get('words', ''), | ||
| 207 | consts.DDA_IC_ID: license_data.get('result', {}).get(consts.DDA_IC_ID, {}).get('words', ''), | ||
| 208 | consts.DDA_BC_NAME: license_data.get('result', {}).get(consts.DDA_BC_NAME, {}).get('words', ''), | ||
| 209 | consts.DDA_BC_ID: license_data.get('result', {}).get(consts.DDA_BC_ID, {}).get('words', ''), | ||
| 210 | consts.DDA_IMG_PATH: img_path, | ||
| 211 | consts.DDA_PRO: pro | ||
| 212 | } | ||
| 213 | license_summary.setdefault(classify, []).append(dda_ocr_result) | ||
| 214 | |||
| 199 | if classify == consts.MVC_CLASSIFY: # 车辆登记证 3/4页结果整合 | 215 | if classify == consts.MVC_CLASSIFY: # 车辆登记证 3/4页结果整合 |
| 200 | for mvc_dict in license_data: | 216 | for mvc_dict in license_data: |
| 201 | try: | 217 | try: |
| ... | @@ -231,6 +247,8 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -231,6 +247,8 @@ class Command(BaseCommand, LoggerMixin): |
| 231 | mvc_dict['解除抵押日期'].append( | 247 | mvc_dict['解除抵押日期'].append( |
| 232 | register_info.get('details', {}).get('date', {}).get('words', '')) | 248 | register_info.get('details', {}).get('date', {}).get('words', '')) |
| 233 | del mvc_res | 249 | del mvc_res |
| 250 | license_summary.setdefault(classify, []).extend(license_data) | ||
| 251 | |||
| 234 | if classify == consts.IC_CLASSIFY: # 身份证真伪 | 252 | if classify == consts.IC_CLASSIFY: # 身份证真伪 |
| 235 | for id_card_dict in license_data: | 253 | for id_card_dict in license_data: |
| 236 | try: | 254 | try: |
| ... | @@ -277,9 +295,15 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -277,9 +295,15 @@ class Command(BaseCommand, LoggerMixin): |
| 277 | '{0} [ocr_4 failed] [img_path={1}]'.format(self.log_base, img_path)) | 295 | '{0} [ocr_4 failed] [img_path={1}]'.format(self.log_base, img_path)) |
| 278 | 296 | ||
| 279 | 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) |
| 298 | finally: | ||
| 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): | ||
| 300 | ic_name = id_card_dict[consts.IC_KEY_FIELD[0]].strip() | ||
| 301 | ic_id = id_card_dict[consts.IC_KEY_FIELD[1]].strip() | ||
| 302 | if len(ic_name) > 0 and len(ic_id) > 0: | ||
| 303 | dda_id_bc_mapping.setdefault(consts.IC_FIELD, []).append((ic_name, ic_id, img_path)) | ||
| 280 | license_summary.setdefault(classify, []).extend(license_data) | 304 | license_summary.setdefault(classify, []).extend(license_data) |
| 281 | 305 | ||
| 282 | def license2_process(self, ocr_res_2, license_summary, pid, classify, res_list, pno, ino, part_idx): | 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): |
| 283 | if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET: | 307 | if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET: |
| 284 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) | 308 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) |
| 285 | if pid == consts.BC_PID: | 309 | if pid == consts.BC_PID: |
| ... | @@ -288,6 +312,10 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -288,6 +312,10 @@ class Command(BaseCommand, LoggerMixin): |
| 288 | # for en_key, chn_key in consts.BC_FIELD: | 312 | # for en_key, chn_key in consts.BC_FIELD: |
| 289 | # res_dict[chn_key] = ocr_res_2.get(en_key, '') | 313 | # res_dict[chn_key] = ocr_res_2.get(en_key, '') |
| 290 | license_summary.setdefault(classify, []).append(ocr_res_2) | 314 | license_summary.setdefault(classify, []).append(ocr_res_2) |
| 315 | if do_dda and isinstance(ocr_res_2.get(consts.BC_KEY_FIELD), str): | ||
| 316 | bc_no = ocr_res_2[consts.BC_KEY_FIELD].strip() | ||
| 317 | if len(bc_no) > 0: | ||
| 318 | dda_id_bc_mapping.setdefault(consts.BC_FIELD, []).append((bc_no, img_path)) | ||
| 291 | else: | 319 | else: |
| 292 | # 营业执照等 | 320 | # 营业执照等 |
| 293 | for result_dict in ocr_res_2.get('ResultList', []): | 321 | for result_dict in ocr_res_2.get('ResultList', []): |
| ... | @@ -714,6 +742,8 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -714,6 +742,8 @@ class Command(BaseCommand, LoggerMixin): |
| 714 | business_type, doc_id_str = task_str.split(consts.SPLIT_STR) | 742 | business_type, doc_id_str = task_str.split(consts.SPLIT_STR) |
| 715 | doc_id = int(doc_id_str) | 743 | doc_id = int(doc_id_str) |
| 716 | doc_class = HILDoc if business_type == consts.HIL_PREFIX else AFCDoc | 744 | doc_class = HILDoc if business_type == consts.HIL_PREFIX else AFCDoc |
| 745 | is_hil = True if business_type == consts.HIL_PREFIX else False | ||
| 746 | dda_id_bc_mapping = dict() | ||
| 717 | 747 | ||
| 718 | doc_data_path = os.path.join(self.data_dir, business_type, consts.TMP_DIR_NAME, doc_id_str) | 748 | doc_data_path = os.path.join(self.data_dir, business_type, consts.TMP_DIR_NAME, doc_id_str) |
| 719 | excel_path = os.path.join(doc_data_path, '{0}.xlsx'.format(doc_id_str)) | 749 | excel_path = os.path.join(doc_data_path, '{0}.xlsx'.format(doc_id_str)) |
| ... | @@ -726,6 +756,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -726,6 +756,7 @@ class Command(BaseCommand, LoggerMixin): |
| 726 | # 'bs': None or normal or mobile, | 756 | # 'bs': None or normal or mobile, |
| 727 | # } | 757 | # } |
| 728 | report_list = [None, False, None] | 758 | report_list = [None, False, None] |
| 759 | do_dda = is_hil and doc.document_scheme == consts.DOC_SCHEME_LIST[1] | ||
| 729 | except Exception as e: | 760 | except Exception as e: |
| 730 | self.online_log.error('{0} [process error (db filter)] [task={1}] [error={2}]'.format( | 761 | self.online_log.error('{0} [process error (db filter)] [task={1}] [error={2}]'.format( |
| 731 | self.log_base, task_str, traceback.format_exc())) | 762 | self.log_base, task_str, traceback.format_exc())) |
| ... | @@ -767,8 +798,8 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -767,8 +798,8 @@ class Command(BaseCommand, LoggerMixin): |
| 767 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_OTHER)) | 798 | res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_OTHER)) |
| 768 | continue | 799 | continue |
| 769 | elif classify in consts.LICENSE_CLASSIFY_SET_1: # 证件1 | 800 | elif classify in consts.LICENSE_CLASSIFY_SET_1: # 证件1 |
| 770 | self.license1_process(ocr_data, license_summary, classify, res_list, | 801 | self.license1_process(ocr_data, license_summary, classify, res_list, pno, |
| 771 | pno, ino, part_idx, img_path) | 802 | ino, part_idx, img_path, do_dda, dda_id_bc_mapping) |
| 772 | elif classify in consts.LICENSE_CLASSIFY_SET_2: # 证件2 | 803 | elif classify in consts.LICENSE_CLASSIFY_SET_2: # 证件2 |
| 773 | pid, _, _, _, _, _ = consts.LICENSE_CLASSIFY_MAPPING.get(classify) | 804 | pid, _, _, _, _, _ = consts.LICENSE_CLASSIFY_MAPPING.get(classify) |
| 774 | file_data = ocr_data.get('section_img') | 805 | file_data = ocr_data.get('section_img') |
| ... | @@ -813,7 +844,9 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -813,7 +844,9 @@ class Command(BaseCommand, LoggerMixin): |
| 813 | card_name_res.get('data', {}).get('is_exists_name') == 0: | 844 | card_name_res.get('data', {}).get('is_exists_name') == 0: |
| 814 | name = '无' | 845 | name = '无' |
| 815 | ocr_2_res['Name'] = name | 846 | ocr_2_res['Name'] = name |
| 816 | self.license2_process(ocr_2_res, license_summary, pid, classify, res_list, pno, ino, part_idx) | 847 | self.license2_process(ocr_2_res, license_summary, pid, classify, |
| 848 | res_list, pno, ino, part_idx, img_path, | ||
| 849 | do_dda, dda_id_bc_mapping) | ||
| 817 | break | 850 | break |
| 818 | else: | 851 | else: |
| 819 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) | 852 | res_list.append((pno, ino, part_idx, consts.RES_FAILED_2)) |
| ... | @@ -930,6 +963,8 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -930,6 +963,8 @@ class Command(BaseCommand, LoggerMixin): |
| 930 | os.remove(excel_path) | 963 | os.remove(excel_path) |
| 931 | finally: | 964 | finally: |
| 932 | # TODO 识别结果存一张表,方便跑报表 | 965 | # TODO 识别结果存一张表,方便跑报表 |
| 966 | |||
| 967 | # CA比对 | ||
| 933 | if doc.document_scheme == consts.DOC_SCHEME_LIST[0]: | 968 | if doc.document_scheme == consts.DOC_SCHEME_LIST[0]: |
| 934 | try: | 969 | try: |
| 935 | # 更新OCR累计识别结果表 | 970 | # 更新OCR累计识别结果表 |
| ... | @@ -978,6 +1013,204 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -978,6 +1013,204 @@ class Command(BaseCommand, LoggerMixin): |
| 978 | else: | 1013 | else: |
| 979 | self.online_log.info('{0} [comparison info send success] [task={1}] ' | 1014 | self.online_log.info('{0} [comparison info send success] [task={1}] ' |
| 980 | '[res_id={2}]'.format(self.log_base, task_str, res_obj.id)) | 1015 | '[res_id={2}]'.format(self.log_base, task_str, res_obj.id)) |
| 1016 | |||
| 1017 | # DDA处理 | ||
| 1018 | if do_dda: | ||
| 1019 | # 入库 | ||
| 1020 | try: | ||
| 1021 | dda_record = DDARecords.objects.filter( | ||
| 1022 | application_id=doc.application_id).first() | ||
| 1023 | if dda_record is None: | ||
| 1024 | dda_record = DDARecords(application_id=doc.application_id) | ||
| 1025 | except Exception as e: | ||
| 1026 | self.online_log.error('{0} [process error (dda db get)] [task={1}] ' | ||
| 1027 | '[error={2}]'.format(self.log_base, task_str, traceback.format_exc())) | ||
| 1028 | else: | ||
| 1029 | try: | ||
| 1030 | if not dda_record.all_found: | ||
| 1031 | found_time = timezone.now() | ||
| 1032 | move_img_path_dict = dict() | ||
| 1033 | ic_res_list = dda_id_bc_mapping.get(consts.IC_FIELD, []) | ||
| 1034 | bc_res_list = dda_id_bc_mapping.get(consts.BC_FIELD, []) | ||
| 1035 | self.online_log.info('{0} [dda process] [task={1}] [ic={2}] ' | ||
| 1036 | '[bc={3}]'.format(self.log_base, task_str,ic_res_list, | ||
| 1037 | bc_res_list)) | ||
| 1038 | |||
| 1039 | if not dda_record.is_dda_found: | ||
| 1040 | try: | ||
| 1041 | # DDA过滤,获取有效DDA | ||
| 1042 | best_dda_res = None | ||
| 1043 | dda_res_list = license_summary.get(consts.DDA_CLASSIFY, []) | ||
| 1044 | if len(dda_res_list) > 0: | ||
| 1045 | dda_res_list.sort(key=lambda x: x.get(consts.DDA_PRO, 0), | ||
| 1046 | reverse=True) | ||
| 1047 | tmp_best_dda_res = dda_res_list[0] | ||
| 1048 | if tmp_best_dda_res.get(consts.DDA_PRO, 0) >= 0.6: | ||
| 1049 | best_dda_res = tmp_best_dda_res | ||
| 1050 | self.online_log.info( | ||
| 1051 | '{0} [dda process] [task={1}] [dda={2}]'.format( | ||
| 1052 | self.log_base, task_str, dda_res_list)) | ||
| 1053 | except Exception as e: | ||
| 1054 | best_dda_res = None | ||
| 1055 | |||
| 1056 | dda_record.is_dda_found = False if best_dda_res is None else True | ||
| 1057 | |||
| 1058 | if dda_record.is_dda_found: | ||
| 1059 | dda_path = best_dda_res.get(consts.DDA_IMG_PATH, '') | ||
| 1060 | customer_name = best_dda_res.get(consts.DDA_IC_NAME, '') | ||
| 1061 | customer_id = best_dda_res.get(consts.DDA_IC_ID, '') | ||
| 1062 | account_id = best_dda_res.get(consts.DDA_BC_ID, '') | ||
| 1063 | dda_record.dda_path = dda_path | ||
| 1064 | dda_record.dda_found_time = found_time | ||
| 1065 | dda_record.customer_name = customer_name | ||
| 1066 | dda_record.customer_id = customer_id | ||
| 1067 | dda_record.account_id = account_id | ||
| 1068 | # move | ||
| 1069 | move_img_path_dict.setdefault( | ||
| 1070 | consts.DDA_FIELD, set()).add(dda_path) | ||
| 1071 | |||
| 1072 | if dda_record.is_dda_found: | ||
| 1073 | |||
| 1074 | try: | ||
| 1075 | if not dda_record.is_id_found: | ||
| 1076 | for ic_name, ic_id, ic_img_path in ic_res_list: | ||
| 1077 | if ic_id == dda_record.customer_id \ | ||
| 1078 | or ic_name == dda_record.customer_name: | ||
| 1079 | dda_record.is_id_found = True | ||
| 1080 | dda_record.id_path = ic_img_path | ||
| 1081 | dda_record.id_found_time = found_time | ||
| 1082 | move_img_path_dict.setdefault( | ||
| 1083 | consts.IC_FIELD, set()).add(ic_img_path) | ||
| 1084 | break | ||
| 1085 | else: | ||
| 1086 | id_record = IDBCRecords.objects.filter( | ||
| 1087 | application_id=doc.application_id, | ||
| 1088 | target_id=dda_record.customer_id, | ||
| 1089 | is_id=True).first() | ||
| 1090 | |||
| 1091 | if id_record is None: | ||
| 1092 | id_record = IDBCRecords.objects.filter( | ||
| 1093 | application_id=doc.application_id, | ||
| 1094 | target_name=dda_record.customer_name, | ||
| 1095 | is_id=True).first() | ||
| 1096 | |||
| 1097 | if id_record is not None: | ||
| 1098 | dda_record.is_id_found = True | ||
| 1099 | dda_record.id_path = id_record.file_path | ||
| 1100 | dda_record.id_found_time = id_record.create_time | ||
| 1101 | move_img_path_dict.setdefault( | ||
| 1102 | consts.IC_FIELD, set()).add(id_record.file_path) | ||
| 1103 | except Exception as e: | ||
| 1104 | self.online_log.error( | ||
| 1105 | '{0} [process error (dda id process)] [task={1}] ' | ||
| 1106 | '[error={2}]'.format(self.log_base, task_str, | ||
| 1107 | traceback.format_exc())) | ||
| 1108 | |||
| 1109 | try: | ||
| 1110 | if not dda_record.is_bc_found: | ||
| 1111 | for bc_no, bc_img_path in bc_res_list: | ||
| 1112 | if bc_no == dda_record.account_id: | ||
| 1113 | dda_record.is_bc_found = True | ||
| 1114 | dda_record.bc_path = bc_img_path | ||
| 1115 | dda_record.bc_found_time = found_time | ||
| 1116 | move_img_path_dict.setdefault( | ||
| 1117 | consts.BC_FIELD, set()).add(bc_img_path) | ||
| 1118 | break | ||
| 1119 | else: | ||
| 1120 | bc_record = IDBCRecords.objects.filter( | ||
| 1121 | application_id=doc.application_id, | ||
| 1122 | target_id=dda_record.account_id, | ||
| 1123 | is_id=False).first() | ||
| 1124 | |||
| 1125 | if bc_record is not None: | ||
| 1126 | dda_record.is_bc_found = True | ||
| 1127 | dda_record.bc_path = bc_record.file_path | ||
| 1128 | dda_record.bc_found_time = bc_record.create_time | ||
| 1129 | move_img_path_dict.setdefault( | ||
| 1130 | consts.BC_FIELD, set()).add(bc_record.file_path) | ||
| 1131 | except Exception as e: | ||
| 1132 | self.online_log.error( | ||
| 1133 | '{0} [process error (dda bc process)] [task={1}] ' | ||
| 1134 | '[error={2}]'.format(self.log_base, task_str, | ||
| 1135 | traceback.format_exc())) | ||
| 1136 | |||
| 1137 | if dda_record.is_dda_found and dda_record.is_id_found and dda_record.is_bc_found: | ||
| 1138 | dda_record.all_found = True | ||
| 1139 | dda_record.save() | ||
| 1140 | |||
| 1141 | # 图片移动 | ||
| 1142 | try: | ||
| 1143 | if len(move_img_path_dict) > 0: | ||
| 1144 | self.online_log.info( | ||
| 1145 | '{0} [dda process] [task={1}] [move_img_path={2}]'.format( | ||
| 1146 | self.log_base, task_str, move_img_path_dict)) | ||
| 1147 | |||
| 1148 | wanting_dir = os.path.join(self.dda_wanting_dir, doc.application_id) | ||
| 1149 | wanting_dir_exists = os.path.isdir(wanting_dir) | ||
| 1150 | if dda_record.all_found: | ||
| 1151 | target_dir = os.path.join(self.dda_complete_dir, doc.application_id) | ||
| 1152 | if wanting_dir_exists: | ||
| 1153 | shutil.move(wanting_dir, target_dir) | ||
| 1154 | else: | ||
| 1155 | os.makedirs(target_dir, exist_ok=True) | ||
| 1156 | else: | ||
| 1157 | target_dir = wanting_dir | ||
| 1158 | if not wanting_dir_exists: | ||
| 1159 | os.makedirs(target_dir, exist_ok=True) | ||
| 1160 | |||
| 1161 | for prefix, path_set in move_img_path_dict.items(): | ||
| 1162 | for idx, path in enumerate(path_set): | ||
| 1163 | if os.path.isfile(path): | ||
| 1164 | file_name = '{0}_{1}{2}'.format( | ||
| 1165 | prefix, idx, os.path.splitext(path)[-1]) | ||
| 1166 | target_path = os.path.join(target_dir, file_name) | ||
| 1167 | shutil.copyfile(path, target_path) | ||
| 1168 | else: | ||
| 1169 | self.online_log.warn( | ||
| 1170 | '{0} [dda process] [img path empty] [task={1}] ' | ||
| 1171 | '[path={2}]'.format(self.log_base, task_str, path)) | ||
| 1172 | except Exception as e: | ||
| 1173 | self.online_log.error( | ||
| 1174 | '{0} [process error (dda img move)] [task={1}] ' | ||
| 1175 | '[error={2}]'.format(self.log_base, task_str, traceback.format_exc())) | ||
| 1176 | |||
| 1177 | # id & bc 入库 | ||
| 1178 | try: | ||
| 1179 | if not dda_record.is_dda_found and not dda_record.is_id_found: | ||
| 1180 | ic_set = set() | ||
| 1181 | for ic_name, ic_id, ic_img_path in ic_res_list: | ||
| 1182 | query_str = '{0}{1}'.format(ic_name, ic_id) | ||
| 1183 | if query_str in ic_set: | ||
| 1184 | continue | ||
| 1185 | ic_set.add(query_str) | ||
| 1186 | IDBCRecords.objects.create( | ||
| 1187 | application_id=doc.application_id, | ||
| 1188 | target_name=ic_name, | ||
| 1189 | target_id=ic_id, | ||
| 1190 | is_id=True, | ||
| 1191 | file_path=ic_img_path) | ||
| 1192 | if not dda_record.is_dda_found and not dda_record.is_bc_found: | ||
| 1193 | bc_set = set() | ||
| 1194 | for bc_no, bc_img_path in bc_res_list: | ||
| 1195 | if bc_no in bc_set: | ||
| 1196 | continue | ||
| 1197 | bc_set.add(bc_no) | ||
| 1198 | IDBCRecords.objects.create( | ||
| 1199 | application_id=doc.application_id, | ||
| 1200 | target_id=bc_no, | ||
| 1201 | is_id=False, | ||
| 1202 | file_path=bc_img_path) | ||
| 1203 | except Exception as e: | ||
| 1204 | self.online_log.error( | ||
| 1205 | '{0} [process error (dda id&bc db save)] [task={1}] ' | ||
| 1206 | '[error={2}]'.format(self.log_base, task_str, traceback.format_exc())) | ||
| 1207 | |||
| 1208 | # TODO report | ||
| 1209 | |||
| 1210 | except Exception as e: | ||
| 1211 | self.online_log.error( | ||
| 1212 | '{0} [process error (dda process)] [task={1}] ' | ||
| 1213 | '[error={2}]'.format(self.log_base, task_str, traceback.format_exc())) | ||
| 981 | finally: | 1214 | finally: |
| 982 | # report_dict = { | 1215 | # report_dict = { |
| 983 | # 'process': None or pdf or excel or edms | 1216 | # 'process': None or pdf or excel or edms | ... | ... |
| ... | @@ -387,3 +387,51 @@ class AFCCompareOfflineReport(models.Model): | ... | @@ -387,3 +387,51 @@ class AFCCompareOfflineReport(models.Model): |
| 387 | situ_db_label = 'afc' | 387 | situ_db_label = 'afc' |
| 388 | 388 | ||
| 389 | 389 | ||
| 390 | # DDA ID & BC ----> HIL SE 专有 | ||
| 391 | class DDARecords(models.Model): | ||
| 392 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | ||
| 393 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 | ||
| 394 | |||
| 395 | is_dda_found = models.BooleanField(default=False, verbose_name="DDA是否找到") | ||
| 396 | is_id_found = models.BooleanField(default=False, verbose_name="身份证是否找到") | ||
| 397 | is_bc_found = models.BooleanField(default=False, verbose_name="银行卡是否找到") | ||
| 398 | all_found = models.BooleanField(default=False, verbose_name="是否全找到") | ||
| 399 | |||
| 400 | dda_path = models.CharField(null=True, max_length=1024, verbose_name="DDA图片路径") | ||
| 401 | id_path = models.CharField(null=True, max_length=1024, verbose_name="身份证图片路径") | ||
| 402 | bc_path = models.CharField(null=True, max_length=1024, verbose_name="银行卡图片路径") | ||
| 403 | |||
| 404 | customer_name = models.CharField(null=True, max_length=1024, verbose_name="DDA身份证姓名") | ||
| 405 | customer_id = models.CharField(null=True, max_length=1024, verbose_name="DDA身份证号码") | ||
| 406 | account_id = models.CharField(null=True, max_length=1024, verbose_name="DDA银行卡号") | ||
| 407 | |||
| 408 | dda_found_time = models.DateTimeField(null=True, verbose_name='DDA时间') | ||
| 409 | id_found_time = models.DateTimeField(null=True, verbose_name='身份证时间') | ||
| 410 | bc_found_time = models.DateTimeField(null=True, verbose_name='银行卡时间') | ||
| 411 | |||
| 412 | update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') # 索引 | ||
| 413 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') # 索引 | ||
| 414 | |||
| 415 | class Meta: | ||
| 416 | managed = False | ||
| 417 | db_table = 'dda_records' | ||
| 418 | |||
| 419 | |||
| 420 | class IDBCRecords(models.Model): | ||
| 421 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | ||
| 422 | application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引 | ||
| 423 | |||
| 424 | target_name = models.CharField(null=True, max_length=1024, verbose_name="DDA身份证姓名") # 与申请号联合索引 | ||
| 425 | target_id = models.CharField(max_length=1024, verbose_name="DDA身份证号码or银行卡号") # 与申请号联合索引 | ||
| 426 | |||
| 427 | is_id = models.BooleanField(default=True, verbose_name="身份证or银行卡") | ||
| 428 | |||
| 429 | file_path = models.CharField(max_length=1024, verbose_name="图片路径") | ||
| 430 | |||
| 431 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | ||
| 432 | |||
| 433 | class Meta: | ||
| 434 | managed = False | ||
| 435 | db_table = 'idbc_records' | ||
| 436 | |||
| 437 | ... | ... |
| ... | @@ -708,7 +708,7 @@ class BSWorkbook(Workbook): | ... | @@ -708,7 +708,7 @@ class BSWorkbook(Workbook): |
| 708 | self.remove(self.get_sheet_by_name('Sheet')) | 708 | self.remove(self.get_sheet_by_name('Sheet')) |
| 709 | 709 | ||
| 710 | def rebuild(self, bs_summary, license_summary, res_list, document_scheme): | 710 | def rebuild(self, bs_summary, license_summary, res_list, document_scheme): |
| 711 | count_list = [(consts.MODEL_FIELD_BS, len(self.sheetnames) - 1)] | 711 | count_list = [(consts.MODEL_FIELD_BS, len(bs_summary))] |
| 712 | if document_scheme == consts.DOC_SCHEME_LIST[1]: | 712 | if document_scheme == consts.DOC_SCHEME_LIST[1]: |
| 713 | self.license_rebuild(license_summary, document_scheme, count_list) | 713 | self.license_rebuild(license_summary, document_scheme, count_list) |
| 714 | self.bs_rebuild(bs_summary) | 714 | self.bs_rebuild(bs_summary) | ... | ... |
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