89149364 by 周伟奇

compare update

1 parent 4e022eb3
...@@ -1018,61 +1018,69 @@ BASE_XML_TEXT = """<?xml version="1.0" encoding="utf-8"?> ...@@ -1018,61 +1018,69 @@ BASE_XML_TEXT = """<?xml version="1.0" encoding="utf-8"?>
1018 1018
1019 CDATA_TEXT = """<![CDATA[<Exec xmlns="http://tempuri.org/"><strXMLParm>&lt;Request&gt;&lt;Framework&gt;&lt;UserName&gt;SFCHINA\qqcout0&lt;/UserName&gt;&lt;GUID&gt;70d0efcb-3bc2-4018-ac4e-681c8f3131b6&lt;/GUID&gt;&lt;DetailedTracingEnabled&gt;False&lt;/DetailedTracingEnabled&gt;&lt;ServiceName&gt;AMSWebService&lt;/ServiceName&gt;&lt;SupportsRedirection&gt;true&lt;/SupportsRedirection&gt;&lt;ServiceType&gt;Service&lt;/ServiceType&gt;&lt;/Framework&gt;&lt;Parms&gt;&lt;InputXML type="string"&gt;&amp;lt;?xml version="1.0" encoding="utf-16"?&amp;gt;&amp;lt;InputXML&amp;gt; &amp;lt;Result&amp;gt; {0} &amp;lt;/Result&amp;gt;&amp;lt;AuthorizationData&amp;gt;&amp;lt;ServiceComponent&amp;gt;OCR&amp;lt;/ServiceComponent&amp;gt;&amp;lt;RoleId/&amp;gt;&amp;lt;CompanyId/&amp;gt;&amp;lt;/AuthorizationData&amp;gt;&amp;lt;/InputXML&amp;gt;&lt;/InputXML&gt;&lt;/Parms&gt;&lt;/Request&gt;</strXMLParm></Exec>]]>""" 1019 CDATA_TEXT = """<![CDATA[<Exec xmlns="http://tempuri.org/"><strXMLParm>&lt;Request&gt;&lt;Framework&gt;&lt;UserName&gt;SFCHINA\qqcout0&lt;/UserName&gt;&lt;GUID&gt;70d0efcb-3bc2-4018-ac4e-681c8f3131b6&lt;/GUID&gt;&lt;DetailedTracingEnabled&gt;False&lt;/DetailedTracingEnabled&gt;&lt;ServiceName&gt;AMSWebService&lt;/ServiceName&gt;&lt;SupportsRedirection&gt;true&lt;/SupportsRedirection&gt;&lt;ServiceType&gt;Service&lt;/ServiceType&gt;&lt;/Framework&gt;&lt;Parms&gt;&lt;InputXML type="string"&gt;&amp;lt;?xml version="1.0" encoding="utf-16"?&amp;gt;&amp;lt;InputXML&amp;gt; &amp;lt;Result&amp;gt; {0} &amp;lt;/Result&amp;gt;&amp;lt;AuthorizationData&amp;gt;&amp;lt;ServiceComponent&amp;gt;OCR&amp;lt;/ServiceComponent&amp;gt;&amp;lt;RoleId/&amp;gt;&amp;lt;CompanyId/&amp;gt;&amp;lt;/AuthorizationData&amp;gt;&amp;lt;/InputXML&amp;gt;&lt;/InputXML&gt;&lt;/Parms&gt;&lt;/Request&gt;</strXMLParm></Exec>]]>"""
1020 1020
1021 IC_OCR_FIELD = 'ic_ocr'
1022 RP_OCR_FIELD = 'rp_ocr'
1023 BL_OCR_FIELD = 'bl_ocr'
1024 EEP_OCR_FIELD = 'eep_ocr'
1025 DL_OCR_FIELD = 'dl_ocr'
1026 PP_OCR_FIELD = 'pp_ocr'
1027 MVC_OCR_FIELD = 'mvc_ocr'
1028
1021 RESULT_MAPPING = { 1029 RESULT_MAPPING = {
1022 # MVI_CLASSIFY: 'mvi_ocr', 1030 # MVI_CLASSIFY: 'mvi_ocr',
1023 IC_CLASSIFY: 'ic_ocr', 1031 IC_CLASSIFY: IC_OCR_FIELD,
1024 RP_CLASSIFY: 'rp_ocr', 1032 RP_CLASSIFY: RP_OCR_FIELD,
1025 # BC_CLASSIFY: 'bc_ocr', 1033 # BC_CLASSIFY: 'bc_ocr',
1026 BL_CLASSIFY: 'bl_ocr', 1034 BL_CLASSIFY: BL_OCR_FIELD,
1027 # UCI_CLASSIFY: 'uci_ocr', 1035 # UCI_CLASSIFY: 'uci_ocr',
1028 EEP_CLASSIFY: 'eep_ocr', 1036 EEP_CLASSIFY: EEP_OCR_FIELD,
1029 DL_CLASSIFY: 'dl_ocr', 1037 DL_CLASSIFY: DL_OCR_FIELD,
1030 PP_CLASSIFY: 'pp_ocr', 1038 PP_CLASSIFY: PP_OCR_FIELD,
1031 MVC_CLASSIFY: 'mvc_ocr', 1039 MVC_CLASSIFY: MVC_OCR_FIELD,
1032 # VAT_CLASSIFY: 'vat_ocr', 1040 # VAT_CLASSIFY: 'vat_ocr',
1033 } 1041 }
1034 1042
1035 COMPARE_FIELDS = ('ic_ocr', 'rp_ocr', 'bl_ocr', 'eep_ocr', 'dl_ocr', 'pp_ocr', 'mvc_ocr') 1043 COMPARE_FIELDS = (IC_OCR_FIELD, RP_OCR_FIELD, BL_OCR_FIELD, EEP_OCR_FIELD, DL_OCR_FIELD, PP_OCR_FIELD, MVC_OCR_FIELD)
1036 1044
1037 # 身份证 1045 # 身份证
1038 ITPRC = { 1046 ITPRC = [
1039 'customerChineseName': ('姓名', 'common_compare', {}), 1047 ('customerChineseName', '姓名', 'name_compare', {}),
1040 'idNum': ('公民身份号码', 'common_compare', {}), 1048 ('idNum', '公民身份号码', 'common_compare', {}),
1041 # 20200410-20250410 OCR识别为长期,向GCAP发送:2099-12-31 00:00:00.0 1049 # 20200410-20250410 OCR识别为长期,向GCAP发送:2099-12-31 00:00:00.0
1042 'idExpiryDate': ('有效期限', 'date_compare', {'long': True, 'ocr_split': True, 'input_replace': ''}), 1050 ('idExpiryDate', '有效期限', 'date_compare', {'long': True, 'ocr_split': True, 'input_replace': ''}),
1043 } 1051 ]
1044 1052
1045 # 护照 1053 # 护照
1046 ITPSP = { 1054 ITPSP = [
1047 'customerChineseName': ('英文姓名', 'common_compare', {}), 1055 ('customerChineseName', '英文姓名', 'name_compare', {'is_passport': True}),
1048 'idNum': ('护照号码', 'common_compare', {}), 1056 ('idNum', '护照号码', 'common_compare', {}),
1049 'idExpiryDate': ('有效期至', 'date_compare', {'input_replace': ''}), # 20250410 1057 ('idExpiryDate', '有效期至', 'date_compare', {'input_replace': ''}), # 20250410
1050 'dateOfBirth': ('出生日期', 'date_compare', {'input_replace': ''}), # 20250410 1058 ('dateOfBirth', '出生日期', 'date_compare', {'input_replace': ''}), # 20250410
1051 } 1059 ]
1052 1060
1053 # 港澳台通行证 1061 # 港澳台通行证
1054 ITHKM_ITTID = { 1062 ITHKM_ITTID = [
1055 'customerChineseName': ('中文名', 'common_compare', {}), 1063 ('customerChineseName', '中文名', 'common_compare', {}),
1056 'idNum': ('证件号码', 'common_compare', {}), 1064 ('idNum', '证件号码', 'common_compare', {}),
1057 'idExpiryDate': ('有效期限', 'date_compare', {'ocr_split': True, 'input_replace': '.'}), # 2013.10.24-2023.10.23 1065 ('idExpiryDate', '有效期限', 'date_compare', {'ocr_split': True, 'input_replace': '.'}), # 2013.10.24-2023.10.23
1058 'dateOfBirth': ('出生日期', 'date_compare', {'input_replace': '.'}), # 2023.10.23 1066 ('dateOfBirth', '出生日期', 'date_compare', {'input_replace': '.'}), # 2023.10.23
1059 # 'secondIdNum': '' 1067 # 'secondIdNum': ''
1060 } 1068 ]
1061 1069
1062 # 居住证 1070 # 居住证
1063 ITRES = { 1071 ITRES = [
1064 'customerChineseName': ('姓名', 'common_compare', {}), 1072 ('customerChineseName', '姓名', 'common_compare', {}),
1065 'idNum': ('公民身份号码', 'common_compare', {}), 1073 ('idNum', '公民身份号码', 'common_compare', {}),
1066 'idExpiryDate': ('有效期限', 'date_compare', {'ocr_split': True, 'input_replace': ''}), # 20200410-20250410 1074 ('idExpiryDate', '有效期限', 'date_compare', {'ocr_split': True, 'input_replace': ''}), # 20200410-20250410
1067 'secondIdNum': ('通行证号码', 'common_compare', {}) 1075 ('secondIdNum', '通行证号码', 'common_compare', {})
1068 } 1076 ]
1069 1077
1070 ID_TYPE_COMPARE = { 1078 ID_TYPE_COMPARE = {
1071 'ITPRC': {'model_field': 'ic_ocr', 'compare_field': ITPRC}, 1079 'ITPRC': [IC_OCR_FIELD, ITPRC],
1072 'ITPSP': {'model_field': 'pp_ocr', 'compare_field': ITPSP}, 1080 'ITPSP': [PP_OCR_FIELD, ITPSP],
1073 'ITHKM': {'model_field': 'eep_ocr', 'compare_field': ITHKM_ITTID}, 1081 'ITHKM': [EEP_OCR_FIELD, ITHKM_ITTID],
1074 'ITTID': {'model_field': 'eep_ocr', 'compare_field': ITHKM_ITTID}, 1082 'ITTID': [EEP_OCR_FIELD, ITHKM_ITTID],
1075 'ITRES': {'model_field': 'rp_ocr', 'compare_field': ITRES}, 1083 'ITRES': [RP_OCR_FIELD, ITRES],
1076 } 1084 }
1077 1085
1078 # 1. 分别对比 POS车架号 vs 车辆登记正,POS车架号 vs 行驶证 1086 # 1. 分别对比 POS车架号 vs 车辆登记正,POS车架号 vs 行驶证
...@@ -1080,37 +1088,35 @@ ID_TYPE_COMPARE = { ...@@ -1080,37 +1088,35 @@ ID_TYPE_COMPARE = {
1080 # b)其中一个 不一致:N,向GCAP发送:不一致的OCR识别结果 1088 # b)其中一个 不一致:N,向GCAP发送:不一致的OCR识别结果
1081 # c)两中比对 均不一致:N,向GCAP发送:车辆登记证 & 行驶证识别结果 1089 # c)两中比对 均不一致:N,向GCAP发送:车辆登记证 & 行驶证识别结果
1082 # 车辆登记证 1090 # 车辆登记证
1083 PCUSD_MVC = { 1091 PCUSD_MVC = [
1084 'vinNo': ('9.车辆识别代号/车架号', 'common_compare', {}), 1092 ('vinNo', '9.车辆识别代号/车架号', 'common_compare', {}),
1085 'manufactureDate': ('32.车辆出厂日期', 'common_compare', {}), 1093 ('manufactureDate', '32.车辆出厂日期', 'common_compare', {}),
1086 'firstRegistrationDate': ('3.登记日期', 'common_compare', {}), 1094 ('firstRegistrationDate', '3.登记日期', 'common_compare', {}),
1087 } 1095 ]
1088 1096
1089 # 行驶证 1097 # 行驶证
1090 PCUSD_DL = { 1098 PCUSD_DL = [
1091 'vinNo': ('车辆识别代码', 'common_compare', {}), 1099 ('vinNo', '车辆识别代码', 'common_compare', {}),
1092 # 'manufactureDate': '', 1100 ]
1093 # 'firstRegistrationDate': '',
1094 }
1095 1101
1096 # 营业执照 1102 # 营业执照
1097 TCCOR = { 1103 TCCOR = [
1098 'customerChineseName': ('企业名称', 'common_compare', {}), 1104 ('customerChineseName', '企业名称', 'common_compare', {}),
1099 'legalRepName': ('经营者姓名', 'common_compare', {}), 1105 ('legalRepName', '经营者姓名', 'name_compare', {}),
1100 'idNum': ('注册号', 'common_compare', {}), 1106 ('idNum', '注册号', 'common_compare', {}),
1101 'businessLicenseNo': ('注册号', 'common_compare', {}), 1107 ('businessLicenseNo', '注册号', 'common_compare', {}),
1102 'taxRegistrationCode': ('注册号', 'common_compare', {}), 1108 ('taxRegistrationCode', '注册号', 'common_compare', {}),
1103 'incorporationDate': ('成立日期', 'date_compare', {'ocr_replace': True}), # 2017年07月11日 1109 ('incorporationDate', '成立日期', 'date_compare', {'ocr_replace': True}), # 2017年07月11日
1104 # 2017年07月11日至长期 1. OCR识别为长期,向GCAP发送:2099-12-31 00:00:00.0 1110 # 2017年07月11日至长期 1. OCR识别为长期,向GCAP发送:2099-12-31 00:00:00.0
1105 'businessLicenseDueDate': ('营业期限', 'date_compare', {'long': True, 'ocr_replace': True}), 1111 ('businessLicenseDueDate', '营业期限', 'date_compare', {'long': True, 'ocr_replace': True}),
1106 'capitalRegAmount': ('注册资本', 'rmb_compare', {}), # 壹拾万元整 将OCR识别结果(人民币大写)转化为数字 1112 ('capitalRegAmount', '注册资本', 'rmb_compare', {}), # 壹拾万元整 将OCR识别结果(人民币大写)转化为数字
1107 } 1113 ]
1108 1114
1109 TCSEP = { 1115 TCSEP = [
1110 'companyName': ('企业名称', 'common_compare', {}), 1116 ('companyName', '企业名称', 'common_compare', {}),
1111 'registeredCapital': ('注册资本', 'rmb_compare', {}), # 壹拾万元整 将OCR识别结果(人民币大写)转化为数字 1117 ('registeredCapital', '注册资本', 'rmb_compare', {}), # 壹拾万元整 将OCR识别结果(人民币大写)转化为数字
1112 'selfEmployedSubType': ('企业类型', 'type_compare', {}), # 有限责任公司 1118 ('selfEmployedSubType', '企业类型', 'type_compare', {}) # 有限责任公司
1113 } 1119 ]
1114 1120
1115 # 1. POS数据OCR识别结果对应关系如下: 1121 # 1. POS数据OCR识别结果对应关系如下:
1116 # a)Individual Businessman CSIBM => 个体工商户 1122 # a)Individual Businessman CSIBM => 个体工商户
......
...@@ -444,7 +444,7 @@ class DocView(GenericView, DocHandler): ...@@ -444,7 +444,7 @@ class DocView(GenericView, DocHandler):
444 file.close() 444 file.close()
445 # 1. 上传信息记录 445 # 1. 上传信息记录
446 # application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id) 446 # application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id)
447 application_id = 'CH-S200012772' 447 application_id = 'CH-S200012727'
448 upload_finish_time = timezone.now() 448 upload_finish_time = timezone.now()
449 document_scheme = random.choice(consts.DOC_SCHEME_LIST) 449 document_scheme = random.choice(consts.DOC_SCHEME_LIST)
450 data_source = random.choice(consts.DATA_SOURCE_LIST) 450 data_source = random.choice(consts.DATA_SOURCE_LIST)
......
...@@ -12,6 +12,29 @@ compare_log = logging.getLogger('compare') ...@@ -12,6 +12,29 @@ compare_log = logging.getLogger('compare')
12 log_base = '[CA Compare]' 12 log_base = '[CA Compare]'
13 13
14 14
15 def field_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set):
16 is_find = False
17 ocr_res_str = ocr_res_dict.get(ocr_field)
18 if ocr_res_str is not None:
19 ocr_res_list = json.loads(ocr_res_str)
20 res_len = len(ocr_res_list)
21 for ocr_res in ocr_res_list:
22 if is_find:
23 break
24 for idx, compare_tuple in enumerate(compare_list):
25 compare_res = getattr(cp, compare_tuple[2])(
26 info_dict.get(compare_tuple[0]), ocr_res.get(compare_tuple[1]), **compare_tuple[3])
27 if idx == 0 and compare_res == consts.RESULT_N and res_len != 1:
28 break
29 is_find = True
30 info_dict[compare_tuple[0] + 'Result'] = compare_res
31 res_set.add(compare_res)
32 if not is_find:
33 res_set.add(consts.RESULT_N)
34 for compare_tuple in compare_list:
35 info_dict[compare_tuple[0] + 'Result'] = consts.RESULT_N
36
37
15 @app.task 38 @app.task
16 def compare(application_id, application_entity, uniq_seq, ocr_res_id): 39 def compare(application_id, application_entity, uniq_seq, ocr_res_id):
17 # POS: application_id, application_entity, uniq_seq, None 40 # POS: application_id, application_entity, uniq_seq, None
...@@ -25,8 +48,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): ...@@ -25,8 +48,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id):
25 last_obj = comparison_class.objects.filter(application_id=application_id).last() 48 last_obj = comparison_class.objects.filter(application_id=application_id).last()
26 if last_obj is None: 49 if last_obj is None:
27 compare_log.info('{0} [comparison info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format( 50 compare_log.info('{0} [comparison info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format(
28 log_base, application_entity, application_id, uniq_seq, ocr_res_id 51 log_base, application_entity, application_id, uniq_seq, ocr_res_id))
29 ))
30 return 52 return
31 53
32 # 根据application_id查找OCR累计结果指定license字段,如果没有,结束 54 # 根据application_id查找OCR累计结果指定license字段,如果没有,结束
...@@ -42,165 +64,89 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): ...@@ -42,165 +64,89 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id):
42 return 64 return
43 65
44 # 比对信息 66 # 比对信息
45 comparison_res = { 67 try:
46 'OCR_Input': { 68 comparison_res = {
47 'uniqSeq': last_obj.uniq_seq, 69 'OCR_Input': {
48 'applicationId': application_id, 70 'uniqSeq': last_obj.uniq_seq,
49 'applicationEntity': application_entity, 71 'applicationId': application_id,
50 'applicationVersion': last_obj.application_version, 72 'applicationEntity': application_entity,
51 'vehicleStatus': last_obj.vehicle_status, 73 'applicationVersion': last_obj.application_version,
52 'wholeResult': 'Y', 74 'vehicleStatus': last_obj.vehicle_status,
53 'wholeResultMessage': '', 75 'wholeResult': 'Y',
54 'applicationLink': '', 76 'wholeResultMessage': '',
77 'applicationLink': '',
78 }
55 } 79 }
56 } 80
57 81 res_set = set()
58 res_set = set() 82
59 83 is_sep = True if last_obj.customer_type == consts.CUSTOMER_TYPE[5] else False
60 is_sep = True if last_obj.customer_type == consts.CUSTOMER_TYPE[5] else False 84
61 85 individual_cus_info_list = json.loads(last_obj.individual_cus_info)
62 individual_cus_info_list = json.loads(last_obj.individual_cus_info) 86 for individual_cus_info in individual_cus_info_list:
63 for individual_cus_info in individual_cus_info_list: 87 individual_cus_info['customerType'] = last_obj.customer_type
64 individual_cus_info['customerType'] = last_obj.customer_type 88 # sep营业执照
65 # sep营业执照 89 if is_sep and individual_cus_info.get('companyName') is not None:
66 if is_sep and individual_cus_info.get('companyName') is not None: 90 field_compare(individual_cus_info, ocr_res_dict, consts.BL_OCR_FIELD, consts.TCSEP, res_set)
67 sep_is_find = False 91
68 sep_ocr_res_str = ocr_res_dict.get('bl_ocr') 92 # 个人信息证件
69 if sep_ocr_res_str is not None: 93 id_type = individual_cus_info.get('idType')
70 sep_ocr_list = json.loads(sep_ocr_res_str) 94 compare_info_list = consts.ID_TYPE_COMPARE.get(id_type)
71 for sep_ocr in sep_ocr_list: 95 if compare_info_list is None:
72 company_name = sep_ocr.get(consts.TCSEP.get('companyName')[0]) 96 continue
73 if company_name is None or company_name != individual_cus_info.get('companyName'): 97 field_compare(individual_cus_info, ocr_res_dict, compare_info_list[0], compare_info_list[1], res_set)
74 continue 98
75 sep_is_find = True 99 comparison_res['OCR_Input']['individualCusInfo'] = individual_cus_info_list
76 for sep_field, sep_tuple in consts.TCSEP.items(): 100
77 sep_res = getattr(cp, sep_tuple[1])( 101 if last_obj.corporate_cus_info is not None:
78 individual_cus_info.get(sep_field), sep_ocr.get(sep_tuple[0]), **sep_tuple[2]) 102 corporate_cus_info = json.loads(last_obj.corporate_cus_info)
79 individual_cus_info[sep_field + 'Result'] = sep_res 103 corporate_cus_info['customerType'] = last_obj.customer_type
80 res_set.add(sep_res) 104 field_compare(corporate_cus_info, ocr_res_dict, consts.BL_OCR_FIELD, consts.TCCOR, res_set)
81 break 105
82 if not sep_is_find: 106 comparison_res['OCR_Input']['corporateCusInfo'] = corporate_cus_info
83 res_set.add(consts.RESULT_N) 107
84 for field in consts.TCSEP.keys(): 108 if last_obj.vehicle_status == consts.VEHICLE_STATUS[0] and last_obj.usedcar_info is not None:
85 individual_cus_info[field + 'Result'] = consts.RESULT_N 109 usedcar_info = json.loads(last_obj.usedcar_info)
86 110
87 # 个人信息证件 111 field_compare(usedcar_info, ocr_res_dict, consts.MVC_OCR_FIELD, consts.PCUSD_MVC, res_set)
88 id_type = individual_cus_info.get('idType') 112
89 compare_target = consts.ID_TYPE_COMPARE.get(id_type) 113 if usedcar_info[consts.PCUSD_MVC[0][0] + 'Result'] == consts.RESULT_Y:
90 if compare_target is None: 114 field_compare(usedcar_info, ocr_res_dict, consts.DL_OCR_FIELD, consts.PCUSD_DL, res_set)
91 continue 115
92 is_find = False 116 comparison_res['OCR_Input']['usedCarInfo'] = usedcar_info
93 ocr_res_str = ocr_res_dict.get(compare_target.get('model_field')) 117
94 if ocr_res_str is not None: 118 comparison_res['OCR_Input']['wholeResult'] = consts.RESULT_N if consts.RESULT_N in res_set else consts.RESULT_Y
95 ocr_res_list = json.loads(ocr_res_str) 119
96 compare_target_dict = compare_target.get('compare_field') 120 except Exception as e:
97 for ocr_res in ocr_res_list: 121 compare_log.error('{0} [compare error] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
98 base_name = ocr_res.get(compare_target_dict.get('customerChineseName')[0]) 122 '[error={5}]'.format(log_base, application_entity, application_id, uniq_seq, ocr_res_id,
99 if base_name is None or base_name != individual_cus_info.get('customerChineseName'): # TODO 特殊姓名比对 123 traceback.format_exc()))
100 continue 124 else:
101 is_find = True 125 compare_log.info('{0} [compare success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format(
102 for compare_field, compare_tuple in compare_target.get('compare_field').items(): 126 log_base, application_entity, application_id, uniq_seq, ocr_res_id))
103 compare_res = getattr(cp, compare_tuple[1])( 127
104 individual_cus_info.get(compare_field), ocr_res.get(compare_tuple[0]), **compare_tuple[2]) 128 # 将比对结果发送GCAP
105 individual_cus_info[compare_field + 'Result'] = compare_res 129 try:
106 res_set.add(compare_res) 130 data = gcap.dict_to_xml(comparison_res)
107 break 131 except Exception as e:
108 if not is_find: 132 compare_log.error('{0} [dict to xml failed] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
109 res_set.add(consts.RESULT_N) 133 '[error={5}]'.format(log_base, application_entity, application_id, uniq_seq, ocr_res_id,
110 for field in compare_target.get('compare_field').keys(): 134 traceback.format_exc()))
111 individual_cus_info[field + 'Result'] = consts.RESULT_N 135 else:
112 136 try:
113 comparison_res['OCR_Input']['individualCusInfo'] = individual_cus_info_list 137 for times in range(consts.RETRY_TIMES):
114 138 try:
115 if last_obj.corporate_cus_info is not None: 139 gcap.send(data)
116 corporate_cus_info = json.loads(last_obj.corporate_cus_info) 140 except Exception as e:
117 corporate_cus_info['customerType'] = last_obj.customer_type 141 gcap_exc = str(e)
118 142 else:
119 is_bl_find = False
120 bl_ocr_res_str = ocr_res_dict.get('bl_ocr')
121 if bl_ocr_res_str is not None:
122 bl_ocr_list = json.loads(bl_ocr_res_str)
123 for bl_ocr in bl_ocr_list:
124 company_name = bl_ocr.get(consts.TCCOR.get('customerChineseName')[0])
125 if company_name is None or company_name != corporate_cus_info.get('customerChineseName'):
126 continue
127 is_bl_find = True
128 for bl_field, bl_tuple in consts.TCCOR.items():
129 bl_res = getattr(cp, bl_tuple[1])(
130 corporate_cus_info.get(bl_field), bl_ocr.get(bl_tuple[0]), **bl_tuple[2])
131 corporate_cus_info[bl_field + 'Result'] = bl_res
132 res_set.add(bl_res)
133 break
134 if not is_bl_find:
135 res_set.add(consts.RESULT_N)
136 for field in consts.TCCOR.keys():
137 corporate_cus_info[field + 'Result'] = consts.RESULT_N
138
139 comparison_res['OCR_Input']['corporateCusInfo'] = corporate_cus_info
140
141 if last_obj.vehicle_status == consts.VEHICLE_STATUS[0] and last_obj.usedcar_info is not None:
142 usedcar_info = json.loads(last_obj.usedcar_info)
143
144 is_usedcar_find = False
145 mvc_ocr_res_str = ocr_res_dict.get('mvc_ocr')
146 if mvc_ocr_res_str is not None:
147 mvc_ocr_list = json.loads(mvc_ocr_res_str)
148 for mvc_ocr in mvc_ocr_list:
149 vin_no = mvc_ocr.get(consts.PCUSD_MVC.get('vinNo')[0])
150 if vin_no is None or vin_no != usedcar_info.get('vinNo'):
151 continue
152 is_usedcar_find = True
153 for mvc_field, mvc_tuple in consts.PCUSD_MVC.items():
154 mvc_res = getattr(cp, mvc_tuple[1])(
155 usedcar_info.get(mvc_field), mvc_ocr.get(mvc_tuple[0]), **mvc_tuple[2])
156 usedcar_info[mvc_field + 'Result'] = mvc_res
157 res_set.add(mvc_res)
158
159 dl_find = False
160 dl_ocr_res_str = ocr_res_dict.get('dl_ocr')
161 if dl_ocr_res_str is not None:
162 dl_ocr_list = json.loads(dl_ocr_res_str)
163 for dl_ocr in dl_ocr_list:
164 dl_vin_no = dl_ocr.get(consts.PCUSD_DL.get('vinNo')[0])
165 if dl_vin_no is None or dl_vin_no != usedcar_info.get('vinNo'):
166 continue
167 dl_find = True
168 break 143 break
169 if not dl_find: 144 else:
170 res_set.add(consts.RESULT_N) 145 raise GCAPException(gcap_exc)
171 usedcar_info['vinNo' + 'Result'] = consts.RESULT_N 146 except Exception as e:
172 break 147 compare_log.error('{0} [gcap failed] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
173 if not is_usedcar_find: 148 '[error={5}]'.format(log_base, application_entity, application_id, uniq_seq,
174 res_set.add(consts.RESULT_N) 149 ocr_res_id, traceback.format_exc()))
175 for field in consts.PCUSD_MVC.keys(): 150 else:
176 usedcar_info[field + 'Result'] = consts.RESULT_N 151 compare_log.info('{0} [task success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format(
177 comparison_res['OCR_Input']['usedCarInfo'] = usedcar_info 152 log_base, application_entity, application_id, uniq_seq, ocr_res_id))
178
179 comparison_res['OCR_Input']['wholeResult'] = consts.RESULT_N if consts.RESULT_N in res_set else consts.RESULT_Y
180 print(comparison_res)
181
182 # 将比对结果发送GCAP
183 # try:
184 # data = gcap.dict_to_xml(comparison_res)
185 # except Exception as e:
186 # compare_log.error('{0} [dict to xml failed] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
187 # '[error={5}]'.format(log_base, application_entity, application_id, uniq_seq, ocr_res_id,
188 # traceback.format_exc()))
189 # else:
190 # try:
191 # for times in range(consts.RETRY_TIMES):
192 # try:
193 # gcap.send(data)
194 # except Exception as e:
195 # gcap_exc = str(e)
196 # else:
197 # break
198 # else:
199 # raise GCAPException(gcap_exc)
200 # except Exception as e:
201 # compare_log.error('{0} [gcap failed] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
202 # '[error={5}]'.format(log_base, application_entity, application_id, uniq_seq,
203 # ocr_res_id, traceback.format_exc()))
204 # else:
205 # compare_log.info('{0} [task success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format(
206 # log_base, application_entity, application_id, uniq_seq, ocr_res_id))
......
...@@ -19,7 +19,13 @@ class Comparison: ...@@ -19,7 +19,13 @@ class Comparison:
19 19
20 self.RESULT_Y = 'Y' 20 self.RESULT_Y = 'Y'
21 self.RESULT_N = 'N' 21 self.RESULT_N = 'N'
22 self.RESULT_NA = 'NA' # TODO NA情况 22 self.RESULT_NA = 'NA'
23
24 self.TRANS_MAP = {
25 ' ': '',
26 '·': '',
27 }
28 self.TRANS = str.maketrans(self.TRANS_MAP)
23 29
24 def build_res(self, result): 30 def build_res(self, result):
25 if result: 31 if result:
...@@ -28,9 +34,34 @@ class Comparison: ...@@ -28,9 +34,34 @@ class Comparison:
28 return self.RESULT_N 34 return self.RESULT_N
29 35
30 def common_compare(self, input_str, ocr_str, **kwargs): 36 def common_compare(self, input_str, ocr_str, **kwargs):
37 if not isinstance(input_str, str) or isinstance(ocr_str, str):
38 return self.RESULT_N
31 return self.build_res(input_str == ocr_str) 39 return self.build_res(input_str == ocr_str)
32 40
41 def name_compare(self, input_str, ocr_str, **kwargs):
42 if not isinstance(input_str, str) or isinstance(ocr_str, str):
43 return self.RESULT_N
44 if kwargs.get('is_passport'):
45 input_obj = re.search(r'[a-zA-Z]]!', input_str)
46 if input_obj:
47 input_s = input_obj.group()
48 ocr_obj = re.search(r'[a-zA-Z]]!', ocr_str)
49 if ocr_obj:
50 ocr_s = ocr_obj.group()
51 return self.build_res(input_s == ocr_s)
52 return self.RESULT_N
53 else:
54 return self.build_res((input_str == ocr_str))
55 else:
56 if re.search(r'[a-zA-Z]]', input_str):
57 return self.RESULT_NA
58 input_s = input_str.translate(self.TRANS)
59 ocr_s = ocr_str.translate(self.TRANS)
60 return self.build_res(input_s == ocr_s)
61
33 def date_compare(self, input_str, ocr_str, **kwargs): 62 def date_compare(self, input_str, ocr_str, **kwargs):
63 if not isinstance(input_str, str) or isinstance(ocr_str, str):
64 return self.RESULT_N
34 if kwargs.get('long', False) and '长期' in ocr_str: 65 if kwargs.get('long', False) and '长期' in ocr_str:
35 return '2099-12-31' 66 return '2099-12-31'
36 if kwargs.get('ocr_split', False): 67 if kwargs.get('ocr_split', False):
...@@ -42,10 +73,14 @@ class Comparison: ...@@ -42,10 +73,14 @@ class Comparison:
42 return self.build_res(input_str == ocr_str) 73 return self.build_res(input_str == ocr_str)
43 74
44 def rmb_compare(self, input_str, ocr_str, **kwargs): 75 def rmb_compare(self, input_str, ocr_str, **kwargs):
76 if not isinstance(input_str, str) or isinstance(ocr_str, str):
77 return self.RESULT_N
45 input_rmb_upper = to_rmb_upper(float(input_str)) 78 input_rmb_upper = to_rmb_upper(float(input_str))
46 return self.build_res(input_rmb_upper == ocr_str) 79 return self.build_res(input_rmb_upper == ocr_str)
47 80
48 def type_compare(self, input_str, ocr_str, **kwargs): 81 def type_compare(self, input_str, ocr_str, **kwargs):
82 if not isinstance(input_str, str) or isinstance(ocr_str, str):
83 return self.RESULT_N
49 for map_tuple in self.TYPE_MAPPING: 84 for map_tuple in self.TYPE_MAPPING:
50 if re.search(map_tuple[0], ocr_str) is not None: 85 if re.search(map_tuple[0], ocr_str) is not None:
51 compare_str = map_tuple[1] 86 compare_str = map_tuple[1]
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!