35db299e by 周伟奇

slice1 part2

1 parent 254938ba
......@@ -1449,7 +1449,112 @@ SE_SECOND_ID_FIELD_MAPPING = {
HEAD_LIST = ['Info', 'Index', 'License', 'Field', 'Input', 'OCR', 'Result', 'Position', 'Image', 'errorType']
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),
}
......
......@@ -244,7 +244,10 @@ class Command(BaseCommand, LoggerMixin):
elif classify == consts.IC_CLASSIFY: # 身份证真伪
for id_card_dict in license_data:
id_card_dict[consts.IMG_PATH_KEY] = img_path
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:
......@@ -1030,7 +1033,7 @@ class Command(BaseCommand, LoggerMixin):
license_list = license_summary.get(classify)
if not license_list:
continue
if classify == consts.IC_CLASSIFY and ic_merge: # TODO 正反面合并时的img_path处理
if classify == consts.IC_CLASSIFY and ic_merge:
license_list[0].update(license_list[1])
license_list.pop(1)
elif classify == consts.RP_CLASSIFY and rp_merge:
......@@ -1357,9 +1360,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))
......
......@@ -546,7 +546,7 @@ class AFCSECompareResult(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
version = models.CharField(max_length=8, verbose_name="POS/CMS version")
is_finish = models.BooleanField(default=False, verbose_name="是否完成")
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数目")
......@@ -574,7 +574,7 @@ class AFCCACompareResult(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
version = models.CharField(max_length=8, verbose_name="POS/CMS version")
is_finish = models.BooleanField(default=False, verbose_name="是否完成")
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数目")
......@@ -602,7 +602,7 @@ class HILSECompareResult(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
version = models.CharField(max_length=8, verbose_name="POS/CMS version")
is_finish = models.BooleanField(default=False, verbose_name="是否完成")
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数目")
......@@ -629,7 +629,7 @@ class HILCACompareResult(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
version = models.CharField(max_length=8, verbose_name="POS/CMS version")
is_finish = models.BooleanField(default=False, verbose_name="是否完成")
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数目")
......@@ -652,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'
......
......@@ -30,6 +30,10 @@ from .models import (
AFCSECompareResult,
HILCACompareResult,
HILSECompareResult,
AFCCACompareResultRecord,
AFCSECompareResultRecord,
HILCACompareResultRecord,
HILSECompareResultRecord,
)
from .named_enum import ErrorType
from .mixins import DocHandler
......@@ -295,7 +299,6 @@ application_information = {
priority_doc_args = {
'APPLICATION_INFORMATION': fields.Nested(application_information, required=True)
}
compare_offline_args = {
......@@ -313,6 +316,32 @@ compare_offline_args = {
'workflow_name': fields.Str(required=True, validate=validate.Length(max=1024)),
}
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 = []
......@@ -776,7 +805,7 @@ class CompareResultView(GenericView):
if result_obj is None:
whole_result = ''
else:
whole_result = 'Y' if result_obj.is_finish else 'N'
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 = ''
......@@ -786,6 +815,7 @@ class CompareResultView(GenericView):
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'),
......@@ -831,40 +861,79 @@ class CompareResultView(GenericView):
# return HttpResponse(html)
# 比对结果更新
# @use_args(result_update_args, location='data')
def post(self, request):
tmp_flag = random.choice([0, 1])
if tmp_flag == 0:
return response.ok()
@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_id = None
entity = "AFC"
scheme = 'SE'
case_id = 'CH-S1120929121'
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 entity == consts.HIL_PREFIX:
result_table = HILCACompareResult if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else HILSECompareResult
else:
result_table = AFCCACompareResult if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else AFCSECompareResult
if result_id is not None:
result_obj = result_table.objects.filter(id=result_id).first()
else:
result_obj = result_table.objects.filter(application_id=case_id).first()
if result_id is not None:
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:
return response.ok()
if result_obj is None:
whole_result = ''
else:
whole_result = 'Y' if result_obj.is_finish else 'N'
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:
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 result_obj is None or result_obj.comments is None:
comments = ''
else:
comments = result_obj.comments
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:
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,
......
......@@ -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,7 +19,9 @@ from apps.doc.models import (
HILCompareReport,
AFCCompareReport,
AFCSECompareResult,
AFCCACompareResult,
HILSECompareResult,
HILCACompareResult,
)
from apps.doc import consts
from apps.doc.ocr.gcap import gcap
......@@ -29,6 +32,7 @@ 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):
......@@ -97,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])
......@@ -160,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])
......@@ -196,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:
......@@ -211,7 +438,7 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
'vehicleStatus': last_obj.vehicle_status,
'wholeResult': 'N',
'wholeResultMessage': empty_str,
'applicationLink': r'//china.bmw.corp/WINFS/SF-CN-data/SF3-CN-S/SF3-CN-S-1-New Business/CA/OCR II test',
'applicationLink': application_link,
}
})
......@@ -672,7 +899,7 @@ def se_compare_license(license_en, ocr_res_dict, field_list):
break
img_path = ocr_res_list[res_idx].get(consts.IMG_PATH_KEY, '') if result == consts.RESULT_N else empty_str
error_type = empty_str if result == consts.RESULT_Y else ErrorType.OCR.value
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:
......@@ -738,7 +965,7 @@ def se_mvc34_compare(license_en, ocr_res_dict, field_list):
else:
result = getattr(cp, compare_logic[name][1])(value, ocr_str, **compare_logic[name][2])
img_path = ocr_res.get(consts.IMG_PATH_KEY, '') if result == consts.RESULT_N else empty_str
error_type = empty_str if result == consts.RESULT_Y else ErrorType.OCR.value
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:
......@@ -774,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': empty_str,
'Image': img_path,
'errorType': error_type,
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,
}
)
failure_reason.setdefault(license_en, []).append('/'.join(failure_field))
......@@ -802,16 +1029,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': empty_str,
'Image': img_path,
'errorType': error_type,
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,
}
)
failure_reason.setdefault(license_en, []).append('/'.join(failure_field))
......
......@@ -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")
......
......@@ -3,11 +3,123 @@ 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)
......
......@@ -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
......
......@@ -10,4 +10,6 @@ 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
\ No newline at end of file
DEALER_CODE = ocr_situ_group
BASE_URL = https://staging-bmw-ocr.situdata.com
\ No newline at end of file
......
......@@ -10,4 +10,6 @@ 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
\ No newline at end of file
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!