ed435b3f by 周伟奇

fix merge

2 parents 069dea93 35db299e
......@@ -8,4 +8,5 @@ urlpatterns = [
path(r'settlement/cms/v1', views.SECMSView.as_view()),
path(r'offline/v1', views.CompareOfflineView.as_view()),
path(r'result', views.CompareResultView.as_view()),
path(r'resources', views.ResourcesView.as_view()),
]
......
......@@ -1488,3 +1488,114 @@ BC_FIELD_ORDER_2 = (('BankName', '发卡行名称'),
('CardNum', '银行卡号'),
('CardType', '银行卡类型'),)
IMG_PATH_KEY = 'uniq_img_path_key'
IMG_PATH_KEY_2 = 'uniq_img_path_key_2'
INFO_SOURCE = ['POS', 'CMS']
# -------------------
CA_FIRST_ID_FIELD = ['customerChineseName', 'idNum', 'idExpiryDate', 'dateOfBirth']
CA_FIRST_ID_FIELD_MAPPING = {
'ITPRC': (ID_EN, CA_FIRST_ID_FIELD),
'ITPSP': (PP_EN, CA_FIRST_ID_FIELD),
'ITHKM': (EEP_EN, CA_FIRST_ID_FIELD),
'ITTID': (EEP_EN, CA_FIRST_ID_FIELD),
'ITRES': (RP_EN, CA_FIRST_ID_FIELD),
}
CA_SECOND_ID_FIELD = [
('customerChineseName', 'customerChineseName'),
('secondIdNum', 'idNum')
]
CA_SECOND_ID_FIELD_MAPPING = {
'ITPRC': (ID_EN, CA_SECOND_ID_FIELD),
'ITPSP': (PP_EN, CA_SECOND_ID_FIELD),
'ITHKM': (EEP_EN, CA_SECOND_ID_FIELD),
'ITTID': (EEP_EN, CA_SECOND_ID_FIELD),
'ITRES': (RP_EN, CA_SECOND_ID_FIELD),
}
CA_SEP_FIELD = ['companyName', 'customerChineseName', 'registeredCapital', 'selfEmployedSubType']
CA_CORPORATE_FIELD = [
('customerChineseName', 'companyName'),
('legalRepName', 'customerChineseName'),
('idNum', 'idNum'),
('businessLicenseNo', 'businessLicenseNo'),
('taxRegistrationCode', 'taxRegistrationCode'),
('incorporationDate', 'incorporationDate'),
('businessLicenseDueDate', 'businessLicenseDueDate'),
('capitalRegAmount', 'registeredCapital'),
]
CA_MVC_FIELD = ['vinNo', 'manufactureDate', 'firstRegistrationDate']
CA_DL_FIELD = ['vinNo']
DL_EN = 'Driving Licence'
CA_ID_COMPARE_LOGIC = {
'customerChineseName': ('姓名', 'ca_name_compare', {}),
'idNum': ('公民身份号码', 'ca_common_compare', {}),
'dateOfBirth': ('出生年月', 'ca_date_compare', {'input_replace': ''}),
'idExpiryDate': ('有效期限', 'ca_date_compare', {'long': True, 'ocr_split': True, 'input_replace': ''}),
}
CA_PP_COMPARE_LOGIC = {
'customerChineseName': ('英文姓名', 'ca_name_compare', {'is_passport': True}),
'idNum': ('护照号码', 'ca_common_compare', {}),
'dateOfBirth': ('出生日期', 'ca_date_compare', {'input_replace': ''}),
'idExpiryDate': ('有效期至', 'ca_date_compare', {'input_replace': ''}),
}
CA_EEP_COMPARE_LOGIC = {
'customerChineseName': ('中文名', 'ca_common_compare', {}),
'idNum': ('证件号码', 'ca_common_compare', {}),
'dateOfBirth': ('出生日期', 'ca_date_compare', {'input_replace': '.'}),
'idExpiryDate': ('有效期限', 'ca_date_compare', {'ocr_split': True, 'input_replace': '.'}),
}
CA_RP_COMPARE_LOGIC = {
'customerChineseName': ('姓名', 'ca_common_compare', {}),
'idNum': ('公民身份号码', 'ca_common_compare', {}),
'dateOfBirth': ('出生年月', 'ca_date_compare', {'input_replace': ''}),
'idExpiryDate': ('有效期限', 'ca_date_compare', {'ocr_split': True, 'input_replace': ''}),
}
CA_BL_COMPARE_LOGIC = {
'companyName': ('企业名称', 'ca_company_compare', {}),
'customerChineseName': ('经营者姓名', 'ca_name_compare', {}),
'idNum': ('注册号', 'ca_common_compare', {}),
'businessLicenseNo': ('注册号', 'ca_common_compare', {}),
'taxRegistrationCode': ('注册号', 'ca_common_compare', {}),
'incorporationDate': ('成立日期', 'ca_date_compare', {'ocr_replace': True}),
'businessLicenseDueDate': ('营业期限', 'ca_date_compare', {'ocr_split': True, 'long': True, 'ocr_replace': True}),
'registeredCapital': ('注册资本', 'ca_rmb_compare', {}),
'selfEmployedSubType': ('企业类型', 'ca_type_compare', {}),
}
CA_MVC_COMPARE_LOGIC = {
'vinNo': ('9.车辆识别代号/车架号', 'ca_common_compare', {}),
'manufactureDate': ('32.车辆出厂日期', 'ca_date_compare', {}),
'firstRegistrationDate': ('3.登记日期', 'ca_date_compare', {}),
}
CA_DL_COMPARE_LOGIC = {
'vinNo': ('车辆识别代码', 'ca_common_compare', {}),
}
CA_COMPARE_FIELD = {
ID_EN: (IC_OCR_FIELD, CA_ID_COMPARE_LOGIC, True),
PP_EN: (PP_OCR_FIELD, CA_PP_COMPARE_LOGIC, False),
EEP_EN: (EEP_OCR_FIELD, CA_EEP_COMPARE_LOGIC, False),
RP_EN: (RP_OCR_FIELD, CA_RP_COMPARE_LOGIC, True),
BL_EN: (BL_OCR_FIELD, CA_BL_COMPARE_LOGIC, False),
MVC_EN: (MVC_OCR_FIELD, CA_MVC_COMPARE_LOGIC, False),
DL_EN: (DL_OCR_FIELD, CA_DL_COMPARE_LOGIC, False),
}
......
......@@ -221,6 +221,7 @@ class Command(BaseCommand, LoggerMixin):
dda_ocr_result = {key: value.get('words', '') for key, value in license_data.get('result', {}).items()}
dda_ocr_result[consts.DDA_IMG_PATH] = img_path
dda_ocr_result[consts.DDA_PRO] = pro
dda_ocr_result[consts.IMG_PATH_KEY] = img_path
license_summary.setdefault(classify, []).append(dda_ocr_result)
elif classify == consts.HMH_CLASSIFY: # 抵押登记豁免函
hmh_ocr_result = {key: value.get('words', '') for key, value in license_data.items()}
......@@ -230,6 +231,7 @@ class Command(BaseCommand, LoggerMixin):
license_summary.setdefault(classify, []).append(jypz_ocr_result)
elif classify == consts.MVC_CLASSIFY: # 车辆登记证 3/4页结果整合
for mvc_dict in license_data:
mvc_dict[consts.IMG_PATH_KEY] = img_path
try:
mvc_page = mvc_dict.pop('page')
except Exception as e:
......@@ -247,6 +249,10 @@ class Command(BaseCommand, LoggerMixin):
elif classify == consts.IC_CLASSIFY: # 身份证真伪
for id_card_dict in license_data:
if '有效期限' in id_card_dict:
id_card_dict[consts.IMG_PATH_KEY_2] = img_path
else:
id_card_dict[consts.IMG_PATH_KEY] = img_path
try:
base64_img = id_card_dict.pop('base64_img')
except Exception as e:
......@@ -299,6 +305,8 @@ class Command(BaseCommand, LoggerMixin):
dda_id_bc_mapping.setdefault(consts.IC_FIELD, []).append((ic_name, ic_id, img_path))
license_summary.setdefault(classify, []).extend(license_data)
else:
for res_dict in license_data:
res_dict[consts.IMG_PATH_KEY] = img_path
license_summary.setdefault(classify, []).extend(license_data)
res_list.append((pno, ino, part_idx, consts.RES_SUCCESS))
......@@ -310,6 +318,7 @@ class Command(BaseCommand, LoggerMixin):
# res_dict = {}
# for en_key, chn_key in consts.BC_FIELD:
# res_dict[chn_key] = ocr_res_2.get(en_key, '')
ocr_res_2[consts.IMG_PATH_KEY] = img_path
license_summary.setdefault(classify, []).append(ocr_res_2)
if do_dda and isinstance(ocr_res_2.get(consts.BC_KEY_FIELD), str):
bc_no = ocr_res_2[consts.BC_KEY_FIELD].strip()
......@@ -321,6 +330,7 @@ class Command(BaseCommand, LoggerMixin):
res_dict = {}
for field_dict in result_dict.get('FieldList', []):
res_dict[field_dict.get('chn_key', '')] = field_dict.get('value', '')
res_dict[consts.IMG_PATH_KEY] = img_path
license_summary.setdefault(classify, []).append(res_dict)
else:
res_list.append((pno, ino, part_idx, consts.RES_FAILED_2))
......@@ -1355,9 +1365,9 @@ class Command(BaseCommand, LoggerMixin):
finally:
try:
img_save_path = os.path.join(doc_data_path, 'img')
write_zip_file(img_save_path, os.path.join(doc_data_path, '{0}_img.zip'.format(doc_id_str)))
shutil.rmtree(img_save_path, ignore_errors=True)
# img_save_path = os.path.join(doc_data_path, 'img')
# write_zip_file(img_save_path, os.path.join(doc_data_path, '{0}_img.zip'.format(doc_id_str)))
# shutil.rmtree(img_save_path, ignore_errors=True)
pdf_path = os.path.join(doc_data_path, '{0}.pdf'.format(doc_id_str))
os.remove(pdf_path)
self.online_log.info('{0} [pdf & img removed] [task={1}]'.format(self.log_base, task_str))
......
......@@ -58,3 +58,11 @@ class WorkflowName(NamedEnum):
NORMAL = (0, 'Normal BS')
MOBILE = (1, 'Mobile BS')
class ErrorType(NamedEnum):
OCR = (0, 'OCR识别错误')
INPUT = (1, '输入比对信息错误')
NF = (2, '相关文件未找到')
IMAGE = (3, '图片问题')
OTHER = (4, '其他')
......
......@@ -20,6 +20,7 @@ class MetaStatus(NamedEnum):
ASYNC_WAIT = (5, 'async wait')
NO_PERMISSION = (6, 'no permission')
ILLEGAL_OPERATION = (7, 'illegal operation')
NEED_UPDATE = (8, 'need update')
class APIResponse(JsonResponse):
......@@ -32,3 +33,7 @@ class APIResponse(JsonResponse):
def ok(**kwargs):
return APIResponse(MetaStatus.SUCCESS.value, msg=MetaStatus.SUCCESS.verbose_name, **kwargs)
def need_update(**kwargs):
return APIResponse(MetaStatus.NEED_UPDATE.value, msg=MetaStatus.NEED_UPDATE.verbose_name, **kwargs)
......
......@@ -155,9 +155,30 @@ class Comparison:
ocr_s = ocr_str.translate(self.TRANS)
return self.build_res(input_s == ocr_s)
def ca_name_compare(self, input_str, ocr_str, **kwargs):
if kwargs.get('is_passport'):
input_tmp = input_str.upper().replace(' ', '')
ocr_tmp = ocr_str.upper().replace(' ', '')
if input_tmp.find(ocr_tmp) == -1:
return self.RESULT_N
else:
if ocr_str.strip() == '':
return self.RESULT_N
else:
return self.RESULT_Y
else:
# if re.search(r'[a-zA-Z]]', input_str):
# return self.RESULT_NA, ocr_str
input_s = input_str.translate(self.TRANS)
ocr_s = ocr_str.translate(self.TRANS)
return self.build_res(input_s == ocr_s)
def se_common_compare(self, input_str, ocr_str, **kwargs):
return self.build_res(input_str == ocr_str)
def ca_common_compare(self, input_str, ocr_str, **kwargs):
return self.build_res(input_str == ocr_str)
def se_date_compare(self, input_str, ocr_str, **kwargs):
if kwargs.get('long', False):
if '长期' in ocr_str or '永久' in ocr_str or '***' in ocr_str or '至今' in ocr_str:
......@@ -176,6 +197,24 @@ class Comparison:
input_str = input_str.replace('-', kwargs.get('input_replace'))
return self.build_res(input_str == ocr_str)
def ca_date_compare(self, input_str, ocr_str, **kwargs):
if kwargs.get('long', False):
if '长期' in ocr_str or '永久' in ocr_str:
if input_str in ['2099-12-31', '2099-01-01']:
return self.RESULT_Y
else:
return self.RESULT_N
if kwargs.get('ocr_split', False):
if '至' in ocr_str:
ocr_str = ocr_str.split('至')[-1]
elif '-' in ocr_str:
ocr_str = ocr_str.split('-')[-1]
if kwargs.get('ocr_replace', False):
ocr_str = ocr_str.replace('年', '-').replace('月', '-').replace('日', '')
if kwargs.get('input_replace') is not None:
input_str = input_str.replace('-', kwargs.get('input_replace'))
return self.build_res(input_str == ocr_str)
def se_contain_compare(self, input_str, ocr_str, **kwargs):
if ocr_str.find(input_str) == -1:
return self.RESULT_N
......@@ -220,6 +259,11 @@ class Comparison:
ocr_tmp = re.sub(self.re_obj, '', ocr_str).strip()
return self.build_res(input_tmp == ocr_tmp)
def ca_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()
return self.build_res(input_tmp == ocr_tmp)
def se_rmb_compare(self, input_str, ocr_str, **kwargs):
try:
ocr_lower = rmb_handler.to_rmb_lower(ocr_str)
......@@ -231,6 +275,17 @@ class Comparison:
else:
return res
def ca_rmb_compare(self, input_str, ocr_str, **kwargs):
try:
ocr_lower = rmb_handler.to_rmb_lower(ocr_str)
res = self.build_res(float(input_str) == ocr_lower)
# input_rmb_upper = to_rmb_upper(float(input_str))
# res = self.build_res(input_rmb_upper == ocr_str)
except Exception as e:
return self.RESULT_N
else:
return res
def se_type_compare(self, input_str, ocr_str, **kwargs):
for map_tuple in self.TYPE_MAPPING:
if re.search(map_tuple[0], ocr_str) is not None:
......@@ -240,6 +295,15 @@ class Comparison:
compare_str = self.CSOTH
return self.build_res(input_str == compare_str)
def ca_type_compare(self, input_str, ocr_str, **kwargs):
for map_tuple in self.TYPE_MAPPING:
if re.search(map_tuple[0], ocr_str) is not None:
compare_str = map_tuple[1]
break
else:
compare_str = self.CSOTH
return self.build_res(input_str == compare_str)
def se_date_compare_2(self, input_str, ocr_str, **kwargs):
try:
input_date = time.strptime(input_str, "%Y-%m-%d")
......
import pyodbc
hil_sql = """
ALTER TABLE hil_ca_compare_result ADD version nvarchar(8), comments nvarchar(max);
ALTER TABLE hil_se_compare_result ADD version nvarchar(8), comments nvarchar(max);
create table hil_se_compare_result_record
(
id int identity primary key,
application_id nvarchar(64) not null,
is_finish bit default 0 not null,
compare_count smallint default 0 not null,
failed_count smallint default 0 not null,
reason1_count smallint default 0 not null,
reason2_count smallint default 0 not null,
reason3_count smallint default 0 not null,
reason4_count smallint default 0 not null,
reason5_count smallint default 0 not null,
reason6_count smallint default 0 not null,
reason7_count smallint default 0 not null,
reason8_count smallint default 0 not null,
reason9_count smallint default 0 not null,
reason10_count smallint default 0 not null,
result nvarchar(max),
comments nvarchar(max),
create_time datetime not null
);
create index hil_se_compare_result_record_application_id_index
on hil_se_compare_result_record (application_id);
create index hil_se_compare_result_record_create_time_index
on hil_se_compare_result_record (create_time);
create table hil_ca_compare_result_record
(
id int identity primary key,
application_id nvarchar(64) not null,
is_finish bit default 0 not null,
compare_count smallint default 0 not null,
failed_count smallint default 0 not null,
reason1_count smallint default 0 not null,
reason2_count smallint default 0 not null,
reason3_count smallint default 0 not null,
reason4_count smallint default 0 not null,
reason5_count smallint default 0 not null,
reason6_count smallint default 0 not null,
reason7_count smallint default 0 not null,
reason8_count smallint default 0 not null,
reason9_count smallint default 0 not null,
reason10_count smallint default 0 not null,
result nvarchar(max),
comments nvarchar(max),
create_time datetime not null
);
create index hil_ca_compare_result_record_application_id_index
on hil_ca_compare_result_record (application_id);
create index hil_ca_compare_result_record_create_time_index
on hil_ca_compare_result_record (create_time);
"""
afc_sql = """
ALTER TABLE afc_ca_compare_result ADD version nvarchar(8), comments nvarchar(max);
ALTER TABLE afc_se_compare_result ADD version nvarchar(8), comments nvarchar(max);
create table afc_se_compare_result_record
(
id int identity primary key,
application_id nvarchar(64) not null,
is_finish bit default 0 not null,
compare_count smallint default 0 not null,
failed_count smallint default 0 not null,
reason1_count smallint default 0 not null,
reason2_count smallint default 0 not null,
reason3_count smallint default 0 not null,
reason4_count smallint default 0 not null,
reason5_count smallint default 0 not null,
reason6_count smallint default 0 not null,
reason7_count smallint default 0 not null,
reason8_count smallint default 0 not null,
reason9_count smallint default 0 not null,
reason10_count smallint default 0 not null,
result nvarchar(max),
comments nvarchar(max),
create_time datetime not null
);
create index afc_se_compare_result_record_application_id_index
on afc_se_compare_result_record (application_id);
create index afc_se_compare_result_record_create_time_index
on afc_se_compare_result_record (create_time);
create table afc_ca_compare_result_record
(
id int identity primary key,
application_id nvarchar(64) not null,
is_finish bit default 0 not null,
compare_count smallint default 0 not null,
failed_count smallint default 0 not null,
reason1_count smallint default 0 not null,
reason2_count smallint default 0 not null,
reason3_count smallint default 0 not null,
reason4_count smallint default 0 not null,
reason5_count smallint default 0 not null,
reason6_count smallint default 0 not null,
reason7_count smallint default 0 not null,
reason8_count smallint default 0 not null,
reason9_count smallint default 0 not null,
reason10_count smallint default 0 not null,
result nvarchar(max),
comments nvarchar(max),
create_time datetime not null
);
create index afc_ca_compare_result_record_application_id_index
on afc_ca_compare_result_record (application_id);
create index afc_ca_compare_result_record_create_time_index
on afc_ca_compare_result_record (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()
......@@ -12,3 +12,5 @@ EDMS_DOWNLOAD_URL = http://sccn0639.bmwgroup.net/FH/FileHold/DocumentRepository/
EDMS_UPLOAD_URL = http://sccn0639.bmwgroup.net/FH/FileHold/DocumentRepository/UploadHandler.ashx
DEALER_CODE = ocr_group
BASE_URL = https://li19dkocruat02vm.bmwgroup.net
......
......@@ -11,3 +11,5 @@ IMG_QUEUE_SIZE = 500
EDMS_DOWNLOAD_URL = https://edms-test.bmw.com/FH/FileHold/DocumentRepository/DownloadHandler.ashx
EDMS_UPLOAD_URL = https://edms-test.bmw.com/FH/FileHold/DocumentRepository/UploadHandler.ashx
DEALER_CODE = ocr_situ_group
BASE_URL = https://staging-bmw-ocr.situdata.com
\ No newline at end of file
......
......@@ -11,3 +11,5 @@ IMG_QUEUE_SIZE = 500
EDMS_DOWNLOAD_URL = http://sccn0637.bmwgroup.net/FH/FileHold/DocumentRepository/DownloadHandler.ashx
EDMS_UPLOAD_URL = http://sccn0637.bmwgroup.net/FH/FileHold/DocumentRepository/UploadHandler.ashx
DEALER_CODE = ocr_situ_group
BASE_URL = https://li19dkocruat01vm.bmwgroup.net
\ No newline at end of file
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!