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
7bb25c16
authored
2022-08-10 15:28:25 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
modify ht asp
1 parent
3478cf88
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
141 additions
and
110 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 @
7bb25c1
...
...
@@ -1585,13 +1585,13 @@ SE_AFC_CON_FIELD = ['-瘥△', '韐剛膠颲遠-撠-
'车辆贷款本金金额-重要条款'
,
'附加产品融资贷款本金总额-重要条款'
,
'所购车辆价格'
,
'车架号'
,
'经销商'
,
'贷款本金金额'
,
'车辆贷款本金金额'
,
'附加产品融资贷款本金总额'
,
'贷款期限'
,
'还款账号'
,
'户名'
,
'开户行'
,
'还款计划表'
,
'见证人签字'
,
'见证人日期'
,
'ASP项目详情-重要条款'
,
'购置税校验'
,
'ASP项目详情'
,
'合同编号-每页(no-asp)'
]
'合同编号-每页(no-a
sp)'
,
'无
ASP产品'
]
CON_BANK_FIELD
=
[
'还款账号'
,
'户名'
,
'开户行'
]
# '承租人姓名', '承租人证件号码', '承租人法定代表人或授权代表'
SE_HIL_CON_1_FIELD
=
[
'合同编号-每页'
,
'合同编号-正文'
,
'车辆识别代码'
,
'车辆卖方'
,
'车辆原始销售价格'
,
'融资成本总额'
,
'租期'
,
'还款计划表'
,
'ASP项目详情'
,
'购置税校验'
,
'承租人法定代表人或授权代表'
,
'还款账号'
,
'户名'
,
'开户行'
,
'共同承租人法定代表人或授权代表'
]
'共同承租人法定代表人
或授权代表'
,
'无ASP产品'
]
SE_HIL_CON_2_FIELD
=
[
'合同编号'
,
'合同编号-正文'
,
'车辆识别代码'
,
'租金总额'
,
'融资租赁期限'
]
SE_HIL_CON_3_FIELD
=
[
'合同编号-每页'
,
'承租人姓名'
,
'承租人证件号码'
,
'销售经销商'
,
'合同编号-正文'
,
'姓名/名称'
,
'自然人身份证件号码/法人执照号码'
,
'承租人签字'
]
...
...
@@ -1916,6 +1916,9 @@ HIL_CONTRACT_1_COMPARE_LOGIC = {
'保证人姓名2'
:
(
'保证人姓名2'
,
'se_name_compare'
,
{},
'售后回租合同保证人姓名2与系统不一致'
),
'保证人证件号2'
:
(
'保证人证件号2'
,
'se_common_compare'
,
{},
'售后回租合同保证人证件号2与系统不一致'
),
'保证人签字2'
:
(
'保证人签字2'
,
'se_contain_compare'
,
{},
'售后回租合同保证人签字2与系统不一致'
),
'购置税校验'
:
(
'购置税校验'
,
'se_self_compare_gzs'
,
{},
GZS_REASON_2
),
'无ASP产品'
:
(
'无ASP产品'
,
'se_self_compare_other_asp'
,
{},
GZS_REASON_1
),
}
# ['合同编号', '合同编号-正文', '车辆识别代码', '租金总额', '融资租赁期限']
...
...
@@ -1995,6 +1998,9 @@ HT_COMPARE_LOGIC = {
'ASP项目详情-重要条款'
:
(
'ASP项目详情-重要条款'
,
'se_asp_compare'
,
{},
'合同(重要条款)ASP名称或者金额与系统不一致'
),
'ASP项目详情'
:
(
'ASP项目详情'
,
'se_asp_compare'
,
{},
'合同ASP名称或者金额与系统不一致'
),
'购置税校验'
:
(
'购置税校验'
,
'se_self_compare_gzs'
,
{},
GZS_REASON_2
),
'无ASP产品'
:
(
'无ASP产品'
,
'se_self_compare_other_asp'
,
{},
GZS_REASON_1
),
}
AFC_HT_DATE_FIELDS
=
[
'主借人日期'
,
'共借人日期'
,
'保证人日期1'
,
'保证人日期2'
]
...
...
src/apps/doc/management/commands/ocr_process.py
View file @
7bb25c1
...
...
@@ -310,7 +310,7 @@ class Command(BaseCommand, LoggerMixin):
elif
isinstance
(
sub_value
[
text_key
],
str
):
page_compare_dict
[
key
][
sub_key
]
=
sub_value
[
text_key
]
#
contract_result_compare.setdefault(classify, dict())[consts.ASP_KEY] = contract_dict.get(consts.ASP_KEY, False)
contract_result_compare
.
setdefault
(
classify
,
dict
())[
consts
.
ASP_KEY
]
=
contract_dict
.
get
(
consts
.
ASP_KEY
,
False
)
# "position" = [xmin, ymin, xmax, ymax]
contract_result_compare
.
setdefault
(
classify
,
dict
())[
page_num_only
]
=
page_compare_dict
...
...
src/celery_compare/tasks.py
View file @
7bb25c1
...
...
@@ -1160,20 +1160,17 @@ def get_se_cms_compare_info_auto(last_obj, application_entity, auto=True, ignore
# ASP -------------------------------------------------------------------------------------------------------
asp_list
=
[]
gzs_status
=
consts
.
GZS_STATUS
[
1
]
gzs_list
=
[
gzs_status
]
gzs_price
=
'0.00'
is_asp
=
False
# insurance_price = None
insurance_price
=
None
gzs_price
=
None
have_other_asp
=
False
fin_total
=
0
if
str
(
cms_info
.
get
(
'financialInformation'
,
{})
.
get
(
'associatedServicePrincipal'
,
'0.00'
))
!=
'0.00'
:
is_asp
=
True
# for asp_info in cms_info.get('associatedServices', []):
for
asp_info
in
cms_info
.
get
(
'associatedServices'
,
{})
.
get
(
'SubassociatedServices'
,
[]):
tmp_asp_name
=
asp_info
.
get
(
'associatedServices'
)
if
isinstance
(
tmp_asp_name
,
str
)
and
len
(
tmp_asp_name
)
>
0
:
if
gzs_status
==
consts
.
GZS_STATUS
[
1
]
and
tmp_asp_name
.
find
(
consts
.
GZS_NAME
)
!=
-
1
:
gzs_status
=
consts
.
GZS_STATUS
[
2
]
gzs_price
=
asp_info
.
get
(
'price'
,
'0.00'
)
asp_list
.
append
(
(
tmp_asp_name
,
...
...
@@ -1181,18 +1178,16 @@ def get_se_cms_compare_info_auto(last_obj, application_entity, auto=True, ignore
asp_info
.
get
(
'financed'
,
'0.00'
)
)
)
fin_total
+=
float
(
asp_info
.
get
(
'financed'
,
'0.00'
))
# 购置税
if
tmp_asp_name
.
find
(
consts
.
GZS_NAME
)
!=
-
1
:
gzs_price
=
asp_info
.
get
(
'price'
,
'0.00'
)
# 保单费合计
# if tmp_asp_name.find('机动车辆保险') != -1:
# insurance_price = asp_info.get('price', '0.00')
fin_total
=
0
# fin_total_tmp = cms_info.get('associatedServices', {}).get('financed total', '0.00')
# fin_total = '0.00' if fin_total_tmp.strip() == '' else fin_total_tmp
for
asp_name
,
_
,
asp_fin
in
asp_list
:
if
gzs_status
==
consts
.
GZS_STATUS
[
2
]
and
asp_name
.
find
(
consts
.
GZS_NAME
)
==
-
1
and
\
asp_name
.
find
(
'机动车辆保险'
)
==
-
1
:
gzs_status
=
consts
.
GZS_STATUS
[
0
]
fin_total
+=
float
(
asp_fin
)
elif
tmp_asp_name
.
find
(
'机动车辆保险'
)
!=
-
1
:
insurance_price
=
asp_info
.
get
(
'price'
,
'0.00'
)
else
:
have_other_asp
=
True
asp_list
.
append
(
(
consts
.
ASP_SUM_NAME
,
...
...
@@ -1203,11 +1198,7 @@ def get_se_cms_compare_info_auto(last_obj, application_entity, auto=True, ignore
)
# CMS Vehicle Price / 1.13 * 10 %
gzs_list
=
[
gzs_status
]
if
gzs_status
!=
consts
.
GZS_STATUS
[
1
]:
gzs_value
=
float
(
amount
)
*
0.1
/
1.13
gzs_list
.
append
(
gzs_value
)
gzs_list
.
append
(
float
(
gzs_price
))
# gzs_list = [float(amount) * 0.1 / 1.13, float(gzs_price)]
# 保单 -----------------------------------------------------------------------------------------------------------
# is_insurance = 0
...
...
@@ -1275,8 +1266,15 @@ def get_se_cms_compare_info_auto(last_obj, application_entity, auto=True, ignore
]
if
is_asp
:
# asp各项
hil_contract_1_input
.
append
((
consts
.
SE_HIL_CON_1_FIELD
[
8
],
asp_list
))
hil_contract_1_input
.
append
((
consts
.
SE_HIL_CON_1_FIELD
[
9
],
gzs_list
))
# 购置税校验
if
isinstance
(
gzs_price
,
str
):
hil_contract_1_input
.
append
(
(
consts
.
SE_HIL_CON_1_FIELD
[
9
],
[
amount
,
gzs_price
]))
# 非购置税非车辆保险的其他asp
if
have_other_asp
:
hil_contract_1_input
.
append
((
consts
.
SE_HIL_CON_1_FIELD
[
15
],
'N'
))
if
isinstance
(
company_info
,
tuple
):
if
is_cdfl
:
...
...
@@ -1379,7 +1377,13 @@ def get_se_cms_compare_info_auto(last_obj, application_entity, auto=True, ignore
if
is_asp
:
afc_contract_input
.
append
((
consts
.
SE_AFC_CON_FIELD
[
20
],
asp_list
))
afc_contract_input
.
append
((
consts
.
SE_AFC_CON_FIELD
[
22
],
asp_list
))
afc_contract_input
.
append
((
consts
.
SE_AFC_CON_FIELD
[
21
],
gzs_list
))
# 购置税校验
if
isinstance
(
gzs_price
,
str
):
afc_contract_input
.
append
(
(
consts
.
SE_AFC_CON_FIELD
[
21
],
[
amount
,
gzs_price
]))
# 非购置税非车辆保险的其他asp
if
have_other_asp
:
afc_contract_input
.
append
((
consts
.
SE_AFC_CON_FIELD
[
24
],
'N'
))
else
:
afc_contract_input
.
pop
(
5
)
afc_contract_input
.
pop
(
5
)
...
...
@@ -1696,20 +1700,16 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list, auto=Fals
# ASP -------------------------------------------------------------------------------------------------------
asp_list
=
[]
gzs_status
=
consts
.
GZS_STATUS
[
1
]
# N-No
gzs_list
=
[
gzs_status
]
gzs_price
=
'0.00'
is_asp
=
False
insurance_price
=
None
gzs_price
=
None
have_other_asp
=
False
fin_total
=
0
if
str
(
cms_info
.
get
(
'financialInformation'
,
{})
.
get
(
'associatedServicePrincipal'
,
'0.00'
))
!=
'0.00'
:
is_asp
=
True
# for asp_info in cms_info.get('associatedServices', []):
for
asp_info
in
cms_info
.
get
(
'associatedServices'
,
{})
.
get
(
'SubassociatedServices'
,
[]):
tmp_asp_name
=
asp_info
.
get
(
'associatedServices'
)
if
isinstance
(
tmp_asp_name
,
str
)
and
len
(
tmp_asp_name
)
>
0
:
if
gzs_status
==
consts
.
GZS_STATUS
[
1
]
and
tmp_asp_name
.
find
(
consts
.
GZS_NAME
)
!=
-
1
:
gzs_status
=
consts
.
GZS_STATUS
[
2
]
# O-Only
gzs_price
=
asp_info
.
get
(
'price'
,
'0.00'
)
asp_list
.
append
(
(
tmp_asp_name
,
...
...
@@ -1717,18 +1717,16 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list, auto=Fals
asp_info
.
get
(
'financed'
,
'0.00'
)
)
)
fin_total
+=
float
(
asp_info
.
get
(
'financed'
,
'0.00'
))
# 购置税
if
tmp_asp_name
.
find
(
consts
.
GZS_NAME
)
!=
-
1
:
gzs_price
=
asp_info
.
get
(
'price'
,
'0.00'
)
# 保单费合计
if
tmp_asp_name
.
find
(
'机动车辆保险'
)
!=
-
1
:
el
if
tmp_asp_name
.
find
(
'机动车辆保险'
)
!=
-
1
:
insurance_price
=
asp_info
.
get
(
'price'
,
'0.00'
)
else
:
have_other_asp
=
True
fin_total
=
0
# fin_total_tmp = cms_info.get('associatedServices', {}).get('financed total', '0.00')
# fin_total = '0.00' if fin_total_tmp.strip() == '' else fin_total_tmp
for
asp_name
,
_
,
asp_fin
in
asp_list
:
if
gzs_status
==
consts
.
GZS_STATUS
[
2
]
and
asp_name
.
find
(
consts
.
GZS_NAME
)
==
-
1
and
\
asp_name
.
find
(
'机动车辆保险'
)
==
-
1
:
gzs_status
=
consts
.
GZS_STATUS
[
0
]
# Y-Yes
fin_total
+=
float
(
asp_fin
)
asp_list
.
append
(
(
consts
.
ASP_SUM_NAME
,
...
...
@@ -1739,11 +1737,7 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list, auto=Fals
)
# CMS Vehicle Price / 1.13 * 10 %
gzs_list
=
[
gzs_status
]
if
gzs_status
!=
consts
.
GZS_STATUS
[
1
]:
gzs_value
=
float
(
amount
)
*
0.1
/
1.13
gzs_list
.
append
(
gzs_value
)
gzs_list
.
append
(
float
(
gzs_price
))
# gzs_list = [float(amount) * 0.1 / 1.13, float(gzs_price)]
# 保单 -----------------------------------------------------------------------------------------------------------
is_insurance
=
0
...
...
@@ -1810,8 +1804,14 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list, auto=Fals
]
if
is_asp
:
# asp各项
hil_contract_1_input
.
append
((
consts
.
SE_HIL_CON_1_FIELD
[
8
],
asp_list
))
hil_contract_1_input
.
append
((
consts
.
SE_HIL_CON_1_FIELD
[
9
],
gzs_list
))
# 购置税校验
if
isinstance
(
gzs_price
,
str
):
hil_contract_1_input
.
append
((
consts
.
SE_HIL_CON_1_FIELD
[
9
],
[
amount
,
gzs_price
]))
# 非购置税非车辆保险的其他asp
if
have_other_asp
:
hil_contract_1_input
.
append
((
consts
.
SE_HIL_CON_1_FIELD
[
15
],
'N'
))
if
isinstance
(
company_info
,
tuple
):
if
is_cdfl
:
...
...
@@ -1911,9 +1911,16 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list, auto=Fals
])
if
is_asp
:
# asp各项
afc_contract_input
.
append
((
consts
.
SE_AFC_CON_FIELD
[
20
],
asp_list
))
afc_contract_input
.
append
((
consts
.
SE_AFC_CON_FIELD
[
22
],
asp_list
))
afc_contract_input
.
append
((
consts
.
SE_AFC_CON_FIELD
[
21
],
gzs_list
))
# 购置税校验
if
isinstance
(
gzs_price
,
str
):
afc_contract_input
.
append
(
(
consts
.
SE_AFC_CON_FIELD
[
21
],
[
amount
,
gzs_price
]))
# 非购置税非车辆保险的其他asp
if
have_other_asp
:
afc_contract_input
.
append
((
consts
.
SE_AFC_CON_FIELD
[
24
],
'N'
))
else
:
afc_contract_input
.
pop
(
5
)
afc_contract_input
.
pop
(
5
)
...
...
@@ -2524,69 +2531,75 @@ def se_contract_compare(license_en, ocr_res_dict, strip_list, is_gsyh):
for
name
,
value
in
strip_list
:
# 购置税校验
if
name
==
consts
.
SE_AFC_CON_FIELD
[
21
]:
if
len
(
value
)
==
3
:
reason
=
[]
gzs_verify
=
value
[
1
]
>=
value
[
2
]
if
gzs_verify
:
if
value
[
0
]
==
consts
.
GZS_STATUS
[
0
]:
reason
.
append
(
consts
.
GZS_REASON_1
)
result
=
consts
.
RESULT_N
else
:
result
=
consts
.
RESULT_Y
else
:
if
value
[
0
]
==
consts
.
GZS_STATUS
[
0
]:
reason
.
append
(
consts
.
GZS_REASON_1
)
result
=
consts
.
RESULT_N
reason
.
append
(
consts
.
GZS_REASON_2
)
else
:
result
=
consts
.
RESULT_N
reason
=
consts
.
GZS_REASON_1
ocr_str
=
empty_str
# if name == consts.SE_AFC_CON_FIELD[21]:
# if len(value) == 3:
# reason = []
# gzs_verify = value[1] >= value[2]
# if gzs_verify:
# if value[0] == consts.GZS_STATUS[0]:
# reason.append(consts.GZS_REASON_1)
# result = consts.RESULT_N
# else:
# result = consts.RESULT_Y
# else:
# if value[0] == consts.GZS_STATUS[0]:
# reason.append(consts.GZS_REASON_1)
# result = consts.RESULT_N
# reason.append(consts.GZS_REASON_2)
# else:
# result = consts.RESULT_N
# reason = consts.GZS_REASON_1
# ocr_str = empty_str
# else:
if
name
==
consts
.
SE_HIL_CON_1_FIELD
[
9
]
or
name
==
consts
.
SE_HIL_CON_1_FIELD
[
15
]
or
\
name
==
consts
.
SE_AFC_CON_FIELD
[
21
]
or
name
==
consts
.
SE_AFC_CON_FIELD
[
24
]:
ocr_str_or_list
=
''
else
:
ocr_str_or_list
=
ocr_res
.
get
(
compare_logic
[
name
][
0
])
# 招商银行特殊
# if ocr_str_or_list is None and license_en == consts.AFC_CONTRACT_EN \
# and is_gsyh is True and name in consts.CON_BANK_FIELD:
# result = consts.RESULT_Y
# ocr_str = empty_str
# reason = compare_logic[name][3]
# 见证人日期
if
name
==
consts
.
SE_AFC_CON_FIELD
[
19
]:
if
not
isinstance
(
ocr_str_or_list
,
str
)
or
len
(
ocr_str_or_list
)
==
0
:
result
=
consts
.
RESULT_N
ocr_str
=
empty_str
else
:
is_find_date
=
False
all_date_list
=
[
ocr_str_or_list
]
for
date_name
in
consts
.
AFC_HT_DATE_FIELDS
:
all_date_list
.
append
(
ocr_res
.
get
(
compare_logic
[
date_name
][
0
],
''
))
if
not
is_find_date
and
ocr_str_or_list
==
ocr_res
.
get
(
compare_logic
[
date_name
][
0
],
''
):
is_find_date
=
True
result
=
consts
.
RESULT_Y
if
is_find_date
else
consts
.
RESULT_N
ocr_str
=
json
.
dumps
(
all_date_list
,
ensure_ascii
=
False
)
reason
=
compare_logic
[
name
][
3
]
elif
isinstance
(
ocr_str_or_list
,
str
)
or
isinstance
(
ocr_str_or_list
,
list
):
# if is_gsyh is True and name in consts.CON_BANK_FIELD:
# update_args = {'is_gsyh': is_gsyh}
# for k, v in compare_logic[name][2].items():
# update_args[k] = v
# else:
# update_args = compare_logic[name][2]
if
isinstance
(
ocr_str_or_list
,
list
):
# no-asp 合同编号-每页(no-asp)
if
name
==
consts
.
SE_AFC_CON_FIELD
[
23
]:
ocr_str_or_list
.
pop
()
ocr_str
=
json
.
dumps
(
ocr_str_or_list
,
ensure_ascii
=
False
)
else
:
ocr_str_or_list
=
ocr_str_or_list
.
strip
()
ocr_str
=
ocr_str_or_list
result
=
getattr
(
cp
,
compare_logic
[
name
][
1
])(
value
,
ocr_str_or_list
,
**
compare_logic
[
name
][
2
])
reason
=
compare_logic
[
name
][
3
]
else
:
# 招商银行特殊
# if ocr_str_or_list is None and license_en == consts.AFC_CONTRACT_EN \
# and is_gsyh is True and name in consts.CON_BANK_FIELD:
# result = consts.RESULT_Y
# ocr_str = empty_str
# reason = compare_logic[name][3]
# 见证人日期
if
name
==
consts
.
SE_AFC_CON_FIELD
[
19
]:
if
not
isinstance
(
ocr_str_or_list
,
str
)
or
len
(
ocr_str_or_list
)
==
0
:
result
=
consts
.
RESULT_N
ocr_str
=
empty_str
reason
=
compare_logic
[
name
][
3
]
else
:
is_find_date
=
False
all_date_list
=
[
ocr_str_or_list
]
for
date_name
in
consts
.
AFC_HT_DATE_FIELDS
:
all_date_list
.
append
(
ocr_res
.
get
(
compare_logic
[
date_name
][
0
],
''
))
if
not
is_find_date
and
ocr_str_or_list
==
ocr_res
.
get
(
compare_logic
[
date_name
][
0
],
''
):
is_find_date
=
True
result
=
consts
.
RESULT_Y
if
is_find_date
else
consts
.
RESULT_N
ocr_str
=
json
.
dumps
(
all_date_list
,
ensure_ascii
=
False
)
reason
=
compare_logic
[
name
][
3
]
elif
isinstance
(
ocr_str_or_list
,
str
)
or
isinstance
(
ocr_str_or_list
,
list
):
# if is_gsyh is True and name in consts.CON_BANK_FIELD:
# update_args = {'is_gsyh': is_gsyh}
# for k, v in compare_logic[name][2].items():
# update_args[k] = v
# else:
# update_args = compare_logic[name][2]
if
isinstance
(
ocr_str_or_list
,
list
):
# no-asp 合同编号-每页(no-asp)
if
name
==
consts
.
SE_AFC_CON_FIELD
[
23
]:
ocr_str_or_list
.
pop
()
ocr_str
=
json
.
dumps
(
ocr_str_or_list
,
ensure_ascii
=
False
)
else
:
ocr_str_or_list
=
ocr_str_or_list
.
strip
()
ocr_str
=
ocr_str_or_list
result
=
getattr
(
cp
,
compare_logic
[
name
][
1
])(
value
,
ocr_str_or_list
,
**
compare_logic
[
name
][
2
])
reason
=
compare_logic
[
name
][
3
]
else
:
result
=
consts
.
RESULT_N
ocr_str
=
empty_str
reason
=
compare_logic
[
name
][
3
]
# img_path = empty_str
if
name
not
in
compare_logic
:
...
...
src/common/tools/comparison.py
View file @
7bb25c1
...
...
@@ -587,6 +587,18 @@ class Comparison:
else
:
return
self
.
RESULT_N
def
se_self_compare_gzs
(
self
,
input_list
,
ocr_str
,
**
kwargs
):
if
isinstance
(
input_list
,
list
)
and
len
(
input_list
)
==
2
:
try
:
if
float
(
input_list
[
0
])
*
0.1
/
1.13
>=
float
(
input_list
[
1
]):
return
self
.
RESULT_Y
except
Exception
as
e
:
return
self
.
RESULT_N
return
self
.
RESULT_N
def
se_self_compare_other_asp
(
self
,
input_str
,
ocr_str
,
**
kwargs
):
return
self
.
RESULT_N
cp
=
Comparison
()
...
...
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