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
d915554f
authored
2024-01-19 15:23:43 +0800
by
冯轩
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
ADD:lock
1 parent
d8bb22a8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
25 deletions
src/apps/doc/management/commands/ocr_process.py
src/apps/doc/management/commands/ocr_process.py
View file @
d915554
...
...
@@ -10,6 +10,7 @@ import traceback
from
collections
import
Counter
from
datetime
import
datetime
,
date
from
django
import
db
from
django.db
import
transaction
from
django.utils
import
timezone
from
django.core.management
import
BaseCommand
from
multiprocessing
import
Process
,
Queue
,
Manager
,
Lock
...
...
@@ -2034,31 +2035,32 @@ class Command(BaseCommand, LoggerMixin):
result_class
=
HILOCRResult
if
is_ca
else
HILSEOCRResult
else
:
result_class
=
AFCOCRResult
if
is_ca
else
AFCSEOCRResult
res_obj
=
result_class
.
objects
.
filter
(
application_id
=
doc
.
application_id
)
.
first
()
if
res_obj
is
None
:
res_obj
=
result_class
()
res_obj
.
application_id
=
doc
.
application_id
for
classify
,
field
in
consts
.
RESULT_MAPPING
.
items
():
if
not
hasattr
(
res_obj
,
field
):
continue
license_list
=
license_summary
.
get
(
classify
)
if
not
license_list
:
continue
if
classify
==
consts
.
IC_CLASSIFY
and
ic_merge
:
license_list
[
0
]
.
update
(
license_list
[
1
])
license_list
.
pop
(
1
)
elif
classify
==
consts
.
RP_CLASSIFY
and
rp_merge
:
license_list
[
0
]
.
update
(
license_list
[
1
])
license_list
.
pop
(
1
)
old_res_str
=
getattr
(
res_obj
,
field
)
if
old_res_str
is
None
:
last_res_str
=
json
.
dumps
(
license_list
)
else
:
old_res_list
=
json
.
loads
(
old_res_str
)
old_res_list
.
extend
(
license_list
)
last_res_str
=
json
.
dumps
(
old_res_list
)
setattr
(
res_obj
,
field
,
last_res_str
)
res_obj
.
save
()
res_obj
=
result_class
.
objects
.
select_for_update
()
.
filter
(
application_id
=
doc
.
application_id
)
.
first
()
with
transaction
.
atomic
():
if
res_obj
is
None
:
res_obj
=
result_class
()
res_obj
.
application_id
=
doc
.
application_id
for
classify
,
field
in
consts
.
RESULT_MAPPING
.
items
():
if
not
hasattr
(
res_obj
,
field
):
continue
license_list
=
license_summary
.
get
(
classify
)
if
not
license_list
:
continue
if
classify
==
consts
.
IC_CLASSIFY
and
ic_merge
:
license_list
[
0
]
.
update
(
license_list
[
1
])
license_list
.
pop
(
1
)
elif
classify
==
consts
.
RP_CLASSIFY
and
rp_merge
:
license_list
[
0
]
.
update
(
license_list
[
1
])
license_list
.
pop
(
1
)
old_res_str
=
getattr
(
res_obj
,
field
)
if
old_res_str
is
None
:
last_res_str
=
json
.
dumps
(
license_list
)
else
:
old_res_list
=
json
.
loads
(
old_res_str
)
old_res_list
.
extend
(
license_list
)
last_res_str
=
json
.
dumps
(
old_res_list
)
setattr
(
res_obj
,
field
,
last_res_str
)
res_obj
.
save
()
except
Exception
as
e
:
self
.
online_log
.
error
(
'{0} [process error (ocr result save)] [task={1}] [error={2}]'
.
format
(
...
...
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