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
edb14afd
authored
2020-07-16 11:30:59 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
session_id cache
1 parent
eb2d5a51
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
17 deletions
src/apps/doc/edms.py
src/apps/doc/management/commands/doc_process.py
src/apps/doc/mixins.py
src/apps/doc/views.py
src/common/redis_cache/handler.py
src/apps/doc/edms.py
View file @
edb14af
...
...
@@ -2,6 +2,7 @@ import requests
from
zeep
import
Client
from
settings
import
conf
from
.
import
consts
from
common.redis_cache
import
redis_handler
as
rh
class
EDMS
:
...
...
@@ -15,11 +16,24 @@ class EDMS:
self
.
pwd
=
pwd
self
.
session_id
=
None
def
g
et_session_id
(
self
):
def
s
et_session_id
(
self
):
self
.
session_id
=
self
.
sm_client
.
service
.
StartSession
(
login
=
self
.
user_name
,
password
=
self
.
pwd
,
clientType
=
consts
.
CUSTOM_CLIENT
)
rh
.
set_session_id
(
self
.
session_id
)
return
self
.
session_id
def
get_session_id
(
self
):
if
self
.
session_id
is
None
:
# redis获取session_id
self
.
session_id
=
rh
.
get_session_id
()
if
self
.
session_id
is
None
:
return
self
.
set_session_id
()
# 验证session_id
is_session_valid
=
self
.
sm_client
.
service
.
IsSessionValid
(
sessionId
=
self
.
session_id
,
keepAlive
=
False
)
if
is_session_valid
is
True
:
return
self
.
session_id
return
self
.
set_session_id
()
def
get_download_token
(
self
,
headers
,
metadata_version_id
):
with
self
.
dm_client
.
settings
(
extra_http_headers
=
headers
):
...
...
src/apps/doc/management/commands/doc_process.py
View file @
edb14af
...
...
@@ -12,12 +12,11 @@ from zeep import Client
from
django.core.management
import
BaseCommand
from
common.mixins
import
LoggerMixin
from
common.redis_cache
import
redis_handler
as
rh
from
common.tools.file_tools
import
write_zip_file
from
apps.doc.models
import
DocStatus
,
HILDoc
,
AFCDoc
from
apps.doc
import
consts
from
settings
import
conf
from
apps.doc.edms
import
EDMS
from
apps.doc.edms
import
EDMS
,
rh
class
Command
(
BaseCommand
,
LoggerMixin
):
...
...
@@ -57,7 +56,7 @@ class Command(BaseCommand, LoggerMixin):
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'
,
'document_name'
)
.
first
()
'id'
,
'metadata_version_id'
,
'
application_id'
,
'
document_name'
)
.
first
()
if
doc_info
is
None
:
self
.
cronjob_log
.
warn
(
'{0} [get_doc_info] [doc completed] [task_str={1}] [is_priority={2}]'
.
format
(
self
.
log_base
,
task_str
,
is_priority
))
...
...
@@ -125,7 +124,7 @@ class Command(BaseCommand, LoggerMixin):
s
=
item
[
1
]
# xref of its /SMask
is_rgb
=
True
if
item
[
5
]
==
'DeviceRGB'
else
False
#
RGB
#
GRAY/RGB # TODO 颜色空间不同处理
if
is_rgb
:
if
s
==
0
:
return
doc
.
extractImage
(
x
)
...
...
@@ -143,7 +142,7 @@ class Command(BaseCommand, LoggerMixin):
pix1
=
pix2
=
None
# free temp pixmaps
return
self
.
getimage
(
pix
)
#
GRAY/
CMYK
# CMYK
pix1
=
fitz
.
Pixmap
(
doc
,
x
)
pix
=
fitz
.
Pixmap
(
pix1
)
# copy of pix1, alpha channel added
...
...
@@ -159,7 +158,7 @@ class Command(BaseCommand, LoggerMixin):
pix1
=
pix2
=
None
# free temp pixmaps
pix
=
fitz
.
Pixmap
(
fitz
.
csRGB
,
pix
)
#
GRAY/
CMYK to RGB
pix
=
fitz
.
Pixmap
(
fitz
.
csRGB
,
pix
)
# CMYK to RGB
return
self
.
getimage
(
pix
)
@staticmethod
...
...
src/apps/doc/mixins.py
View file @
edb14af
...
...
@@ -6,22 +6,22 @@ from . import consts
class
DocHandler
:
@staticmethod
def
get_link
(
doc_id
,
file
=
'pdf'
):
def
get_link
(
doc_id
,
business_type
,
file
=
'pdf'
):
if
file
==
'pdf'
:
return
'/data/{
0}/{0}.pdf'
.
format
(
doc_id
)
return
'/data/{
1}/{0}/{0}.pdf'
.
format
(
doc_id
,
business_type
)
elif
file
==
'img'
:
return
'/data/{
0}/{0}_img.zip'
.
format
(
doc_id
)
return
'/data/{
1}/{0}/{0}_img.zip'
.
format
(
doc_id
,
business_type
)
else
:
return
'/data/{
0}/{0}.xls'
.
format
(
doc_id
)
return
'/data/{
1}/{0}/{0}.xls'
.
format
(
doc_id
,
business_type
)
def
get_doc_list
(
self
,
doc_queryset
):
def
get_doc_list
(
self
,
doc_queryset
,
business_type
):
for
doc_dict
in
doc_queryset
:
if
doc_dict
[
'status'
]
!=
DocStatus
.
COMPLETE
.
value
:
continue
doc_id
=
doc_dict
.
get
(
'id'
)
doc_dict
[
'pdf_link'
]
=
self
.
get_link
(
doc_id
)
doc_dict
[
'img_link'
]
=
self
.
get_link
(
doc_id
,
'img'
)
doc_dict
[
'excel_link'
]
=
self
.
get_link
(
doc_id
,
'excel'
)
doc_dict
[
'pdf_link'
]
=
self
.
get_link
(
doc_id
,
business_type
)
doc_dict
[
'img_link'
]
=
self
.
get_link
(
doc_id
,
business_type
,
file
=
'img'
)
doc_dict
[
'excel_link'
]
=
self
.
get_link
(
doc_id
,
business_type
,
file
=
'excel'
)
return
list
(
doc_queryset
)
@staticmethod
...
...
src/apps/doc/views.py
View file @
edb14af
...
...
@@ -247,9 +247,9 @@ class DocView(GenericView, DocHandler):
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'
,
'data_source'
,
'status'
)
doc_class
,
_
=
self
.
get_doc_class
(
business_type
)
doc_class
,
prefix
=
self
.
get_doc_class
(
business_type
)
doc_queryset
=
doc_class
.
objects
.
filter
(
query
)
.
values
(
*
val_tuple
)
.
order_by
(
'-upload_finish_time'
)
doc_list
=
self
.
get_doc_list
(
doc_queryset
)
doc_list
=
self
.
get_doc_list
(
doc_queryset
,
prefix
)
total
=
len
(
doc_list
)
start_index
=
page_size
*
(
page
-
1
)
...
...
src/common/redis_cache/handler.py
View file @
edb14af
...
...
@@ -35,6 +35,7 @@ class RedisHandler:
self
.
prefix
=
'bwm_ocr'
self
.
common_queue_key
=
'{0}:common_queue'
.
format
(
self
.
prefix
)
self
.
priority_queue_key
=
'{0}:priority_queue'
.
format
(
self
.
prefix
)
self
.
session_id_key
=
'{0}:session_id'
.
format
(
self
.
prefix
)
def
enqueue
(
self
,
tasks
,
is_priority
=
False
):
# 1
...
...
@@ -50,3 +51,9 @@ class RedisHandler:
is_priority
=
False
return
task
,
is_priority
def
set_session_id
(
self
,
session_id
):
return
self
.
redis
.
set
(
self
.
session_id_key
,
session_id
)
def
get_session_id
(
self
):
return
self
.
redis
.
get
(
self
.
session_id_key
)
...
...
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