se compare part 6
Showing
3 changed files
with
432 additions
and
10 deletions
| ... | @@ -1023,12 +1023,12 @@ IC_RES_MAPPING = { | ... | @@ -1023,12 +1023,12 @@ IC_RES_MAPPING = { |
| 1023 | 1: '真实证件', | 1023 | 1: '真实证件', |
| 1024 | } | 1024 | } |
| 1025 | 1025 | ||
| 1026 | # ----------------- compare --------------------- | 1026 | # ----------------- CA compare --------------------- |
| 1027 | ENTITY = ['HIL', 'AFC'] | 1027 | ENTITY = ['HIL', 'AFC'] |
| 1028 | CUSTOMER_TYPE = ['TCCOR', 'TCDAS', 'TCFRE', 'TCIAS', 'TCIND', 'TCSEP', 'TCURE'] | 1028 | CUSTOMER_TYPE = ['TCCOR', 'TCDAS', 'TCFRE', 'TCIAS', 'TCIND', 'TCSEP', 'TCURE'] |
| 1029 | VEHICLE_STATUS = ['PCUSD', 'PCNEW'] | 1029 | VEHICLE_STATUS = ['PCUSD', 'PCNEW'] |
| 1030 | 1030 | ||
| 1031 | APPLICANT_TYPE = ['COAPP', 'CUSTR', 'GAUTR1', 'GAUTR2'] | 1031 | APPLICANT_TYPE = ['CUSTR', 'COAPP', 'GAUTR1', 'GAUTR2'] |
| 1032 | ID_TYPE = ['ITARI', 'ITHKM', 'ITPRC', 'ITPSP', 'ITRES', 'ITTID', 'ITUSC', 'ITCCU'] | 1032 | ID_TYPE = ['ITARI', 'ITHKM', 'ITPRC', 'ITPSP', 'ITRES', 'ITTID', 'ITUSC', 'ITCCU'] |
| 1033 | SECOND_ID_TYPE = ['ITARI', 'ITHKM', 'ITPRC', 'ITPSP', 'ITRES', 'ITTID'] | 1033 | SECOND_ID_TYPE = ['ITARI', 'ITHKM', 'ITPRC', 'ITPSP', 'ITRES', 'ITTID'] |
| 1034 | SUB_TYPE = ['CSIBM', 'CSOTH', 'CSSME'] | 1034 | SUB_TYPE = ['CSIBM', 'CSOTH', 'CSSME'] |
| ... | @@ -1074,7 +1074,18 @@ RESULT_MAPPING = { | ... | @@ -1074,7 +1074,18 @@ RESULT_MAPPING = { |
| 1074 | # VAT_CLASSIFY: 'vat_ocr', | 1074 | # VAT_CLASSIFY: 'vat_ocr', |
| 1075 | } | 1075 | } |
| 1076 | 1076 | ||
| 1077 | COMPARE_FIELDS = (IC_OCR_FIELD, RP_OCR_FIELD, BL_OCR_FIELD, EEP_OCR_FIELD, DL_OCR_FIELD, PP_OCR_FIELD, MVC_OCR_FIELD) | 1077 | COMPARE_FIELDS = (MVI_OCR_FIELD, |
| 1078 | IC_OCR_FIELD, | ||
| 1079 | RP_OCR_FIELD, | ||
| 1080 | BC_OCR_FIELD, | ||
| 1081 | BL_OCR_FIELD, | ||
| 1082 | UCI_OCR_FIELD, | ||
| 1083 | EEP_OCR_FIELD, | ||
| 1084 | DL_OCR_FIELD, | ||
| 1085 | PP_OCR_FIELD, | ||
| 1086 | MVC_OCR_FIELD, | ||
| 1087 | DDA_OCR_FIELD, | ||
| 1088 | ) | ||
| 1078 | 1089 | ||
| 1079 | # 身份证 | 1090 | # 身份证 |
| 1080 | ITPRC = [ | 1091 | ITPRC = [ |
| ... | @@ -1224,3 +1235,163 @@ DDA_MAPPING = [ | ... | @@ -1224,3 +1235,163 @@ DDA_MAPPING = [ |
| 1224 | (DDA_BC_ID, BC_FIELD), | 1235 | (DDA_BC_ID, BC_FIELD), |
| 1225 | ] | 1236 | ] |
| 1226 | 1237 | ||
| 1238 | # ----------------------- SE compare ----------------------- | ||
| 1239 | SE_FIRST_ID_FIELD = ['customerName', 'idNum', 'dateOfBirth', 'idExpiryDate'] | ||
| 1240 | SE_ID_CARD_FIELD = ['customerName', 'idNum', 'dateOfBirth', 'idExpiryDate', 'hukouProvince', 'hukouCity'] | ||
| 1241 | SE_SECOND_ID_FIELD = [ | ||
| 1242 | ('customerName', 'customerName'), | ||
| 1243 | ('secondIdNum', 'idNum'), | ||
| 1244 | ] | ||
| 1245 | SE_CORPORATE_ID_FIELD = [ | ||
| 1246 | ('legalRepName', 'customerName'), | ||
| 1247 | ('firstIdNo', 'idNum') | ||
| 1248 | ] | ||
| 1249 | SE_SEP_FIELD = [ | ||
| 1250 | ('companyName', 'companyName'), | ||
| 1251 | ('customerName', 'legalRepName'), | ||
| 1252 | ('registeredCapital', 'registeredCapital'), | ||
| 1253 | ('selfEmployedSubType', 'organizationType') | ||
| 1254 | ] | ||
| 1255 | SE_CORPORATE_FIELD = ['companyName', 'legalRepName', 'businessLicenseNo', 'organizationCreditCode', | ||
| 1256 | 'taxRegistrationCertificateNo', 'establishmentDate', 'businessLicenseDueDate', 'organizationType'] | ||
| 1257 | SE_CORPORATE_ALL_FIELD = ['companyName', 'legalRepName', 'firstIdNo', 'businessLicenseNo', 'organizationCreditCode', | ||
| 1258 | 'taxRegistrationCertificateNo', 'establishmentDate', 'businessLicenseDueDate', | ||
| 1259 | 'organizationType'] | ||
| 1260 | SE_NEW_FIELD = ['vinNo', 'dealer', 'vehicleTransactionAmount'] | ||
| 1261 | SE_USED_FIELD = ['vinNo', 'vehicleTransactionAmount'] | ||
| 1262 | SE_NEW_ADD_FIELD = ['customerName', 'idNum', 'dateOfInvoice'] | ||
| 1263 | |||
| 1264 | SE_BANK_FIELD = ['accountNo', 'bankName'] | ||
| 1265 | SE_DDA_FIELD = ['applicationId(1)', 'applicationId(2)', 'bankName', 'companyName', 'customerName', 'idNum', 'accountHolderName', 'accountNo'] | ||
| 1266 | |||
| 1267 | HIL_COMPANY_NAME = '先锋国际融资租赁有限公司' | ||
| 1268 | AFC_COMPANY_NAME = '宝马汽车金融(中国)有限公司' | ||
| 1269 | |||
| 1270 | ID_EN = 'PRC ID' | ||
| 1271 | PP_EN = 'Passport' | ||
| 1272 | EEP_EN = 'Resident Permit to Mainland' | ||
| 1273 | RP_EN = 'Resident ID' | ||
| 1274 | BL_EN = 'Business permit' | ||
| 1275 | MVI_EN = 'newCar Invoice' | ||
| 1276 | UCI_EN = 'usedCar Invoice' | ||
| 1277 | BC_EN = 'Bank Card' | ||
| 1278 | DDA_EN = 'DDA' | ||
| 1279 | |||
| 1280 | ID_COMPARE_LOGIC = [ | ||
| 1281 | ('customerName', '姓名'), | ||
| 1282 | ('idNum', '公民身份号码'), | ||
| 1283 | ('dateOfBirth', '出生年月'), | ||
| 1284 | ('idExpiryDate', '有效期限'), | ||
| 1285 | ('hukouProvince', '住址'), | ||
| 1286 | ('hukouCity', '住址'), | ||
| 1287 | ] | ||
| 1288 | |||
| 1289 | PP_COMPARE_LOGIC = [ | ||
| 1290 | ('customerName', '英文姓名'), | ||
| 1291 | ('idNum', '护照号码'), | ||
| 1292 | ('dateOfBirth', '出生日期'), | ||
| 1293 | ('idExpiryDate', '有效期至'), | ||
| 1294 | ] | ||
| 1295 | |||
| 1296 | EEP_COMPARE_LOGIC = [ | ||
| 1297 | ('customerName', '中文名'), | ||
| 1298 | ('idNum', '证件号码'), | ||
| 1299 | ('dateOfBirth', '出生日期'), | ||
| 1300 | ('idExpiryDate', '有效期限'), | ||
| 1301 | ] | ||
| 1302 | |||
| 1303 | RP_COMPARE_LOGIC = [ | ||
| 1304 | ('customerName', '姓名'), | ||
| 1305 | ('idNum', '公民身份号码'), | ||
| 1306 | ('dateOfBirth', '出生年月'), | ||
| 1307 | ('idExpiryDate', '有效期限'), | ||
| 1308 | ('hukouProvince', '住址'), | ||
| 1309 | ('hukouCity', '住址'), | ||
| 1310 | ] | ||
| 1311 | |||
| 1312 | BL_COMPARE_LOGIC = [ | ||
| 1313 | ('companyName', '企业名称', ), | ||
| 1314 | ('legalRepName', '经营者姓名', ), | ||
| 1315 | ('firstIdNo', '注册号', ), | ||
| 1316 | ('businessLicenseNo', '注册号', ), | ||
| 1317 | ('organizationCreditCode', '注册号', ), | ||
| 1318 | ('taxRegistrationCertificateNo', '注册号', ), | ||
| 1319 | ('establishmentDate', '成立日期', ), # 2017年07月11日 | ||
| 1320 | # 2017年07月11日至长期 1. OCR识别为长期,向GCAP发送:2099-12-31 00:00:00.0 | ||
| 1321 | ('businessLicenseDueDate', '营业期限'), | ||
| 1322 | ('organizationType', '企业类型', ), # 有限责任公司 | ||
| 1323 | ('registeredCapital', '注册资本', ), # 壹拾万元整 将OCR识别结果(人民币大写)转化为数字 | ||
| 1324 | ] | ||
| 1325 | |||
| 1326 | MVI_COMPARE_LOGIC = [ | ||
| 1327 | ('vinNo', '车辆识别代码'), | ||
| 1328 | ('dealer', '销方名称'), | ||
| 1329 | ('vehicleTransactionAmount', '价税合计小写'), | ||
| 1330 | ('customerName', '购方名称'), | ||
| 1331 | ('idNum', '购买方身份证号或组织机构代码'), | ||
| 1332 | ('dateOfInvoice', '开票日期'), | ||
| 1333 | ] | ||
| 1334 | |||
| 1335 | UCI_COMPARE_LOGIC = [ | ||
| 1336 | ('vinNo', '车架号'), | ||
| 1337 | ('vehicleTransactionAmount', '价税合计小写'), | ||
| 1338 | ('customerName', '购方名称'), | ||
| 1339 | ('idNum', '购方纳税人识别号'), | ||
| 1340 | ] | ||
| 1341 | |||
| 1342 | SE_DDA_FIELD = ['applicationId(1)', 'applicationId(2)', 'bankName', 'companyName', 'customerName', 'idNum', 'accountHolderName', 'accountNo'] | ||
| 1343 | |||
| 1344 | |||
| 1345 | BC_COMPARE_LOGIC = [ | ||
| 1346 | ('accountNo', 'CardNum'), | ||
| 1347 | ('bankName', 'BankName'), | ||
| 1348 | ] | ||
| 1349 | |||
| 1350 | DDA_COMPARE_LOGIC = [ | ||
| 1351 | ('applicationId(1)', 'CardNum'), | ||
| 1352 | ('applicationId(2)', 'BankName'), | ||
| 1353 | ('bankName', 'BankName'), | ||
| 1354 | ('companyName', 'BankName'), | ||
| 1355 | ('customerName', 'BankName'), | ||
| 1356 | ('idNum', 'BankName'), | ||
| 1357 | ('accountHolderName', 'BankName'), | ||
| 1358 | ('accountNo', 'BankName'), | ||
| 1359 | ] | ||
| 1360 | |||
| 1361 | |||
| 1362 | # MVC_OCR_FIELD = 'mvc_ocr' | ||
| 1363 | |||
| 1364 | SE_COMPARE_FIELD = { | ||
| 1365 | ID_EN: (IC_OCR_FIELD, ID_COMPARE_LOGIC, True), | ||
| 1366 | PP_EN: (PP_OCR_FIELD, PP_COMPARE_LOGIC, False), | ||
| 1367 | EEP_EN: (EEP_OCR_FIELD, EEP_COMPARE_LOGIC, False), | ||
| 1368 | RP_EN: (RP_OCR_FIELD, RP_COMPARE_LOGIC, True), | ||
| 1369 | BL_EN: (BL_OCR_FIELD, BL_COMPARE_LOGIC, False), | ||
| 1370 | MVI_EN: (MVI_OCR_FIELD, MVI_COMPARE_LOGIC, False), | ||
| 1371 | UCI_EN: (UCI_OCR_FIELD, UCI_COMPARE_LOGIC, False), | ||
| 1372 | BC_EN: (BC_OCR_FIELD, BC_COMPARE_LOGIC, False), | ||
| 1373 | DDA_EN: (DDA_OCR_FIELD, DDA_COMPARE_LOGIC, False), | ||
| 1374 | } | ||
| 1375 | |||
| 1376 | |||
| 1377 | SE_FIRST_ID_FIELD_MAPPING = { | ||
| 1378 | 'ITPRC': (ID_EN, SE_ID_CARD_FIELD), | ||
| 1379 | 'ITPSP': (PP_EN, SE_FIRST_ID_FIELD), | ||
| 1380 | 'ITHKM': (EEP_EN, SE_FIRST_ID_FIELD), | ||
| 1381 | 'ITTID': (EEP_EN, SE_FIRST_ID_FIELD), | ||
| 1382 | 'ITRES': (RP_EN, SE_FIRST_ID_FIELD), | ||
| 1383 | } | ||
| 1384 | |||
| 1385 | SE_SECOND_ID_FIELD_MAPPING = { | ||
| 1386 | 'ITPRC': (ID_EN, SE_SECOND_ID_FIELD), | ||
| 1387 | 'ITPSP': (PP_EN, SE_SECOND_ID_FIELD), | ||
| 1388 | 'ITHKM': (EEP_EN, SE_SECOND_ID_FIELD), | ||
| 1389 | 'ITTID': (EEP_EN, SE_SECOND_ID_FIELD), | ||
| 1390 | 'ITRES': (RP_EN, SE_SECOND_ID_FIELD), | ||
| 1391 | } | ||
| 1392 | |||
| 1393 | HEAD_LIST = ['Info', 'Index', 'License', 'Field', 'Input', 'OCR', 'Result', 'Position', 'Image', 'errorType'] | ||
| 1394 | |||
| 1395 | |||
| 1396 | |||
| 1397 | ... | ... |
| ... | @@ -778,12 +778,11 @@ class CompareResultView(GenericView): | ... | @@ -778,12 +778,11 @@ class CompareResultView(GenericView): |
| 778 | if len(compare_result_list) == 0: | 778 | if len(compare_result_list) == 0: |
| 779 | body_html = "<h1>没有比对结果</h1>" | 779 | body_html = "<h1>没有比对结果</h1>" |
| 780 | else: | 780 | else: |
| 781 | head_list = ['Info', 'Index', 'License', 'Field', 'Result', 'Input', 'OCR', 'Position', 'Image', 'errorType'] | 781 | head_content = ''.join(['<th>{0}</th>'.format(head_name) for head_name in consts.HEAD_LIST]) |
| 782 | head_content = ''.join(['<th>{0}</th>'.format(head_name) for head_name in head_list]) | ||
| 783 | head_html = '<tr>{0}</tr>'.format(head_content) | 782 | head_html = '<tr>{0}</tr>'.format(head_content) |
| 784 | row_html_list = [] | 783 | row_html_list = [] |
| 785 | for row_dict in compare_result_list: | 784 | for row_dict in compare_result_list: |
| 786 | row_list = [row_dict.get(head, '') for head in head_list] | 785 | row_list = [row_dict.get(head, '') for head in consts.HEAD_LIST] |
| 787 | row_content = ''.join(['<td>{0}</td>'.format(row_str) for row_str in row_list]) | 786 | row_content = ''.join(['<td>{0}</td>'.format(row_str) for row_str in row_list]) |
| 788 | row_html = '<tr>{0}</tr>'.format(row_content) | 787 | row_html = '<tr>{0}</tr>'.format(row_content) |
| 789 | row_html_list.append(row_html) | 788 | row_html_list.append(row_html) | ... | ... |
| ... | @@ -435,10 +435,261 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res | ... | @@ -435,10 +435,261 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res |
| 435 | traceback.format_exc())) | 435 | traceback.format_exc())) |
| 436 | 436 | ||
| 437 | 437 | ||
| 438 | def get_se_compare_info(last_obj, application_entity): | ||
| 439 | compare_info = {} | ||
| 440 | individual_info_dict = {} | ||
| 441 | main_role_info = {} | ||
| 442 | for individual_info in json.loads(last_obj.individual_cus_info): | ||
| 443 | main_role_info.setdefault(individual_info['applicantType'], []).append( | ||
| 444 | (individual_info['customerName'], individual_info['idNum'])) | ||
| 445 | |||
| 446 | license_dict = {} | ||
| 447 | |||
| 448 | if individual_info['idType'] in consts.SE_FIRST_ID_FIELD_MAPPING: | ||
| 449 | license_en, field_list = consts.SE_FIRST_ID_FIELD_MAPPING[individual_info['idType']] | ||
| 450 | field_input = [] | ||
| 451 | for field in field_list: | ||
| 452 | if field in individual_info: | ||
| 453 | field_input.append((field, individual_info[field])) | ||
| 454 | license_dict[license_en] = field_input | ||
| 455 | |||
| 456 | if individual_info['secondIdType'] in consts.SE_SECOND_ID_FIELD_MAPPING: | ||
| 457 | second_license_en, second_field_list = consts.SE_SECOND_ID_FIELD_MAPPING[individual_info['secondIdType']] | ||
| 458 | if second_license_en not in license_dict: | ||
| 459 | second_field_input = [] | ||
| 460 | for second_field, write_field in second_field_list: | ||
| 461 | if second_field in individual_info: | ||
| 462 | second_field_input.append((write_field, individual_info[second_field])) | ||
| 463 | license_dict[second_license_en] = second_field_input | ||
| 464 | |||
| 465 | if individual_info['customerType'] == consts.CUSTOMER_TYPE[5]: | ||
| 466 | sep_field_input = [] | ||
| 467 | for sep_field, sep_write_field in consts.SE_SEP_FIELD: | ||
| 468 | if sep_field in individual_info: | ||
| 469 | sep_field_input.append((sep_write_field, individual_info[sep_field])) | ||
| 470 | license_dict[consts.BL_EN] = sep_field_input | ||
| 471 | |||
| 472 | if len(license_dict) > 0: | ||
| 473 | individual_info_dict.setdefault(individual_info['applicantType'], []).append(license_dict) | ||
| 474 | |||
| 475 | compare_info['individualCusInfo'] = individual_info_dict | ||
| 476 | |||
| 477 | for applicant_type in consts.APPLICANT_TYPE: | ||
| 478 | if applicant_type in main_role_info: | ||
| 479 | main_name, main_num = main_role_info[applicant_type][0] | ||
| 480 | break | ||
| 481 | del main_role_info | ||
| 482 | |||
| 483 | company_info = None | ||
| 484 | if isinstance(last_obj.corporate_cus_info, str): | ||
| 485 | corporate_info_dict = json.loads(last_obj.corporate_cus_info) | ||
| 486 | corporate_info = {} | ||
| 487 | company_info = (corporate_info_dict['companyName'], corporate_info_dict['businessLicenseNo']) | ||
| 488 | if corporate_info_dict['firstIdType'] == consts.ID_TYPE[6]: | ||
| 489 | bl_field_input = [] | ||
| 490 | for bl_field in consts.SE_CORPORATE_ALL_FIELD: | ||
| 491 | bl_field_input.append((bl_field, corporate_info_dict[bl_field])) | ||
| 492 | corporate_info[consts.BL_EN] = bl_field_input | ||
| 493 | else: | ||
| 494 | if corporate_info_dict['firstIdType'] in consts.SE_FIRST_ID_FIELD_MAPPING: | ||
| 495 | license_en, _ = consts.SE_FIRST_ID_FIELD_MAPPING[corporate_info_dict['firstIdType']] | ||
| 496 | first_id_field_input = [] | ||
| 497 | for first_id_field, first_id_write_field in consts.SE_CORPORATE_ID_FIELD: | ||
| 498 | first_id_field_input.append((first_id_write_field, corporate_info_dict[first_id_field])) | ||
| 499 | corporate_info[license_en] = first_id_field_input | ||
| 500 | bl_field_input = [] | ||
| 501 | for bl_field in consts.SE_CORPORATE_FIELD: | ||
| 502 | bl_field_input.append((bl_field, corporate_info_dict[bl_field])) | ||
| 503 | corporate_info[consts.BL_EN] = bl_field_input | ||
| 504 | |||
| 505 | compare_info['corporateCusInfo'] = corporate_info | ||
| 506 | |||
| 507 | vehicle_info_dict = json.loads(last_obj.vehicle_info) # TODO 车辆登记证 | ||
| 508 | vehicle_info = {} | ||
| 509 | vehicle_field_input = [] | ||
| 510 | if vehicle_info_dict['vehicleStatus'] == 'New': | ||
| 511 | for vehicle_field in consts.SE_NEW_FIELD: | ||
| 512 | vehicle_field_input.append((vehicle_field, vehicle_info_dict[vehicle_field])) | ||
| 513 | vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[0], main_name)) | ||
| 514 | vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[1], main_num)) | ||
| 515 | vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[2], last_obj.first_submmison_date)) | ||
| 516 | vehicle_info[consts.MVI_EN] = vehicle_field_input | ||
| 517 | else: | ||
| 518 | for vehicle_field in consts.SE_USED_FIELD: | ||
| 519 | vehicle_field_input.append((vehicle_field, vehicle_info_dict[vehicle_field])) | ||
| 520 | if isinstance(company_info, tuple): | ||
| 521 | vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[0], company_info[0])) | ||
| 522 | vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[1], company_info[1])) | ||
| 523 | else: | ||
| 524 | vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[0], main_name)) | ||
| 525 | vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[1], main_num)) | ||
| 526 | vehicle_info[consts.UCI_EN] = vehicle_field_input | ||
| 527 | compare_info['vehicleInfo'] = vehicle_info | ||
| 528 | |||
| 529 | bank_info_dict = json.loads(last_obj.bank_info) | ||
| 530 | bank_info = {} | ||
| 531 | bank_field_input = [] | ||
| 532 | for bank_field in consts.SE_BANK_FIELD: | ||
| 533 | bank_field_input.append((bank_field, bank_info_dict[bank_field])) | ||
| 534 | bank_info[consts.BC_EN] = bank_field_input | ||
| 535 | |||
| 536 | dda_field_input = [] | ||
| 537 | for dda_field in consts.SE_DDA_FIELD: | ||
| 538 | if dda_field.startswith('applicationId'): | ||
| 539 | dda_field_input.append((dda_field, last_obj.application_id)) | ||
| 540 | elif dda_field == 'companyName': | ||
| 541 | company_name = consts.HIL_COMPANY_NAME if application_entity in consts.HIL_SET else consts.AFC_COMPANY_NAME | ||
| 542 | dda_field_input.append((dda_field, company_name)) | ||
| 543 | elif dda_field == 'customerName': | ||
| 544 | dda_field_input.append((dda_field, main_name)) | ||
| 545 | elif dda_field == 'idNum': | ||
| 546 | dda_field_input.append((dda_field, main_num)) | ||
| 547 | else: | ||
| 548 | dda_field_input.append((dda_field, bank_info_dict[dda_field])) | ||
| 549 | bank_info[consts.DDA_EN] = dda_field_input | ||
| 550 | compare_info['bankInfo'] = bank_info | ||
| 551 | |||
| 552 | return compare_info | ||
| 553 | |||
| 554 | |||
| 555 | def se_compare_license(license_en, ocr_res_dict, field_list): | ||
| 556 | ocr_field, compare_logic, special_expiry_date = consts.SE_COMPARE_FIELD[license_en] | ||
| 557 | |||
| 558 | is_find = False | ||
| 559 | ocr_res_str = ocr_res_dict.get(ocr_field) | ||
| 560 | if ocr_res_str is not None: | ||
| 561 | ocr_res_list = json.loads(ocr_res_str) | ||
| 562 | length = len(ocr_res_list) | ||
| 563 | |||
| 564 | # 身份证、居住证 过期期限特殊处理 | ||
| 565 | if special_expiry_date: | ||
| 566 | expiry_dates = [] | ||
| 567 | key = compare_logic[2][1] | ||
| 568 | # for ocr_res in tmp_list: | ||
| 569 | for ocr_res in ocr_res_list: | ||
| 570 | if ocr_res.get(key): | ||
| 571 | expiry_dates.append(ocr_res.get(key)) | ||
| 572 | else: | ||
| 573 | expiry_dates = [] | ||
| 574 | |||
| 575 | # for ocr_res in tmp_list: | ||
| 576 | for ocr_res in ocr_res_list: | ||
| 577 | if is_find: | ||
| 578 | break | ||
| 579 | for idx, compare_tuple in enumerate(compare_list): | ||
| 580 | input_str = info_dict.get(compare_tuple[0]) | ||
| 581 | ocr_str = ocr_res.get(compare_tuple[1]) | ||
| 582 | compare_res, ocr_output = getattr(cp, compare_tuple[2])( | ||
| 583 | input_str, ocr_str, idx, **compare_tuple[3]) | ||
| 584 | # print('type: {0}, idx: {1}, field: {2}, input: {3}, ocr: {4}, res: {5}, out: {6}'.format(ocr_field, idx, compare_tuple[0], input_str, ocr_str, compare_res, ocr_output)) | ||
| 585 | if idx == 0 and compare_res in [consts.RESULT_N, consts.RESULT_NA] and length > 1: | ||
| 586 | break | ||
| 587 | is_find = True | ||
| 588 | |||
| 589 | # 过期期限特殊处理 | ||
| 590 | if idx == 2 and has_expiry_date and compare_res == consts.RESULT_NA: | ||
| 591 | for expiry_date in expiry_dates: | ||
| 592 | expiry_date_compare_res, expiry_date_ocr_output = getattr(cp, compare_tuple[2])( | ||
| 593 | input_str, expiry_date, idx, **compare_tuple[3] | ||
| 594 | ) | ||
| 595 | if expiry_date_compare_res == consts.RESULT_Y: | ||
| 596 | compare_res = consts.RESULT_Y | ||
| 597 | ocr_output = expiry_date_ocr_output | ||
| 598 | ocr_str = expiry_date | ||
| 599 | break | ||
| 600 | |||
| 601 | info_dict[compare_tuple[4]] = compare_res | ||
| 602 | if input_str is not None: | ||
| 603 | if ocr_str is None or ocr_output is None: | ||
| 604 | del info_dict[compare_tuple[0]] | ||
| 605 | else: | ||
| 606 | info_dict[compare_tuple[0]] = ocr_output | ||
| 607 | res_set.add(compare_res) | ||
| 608 | if not is_find: | ||
| 609 | res_set.add(consts.RESULT_N) | ||
| 610 | for compare_tuple in compare_list: | ||
| 611 | info_dict[compare_tuple[4]] = consts.RESULT_NA | ||
| 612 | if compare_tuple[0] in info_dict: | ||
| 613 | del info_dict[compare_tuple[0]] | ||
| 614 | |||
| 615 | |||
| 616 | def se_compare_process(compare_info, ocr_res_dict): | ||
| 617 | # individualCusInfo | ||
| 618 | # corporateCusInfo | ||
| 619 | # vehicleInfo | ||
| 620 | # bankInfo | ||
| 621 | compare_result = [] | ||
| 622 | total_fields = 0 | ||
| 623 | failed_count = 0 | ||
| 624 | successful_at_this_level = True | ||
| 625 | failure_reason = {} | ||
| 626 | |||
| 627 | for info_key, info_value in compare_info.items(): | ||
| 628 | if info_key == 'individualCusInfo': | ||
| 629 | for idx, license_dict in info_value.items(): | ||
| 630 | for license_en, field_list in license_dict.items(): | ||
| 631 | failure_field = [] | ||
| 632 | result_field_list = se_compare_license(license_en, ocr_res_dict, field_list) | ||
| 633 | for name, value, result, ocr_str in result_field_list: | ||
| 634 | total_fields += 1 | ||
| 635 | if result == consts.RESULT_N: | ||
| 636 | failed_count += 1 | ||
| 637 | successful_at_this_level = False | ||
| 638 | failure_field.append(name) | ||
| 639 | compare_result.append( | ||
| 640 | { | ||
| 641 | 'Info': info_key, | ||
| 642 | 'Index': idx, | ||
| 643 | 'License': license_en, | ||
| 644 | 'Field': name, | ||
| 645 | 'Input': value, | ||
| 646 | 'OCR': ocr_str, | ||
| 647 | 'Result': result, | ||
| 648 | 'Position': '', | ||
| 649 | 'Image': '', | ||
| 650 | 'errorType': '', | ||
| 651 | } | ||
| 652 | ) | ||
| 653 | failure_reason.setdefault(license_en, []).append('/'.join(failure_field)) | ||
| 654 | else: | ||
| 655 | for license_en, field_list in info_value.items(): | ||
| 656 | failure_field = [] | ||
| 657 | result_field_list = se_compare_license(license_en, ocr_res_dict, field_list) | ||
| 658 | for name, value, result, ocr_str in result_field_list: | ||
| 659 | total_fields += 1 | ||
| 660 | if result == consts.RESULT_N: | ||
| 661 | failed_count += 1 | ||
| 662 | successful_at_this_level = False | ||
| 663 | failure_field.append(name) | ||
| 664 | compare_result.append( | ||
| 665 | { | ||
| 666 | 'Info': info_key, | ||
| 667 | 'Index': 0, | ||
| 668 | 'License': license_en, | ||
| 669 | 'Field': name, | ||
| 670 | 'Input': value, | ||
| 671 | 'OCR': ocr_str, | ||
| 672 | 'Result': result, | ||
| 673 | 'Position': '', | ||
| 674 | 'Image': '', | ||
| 675 | 'errorType': '', | ||
| 676 | } | ||
| 677 | ) | ||
| 678 | failure_reason.setdefault(license_en, []).append('/'.join(failure_field)) | ||
| 679 | failure_reason_list = [] | ||
| 680 | for license_en, failed_field_list in failure_reason.items(): | ||
| 681 | failure_reason_list.append('{0}:{1}'.format(license_en, ';'.join(failed_field_list))) | ||
| 682 | failure_reason_str = '、'.join(failure_reason_list) | ||
| 683 | return compare_result, total_fields, failed_count, successful_at_this_level, failure_reason_str | ||
| 684 | |||
| 685 | |||
| 438 | def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict): | 686 | def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict): |
| 439 | try: | 687 | try: |
| 440 | # 比对逻辑 | 688 | # 比对逻辑 |
| 441 | pass | 689 | start_time = datetime.now() |
| 690 | compare_info = get_se_compare_info(last_obj, application_entity) | ||
| 691 | compare_result, total_fields, failed_count, successful_at_this_level, failure_reason_str = se_compare_process( | ||
| 692 | compare_info, ocr_res_dict) | ||
| 442 | except Exception as e: | 693 | except Exception as e: |
| 443 | pass | 694 | pass |
| 444 | else: | 695 | else: |
| ... | @@ -452,7 +703,7 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res | ... | @@ -452,7 +703,7 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res |
| 452 | res_obj.compare_count = total_fields | 703 | res_obj.compare_count = total_fields |
| 453 | res_obj.failed_count = failed_count | 704 | res_obj.failed_count = failed_count |
| 454 | # res_obj.reason1_count = reason1_count | 705 | # res_obj.reason1_count = reason1_count |
| 455 | res_obj.result = json.dumps(compare_result_str) | 706 | res_obj.result = json.dumps(compare_result) |
| 456 | res_obj.save() | 707 | res_obj.save() |
| 457 | compare_log.info('{0} [SE] [result save success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format( | 708 | compare_log.info('{0} [SE] [result save success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format( |
| 458 | log_base, application_entity, application_id, ocr_res_id)) | 709 | log_base, application_entity, application_id, ocr_res_id)) |
| ... | @@ -462,6 +713,7 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res | ... | @@ -462,6 +713,7 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res |
| 462 | traceback.format_exc())) | 713 | traceback.format_exc())) |
| 463 | 714 | ||
| 464 | # report | 715 | # report |
| 716 | end_time = datetime.now() | ||
| 465 | try: | 717 | try: |
| 466 | request_trigger = RequestTrigger.SUBMITING.value if ocr_res_id is None else RequestTrigger.UPLOADING.value | 718 | request_trigger = RequestTrigger.SUBMITING.value if ocr_res_id is None else RequestTrigger.UPLOADING.value |
| 467 | report_class = HILCompareReport if application_entity == consts.HIL_PREFIX else AFCCompareReport | 719 | report_class = HILCompareReport if application_entity == consts.HIL_PREFIX else AFCCompareReport |
| ... | @@ -472,10 +724,10 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res | ... | @@ -472,10 +724,10 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res |
| 472 | transaction_start=start_time, | 724 | transaction_start=start_time, |
| 473 | transaction_end=end_time, | 725 | transaction_end=end_time, |
| 474 | successful_at_this_level=successful_at_this_level, | 726 | successful_at_this_level=successful_at_this_level, |
| 475 | failure_reason=failure_reason, | 727 | failure_reason=failure_reason_str, |
| 476 | process_name=ProcessName.SE_CACOMPARE.value, | 728 | process_name=ProcessName.SE_CACOMPARE.value, |
| 477 | total_fields=total_fields, | 729 | total_fields=total_fields, |
| 478 | workflow_name=customer_type, | 730 | workflow_name=last_obj.customer_type, |
| 479 | ) | 731 | ) |
| 480 | compare_log.info('{0} [SE] [report save success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format( | 732 | compare_log.info('{0} [SE] [report save success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format( |
| 481 | log_base, application_entity, application_id, ocr_res_id)) | 733 | log_base, application_entity, application_id, ocr_res_id)) | ... | ... |
-
Please register or sign in to post a comment