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
05f22d9d
authored
2021-11-06 14:35:03 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'feature/e-contract' into feature/1119
2 parents
64325811
9ff5682c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
120 additions
and
100 deletions
src/apps/doc/consts.py
src/apps/doc/management/commands/ocr_process.py
src/apps/doc/models.py
src/apps/doc/views.py
src/celery_compare/tasks.py
src/common/tools/mssql_script10.py
src/apps/doc/consts.py
View file @
05f22d9
...
...
@@ -18,7 +18,7 @@ HIL_PREFIX = 'HIL'
AFC_PREFIX
=
'AFC'
SPLIT_STR
=
'_'
BUSINESS_TYPE_LIST
=
[
HIL_PREFIX
,
AFC_PREFIX
]
HIL_SET
=
{
'HIL'
,
'HIl'
,
'HiL'
,
'Hil'
,
'hIL'
,
'hIl'
,
'hiL'
,
'hil'
,
'CO00002'
}
HIL_SET
=
{
'HIL'
,
'HIl'
,
'HiL'
,
'Hil'
,
'hIL'
,
'hIl'
,
'hiL'
,
'hil'
,
'CO00002'
,
'SF5_CL'
}
PRIORITY_WORDS
=
{
'muw'
,
'MUW'
,
'42'
,
42
}
TMP_DIR_NAME
=
'OCR_Files'
...
...
@@ -1786,6 +1786,18 @@ FILE_NAME_PREFIX_MAP = {
]
}
ECONTRACT_KEYWORDS_MAP
=
{
AFC_PREFIX
:
[
(
'电子签署-汽车抵押贷款合同'
,
CONTRACT_CLASSIFY
,
0
),
(
'电子签署-抵押登记豁免函'
,
HMH_CLASSIFY
,
0
),
],
HIL_PREFIX
:
[
(
'电子签署-售后回租合同'
,
HIL_CONTRACT_1_CLASSIFY
,
HIL_CONTRACT_3_CLASSIFY
),
(
'电子签署-汽车租赁抵押合同'
,
HIL_CONTRACT_2_CLASSIFY
,
0
),
(
'电子签署-抵押登记豁免函'
,
HMH_CLASSIFY
,
0
),
]
}
HIL_CONTRACT_TYPE_MAP
=
{
str
(
HIL_CONTRACT_1_CLASSIFY
):
0
,
str
(
HIL_CONTRACT_2_CLASSIFY
):
2
,
...
...
src/apps/doc/management/commands/ocr_process.py
View file @
05f22d9
...
...
@@ -947,7 +947,7 @@ class Command(BaseCommand, LoggerMixin):
pdf_handler
=
PDFHandler
(
pdf_path
,
img_save_path
,
doc
.
document_name
)
if
classify_1_str
==
'0'
or
classify_1_str
==
str
(
consts
.
HMH_CLASSIFY
)
:
if
classify_1_str
==
'0'
:
try
:
# 2. 从EDMS获取PDF文件
max_count_obj
=
Configs
.
objects
.
filter
(
id
=
2
)
.
first
()
...
...
src/apps/doc/models.py
View file @
05f22d9
...
...
@@ -789,24 +789,24 @@ class HILCACompareResultRecord(models.Model):
db_table
=
'hil_ca_compare_result_record'
class
HILContract
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
# 索引
create_time
=
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
'创建时间'
)
#
class HILContract(models.Model):
#
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
#
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
#
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
class
Meta
:
managed
=
False
db_table
=
'hil_contract'
#
class Meta:
#
managed = False
#
db_table = 'hil_contract'
class
AFCContract
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
# 索引
create_time
=
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
'创建时间'
)
#
class AFCContract(models.Model):
#
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
#
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
#
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
class
Meta
:
managed
=
False
db_table
=
'afc_contract'
situ_db_label
=
'afc'
#
class Meta:
#
managed = False
#
db_table = 'afc_contract'
#
situ_db_label = 'afc'
...
...
src/apps/doc/views.py
View file @
05f22d9
...
...
@@ -36,14 +36,12 @@ from .models import (
AFCSECompareResultRecord
,
HILCACompareResultRecord
,
HILSECompareResultRecord
,
HILContract
,
AFCContract
,
)
from
.named_enum
import
ErrorType
from
.mixins
import
DocHandler
from
.
import
consts
from
apps.account.authentication
import
OAuth2AuthenticationWithUser
from
celery_compare.tasks
import
compare
,
forwarding_station
from
celery_compare.tasks
import
compare
class
CustomDate
(
fields
.
Date
):
...
...
@@ -497,7 +495,7 @@ class UploadDocView(GenericView, DocHandler):
application_id
=
application_data
.
get
(
'applicationId'
)
document_scheme
=
document
.
get
(
'documentScheme'
)
data_source
=
document
.
get
(
'dataSource'
)
document_name
=
document
.
get
(
'documentName'
)
document_name
=
document
.
get
(
'documentName'
,
''
)
# main_name = self.get_name(applicant_data, 'mainApplicantName', 16)
# co_name = self.get_name(applicant_data, 'coApplicantName', 16)
# g1_name = self.get_name(applicant_data, 'guarantor1Name', 16)
...
...
@@ -522,6 +520,12 @@ class UploadDocView(GenericView, DocHandler):
# self.invalid_params(msg='metadataVersionId repeat')
# else:
data_source
=
self
.
fix_data_source
(
data_source
)
document_scheme
=
self
.
fix_scheme
(
document_scheme
)
if
document_name
.
endswith
(
'.zip'
):
self
.
running_log
.
info
(
'[doc upload success] [zip file skip] [args={0}]'
.
format
(
args
))
return
response
.
ok
()
if
data_source
==
consts
.
DATA_SOURCE_LIST
[
1
]:
if
isinstance
(
document_name
,
str
):
if
document_name
.
endswith
(
'-证书.pdf'
)
or
document_name
.
endswith
(
'-证书'
):
...
...
@@ -536,15 +540,23 @@ class UploadDocView(GenericView, DocHandler):
# co_applicant=applicant_data.get('coApplicantName'),
# guarantor_1=applicant_data.get('guarantor1Name'),
# guarantor_2=applicant_data.get('guarantor2Name'),
document_name
=
document
.
get
(
'documentName'
)
,
document_scheme
=
self
.
fix_scheme
(
document_scheme
)
,
data_source
=
self
.
fix_data_source
(
data_source
)
,
document_name
=
document
_name
,
document_scheme
=
document_scheme
,
data_source
=
data_source
,
upload_finish_time
=
document
.
get
(
'uploadFinishTime'
),
)
# 3. 选择队列进入
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
)
classify_1
=
classify_2
=
0
if
data_source
==
consts
.
DATA_SOURCE_LIST
[
-
1
]
and
document_scheme
==
consts
.
DOC_SCHEME_LIST
[
1
]:
for
keyword
,
classify_1_tmp
,
classify_2_tmp
in
consts
.
FILE_NAME_PREFIX_MAP
.
get
(
prefix
):
if
keyword
in
document_name
:
classify_1
=
classify_1_tmp
classify_2
=
classify_2_tmp
break
task
=
consts
.
SPLIT_STR
.
join
([
prefix
,
str
(
doc
.
id
),
str
(
classify_1
),
str
(
classify_2
)])
enqueue_res
=
rh
.
enqueue
([
task
],
is_priority
)
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
))
...
...
@@ -1168,11 +1180,11 @@ class SEContractView(GenericView):
# pos上传e-contract信息接口 SE
@use_args
(
se_contract_args
,
location
=
'data'
)
def
post
(
self
,
request
,
args
):
contract_info
=
args
.
get
(
'content'
,
{})
application_id
=
contract_info
.
get
(
'applicationId'
,
''
)
entity
=
contract_info
.
get
(
'applicationEntity'
,
''
)
table_class
=
HILContract
if
entity
==
consts
.
HIL_PREFIX
else
AFCContract
table_class
.
objects
.
create
(
application_id
=
application_id
)
forwarding_station
.
apply_async
((
application_id
,
entity
),
queue
=
'queue_compare'
,
countdown
=
conf
.
DELAY_SECONDS
)
self
.
running_log
.
info
(
'[e-contract
] [application_id={0}] [entity={1}]'
.
format
(
application_id
,
entity
))
#
contract_info = args.get('content', {})
#
application_id = contract_info.get('applicationId', '')
#
entity = contract_info.get('applicationEntity', '')
#
table_class = HILContract if entity == consts.HIL_PREFIX else AFCContract
#
table_class.objects.create(application_id=application_id)
#
forwarding_station.apply_async((application_id, entity), queue='queue_compare', countdown=conf.DELAY_SECONDS)
self
.
running_log
.
info
(
'[e-contract
pos in] [args={0}]'
.
format
(
args
))
return
response
.
ok
()
...
...
src/celery_compare/tasks.py
View file @
05f22d9
...
...
@@ -27,13 +27,10 @@ from apps.doc.models import (
AFCCACompareResult
,
HILSECompareResult
,
HILCACompareResult
,
AFCDoc
,
HILDoc
)
from
apps.doc
import
consts
from
apps.doc.ocr.gcap
import
gcap
from
apps.doc.ocr.cms
import
cms
from
apps.doc.ocr.ecm
import
ECM
,
rh
from
apps.doc.exceptions
import
GCAPException
from
apps.doc.named_enum
import
RequestTeam
,
RequestTrigger
,
ProcessName
,
ErrorType
from
common.tools.comparison
import
cp
...
...
@@ -41,11 +38,10 @@ from common.tools.des import decode_des
compare_log
=
logging
.
getLogger
(
'compare'
)
log_base
=
'[Compare]'
e_log_base
=
'[e-contract]'
#
e_log_base = '[e-contract]'
empty_str
=
''
empty_error_type
=
1000
des_key
=
conf
.
CMS_DES_KEY
ecm
=
ECM
()
def
rotate_bound
(
image
,
angle
):
...
...
@@ -1872,32 +1868,32 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
se_compare
(
application_id
,
application_entity
,
ocr_res_id
,
last_obj
,
ocr_res_dict
,
is_cms
)
@app.task
def
forwarding_station
(
application_id
,
entity
):
compare_log
.
info
(
'{0} [forward start] [application_id={1}] [entity={2}]'
.
format
(
e_log_base
,
application_id
,
entity
))
doc_class
=
HILDoc
if
entity
in
consts
.
HIL_SET
else
AFCDoc
entity_prefix
=
consts
.
HIL_PREFIX
if
entity
in
consts
.
HIL_SET
else
consts
.
AFC_PREFIX
for
(
classify_1
,
classify_2
),
prefix
in
consts
.
FILE_NAME_PREFIX_MAP
.
get
(
entity
):
try
:
file_list
=
ecm
.
search
(
application_id
,
entity
,
prefix
.
format
(
application_id
))
# TODO 获取最新文件
except
Exception
as
e
:
compare_log
.
error
(
'{0} [search failed] [application_id={1}] [entity={2}] [error={3}]'
.
format
(
e_log_base
,
application_id
,
entity
,
traceback
.
format_exc
()))
else
:
compare_log
.
info
(
'{0} [search end] [application_id={1}] [entity={2}] [file_list={3}]'
.
format
(
e_log_base
,
application_id
,
entity
,
file_list
))
for
object_name
,
object_id
in
file_list
:
doc
=
doc_class
.
objects
.
create
(
metadata_version_id
=
object_id
,
application_id
=
application_id
,
document_name
=
object_name
,
document_scheme
=
'SETTLEMENT'
,
data_source
=
'POS'
,
upload_finish_time
=
datetime
.
now
(),
)
task
=
consts
.
SPLIT_STR
.
join
([
entity_prefix
,
str
(
doc
.
id
),
str
(
classify_1
),
str
(
classify_2
)])
enqueue_res
=
rh
.
enqueue
([
task
],
False
)
compare_log
.
info
(
'{0} [upload success] [res={1}] [application_id={2}] [entity={3}] [object_name={4}] '
'[object_id={5}] [doc_id={6}]'
.
format
(
e_log_base
,
enqueue_res
,
application_id
,
entity
,
object_name
,
object_id
,
doc
.
id
))
compare_log
.
info
(
'{0} [forward end] [application_id={1}] [entity={2}]'
.
format
(
e_log_base
,
application_id
,
entity
))
#
@app.task
#
def forwarding_station(application_id, entity):
#
compare_log.info('{0} [forward start] [application_id={1}] [entity={2}]'.format(e_log_base, application_id, entity))
#
doc_class = HILDoc if entity in consts.HIL_SET else AFCDoc
#
entity_prefix = consts.HIL_PREFIX if entity in consts.HIL_SET else consts.AFC_PREFIX
#
for (classify_1, classify_2), prefix in consts.FILE_NAME_PREFIX_MAP.get(entity):
#
try:
#
file_list = ecm.search(application_id, entity, prefix.format(application_id)) # TODO 获取最新文件
#
except Exception as e:
#
compare_log.error('{0} [search failed] [application_id={1}] [entity={2}] [error={3}]'.format(
#
e_log_base, application_id, entity, traceback.format_exc()))
#
else:
#
compare_log.info('{0} [search end] [application_id={1}] [entity={2}] [file_list={3}]'.format(
#
e_log_base, application_id, entity, file_list))
#
for object_name, object_id in file_list:
#
doc = doc_class.objects.create(
#
metadata_version_id=object_id,
#
application_id=application_id,
#
document_name=object_name,
#
document_scheme='SETTLEMENT',
#
data_source='POS',
#
upload_finish_time=datetime.now(),
#
)
#
task = consts.SPLIT_STR.join([entity_prefix, str(doc.id), str(classify_1), str(classify_2)])
#
enqueue_res = rh.enqueue([task], False)
#
compare_log.info('{0} [upload success] [res={1}] [application_id={2}] [entity={3}] [object_name={4}] '
#
'[object_id={5}] [doc_id={6}]'.format(e_log_base, enqueue_res, application_id, entity,
#
object_name, object_id, doc.id))
#
compare_log.info('{0} [forward end] [application_id={1}] [entity={2}]'.format(e_log_base, application_id, entity))
...
...
src/common/tools/mssql_script10.py
View file @
05f22d9
import
pyodbc
afc_sql
=
"""
create table afc_contract
(
id bigint identity primary key,
application_id nvarchar(64) not null,
create_time datetime not null
);
#
import pyodbc
#
afc_sql = """
#
create table afc_contract
#
(
#
id bigint identity primary key,
#
application_id nvarchar(64) not null,
#
create_time datetime not null
#
);
create index afc_contract_application_id_index
on afc_contract (application_id);
"""
hil_sql
=
"""
create table hil_contract
(
id bigint identity primary key,
application_id nvarchar(64) not null,
create_time datetime not null
);
#
create index afc_contract_application_id_index
#
on afc_contract (application_id);
#
"""
#
hil_sql = """
#
create table hil_contract
#
(
#
id bigint identity primary key,
#
application_id nvarchar(64) not null,
#
create_time datetime not null
#
);
create index hil_contract_application_id_index
on hil_contract (application_id);
"""
#
create index hil_contract_application_id_index
#
on hil_contract (application_id);
#
"""
hil_cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};'
,
autocommit
=
True
)
#
hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
hil_cursor
=
hil_cnxn
.
cursor
()
hil_cursor
.
execute
(
hil_sql
)
#
hil_cursor = hil_cnxn.cursor()
#
hil_cursor.execute(hil_sql)
hil_cursor
.
close
()
hil_cnxn
.
close
()
#
hil_cursor.close()
#
hil_cnxn.close()
afc_cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};'
,
autocommit
=
True
)
#
afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
afc_cursor
=
afc_cnxn
.
cursor
()
afc_cursor
.
execute
(
afc_sql
)
#
afc_cursor = afc_cnxn.cursor()
#
afc_cursor.execute(afc_sql)
afc_cursor
.
close
()
afc_cnxn
.
close
()
#
afc_cursor.close()
#
afc_cnxn.close()
...
...
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