5ae1abb7 by 周伟奇

part 1

1 parent 1992a53f
......@@ -1021,6 +1021,8 @@ JYPZ_FIELD_ORDER = (("type", "标题"),
CONTRACT_CN_NAME = '合同'
CONTRACT_CLASSIFY = 41
# 合同编号: 每页
HIL_CONTRACT_1_CN_NAME = '售后回租合同'
HIL_CONTRACT_1_CLASSIFY = 43
......@@ -1379,15 +1381,49 @@ SE_CORPORATE_ALL_FIELD = ['companyName', 'legalRepName', 'firstIdNo', 'businessL
'taxRegistrationCertificateNo', 'establishmentDate', 'businessLicenseDueDate']
SE_NEW_FIELD = ['vinNo', 'dealer', 'vehicleTransactionAmount']
SE_USED_FIELD = ['vinNo', 'vehicleTransactionAmount']
SE_NEW_ADD_FIELD = ['customerName', 'idNum', 'dateOfInvoice', 'stamp']
SE_NEW_ADD_FIELD = ['customerName', 'idNum', 'dateOfInvoice', 'stamp', '发票联', '发票真伪校验']
SE_FPL_VALUE = '发票联'
SE_STAMP_VALUE = '有'
SE_GB_NEW_FIELD = ['vinNo']
SE_GB_USED_FIELD = ['customerName', 'idNum', 'date']
SE_HMH_FIELD = ['customerName', 'idNum', 'applicationId']
SE_HMH_FIELD = ['借款人/承租人姓名', '借款人/承租人证件号', '申请号', '渠道', '签字']
SE_BANK_FIELD = ['accountNo', 'bankName']
SE_DDA_FIELD = ['applicationId(1)', 'applicationId(2)', 'bankName', 'companyName', 'customerName', 'idNum', 'accountHolderName', 'accountNo']
SE_AFC_CON_FIELD = ['合同编号-每页', '所购车辆价格-小写-重要条款', '车架号-重要条款', '贷款本金金额-重要条款', '贷款期限-重要条款',
'车辆贷款本金金额-重要条款', '附加产品融资贷款本金总额-重要条款', '所购车辆价格', '车架号', '经销商',
'贷款本金金额', '车辆贷款本金金额', '附加产品融资贷款本金总额', '贷款期限', '还款账号', '户名', '开户行',
'还款计划表', '项目1', '用途总金额', '贷款本金', '附加产品融资贷款本金总金额', '购置税校验']
#
# '借款人签字-重要条款'
# '借款人姓名'
# '借款人证件号'
# '主借人签字'
# '主借人日期'
#
# '共借人姓名'
# '共借人证件号'
# '共借人签字'
# '共借人日期'
#
# '保证人姓名1'
# '保证人证件号1'
# '保证人签字1'
# '保证人日期'
#
# '保证人姓名2'
# '保证人证件号2'
# '保证人签字2'
# '保证人日期'
#
# '见证人签字'
# '见证人日期'
GZS_NAME = '车辆购置税'
GZS_STATUS = ['Y', 'N', 'O']
SCHEDULE_SPLIT_STR = '、'
HIL_COMPANY_NAME = '先锋国际融资租赁有限公司'
AFC_COMPANY_NAME = '宝马汽车金融(中国)有限公司'
......@@ -1404,6 +1440,7 @@ BC_EN = 'Bank Card'
DDA_EN = 'DDA'
HMH_EN = 'Mortgage Waiver Letter'
JYPZ_EN = 'Used Car Document'
AFC_CONTRACT_EN = 'AFC Contract'
SKIP_CARD = {ID_EN, RP_EN}
......@@ -1411,10 +1448,11 @@ SKIP_CARD = {ID_EN, RP_EN}
ID_COMPARE_LOGIC = {
'customerName': ('姓名', 'se_name_compare', {}),
'idNum': ('公民身份号码', 'se_common_compare', {}),
'dateOfBirth': ('出生年月', 'se_date_compare', {'input_replace': ''}),
# 'dateOfBirth': ('出生年月', 'se_date_compare', {'input_replace': ''}),
'idExpiryDate': ('有效期限', 'se_date_compare', {'long': True, 'ocr_split': True, 'input_replace': '', 'today': True}),
'hukouProvince': ('住址', 'se_contain_compare', {}),
'hukouCity': ('住址', 'se_contain_compare', {}),
IC_TURE_OR_FALSE: (IC_TURE_OR_FALSE, 'se_common_compare', {}),
}
PP_COMPARE_LOGIC = {
......@@ -1463,13 +1501,20 @@ BL_COMPARE_LOGIC = {
MVI_COMPARE_LOGIC = {
'vinNo': ('车辆识别代码', 'se_common_compare', {}),
'dealer': ('销方名称', 'se_common_compare', {}),
'dealer': ('销方名称', 'se_contain_compare_2', {}),
'vehicleTransactionAmount': ('价税合计小写', 'se_amount_compare', {}),
'customerName': ('购方名称', 'se_name_compare', {'is_passport': True}),
'idNum': ('购买方身份证号或组织机构代码', 'se_contain_compare_2', {}),
'customerName': ('购方名称', 'se_common_compare', {}),
'idNum': ('购买方身份证号或组织机构代码', 'se_common_compare', {}),
'dateOfInvoice': ('开票日期', 'se_date_compare_2', {'three_month': True}),
'stamp': ('销售单位章', 'se_common_compare', {}),
'发票联': ('发票类型', 'se_common_compare', {}),
'发票真伪校验': ('发票真伪校验', 'se_common_compare', {}),
}
ZW_METHOD = 'mvi_special'
LOWER_AMOUNT_FIELD = '价税合计小写'
UPPER_AMOUNT_FIELD = '价税合计大写'
BHSJ_FIELD = '不含税价'
ZZSSE_FIELD = '增值税税额'
UCI_COMPARE_LOGIC = {
'vinNo': ('车架号', 'se_common_compare', {}),
......@@ -1497,9 +1542,11 @@ MVC34_COMPARE_LOGIC = {
'date': (TRANSFER_DATE, 'se_date_compare_2', {}),
}
BC_TYPE_VALUE = '借记卡'
BC_COMPARE_LOGIC = {
'accountNo': ('CardNum', 'se_common_compare', {'remove_space': True}),
'bankName': ('BankName', 'se_both_contain_compare', {}),
'type': ('CardType', 'se_common_compare', {}),
}
DDA_COMPARE_LOGIC = {
......@@ -1522,9 +1569,11 @@ JYPZ_COMPARE_LOGIC = {
}
HMH_COMPARE_LOGIC = {
'customerName': ('借款/承租人姓名', 'se_name_compare', {}),
'idNum': ('证件号码', 'se_common_compare', {}),
'applicationId': ('合同编号', 'se_contain_compare', {}),
'借款人/承租人姓名': ('借款/承租人姓名', 'se_name_compare', {}),
'借款人/承租人证件号': ('证件号码', 'se_common_compare', {}),
'申请号': ('合同编号', 'se_common_compare', {}),
'渠道': ('渠道', 'se_common_compare', {}),
'签字': ('借款人签字/盖章', 'se_common_compare', {}),
}
# MVC_OCR_FIELD = 'mvc_ocr'
......
......@@ -903,7 +903,7 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
customer_name = individual_info.get('name', '')
legal_name = individual_info.get('legalRepName', '')
establishment_date = individual_info.get('establishmentDate', '')
date_of_birth = individual_info.get('dateOfBirth', '')
# date_of_birth = individual_info.get('dateOfBirth', '')
for id_info in individual_info.get('IDInformation', []):
if id_info.get('idType') in consts.SE_CMS_FIRST_ID_FIELD_MAPPING:
......@@ -913,11 +913,13 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
field_input = [
('customerName', customer_name),
('idNum', id_num),
('dateOfBirth', date_of_birth),
('idExpiryDate', id_info.get('idExpiryDate', '')),
# ('dateOfBirth', date_of_birth),
# ('idExpiryDate', id_info.get('idExpiryDate', '')),
]
if is_prc:
field_input.append(('hukouProvince', province))
# field_input.append(('hukouProvince', province))
field_input.append(('真伪', province))
field_input.append(('idExpiryDate', id_info.get('idExpiryDate', '')))
license_dict[license_en] = field_input
all_id_num.append(id_num)
elif id_info.get('idType') == 'Unified Social Credit Code':
......@@ -971,7 +973,7 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
dda_num_list.append(dda_num_part)
dda_name = '、'.join(dda_name_list)
dda_num = '、'.join(dda_num_list)
del main_role_info
# del main_role_info
if len(company_info_list) > 0:
company_info = company_info_list[0]
......@@ -983,20 +985,27 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
vehicle_status = cms_info.get('vehicleStatus', '')
first_submmison_date = cms_info.get('submissionDate', '')
vin_no = cms_info.get('vehicleInformation', {}).get('vinNo', '')
amount = str(cms_info.get('financialInformation', {}).get('vehiclePrice', ''))
amount = str(cms_info.get('financialInformation', {}).get('vehiclePrice', '0.0'))
if vehicle_status == 'New':
vehicle_field_input.append(('vinNo', vin_no))
vehicle_field_input.append(('dealer', cms_info.get('dealerName', '')))
vehicle_field_input.append(('dealer', '、'.join([cms_info.get('dealerName', ''), cms_info.get('fapiaoIssuerDealer', '')])))
vehicle_field_input.append(('vehicleTransactionAmount', amount))
if isinstance(company_info, tuple):
vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[0], company_info[0]))
vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[1], company_info[1]))
else:
vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[0], main_name))
vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[1], main_num))
vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[0], hmh_name))
vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[1], hmh_id))
vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[2], first_submmison_date))
vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[3], consts.SE_STAMP_VALUE))
vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[4], consts.SE_FPL_VALUE))
bhsj = float(amount) / 1.13
vehicle_field_input.append((consts.SE_NEW_ADD_FIELD[5], consts.SPLIT_STR.join([
str(bhsj),
str(float(amount) - bhsj),
consts.RESULT_Y
])))
vehicle_info[consts.MVI_EN] = vehicle_field_input
else:
gb_field_input = [
......@@ -1044,6 +1053,7 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
bank_field_input = [
('accountNo', account_no),
('bankName', bank_name),
('type', consts.BC_TYPE_VALUE),
]
bank_info[consts.BC_EN] = bank_field_input
......@@ -1061,16 +1071,90 @@ def get_se_cms_compare_info(last_obj, application_entity, detect_list):
bank_info[consts.DDA_EN] = dda_field_input
compare_info['bankInfo'] = bank_info
full_no = cms_info.get('settlemnetVerification', {}).get('applicationNo', '')
if cms_info.get('mortgageType', '') == 'Mortgage Free':
other_info = {}
hmh_field_input = [
(consts.SE_HMH_FIELD[0], hmh_name),
(consts.SE_HMH_FIELD[1], hmh_id),
(consts.SE_HMH_FIELD[2], last_obj.application_id)
(consts.SE_HMH_FIELD[2], full_no),
(consts.SE_HMH_FIELD[3], cms_info.get('financeCompany', '')),
(consts.SE_HMH_FIELD[4], consts.SE_STAMP_VALUE),
]
other_info[consts.HMH_EN] = hmh_field_input
compare_info['other'] = other_info
contract_info = {}
schedule_list = []
for schedule_dict in cms_info.get('paymentSchedule', []):
tmp_str = "{1}{0}{2}".format(consts.SPLIT_STR, str(schedule_dict.get('no', '')),
str(schedule_dict.get('grossRentalAmount', '')))
schedule_list.append(tmp_str)
schedule_list_str = consts.SCHEDULE_SPLIT_STR.join(schedule_list)
afc_contract_input = [
(consts.SE_AFC_CON_FIELD[0], full_no),
(consts.SE_AFC_CON_FIELD[1], amount),
(consts.SE_AFC_CON_FIELD[2], vin_no),
(consts.SE_AFC_CON_FIELD[3], str(cms_info.get('financialInformation', {}).get('originationPrincipal', '0.0'))),
(consts.SE_AFC_CON_FIELD[4], str(cms_info.get('terms', '0'))),
(consts.SE_AFC_CON_FIELD[5], str(cms_info.get('financialInformation', {}).get('vehiclePrincipal', '0.0'))),
(consts.SE_AFC_CON_FIELD[6], str(cms_info.get('financialInformation', {}).get('associatedServicePrincipal', '0.0'))),
(consts.SE_AFC_CON_FIELD[7], amount),
(consts.SE_AFC_CON_FIELD[8], vin_no),
(consts.SE_AFC_CON_FIELD[9], cms_info.get('dealerName', '')),
(consts.SE_AFC_CON_FIELD[10], str(cms_info.get('financialInformation', {}).get('originationPrincipal', '0.0'))),
(consts.SE_AFC_CON_FIELD[11], str(cms_info.get('financialInformation', {}).get('vehiclePrincipal', '0.0'))),
(consts.SE_AFC_CON_FIELD[12], str(cms_info.get('financialInformation', {}).get('associatedServicePrincipal', '0.0'))),
(consts.SE_AFC_CON_FIELD[13], str(cms_info.get('terms', '0'))),
(consts.SE_AFC_CON_FIELD[14], account_no),
(consts.SE_AFC_CON_FIELD[15], cms_info.get('bankAccountDetails', {}).get('accountHolderName', '')),
(consts.SE_AFC_CON_FIELD[16], bank_name),
(consts.SE_AFC_CON_FIELD[17], schedule_list_str),
]
asp_list = []
for asp_info in cms_info.get('associatedServices', []):
asp_list.append(
(
asp_info.get('associatedServices', ''),
asp_info.get('price', 0.0),
asp_info.get('financed', 0.0)
)
)
if len(asp_list) > 0:
fin_total = 0
gzs_status = consts.GZS_STATUS[1]
for asp_name, asp_price, asp_fin in asp_list:
if gzs_status == consts.GZS_STATUS[1]:
if consts.GZS_NAME in asp_name:
gzs_status = consts.GZS_STATUS[0]
if gzs_status == consts.GZS_STATUS[0]:
if consts.GZS_NAME not in asp_name:
gzs_status = consts.GZS_STATUS[2]
afc_contract_input.extend(
[
(consts.SE_AFC_CON_FIELD[18], asp_name),
(consts.SE_AFC_CON_FIELD[19], str(asp_price)),
(consts.SE_AFC_CON_FIELD[20], str(asp_fin)),
]
)
fin_total += asp_fin
afc_contract_input.append((consts.SE_AFC_CON_FIELD[21], str(fin_total)))
# CMS Vehicle Price / 1.13 * 10 %
gzs_list = [gzs_status]
if gzs_status != consts.GZS_STATUS[1]:
gzs_value = str(cms_info.get('financialInformation', {}).get('vehiclePrincipal', 0.0) * 0.1 / 1.13)
gzs_list.append(gzs_value)
afc_contract_input.append((consts.SE_AFC_CON_FIELD[22], consts.SPLIT_STR.join(gzs_list)))
# role_name, _, role_id = main_role_info[applicant_type][0]
contract_info[consts.AFC_CONTRACT_EN] = afc_contract_input
compare_info['contract'] = contract_info
return compare_info, cms_info.get('applicationVersion', 1)
......@@ -1433,28 +1517,35 @@ def se_compare_license(license_en, ocr_res_dict, field_list):
# 身份证、居住证 过期期限特殊处理
if special_expiry_date:
expiry_dates = set()
expiry_dates_img_path = set()
expiry_dates = dict()
key = compare_logic.get('idExpiryDate')[0]
for ocr_res in ocr_res_list:
for date_tmp_idx, ocr_res in enumerate(ocr_res_list):
if key in ocr_res:
expiry_dates.add(ocr_res[key])
expiry_dates_img_path.add(ocr_res.get(consts.IMG_PATH_KEY_2, ''))
expiry_dates[ocr_res[key]] = (ocr_res.get(consts.IMG_PATH_KEY_2, ''), date_tmp_idx)
else:
expiry_dates = set()
expiry_dates_img_path = set()
expiry_dates = dict()
for res_idx in range(length-1, -1, -1):
if is_find:
break
for idx, (name, value) in enumerate(field_list):
ocr_str = ocr_res_list[res_idx].get(compare_logic[name][0])
if ocr_field == consts.MVI_OCR_FIELD and name == consts.SE_NEW_ADD_FIELD[-1]:
ocr_str = getattr(cp, consts.ZW_METHOD)(
ocr_res_list[res_idx].get(consts.LOWER_AMOUNT_FIELD, ''),
ocr_res_list[res_idx].get(consts.UPPER_AMOUNT_FIELD, ''),
ocr_res_list[res_idx].get(consts.BHSJ_FIELD, ''),
ocr_res_list[res_idx].get(consts.ZZSSE_FIELD, '')
)
else:
ocr_str = ocr_res_list[res_idx].get(compare_logic[name][0])
if not isinstance(ocr_str, str):
result = consts.RESULT_N
ocr_str = empty_str
no_key = True
else:
result = getattr(cp, compare_logic[name][1])(value, ocr_str, **compare_logic[name][2])
no_key = False
if idx == 0 and result == consts.RESULT_N and length > 1:
break
......@@ -1468,21 +1559,25 @@ def se_compare_license(license_en, ocr_res_dict, field_list):
# 过期期限特殊处理
if special_expiry_date and name == 'idExpiryDate' and result == consts.RESULT_N:
for expiry_date in expiry_dates:
expiry_date_res = getattr(cp, compare_logic[name][1])(value, expiry_date, **compare_logic[name][2])
if expiry_date_res == consts.RESULT_Y:
ocr_str = expiry_date
result = expiry_date_res
break
if result == consts.RESULT_N:
if consts.IMG_PATH_KEY_2 in ocr_res_list[res_idx]:
img_path = ocr_res_list[res_idx].get(consts.IMG_PATH_KEY_2, '')
special_expiry_date_slice = True
if no_key:
for expiry_date, (date_img_path, date_res_idx) in expiry_dates.items():
expiry_date_res = getattr(cp, compare_logic[name][1])(value, expiry_date, **compare_logic[name][2])
if expiry_date_res == consts.RESULT_N:
ocr_str = expiry_date
img_path = date_img_path
special_expiry_date_slice = True
section_img_info[consts.SECTION_IMG_PATH_KEY_2] = ocr_res_list[date_res_idx].get(
consts.SECTION_IMG_PATH_KEY_2, '')
section_img_info[consts.ALL_POSITION_KEY_2] = ocr_res_list[date_res_idx].get(
consts.ALL_POSITION_KEY_2, {})
break
else:
img_path = expiry_dates_img_path.pop() if len(expiry_dates_img_path) > 0 else empty_str
ocr_str = empty_str
result = consts.RESULT_Y
img_path = empty_str
else:
img_path = empty_str
img_path = ocr_res_list[res_idx].get(consts.IMG_PATH_KEY_2, '')
special_expiry_date_slice = True
else:
img_path = ocr_res_list[res_idx].get(consts.IMG_PATH_KEY, '') if result == consts.RESULT_N else empty_str
error_type = empty_error_type if result == consts.RESULT_Y else ErrorType.OCR.value
......@@ -1850,8 +1945,14 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
# 根据application_id查找OCR累计结果指定license字段,如果没有,结束
if is_ca:
result_class = HILOCRResult if application_entity == consts.HIL_PREFIX else AFCOCRResult
ca_ocr_res_dict = dict()
else:
result_class = HILSEOCRResult if application_entity == consts.HIL_PREFIX else AFCSEOCRResult
ca_result_class = HILOCRResult if application_entity == consts.HIL_PREFIX else AFCOCRResult
if ocr_res_id is None:
ca_ocr_res_dict = ca_result_class.objects.filter(application_id=application_id).values(consts.IC_OCR_FIELD).first()
else:
ca_ocr_res_dict = ca_result_class.objects.filter(id=ocr_res_id).values(consts.IC_OCR_FIELD).first()
if ocr_res_id is None:
ocr_res_dict = result_class.objects.filter(application_id=application_id).values(*consts.COMPARE_FIELDS).first()
else:
......@@ -1865,6 +1966,12 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
if is_ca:
ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict)
else:
if isinstance(ca_ocr_res_dict, dict) and isinstance(ca_ocr_res_dict.get(consts.IC_OCR_FIELD), str):
tmp_ca_result = json.loads(ca_ocr_res_dict.get(consts.IC_OCR_FIELD))
if isinstance(ocr_res_dict.get(consts.IC_OCR_FIELD), str):
tmp_se_result = json.loads(ocr_res_dict.get(consts.IC_OCR_FIELD))
tmp_ca_result.extend(tmp_se_result)
ocr_res_dict[consts.IC_OCR_FIELD] = json.dumps(tmp_ca_result)
se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict, is_cms)
......
......@@ -16,6 +16,7 @@ class Comparison:
self.CSIBM = 'CSIBM'
self.CSSME = 'CSSME'
self.CSOTH = 'CSOTH'
self.SPLIT_STR = '_'
self.TYPE_MAPPING = (
(r'个体工商户', self.CSIBM),
......@@ -109,6 +110,16 @@ class Comparison:
ocr_output = None
return self.build_res(input_str == ocr_str), ocr_output
def mvi_special(self, amount_lower_str, amount_upper_str, bhsj_str, zzsse_str):
# 不含税价, 增值税税额
try:
if float(amount_lower_str) != rmb_handler.to_rmb_lower(amount_upper_str):
return self.RESULT_N
except Exception:
return self.RESULT_N
else:
return self.SPLIT_STR.join([bhsj_str, zzsse_str, self.RESULT_Y])
def rmb_compare(self, input_str, ocr_str, idx, **kwargs):
if not isinstance(ocr_str, str) or not isinstance(input_str, str):
return self.RESULT_NA, None
......@@ -198,7 +209,7 @@ class Comparison:
)
dti = DatetimeIndex(dt_array, tz=None, name=None)
ts = dti[0]
if isinstance(ts, NaTType) or ts.date() < datetime.today().date():
if isinstance(ts, NaTType) or ts.date() < (datetime.today() + relativedelta(days=8)).date():
return False
else:
return True
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!