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
ea79bc59
authored
2022-02-14 16:42:22 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add auto bs
1 parent
027e9ba5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
33 deletions
src/apps/doc/consts.py
src/apps/doc/management/commands/ocr_process.py
src/celery_compare/tasks.py
src/common/tools/comparison.py
src/apps/doc/consts.py
View file @
ea79bc5
...
...
@@ -1189,7 +1189,7 @@ BS_FIELD = 'bss_ocr'
HIL_CONTRACT_1_FIELD
=
'hil_contract_1_ocr'
HIL_CONTRACT_2_FIELD
=
'hil_contract_2_ocr'
HIL_CONTRACT_3_FIELD
=
'hil_contract_3_ocr'
BS_CLASSIFY
=
1008
7
BS_CLASSIFY
=
1008
9
RESULT_MAPPING
=
{
MVI_CLASSIFY
:
MVI_OCR_FIELD
,
...
...
@@ -1653,6 +1653,8 @@ HIL_CONTRACT_1_EN = '售后回租合同'
HIL_CONTRACT_2_EN
=
'车辆租赁抵押合同'
HIL_CONTRACT_3_EN
=
'车辆处置协议'
DDA_NO_FIND
=
'需人工查看DDA或截图'
SKIP_CARD
=
{
SME_BL_EN
}
...
...
@@ -1808,17 +1810,29 @@ BD_COMPARE_LOGIC = {
}
BS_COMPARE_LOGIC
=
{
'户名'
:
(
'role'
,
'se_one_compare'
,
{},
'主共借人未提供银行流水'
),
'(担保人1)户名'
:
(
'role'
,
'se_name_compare'
,
{},
'担保人1未提供银行流水'
),
'(担保人2)户名'
:
(
'role'
,
'se_name_compare'
,
{},
'担保人2未提供银行流水'
),
'打印日期'
:
(
'print_time'
,
'se_bs_print_date_compare'
,
{},
'主共借人银行流水打印日期超过15天'
),
'(担保人1)打印日期'
:
(
'print_time'
,
'se_bs_print_date_compare'
,
{},
'担保人1银行流水打印日期超过15天'
),
'(担保人2)打印日期'
:
(
'print_time'
,
'se_bs_print_date_compare'
,
{},
'担保人2银行流水打印日期超过15天'
),
'户名'
:
(
'role'
,
'se_
bs_
one_compare'
,
{},
'主共借人未提供银行流水'
),
'(担保人1)户名'
:
(
'role'
,
'se_
bs_
name_compare'
,
{},
'担保人1未提供银行流水'
),
'(担保人2)户名'
:
(
'role'
,
'se_
bs_
name_compare'
,
{},
'担保人2未提供银行流水'
),
'打印日期'
:
(
'print_time'
,
'se_bs_print_date_compare'
,
{
'days'
:
15
},
'主共借人银行流水打印日期超过15天'
),
'(担保人1)打印日期'
:
(
'print_time'
,
'se_bs_print_date_compare'
,
{
'days'
:
15
},
'担保人1银行流水打印日期超过15天'
),
'(担保人2)打印日期'
:
(
'print_time'
,
'se_bs_print_date_compare'
,
{
'days'
:
15
},
'担保人2银行流水打印日期超过15天'
),
'流水日期'
:
(
'timedelta'
,
'se_bs_date_compare'
,
{},
'主共借人银行流水日期不满足3个月'
),
'(担保人1)流水日期'
:
(
'timedelta'
,
'se_bs_date_compare'
,
{},
'担保人1银行流水日期不满足3个月'
),
'(担保人2)流水日期'
:
(
'timedelta'
,
'se_bs_date_compare'
,
{},
'担保人2银行流水日期不满足3个月'
),
}
BS_COMPARE_LOGIC_AUTO
=
{
'户名'
:
(
'role'
,
'se_bs_one_compare'
,
{},
'主共借人未提供银行流水'
),
'(担保人1)户名'
:
(
'role'
,
'se_bs_name_compare'
,
{},
'担保人1未提供银行流水'
),
'(担保人2)户名'
:
(
'role'
,
'se_bs_name_compare'
,
{},
'担保人2未提供银行流水'
),
'打印日期'
:
(
'print_time'
,
'se_bs_print_date_compare'
,
{
'days'
:
30
},
'主共借人银行流水打印日期超过30天'
),
'(担保人1)打印日期'
:
(
'print_time'
,
'se_bs_print_date_compare'
,
{
'days'
:
30
},
'担保人1银行流水打印日期超过30天'
),
'(担保人2)打印日期'
:
(
'print_time'
,
'se_bs_print_date_compare'
,
{
'days'
:
30
},
'担保人2银行流水打印日期超过30天'
),
'流水日期'
:
(
'timedelta'
,
'se_bs_date_compare'
,
{},
'主共借人银行流水日期不满足2个月'
),
'(担保人1)流水日期'
:
(
'timedelta'
,
'se_bs_date_compare'
,
{},
'担保人1银行流水日期不满足2个月'
),
'(担保人2)流水日期'
:
(
'timedelta'
,
'se_bs_date_compare'
,
{},
'担保人2银行流水日期不满足2个月'
),
}
SPECIAL_REASON
=
'主共借人未提供银行流水,含担保人需人工查看直系亲属关系'
SPECIAL_REASON_2
=
'担保人未提供银行流水,需人工查看直系亲属关系'
SPECIAL_REASON_3
=
'未提供银行流水'
...
...
@@ -1968,6 +1982,10 @@ SE_COMPARE_FIELD = {
HIL_CONTRACT_3_EN
:
(
HIL_CONTRACT_3_FIELD
,
HIL_CONTRACT_3_COMPARE_LOGIC
,
False
),
}
SE_COMPARE_FIELD_AUTO
=
{
BS_EN
:
(
BS_FIELD
,
BS_COMPARE_LOGIC_AUTO
,
False
),
}
SE_FIRST_ID_FIELD_MAPPING
=
{
'ITPRC'
:
(
ID_EN
,
SE_ID_CARD_FIELD
),
...
...
src/apps/doc/management/commands/ocr_process.py
View file @
ea79bc5
...
...
@@ -362,8 +362,9 @@ class Command(BaseCommand, LoggerMixin):
consts
.
IMG_PATH_KEY
:
img_path
,
consts
.
SECTION_IMG_PATH_KEY
:
section_img_path
,
}
# 'position': {'left': 470, 'top': 671, 'right': 542, 'bottom': 694}
# position_dict = {
# '': {consts.FIELD_POSITION_KEY: {}}
# '
被保险人姓名
': {consts.FIELD_POSITION_KEY: {}}
# }
# insurance_ocr_result[consts.ALL_POSITION_KEY] = position_dict
license_summary
.
setdefault
(
classify
,
[])
.
append
(
insurance_ocr_result
)
...
...
src/celery_compare/tasks.py
View file @
ea79bc5
...
...
@@ -872,7 +872,7 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
traceback
.
format_exc
()))
def
get_se_cms_compare_info_auto
(
last_obj
,
application_entity
):
def
get_se_cms_compare_info_auto
(
last_obj
,
application_entity
,
auto
=
True
):
cms_info
=
json
.
loads
(
last_obj
.
content
)
compare_info
=
{}
...
...
@@ -1072,6 +1072,7 @@ def get_se_cms_compare_info_auto(last_obj, application_entity):
# 银行流水 --------------------------------------------------------------------
if
cms_info
.
get
(
'autoApprovedDetails'
,
{})
.
get
(
'aaType'
,
''
)
in
[
'CAA1'
,
'CAA2'
]:
date_timedelta
=
60
if
auto
else
90
bs_role_list
=
[]
for
applicant_type
in
consts
.
APPLICANT_TYPE_ORDER
[:
2
]:
if
applicant_type
in
main_role_info
:
...
...
@@ -1082,7 +1083,7 @@ def get_se_cms_compare_info_auto(last_obj, application_entity):
bs_field_input
=
[
(
consts
.
SE_BS_FIELD
[
0
],
bs_role_list
),
(
consts
.
SE_BS_FIELD
[
1
],
first_submission_date
),
(
consts
.
SE_BS_FIELD
[
2
],
90
),
(
consts
.
SE_BS_FIELD
[
2
],
date_timedelta
),
]
dbr_bs_role_list
=
[]
...
...
@@ -1093,13 +1094,13 @@ def get_se_cms_compare_info_auto(last_obj, application_entity):
bs_field_input
.
extend
([
(
consts
.
SE_BS_FIELD
[
3
],
dbr_bs_role_list
[
0
]),
(
consts
.
SE_BS_FIELD
[
4
],
first_submission_date
),
(
consts
.
SE_BS_FIELD
[
5
],
90
),
(
consts
.
SE_BS_FIELD
[
5
],
date_timedelta
),
])
if
len
(
dbr_bs_role_list
)
>=
2
:
bs_field_input
.
extend
([
(
consts
.
SE_BS_FIELD
[
6
],
dbr_bs_role_list
[
1
]),
(
consts
.
SE_BS_FIELD
[
7
],
first_submission_date
),
(
consts
.
SE_BS_FIELD
[
8
],
90
),
(
consts
.
SE_BS_FIELD
[
8
],
date_timedelta
),
])
bs_info
[
consts
.
BS_EN
]
=
bs_field_input
compare_info
[
'Bank Statement'
]
=
bs_info
...
...
@@ -1358,7 +1359,7 @@ def get_se_cms_compare_info_auto(last_obj, application_entity):
return
compare_info
,
cms_info
.
get
(
'autoApprovedDetails'
,
{})
.
get
(
'aaType'
,
''
),
is_gsyh
def
get_se_cms_compare_info
(
last_obj
,
application_entity
,
detect_list
):
def
get_se_cms_compare_info
(
last_obj
,
application_entity
,
detect_list
,
auto
=
False
):
cms_info
=
json
.
loads
(
last_obj
.
content
)
compare_info
=
{}
...
...
@@ -1402,13 +1403,17 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
(
'businessLicenseNo'
,
id_num
),
(
'organizationCreditCode'
,
id_num
),
(
'taxRegistrationCertificateNo'
,
id_num
),
(
'establishmentDate'
,
establishment_date
),
(
'businessLicenseDueDate'
,
id_info
.
get
(
'idExpiryDate'
,
''
)),
]
license_dict
[
consts
.
BL_EN
]
=
bl_field_input
all_id_num
.
append
(
id_num
)
if
individual_info
.
get
(
'customersubType'
,
''
)
==
'Corporate'
:
company_info_list
.
append
((
customer_name
,
id_num
,
legal_name
))
else
:
bl_field_input
.
append
((
'establishmentDate'
,
establishment_date
))
license_dict
[
consts
.
BL_EN
]
=
bl_field_input
all_id_num
.
append
(
id_num
)
# SME营业执照---------------------------------------------------------------------------------------------------
# if individual_info.get('customersubType', '').startswith('Self Employed'):
...
...
@@ -1437,7 +1442,14 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
dda_name_list
=
[]
dda_num_list
=
[]
for
applicant_type
in
consts
.
APPLICANT_TYPE_ORDER
[:
2
]:
if
len
(
company_info_list
)
>
0
:
tmp_idx
=
1
company_info
=
company_info_list
[
0
]
else
:
tmp_idx
=
0
company_info
=
None
for
applicant_type
in
consts
.
APPLICANT_TYPE_ORDER
[
tmp_idx
:
tmp_idx
+
2
]:
if
applicant_type
in
main_role_info
:
for
dda_name_part
,
_
,
dda_num_part
in
main_role_info
[
applicant_type
]:
dda_name_list
.
append
(
dda_name_part
)
...
...
@@ -1446,11 +1458,6 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
dda_num
=
'、'
.
join
(
dda_num_list
)
# del main_role_info
if
len
(
company_info_list
)
>
0
:
company_info
=
company_info_list
[
0
]
else
:
company_info
=
None
vehicle_info
=
{}
vehicle_field_input
=
[]
vehicle_status
=
cms_info
.
get
(
'vehicleStatus'
,
''
)
...
...
@@ -1555,6 +1562,7 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
# 银行流水 --------------------------------------------------------------------
if
cms_info
.
get
(
'autoApprovedDetails'
,
{})
.
get
(
'aaType'
,
''
)
in
[
'CAA1'
,
'CAA2'
]:
date_timedelta
=
60
if
auto
else
90
bs_role_list
=
[]
for
applicant_type
in
consts
.
APPLICANT_TYPE_ORDER
[:
2
]:
if
applicant_type
in
main_role_info
:
...
...
@@ -1565,7 +1573,7 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
bs_field_input
=
[
(
consts
.
SE_BS_FIELD
[
0
],
bs_role_list
),
(
consts
.
SE_BS_FIELD
[
1
],
first_submission_date
),
(
consts
.
SE_BS_FIELD
[
2
],
90
),
(
consts
.
SE_BS_FIELD
[
2
],
date_timedelta
),
]
dbr_bs_role_list
=
[]
...
...
@@ -1576,13 +1584,13 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
bs_field_input
.
extend
([
(
consts
.
SE_BS_FIELD
[
3
],
dbr_bs_role_list
[
0
]),
(
consts
.
SE_BS_FIELD
[
4
],
first_submission_date
),
(
consts
.
SE_BS_FIELD
[
5
],
90
),
(
consts
.
SE_BS_FIELD
[
5
],
date_timedelta
),
])
if
len
(
dbr_bs_role_list
)
>=
2
:
bs_field_input
.
extend
([
(
consts
.
SE_BS_FIELD
[
6
],
dbr_bs_role_list
[
1
]),
(
consts
.
SE_BS_FIELD
[
7
],
first_submission_date
),
(
consts
.
SE_BS_FIELD
[
8
],
90
),
(
consts
.
SE_BS_FIELD
[
8
],
date_timedelta
),
])
bs_info
[
consts
.
BS_EN
]
=
bs_field_input
compare_info
[
'Bank Statement'
]
=
bs_info
...
...
@@ -2012,11 +2020,14 @@ def get_se_compare_info(last_obj, application_entity, detect_list):
return
compare_info
,
is_gsyh
def
se_bs_compare
(
license_en
,
ocr_res_dict
,
strip_list
):
def
se_bs_compare
(
license_en
,
ocr_res_dict
,
strip_list
,
is_auto
):
# 主共借至少提供一个
# 有担保人,担保人必须提供。主共借没有时,修改comment:人工查看担保人亲属关系
ocr_field
,
compare_logic
,
_
=
consts
.
SE_COMPARE_FIELD
[
license_en
]
if
is_auto
:
ocr_field
,
compare_logic
,
_
=
consts
.
SE_COMPARE_FIELD_AUTO
[
license_en
]
else
:
ocr_field
,
compare_logic
,
_
=
consts
.
SE_COMPARE_FIELD
[
license_en
]
ocr_res_str
=
ocr_res_dict
.
get
(
ocr_field
)
result_field_list
=
[]
...
...
@@ -2311,7 +2322,8 @@ def se_compare_license(license_en, ocr_res_dict, field_list):
for
name
,
value
in
field_list
:
if
isinstance
(
value
,
list
):
value
=
json
.
dumps
(
value
,
ensure_ascii
=
False
)
result_field_list
.
append
((
name
,
value
,
consts
.
RESULT_N
,
empty_str
,
empty_str
,
ErrorType
.
NF
.
value
,
'{0}未找到'
.
format
(
license_en
)))
no_find_str
=
consts
.
DDA_NO_FIND
if
license_en
==
consts
.
DDA_EN
else
'{0}未找到'
.
format
(
license_en
)
result_field_list
.
append
((
name
,
value
,
consts
.
RESULT_N
,
empty_str
,
empty_str
,
ErrorType
.
NF
.
value
,
no_find_str
))
if
is_find
:
if
special_expiry_date_slice
:
...
...
@@ -2573,7 +2585,7 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list):
return
result_field_list
,
field_img_path_dict
def
se_compare_process
(
compare_info
,
ocr_res_dict
,
is_gsyh
):
def
se_compare_process
(
compare_info
,
ocr_res_dict
,
is_gsyh
,
is_auto
):
# individualCusInfo
# corporateCusInfo
# vehicleInfo
...
...
@@ -2652,7 +2664,7 @@ def se_compare_process(compare_info, ocr_res_dict, is_gsyh):
elif
license_en
in
[
consts
.
HIL_CONTRACT_1_EN
,
consts
.
HIL_CONTRACT_2_EN
,
consts
.
HIL_CONTRACT_3_EN
,
consts
.
AFC_CONTRACT_EN
]:
result_field_list
,
field_img_path_dict
=
se_contract_compare
(
license_en
,
ocr_res_dict
,
strip_list
,
is_gsyh
)
elif
license_en
==
consts
.
BS_EN
:
result_field_list
,
field_img_path_dict
=
se_bs_compare
(
license_en
,
ocr_res_dict
,
strip_list
)
result_field_list
,
field_img_path_dict
=
se_bs_compare
(
license_en
,
ocr_res_dict
,
strip_list
,
is_auto
)
else
:
result_field_list
,
_
,
field_img_path_dict
=
se_compare_license
(
license_en
,
ocr_res_dict
,
strip_list
)
...
...
@@ -2726,7 +2738,7 @@ def se_compare_auto(application_id, application_entity, ocr_res_id, last_obj, oc
# detect_list = se_result_detect(ocr_res_dict)
compare_info
,
aa_type
,
is_gsyh
=
get_se_cms_compare_info_auto
(
last_obj
,
application_entity
)
compare_result
,
total_fields
,
failed_count
,
successful_at_this_level
,
failure_reason_str
,
cn_failure_reason_str
,
bs_failure_reason_str
=
se_compare_process
(
compare_info
,
ocr_res_dict
,
is_gsyh
)
compare_result
,
total_fields
,
failed_count
,
successful_at_this_level
,
failure_reason_str
,
cn_failure_reason_str
,
bs_failure_reason_str
=
se_compare_process
(
compare_info
,
ocr_res_dict
,
is_gsyh
,
True
)
compare_log
.
info
(
'{0} [Auto SE] [compare success] [entity={1}] [id={2}] [ocr_res_id={3}] [result={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
compare_result
))
except
Exception
as
e
:
...
...
@@ -2773,7 +2785,7 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
else
:
compare_info
,
is_gsyh
=
get_se_compare_info
(
last_obj
,
application_entity
,
detect_list
)
application_version
=
last_obj
.
application_version
compare_result
,
total_fields
,
failed_count
,
successful_at_this_level
,
failure_reason_str
,
cn_failure_reason_str
,
bs_failure_reason_str
=
se_compare_process
(
compare_info
,
ocr_res_dict
,
is_gsyh
)
compare_result
,
total_fields
,
failed_count
,
successful_at_this_level
,
failure_reason_str
,
cn_failure_reason_str
,
bs_failure_reason_str
=
se_compare_process
(
compare_info
,
ocr_res_dict
,
is_gsyh
,
False
)
compare_log
.
info
(
'{0} [SE] [compare success] [entity={1}] [id={2}] [ocr_res_id={3}] [result={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
compare_result
))
except
Exception
as
e
:
...
...
src/common/tools/comparison.py
View file @
ea79bc5
...
...
@@ -249,6 +249,10 @@ class Comparison:
ocr_s
=
ocr_str
.
translate
(
self
.
TRANS
)
return
self
.
build_res
(
input_s
==
ocr_s
)
def
se_bs_name_compare
(
self
,
input_str
,
ocr_str
,
**
kwargs
):
new_ocr_str
=
re
.
sub
(
r'[^\u4e00-\u9fa5]+'
,
''
,
ocr_str
)
return
self
.
build_res
(
input_str
==
new_ocr_str
)
def
ca_name_compare
(
self
,
input_str
,
ocr_str
,
**
kwargs
):
if
kwargs
.
get
(
'is_passport'
):
input_tmp
=
input_str
.
upper
()
.
replace
(
' '
,
''
)
...
...
@@ -438,6 +442,13 @@ class Comparison:
return
self
.
RESULT_Y
return
self
.
RESULT_N
def
se_bs_one_compare
(
self
,
input_list
,
ocr_str
,
**
kwargs
):
if
isinstance
(
input_list
,
list
):
new_ocr_str
=
re
.
sub
(
r'[^\u4e00-\u9fa5]+'
,
''
,
ocr_str
)
if
new_ocr_str
in
input_list
:
return
self
.
RESULT_Y
return
self
.
RESULT_N
def
se_company_compare
(
self
,
input_str
,
ocr_str
,
**
kwargs
):
input_tmp
=
re
.
sub
(
self
.
re_obj
,
''
,
input_str
)
.
strip
()
ocr_tmp
=
re
.
sub
(
self
.
re_obj
,
''
,
ocr_str
)
.
strip
()
...
...
@@ -524,7 +535,7 @@ class Comparison:
try
:
input_date
=
datetime
.
strptime
(
input_str
,
"
%
Y-
%
m-
%
d"
)
ocr_date
=
datetime
.
strptime
(
ocr_str
,
"
%
Y-
%
m-
%
d"
)
if
ocr_date
>=
input_date
-
relativedelta
(
days
=
15
):
if
ocr_date
>=
input_date
-
relativedelta
(
days
=
kwargs
.
get
(
'days'
,
15
)
):
return
self
.
RESULT_Y
return
self
.
RESULT_N
except
Exception
as
e
:
...
...
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