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
aa782a35
authored
2022-09-19 15:11:11 +0800
by
王聪
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
pre settlement pos 接口提交
1 parent
e1915d08
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
181 additions
and
14 deletions
src/apps/doc/comments.py
src/apps/doc/views.py
src/celery_compare/tasks.py
src/apps/doc/comments.py
0 → 100644
View file @
aa782a3
ID_EN
=
'PRC ID'
PP_EN
=
'Passport'
EEP_EN
=
'Resident Permit to Mainland'
RP_EN
=
'Resident ID'
BL_EN
=
'Business permit'
SME_BL_EN
=
'SME Business permit'
MVI_EN
=
'newCar Invoice'
UCI_EN
=
'usedCar Invoice'
MVC_EN
=
'Green Book(1/2)'
MVC34_EN
=
'Green Book(3/4)'
BC_EN
=
'Bank Card'
DDA_EN
=
'DDA'
HMH_EN
=
'Mortgage Waiver Letter'
JYPZ_EN
=
'Used Car Document'
AFC_CONTRACT_EN
=
'AFC Contract'
BD_EN
=
'Insurance'
BS_EN
=
'Bank Statement'
HIL_CONTRACT_1_EN
=
'售后回租合同'
HIL_CONTRACT_2_EN
=
'车辆租赁抵押合同'
HIL_CONTRACT_3_EN
=
'车辆处置协议'
OCR_COMPARE_COMMENT
=
{
}
\ No newline at end of file
src/apps/doc/views.py
View file @
aa782a3
...
...
@@ -49,7 +49,7 @@ from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult
from
.mixins
import
DocHandler
,
MPOSHandler
from
.
import
consts
from
apps.account.authentication
import
OAuth2AuthenticationWithUser
from
celery_compare.tasks
import
compare
from
celery_compare.tasks
import
compare
,
pos_compare
class
CustomDate
(
fields
.
Date
):
...
...
@@ -222,6 +222,7 @@ se_compare_content = {
'applicationId'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
64
)),
"applicationVersion"
:
fields
.
Int
(
required
=
True
),
'applicationEntity'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
OneOf
(
consts
.
ENTITY
)),
'customerType'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
OneOf
(
consts
.
CUSTOMER_TYPE
)),
"firstSubmmisonDate"
:
CustomDate
(
required
=
True
),
'propertyDocumentPolicy'
:
fields
.
Str
(
required
=
False
,
validate
=
validate
.
Length
(
max
=
16
)),
...
...
@@ -264,7 +265,7 @@ document_args = {
'documentName'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
255
)),
# Acceptance/Settlement/Contract Management
'documentScheme'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
64
)),
'businessType'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
64
)),
# CO00001/CO00002
'businessType'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
64
)),
# CO00001/CO00002
'uploadFinishTime'
:
fields
.
DateTime
(
required
=
True
),
'dataSource'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
64
)),
# POS/EAPP/Econtract
'metadataVersionId'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
64
)),
...
...
@@ -529,6 +530,7 @@ class UploadDocView(GenericView, DocHandler):
# authentication_classes = []
permission_classes
=
[
IsAuthenticated
]
authentication_classes
=
[
OAuth2AuthenticationWithUser
]
# required_scopes = ['write']
# 上传(接收)文件接口
...
...
@@ -573,7 +575,7 @@ class UploadDocView(GenericView, DocHandler):
# if document_name.endswith('.zip'):
# self.running_log.info('[doc upload success] [zip file skip] [args={0}]'.format(args))
# return response.ok()
if
data_source
==
consts
.
DATA_SOURCE_LIST
[
1
]:
if
document_name
.
endswith
(
'-证书.pdf'
)
or
document_name
.
endswith
(
'-证书'
):
self
.
running_log
.
info
(
'[doc upload success] [eapp license skip] [args={0}]'
.
format
(
args
))
...
...
@@ -779,7 +781,21 @@ class SECompareView(GenericView):
bank_obj
.
on_off
=
False
bank_obj
.
save
()
return
response
.
ok
()
# compare_result = pos_compare()
compare_result
=
{
"is_pass"
:
True
,
"particulars"
:
[{
"object_name"
:
"PRC ID"
,
"fields"
:
[{
"input"
:
"张三"
,
"ocr"
:
"张三"
,
"field_is_pass"
:
True
,
"comments"
:
"身份证姓名与系统不一致"
}]
}]
}
return
response
.
ok
(
data
=
compare_result
)
post
.
openapi_doc
=
'''
tags: [info]
...
...
@@ -865,10 +881,10 @@ class DocView(GenericView, DocHandler):
application_id_query
=
Q
(
application_id__contains
=
application_id
)
if
application_id
is
not
None
else
Q
()
data_source_query
=
Q
(
data_source
=
data_source
)
if
data_source
is
not
None
else
Q
()
upload_finish_time_query
=
Q
(
upload_finish_time__gte
=
upload_time_start
,
upload_finish_time__lt
=
upload_time_end
+
datetime
.
timedelta
(
days
=
1
))
\
upload_finish_time__lt
=
upload_time_end
+
datetime
.
timedelta
(
days
=
1
))
\
if
upload_time_start
is
not
None
and
upload_time_end
is
not
None
else
Q
()
create_time_query
=
Q
(
create_time__gte
=
create_time_start
,
create_time__lt
=
create_time_end
+
datetime
.
timedelta
(
days
=
1
))
\
create_time__lt
=
create_time_end
+
datetime
.
timedelta
(
days
=
1
))
\
if
create_time_start
is
not
None
and
create_time_end
is
not
None
else
Q
()
query
=
application_id_query
&
status_query
&
data_source_query
&
upload_finish_time_query
&
create_time_query
val_tuple
=
(
'id'
,
'application_id'
,
'upload_finish_time'
,
'create_time'
,
'document_scheme'
,
'data_source'
,
...
...
@@ -880,10 +896,11 @@ class DocView(GenericView, DocHandler):
if
start_index
>=
total
>
0
:
raise
self
.
invalid_params
(
'页数不存在'
)
doc_queryset
=
doc_class
.
objects
.
filter
(
query
)
.
values
(
*
val_tuple
)
.
order_by
(
'-create_time'
)[
start_index
:
end_index
]
doc_queryset
=
doc_class
.
objects
.
filter
(
query
)
.
values
(
*
val_tuple
)
.
order_by
(
'-create_time'
)[
start_index
:
end_index
]
# doc_list = self.get_doc_list(doc_queryset, prefix)
for
doc_dict
in
doc_queryset
:
tmp_scheme
=
consts
.
COMPARE_DOC_SCHEME_LIST
[
0
]
if
doc_dict
[
'document_scheme'
]
==
consts
.
DOC_SCHEME_LIST
[
0
]
\
tmp_scheme
=
consts
.
COMPARE_DOC_SCHEME_LIST
[
0
]
if
doc_dict
[
'document_scheme'
]
==
consts
.
DOC_SCHEME_LIST
[
0
]
\
else
consts
.
COMPARE_DOC_SCHEME_LIST
[
1
]
application_link
=
'{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'
.
format
(
conf
.
BASE_URL
,
prefix
,
tmp_scheme
,
doc_dict
[
'application_id'
])
...
...
@@ -930,7 +947,6 @@ class DocView(GenericView, DocHandler):
# os.remove(tmp_save_path)
# raise self.invalid_params(msg='invalid params: PDF file XSS')
file
.
close
()
# 1. 上传信息记录
application_id
=
'{0}{1}'
.
format
(
consts
.
FIXED_APPLICATION_ID_PREFIX
,
metadata_version_id
)
...
...
@@ -1013,7 +1029,8 @@ class CompareResultView(GenericView):
latest_compared_time
=
''
else
:
whole_result
=
consts
.
RESULT_Y
if
result_obj
.
ocr_auto_result_pass
else
consts
.
RESULT_N
latest_compared_time
=
''
if
result_obj
.
ocr_latest_comparison_time
is
None
else
result_obj
.
ocr_latest_comparison_time
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M'
)
latest_compared_time
=
''
if
result_obj
.
ocr_latest_comparison_time
is
None
else
result_obj
.
ocr_latest_comparison_time
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M'
)
source
=
consts
.
INFO_SOURCE
[
1
]
version
=
comments
=
''
...
...
@@ -1029,7 +1046,8 @@ class CompareResultView(GenericView):
'source'
:
source
,
'version'
:
version
,
'comments'
:
comments
,
'result'
:
[]
if
result_obj
is
None
or
not
result_obj
.
ocr_auto_result
else
json
.
loads
(
result_obj
.
ocr_auto_result
)
'result'
:
[]
if
result_obj
is
None
or
not
result_obj
.
ocr_auto_result
else
json
.
loads
(
result_obj
.
ocr_auto_result
)
}
return
response
.
ok
(
data
=
compare_result
)
...
...
@@ -1064,7 +1082,8 @@ class CompareResultView(GenericView):
'id'
:
0
if
result_obj
is
None
else
result_obj
.
id
,
'application_id'
:
case_id
,
'entity'
:
entity
,
'scheme'
:
consts
.
DOC_SCHEME_LIST
[
0
]
if
scheme
==
consts
.
COMPARE_DOC_SCHEME_LIST
[
0
]
else
consts
.
DOC_SCHEME_LIST
[
1
],
'scheme'
:
consts
.
DOC_SCHEME_LIST
[
0
]
if
scheme
==
consts
.
COMPARE_DOC_SCHEME_LIST
[
0
]
else
consts
.
DOC_SCHEME_LIST
[
1
],
'whole_result'
:
whole_result
,
'latest_compared_time'
:
''
if
result_obj
is
None
else
result_obj
.
update_time
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M'
),
'source'
:
source
,
...
...
@@ -1235,7 +1254,8 @@ class SECMSView(GenericView):
def
post
(
self
,
request
):
args
=
request
.
data
cms_info
=
args
.
get
(
'content'
,
{})
business_type
=
consts
.
AFC_PREFIX
if
cms_info
.
get
(
'financeCompany'
,
''
)
.
startswith
(
'宝马'
)
else
consts
.
HIL_PREFIX
business_type
=
consts
.
AFC_PREFIX
if
cms_info
.
get
(
'financeCompany'
,
''
)
.
startswith
(
'宝马'
)
else
consts
.
HIL_PREFIX
src_application_id
=
cms_info
.
get
(
'settlemnetVerification'
,
{})
.
get
(
'applicationNo'
,
''
)
application_id
=
src_application_id
[:
src_application_id
.
rfind
(
'-'
)]
...
...
@@ -1350,7 +1370,7 @@ class AutoSettlementView(GenericView):
whole_result_query
=
Q
(
ocr_whole_result_pass
=
whole_result
)
if
not
isinstance
(
whole_result
,
str
)
else
Q
()
rpa_result_query
=
Q
(
rpa_result
=
rpa_result
)
if
not
isinstance
(
rpa_result
,
str
)
else
Q
()
time1_query
=
Q
(
rpa_get_case_from_ocr_time__gte
=
get_case_from_ocr_time_start
,
rpa_get_case_from_ocr_time__lt
=
get_case_from_ocr_time_end
+
datetime
.
timedelta
(
days
=
1
))
\
rpa_get_case_from_ocr_time__lt
=
get_case_from_ocr_time_end
+
datetime
.
timedelta
(
days
=
1
))
\
if
get_case_from_ocr_time_start
is
not
None
and
get_case_from_ocr_time_end
is
not
None
else
Q
()
time2_query
=
Q
(
rpa_activated_time__gte
=
activated_time_start
,
rpa_activated_time__lt
=
activated_time_end
+
datetime
.
timedelta
(
days
=
1
))
\
...
...
src/celery_compare/tasks.py
View file @
aa782a3
...
...
@@ -3179,3 +3179,125 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
compare_log
.
error
(
'{0} [Auto SE] [result save error] [entity={1}] [id={2}] [ocr_res_id={3}] '
'[error={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
traceback
.
format_exc
()))
def
pos_compare
(
application_id
,
application_entity
,
uniq_seq
,
ocr_res_id
=
None
,
is_ca
=
True
,
is_cms
=
False
):
# POS: application_id, application_entity, uniq_seq, None
# OCR: application_id, business_type(application_entity), None, ocr_res_id
compare_log
.
info
(
'{0} [pos_compare] [entity={1}] [id={2}] [uniq_seq={3}] [is_ca={4}] '
'[is_cms={5}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
is_ca
,
is_cms
))
# 根据application_id查找最新的比对信息,如果没有,结束
if
is_ca
:
comparison_class
=
HILComparisonInfo
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCComparisonInfo
else
:
if
application_entity
==
consts
.
HIL_PREFIX
:
comparison_class
=
HILSECMSInfo
if
is_cms
else
HILSEComparisonInfo
else
:
comparison_class
=
AFCSECMSInfo
if
is_cms
else
AFCSEComparisonInfo
last_obj
=
comparison_class
.
objects
.
filter
(
application_id
=
application_id
)
.
last
()
if
last_obj
is
None
:
compare_log
.
info
(
'{0} [comparison info empty] [entity={1}] [id={2}] [uniq_seq={3}] '
'[is_ca={4}] [is_cms]={5}'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
is_ca
,
is_cms
))
return
# 根据application_id查找OCR累计结果指定license字段,如果没有,结束
if
is_ca
:
result_class
=
HILOCRResult
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCOCRResult
ca_ocr_res_dict
=
dict
()
else
:
result_class
=
HILSEOCRResult
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCSEOCRResult
ca_result_class
=
HILOCRResult
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCOCRResult
# if ocr_res_id is None:
ca_ocr_res_dict
=
ca_result_class
.
objects
.
filter
(
application_id
=
application_id
)
.
values
(
*
consts
.
CA_ADD_COMPARE_FIELDS
)
.
first
()
# else:
# ca_ocr_res_dict = ca_result_class.objects.filter(id=ocr_res_id).values(
# *consts.CA_ADD_COMPARE_FIELDS).first()
ocr_res_dict
=
result_class
.
objects
.
filter
(
application_id
=
application_id
)
.
values
(
*
consts
.
COMPARE_FIELDS
)
.
first
()
if
ocr_res_dict
is
None
:
compare_log
.
info
(
'{0} [ocr info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
'[is_ca={5}] [is_cms]={6}'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
,
is_ca
,
is_cms
))
return
if
is_ca
:
ca_compare
(
application_id
,
application_entity
,
ocr_res_id
,
last_obj
,
ocr_res_dict
)
else
:
id_res_list
=
[]
for
field_name
in
consts
.
CA_ADD_COMPARE_FIELDS
:
if
field_name
==
consts
.
IC_OCR_FIELD
:
id_res_list
.
append
(
ocr_res_dict
.
get
(
field_name
))
id_res_list
.
append
(
ca_ocr_res_dict
.
get
(
field_name
)
if
isinstance
(
ca_ocr_res_dict
,
dict
)
else
None
)
if
isinstance
(
ca_ocr_res_dict
,
dict
)
and
isinstance
(
ca_ocr_res_dict
.
get
(
field_name
),
str
):
tmp_ca_result
=
json
.
loads
(
ca_ocr_res_dict
.
get
(
field_name
))
if
isinstance
(
ocr_res_dict
.
get
(
field_name
),
str
):
tmp_se_result
=
json
.
loads
(
ocr_res_dict
.
get
(
field_name
))
tmp_ca_result
.
extend
(
tmp_se_result
)
ocr_res_dict
[
field_name
]
=
json
.
dumps
(
tmp_ca_result
)
# auto settlement
auto_class
=
HILAutoSettlement
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCAutoSettlement
auto_obj
=
auto_class
.
objects
.
filter
(
application_id
=
application_id
,
on_off
=
True
)
.
first
()
bank_class
=
HILbankVerification
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCbankVerification
ignore_bank
=
bank_class
.
objects
.
filter
(
application_id
=
application_id
,
on_off
=
True
)
.
exists
()
if
auto_obj
is
not
None
:
auto_result
=
se_compare_auto
(
application_id
,
application_entity
,
ocr_res_id
,
last_obj
,
ocr_res_dict
,
auto_obj
,
ignore_bank
,
id_res_list
)
else
:
auto_result
=
None
full_result
=
se_compare
(
application_id
,
application_entity
,
ocr_res_id
,
last_obj
,
ocr_res_dict
,
is_cms
,
auto_result
,
ignore_bank
,
id_res_list
)
if
auto_obj
is
not
None
:
try
:
auto_obj
.
ocr_whole_result_pass
=
full_result
auto_obj
.
save
()
compare_log
.
info
(
'{0} [Auto SE] [result save success] [entity={1}] [id={2}] [ocr_res_id={3}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
))
except
Exception
as
e
:
compare_log
.
error
(
'{0} [Auto SE] [result save error] [entity={1}] [id={2}] [ocr_res_id={3}] '
'[error={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
traceback
.
format_exc
()))
result_table
=
HILCACompareResult
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCCACompareResult
res_obj
=
result_table
.
objects
.
filter
(
application_id
=
application_id
)
.
first
()
return
pos_result_output
(
res_obj
.
result
)
# pos输出解析
def
pos_result_output
(
compare_result
):
result_obj
=
json
.
loads
(
compare_result
)
license_map
=
dict
()
for
item
in
result_obj
:
license_en
=
item
.
get
(
"License"
)
if
license_map
.
get
(
license_en
):
license_map
.
get
(
license_en
)
.
append
(
item
)
else
:
info_items
=
[
item
]
license_map
[
license_en
]
=
info_items
is_pass
=
True
particulars
=
[]
for
license
,
license_items
in
license_map
.
items
():
particular
=
{
"object_name"
:
license
}
fields
=
[]
particular
[
"fields"
]
=
fields
for
license_item
in
license_items
:
field
=
dict
()
field
[
"input"
]
=
license_item
.
get
(
"Input"
)
field
[
"ocr"
]
=
license_item
.
get
(
"OCR"
)
field
[
"field_is_pass"
]
=
license_item
.
get
(
"Result"
)
==
'Y'
if
not
field
[
"field_is_pass"
]:
is_pass
=
False
field
[
"comments"
]
=
''
fields
.
append
(
field
)
particular
[
"fields"
]
=
fields
particulars
.
append
(
particular
)
return
{
"is_pass"
:
is_pass
,
"particulars"
:
particulars
}
...
...
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