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
b197e486
authored
2021-09-13 21:22:48 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
cms part 2
1 parent
03fecf38
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
173 additions
and
21 deletions
src/apps/doc/consts.py
src/apps/doc/models.py
src/apps/doc/views.py
src/celery_compare/tasks.py
src/common/tools/3des.py → src/common/tools/des.py
src/common/tools/mssql_script9.py
src/apps/doc/consts.py
View file @
b197e48
...
...
@@ -1683,3 +1683,11 @@ TENANT_MAP = {
AFC_PREFIX
:
1
,
HIL_PREFIX
:
2
,
}
APPLICANT_TYPE_MAP
=
{
'Borrower'
:
'CUSTR'
,
'Co Borrower'
:
'COAPP'
,
'Guarantor'
:
'GAUTR1'
,
'Mortgager'
:
'GAUTR2'
}
...
...
src/apps/doc/models.py
View file @
b197e48
...
...
@@ -244,6 +244,33 @@ class HILSEComparisonInfo(models.Model):
# 比对信息表
class
AFCSECMSInfo
(
models
.
Model
):
id
=
models
.
BigAutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
# 索引
content
=
models
.
TextField
(
verbose_name
=
"CMS信息"
)
update_time
=
models
.
DateTimeField
(
auto_now
=
True
,
verbose_name
=
'修改时间'
)
create_time
=
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
'创建时间'
)
# 索引
class
Meta
:
managed
=
False
db_table
=
'afc_se_cms_info'
situ_db_label
=
'afc'
# 比对信息表
class
HILSECMSInfo
(
models
.
Model
):
id
=
models
.
BigAutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
# 索引
content
=
models
.
TextField
(
verbose_name
=
"CMS信息"
)
update_time
=
models
.
DateTimeField
(
auto_now
=
True
,
verbose_name
=
'修改时间'
)
create_time
=
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
'创建时间'
)
# 索引
class
Meta
:
managed
=
False
db_table
=
'hil_se_cms_info'
# 比对信息表
class
HILComparisonInfo
(
models
.
Model
):
id
=
models
.
BigAutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
uniq_seq
=
models
.
CharField
(
max_length
=
128
,
verbose_name
=
"唯一序列号"
)
# 索引?
...
...
src/apps/doc/views.py
View file @
b197e48
...
...
@@ -22,8 +22,10 @@ from .models import (
GCAPRecords
,
AFCComparisonInfo
,
AFCSEComparisonInfo
,
AFCSECMSInfo
,
HILComparisonInfo
,
HILSEComparisonInfo
,
HILSECMSInfo
,
AFCCompareOfflineReport
,
HILCompareOfflineReport
,
AFCCACompareResult
,
...
...
@@ -1091,10 +1093,20 @@ class SECMSView(GenericView):
# pos上传比对信息接口 SE
@use_args
(
se_cms_args
,
location
=
'data'
)
def
post
(
self
,
request
,
args
):
cms_info
=
args
.
get
(
'content'
,
{})
business_type
=
consts
.
AFC_PREFIX
if
cms_info
.
get
(
'financeCompany'
,
''
)
.
startswith
(
'宝马'
)
else
consts
.
HIL_PREFIX
src_application_id
=
cms_info
.
get
(
'settlemnetVerification'
,
{})
.
get
(
'applicationNo'
,
''
)
application_id
=
src_application_id
[:
src_application_id
.
rfind
(
'-'
)]
content_str
=
json
.
dumps
(
cms_info
)
comparison_class
=
HILSECMSInfo
if
business_type
in
consts
.
HIL_SET
else
AFCSECMSInfo
comparison_class
.
objects
.
create
(
application_id
=
application_id
,
content
=
content_str
,
)
# 触发比对
compare
.
apply_async
((
application_id
,
business_type
,
uniq_seq
,
None
,
False
,
True
),
compare
.
apply_async
((
application_id
,
business_type
,
None
,
None
,
False
,
True
),
queue
=
'queue_compare'
)
return
response
.
ok
()
...
...
src/celery_compare/tasks.py
View file @
b197e48
...
...
@@ -13,8 +13,10 @@ from apps.doc.models import (
HILSEOCRResult
,
AFCComparisonInfo
,
AFCSEComparisonInfo
,
AFCSECMSInfo
,
HILComparisonInfo
,
HILSEComparisonInfo
,
HILSECMSInfo
,
Configs
,
HILCompareReport
,
AFCCompareReport
,
...
...
@@ -29,11 +31,13 @@ from apps.doc.ocr.cms import cms
from
apps.doc.exceptions
import
GCAPException
from
apps.doc.named_enum
import
RequestTeam
,
RequestTrigger
,
ProcessName
,
ErrorType
from
common.tools.comparison
import
cp
from
common.tools.des
import
decode_des
compare_log
=
logging
.
getLogger
(
'compare'
)
log_base
=
'[Compare]'
empty_str
=
''
empty_error_type
=
1000
des_key
=
conf
.
CMS_DES_KEY
class
FakePOS
:
...
...
@@ -42,19 +46,11 @@ class FakePOS:
application_id
,
first_submmison_date
,
application_version
,
customer_type
,
individual_cus_info
,
corporate_cus_info
,
vehicle_info
,
bank_info
):
customer_type
):
self
.
application_id
=
application_id
self
.
first_submmison_date
=
first_submmison_date
self
.
application_version
=
application_version
self
.
customer_type
=
customer_type
self
.
individual_cus_info
=
individual_cus_info
self
.
corporate_cus_info
=
corporate_cus_info
self
.
vehicle_info
=
vehicle_info
self
.
bank_info
=
bank_info
def
name_check
(
ocr_res_dict
,
second_ocr_field
,
second_compare_list
,
second_id_num
,
name
):
...
...
@@ -903,7 +899,7 @@ def get_se_compare_info(last_obj, application_entity, detect_list):
return
compare_info
,
is_gsyh
def
rebuild_compare_info
(
last_obj
):
def
rebuild_compare_info
(
last_obj
,
application_id
):
# {
# "content": {
# "financeCompany": "宝马汽车金融有限公司",
...
...
@@ -1005,14 +1001,69 @@ def rebuild_compare_info(last_obj):
# }
# }
return
FakePOS
(
application_id
,
first_submmison_date
,
application_version
,
customer_type
,
individual_cus_info
,
corporate_cus_info
,
vehicle_info
,
bank_info
)
cms_info
=
json
.
loads
(
last_obj
.
content
)
fake_pos
=
FakePOS
(
application_id
,
cms_info
.
get
(
'submissionDate'
,
''
),
cms_info
.
get
(
'applicationVersion'
,
1
),
cms_info
.
get
(
'applicantInformation'
,
[])[
0
]
.
get
(
'customersubType'
,
''
))
fake_pos
.
bank_info
=
json
.
dumps
(
{
'accountNo'
:
decode_des
(
cms_info
.
get
(
'bankAccountDetails'
,
{})
.
get
(
'accountNo'
,
''
),
des_key
),
'bankName'
:
cms_info
.
get
(
'bankAccountDetails'
,
{})
.
get
(
'bankName'
,
''
),
'accountHolderName'
:
cms_info
.
get
(
'bankAccountDetails'
,
{})
.
get
(
'accountHolderName'
,
''
),
}
)
fake_pos
.
vehicle_info
=
json
.
dumps
(
{
'vehicleStatus'
:
cms_info
.
get
(
'vehicleStatus'
,
''
),
'vinNo'
:
cms_info
.
get
(
'vehicleInformation'
,
{})
.
get
(
'vinNo'
,
''
),
'dealer'
:
cms_info
.
get
(
'dealerName'
,
''
),
'vehicleTransactionAmount'
:
str
(
cms_info
.
get
(
'totalFinanceAmount'
,
''
)),
}
)
individual_cus_info
=
[]
for
individual_cus
in
cms_info
.
get
(
'applicantInformation'
,
[]):
id_type
=
id_num
=
id_date
=
second_id_type
=
second_id_num
=
None
for
idx
,
id_info
in
enumerate
(
individual_cus
.
get
(
''
,
[])):
if
idx
>
1
:
break
elif
idx
==
0
:
id_type
=
id_info
.
get
(
'idType'
)
id_num
=
decode_des
(
id_info
.
get
(
'idNum'
))
id_date
=
id_info
.
get
(
'idExpiryDate'
)
else
:
second_id_type
=
id_info
.
get
(
'idType'
)
second_id_num
=
decode_des
(
id_info
.
get
(
'idNum'
))
individual_cus_info
.
append
(
{
'applicantType'
:
consts
.
APPLICANT_TYPE_MAP
.
get
(
individual_cus
.
get
(
'applicantType'
)),
'customerType'
:
individual_cus
.
get
(
'customersubType'
),
'idType'
:
id_type
,
'idNum'
:
id_num
,
'idExpiryDate'
:
id_date
,
'customerName'
:
individual_cus
.
get
(
'name'
),
'dateOfBirth'
:
individual_cus
.
get
(
'dateOfBirth'
,
''
),
'hukouProvince'
:
cms_info
.
get
(
'province'
,
''
),
'secondIdType'
:
second_id_type
,
'secondIdNum'
:
second_id_num
,
'companyName'
:
individual_cus
.
get
(
'name'
),
'selfEmployedSubType'
:
individual_cus
.
get
(
'selfEmployedSubType'
,
''
),
}
)
fake_pos
.
individual_cus_info
=
json
.
dumps
(
individual_cus_info
)
fake_pos
.
corporate_cus_info
=
None
return
fake_pos
def
se_compare_license
(
license_en
,
ocr_res_dict
,
field_list
):
...
...
@@ -1235,7 +1286,7 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
start_time
=
datetime
.
now
()
detect_list
=
se_result_detect
(
ocr_res_dict
)
if
is_cms
:
last_obj
=
rebuild_compare_info
(
last_obj
)
last_obj
=
rebuild_compare_info
(
last_obj
,
application_id
)
compare_info
,
is_gsyh
=
get_se_compare_info
(
last_obj
,
application_entity
,
detect_list
)
compare_result
,
total_fields
,
failed_count
,
successful_at_this_level
,
failure_reason_str
=
se_compare_process
(
compare_info
,
ocr_res_dict
,
is_gsyh
)
...
...
@@ -1331,7 +1382,10 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
if
is_ca
:
comparison_class
=
HILComparisonInfo
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCComparisonInfo
else
:
comparison_class
=
HILSEComparisonInfo
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCSEComparisonInfo
if
application_entity
==
consts
.
HIL_PREFIX
:
comparison_class
=
HILSECMSInfo
if
is_cms
else
HILSEComparisonInfo
else
:
comparison_class
=
AFCSECMSInfo
if
is_cms
else
AFCSEComparisonInfo
last_obj
=
comparison_class
.
objects
.
filter
(
application_id
=
application_id
)
.
last
()
if
last_obj
is
None
:
compare_log
.
info
(
'{0} [comparison info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
...
...
src/common/tools/
3
des.py
→
src/common/tools/des.py
View file @
b197e48
File moved
src/common/tools/mssql_script9.py
0 → 100644
View file @
b197e48
import
pyodbc
hil_sql
=
"""
create table afc_se_cms_info
(
id bigint identity primary key,
application_id nvarchar(64) not null,
content nvarchar(max) not null,
update_time datetime not null,
create_time datetime not null
);
create index afc_se_cms_info_application_id_index
on afc_se_cms_info (application_id);
create index afc_se_cms_info_create_time_index
on afc_se_cms_info (create_time);
"""
afc_sql
=
"""
create table hil_se_cms_info
(
id bigint identity primary key,
application_id nvarchar(64) not null,
content nvarchar(max) not null,
update_time datetime not null,
create_time datetime not null
);
create index hil_se_cms_info_application_id_index
on hil_se_cms_info (application_id);
create index hil_se_cms_info_create_time_index
on hil_se_cms_info (create_time);
"""
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
.
close
()
hil_cnxn
.
close
()
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
.
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