Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
6f8d522c
authored
2021-04-02 12:42:40 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix gcap bug
1 parent
867f6a13
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
142 additions
and
19 deletions
src/apps/doc/consts.py
src/apps/doc/ocr/gcap.py
src/celery_compare/tasks.py
src/common/tools/dict_to_xml.py
src/apps/doc/consts.py
View file @
6f8d522
...
...
@@ -1048,6 +1048,7 @@ ITPRC = [
(
'idNum'
,
'公民身份号码'
,
'common_compare'
,
{}),
# 20200410-20250410 OCR识别为长期,向GCAP发送:2099-12-31 00:00:00.0
(
'idExpiryDate'
,
'有效期限'
,
'date_compare'
,
{
'long'
:
True
,
'ocr_split'
:
True
,
'input_replace'
:
''
}),
(
'dateOfBirth'
,
'出生年月'
,
'date_compare'
,
{
'input_replace'
:
''
}),
# 20231023
]
# 护照
...
...
@@ -1064,15 +1065,15 @@ ITHKM_ITTID = [
(
'idNum'
,
'证件号码'
,
'common_compare'
,
{}),
(
'idExpiryDate'
,
'有效期限'
,
'date_compare'
,
{
'ocr_split'
:
True
,
'input_replace'
:
'.'
}),
# 2013.10.24-2023.10.23
(
'dateOfBirth'
,
'出生日期'
,
'date_compare'
,
{
'input_replace'
:
'.'
}),
# 2023.10.23
# 'secondIdNum': ''
]
# 居住证
ITRES
=
[
(
'customerChineseName'
,
'姓名'
,
'common_compare'
,
{}),
(
'idNum'
,
'公民身份号码'
,
'common_compare'
,
{}),
(
'secondIdNum'
,
'通行证号码'
,
'common_compare'
,
{}),
(
'idExpiryDate'
,
'有效期限'
,
'date_compare'
,
{
'ocr_split'
:
True
,
'input_replace'
:
''
}),
# 20200410-20250410
(
'
secondIdNum'
,
'通行证号码'
,
'common_compare'
,
{})
(
'
dateOfBirth'
,
'出生年月'
,
'date_compare'
,
{
'input_replace'
:
''
}),
# 20231023
]
ID_TYPE_COMPARE
=
{
...
...
@@ -1127,6 +1128,11 @@ RESULT_Y = 'Y'
RESULT_N
=
'N'
RESULT_NA
=
'NA'
IN_ORDER
=
(
'applicantType'
,
'idType'
,
'secondIdType'
,
'customerType'
,
'customerChineseName'
,
'idNum'
,
'secondIdNum'
,
"idExpiryDate"
,
"dateOfBirth"
,
'companyName'
,
"registeredCapital"
,
'selfEmployedSubType'
,)
UC_ORDER
=
(
'vinNo'
,
'manufactureDate'
,
'firstRegistrationDate'
)
CO_ORDER
=
(
'customerChineseName'
,
'legalRepName'
,
'idNum'
,
'businessLicenseNo'
,
'taxRegistrationCode'
,
'incorporationDate'
,
'businessLicenseDueDate'
,
'capitalRegAmount'
)
...
...
src/apps/doc/ocr/gcap.py
View file @
6f8d522
...
...
@@ -4,6 +4,7 @@ from settings import conf
from
common.tools.dict_to_xml
import
dicttoxml
,
escape_xml
from
apps.doc
import
consts
from
apps.doc.exceptions
import
GCAPException
from
collections
import
OrderedDict
class
GCAP
:
...
...
@@ -24,6 +25,106 @@ class GCAP:
response
=
requests
.
post
(
self
.
url
,
headers
=
self
.
headers
,
data
=
data
,
verify
=
False
,
auth
=
self
.
auth
)
if
response
.
status_code
!=
200
:
raise
GCAPException
(
'GCAP response with code: {0}'
.
format
(
response
.
status_code
))
return
response
.
status_code
def
test_send
(
self
):
test_res
=
OrderedDict
({
'OCR_Input'
:
{
'uniqSeq'
:
'201809301905121000'
,
'applicationId'
:
'CH-B000046340'
,
'applicationEntity'
:
'AFC'
,
'applicationVersion'
:
3
,
'vehicleStatus'
:
'PCNEW'
,
'wholeResult'
:
'Y'
,
'wholeResultMessage'
:
'msg'
,
'applicationLink'
:
'url1'
,
'individualCusInfo'
:
[
{
'applicantType'
:
'COAPP'
,
'idType'
:
'ITARI'
,
'customerType'
:
'TCDAS'
,
'customerChineseName'
:
'co-app-name'
,
'idNum'
:
'idNum'
,
'idExpiryDate'
:
'2020-02-02T15:52:18.1049637+08:00'
,
'dateOfBirth'
:
'2020-02-02T15:52:18.1049637+08:00'
,
'registeredCapital'
:
'20192'
,
'customerChineseNameResult'
:
'Y'
,
'idNumResult'
:
'Y'
,
'secondIdNumResult'
:
'Y'
,
'idExpiryDateResult'
:
'Y'
,
'dateOfBirthResult'
:
'Y'
,
'companyNameResult'
:
'Y'
,
'registeredCapitalResult'
:
'Y'
,
'selfEmployedSubTypeResult'
:
'Y'
,
},
{
'applicantType'
:
'GAUTR1'
,
'idType'
:
'ITPSP'
,
'customerType'
:
'TCDAS'
,
'customerChineseName'
:
'ga1-name'
,
'idNum'
:
'id3'
,
'idExpiryDate'
:
'2020-03-03T15:52:18.1049637+08:00'
,
'dateOfBirth'
:
'2020-03-03T15:52:18.1049637+08:00'
,
'registeredCapital'
:
'20193'
,
'customerChineseNameResult'
:
'Y'
,
'idNumResult'
:
'Y'
,
'secondIdNumResult'
:
'Y'
,
'idExpiryDateResult'
:
'Y'
,
'dateOfBirthResult'
:
'Y'
,
'companyNameResult'
:
'Y'
,
'registeredCapitalResult'
:
'Y'
,
'selfEmployedSubTypeResult'
:
'Y'
,
},
{
'applicantType'
:
'GAUTR2'
,
'idType'
:
'ITHKM'
,
'customerType'
:
'TCDAS'
,
'customerChineseName'
:
'ga2-name'
,
'idNum'
:
'id4'
,
'idExpiryDate'
:
'2020-04-04T15:52:18.1049637+08:00'
,
'dateOfBirth'
:
'2020-04-04T15:52:18.1049637+08:00'
,
'registeredCapital'
:
'20194'
,
'customerChineseNameResult'
:
'Y'
,
'idNumResult'
:
'Y'
,
'secondIdNumResult'
:
'Y'
,
'idExpiryDateResult'
:
'Y'
,
'dateOfBirthResult'
:
'Y'
,
'companyNameResult'
:
'Y'
,
'registeredCapitalResult'
:
'Y'
,
'selfEmployedSubTypeResult'
:
'Y'
,
},
],
'usedCarInfo'
:
{
'vinNo'
:
'LBVSFJSDLFJLSDJF'
,
'manufactureDate'
:
'2020-09-03T15:52:18.1049637+08:00'
,
'firstRegistrationDate'
:
'2020-09-03T15:52:18.1049637+08:00'
,
'vinNoResult'
:
'Y'
,
'manufactureDateResult'
:
'Y'
,
'firstRegistrationDateResult'
:
'Y'
,
},
'corporateCusInfo'
:
{
'customerChineseName'
:
'北京思图场景数据科技服务有限公司'
,
'legalRepName'
:
'李六'
,
'idNum'
:
'MA007438143XJ1P'
,
'customerType'
:
'TCCOR'
,
'businessLicenseNo'
:
'MA007438143XJ1P'
,
'taxRegistrationCode'
:
'MA007438143XJ1P'
,
'incorporationDate'
:
'2020-09-02T15:52:18.1049637+08:00'
,
'businessLicenseDueDate'
:
'2020-09-02T15:52:18.1049637+08:00'
,
'capitalRegAmount'
:
'60000000'
,
'customerChinessNameResult'
:
'Y'
,
'legalRepNameResult'
:
'Y'
,
'idNumResult'
:
'Y'
,
'businessLicenseNoResult'
:
'Y'
,
'taxRegistrationCodeResult'
:
'Y'
,
'incorporationDateResult'
:
'Y'
,
'businessLicenseDueDateResult'
:
'Y'
,
'capitalRegAmountResult'
:
'Y'
,
}
}
})
status_code
=
self
.
send
(
self
.
dict_to_xml
(
test_res
))
print
(
status_code
)
gcap
=
GCAP
()
...
...
src/celery_compare/tasks.py
View file @
6f8d522
import
json
import
logging
import
traceback
from
collections
import
OrderedDict
from
.
import
app
from
apps.doc.models
import
AFCOCRResult
,
HILOCRResult
,
AFCComparisonInfo
,
HILComparisonInfo
from
apps.doc
import
consts
...
...
@@ -12,6 +13,15 @@ compare_log = logging.getLogger('compare')
log_base
=
'[CA Compare]'
def
get_order_dict
(
src_dict
,
order_tuple
):
order_dict
=
OrderedDict
({})
for
field
in
order_tuple
:
value
=
src_dict
.
get
(
field
)
if
value
is
not
None
:
order_dict
[
field
]
=
value
return
order_dict
def
field_compare
(
info_dict
,
ocr_res_dict
,
ocr_field
,
compare_list
,
res_set
):
is_find
=
False
ocr_res_str
=
ocr_res_dict
.
get
(
ocr_field
)
...
...
@@ -65,7 +75,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id):
# 比对信息
try
:
comparison_res
=
{
comparison_res
=
OrderedDict
(
{
'OCR_Input'
:
{
'uniqSeq'
:
last_obj
.
uniq_seq
,
'applicationId'
:
application_id
,
...
...
@@ -76,42 +86,48 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id):
'wholeResultMessage'
:
''
,
'applicationLink'
:
''
,
}
}
}
)
res_set
=
set
()
is_sep
=
True
if
last_obj
.
customer_type
==
consts
.
CUSTOMER_TYPE
[
5
]
else
False
individual_cus_info_list
=
json
.
loads
(
last_obj
.
individual_cus_info
)
order_individual_cus_info_list
=
[]
for
individual_cus_info
in
individual_cus_info_list
:
order_individual_cus_info
=
get_order_dict
(
individual_cus_info
,
consts
.
IN_ORDER
)
# sep营业执照
if
is_sep
and
individual_cus_info
.
get
(
'companyName'
)
is
not
None
:
field_compare
(
individual_cus_info
,
ocr_res_dict
,
consts
.
BL_OCR_FIELD
,
consts
.
TCSEP
,
res_set
)
if
is_sep
and
order_
individual_cus_info
.
get
(
'companyName'
)
is
not
None
:
field_compare
(
order_
individual_cus_info
,
ocr_res_dict
,
consts
.
BL_OCR_FIELD
,
consts
.
TCSEP
,
res_set
)
# 个人信息证件
id_type
=
individual_cus_info
.
get
(
'idType'
)
id_type
=
order_
individual_cus_info
.
get
(
'idType'
)
compare_info_list
=
consts
.
ID_TYPE_COMPARE
.
get
(
id_type
)
if
compare_info_list
is
None
:
continue
field_compare
(
individual_cus_info
,
ocr_res_dict
,
compare_info_list
[
0
],
compare_info_list
[
1
],
res_set
)
comparison_res
[
'OCR_Input'
][
'individualCusInfo'
]
=
individual_cus_info_list
field_compare
(
order_individual_cus_info
,
ocr_res_dict
,
compare_info_list
[
0
],
compare_info_list
[
1
],
res_set
)
if
last_obj
.
corporate_cus_info
is
not
None
:
corporate_cus_info
=
json
.
loads
(
last_obj
.
corporate_cus_info
)
field_compare
(
corporate_cus_info
,
ocr_res_dict
,
consts
.
BL_OCR_FIELD
,
consts
.
TCCOR
,
res_set
)
order_individual_cus_info_list
.
append
(
order_individual_cus_info
)
comparison_res
[
'OCR_Input'
][
'corporateCusInfo'
]
=
corporate_cus_info
comparison_res
[
'OCR_Input'
][
'individualCusInfo'
]
=
order_individual_cus_info_list
if
last_obj
.
vehicle_status
==
consts
.
VEHICLE_STATUS
[
0
]
and
last_obj
.
usedcar_info
is
not
None
:
usedcar_info
=
json
.
loads
(
last_obj
.
usedcar_info
)
order_usedcar_info
=
get_order_dict
(
usedcar_info
,
consts
.
UC_ORDER
)
field_compare
(
usedcar_info
,
ocr_res_dict
,
consts
.
MVC_OCR_FIELD
,
consts
.
PCUSD_MVC
,
res_set
)
field_compare
(
order_
usedcar_info
,
ocr_res_dict
,
consts
.
MVC_OCR_FIELD
,
consts
.
PCUSD_MVC
,
res_set
)
if
usedcar_info
[
consts
.
PCUSD_MVC
[
0
][
0
]
+
'Result'
]
==
consts
.
RESULT_Y
:
field_compare
(
usedcar_info
,
ocr_res_dict
,
consts
.
DL_OCR_FIELD
,
consts
.
PCUSD_DL
,
res_set
)
if
order_usedcar_info
[
consts
.
PCUSD_MVC
[
0
][
0
]
+
'Result'
]
==
consts
.
RESULT_Y
:
field_compare
(
order_usedcar_info
,
ocr_res_dict
,
consts
.
DL_OCR_FIELD
,
consts
.
PCUSD_DL
,
res_set
)
comparison_res
[
'OCR_Input'
][
'usedCarInfo'
]
=
order_usedcar_info
if
last_obj
.
corporate_cus_info
is
not
None
:
corporate_cus_info
=
json
.
loads
(
last_obj
.
corporate_cus_info
)
order_corporate_cus_info
=
get_order_dict
(
corporate_cus_info
,
consts
.
CO_ORDER
)
field_compare
(
order_corporate_cus_info
,
ocr_res_dict
,
consts
.
BL_OCR_FIELD
,
consts
.
TCCOR
,
res_set
)
comparison_res
[
'OCR_Input'
][
'
usedCarInfo'
]
=
usedcar
_info
comparison_res
[
'OCR_Input'
][
'
corporateCusInfo'
]
=
order_corporate_cus
_info
comparison_res
[
'OCR_Input'
][
'wholeResult'
]
=
consts
.
RESULT_N
if
consts
.
RESULT_N
in
res_set
else
consts
.
RESULT_Y
...
...
src/common/tools/dict_to_xml.py
View file @
6f8d522
...
...
@@ -7,7 +7,7 @@ Supports item (`int`, `float`, `long`, `decimal.Decimal`, `bool`, `str`, `unicod
This module works with both Python 2 and 3.
"""
from
__future__
import
unicode_literals
#
from __future__ import unicode_literals
from
random
import
randint
import
collections
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment