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
e3d719b8
authored
2020-11-19 13:35:56 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix db bug
1 parent
1f46e609
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
11 deletions
src/apps/doc/management/commands/ocr_process.py
src/apps/doc/management/commands/ocr_process.py
View file @
e3d719b
...
...
@@ -55,14 +55,14 @@ class Command(BaseCommand, LoggerMixin):
def
signal_handler
(
self
,
sig
,
frame
):
self
.
switch
=
False
# 停止处理文件
def
get_doc_object
(
self
,
task_str
):
business_type
,
doc_id_str
=
task_str
.
split
(
consts
.
SPLIT_STR
)
doc_id
=
int
(
doc_id_str
)
doc_class
=
HILDoc
if
business_type
==
consts
.
HIL_PREFIX
else
AFCDoc
# doc_info = doc_class.objects.filter(id=doc_id, status=DocStatus.INIT.value).values(
# 'id', 'metadata_version_id', 'application_id', 'document_name', 'document_scheme').first()
doc
=
doc_class
.
objects
.
filter
(
id
=
doc_id
)
.
first
()
return
doc
,
business_type
#
def get_doc_object(self, task_str):
#
business_type, doc_id_str = task_str.split(consts.SPLIT_STR)
#
doc_id = int(doc_id_str)
#
doc_class = HILDoc if business_type == consts.HIL_PREFIX else AFCDoc
#
# doc_info = doc_class.objects.filter(id=doc_id, status=DocStatus.INIT.value).values(
#
# 'id', 'metadata_version_id', 'application_id', 'document_name', 'document_scheme').first()
#
doc = doc_class.objects.filter(id=doc_id).first()
#
return doc, business_type
def
get_doc_info
(
self
):
task_str
,
is_priority
=
rh
.
dequeue
()
...
...
@@ -73,7 +73,12 @@ class Command(BaseCommand, LoggerMixin):
self
.
cronjob_log
.
info
(
'{0} [get_doc_info] [task={1}] [is_priority={2}]'
.
format
(
self
.
log_base
,
task_str
,
is_priority
))
try
:
doc
,
business_type
=
self
.
get_doc_object
(
task_str
)
# doc, business_type = self.get_doc_object(task_str)
business_type
,
doc_id_str
=
task_str
.
split
(
consts
.
SPLIT_STR
)
doc_id
=
int
(
doc_id_str
)
doc_class
=
HILDoc
if
business_type
==
consts
.
HIL_PREFIX
else
AFCDoc
doc
=
doc_class
.
objects
.
filter
(
id
=
doc_id
)
.
first
()
if
doc
is
None
:
self
.
cronjob_log
.
warn
(
'{0} [get_doc_info] [doc not exist] [task_str={1}] [is_priority={2}]'
.
format
(
self
.
log_base
,
task_str
,
is_priority
))
...
...
@@ -627,7 +632,11 @@ class Command(BaseCommand, LoggerMixin):
del
unknown_summary
# 4.2 重构Excel文件
doc
,
business_type
=
self
.
get_doc_object
(
task_str
)
# doc, business_type = self.get_doc_object(task_str)
business_type
,
doc_id_str
=
task_str
.
split
(
consts
.
SPLIT_STR
)
doc_id
=
int
(
doc_id_str
)
doc_class
=
HILDoc
if
business_type
==
consts
.
HIL_PREFIX
else
AFCDoc
doc
=
doc_class
.
objects
.
filter
(
id
=
doc_id
)
.
first
()
doc_data_path
=
os
.
path
.
join
(
self
.
data_dir
,
business_type
,
consts
.
TMP_DIR_NAME
,
str
(
doc
.
id
))
excel_path
=
os
.
path
.
join
(
doc_data_path
,
'{0}.xlsx'
.
format
(
doc
.
id
))
# src_excel_path = os.path.join(doc_data_path, 'src.xlsx')
...
...
@@ -639,7 +648,11 @@ class Command(BaseCommand, LoggerMixin):
with
lock
:
if
task_str
in
res_dict
:
del
res_dict
[
task_str
]
doc
,
business_type
=
self
.
get_doc_object
(
task_str
)
# doc, business_type = self.get_doc_object(task_str)
business_type
,
doc_id_str
=
task_str
.
split
(
consts
.
SPLIT_STR
)
doc_id
=
int
(
doc_id_str
)
doc_class
=
HILDoc
if
business_type
==
consts
.
HIL_PREFIX
else
AFCDoc
doc
=
doc_class
.
objects
.
filter
(
id
=
doc_id
)
.
first
()
doc
.
status
=
DocStatus
.
PROCESS_FAILED
.
value
doc
.
save
()
self
.
cronjob_log
.
warn
(
'{0} [process failed (res to wb)] [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