fix gcap bug
Showing
4 changed files
with
142 additions
and
19 deletions
... | @@ -1048,6 +1048,7 @@ ITPRC = [ | ... | @@ -1048,6 +1048,7 @@ ITPRC = [ |
1048 | ('idNum', '公民身份号码', 'common_compare', {}), | 1048 | ('idNum', '公民身份号码', 'common_compare', {}), |
1049 | # 20200410-20250410 OCR识别为长期,向GCAP发送:2099-12-31 00:00:00.0 | 1049 | # 20200410-20250410 OCR识别为长期,向GCAP发送:2099-12-31 00:00:00.0 |
1050 | ('idExpiryDate', '有效期限', 'date_compare', {'long': True, 'ocr_split': True, 'input_replace': ''}), | 1050 | ('idExpiryDate', '有效期限', 'date_compare', {'long': True, 'ocr_split': True, 'input_replace': ''}), |
1051 | ('dateOfBirth', '出生年月', 'date_compare', {'input_replace': ''}), # 20231023 | ||
1051 | ] | 1052 | ] |
1052 | 1053 | ||
1053 | # 护照 | 1054 | # 护照 |
... | @@ -1064,15 +1065,15 @@ ITHKM_ITTID = [ | ... | @@ -1064,15 +1065,15 @@ ITHKM_ITTID = [ |
1064 | ('idNum', '证件号码', 'common_compare', {}), | 1065 | ('idNum', '证件号码', 'common_compare', {}), |
1065 | ('idExpiryDate', '有效期限', 'date_compare', {'ocr_split': True, 'input_replace': '.'}), # 2013.10.24-2023.10.23 | 1066 | ('idExpiryDate', '有效期限', 'date_compare', {'ocr_split': True, 'input_replace': '.'}), # 2013.10.24-2023.10.23 |
1066 | ('dateOfBirth', '出生日期', 'date_compare', {'input_replace': '.'}), # 2023.10.23 | 1067 | ('dateOfBirth', '出生日期', 'date_compare', {'input_replace': '.'}), # 2023.10.23 |
1067 | # 'secondIdNum': '' | ||
1068 | ] | 1068 | ] |
1069 | 1069 | ||
1070 | # 居住证 | 1070 | # 居住证 |
1071 | ITRES = [ | 1071 | ITRES = [ |
1072 | ('customerChineseName', '姓名', 'common_compare', {}), | 1072 | ('customerChineseName', '姓名', 'common_compare', {}), |
1073 | ('idNum', '公民身份号码', 'common_compare', {}), | 1073 | ('idNum', '公民身份号码', 'common_compare', {}), |
1074 | ('secondIdNum', '通行证号码', 'common_compare', {}), | ||
1074 | ('idExpiryDate', '有效期限', 'date_compare', {'ocr_split': True, 'input_replace': ''}), # 20200410-20250410 | 1075 | ('idExpiryDate', '有效期限', 'date_compare', {'ocr_split': True, 'input_replace': ''}), # 20200410-20250410 |
1075 | ('secondIdNum', '通行证号码', 'common_compare', {}) | 1076 | ('dateOfBirth', '出生年月', 'date_compare', {'input_replace': ''}), # 20231023 |
1076 | ] | 1077 | ] |
1077 | 1078 | ||
1078 | ID_TYPE_COMPARE = { | 1079 | ID_TYPE_COMPARE = { |
... | @@ -1127,6 +1128,11 @@ RESULT_Y = 'Y' | ... | @@ -1127,6 +1128,11 @@ RESULT_Y = 'Y' |
1127 | RESULT_N = 'N' | 1128 | RESULT_N = 'N' |
1128 | RESULT_NA = 'NA' | 1129 | RESULT_NA = 'NA' |
1129 | 1130 | ||
1131 | IN_ORDER = ('applicantType', 'idType', 'secondIdType', 'customerType', 'customerChineseName', 'idNum', 'secondIdNum', | ||
1132 | "idExpiryDate", "dateOfBirth", 'companyName', "registeredCapital", 'selfEmployedSubType',) | ||
1133 | UC_ORDER = ('vinNo', 'manufactureDate', 'firstRegistrationDate') | ||
1134 | CO_ORDER = ('customerChineseName', 'legalRepName', 'idNum', 'businessLicenseNo', 'taxRegistrationCode', | ||
1135 | 'incorporationDate', 'businessLicenseDueDate', 'capitalRegAmount') | ||
1130 | 1136 | ||
1131 | 1137 | ||
1132 | 1138 | ... | ... |
... | @@ -4,6 +4,7 @@ from settings import conf | ... | @@ -4,6 +4,7 @@ from settings import conf |
4 | from common.tools.dict_to_xml import dicttoxml, escape_xml | 4 | from common.tools.dict_to_xml import dicttoxml, escape_xml |
5 | from apps.doc import consts | 5 | from apps.doc import consts |
6 | from apps.doc.exceptions import GCAPException | 6 | from apps.doc.exceptions import GCAPException |
7 | from collections import OrderedDict | ||
7 | 8 | ||
8 | 9 | ||
9 | class GCAP: | 10 | class GCAP: |
... | @@ -24,6 +25,106 @@ class GCAP: | ... | @@ -24,6 +25,106 @@ class GCAP: |
24 | response = requests.post(self.url, headers=self.headers, data=data, verify=False, auth=self.auth) | 25 | response = requests.post(self.url, headers=self.headers, data=data, verify=False, auth=self.auth) |
25 | if response.status_code != 200: | 26 | if response.status_code != 200: |
26 | raise GCAPException('GCAP response with code: {0}'.format(response.status_code)) | 27 | raise GCAPException('GCAP response with code: {0}'.format(response.status_code)) |
28 | return response.status_code | ||
29 | |||
30 | def test_send(self): | ||
31 | test_res = OrderedDict({ | ||
32 | 'OCR_Input': { | ||
33 | 'uniqSeq': '201809301905121000', | ||
34 | 'applicationId': 'CH-B000046340', | ||
35 | 'applicationEntity': 'AFC', | ||
36 | 'applicationVersion': 3, | ||
37 | 'vehicleStatus': 'PCNEW', | ||
38 | 'wholeResult': 'Y', | ||
39 | 'wholeResultMessage': 'msg', | ||
40 | 'applicationLink': 'url1', | ||
41 | 'individualCusInfo': [ | ||
42 | { | ||
43 | 'applicantType': 'COAPP', | ||
44 | 'idType': 'ITARI', | ||
45 | 'customerType': 'TCDAS', | ||
46 | 'customerChineseName': 'co-app-name', | ||
47 | 'idNum': 'idNum', | ||
48 | 'idExpiryDate': '2020-02-02T15:52:18.1049637+08:00', | ||
49 | 'dateOfBirth': '2020-02-02T15:52:18.1049637+08:00', | ||
50 | 'registeredCapital': '20192', | ||
51 | 'customerChineseNameResult': 'Y', | ||
52 | 'idNumResult': 'Y', | ||
53 | 'secondIdNumResult': 'Y', | ||
54 | 'idExpiryDateResult': 'Y', | ||
55 | 'dateOfBirthResult': 'Y', | ||
56 | 'companyNameResult': 'Y', | ||
57 | 'registeredCapitalResult': 'Y', | ||
58 | 'selfEmployedSubTypeResult': 'Y', | ||
59 | }, | ||
60 | { | ||
61 | 'applicantType': 'GAUTR1', | ||
62 | 'idType': 'ITPSP', | ||
63 | 'customerType': 'TCDAS', | ||
64 | 'customerChineseName': 'ga1-name', | ||
65 | 'idNum': 'id3', | ||
66 | 'idExpiryDate': '2020-03-03T15:52:18.1049637+08:00', | ||
67 | 'dateOfBirth': '2020-03-03T15:52:18.1049637+08:00', | ||
68 | 'registeredCapital': '20193', | ||
69 | 'customerChineseNameResult': 'Y', | ||
70 | 'idNumResult': 'Y', | ||
71 | 'secondIdNumResult': 'Y', | ||
72 | 'idExpiryDateResult': 'Y', | ||
73 | 'dateOfBirthResult': 'Y', | ||
74 | 'companyNameResult': 'Y', | ||
75 | 'registeredCapitalResult': 'Y', | ||
76 | 'selfEmployedSubTypeResult': 'Y', | ||
77 | }, | ||
78 | { | ||
79 | 'applicantType': 'GAUTR2', | ||
80 | 'idType': 'ITHKM', | ||
81 | 'customerType': 'TCDAS', | ||
82 | 'customerChineseName': 'ga2-name', | ||
83 | 'idNum': 'id4', | ||
84 | 'idExpiryDate': '2020-04-04T15:52:18.1049637+08:00', | ||
85 | 'dateOfBirth': '2020-04-04T15:52:18.1049637+08:00', | ||
86 | 'registeredCapital': '20194', | ||
87 | 'customerChineseNameResult': 'Y', | ||
88 | 'idNumResult': 'Y', | ||
89 | 'secondIdNumResult': 'Y', | ||
90 | 'idExpiryDateResult': 'Y', | ||
91 | 'dateOfBirthResult': 'Y', | ||
92 | 'companyNameResult': 'Y', | ||
93 | 'registeredCapitalResult': 'Y', | ||
94 | 'selfEmployedSubTypeResult': 'Y', | ||
95 | }, | ||
96 | ], | ||
97 | 'usedCarInfo': { | ||
98 | 'vinNo': 'LBVSFJSDLFJLSDJF', | ||
99 | 'manufactureDate': '2020-09-03T15:52:18.1049637+08:00', | ||
100 | 'firstRegistrationDate': '2020-09-03T15:52:18.1049637+08:00', | ||
101 | 'vinNoResult': 'Y', | ||
102 | 'manufactureDateResult': 'Y', | ||
103 | 'firstRegistrationDateResult': 'Y', | ||
104 | }, | ||
105 | 'corporateCusInfo': { | ||
106 | 'customerChineseName': '北京思图场景数据科技服务有限公司', | ||
107 | 'legalRepName': '李六', | ||
108 | 'idNum': 'MA007438143XJ1P', | ||
109 | 'customerType': 'TCCOR', | ||
110 | 'businessLicenseNo': 'MA007438143XJ1P', | ||
111 | 'taxRegistrationCode': 'MA007438143XJ1P', | ||
112 | 'incorporationDate': '2020-09-02T15:52:18.1049637+08:00', | ||
113 | 'businessLicenseDueDate': '2020-09-02T15:52:18.1049637+08:00', | ||
114 | 'capitalRegAmount': '60000000', | ||
115 | 'customerChinessNameResult': 'Y', | ||
116 | 'legalRepNameResult': 'Y', | ||
117 | 'idNumResult': 'Y', | ||
118 | 'businessLicenseNoResult': 'Y', | ||
119 | 'taxRegistrationCodeResult': 'Y', | ||
120 | 'incorporationDateResult': 'Y', | ||
121 | 'businessLicenseDueDateResult': 'Y', | ||
122 | 'capitalRegAmountResult': 'Y', | ||
123 | } | ||
124 | } | ||
125 | }) | ||
126 | status_code = self.send(self.dict_to_xml(test_res)) | ||
127 | print(status_code) | ||
27 | 128 | ||
28 | 129 | ||
29 | gcap = GCAP() | 130 | gcap = GCAP() | ... | ... |
1 | import json | 1 | import json |
2 | import logging | 2 | import logging |
3 | import traceback | 3 | import traceback |
4 | from collections import OrderedDict | ||
4 | from . import app | 5 | from . import app |
5 | from apps.doc.models import AFCOCRResult, HILOCRResult, AFCComparisonInfo, HILComparisonInfo | 6 | from apps.doc.models import AFCOCRResult, HILOCRResult, AFCComparisonInfo, HILComparisonInfo |
6 | from apps.doc import consts | 7 | from apps.doc import consts |
... | @@ -12,6 +13,15 @@ compare_log = logging.getLogger('compare') | ... | @@ -12,6 +13,15 @@ compare_log = logging.getLogger('compare') |
12 | log_base = '[CA Compare]' | 13 | log_base = '[CA Compare]' |
13 | 14 | ||
14 | 15 | ||
16 | def get_order_dict(src_dict, order_tuple): | ||
17 | order_dict = OrderedDict({}) | ||
18 | for field in order_tuple: | ||
19 | value = src_dict.get(field) | ||
20 | if value is not None: | ||
21 | order_dict[field] = value | ||
22 | return order_dict | ||
23 | |||
24 | |||
15 | def field_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set): | 25 | def field_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set): |
16 | is_find = False | 26 | is_find = False |
17 | ocr_res_str = ocr_res_dict.get(ocr_field) | 27 | ocr_res_str = ocr_res_dict.get(ocr_field) |
... | @@ -65,7 +75,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): | ... | @@ -65,7 +75,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): |
65 | 75 | ||
66 | # 比对信息 | 76 | # 比对信息 |
67 | try: | 77 | try: |
68 | comparison_res = { | 78 | comparison_res = OrderedDict({ |
69 | 'OCR_Input': { | 79 | 'OCR_Input': { |
70 | 'uniqSeq': last_obj.uniq_seq, | 80 | 'uniqSeq': last_obj.uniq_seq, |
71 | 'applicationId': application_id, | 81 | 'applicationId': application_id, |
... | @@ -76,42 +86,48 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): | ... | @@ -76,42 +86,48 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): |
76 | 'wholeResultMessage': '', | 86 | 'wholeResultMessage': '', |
77 | 'applicationLink': '', | 87 | 'applicationLink': '', |
78 | } | 88 | } |
79 | } | 89 | }) |
80 | 90 | ||
81 | res_set = set() | 91 | res_set = set() |
82 | 92 | ||
83 | is_sep = True if last_obj.customer_type == consts.CUSTOMER_TYPE[5] else False | 93 | is_sep = True if last_obj.customer_type == consts.CUSTOMER_TYPE[5] else False |
84 | 94 | ||
85 | individual_cus_info_list = json.loads(last_obj.individual_cus_info) | 95 | individual_cus_info_list = json.loads(last_obj.individual_cus_info) |
96 | order_individual_cus_info_list = [] | ||
86 | for individual_cus_info in individual_cus_info_list: | 97 | for individual_cus_info in individual_cus_info_list: |
98 | order_individual_cus_info = get_order_dict(individual_cus_info, consts.IN_ORDER) | ||
87 | # sep营业执照 | 99 | # sep营业执照 |
88 | if is_sep and individual_cus_info.get('companyName') is not None: | 100 | if is_sep and order_individual_cus_info.get('companyName') is not None: |
89 | field_compare(individual_cus_info, ocr_res_dict, consts.BL_OCR_FIELD, consts.TCSEP, res_set) | 101 | field_compare(order_individual_cus_info, ocr_res_dict, consts.BL_OCR_FIELD, consts.TCSEP, res_set) |
90 | 102 | ||
91 | # 个人信息证件 | 103 | # 个人信息证件 |
92 | id_type = individual_cus_info.get('idType') | 104 | id_type = order_individual_cus_info.get('idType') |
93 | compare_info_list = consts.ID_TYPE_COMPARE.get(id_type) | 105 | compare_info_list = consts.ID_TYPE_COMPARE.get(id_type) |
94 | if compare_info_list is None: | 106 | if compare_info_list is None: |
95 | continue | 107 | continue |
96 | field_compare(individual_cus_info, ocr_res_dict, compare_info_list[0], compare_info_list[1], res_set) | 108 | field_compare(order_individual_cus_info, ocr_res_dict, compare_info_list[0], compare_info_list[1], res_set) |
97 | |||
98 | comparison_res['OCR_Input']['individualCusInfo'] = individual_cus_info_list | ||
99 | 109 | ||
100 | if last_obj.corporate_cus_info is not None: | 110 | order_individual_cus_info_list.append(order_individual_cus_info) |
101 | corporate_cus_info = json.loads(last_obj.corporate_cus_info) | ||
102 | field_compare(corporate_cus_info, ocr_res_dict, consts.BL_OCR_FIELD, consts.TCCOR, res_set) | ||
103 | 111 | ||
104 | comparison_res['OCR_Input']['corporateCusInfo'] = corporate_cus_info | 112 | comparison_res['OCR_Input']['individualCusInfo'] = order_individual_cus_info_list |
105 | 113 | ||
106 | if last_obj.vehicle_status == consts.VEHICLE_STATUS[0] and last_obj.usedcar_info is not None: | 114 | if last_obj.vehicle_status == consts.VEHICLE_STATUS[0] and last_obj.usedcar_info is not None: |
107 | usedcar_info = json.loads(last_obj.usedcar_info) | 115 | usedcar_info = json.loads(last_obj.usedcar_info) |
116 | order_usedcar_info = get_order_dict(usedcar_info, consts.UC_ORDER) | ||
108 | 117 | ||
109 | field_compare(usedcar_info, ocr_res_dict, consts.MVC_OCR_FIELD, consts.PCUSD_MVC, res_set) | 118 | field_compare(order_usedcar_info, ocr_res_dict, consts.MVC_OCR_FIELD, consts.PCUSD_MVC, res_set) |
110 | 119 | ||
111 | if usedcar_info[consts.PCUSD_MVC[0][0] + 'Result'] == consts.RESULT_Y: | 120 | if order_usedcar_info[consts.PCUSD_MVC[0][0] + 'Result'] == consts.RESULT_Y: |
112 | field_compare(usedcar_info, ocr_res_dict, consts.DL_OCR_FIELD, consts.PCUSD_DL, res_set) | 121 | field_compare(order_usedcar_info, ocr_res_dict, consts.DL_OCR_FIELD, consts.PCUSD_DL, res_set) |
122 | |||
123 | comparison_res['OCR_Input']['usedCarInfo'] = order_usedcar_info | ||
124 | |||
125 | if last_obj.corporate_cus_info is not None: | ||
126 | corporate_cus_info = json.loads(last_obj.corporate_cus_info) | ||
127 | order_corporate_cus_info = get_order_dict(corporate_cus_info, consts.CO_ORDER) | ||
128 | field_compare(order_corporate_cus_info, ocr_res_dict, consts.BL_OCR_FIELD, consts.TCCOR, res_set) | ||
113 | 129 | ||
114 | comparison_res['OCR_Input']['usedCarInfo'] = usedcar_info | 130 | comparison_res['OCR_Input']['corporateCusInfo'] = order_corporate_cus_info |
115 | 131 | ||
116 | comparison_res['OCR_Input']['wholeResult'] = consts.RESULT_N if consts.RESULT_N in res_set else consts.RESULT_Y | 132 | comparison_res['OCR_Input']['wholeResult'] = consts.RESULT_N if consts.RESULT_N in res_set else consts.RESULT_Y |
117 | 133 | ... | ... |
... | @@ -7,7 +7,7 @@ Supports item (`int`, `float`, `long`, `decimal.Decimal`, `bool`, `str`, `unicod | ... | @@ -7,7 +7,7 @@ Supports item (`int`, `float`, `long`, `decimal.Decimal`, `bool`, `str`, `unicod |
7 | This module works with both Python 2 and 3. | 7 | This module works with both Python 2 and 3. |
8 | """ | 8 | """ |
9 | 9 | ||
10 | from __future__ import unicode_literals | 10 | # from __future__ import unicode_literals |
11 | 11 | ||
12 | from random import randint | 12 | from random import randint |
13 | import collections | 13 | import collections | ... | ... |
-
Please register or sign in to post a comment