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
0c6d8799
authored
2022-01-14 10:38:19 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add MPOS
1 parent
e914ba66
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
114 additions
and
3 deletions
src/apps/doc/consts.py
src/apps/doc/mixins.py
src/apps/doc/mpos_urls.py
src/apps/doc/views.py
src/apps/urls.py
src/celery_compare/tasks.py
src/apps/doc/consts.py
View file @
0c6d879
...
...
@@ -1407,6 +1407,7 @@ SE_USED_FIELD = ['vinNo', 'vehicleTransactionAmount']
SE_NEW_ADD_FIELD
=
[
'customerName'
,
'idNum'
,
'dateOfInvoice'
,
'stamp'
,
'发票联'
,
'发票真伪校验'
,
'新旧版式'
]
SE_FPL_VALUE
=
'发票联'
SE_STAMP_VALUE
=
'有'
SE_DYSYR_VALUE
=
'无'
SE_LAYOUT_VALUE
=
'旧版-旧打印、新版-新打印'
SE_GB_NEW_FIELD
=
[
'vinNo'
]
SE_GB_USED_FIELD
=
[
'customerName'
,
'idNum'
,
'date'
]
...
...
@@ -2226,3 +2227,8 @@ AUTO_WB_FIELD = (
'rpa_get_case_from_ocr_time'
,
'rpa_get_case_from_oc_time'
,
'rpa_payment_authorize_time'
,
'rpa_second_eye_time'
)
)
MPOS_MAP
=
{
IC_CLASSIFY
,
BC_CLASSIFY
,
BL_CLASSIFY
,
}
...
...
src/apps/doc/mixins.py
View file @
0c6d879
import
re
import
json
import
requests
from
.named_enum
import
DocStatus
from
.models
import
HILDoc
,
AFCDoc
from
.
import
consts
class
MPOSHandler
:
@staticmethod
def
ocr1_process
(
url
,
img_base64
):
result_list
=
[]
json_data
=
{
"file"
:
img_base64
,
}
ocr_1_response
=
requests
.
post
(
url
,
json
=
json_data
)
if
ocr_1_response
.
status_code
!=
200
:
return
result_list
ocr_1_res
=
ocr_1_response
.
json
()
for
ocr_data
in
ocr_1_res
.
get
(
'data'
,
[]):
license_data
=
ocr_data
.
get
(
'data'
)
if
not
license_data
:
continue
if
isinstance
(
license_data
,
dict
):
license_data
.
pop
(
'base64_img'
,
''
)
id_card_dict
=
{}
card_type
=
license_data
.
get
(
'type'
,
''
)
is_ic
=
card_type
.
startswith
(
'身份证'
)
is_info_side
=
card_type
.
endswith
(
'信息面'
)
# id_card_dict['类别'] = '0' if is_ic else '1'
if
is_ic
:
field_map
=
consts
.
IC_MAP_0
if
is_info_side
else
consts
.
IC_MAP_1
else
:
field_map
=
consts
.
RP_MAP_0
if
is_info_side
else
consts
.
RP_MAP_1
for
write_field
,
search_field
in
field_map
:
id_card_dict
[
write_field
]
=
license_data
.
get
(
'words_result'
,
{})
.
get
(
search_field
,
{})
.
get
(
'words'
,
''
)
if
not
is_info_side
:
start_time
=
license_data
.
get
(
'words_result'
,
{})
.
get
(
'签发日期'
,
{})
.
get
(
'words'
,
''
)
end_time
=
license_data
.
get
(
'words_result'
,
{})
.
get
(
'失效日期'
,
{})
.
get
(
'words'
,
''
)
id_card_dict
[
'有效期限'
]
=
'{0}-{1}'
.
format
(
start_time
,
end_time
)
result_list
.
append
(
id_card_dict
)
return
result_list
@staticmethod
def
ocr2_process
(
url
,
classify
,
img_base64
):
result_list
=
[]
pid
,
_
,
_
,
_
,
_
,
_
=
consts
.
LICENSE_CLASSIFY_MAPPING
.
get
(
classify
)
json_data_2
=
{
"pid"
:
str
(
pid
),
"filedata"
:
img_base64
}
ocr_2_response
=
requests
.
post
(
url
,
data
=
json_data_2
)
if
ocr_2_response
.
status_code
!=
200
:
return
result_list
ocr_2_res
=
json
.
loads
(
ocr_2_response
.
text
)
if
ocr_2_res
.
get
(
'ErrorCode'
)
in
consts
.
SUCCESS_CODE_SET
:
if
pid
==
consts
.
BC_PID
:
# 银行卡
# res_dict = {}
# for en_key, chn_key in consts.BC_FIELD:
# res_dict[chn_key] = ocr_res_2.get(en_key, '')
result_list
.
append
(
ocr_2_res
)
else
:
# 营业执照等
for
result_dict
in
ocr_2_res
.
get
(
'ResultList'
,
[]):
res_dict
=
{}
for
field_dict
in
result_dict
.
get
(
'FieldList'
,
[]):
res_dict
[
field_dict
.
get
(
'chn_key'
,
''
)]
=
field_dict
.
get
(
'value'
,
''
)
result_list
.
append
(
res_dict
)
return
result_list
class
DocHandler
:
@staticmethod
...
...
src/apps/doc/mpos_urls.py
0 → 100644
View file @
0c6d879
from
django.urls
import
path
from
.
import
views
urlpatterns
=
[
path
(
r'v1'
,
views
.
MPOSView
.
as_view
()),
]
src/apps/doc/views.py
View file @
0c6d879
...
...
@@ -43,7 +43,7 @@ from .models import (
AFCAutoSettlement
,
)
from
.named_enum
import
ErrorType
,
AutoResult
,
WholeResult
,
RPAResult
from
.mixins
import
DocHandler
from
.mixins
import
DocHandler
,
MPOSHandler
from
.
import
consts
from
apps.account.authentication
import
OAuth2AuthenticationWithUser
from
celery_compare.tasks
import
compare
...
...
@@ -507,6 +507,11 @@ result_update_args = {
'result'
:
fields
.
List
(
fields
.
Nested
(
result_item_args
),
required
=
True
,
validate
=
validate
.
Length
(
min
=
1
)),
}
mpos_args
=
{
'type'
:
fields
.
Int
(
required
=
True
,
validate
=
validate
.
OneOf
(
consts
.
MPOS_MAP
.
keys
())),
'file_base64_content'
:
fields
.
List
(
fields
.
Str
(),
required
=
True
,
validate
=
validate
.
Length
(
min
=
1
)),
}
class
UploadDocView
(
GenericView
,
DocHandler
):
# permission_classes = []
...
...
@@ -1422,3 +1427,23 @@ class AutoSettlementExcelView(GenericView):
wb
.
close
()
file_name
=
'cr_auto_records_{0}'
.
format
(
timezone
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d_
%
H:
%
M:
%
S'
))
return
response
.
excel_response
(
file_name
,
io_content
)
class
MPOSView
(
GenericView
,
MPOSHandler
):
permission_classes
=
[
IsAuthenticated
]
authentication_classes
=
[
OAuth2AuthenticationWithUser
]
# MPOS
@use_args
(
mpos_args
,
location
=
'data'
)
def
post
(
self
,
request
,
args
):
classify
=
args
.
get
(
'type'
)
result_list
=
[]
for
img_base64
in
args
.
get
(
'file_base64_content'
,
[]):
if
classify
in
consts
.
LICENSE_CLASSIFY_SET_1
:
result
=
self
.
ocr1_process
(
conf
.
MPOS_URL1
,
img_base64
)
else
:
result
=
self
.
ocr2_process
(
conf
.
MPOS_URL2
,
classify
,
img_base64
)
result_list
.
extend
(
result
)
return
response
.
ok
(
data
=
result_list
)
...
...
src/apps/urls.py
View file @
0c6d879
...
...
@@ -23,5 +23,6 @@ urlpatterns = [
path
(
r'api/priority/'
,
include
(
'apps.doc.priority_urls'
)),
path
(
r'api/compare/'
,
include
(
'apps.doc.compare_urls'
)),
path
(
r'api/doc/'
,
include
(
'apps.doc.internal_urls'
)),
path
(
r'api/mpos/'
,
include
(
'apps.doc.mpos_urls'
)),
path
(
'api/oauth/'
,
include
(
'oauth2_provider.urls'
,
namespace
=
'oauth2_provider'
)),
]
...
...
src/celery_compare/tasks.py
View file @
0c6d879
...
...
@@ -1194,7 +1194,7 @@ def get_se_cms_compare_info_auto(last_obj, application_entity):
# (consts.SE_BD_FIELD[6], cms_info.get('insuranceDetails', {}).get('startDate', '')),
# (consts.SE_BD_FIELD[7], cms_info.get('insuranceDetails', {}).get('endDate', '')),
# (consts.SE_BD_FIELD[8], consts.SE_STAMP_VALUE),
# (consts.SE_BD_FIELD[9], consts.SE_
STAMP
_VALUE),
# (consts.SE_BD_FIELD[9], consts.SE_
DYSYR
_VALUE),
# ]
# if is_insurance == 1:
# bd_field_input.append((consts.SE_BD_FIELD[10], insurance_price))
...
...
@@ -1677,7 +1677,7 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
(
consts
.
SE_BD_FIELD
[
6
],
cms_info
.
get
(
'insuranceDetails'
,
{})
.
get
(
'startDate'
,
''
)),
(
consts
.
SE_BD_FIELD
[
7
],
cms_info
.
get
(
'insuranceDetails'
,
{})
.
get
(
'endDate'
,
''
)),
(
consts
.
SE_BD_FIELD
[
8
],
consts
.
SE_STAMP_VALUE
),
(
consts
.
SE_BD_FIELD
[
9
],
consts
.
SE_
STAMP
_VALUE
),
(
consts
.
SE_BD_FIELD
[
9
],
consts
.
SE_
DYSYR
_VALUE
),
]
if
is_insurance
==
1
:
bd_field_input
.
append
((
consts
.
SE_BD_FIELD
[
10
],
insurance_price
))
...
...
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