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
50ad42a7
authored
2020-09-22 15:48:46 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
mysql --> mssql
1 parent
a7e918d7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
22 deletions
src/apps/doc/models.py
src/apps/doc/views.py
src/common/tools/mssql_script.py
src/settings/__init__.py
src/settings/database.py
src/apps/doc/models.py
View file @
50ad42a
...
...
@@ -7,7 +7,7 @@ from .named_enum import DocStatus, KeywordsType
# 上传文件记录表/任务表
class
UploadDocRecords
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
metadata_version_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"元数据版本id"
)
metadata_version_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"元数据版本id"
)
# 索引
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
main_applicant
=
models
.
CharField
(
max_length
=
16
,
verbose_name
=
"主申请人"
)
co_applicant
=
models
.
CharField
(
max_length
=
16
,
verbose_name
=
"共同申请人"
)
...
...
@@ -28,7 +28,6 @@ class UploadDocRecords(models.Model):
class
HILDoc
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
record_id
=
models
.
IntegerField
(
verbose_name
=
'记录id'
)
metadata_version_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"元数据版本id"
)
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
# 联合索引
status
=
models
.
SmallIntegerField
(
default
=
DocStatus
.
INIT
.
value
,
verbose_name
=
"文件状态"
)
# 联合索引
...
...
@@ -50,7 +49,6 @@ class HILDoc(models.Model):
class
AFCDoc
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
record_id
=
models
.
IntegerField
(
verbose_name
=
'记录id'
)
metadata_version_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"元数据版本id"
)
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
status
=
models
.
SmallIntegerField
(
default
=
DocStatus
.
INIT
.
value
,
verbose_name
=
"文件状态"
)
...
...
@@ -76,7 +74,7 @@ class GCAPRecords(models.Model):
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_id
=
models
.
CharField
(
max_length
=
64
,
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
=
'提交时间'
)
...
...
src/apps/doc/views.py
View file @
50ad42a
...
...
@@ -106,7 +106,7 @@ class UploadDocView(GenericView, DocHandler):
data_source
=
document
.
get
(
'dataSource'
)
try
:
# 1. 上传信息记录
record
=
UploadDocRecords
.
objects
.
create
(
UploadDocRecords
.
objects
.
create
(
metadata_version_id
=
document
.
get
(
'metadataVersionId'
),
application_id
=
application_id
,
main_applicant
=
applicant_data
.
get
(
'mainApplicantName'
),
...
...
@@ -126,7 +126,6 @@ class UploadDocView(GenericView, DocHandler):
# 2. 根据业务类型分库存储
doc_class
,
prefix
=
self
.
get_doc_class
(
business_type
)
doc
=
doc_class
.
objects
.
create
(
record_id
=
record
.
id
,
metadata_version_id
=
document
.
get
(
'metadataVersionId'
),
application_id
=
application_id
,
main_applicant
=
applicant_data
.
get
(
'mainApplicantName'
),
...
...
@@ -142,8 +141,8 @@ class UploadDocView(GenericView, DocHandler):
is_priority
=
PriorityApplication
.
objects
.
filter
(
application_id
=
application_id
,
on_off
=
True
)
.
exists
()
tasks
=
[
'{0}{1}{2}'
.
format
(
prefix
,
consts
.
SPLIT_STR
,
doc
.
id
)]
enqueue_res
=
rh
.
enqueue
(
tasks
,
is_priority
)
self
.
running_log
.
info
(
'[doc upload success] [args={0}] [
record_id={1}] [business_type={2}] [doc_id={3
}] '
'[is_priority={
4}] [enqueue_res={5}]'
.
format
(
args
,
record
.
id
,
prefix
,
doc
.
id
,
self
.
running_log
.
info
(
'[doc upload success] [args={0}] [
business_type={1}] [doc_id={2
}] '
'[is_priority={
3}] [enqueue_res={4}]'
.
format
(
args
,
prefix
,
doc
.
id
,
is_priority
,
enqueue_res
))
return
response
.
ok
()
...
...
@@ -279,7 +278,7 @@ class DocView(GenericView, DocHandler):
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
(
UploadDocRecords
.
objects
.
create
(
metadata_version_id
=
metadata_version_id
,
application_id
=
application_id
,
main_applicant
=
''
,
...
...
@@ -296,7 +295,6 @@ class DocView(GenericView, DocHandler):
# 2. 根据业务类型分库存储
doc_class
,
prefix
=
self
.
get_doc_class
(
business_type
)
doc
=
doc_class
.
objects
.
create
(
record_id
=
record
.
id
,
metadata_version_id
=
metadata_version_id
,
application_id
=
application_id
,
main_applicant
=
''
,
...
...
@@ -319,7 +317,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}] [business_type={2}] [doc_id={3
}] '
'[is_priority={
4}] [enqueue_res={5}]'
.
format
(
args
,
record
.
id
,
prefix
,
doc
.
id
,
self
.
running_log
.
info
(
'[mock doc upload success] [args={0}] [
business_type={1}] [doc_id={2
}] '
'[is_priority={
3}] [enqueue_res={4}]'
.
format
(
args
,
prefix
,
doc
.
id
,
is_priority
,
enqueue_res
))
return
response
.
ok
()
...
...
src/common/tools/mssql_script.py
0 → 100644
View file @
50ad42a
This diff is collapsed.
Click to expand it.
src/settings/__init__.py
View file @
50ad42a
...
...
@@ -95,8 +95,15 @@ DATABASES = {
'default'
:
conf
.
get_namespace
(
'MYSQL_DEFAULT_'
),
'afc'
:
conf
.
get_namespace
(
'MYSQL_AFC_'
)
}
for
db_setting
in
DATABASES
.
values
():
db_setting
[
'OPTIONS'
]
=
{
'driver'
:
'ODBC Driver 17 for SQL Server'
}
DATABASE_ROUTERS
=
[
'settings.database.DBRouter'
]
MYSQLPOOL_ARGUMENTS
=
database
.
MYSQLPOOL_ARGUMENTS
#
MYSQLPOOL_ARGUMENTS = database.MYSQLPOOL_ARGUMENTS
# Password validation
...
...
@@ -180,3 +187,5 @@ OAUTH2_PROVIDER = {
# this is the list of available scopes
'SCOPES'
:
{
'read'
:
'Read scope'
,
'write'
:
'Write scope'
}
}
# print(DATABASES)
...
...
src/settings/database.py
View file @
50ad42a
...
...
@@ -2,10 +2,10 @@
Database
https://docs.djangoproject.com/en/1.11/ref/settings/#databases
"""
import
pymysql
#
import pymysql
from
django.db.models
import
options
pymysql
.
install_as_MySQLdb
()
#
pymysql.install_as_MySQLdb()
# 同一App下的Model可能会存储到不同的db,所以根据app_label来做db_router不是特别合适
# 所以添加situ_db_label来映射model到db
...
...
@@ -13,13 +13,13 @@ pymysql.install_as_MySQLdb()
options
.
DEFAULT_NAMES
=
tuple
(
list
(
options
.
DEFAULT_NAMES
)
+
[
'situ_db_label'
])
# 数据库连接池配置
MYSQLPOOL_ARGUMENTS
=
{
'recycle'
:
30
,
'pool_size'
:
64
,
'max_overflow'
:
10
,
'timeout'
:
5
,
'use_threadlocal'
:
False
,
}
#
MYSQLPOOL_ARGUMENTS = {
#
'recycle': 30,
#
'pool_size': 64,
#
'max_overflow': 10,
#
'timeout': 5,
#
'use_threadlocal': False,
#
}
class
DBRouter
(
object
):
...
...
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