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
a2fbe7b9
authored
2020-07-08 18:55:15 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix GCAP
1 parent
b8034b9f
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
12 deletions
requirements/base.txt
src/apps/doc/models.py
src/apps/doc/named_enum.py
src/apps/doc/views.py
requirements/base.txt
View file @
a2fbe7b
-r github.txt
aiohttp==3.6.2
appdirs==1.4.4
async-timeout==3.0.1
attrs==19.3.0
certifi==2016.2.28
cached-property==1.5.1
certifi==2020.6.20
chardet==3.0.4
defusedxml==0.6.0
Django==2.1
djangorestframework==3.9.0
djangorestframework-jwt==1.11.0
idna==2.9
idna-ssl==1.1.0
isodate==0.6.0
lxml==4.5.1
marshmallow==3.6.1
multidict==4.7.6
pdfminer3k==1.3.4
...
...
@@ -20,9 +25,14 @@ PyMuPDF==1.17.0
PyMySQL==0.9.3
pytz==2020.1
redis==3.4.1
requests==2.24.0
requests-toolbelt==0.9.1
six==1.14.0
SQLAlchemy==0.9.10
typing-extensions==3.7.4.2
urllib3==1.25.9
webargs==6.1.0
XlsxWriter==1.2.9
xlwt==1.3.0
yarl==1.4.2
zeep==3.4.0
...
...
src/apps/doc/models.py
View file @
a2fbe7b
...
...
@@ -71,10 +71,26 @@ class AFCDoc(models.Model):
db_table
=
'afc_doc'
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
=
'排名'
)
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
=
"中间决策"
)
submit_datetime
=
models
.
DateTimeField
(
null
=
True
,
verbose_name
=
'提交时间'
)
update_time
=
models
.
DateTimeField
(
auto_now
=
True
,
verbose_name
=
'修改时间'
)
create_time
=
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
'创建时间'
)
class
Meta
:
managed
=
False
situ_db_label
=
'afc'
db_table
=
'gcap_records'
class
PriorityApplication
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
# 联合索引
business_type
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"业务类型"
)
# 联合索引
on_off
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
"是否有效"
)
# 联合索引
update_time
=
models
.
DateTimeField
(
auto_now
=
True
,
verbose_name
=
'修改时间'
)
create_time
=
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
'创建时间'
)
...
...
src/apps/doc/named_enum.py
View file @
a2fbe7b
...
...
@@ -7,3 +7,27 @@ class DocStatus(NamedEnum):
PROCESS_FAILED
=
(
2
,
'识别失败'
)
UPLOAD_FAILED
=
(
3
,
'同步失败'
)
COMPLETE
=
(
4
,
'已完成'
)
class
DocScheme
(
NamedEnum
):
ACCEPTANCE
=
(
0
,
"Acceptance"
)
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"
)
HIL
=
(
1
,
'CO00002'
)
class
DataSource
(
NamedEnum
):
POS
=
(
0
,
"POS"
)
EAPP
=
(
1
,
'EAPP'
)
ECONTRACT
=
(
2
,
'Econtract'
)
...
...
src/apps/doc/views.py
View file @
a2fbe7b
...
...
@@ -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
from
.models
import
UploadDocRecords
,
DocStatus
,
HILDoc
,
AFCDoc
,
PriorityApplication
,
GCAPRecords
from
.mixins
import
DocHandler
from
.
import
consts
...
...
@@ -70,10 +70,17 @@ upload_pdf_args = {
'pdf_file'
:
fields
.
Raw
(
required
=
True
),
}
application_information
=
{
"SUBMIT_DATETIME"
:
fields
.
DateTime
(
required
=
True
),
"STATUS"
:
fields
.
Int
(
required
=
True
),
"RATING"
:
fields
.
Int
(
required
=
True
),
"APPLICATION_ID"
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
100
)),
"APPLICATION_VERSION"
:
fields
.
Int
(
required
=
True
),
"INTERMEDIATE_DECISION"
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
100
)),
}
priority_doc_args
=
{
'applicationId'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
64
)),
'businessType'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
OneOf
(
consts
.
BUSINESS_TYPE
)),
'APPLICATION_INFORMATION'
:
fields
.
Nested
(
application_information
,
required
=
True
)
}
...
...
@@ -158,17 +165,34 @@ class PriorityDocView(GenericView):
# 优先级订单接口
@use_args
(
priority_doc_args
,
location
=
'data'
)
def
post
(
self
,
request
,
args
):
application_id
=
args
.
get
(
'applicationId'
)
business_type
=
args
.
get
(
'businessType'
)
application_info
=
args
.
get
(
'APPLICATION_INFORMATION'
)
application_id
=
application_info
.
get
(
'APPLICATION_ID'
)
submit_datetime
=
application_info
.
get
(
'SUBMIT_DATETIME'
)
submit_datetime
=
timezone
.
make_naive
(
submit_datetime
,
timezone
.
get_current_timezone
())
print
(
submit_datetime
)
GCAPRecords
.
objects
.
create
(
status
=
application_info
.
get
(
'STATUS'
),
rating
=
application_info
.
get
(
'RATING'
),
application_id
=
application_id
,
application_version
=
application_info
.
get
(
'APPLICATION_VERSION'
),
intermediate_decision
=
application_info
.
get
(
'INTERMEDIATE_DECISION'
),
submit_datetime
=
submit_datetime
,
)
_
,
created
=
PriorityApplication
.
objects
.
update_or_create
(
application_id
=
application_id
,
business_type
=
business_type
,
defaults
=
{
'on_off'
:
True
})
if
created
:
doc_class
,
prefix
=
(
HILDoc
,
consts
.
HIL_PREFIX
)
if
business_type
==
consts
.
HIL_PREFIX
\
else
(
AFCDoc
,
consts
.
AFC_PREFIX
)
doc_ids
=
doc_class
.
objects
.
filter
(
application_id
=
application_id
,
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
task_str_list
=
[
'{0}_{1}'
.
format
(
prefix
,
doc_id
)
for
doc_id
in
doc_ids
]
if
not
task_str_list
:
self
.
running_log
.
info
(
'[priority doc success] [args={0}] [task_str_list={1}]'
.
format
(
args
,
task_str_list
))
else
:
enqueue_res
=
rh
.
enqueue
(
task_str_list
,
is_priority
=
True
)
self
.
running_log
.
info
(
'[priority doc success] [args={0}] [task_str_list={1}] [enqueue_res={2}]'
.
format
(
args
,
task_str_list
,
enqueue_res
))
...
...
@@ -192,7 +216,7 @@ class DocView(GenericView, DocHandler):
create_time_end
=
args
.
get
(
'create_time_end'
)
status_query
=
Q
(
status
=
status
)
if
status
is
not
None
else
Q
()
application_id_query
=
Q
(
application_id
=
application_id
)
if
application_id
is
not
None
else
Q
()
application_id_query
=
Q
(
application_id
__contains
=
application_id
)
if
application_id
is
not
None
else
Q
()
data_source_query
=
Q
(
data_source
=
data_source
)
if
data_source
is
not
None
else
Q
()
upload_finish_time_query
=
Q
(
upload_finish_time__gte
=
upload_time_start
,
upload_finish_time__lt
=
upload_time_end
+
datetime
.
timedelta
(
days
=
1
))
\
...
...
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