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
5731e2bd
authored
2020-07-09 14:36:22 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
GCAP add business type
1 parent
a2fbe7b9
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
35 additions
and
35 deletions
.gitignore
src/apps/account/views.py
src/apps/doc/consts.py
src/apps/doc/mixins.py
src/apps/doc/models.py
src/apps/doc/named_enum.py
src/apps/doc/views.py
wsdl/DocumentManager.wsdl
.gitignore
View file @
5731e2b
...
...
@@ -31,4 +31,6 @@ conf/*
data/*
# 脚本
src/*.sh
\ No newline at end of file
src/*.sh
test.py
\ No newline at end of file
...
...
src/apps/account/views.py
View file @
5731e2b
...
...
@@ -22,4 +22,4 @@ class LoginView(ObtainJSONWebToken, GenericView):
'user_name'
:
user
.
username
,
'token'
:
res
.
data
.
get
(
'token'
),
}
return
response
.
ok
(
data
=
data
)
\ No newline at end of file
return
response
.
ok
(
data
=
data
)
...
...
src/apps/doc/consts.py
View file @
5731e2b
PAGE_DEFAULT
=
1
PAGE_SIZE_DEFAULT
=
10
BUSINESS_TYPE
=
[
'HIL'
,
'AFC'
]
HIL_SET
=
{
'HIL'
,
'hil'
,
'CO00002'
,
'C000002'
}
DOC_SCHEME_LIST
=
[
'Acceptance'
,
'Settlement'
,
'Contract Management'
]
DATA_SOURCE_LIST
=
[
'POS'
,
'EAPP'
,
'Econtract'
]
BUSINESS_TYPE_LIST
=
[
'HIL'
,
'AFC'
]
HIL_SET
=
{
'HIL'
,
'HIl'
,
'HiL'
,
'Hil'
,
'hIL'
,
'hIl'
,
'hiL'
,
'hil'
,
'CO00002'
}
HIL_PREFIX
=
'HIL'
AFC_PREFIX
=
'AFC'
...
...
src/apps/doc/mixins.py
View file @
5731e2b
import
os
from
settings
import
conf
from
.named_enum
import
DocStatus
from
.models
import
HILDoc
,
AFCDoc
from
.
import
consts
class
DocHandler
:
...
...
@@ -24,3 +24,9 @@ class DocHandler:
doc_dict
[
'excel_link'
]
=
self
.
get_link
(
doc_id
,
'excel'
)
return
list
(
doc_queryset
)
@staticmethod
def
get_doc_class
(
business_type
):
is_hil
=
business_type
in
consts
.
HIL_SET
doc_class
,
prefix
=
(
HILDoc
,
consts
.
HIL_PREFIX
)
if
is_hil
else
(
AFCDoc
,
consts
.
AFC_PREFIX
)
return
doc_class
,
prefix
...
...
src/apps/doc/models.py
View file @
5731e2b
...
...
@@ -75,6 +75,7 @@ class GCAPRecords(models.Model):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
status
=
models
.
IntegerField
(
null
=
True
,
verbose_name
=
'状态'
)
rating
=
models
.
IntegerField
(
null
=
True
,
verbose_name
=
'排名'
)
entity
=
models
.
CharField
(
null
=
True
,
max_length
=
128
,
verbose_name
=
"业务类型"
)
application_id
=
models
.
CharField
(
max_length
=
128
,
verbose_name
=
"申请id"
)
application_version
=
models
.
IntegerField
(
null
=
True
,
verbose_name
=
'申请版本'
)
intermediate_decision
=
models
.
CharField
(
null
=
True
,
max_length
=
128
,
verbose_name
=
"中间决策"
)
...
...
src/apps/doc/named_enum.py
View file @
5731e2b
...
...
@@ -14,13 +14,6 @@ class DocScheme(NamedEnum):
SETTLEMENT
=
(
1
,
'Settlement'
)
CONTRACT_MANAGEMENT
=
(
2
,
'Contract Management'
)
@classmethod
def
get_value
(
cls
,
verbose_name
,
default
=
None
,
raise_on_missing
=
False
):
val
=
super
()
.
get_value
(
verbose_name
,
default
=
None
,
raise_on_missing
=
False
)
if
val
is
None
:
pass
return
val
class
BusinessType
(
NamedEnum
):
AFC
=
(
0
,
"CO00001"
)
...
...
src/apps/doc/views.py
View file @
5731e2b
...
...
@@ -12,7 +12,7 @@ from common import response
from
common.mixins
import
GenericView
from
common.tools.file_tools
import
file_write
from
common.redis_cache
import
redis_handler
as
rh
from
.models
import
UploadDocRecords
,
DocStatus
,
HILDoc
,
AFCDoc
,
PriorityApplication
,
GCAPRecords
from
.models
import
UploadDocRecords
,
DocStatus
,
PriorityApplication
,
GCAPRecords
from
.mixins
import
DocHandler
from
.
import
consts
...
...
@@ -59,7 +59,7 @@ doc_list_args = {
validate
=
validate
.
OneOf
(
DocStatus
.
get_value_lst
())),
'application_id'
:
fields
.
Str
(
required
=
False
,
validate
=
validate
.
Length
(
max
=
64
)),
'data_source'
:
fields
.
Str
(
required
=
False
,
validate
=
validate
.
Length
(
max
=
64
)),
'business_type'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
OneOf
(
consts
.
BUSINESS_TYPE
)),
'business_type'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
OneOf
(
consts
.
BUSINESS_TYPE
_LIST
)),
'upload_time_start'
:
fields
.
Date
(
required
=
False
),
'upload_time_end'
:
fields
.
Date
(
required
=
False
),
'create_time_start'
:
fields
.
Date
(
required
=
False
),
...
...
@@ -73,6 +73,7 @@ upload_pdf_args = {
application_information
=
{
"SUBMIT_DATETIME"
:
fields
.
DateTime
(
required
=
True
),
"STATUS"
:
fields
.
Int
(
required
=
True
),
'ENTITY'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
100
)),
"RATING"
:
fields
.
Int
(
required
=
True
),
"APPLICATION_ID"
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
100
)),
"APPLICATION_VERSION"
:
fields
.
Int
(
required
=
True
),
...
...
@@ -84,7 +85,7 @@ priority_doc_args = {
}
class
UploadDocView
(
GenericView
):
class
UploadDocView
(
GenericView
,
DocHandler
):
permission_classes
=
[]
# 上传(接收)文件接口
...
...
@@ -95,7 +96,6 @@ class UploadDocView(GenericView):
document
=
args
.
get
(
'document'
)
business_type
=
document
.
get
(
'businessType'
)
application_id
=
application_data
.
get
(
'applicationId'
)
is_hil
=
business_type
in
consts
.
HIL_SET
try
:
# 1. 上传信息记录
record
=
UploadDocRecords
.
objects
.
create
(
...
...
@@ -116,7 +116,7 @@ class UploadDocView(GenericView):
self
.
invalid_params
(
msg
=
'metadataVersionId repeat'
)
else
:
# 2. 根据业务类型分库存储
doc_class
,
prefix
=
(
HILDoc
,
consts
.
HIL_PREFIX
)
if
is_hil
else
(
AFCDoc
,
consts
.
AFC_PREFIX
)
doc_class
,
prefix
=
self
.
get_doc_class
(
business_type
)
doc
=
doc_class
.
objects
.
create
(
record_id
=
record
.
id
,
metadata_version_id
=
document
.
get
(
'metadataVersionId'
),
...
...
@@ -159,7 +159,7 @@ class UploadDocView(GenericView):
'''
class
PriorityDocView
(
GenericView
):
class
PriorityDocView
(
GenericView
,
DocHandler
):
permission_classes
=
[]
# 优先级订单接口
...
...
@@ -168,9 +168,10 @@ class PriorityDocView(GenericView):
application_info
=
args
.
get
(
'APPLICATION_INFORMATION'
)
application_id
=
application_info
.
get
(
'APPLICATION_ID'
)
submit_datetime
=
application_info
.
get
(
'SUBMIT_DATETIME'
)
entity
=
application_info
.
get
(
'ENTITY'
)
submit_datetime
=
timezone
.
make_naive
(
submit_datetime
,
timezone
.
get_current_timezone
())
print
(
submit_datetime
)
GCAPRecords
.
objects
.
create
(
entity
=
entity
,
status
=
application_info
.
get
(
'STATUS'
),
rating
=
application_info
.
get
(
'RATING'
),
application_id
=
application_id
,
...
...
@@ -181,13 +182,9 @@ class PriorityDocView(GenericView):
_
,
created
=
PriorityApplication
.
objects
.
update_or_create
(
application_id
=
application_id
,
defaults
=
{
'on_off'
:
True
})
if
created
:
doc_ids
=
HILDoc
.
objects
.
filter
(
application_id
=
application_id
,
status
=
DocStatus
.
INIT
.
value
)
.
values_list
(
'id'
,
flat
=
True
)
prefix
=
consts
.
HIL_PREFIX
if
len
(
doc_ids
)
==
0
:
doc_ids
=
AFCDoc
.
objects
.
filter
(
application_id
=
application_id
,
status
=
DocStatus
.
INIT
.
value
)
.
values_list
(
'id'
,
flat
=
True
)
prefix
=
consts
.
AFC_PREFIX
doc_class
,
prefix
=
self
.
get_doc_class
(
entity
)
doc_ids
=
doc_class
.
objects
.
filter
(
application_id
=
application_id
,
status
=
DocStatus
.
INIT
.
value
)
.
values_list
(
'id'
,
flat
=
True
)
task_str_list
=
[
'{0}_{1}'
.
format
(
prefix
,
doc_id
)
for
doc_id
in
doc_ids
]
if
not
task_str_list
:
self
.
running_log
.
info
(
...
...
@@ -226,7 +223,7 @@ 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
=
HILDoc
if
business_type
==
consts
.
HIL_PREFIX
else
AFCDoc
doc_class
,
_
=
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
)
...
...
@@ -250,10 +247,9 @@ class DocView(GenericView, DocHandler):
const_str
=
'手工单'
metadata_version_id
=
str
(
int
(
time
.
time
()))
upload_finish_time
=
timezone
.
now
()
document_scheme
=
random
.
choice
([
'Acceptance'
,
'Settlement'
,
'Contract Management'
])
data_source
=
random
.
choice
([
'POS'
,
'EAPP'
,
'Econtract'
])
business_type
=
random
.
choice
([
'AFC'
,
'HIL'
])
is_hil
=
business_type
in
consts
.
HIL_SET
document_scheme
=
random
.
choice
(
consts
.
DOC_SCHEME_LIST
)
data_source
=
random
.
choice
(
consts
.
DATA_SOURCE_LIST
)
business_type
=
random
.
choice
(
consts
.
BUSINESS_TYPE_LIST
)
record
=
UploadDocRecords
.
objects
.
create
(
metadata_version_id
=
metadata_version_id
,
application_id
=
const_str
,
...
...
@@ -269,7 +265,7 @@ class DocView(GenericView, DocHandler):
)
# 2. 根据业务类型分库存储
doc_class
,
prefix
=
(
HILDoc
,
consts
.
HIL_PREFIX
)
if
is_hil
else
(
AFCDoc
,
consts
.
AFC_PREFIX
)
doc_class
,
prefix
=
self
.
get_doc_class
(
business_type
)
doc
=
doc_class
.
objects
.
create
(
record_id
=
record
.
id
,
metadata_version_id
=
metadata_version_id
,
...
...
@@ -294,7 +290,7 @@ class DocView(GenericView, DocHandler):
os
.
makedirs
(
save_dir_path
,
exist_ok
=
True
)
file_write
(
pdf_file
,
save_file_path
)
self
.
running_log
.
info
(
'[mock doc upload success] [args={0}] [record_id={1}] [
is_hil
={2}] [doc_id={3}] '
'[is_priority={4}] [enqueue_res={5}]'
.
format
(
args
,
record
.
id
,
is_hil
,
doc
.
id
,
self
.
running_log
.
info
(
'[mock doc upload success] [args={0}] [record_id={1}] [
prefix
={2}] [doc_id={3}] '
'[is_priority={4}] [enqueue_res={5}]'
.
format
(
args
,
record
.
id
,
prefix
,
doc
.
id
,
is_priority
,
redis_res
))
return
response
.
ok
()
...
...
wsdl/DocumentManager.wsdl
0 → 100644
View file @
5731e2b
This diff could not be displayed because it is too large.
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