Merge branch 'feature/ca_compare' into feature/0611
Showing
3 changed files
with
81 additions
and
87 deletions
| ... | @@ -1136,34 +1136,35 @@ ITRES = [ | ... | @@ -1136,34 +1136,35 @@ ITRES = [ |
| 1136 | ] | 1136 | ] |
| 1137 | 1137 | ||
| 1138 | ID_TYPE_COMPARE = { | 1138 | ID_TYPE_COMPARE = { |
| 1139 | 'ITPRC': [IC_OCR_FIELD, ITPRC], | 1139 | 'ITPRC': [IC_OCR_FIELD, ITPRC, True], |
| 1140 | 'ITPSP': [PP_OCR_FIELD, ITPSP], | 1140 | 'ITPSP': [PP_OCR_FIELD, ITPSP, False], |
| 1141 | 'ITHKM': [EEP_OCR_FIELD, ITHKM_ITTID], | 1141 | 'ITHKM': [EEP_OCR_FIELD, ITHKM_ITTID, False], |
| 1142 | 'ITTID': [EEP_OCR_FIELD, ITHKM_ITTID], | 1142 | 'ITTID': [EEP_OCR_FIELD, ITHKM_ITTID, False], |
| 1143 | 'ITRES': [RP_OCR_FIELD, ITRES], | 1143 | 'ITRES': [RP_OCR_FIELD, ITRES, True], |
| 1144 | } | 1144 | } |
| 1145 | 1145 | ||
| 1146 | ID_RES = 'idNumResult' | 1146 | ID_RES = 'idNumResult' |
| 1147 | SECOND_ID_TYPE_FIELD = 'secondIdType' | ||
| 1147 | SECOND_ID_FIELD = 'secondIdNum' | 1148 | SECOND_ID_FIELD = 'secondIdNum' |
| 1148 | SECOND_ID_RES = 'secondIdNumResult' | 1149 | SECOND_ID_RES = 'secondIdNumResult' |
| 1149 | 1150 | ||
| 1150 | SECOND_ITPRC = [ | 1151 | SECOND_ITPRC = [ |
| 1151 | ('secondIdNum', '公民身份号码', 'common_compare', {}, SECOND_ID_RES), | 1152 | (SECOND_ID_FIELD, '公民身份号码', 'common_compare', {}, SECOND_ID_RES), |
| 1152 | ] | 1153 | ] |
| 1153 | 1154 | ||
| 1154 | # 护照 | 1155 | # 护照 |
| 1155 | SECOND_ITPSP = [ | 1156 | SECOND_ITPSP = [ |
| 1156 | ('secondIdNum', '护照号码', 'common_compare', {}, SECOND_ID_RES), | 1157 | (SECOND_ID_FIELD, '护照号码', 'common_compare', {}, SECOND_ID_RES), |
| 1157 | ] | 1158 | ] |
| 1158 | 1159 | ||
| 1159 | # 港澳台通行证 | 1160 | # 港澳台通行证 |
| 1160 | SECOND_ITHKM_ITTID = [ | 1161 | SECOND_ITHKM_ITTID = [ |
| 1161 | ('secondIdNum', '证件号码', 'common_compare', {}, SECOND_ID_RES), | 1162 | (SECOND_ID_FIELD, '证件号码', 'common_compare', {}, SECOND_ID_RES), |
| 1162 | ] | 1163 | ] |
| 1163 | 1164 | ||
| 1164 | # 居住证 | 1165 | # 居住证 |
| 1165 | SECOND_ITRES = [ | 1166 | SECOND_ITRES = [ |
| 1166 | ('secondIdNum', '公民身份号码', 'common_compare', {}, SECOND_ID_RES), | 1167 | (SECOND_ID_FIELD, '公民身份号码', 'common_compare', {}, SECOND_ID_RES), |
| 1167 | ] | 1168 | ] |
| 1168 | 1169 | ||
| 1169 | SECOND_ID_TYPE_COMPARE = { | 1170 | SECOND_ID_TYPE_COMPARE = { |
| ... | @@ -1219,14 +1220,15 @@ RESULT_Y = 'Y' | ... | @@ -1219,14 +1220,15 @@ RESULT_Y = 'Y' |
| 1219 | RESULT_N = 'N' | 1220 | RESULT_N = 'N' |
| 1220 | RESULT_NA = 'NA' | 1221 | RESULT_NA = 'NA' |
| 1221 | 1222 | ||
| 1222 | IN_ORDER = ('applicantType', 'idType', 'secondIdType', 'customerType', 'customerChineseName', 'idNum', 'secondIdNum', | 1223 | IN_ORDER = ('applicantType', 'idType', SECOND_ID_TYPE_FIELD, 'customerType', 'customerChineseName', 'idNum', |
| 1223 | "idExpiryDate", "dateOfBirth", 'companyName', "registeredCapital", 'selfEmployedSubType',) | 1224 | SECOND_ID_FIELD, "idExpiryDate", "dateOfBirth", 'companyName', "registeredCapital", 'selfEmployedSubType',) |
| 1224 | UC_ORDER = ('vinNo', 'manufactureDate', 'firstRegistrationDate') | 1225 | UC_ORDER = ('vinNo', 'manufactureDate', 'firstRegistrationDate') |
| 1225 | CO_ORDER = ('customerType', 'customerChineseName', 'legalRepName', 'idNum', 'businessLicenseNo', 'taxRegistrationCode', | 1226 | CO_ORDER = ('customerType', 'customerChineseName', 'legalRepName', 'idNum', 'businessLicenseNo', 'taxRegistrationCode', |
| 1226 | 'incorporationDate', 'businessLicenseDueDate', 'capitalRegAmount') | 1227 | 'incorporationDate', 'businessLicenseDueDate', 'capitalRegAmount') |
| 1227 | 1228 | ||
| 1228 | PREFIX_MVC = 'GB' | 1229 | PREFIX_MVC = 'G' |
| 1229 | PREFIX_DL = 'DL' | 1230 | PREFIX_DL = 'V' |
| 1231 | SPLIT = ';' | ||
| 1230 | 1232 | ||
| 1231 | # --------------- DDA 保存图片 -------------------- | 1233 | # --------------- DDA 保存图片 -------------------- |
| 1232 | DDA_FIELD = 'DDA' | 1234 | DDA_FIELD = 'DDA' | ... | ... |
| ... | @@ -17,11 +17,15 @@ log_base = '[CA Compare]' | ... | @@ -17,11 +17,15 @@ log_base = '[CA Compare]' |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | def get_order_dict(src_dict, order_tuple): | 19 | def get_order_dict(src_dict, order_tuple): |
| 20 | if consts.SECOND_ID_TYPE_FIELD in src_dict: | ||
| 21 | if src_dict.get(consts.SECOND_ID_TYPE_FIELD) not in consts.SECOND_ID_TYPE_COMPARE: | ||
| 22 | src_dict.pop(consts.SECOND_ID_TYPE_FIELD, None) | ||
| 23 | src_dict.pop(consts.SECOND_ID_FIELD, None) | ||
| 24 | |||
| 20 | order_dict = OrderedDict({}) | 25 | order_dict = OrderedDict({}) |
| 21 | for field in order_tuple: | 26 | for field in order_tuple: |
| 22 | value = src_dict.get(field) | 27 | if field in src_dict: |
| 23 | if value is not None: | 28 | order_dict[field] = src_dict[field] |
| 24 | order_dict[field] = value | ||
| 25 | return order_dict | 29 | return order_dict |
| 26 | 30 | ||
| 27 | 31 | ||
| ... | @@ -30,33 +34,33 @@ def field_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set, has | ... | @@ -30,33 +34,33 @@ def field_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set, has |
| 30 | ocr_res_str = ocr_res_dict.get(ocr_field) | 34 | ocr_res_str = ocr_res_dict.get(ocr_field) |
| 31 | if ocr_res_str is not None: | 35 | if ocr_res_str is not None: |
| 32 | ocr_res_list = json.loads(ocr_res_str) | 36 | ocr_res_list = json.loads(ocr_res_str) |
| 33 | length = len(ocr_res_list) | 37 | # length = len(ocr_res_list) |
| 34 | 38 | ||
| 35 | # # sep营业执照根据法人过滤 | 39 | # sep营业执照根据法人过滤 |
| 36 | # if isinstance(sep_name, str): | 40 | if isinstance(sep_name, str): |
| 37 | # tmp_list = [] | 41 | tmp_list = [] |
| 38 | # for ocr_res in ocr_res_list: | 42 | for ocr_res in ocr_res_list: |
| 39 | # ocr_sep_name = ocr_res.get(consts.LEGAL_REP_NAME) | 43 | ocr_sep_name = ocr_res.get(consts.LEGAL_REP_NAME) |
| 40 | # if isinstance(ocr_sep_name, str) and ocr_sep_name == sep_name: | 44 | if isinstance(ocr_sep_name, str) and ocr_sep_name == sep_name: |
| 41 | # tmp_list.append(ocr_res) | 45 | tmp_list.append(ocr_res) |
| 42 | # else: | 46 | else: |
| 43 | # tmp_list = ocr_res_list | 47 | tmp_list = ocr_res_list |
| 44 | # | 48 | |
| 45 | # length = len(tmp_list) | 49 | length = len(tmp_list) |
| 46 | 50 | ||
| 47 | # 过期期限特殊处理 | 51 | # 过期期限特殊处理 |
| 48 | if has_expiry_date: | 52 | if has_expiry_date: |
| 49 | expiry_dates = [] | 53 | expiry_dates = [] |
| 50 | key = compare_list[2][1] | 54 | key = compare_list[2][1] |
| 51 | # for ocr_res in tmp_list: | 55 | for ocr_res in tmp_list: |
| 52 | for ocr_res in ocr_res_list: | 56 | # for ocr_res in ocr_res_list: |
| 53 | if ocr_res.get(key): | 57 | if ocr_res.get(key): |
| 54 | expiry_dates.append(ocr_res.get(key)) | 58 | expiry_dates.append(ocr_res.get(key)) |
| 55 | else: | 59 | else: |
| 56 | expiry_dates = [] | 60 | expiry_dates = [] |
| 57 | 61 | ||
| 58 | # for ocr_res in tmp_list: | 62 | for ocr_res in tmp_list: |
| 59 | for ocr_res in ocr_res_list: | 63 | # for ocr_res in ocr_res_list: |
| 60 | if is_find: | 64 | if is_find: |
| 61 | break | 65 | break |
| 62 | for idx, compare_tuple in enumerate(compare_list): | 66 | for idx, compare_tuple in enumerate(compare_list): |
| ... | @@ -204,29 +208,29 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): | ... | @@ -204,29 +208,29 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): |
| 204 | for individual_cus_info in individual_cus_info_list: | 208 | for individual_cus_info in individual_cus_info_list: |
| 205 | order_individual_cus_info = get_order_dict(individual_cus_info, consts.IN_ORDER) | 209 | order_individual_cus_info = get_order_dict(individual_cus_info, consts.IN_ORDER) |
| 206 | 210 | ||
| 207 | # # 获取sep下营业执照法人代表 | 211 | # 获取sep下营业执照法人代表 |
| 208 | # if order_individual_cus_info.get('customerType') == consts.CUSTOMER_TYPE[5]: | 212 | if order_individual_cus_info.get('customerType') == consts.CUSTOMER_TYPE[5]: |
| 209 | # sep_name = order_individual_cus_info.get('customerChineseName') | 213 | sep_name = order_individual_cus_info.get('customerChineseName') |
| 210 | # if isinstance(sep_name, str): | 214 | if isinstance(sep_name, str): |
| 211 | # sep_name = sep_name.strip() | 215 | sep_name = sep_name.strip() |
| 212 | # if sep_name == '': | 216 | if sep_name == '': |
| 213 | # sep_name = None | 217 | sep_name = None |
| 214 | # else: | 218 | else: |
| 215 | # sep_name = None | 219 | sep_name = None |
| 216 | 220 | ||
| 217 | # 个人信息证件 | 221 | # 个人信息证件 |
| 218 | id_type = order_individual_cus_info.get('idType') | 222 | id_type = order_individual_cus_info.get('idType') |
| 219 | compare_info_list = consts.ID_TYPE_COMPARE.get(id_type) | 223 | if id_type not in consts.ID_TYPE_COMPARE: |
| 220 | if compare_info_list is not None: | 224 | continue |
| 221 | field_compare(order_individual_cus_info, ocr_res_dict, compare_info_list[0], compare_info_list[1], | 225 | ocr_field, compare_list, has_expiry_date = consts.ID_TYPE_COMPARE.get(id_type) |
| 222 | res_set, has_expiry_date=True) | 226 | field_compare(order_individual_cus_info, ocr_res_dict, ocr_field, compare_list, res_set, |
| 227 | has_expiry_date=has_expiry_date) | ||
| 223 | 228 | ||
| 224 | # 第二证件 | 229 | # 第二证件 |
| 225 | second_id_type = order_individual_cus_info.get('secondIdType') | 230 | second_id_type = order_individual_cus_info.get('secondIdType') |
| 226 | second_compare_info_list = consts.SECOND_ID_TYPE_COMPARE.get(second_id_type) | 231 | if second_id_type is not None: |
| 227 | if second_compare_info_list is not None: | 232 | second_ocr_field, second_compare_list = consts.SECOND_ID_TYPE_COMPARE.get(second_id_type) |
| 228 | field_compare(order_individual_cus_info, ocr_res_dict, second_compare_info_list[0], | 233 | field_compare(order_individual_cus_info, ocr_res_dict, second_ocr_field, second_compare_list, res_set) |
| 229 | second_compare_info_list[1], res_set) | ||
| 230 | # 重新排列 | 234 | # 重新排列 |
| 231 | new_dict = OrderedDict({}) | 235 | new_dict = OrderedDict({}) |
| 232 | second_id_res = order_individual_cus_info.pop(consts.SECOND_ID_RES, consts.RESULT_NA) | 236 | second_id_res = order_individual_cus_info.pop(consts.SECOND_ID_RES, consts.RESULT_NA) |
| ... | @@ -238,9 +242,9 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): | ... | @@ -238,9 +242,9 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): |
| 238 | 242 | ||
| 239 | # sep营业执照 | 243 | # sep营业执照 |
| 240 | if order_individual_cus_info.get('customerType') == consts.CUSTOMER_TYPE[5]: | 244 | if order_individual_cus_info.get('customerType') == consts.CUSTOMER_TYPE[5]: |
| 241 | # field_compare(order_individual_cus_info, ocr_res_dict, consts.BL_OCR_FIELD, consts.TCSEP, res_set, | 245 | field_compare(order_individual_cus_info, ocr_res_dict, consts.BL_OCR_FIELD, consts.TCSEP, res_set, |
| 242 | # sep_name=sep_name) | 246 | sep_name=sep_name) |
| 243 | field_compare(order_individual_cus_info, ocr_res_dict, consts.BL_OCR_FIELD, consts.TCSEP, res_set) | 247 | # field_compare(order_individual_cus_info, ocr_res_dict, consts.BL_OCR_FIELD, consts.TCSEP, res_set) |
| 244 | 248 | ||
| 245 | order_individual_cus_info_list.append(order_individual_cus_info) | 249 | order_individual_cus_info_list.append(order_individual_cus_info) |
| 246 | 250 | ||
| ... | @@ -257,39 +261,27 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): | ... | @@ -257,39 +261,27 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): |
| 257 | dl_find, dl_vinos = usedcar_info_compare(order_usedcar_info, ocr_res_dict, consts.DL_OCR_FIELD, | 261 | dl_find, dl_vinos = usedcar_info_compare(order_usedcar_info, ocr_res_dict, consts.DL_OCR_FIELD, |
| 258 | consts.PCUSD_DL, res_set) | 262 | consts.PCUSD_DL, res_set) |
| 259 | 263 | ||
| 260 | # if mvc_find is True and dl_find is False: | ||
| 261 | # vino = dl_vinos[-1] if len(dl_vinos) > 0 else '' | ||
| 262 | # order_usedcar_info[consts.PCUSD_MVC[0][0]] = '{0}: {1}'.format(consts.PREFIX_MVC, vino) | ||
| 263 | # order_usedcar_info[consts.PCUSD_MVC[0][4]] = consts.RESULT_N | ||
| 264 | # elif mvc_find is False and dl_find is True: | ||
| 265 | # vino = mvc_vinos[-1] if len(mvc_vinos) > 0 else '' | ||
| 266 | # order_usedcar_info[consts.PCUSD_MVC[0][0]] = '{0}: {1}'.format(consts.PREFIX_DL, vino) | ||
| 267 | # order_usedcar_info[consts.PCUSD_MVC[0][4]] = consts.RESULT_N | ||
| 268 | # elif mvc_find is False and dl_find is False: | ||
| 269 | # vino_list = [] | ||
| 270 | # mvc_vino = mvc_vinos[-1] if len(mvc_vinos) > 0 else '' | ||
| 271 | # dl_vino = dl_vinos[-1] if len(dl_vinos) > 0 else '' | ||
| 272 | # vino_list.append('{0}: {1}'.format(consts.PREFIX_MVC, mvc_vino)) | ||
| 273 | # vino_list.append(dl_vinos[-1]) | ||
| 274 | # vino = '、'.join('{0}: {1}'.format(consts.PREFIX_DL, dl_vino)) | ||
| 275 | # order_usedcar_info[consts.PCUSD_MVC[0][0]] = vino | ||
| 276 | |||
| 277 | if mvc_find is True and dl_find is False: | 264 | if mvc_find is True and dl_find is False: |
| 278 | vino = dl_vinos[0] if len(dl_vinos) > 0 else '' | 265 | vino = dl_vinos[-1] if len(dl_vinos) > 0 else '' |
| 279 | order_usedcar_info[consts.PCUSD_MVC[0][0]] = vino | 266 | order_usedcar_info[consts.PCUSD_MVC[0][0]] = '{0}-{1} {2} {3}-{4}'.format( |
| 267 | consts.PREFIX_MVC, consts.RESULT_Y, consts.SPLIT, consts.PREFIX_DL, vino) | ||
| 280 | order_usedcar_info[consts.PCUSD_MVC[0][4]] = consts.RESULT_N | 268 | order_usedcar_info[consts.PCUSD_MVC[0][4]] = consts.RESULT_N |
| 281 | elif mvc_find is False and dl_find is True: | 269 | elif mvc_find is False and dl_find is True: |
| 282 | vino = mvc_vinos[0] if len(mvc_vinos) > 0 else '' | 270 | vino = mvc_vinos[-1] if len(mvc_vinos) > 0 else '' |
| 283 | order_usedcar_info[consts.PCUSD_MVC[0][0]] = vino | 271 | order_usedcar_info[consts.PCUSD_MVC[0][0]] = '{0}-{1} {2} {3}-{4}'.format( |
| 272 | consts.PREFIX_MVC, vino, consts.SPLIT, consts.PREFIX_DL, consts.RESULT_Y) | ||
| 284 | order_usedcar_info[consts.PCUSD_MVC[0][4]] = consts.RESULT_N | 273 | order_usedcar_info[consts.PCUSD_MVC[0][4]] = consts.RESULT_N |
| 285 | elif mvc_find is False and dl_find is False: | 274 | elif mvc_find is False and dl_find is False: |
| 286 | vino_list = [] | 275 | if len(mvc_vinos) == 0 and len(dl_vinos) == 0: |
| 287 | if len(mvc_vinos) > 0: | 276 | order_usedcar_info[consts.PCUSD_MVC[0][0]] = None |
| 288 | vino_list.append(mvc_vinos[0]) | 277 | order_usedcar_info[consts.PCUSD_MVC[0][4]] = consts.RESULT_NA |
| 289 | if len(dl_vinos) > 0: | 278 | else: |
| 290 | vino_list.append(dl_vinos[0]) | 279 | mvc_vino = mvc_vinos[-1] if len(mvc_vinos) > 0 else '' |
| 291 | vino = '、'.join(vino_list) | 280 | dl_vino = dl_vinos[-1] if len(dl_vinos) > 0 else '' |
| 281 | vino = '{0}-{1} {2} {3}-{4}'.format( | ||
| 282 | consts.PREFIX_MVC, mvc_vino, consts.SPLIT, consts.PREFIX_DL, dl_vino) | ||
| 292 | order_usedcar_info[consts.PCUSD_MVC[0][0]] = vino | 283 | order_usedcar_info[consts.PCUSD_MVC[0][0]] = vino |
| 284 | order_usedcar_info[consts.PCUSD_MVC[0][4]] = consts.RESULT_N | ||
| 293 | 285 | ||
| 294 | comparison_res['OCR_Input']['usedCarInfo'] = order_usedcar_info | 286 | comparison_res['OCR_Input']['usedCarInfo'] = order_usedcar_info |
| 295 | 287 | ... | ... |
| 1 | import re | 1 | import re |
| 2 | from datetime import datetime | 2 | from datetime import datetime |
| 3 | # from .rmb_lower import rmb_handler | 3 | from .rmb_lower import rmb_handler |
| 4 | from .rmb_upper import to_rmb_upper | 4 | # from .rmb_upper import to_rmb_upper |
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | class Comparison: | 7 | class Comparison: |
| ... | @@ -109,18 +109,18 @@ class Comparison: | ... | @@ -109,18 +109,18 @@ class Comparison: |
| 109 | if ocr_str == '' or ocr_str.strip() == '': | 109 | if ocr_str == '' or ocr_str.strip() == '': |
| 110 | return self.RESULT_NA, None | 110 | return self.RESULT_NA, None |
| 111 | try: | 111 | try: |
| 112 | # ocr_lower = rmb_handler.to_rmb_lower() | 112 | ocr_lower = rmb_handler.to_rmb_lower() |
| 113 | # res = self.build_res(float(input_str) == ocr_lower) | 113 | res = self.build_res(float(input_str) == ocr_lower) |
| 114 | input_rmb_upper = to_rmb_upper(float(input_str)) | 114 | # input_rmb_upper = to_rmb_upper(float(input_str)) |
| 115 | res = self.build_res(input_rmb_upper == ocr_str) | 115 | # res = self.build_res(input_rmb_upper == ocr_str) |
| 116 | except Exception as e: | 116 | except Exception as e: |
| 117 | return self.RESULT_N, None | 117 | return self.RESULT_N, None |
| 118 | else: | 118 | else: |
| 119 | if res == self.RESULT_Y: | 119 | if res == self.RESULT_Y: |
| 120 | return res, input_str | 120 | return res, input_str |
| 121 | else: | 121 | else: |
| 122 | # return res, ocr_lower | 122 | return res, ocr_lower |
| 123 | return res, None | 123 | # return res, None |
| 124 | 124 | ||
| 125 | def type_compare(self, input_str, ocr_str, idx, **kwargs): | 125 | def type_compare(self, input_str, ocr_str, idx, **kwargs): |
| 126 | if not isinstance(ocr_str, str) or not isinstance(input_str, str): | 126 | if not isinstance(ocr_str, str) or not isinstance(input_str, str): | ... | ... |
-
Please register or sign in to post a comment