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))
......
......@@ -545,7 +545,8 @@ class IDBCRecords(models.Model):
class AFCSECompareResult(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
is_finish = models.BooleanField(default=False, verbose_name="是否完成")
version = models.CharField(max_length=8, verbose_name="POS/CMS version")
is_finish = models.BooleanField(default=False, verbose_name="整体结果")
compare_count = models.SmallIntegerField(default=0, verbose_name="比对字段总数")
failed_count = models.SmallIntegerField(default=0, verbose_name="比对失败数目")
reason1_count = models.SmallIntegerField(default=0, verbose_name="原因1数目")
......@@ -559,6 +560,7 @@ class AFCSECompareResult(models.Model):
reason9_count = models.SmallIntegerField(default=0, verbose_name="原因9数目")
reason10_count = models.SmallIntegerField(default=0, verbose_name="原因10数目")
result = models.TextField(null=True, verbose_name="比对结果")
comments = models.TextField(null=True, verbose_name="备注")
update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') # 索引
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
......@@ -571,7 +573,8 @@ class AFCSECompareResult(models.Model):
class AFCCACompareResult(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
is_finish = models.BooleanField(default=False, verbose_name="是否完成")
version = models.CharField(max_length=8, verbose_name="POS/CMS version")
is_finish = models.BooleanField(default=False, verbose_name="整体结果")
compare_count = models.SmallIntegerField(default=0, verbose_name="比对字段总数")
failed_count = models.SmallIntegerField(default=0, verbose_name="比对失败数目")
reason1_count = models.SmallIntegerField(default=0, verbose_name="原因1数目")
......@@ -585,6 +588,7 @@ class AFCCACompareResult(models.Model):
reason9_count = models.SmallIntegerField(default=0, verbose_name="原因9数目")
reason10_count = models.SmallIntegerField(default=0, verbose_name="原因10数目")
result = models.TextField(null=True, verbose_name="比对结果")
comments = models.TextField(null=True, verbose_name="备注")
update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') # 索引
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
......@@ -597,7 +601,8 @@ class AFCCACompareResult(models.Model):
class HILSECompareResult(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
is_finish = models.BooleanField(default=False, verbose_name="是否完成")
version = models.CharField(max_length=8, verbose_name="POS/CMS version")
is_finish = models.BooleanField(default=False, verbose_name="整体结果")
compare_count = models.SmallIntegerField(default=0, verbose_name="比对字段总数")
failed_count = models.SmallIntegerField(default=0, verbose_name="比对失败数目")
reason1_count = models.SmallIntegerField(default=0, verbose_name="原因1数目")
......@@ -611,6 +616,7 @@ class HILSECompareResult(models.Model):
reason9_count = models.SmallIntegerField(default=0, verbose_name="原因9数目")
reason10_count = models.SmallIntegerField(default=0, verbose_name="原因10数目")
result = models.TextField(null=True, verbose_name="比对结果")
comments = models.TextField(null=True, verbose_name="备注")
update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') # 索引
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
......@@ -622,7 +628,8 @@ class HILSECompareResult(models.Model):
class HILCACompareResult(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
is_finish = models.BooleanField(default=False, verbose_name="是否完成")
version = models.CharField(max_length=8, verbose_name="POS/CMS version")
is_finish = models.BooleanField(default=False, verbose_name="整体结果")
compare_count = models.SmallIntegerField(default=0, verbose_name="比对字段总数")
failed_count = models.SmallIntegerField(default=0, verbose_name="比对失败数目")
reason1_count = models.SmallIntegerField(default=0, verbose_name="原因1数目")
......@@ -636,6 +643,7 @@ class HILCACompareResult(models.Model):
reason9_count = models.SmallIntegerField(default=0, verbose_name="原因9数目")
reason10_count = models.SmallIntegerField(default=0, verbose_name="原因10数目")
result = models.TextField(null=True, verbose_name="比对结果")
comments = models.TextField(null=True, verbose_name="备注")
update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间') # 索引
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
......@@ -644,3 +652,103 @@ class HILCACompareResult(models.Model):
db_table = 'hil_ca_compare_result'
class AFCSECompareResultRecord(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
is_finish = models.BooleanField(default=False, verbose_name="整体结果")
compare_count = models.SmallIntegerField(default=0, verbose_name="比对字段总数")
failed_count = models.SmallIntegerField(default=0, verbose_name="比对失败数目")
reason1_count = models.SmallIntegerField(default=0, verbose_name="原因1数目")
reason2_count = models.SmallIntegerField(default=0, verbose_name="原因2数目")
reason3_count = models.SmallIntegerField(default=0, verbose_name="原因3数目")
reason4_count = models.SmallIntegerField(default=0, verbose_name="原因4数目")
reason5_count = models.SmallIntegerField(default=0, verbose_name="原因5数目")
reason6_count = models.SmallIntegerField(default=0, verbose_name="原因6数目")
reason7_count = models.SmallIntegerField(default=0, verbose_name="原因7数目")
reason8_count = models.SmallIntegerField(default=0, verbose_name="原因8数目")
reason9_count = models.SmallIntegerField(default=0, verbose_name="原因9数目")
reason10_count = models.SmallIntegerField(default=0, verbose_name="原因10数目")
result = models.TextField(null=True, verbose_name="比对结果")
comments = models.TextField(null=True, verbose_name="备注")
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
class Meta:
managed = False
db_table = 'afc_se_compare_result_record'
class AFCCACompareResultRecord(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
is_finish = models.BooleanField(default=False, verbose_name="整体结果")
compare_count = models.SmallIntegerField(default=0, verbose_name="比对字段总数")
failed_count = models.SmallIntegerField(default=0, verbose_name="比对失败数目")
reason1_count = models.SmallIntegerField(default=0, verbose_name="原因1数目")
reason2_count = models.SmallIntegerField(default=0, verbose_name="原因2数目")
reason3_count = models.SmallIntegerField(default=0, verbose_name="原因3数目")
reason4_count = models.SmallIntegerField(default=0, verbose_name="原因4数目")
reason5_count = models.SmallIntegerField(default=0, verbose_name="原因5数目")
reason6_count = models.SmallIntegerField(default=0, verbose_name="原因6数目")
reason7_count = models.SmallIntegerField(default=0, verbose_name="原因7数目")
reason8_count = models.SmallIntegerField(default=0, verbose_name="原因8数目")
reason9_count = models.SmallIntegerField(default=0, verbose_name="原因9数目")
reason10_count = models.SmallIntegerField(default=0, verbose_name="原因10数目")
result = models.TextField(null=True, verbose_name="比对结果")
comments = models.TextField(null=True, verbose_name="备注")
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
class Meta:
managed = False
db_table = 'afc_ca_compare_result_record'
class HILSECompareResultRecord(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
is_finish = models.BooleanField(default=False, verbose_name="整体结果")
compare_count = models.SmallIntegerField(default=0, verbose_name="比对字段总数")
failed_count = models.SmallIntegerField(default=0, verbose_name="比对失败数目")
reason1_count = models.SmallIntegerField(default=0, verbose_name="原因1数目")
reason2_count = models.SmallIntegerField(default=0, verbose_name="原因2数目")
reason3_count = models.SmallIntegerField(default=0, verbose_name="原因3数目")
reason4_count = models.SmallIntegerField(default=0, verbose_name="原因4数目")
reason5_count = models.SmallIntegerField(default=0, verbose_name="原因5数目")
reason6_count = models.SmallIntegerField(default=0, verbose_name="原因6数目")
reason7_count = models.SmallIntegerField(default=0, verbose_name="原因7数目")
reason8_count = models.SmallIntegerField(default=0, verbose_name="原因8数目")
reason9_count = models.SmallIntegerField(default=0, verbose_name="原因9数目")
reason10_count = models.SmallIntegerField(default=0, verbose_name="原因10数目")
result = models.TextField(null=True, verbose_name="比对结果")
comments = models.TextField(null=True, verbose_name="备注")
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
class Meta:
managed = False
db_table = 'hil_se_compare_result_record'
class HILCACompareResultRecord(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
is_finish = models.BooleanField(default=False, verbose_name="整体结果")
compare_count = models.SmallIntegerField(default=0, verbose_name="比对字段总数")
failed_count = models.SmallIntegerField(default=0, verbose_name="比对失败数目")
reason1_count = models.SmallIntegerField(default=0, verbose_name="原因1数目")
reason2_count = models.SmallIntegerField(default=0, verbose_name="原因2数目")
reason3_count = models.SmallIntegerField(default=0, verbose_name="原因3数目")
reason4_count = models.SmallIntegerField(default=0, verbose_name="原因4数目")
reason5_count = models.SmallIntegerField(default=0, verbose_name="原因5数目")
reason6_count = models.SmallIntegerField(default=0, verbose_name="原因6数目")
reason7_count = models.SmallIntegerField(default=0, verbose_name="原因7数目")
reason8_count = models.SmallIntegerField(default=0, verbose_name="原因8数目")
reason9_count = models.SmallIntegerField(default=0, verbose_name="原因9数目")
reason10_count = models.SmallIntegerField(default=0, verbose_name="原因10数目")
result = models.TextField(null=True, verbose_name="比对结果")
comments = models.TextField(null=True, verbose_name="备注")
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') # 索引
class Meta:
managed = False
db_table = 'hil_ca_compare_result_record'
......
......@@ -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, '其他')
......
......@@ -30,7 +30,12 @@ from .models import (
AFCSECompareResult,
HILCACompareResult,
HILSECompareResult,
AFCCACompareResultRecord,
AFCSECompareResultRecord,
HILCACompareResultRecord,
HILSECompareResultRecord,
)
from .named_enum import ErrorType
from .mixins import DocHandler
from . import consts
from apps.account.authentication import OAuth2AuthenticationWithUser
......@@ -294,7 +299,6 @@ application_information = {
priority_doc_args = {
'APPLICATION_INFORMATION': fields.Nested(application_information, required=True)
}
compare_offline_args = {
......@@ -434,6 +438,32 @@ se_cms_args = {
'content': fields.Nested(se_cms_content, required=True)
}
result_item_args = {
consts.HEAD_LIST[0]: fields.Str(required=True),
consts.HEAD_LIST[1]: fields.Str(required=True),
consts.HEAD_LIST[2]: fields.Str(required=True),
consts.HEAD_LIST[3]: fields.Str(required=True),
consts.HEAD_LIST[4]: fields.Str(required=True),
consts.HEAD_LIST[5]: fields.Str(required=True),
consts.HEAD_LIST[6]: fields.Str(required=True),
consts.HEAD_LIST[7]: fields.Str(required=True),
consts.HEAD_LIST[8]: fields.List(fields.Str(), required=True),
consts.HEAD_LIST[9]: fields.Int(required=True),
}
result_update_args = {
'id': fields.Int(required=True),
'application_id': fields.Str(required=True, validate=validate.Length(max=64)),
'entity': fields.Str(required=True, validate=validate.OneOf(consts.BUSINESS_TYPE_LIST)),
'scheme': fields.Str(required=True, validate=validate.OneOf(consts.DOC_SCHEME_LIST)),
'whole_result': fields.Str(required=True),
'version': fields.Str(required=True),
'source': fields.Str(required=True),
'latest_compared_time': fields.Str(required=True),
'comments': fields.Str(required=True),
'result': fields.List(fields.Nested(result_item_args), required=True, validate=validate.Length(min=1)),
}
class UploadDocView(GenericView, DocHandler):
# permission_classes = []
......@@ -890,44 +920,166 @@ class CompareResultView(GenericView):
result_table = AFCCACompareResult if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else AFCSECompareResult
if result_id is not None:
result_str_list = result_table.objects.filter(id=result_id).values_list('result', flat=True)
result_obj = result_table.objects.filter(id=result_id).first()
else:
result_obj = result_table.objects.filter(application_id=case_id).first()
if result_obj is None:
whole_result = ''
else:
whole_result = consts.RESULT_Y if result_obj.is_finish else consts.RESULT_N
if result_obj is None or result_obj.comments is None:
comments = ''
else:
comments = result_obj.comments
compare_result = {
'id': 0 if result_obj is None else result_obj.id,
'application_id': case_id,
'entity': entity,
'scheme': consts.DOC_SCHEME_LIST[0] if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else consts.DOC_SCHEME_LIST[1],
'whole_result': whole_result,
'latest_compared_time': '' if result_obj is None else result_obj.update_time.strftime('%Y-%m-%d %H:%M'),
'source': '' if result_obj is None else result_obj.version.split(consts.SPLIT_STR)[0],
'version': '' if result_obj is None else result_obj.version.split(consts.SPLIT_STR)[1],
'comments': comments,
'result': [] if result_obj is None else json.loads(result_obj.result)
}
return response.ok(data=compare_result)
# if len(result_str_list) == 0:
# compare_result_list = []
# else:
# compare_result_list = json.loads(result_str_list[0])
#
# if len(compare_result_list) == 0:
# body_html = "<h1>没有比对结果</h1>"
# else:
# head_content = ''.join(['<th>{0}</th>'.format(head_name) for head_name in consts.HEAD_LIST])
# head_html = '<tr>{0}</tr>'.format(head_content)
# row_html_list = []
# for row_dict in compare_result_list:
# row_list = [row_dict.get(head, '') for head in consts.HEAD_LIST]
# row_content = ''.join(['<td>{0}</td>'.format(row_str) for row_str in row_list])
# row_html = '<tr>{0}</tr>'.format(row_content)
# row_html_list.append(row_html)
# content_html = ''.join(row_html_list)
# body_html = '<table border="1">{0}{1}</table>'.format(head_html, content_html)
#
# html = """
# <!DOCTYPE html>
# <html>
# <head>
# <meta charset="utf-8">
# <title>比对结果</title>
# </head>
# <body>
# {0}
# </body>
# </html>
# """.format(body_html)
# return HttpResponse(html)
# 比对结果更新
@use_args(result_update_args, location='data')
def post(self, request, args):
result_id = args.get('id')
case_id = args.get('application_id')
update_time = args.get('latest_compared_time')
scheme = args.get('scheme')
entity = args.get('entity')
whole_result = args.get('whole_result')
if entity == consts.HIL_PREFIX:
result_table = HILCACompareResult if scheme == consts.DOC_SCHEME_LIST[0] else HILSECompareResult
record_table = HILCACompareResultRecord if scheme == consts.DOC_SCHEME_LIST[0] else HILSECompareResultRecord
else:
result_table = AFCCACompareResult if scheme == consts.DOC_SCHEME_LIST[0] else AFCSECompareResult
record_table = AFCCACompareResultRecord if scheme == consts.DOC_SCHEME_LIST[0] else AFCSECompareResultRecord
if result_id is not None:
result_obj = result_table.objects.filter(id=result_id).first()
else:
result_str_list = result_table.objects.filter(application_id=case_id).values_list('result', flat=True)
result_obj = result_table.objects.filter(application_id=case_id).first()
if result_obj is None:
return response.ok()
if len(result_str_list) == 0:
compare_result_list = []
result_str = json.dumps(args.get('result', []))
is_finish = whole_result == consts.RESULT_Y
compare_count = 0
failed_count = 0
reason_dict = {}
for result in args.get('result', []):
compare_count += 1
if result.get(consts.HEAD_LIST[6]) == consts.RESULT_N:
failed_count += 1
error_type = result.get(consts.HEAD_LIST[-1], '')
if error_type in reason_dict:
reason_dict[error_type] = reason_dict[error_type] + 1
else:
compare_result_list = json.loads(result_str_list[0])
reason_dict[error_type] = 1
record_table.objects.create(
application_id=case_id,
is_finish=is_finish,
compare_count=compare_count,
failed_count=failed_count,
reason1_count=reason_dict.get(0, 0),
reason2_count=reason_dict.get(1, 0),
reason3_count=reason_dict.get(2, 0),
reason4_count=reason_dict.get(3, 0),
reason5_count=reason_dict.get(4, 0),
reason6_count=reason_dict.get(5, 0),
reason7_count=reason_dict.get(6, 0),
reason8_count=reason_dict.get(7, 0),
reason9_count=reason_dict.get(8, 0),
reason10_count=reason_dict.get(9, 0),
result=result_str,
comments=args.get('comments', ''),
)
if len(compare_result_list) == 0:
body_html = "<h1>没有比对结果</h1>"
if update_time == result_obj.update_time.strftime('%Y-%m-%d %H:%M'):
result_obj.result = result_str
result_obj.comments = args.get('comments', '')
result_obj.update_time = result_obj.update_time
result_obj.save()
return response.ok()
else:
head_content = ''.join(['<th>{0}</th>'.format(head_name) for head_name in consts.HEAD_LIST])
head_html = '<tr>{0}</tr>'.format(head_content)
row_html_list = []
for row_dict in compare_result_list:
row_list = [row_dict.get(head, '') for head in consts.HEAD_LIST]
row_content = ''.join(['<td>{0}</td>'.format(row_str) for row_str in row_list])
row_html = '<tr>{0}</tr>'.format(row_content)
row_html_list.append(row_html)
content_html = ''.join(row_html_list)
body_html = '<table border="1">{0}{1}</table>'.format(head_html, content_html)
html = """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>比对结果</title>
</head>
<body>
{0}
</body>
</html>
""".format(body_html)
return HttpResponse(html)
# return response.ok(data=compare_result)
whole_result = consts.RESULT_Y if result_obj.is_finish else consts.RESULT_N
comments = '' if result_obj.comments is None else comments = result_obj.comments
compare_result = {
'id': 0 if result_obj is None else result_obj.id,
'application_id': case_id,
'entity': entity,
'scheme': consts.DOC_SCHEME_LIST[0] if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else
consts.DOC_SCHEME_LIST[1],
'whole_result': whole_result,
'latest_compared_time': '' if result_obj is None else result_obj.update_time.strftime('%Y-%m-%d %H:%M'),
'source': '' if result_obj is None else result_obj.version.split(consts.SPLIT_STR)[0],
'version': '' if result_obj is None else result_obj.version.split(consts.SPLIT_STR)[1],
'comments': comments,
'result': [] if result_obj is None else json.loads(result_obj.result)
}
return response.need_update(data=compare_result)
class ResourcesView(GenericView):
permission_classes = []
authentication_classes = []
def get(self, request):
error_type_map = ErrorType.get_mappings()
error_type = [{'label': v, 'value': k} for k, v in error_type_map.items()]
resources = {
'error_type': error_type
}
return response.ok(data=resources)
class SECMSView(GenericView):
......
......@@ -5,6 +5,7 @@ import traceback
from datetime import datetime, timedelta
from collections import OrderedDict
from . import app
from settings import conf
from apps.doc.models import (
AFCOCRResult,
AFCSEOCRResult,
......@@ -18,16 +19,20 @@ from apps.doc.models import (
HILCompareReport,
AFCCompareReport,
AFCSECompareResult,
AFCCACompareResult,
HILSECompareResult,
HILCACompareResult,
)
from apps.doc import consts
from apps.doc.ocr.gcap import gcap
from apps.doc.exceptions import GCAPException
from apps.doc.named_enum import RequestTeam, RequestTrigger, ProcessName
from apps.doc.named_enum import RequestTeam, RequestTrigger, ProcessName, ErrorType
from common.tools.comparison import cp
compare_log = logging.getLogger('compare')
log_base = '[Compare]'
empty_str = ''
empty_error_type = 1000
def name_check(ocr_res_dict, second_ocr_field, second_compare_list, second_id_num, name):
......@@ -96,10 +101,11 @@ def field_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set,
else:
expiry_dates = []
for ocr_res in tmp_list:
for res_idx in range(length-1, -1, -1):
# for ocr_res in ocr_res_list:
if is_find:
break
ocr_res = tmp_list[res_idx]
for idx, compare_tuple in enumerate(compare_list):
input_str = info_dict.get(compare_tuple[0])
ocr_str = ocr_res.get(compare_tuple[1])
......@@ -159,9 +165,10 @@ def usedcar_info_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_s
length = len(tmp_list)
for ocr_res in tmp_list:
for res_idx in range(length-1, -1, -1):
if is_find:
break
ocr_res = tmp_list[res_idx]
for idx, compare_tuple in enumerate(compare_list):
input_str = info_dict.get(compare_tuple[0])
ocr_str = ocr_res.get(compare_tuple[1])
......@@ -195,9 +202,230 @@ def usedcar_info_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_s
return is_find and key_right, no_match_vino
def get_ca_compare_info(last_obj):
compare_info = {}
individual_info_dict = {}
for individual_info in json.loads(last_obj.individual_cus_info):
license_dict = {}
if individual_info['idType'] in consts.CA_FIRST_ID_FIELD_MAPPING:
license_en, field_list = consts.CA_FIRST_ID_FIELD_MAPPING[individual_info['idType']]
field_input = []
for field in field_list:
if field in individual_info:
field_input.append((field, individual_info.get(field, '')))
license_dict[license_en] = field_input
if individual_info.get('secondIdType') in consts.CA_SECOND_ID_FIELD_MAPPING:
second_license_en, second_field_list = consts.CA_SECOND_ID_FIELD_MAPPING[individual_info['secondIdType']]
if second_license_en not in license_dict:
second_field_input = []
for second_field, write_field in second_field_list:
if second_field in individual_info:
second_field_input.append((write_field, individual_info.get(second_field, '')))
license_dict[second_license_en] = second_field_input
if individual_info['customerType'] == consts.CUSTOMER_TYPE[5]:
sep_field_input = []
for sep_field in consts.CA_SEP_FIELD:
if sep_field in individual_info:
sep_field_input.append((sep_field, individual_info.get(sep_field, '')))
license_dict[consts.BL_EN] = sep_field_input
if len(license_dict) > 0:
individual_info_dict.setdefault(individual_info['applicantType'], []).append(license_dict)
compare_info['individualCusInfo'] = individual_info_dict
if isinstance(last_obj.corporate_cus_info, str):
corporate_info_dict = json.loads(last_obj.corporate_cus_info)
corporate_info = {}
bl_field_input = []
for bl_field, write_field in consts.CA_CORPORATE_FIELD:
bl_field_input.append((write_field, corporate_info_dict.get(bl_field, '')))
corporate_info[consts.BL_EN] = bl_field_input
compare_info['corporateCusInfo'] = corporate_info
if last_obj.vehicle_status == consts.VEHICLE_STATUS[0] and isinstance(last_obj.usedcar_info, str):
usedcar_info_dict = json.loads(last_obj.usedcar_info)
usedcar_info = {}
mvc_field_input = []
for mvc_field in consts.CA_MVC_FIELD:
mvc_field_input.append((mvc_field, usedcar_info_dict.get(mvc_field, '')))
usedcar_info[consts.MVC_EN] = mvc_field_input
dl_field_input = []
for dl_field in consts.CA_DL_FIELD:
dl_field_input.append((dl_field, usedcar_info_dict.get(dl_field, '')))
usedcar_info[consts.DL_EN] = dl_field_input
compare_info['usedCarInfo'] = usedcar_info
return compare_info
def ca_compare_license(license_en, ocr_res_dict, field_list):
ocr_field, compare_logic, special_expiry_date = consts.CA_COMPARE_FIELD[license_en]
is_find = False
result_field_list = []
ocr_res_str = ocr_res_dict.get(ocr_field)
if ocr_res_str is not None:
ocr_res_list = json.loads(ocr_res_str)
length = len(ocr_res_list)
# 身份证、居住证 过期期限特殊处理
if special_expiry_date:
expiry_dates = set()
expiry_dates_img_path = set()
key = compare_logic.get('idExpiryDate')[0]
for ocr_res in 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, ''))
else:
expiry_dates = set()
expiry_dates_img_path = set()
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 not isinstance(ocr_str, str):
result = consts.RESULT_N
ocr_str = empty_str
else:
result = getattr(cp, compare_logic[name][1])(value, ocr_str, **compare_logic[name][2])
if idx == 0 and result == consts.RESULT_N and length > 1:
break
is_find = True
# 过期期限特殊处理
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:
next_img_path = expiry_dates_img_path.pop() if len(expiry_dates_img_path) > 0 else empty_str
img_path = ocr_res_list[res_idx].get(consts.IMG_PATH_KEY_2, next_img_path)
else:
img_path = empty_str
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
result_field_list.append((name, value, result, ocr_str, img_path, error_type))
if not is_find:
for name, value in field_list:
result_field_list.append((name, value, consts.RESULT_N, empty_str, empty_str, ErrorType.NF.value))
return result_field_list
def ca_compare_process(compare_info, ocr_res_dict):
# individualCusInfo
# corporateCusInfo
# usedCarInfo
compare_result = []
total_fields = 0
failed_count = 0
for info_key, info_value in compare_info.items():
if info_key == 'individualCusInfo':
for idx, license_list in info_value.items():
for license_dict in license_list:
for license_en, field_list in license_dict.items():
result_field_list = ca_compare_license(license_en, ocr_res_dict, field_list)
for name, value, result, ocr_str, img_path, error_type in result_field_list:
total_fields += 1
if result == consts.RESULT_N:
failed_count += 1
compare_result.append(
{
consts.HEAD_LIST[0]: info_key,
consts.HEAD_LIST[1]: idx,
consts.HEAD_LIST[2]: license_en,
consts.HEAD_LIST[3]: name,
consts.HEAD_LIST[4]: value,
consts.HEAD_LIST[5]: ocr_str,
consts.HEAD_LIST[6]: result,
consts.HEAD_LIST[7]: empty_str,
consts.HEAD_LIST[8]: img_path,
consts.HEAD_LIST[9]: error_type,
}
)
else:
for license_en, field_list in info_value.items():
result_field_list = ca_compare_license(license_en, ocr_res_dict, field_list)
for name, value, result, ocr_str, img_path, error_type in result_field_list:
total_fields += 1
if result == consts.RESULT_N:
failed_count += 1
compare_result.append(
{
consts.HEAD_LIST[0]: info_key,
consts.HEAD_LIST[1]: "0",
consts.HEAD_LIST[2]: license_en,
consts.HEAD_LIST[3]: name,
consts.HEAD_LIST[4]: value,
consts.HEAD_LIST[5]: ocr_str,
consts.HEAD_LIST[6]: result,
consts.HEAD_LIST[7]: empty_str,
consts.HEAD_LIST[8]: img_path,
consts.HEAD_LIST[9]: error_type,
}
)
return compare_result, total_fields, failed_count
def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict):
start_time = datetime.now()
try:
# 比对逻辑
compare_info = get_ca_compare_info(last_obj)
compare_result, total_fields, failed_count = ca_compare_process(compare_info, ocr_res_dict)
compare_log.info('{0} [CA] [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:
compare_log.error('{0} [CA] [compare error] [entity={1}] [id={2}] [ocr_res_id={3}] '
'[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id,
traceback.format_exc()))
else:
# 将比对结果写入数据库
try:
result_table = HILCACompareResult if application_entity == consts.HIL_PREFIX else AFCCACompareResult
res_obj = result_table.objects.filter(application_id=application_id).first()
if res_obj is None:
res_obj = result_table()
res_obj.application_id = application_id
res_obj.compare_count = total_fields
res_obj.failed_count = failed_count
res_obj.is_finish = failed_count == 0
res_obj.version = '{0}{1}{2}'.format(consts.INFO_SOURCE[0], consts.SPLIT_STR, last_obj.application_version)
# res_obj.reason1_count = reason1_count
res_obj.result = json.dumps(compare_result)
res_obj.save()
compare_log.info('{0} [CA] [result save success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format(
log_base, application_entity, application_id, ocr_res_id))
except Exception as e:
compare_log.error('{0} [CA] [result save error] [entity={1}] [id={2}] [ocr_res_id={3}] '
'[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id,
traceback.format_exc()))
compare_failed = False
application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format(
conf.BASE_URL, application_entity, consts.COMPARE_DOC_SCHEME_LIST[0], application_id)
# 比对信息
try:
......@@ -209,8 +437,8 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
'applicationVersion': last_obj.application_version,
'vehicleStatus': last_obj.vehicle_status,
'wholeResult': 'N',
'wholeResultMessage': '',
'applicationLink': r'//china.bmw.corp/WINFS/SF-CN-data/SF3-CN-S/SF3-CN-S-1-New Business/CA/OCR II test',
'wholeResultMessage': empty_str,
'applicationLink': application_link,
}
})
......@@ -230,7 +458,7 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
sep_name = order_individual_cus_info.get('customerChineseName')
if isinstance(sep_name, str):
sep_name = sep_name.strip()
if sep_name == '':
if sep_name == empty_str:
sep_name = None
else:
sep_name = None
......@@ -296,12 +524,12 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
consts.PCUSD_DL, res_set)
if mvc_find is True and dl_find is False:
vino = dl_vinos[-1] if len(dl_vinos) > 0 else ''
vino = dl_vinos[-1] if len(dl_vinos) > 0 else empty_str
order_usedcar_info[consts.PCUSD_MVC[0][0]] = '{0}-{1} {2} {3}-{4}'.format(
consts.PREFIX_MVC, consts.RESULT_Y, consts.SPLIT, consts.PREFIX_DL, vino)
order_usedcar_info[consts.PCUSD_MVC[0][4]] = consts.RESULT_N
elif mvc_find is False and dl_find is True:
vino = mvc_vinos[-1] if len(mvc_vinos) > 0 else ''
vino = mvc_vinos[-1] if len(mvc_vinos) > 0 else empty_str
order_usedcar_info[consts.PCUSD_MVC[0][0]] = '{0}-{1} {2} {3}-{4}'.format(
consts.PREFIX_MVC, vino, consts.SPLIT, consts.PREFIX_DL, consts.RESULT_Y)
order_usedcar_info[consts.PCUSD_MVC[0][4]] = consts.RESULT_N
......@@ -310,8 +538,8 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
order_usedcar_info[consts.PCUSD_MVC[0][0]] = None
order_usedcar_info[consts.PCUSD_MVC[0][4]] = consts.RESULT_NA
else:
mvc_vino = mvc_vinos[-1] if len(mvc_vinos) > 0 else ''
dl_vino = dl_vinos[-1] if len(dl_vinos) > 0 else ''
mvc_vino = mvc_vinos[-1] if len(mvc_vinos) > 0 else empty_str
dl_vino = dl_vinos[-1] if len(dl_vinos) > 0 else empty_str
vino = '{0}-{1} {2} {3}-{4}'.format(
consts.PREFIX_MVC, mvc_vino, consts.SPLIT, consts.PREFIX_DL, dl_vino)
order_usedcar_info[consts.PCUSD_MVC[0][0]] = vino
......@@ -452,7 +680,7 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
failure_reason = '、'.join(reason_list)
else:
failure_reason = ''
failure_reason = empty_str
request_trigger = RequestTrigger.SUBMITING.value if ocr_res_id is None else RequestTrigger.UPLOADING.value
report_class = HILCompareReport if application_entity == consts.HIL_PREFIX else AFCCompareReport
......@@ -652,7 +880,7 @@ def se_compare_license(license_en, ocr_res_dict, field_list):
ocr_str = ocr_res_list[res_idx].get(compare_logic[name][0])
if not isinstance(ocr_str, str):
result = consts.RESULT_N
ocr_str = ''
ocr_str = empty_str
else:
result = getattr(cp, compare_logic[name][1])(value, ocr_str, **compare_logic[name][2])
......@@ -670,11 +898,13 @@ def se_compare_license(license_en, ocr_res_dict, field_list):
result = expiry_date_res
break
result_field_list.append((name, value, result, ocr_str))
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
result_field_list.append((name, value, result, ocr_str, img_path, error_type))
if not is_find:
for name, value in field_list:
result_field_list.append((name, value, consts.RESULT_N, ''))
result_field_list.append((name, value, consts.RESULT_N, empty_str, empty_str, ErrorType.NF.value))
return result_field_list
......@@ -694,19 +924,21 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list):
first_res = None
for res_idx in range(length-1, -1, -1):
if consts.TRANSFER_DATE in ocr_res_list[res_idx]:
img_path = ocr_res_list[res_idx].get(consts.IMG_PATH_KEY, '')
for idx, transfer_date in enumerate(ocr_res_list[res_idx].get(consts.TRANSFER_DATE, [])):
try:
transfer_name = ocr_res_list[res_idx].get(consts.TRANSFER_NAME, [])[idx]
except Exception as e:
transfer_name = ''
transfer_name = empty_str
try:
transfer_num = ocr_res_list[res_idx].get(consts.TRANSFER_NUM, [])[idx]
except Exception as e:
transfer_num = ''
transfer_num = empty_str
core_info = {
consts.TRANSFER_NAME: transfer_name,
consts.TRANSFER_NUM: transfer_num,
consts.TRANSFER_DATE: transfer_date
consts.TRANSFER_DATE: transfer_date,
consts.IMG_PATH_KEY: img_path,
}
page34_date_dict.setdefault(transfer_date, []).append(core_info)
if first_res is None:
......@@ -729,14 +961,16 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list):
ocr_str = ocr_res.get(compare_logic[name][0])
if not isinstance(ocr_str, str):
result = consts.RESULT_N
ocr_str = ''
ocr_str = empty_str
else:
result = getattr(cp, compare_logic[name][1])(value, ocr_str, **compare_logic[name][2])
result_field_list.append((name, value, result, ocr_str))
img_path = ocr_res.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
result_field_list.append((name, value, result, ocr_str, img_path, error_type))
if not is_find:
for name, value in field_list:
result_field_list.append((name, value, consts.RESULT_N, ''))
result_field_list.append((name, value, consts.RESULT_N, empty_str, empty_str, ErrorType.NF.value))
return result_field_list
......@@ -759,7 +993,7 @@ def se_compare_process(compare_info, ocr_res_dict):
for license_en, field_list in license_dict.items():
failure_field = []
result_field_list = se_compare_license(license_en, ocr_res_dict, field_list)
for name, value, result, ocr_str in result_field_list:
for name, value, result, ocr_str, img_path, error_type in result_field_list:
total_fields += 1
if result == consts.RESULT_N:
failed_count += 1
......@@ -767,16 +1001,16 @@ def se_compare_process(compare_info, ocr_res_dict):
failure_field.append(name)
compare_result.append(
{
'Info': info_key,
'Index': idx,
'License': license_en,
'Field': name,
'Input': value,
'OCR': ocr_str,
'Result': result,
'Position': '',
'Image': '',
'errorType': '',
consts.HEAD_LIST[0]: info_key,
consts.HEAD_LIST[1]: idx,
consts.HEAD_LIST[2]: license_en,
consts.HEAD_LIST[3]: name,
consts.HEAD_LIST[4]: value,
consts.HEAD_LIST[5]: ocr_str,
consts.HEAD_LIST[6]: result,
consts.HEAD_LIST[7]: empty_str,
consts.HEAD_LIST[8]: img_path,
consts.HEAD_LIST[9]: error_type,
}
)
if len(failure_field) > 0:
......@@ -788,7 +1022,7 @@ def se_compare_process(compare_info, ocr_res_dict):
result_field_list = se_mvc34_compare(license_en, ocr_res_dict, field_list)
else:
result_field_list = se_compare_license(license_en, ocr_res_dict, field_list)
for name, value, result, ocr_str in result_field_list:
for name, value, result, ocr_str, img_path, error_type in result_field_list:
total_fields += 1
if result == consts.RESULT_N:
failed_count += 1
......@@ -796,16 +1030,16 @@ def se_compare_process(compare_info, ocr_res_dict):
failure_field.append(name)
compare_result.append(
{
'Info': info_key,
'Index': 0,
'License': license_en,
'Field': name,
'Input': value,
'OCR': ocr_str,
'Result': result,
'Position': '',
'Image': '',
'errorType': '',
consts.HEAD_LIST[0]: info_key,
consts.HEAD_LIST[1]: "0",
consts.HEAD_LIST[2]: license_en,
consts.HEAD_LIST[3]: name,
consts.HEAD_LIST[4]: value,
consts.HEAD_LIST[5]: ocr_str,
consts.HEAD_LIST[6]: result,
consts.HEAD_LIST[7]: empty_str,
consts.HEAD_LIST[8]: img_path,
consts.HEAD_LIST[9]: error_type,
}
)
if len(failure_field) > 0:
......@@ -840,6 +1074,8 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
res_obj.application_id = application_id
res_obj.compare_count = total_fields
res_obj.failed_count = failed_count
res_obj.is_finish = failed_count == 0
res_obj.version = '{0}{1}{2}'.format(consts.INFO_SOURCE[0], consts.SPLIT_STR, last_obj.application_version)
# res_obj.reason1_count = reason1_count
res_obj.result = json.dumps(compare_result)
res_obj.save()
......
......@@ -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!