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
14adf361
authored
2021-07-08 11:19:12 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
se compare part 2
1 parent
beebba6a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
58 deletions
src/apps/doc/models.py
src/celery_compare/tasks.py
src/apps/doc/models.py
View file @
14adf36
...
...
@@ -488,3 +488,16 @@ class IDBCRecords(models.Model):
db_table
=
'idbc_records'
class
AFCSECompareResult
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
# 索引
update_time
=
models
.
DateTimeField
(
auto_now
=
True
,
verbose_name
=
'修改时间'
)
create_time
=
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
'创建时间'
)
class
Meta
:
managed
=
False
db_table
=
'afc_se_compare_result'
situ_db_label
=
'afc'
...
...
src/celery_compare/tasks.py
View file @
14adf36
...
...
@@ -149,34 +149,7 @@ def usedcar_info_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_s
return
is_find
and
key_right
,
no_match_vino
@app.task
def
compare
(
application_id
,
application_entity
,
uniq_seq
,
ocr_res_id
,
is_ca
=
True
):
# POS: application_id, application_entity, uniq_seq, None
# OCR: application_id, business_type(application_entity), None, ocr_res_id
compare_log
.
info
(
'{0} [receive task] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
))
# 根据application_id查找最新的比对信息,如果没有,结束
comparison_class
=
HILComparisonInfo
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCComparisonInfo
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}] [ocr_res_id={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
))
return
# 根据application_id查找OCR累计结果指定license字段,如果没有,结束
result_class
=
HILOCRResult
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCOCRResult
if
ocr_res_id
is
None
:
ocr_res_dict
=
result_class
.
objects
.
filter
(
application_id
=
application_id
)
.
values
(
*
consts
.
COMPARE_FIELDS
)
.
first
()
else
:
ocr_res_dict
=
result_class
.
objects
.
filter
(
id
=
ocr_res_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}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
))
return
def
ca_compare
(
application_id
,
application_entity
,
ocr_res_id
,
last_obj
,
ocr_res_dict
):
start_time
=
datetime
.
now
()
compare_failed
=
False
...
...
@@ -300,38 +273,36 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
comparison_res
[
'OCR_Input'
][
'corporateCusInfo'
]
=
order_corporate_cus_info
comparison_res
[
'OCR_Input'
][
'wholeResult'
]
=
consts
.
RESULT_N
if
consts
.
RESULT_N
in
res_set
or
consts
.
RESULT_NA
in
res_set
else
consts
.
RESULT_Y
comparison_res
[
'OCR_Input'
][
'wholeResult'
]
=
consts
.
RESULT_N
if
consts
.
RESULT_N
in
res_set
or
consts
.
RESULT_NA
in
res_set
else
consts
.
RESULT_Y
except
Exception
as
e
:
compare_failed
=
True
compare_log
.
error
(
'{0} [compare error] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
'[error={5}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
,
traceback
.
format_exc
()))
compare_log
.
error
(
'{0} [CA] [compare error] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
traceback
.
format_exc
()))
else
:
compare_log
.
info
(
'{0} [compare success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
'[compare_res={5}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
,
comparison_res
))
compare_log
.
info
(
'{0} [CA] [compare success] [entity={1}] [id={2}] [ocr_res_id={3}] [compare_res={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
comparison_res
))
is_gcap_send
=
Configs
.
objects
.
filter
(
id
=
1
)
.
first
()
if
is_gcap_send
is
not
None
and
is_gcap_send
.
value
==
'N'
:
compare_log
.
info
(
'{0} [
gcap closed] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4
}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
))
compare_log
.
info
(
'{0} [
CA] [gcap closed] [entity={1}] [id={2}] [ocr_res_id={3
}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
))
return
# 时间延迟
send_time
=
last_obj
.
create_time
+
timedelta
(
seconds
=
15
)
while
datetime
.
now
()
<
send_time
:
compare_log
.
info
(
'{0} [
time wait 5s] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4
}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
))
compare_log
.
info
(
'{0} [
CA] [time wait 5s] [entity={1}] [id={2}] [ocr_res_id={3
}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
))
time
.
sleep
(
5
)
# 将比对结果发送GCAP
try
:
data
=
gcap
.
dict_to_xml
(
comparison_res
)
except
Exception
as
e
:
compare_log
.
error
(
'{0} [dict to xml failed] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
'[error={5}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
,
traceback
.
format_exc
()))
compare_log
.
error
(
'{0} [CA] [dict to xml failed] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
traceback
.
format_exc
()))
else
:
try
:
for
times
in
range
(
consts
.
RETRY_TIMES
):
...
...
@@ -344,16 +315,15 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
else
:
raise
GCAPException
(
gcap_exc
)
except
Exception
as
e
:
compare_log
.
error
(
'{0} [gcap failed] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
'[error={5}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
,
traceback
.
format_exc
()))
compare_log
.
error
(
'{0} [CA] [gcap failed] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
traceback
.
format_exc
()))
else
:
compare_log
.
info
(
'{0} [
gcap success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
'[response={5}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
,
res_text
))
compare_log
.
info
(
'{0} [task success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
))
finally
:
compare_log
.
info
(
'{0} [
CA] [gcap success] [entity={1}] [id={2}] [ocr_res_id={3}] [response={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
res_text
))
compare_log
.
info
(
'{0} [CA] [task success] [entity={1}] [id={2}] [ocr_res_id={3}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
))
# report
try
:
end_time
=
datetime
.
now
()
if
compare_failed
:
...
...
@@ -361,7 +331,8 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
failure_reason
=
'Compare process error'
total_fields
=
0
else
:
successful_at_this_level
=
True
if
comparison_res
[
'OCR_Input'
][
'wholeResult'
]
==
consts
.
RESULT_Y
else
False
successful_at_this_level
=
True
if
comparison_res
[
'OCR_Input'
][
'wholeResult'
]
==
consts
.
RESULT_Y
else
False
field_failed
=
{
'individualCusInfo'
:
[],
'corporateCusInfo'
:
[],
...
...
@@ -427,7 +398,6 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
else
:
failure_reason
=
''
request_trigger
=
RequestTrigger
.
SUBMITING
.
value
if
ocr_res_id
is
None
else
RequestTrigger
.
UPLOADING
.
value
report_class
=
HILCompareReport
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCCompareReport
report_class
.
objects
.
create
(
...
...
@@ -442,10 +412,84 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
total_fields
=
total_fields
,
workflow_name
=
last_obj
.
customer_type
,
)
compare_log
.
info
(
'{0} [report save success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
))
compare_log
.
info
(
'{0} [CA] [report 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} [CA] [report 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
se_compare
(
application_id
,
application_entity
,
ocr_res_id
,
last_obj
,
ocr_res_dict
):
try
:
# 比对逻辑
pass
except
Exception
as
e
:
pass
else
:
# 将比对结果写入数据库
try
:
pass
except
Exception
as
e
:
pass
# report
try
:
request_trigger
=
RequestTrigger
.
SUBMITING
.
value
if
ocr_res_id
is
None
else
RequestTrigger
.
UPLOADING
.
value
report_class
=
HILCompareReport
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCCompareReport
report_class
.
objects
.
create
(
case_number
=
application_id
,
request_team
=
RequestTeam
.
SETTLEMENT
.
value
,
request_trigger
=
request_trigger
,
transaction_start
=
start_time
,
transaction_end
=
end_time
,
successful_at_this_level
=
successful_at_this_level
,
failure_reason
=
failure_reason
,
process_name
=
ProcessName
.
CACOMPARE
.
value
,
total_fields
=
total_fields
,
workflow_name
=
customer_type
,
)
compare_log
.
info
(
'{0} [SE] [report 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} [report save success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
'[error={5}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
,
traceback
.
format_exc
()))
compare_log
.
error
(
'{0} [SE] [report 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
()))
@app.task
def
compare
(
application_id
,
application_entity
,
uniq_seq
,
ocr_res_id
,
is_ca
=
True
):
# POS: application_id, application_entity, uniq_seq, None
# OCR: application_id, business_type(application_entity), None, ocr_res_id
compare_log
.
info
(
'{0} [receive task] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] [is_ca={5}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
,
is_ca
))
# 根据application_id查找最新的比对信息,如果没有,结束
comparison_class
=
HILComparisonInfo
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCComparisonInfo
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}] [ocr_res_id={4}] '
'[is_ca={5}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
,
is_ca
))
return
# 根据application_id查找OCR累计结果指定license字段,如果没有,结束
result_class
=
HILOCRResult
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCOCRResult
if
ocr_res_id
is
None
:
ocr_res_dict
=
result_class
.
objects
.
filter
(
application_id
=
application_id
)
.
values
(
*
consts
.
COMPARE_FIELDS
)
.
first
()
else
:
ocr_res_dict
=
result_class
.
objects
.
filter
(
id
=
ocr_res_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}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
,
is_ca
))
return
if
is_ca
:
ca_compare
(
application_id
,
application_entity
,
ocr_res_id
,
last_obj
,
ocr_res_dict
)
else
:
se_compare
()
...
...
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