802a919c by 周伟奇

fix merge

2 parents c61cf5a2 12a2684f
...@@ -6,4 +6,5 @@ urlpatterns = [ ...@@ -6,4 +6,5 @@ urlpatterns = [
6 path(r'v1', views.CompareView.as_view()), 6 path(r'v1', views.CompareView.as_view()),
7 path(r'settlement/v1', views.SECompareView.as_view()), 7 path(r'settlement/v1', views.SECompareView.as_view()),
8 path(r'offline/v1', views.CompareOfflineView.as_view()), 8 path(r'offline/v1', views.CompareOfflineView.as_view()),
9 path(r'result', views.CompareResultView.as_view()),
9 ] 10 ]
......
...@@ -12,6 +12,7 @@ FIXED_APPLICATION_ID_PREFIX = 'CH-S' ...@@ -12,6 +12,7 @@ FIXED_APPLICATION_ID_PREFIX = 'CH-S'
12 12
13 DOC_SCHEME_LIST = ['ACCEPTANCE', 'SETTLEMENT', 'CONTRACTMANAGEMENT'] 13 DOC_SCHEME_LIST = ['ACCEPTANCE', 'SETTLEMENT', 'CONTRACTMANAGEMENT']
14 DATA_SOURCE_LIST = ['POS', 'EAPP', 'ECONTRACT'] 14 DATA_SOURCE_LIST = ['POS', 'EAPP', 'ECONTRACT']
15 COMPARE_DOC_SCHEME_LIST = ['CA', 'SE']
15 16
16 HIL_PREFIX = 'HIL' 17 HIL_PREFIX = 'HIL'
17 AFC_PREFIX = 'AFC' 18 AFC_PREFIX = 'AFC'
...@@ -1055,13 +1056,13 @@ IC_RES_MAPPING = { ...@@ -1055,13 +1056,13 @@ IC_RES_MAPPING = {
1055 1: '真实证件', 1056 1: '真实证件',
1056 } 1057 }
1057 1058
1058 # ----------------- compare --------------------- 1059 # ----------------- CA compare ---------------------
1059 ENTITY = ['HIL', 'AFC'] 1060 ENTITY = ['HIL', 'AFC']
1060 CUSTOMER_TYPE = ['TCCOR', 'TCDAS', 'TCFRE', 'TCIAS', 'TCIND', 'TCSEP', 'TCURE'] 1061 CUSTOMER_TYPE = ['TCCOR', 'TCDAS', 'TCFRE', 'TCIAS', 'TCIND', 'TCSEP', 'TCURE']
1061 NO_COMPARE_CUSTOMER_TYPE = ['TCFRE', 'TCIND'] 1062 NO_COMPARE_CUSTOMER_TYPE = ['TCFRE', 'TCIND']
1062 VEHICLE_STATUS = ['PCUSD', 'PCNEW'] 1063 VEHICLE_STATUS = ['PCUSD', 'PCNEW']
1063 1064
1064 APPLICANT_TYPE = ['COAPP', 'CUSTR', 'GAUTR1', 'GAUTR2'] 1065 APPLICANT_TYPE = ['CUSTR', 'COAPP', 'GAUTR1', 'GAUTR2']
1065 ID_TYPE = ['ITARI', 'ITHKM', 'ITPRC', 'ITPSP', 'ITRES', 'ITTID', 'ITUSC', 'ITCCU'] 1066 ID_TYPE = ['ITARI', 'ITHKM', 'ITPRC', 'ITPSP', 'ITRES', 'ITTID', 'ITUSC', 'ITCCU']
1066 SECOND_ID_TYPE = ['ITARI', 'ITHKM', 'ITPRC', 'ITPSP', 'ITRES', 'ITTID'] 1067 SECOND_ID_TYPE = ['ITARI', 'ITHKM', 'ITPRC', 'ITPSP', 'ITRES', 'ITTID']
1067 SUB_TYPE = ['CSIBM', 'CSOTH', 'CSSME'] 1068 SUB_TYPE = ['CSIBM', 'CSOTH', 'CSSME']
...@@ -1087,22 +1088,38 @@ EEP_OCR_FIELD = 'eep_ocr' ...@@ -1087,22 +1088,38 @@ EEP_OCR_FIELD = 'eep_ocr'
1087 DL_OCR_FIELD = 'dl_ocr' 1088 DL_OCR_FIELD = 'dl_ocr'
1088 PP_OCR_FIELD = 'pp_ocr' 1089 PP_OCR_FIELD = 'pp_ocr'
1089 MVC_OCR_FIELD = 'mvc_ocr' 1090 MVC_OCR_FIELD = 'mvc_ocr'
1091 MVI_OCR_FIELD = 'mvi_ocr'
1092 BC_OCR_FIELD = 'bc_ocr'
1093 UCI_OCR_FIELD = 'uci_ocr'
1094 DDA_OCR_FIELD = 'bs_ocr'
1090 1095
1091 RESULT_MAPPING = { 1096 RESULT_MAPPING = {
1092 # MVI_CLASSIFY: 'mvi_ocr', 1097 MVI_CLASSIFY: MVI_OCR_FIELD,
1093 IC_CLASSIFY: IC_OCR_FIELD, 1098 IC_CLASSIFY: IC_OCR_FIELD,
1094 RP_CLASSIFY: RP_OCR_FIELD, 1099 RP_CLASSIFY: RP_OCR_FIELD,
1095 # BC_CLASSIFY: 'bc_ocr', 1100 BC_CLASSIFY: BC_OCR_FIELD,
1096 BL_CLASSIFY: BL_OCR_FIELD, 1101 BL_CLASSIFY: BL_OCR_FIELD,
1097 # UCI_CLASSIFY: 'uci_ocr', 1102 UCI_CLASSIFY: UCI_OCR_FIELD,
1098 EEP_CLASSIFY: EEP_OCR_FIELD, 1103 EEP_CLASSIFY: EEP_OCR_FIELD,
1099 DL_CLASSIFY: DL_OCR_FIELD, 1104 DL_CLASSIFY: DL_OCR_FIELD,
1100 PP_CLASSIFY: PP_OCR_FIELD, 1105 PP_CLASSIFY: PP_OCR_FIELD,
1101 MVC_CLASSIFY: MVC_OCR_FIELD, 1106 MVC_CLASSIFY: MVC_OCR_FIELD,
1107 DDA_CLASSIFY: DDA_OCR_FIELD,
1102 # VAT_CLASSIFY: 'vat_ocr', 1108 # VAT_CLASSIFY: 'vat_ocr',
1103 } 1109 }
1104 1110
1105 COMPARE_FIELDS = (IC_OCR_FIELD, RP_OCR_FIELD, BL_OCR_FIELD, EEP_OCR_FIELD, DL_OCR_FIELD, PP_OCR_FIELD, MVC_OCR_FIELD) 1111 COMPARE_FIELDS = (MVI_OCR_FIELD,
1112 IC_OCR_FIELD,
1113 RP_OCR_FIELD,
1114 BC_OCR_FIELD,
1115 BL_OCR_FIELD,
1116 UCI_OCR_FIELD,
1117 EEP_OCR_FIELD,
1118 DL_OCR_FIELD,
1119 PP_OCR_FIELD,
1120 MVC_OCR_FIELD,
1121 DDA_OCR_FIELD,
1122 )
1106 1123
1107 # 身份证 1124 # 身份证
1108 ITPRC = [ 1125 ITPRC = [
...@@ -1253,5 +1270,167 @@ DDA_MAPPING = [ ...@@ -1253,5 +1270,167 @@ DDA_MAPPING = [
1253 1270
1254 DDA_PRO_MIN = 0.6 1271 DDA_PRO_MIN = 0.6
1255 1272
1273 # ----------------------- SE compare -----------------------
1274 SE_FIRST_ID_FIELD = ['customerName', 'idNum', 'dateOfBirth', 'idExpiryDate']
1275 SE_ID_CARD_FIELD = ['customerName', 'idNum', 'dateOfBirth', 'idExpiryDate', 'hukouProvince', 'hukouCity']
1276 SE_SECOND_ID_FIELD = [
1277 ('customerName', 'customerName'),
1278 ('secondIdNum', 'idNum'),
1279 ]
1280 SE_CORPORATE_ID_FIELD = [
1281 ('legalRepName', 'customerName'),
1282 ('firstIdNo', 'idNum')
1283 ]
1284 SE_SEP_FIELD = [
1285 ('companyName', 'companyName'),
1286 ('customerName', 'legalRepName'),
1287 ('registeredCapital', 'registeredCapital'),
1288 ('selfEmployedSubType', 'organizationType')
1289 ]
1290 SE_CORPORATE_FIELD = ['companyName', 'legalRepName', 'businessLicenseNo', 'organizationCreditCode',
1291 'taxRegistrationCertificateNo', 'establishmentDate', 'businessLicenseDueDate']
1292 SE_CORPORATE_ALL_FIELD = ['companyName', 'legalRepName', 'firstIdNo', 'businessLicenseNo', 'organizationCreditCode',
1293 'taxRegistrationCertificateNo', 'establishmentDate', 'businessLicenseDueDate']
1294 SE_NEW_FIELD = ['vinNo', 'dealer', 'vehicleTransactionAmount']
1295 SE_USED_FIELD = ['vinNo', 'vehicleTransactionAmount']
1296 SE_NEW_ADD_FIELD = ['customerName', 'idNum', 'dateOfInvoice']
1297 SE_GB_NEW_FIELD = ['vinNo']
1298 SE_GB_USED_FIELD = ['customerName', 'idNum', 'date']
1299
1300 SE_BANK_FIELD = ['accountNo', 'bankName']
1301 SE_DDA_FIELD = ['applicationId(1)', 'applicationId(2)', 'bankName', 'companyName', 'customerName', 'idNum', 'accountHolderName', 'accountNo']
1302
1303 HIL_COMPANY_NAME = '先锋国际融资租赁有限公司'
1304 AFC_COMPANY_NAME = '宝马汽车金融(中国)有限公司'
1305
1306 ID_EN = 'PRC ID'
1307 PP_EN = 'Passport'
1308 EEP_EN = 'Resident Permit to Mainland'
1309 RP_EN = 'Resident ID'
1310 BL_EN = 'Business permit'
1311 MVI_EN = 'newCar Invoice'
1312 UCI_EN = 'usedCar Invoice'
1313 MVC_EN = 'Green Book'
1314 BC_EN = 'Bank Card'
1315 DDA_EN = 'DDA'
1316
1317 ID_COMPARE_LOGIC = {
1318 'customerName': ('姓名', 'se_name_compare', {}),
1319 'idNum': ('公民身份号码', 'se_common_compare', {}),
1320 'dateOfBirth': ('出生年月', 'se_date_compare', {'input_replace': ''}),
1321 'idExpiryDate': ('有效期限', 'se_date_compare', {'long': True, 'ocr_split': True, 'input_replace': ''}),
1322 'hukouProvince': ('住址', 'se_contain_compare', {}),
1323 'hukouCity': ('住址', 'se_contain_compare', {}),
1324 }
1325
1326 PP_COMPARE_LOGIC = {
1327 'customerName': ('英文姓名', 'se_name_compare', {'is_passport': True}),
1328 'idNum': ('护照号码', 'se_common_compare', {}),
1329 'dateOfBirth': ('出生日期', 'se_date_compare', {'input_replace': ''}),
1330 'idExpiryDate': ('有效期至', 'se_date_compare', {'input_replace': ''}),
1331 }
1332
1333 EEP_COMPARE_LOGIC = {
1334 'customerName': ('中文名', 'se_common_compare', {}),
1335 'idNum': ('证件号码', 'se_common_compare', {}),
1336 'dateOfBirth': ('出生日期', 'se_date_compare', {'input_replace': '.'}),
1337 'idExpiryDate': ('有效期限', 'se_date_compare', {'ocr_split': True, 'input_replace': '.'}),
1338 }
1339
1340 RP_COMPARE_LOGIC = {
1341 'customerName': ('姓名', 'se_name_compare', {}),
1342 'idNum': ('公民身份号码', 'se_common_compare', {}),
1343 'dateOfBirth': ('出生年月', 'se_date_compare', {'input_replace': ''}),
1344 'idExpiryDate': ('有效期限', 'se_date_compare', {'ocr_split': True, 'input_replace': ''}),
1345 'hukouProvince': ('住址', 'se_contain_compare', {}),
1346 'hukouCity': ('住址', 'se_contain_compare', {}),
1347 }
1348
1349 BL_COMPARE_LOGIC = {
1350 'companyName': ('企业名称', 'se_company_compare', {}),
1351 'legalRepName': ('经营者姓名', 'se_name_compare', {}),
1352 'firstIdNo': ('注册号', 'se_common_compare', {}),
1353 'businessLicenseNo': ('注册号', 'se_common_compare', {}),
1354 'organizationCreditCode': ('注册号', 'se_common_compare', {}),
1355 'taxRegistrationCertificateNo': ('注册号', 'se_common_compare', {}),
1356 'establishmentDate': ('成立日期', 'se_date_compare', {'ocr_replace': True}),
1357 'businessLicenseDueDate': ('营业期限', 'se_date_compare', {'ocr_split': True, 'long': True, 'ocr_replace': True}),
1358 'organizationType': ('企业类型', 'se_type_compare', {}),
1359 'registeredCapital': ('注册资本', 'se_rmb_compare', {}),
1360 }
1361
1362 MVI_COMPARE_LOGIC = {
1363 'vinNo': ('车辆识别代码', 'se_common_compare', {}),
1364 'dealer': ('销方名称', 'se_common_compare', {}),
1365 'vehicleTransactionAmount': ('价税合计小写', 'se_amount_compare', {}),
1366 'customerName': ('购方名称', 'se_name_compare', {}),
1367 'idNum': ('购买方身份证号或组织机构代码', 'se_common_compare', {}),
1368 'dateOfInvoice': ('开票日期', 'se_date_compare', {}),
1369 }
1370
1371 UCI_COMPARE_LOGIC = {
1372 'vinNo': ('车架号', 'se_common_compare', {}),
1373 'vehicleTransactionAmount': ('价税合计小写', 'se_amount_compare', {}),
1374 'customerName': ('购方名称', 'se_name_compare', {}),
1375 'idNum': ('购方纳税人识别号', 'se_common_compare', {}),
1376 }
1377
1378 MVC_COMPARE_LOGIC = {
1379 'vinNo': ('9.车辆识别代号/车架号', 'se_common_compare', {}),
1380 # 'customerName': ('姓名/名称', ),
1381 # 'idNum': ('身份证明名称/号码', ),
1382 # 'date': ('转移登记日期', ),
1383 }
1384
1385 BC_COMPARE_LOGIC = {
1386 'accountNo': ('CardNum', 'se_common_compare', {}),
1387 'bankName': ('BankName', 'se_common_compare', {}),
1388 }
1389
1390 DDA_COMPARE_LOGIC = {
1391 'applicationId(1)': ('check_Num', ),
1392 'applicationId(2)': ('check_Num', ),
1393 'bankName': ('to_bank', ),
1394 'companyName': ('to_company', ),
1395 'customerName': (DDA_IC_NAME, ),
1396 'idNum': (DDA_IC_ID, ),
1397 'accountHolderName': (DDA_BC_NAME, ),
1398 'accountNo': (DDA_BC_ID, ),
1399 }
1400
1401
1402 # MVC_OCR_FIELD = 'mvc_ocr'
1403
1404 SE_COMPARE_FIELD = {
1405 ID_EN: (IC_OCR_FIELD, ID_COMPARE_LOGIC, True),
1406 PP_EN: (PP_OCR_FIELD, PP_COMPARE_LOGIC, False),
1407 EEP_EN: (EEP_OCR_FIELD, EEP_COMPARE_LOGIC, False),
1408 RP_EN: (RP_OCR_FIELD, RP_COMPARE_LOGIC, True),
1409 BL_EN: (BL_OCR_FIELD, BL_COMPARE_LOGIC, False),
1410 MVI_EN: (MVI_OCR_FIELD, MVI_COMPARE_LOGIC, False),
1411 UCI_EN: (UCI_OCR_FIELD, UCI_COMPARE_LOGIC, False),
1412 MVC_EN: (MVC_OCR_FIELD, MVC_COMPARE_LOGIC, False),
1413 BC_EN: (BC_OCR_FIELD, BC_COMPARE_LOGIC, False),
1414 DDA_EN: (DDA_OCR_FIELD, DDA_COMPARE_LOGIC, False),
1415 }
1416
1417
1418 SE_FIRST_ID_FIELD_MAPPING = {
1419 'ITPRC': (ID_EN, SE_ID_CARD_FIELD),
1420 'ITPSP': (PP_EN, SE_FIRST_ID_FIELD),
1421 'ITHKM': (EEP_EN, SE_FIRST_ID_FIELD),
1422 'ITTID': (EEP_EN, SE_FIRST_ID_FIELD),
1423 'ITRES': (RP_EN, SE_FIRST_ID_FIELD),
1424 }
1425
1426 SE_SECOND_ID_FIELD_MAPPING = {
1427 'ITPRC': (ID_EN, SE_SECOND_ID_FIELD),
1428 'ITPSP': (PP_EN, SE_SECOND_ID_FIELD),
1429 'ITHKM': (EEP_EN, SE_SECOND_ID_FIELD),
1430 'ITTID': (EEP_EN, SE_SECOND_ID_FIELD),
1431 'ITRES': (RP_EN, SE_SECOND_ID_FIELD),
1432 }
1433
1434 HEAD_LIST = ['Info', 'Index', 'License', 'Field', 'Input', 'OCR', 'Result', 'Position', 'Image', 'errorType']
1256 1435
1257 1436
......
...@@ -23,7 +23,21 @@ from apps.doc.ocr.edms import EDMS, rh ...@@ -23,7 +23,21 @@ from apps.doc.ocr.edms import EDMS, rh
23 from apps.doc.named_enum import KeywordsType, FailureReason, WorkflowName, ProcessName, RequestTeam, RequestTrigger 23 from apps.doc.named_enum import KeywordsType, FailureReason, WorkflowName, ProcessName, RequestTeam, RequestTrigger
24 from apps.doc.exceptions import EDMSException, OCR1Exception, OCR2Exception, OCR4Exception 24 from apps.doc.exceptions import EDMSException, OCR1Exception, OCR2Exception, OCR4Exception
25 from apps.doc.ocr.wb import BSWorkbook 25 from apps.doc.ocr.wb import BSWorkbook
26 from apps.doc.models import DocStatus, HILDoc, AFCDoc, Keywords, HILOCRResult, AFCOCRResult, HILOCRReport, AFCOCRReport, DDARecords, IDBCRecords, Configs 26 from apps.doc.models import (
27 DocStatus,
28 HILDoc,
29 AFCDoc,
30 Keywords,
31 HILOCRResult,
32 AFCOCRResult,
33 AFCSEOCRResult,
34 HILOCRReport,
35 HILSEOCRResult,
36 AFCOCRReport,
37 DDARecords,
38 IDBCRecords,
39 Configs,
40 )
27 from celery_compare.tasks import compare 41 from celery_compare.tasks import compare
28 42
29 43
...@@ -990,16 +1004,22 @@ class Command(BaseCommand, LoggerMixin): ...@@ -990,16 +1004,22 @@ class Command(BaseCommand, LoggerMixin):
990 finally: 1004 finally:
991 # TODO 识别结果存一张表,方便跑报表 1005 # TODO 识别结果存一张表,方便跑报表
992 1006
993 # CA比对 1007 # 比对
994 if doc.document_scheme == consts.DOC_SCHEME_LIST[0] and len(license_summary) > 0: 1008 if len(license_summary) > 0 and doc.document_scheme != consts.DOC_SCHEME_LIST[2]:
995 try: 1009 try:
1010 is_ca = True if doc.document_scheme == consts.DOC_SCHEME_LIST[0] else False
996 # 更新OCR累计识别结果表 1011 # 更新OCR累计识别结果表
997 result_class = HILOCRResult if business_type == consts.HIL_PREFIX else AFCOCRResult 1012 if business_type == consts.HIL_PREFIX:
1013 result_class = HILOCRResult if is_ca else HILSEOCRResult
1014 else:
1015 result_class = AFCOCRResult if is_ca else AFCSEOCRResult
998 res_obj = result_class.objects.filter(application_id=doc.application_id).first() 1016 res_obj = result_class.objects.filter(application_id=doc.application_id).first()
999 if res_obj is None: 1017 if res_obj is None:
1000 res_obj = result_class() 1018 res_obj = result_class()
1001 res_obj.application_id = doc.application_id 1019 res_obj.application_id = doc.application_id
1002 for classify, field in consts.RESULT_MAPPING.items(): 1020 for classify, field in consts.RESULT_MAPPING.items():
1021 if not hasattr(res_obj, field):
1022 continue
1003 license_list = license_summary.get(classify) 1023 license_list = license_summary.get(classify)
1004 if not license_list: 1024 if not license_list:
1005 continue 1025 continue
...@@ -1009,8 +1029,6 @@ class Command(BaseCommand, LoggerMixin): ...@@ -1009,8 +1029,6 @@ class Command(BaseCommand, LoggerMixin):
1009 elif classify == consts.RP_CLASSIFY and rp_merge: 1029 elif classify == consts.RP_CLASSIFY and rp_merge:
1010 license_list[0].update(license_list[1]) 1030 license_list[0].update(license_list[1])
1011 license_list.pop(1) 1031 license_list.pop(1)
1012 if not hasattr(res_obj, field):
1013 continue
1014 old_res_str = getattr(res_obj, field) 1032 old_res_str = getattr(res_obj, field)
1015 if old_res_str is None: 1033 if old_res_str is None:
1016 last_res_str = json.dumps(license_list) 1034 last_res_str = json.dumps(license_list)
...@@ -1030,8 +1048,8 @@ class Command(BaseCommand, LoggerMixin): ...@@ -1030,8 +1048,8 @@ class Command(BaseCommand, LoggerMixin):
1030 # 触发比对 1048 # 触发比对
1031 try: 1049 try:
1032 # pass 1050 # pass
1033 compare.apply_async((doc.application_id, business_type, None, res_obj.id), 1051 compare.apply_async((doc.application_id, business_type, None, res_obj.id,
1034 queue='queue_compare') 1052 is_ca), queue='queue_compare')
1035 except Exception as e: 1053 except Exception as e:
1036 self.online_log.error( 1054 self.online_log.error(
1037 '{0} [process error (comparison info send)] [task={1}] [error={2}]'.format( 1055 '{0} [process error (comparison info send)] [task={1}] [error={2}]'.format(
......
...@@ -51,6 +51,7 @@ class ProcessName(NamedEnum): ...@@ -51,6 +51,7 @@ class ProcessName(NamedEnum):
51 IDCARD = (2, 'F2_IDReport') 51 IDCARD = (2, 'F2_IDReport')
52 DDA = (3, 'CL_S1_DDAConsolidation') 52 DDA = (3, 'CL_S1_DDAConsolidation')
53 CACOMPARE = (4, 'S1_CA_DocumentVerify') 53 CACOMPARE = (4, 'S1_CA_DocumentVerify')
54 SE_CACOMPARE = (5, 'S1_SE_DocumentVerify')
54 55
55 56
56 class WorkflowName(NamedEnum): 57 class WorkflowName(NamedEnum):
......
...@@ -6,7 +6,7 @@ import datetime ...@@ -6,7 +6,7 @@ import datetime
6 import fitz 6 import fitz
7 import shutil 7 import shutil
8 from django.utils import timezone 8 from django.utils import timezone
9 from django.db.utils import IntegrityError 9 from django.http import HttpResponse
10 from django.db.models import Q 10 from django.db.models import Q
11 from rest_framework.permissions import IsAuthenticated 11 from rest_framework.permissions import IsAuthenticated
12 from webargs import fields, validate 12 from webargs import fields, validate
...@@ -16,7 +16,21 @@ from common import response ...@@ -16,7 +16,21 @@ from common import response
16 from common.mixins import GenericView 16 from common.mixins import GenericView
17 from common.tools.file_tools import file_write 17 from common.tools.file_tools import file_write
18 from common.redis_cache import redis_handler as rh 18 from common.redis_cache import redis_handler as rh
19 from .models import DocStatus, PriorityApplication, GCAPRecords, AFCComparisonInfo, HILComparisonInfo, AFCCompareOfflineReport, HILCompareOfflineReport 19 from .models import (
20 DocStatus,
21 PriorityApplication,
22 GCAPRecords,
23 AFCComparisonInfo,
24 AFCSEComparisonInfo,
25 HILComparisonInfo,
26 HILSEComparisonInfo,
27 AFCCompareOfflineReport,
28 HILCompareOfflineReport,
29 AFCCACompareResult,
30 AFCSECompareResult,
31 HILCACompareResult,
32 HILSECompareResult,
33 )
20 from .mixins import DocHandler 34 from .mixins import DocHandler
21 from . import consts 35 from . import consts
22 from apps.account.authentication import OAuth2AuthenticationWithUser 36 from apps.account.authentication import OAuth2AuthenticationWithUser
...@@ -257,6 +271,13 @@ doc_list_args = { ...@@ -257,6 +271,13 @@ doc_list_args = {
257 'create_time_end': fields.Date(required=False), 271 'create_time_end': fields.Date(required=False),
258 } 272 }
259 273
274 compare_result_args = {
275 'entity': fields.Str(required=True, validate=validate.OneOf(consts.BUSINESS_TYPE_LIST)),
276 'scheme': fields.Str(required=True, validate=validate.OneOf(consts.COMPARE_DOC_SCHEME_LIST)),
277 'id': fields.Int(required=False, validate=lambda val: val >= 1),
278 'case_id': fields.Str(required=True, validate=validate.Length(max=64)),
279 }
280
260 upload_pdf_args = { 281 upload_pdf_args = {
261 'pdf_file': fields.Raw(required=True), 282 'pdf_file': fields.Raw(required=True),
262 } 283 }
...@@ -474,7 +495,8 @@ class CompareView(GenericView): ...@@ -474,7 +495,8 @@ class CompareView(GenericView):
474 corporate_cus_info=corporate_cus_info, 495 corporate_cus_info=corporate_cus_info,
475 ) 496 )
476 # 触发比对 497 # 触发比对
477 compare.apply_async((application_id, business_type, uniq_seq, None), queue='queue_compare') 498 compare.apply_async((application_id, business_type, uniq_seq, None, True),
499 queue='queue_compare')
478 return response.ok() 500 return response.ok()
479 501
480 post.openapi_doc = ''' 502 post.openapi_doc = '''
...@@ -504,7 +526,38 @@ class SECompareView(GenericView): ...@@ -504,7 +526,38 @@ class SECompareView(GenericView):
504 # pos上传比对信息接口 SE 526 # pos上传比对信息接口 SE
505 @use_args(se_compare_args, location='data') 527 @use_args(se_compare_args, location='data')
506 def post(self, request, args): 528 def post(self, request, args):
507 self.running_log.info('se compare in') 529 # 存库
530 content = args.get('content', {})
531 uniq_seq = content.get('uniqSeq')
532 business_type = content.get('applicationEntity')
533 application_id = content.get('applicationId')
534
535 individual_cus_info = json.dumps(content.get('individualCusInfo'))
536 vehicle_info = json.dumps(content.get('vehicleInfo'))
537 insurance_info = json.dumps(content.get('insuranceInfo'))
538 bank_info = json.dumps(content.get('bankInfo'))
539 quotationt_info = json.dumps(content.get('quotationtInfo'))
540 corporate_cus_info = json.dumps(content.get('corporateCusInfo')) if isinstance(
541 content.get('corporateCusInfo'), dict) else None
542
543 comparison_class = HILSEComparisonInfo if business_type in consts.HIL_SET else AFCSEComparisonInfo
544 comparison_class.objects.create(
545 uniq_seq=uniq_seq,
546 application_id=application_id,
547 application_version=content.get('applicationVersion'),
548 customer_type=content.get('customerType'),
549 first_submmison_date=content.get('firstSubmmisonDate'),
550 property_doc_policy=content.get('propertyDocumentPolicy', None),
551 individual_cus_info=individual_cus_info,
552 corporate_cus_info=corporate_cus_info,
553 vehicle_info=vehicle_info,
554 insurance_info=insurance_info,
555 bank_info=bank_info,
556 quotationt_info=quotationt_info
557 )
558 # 触发比对
559 compare.apply_async((application_id, business_type, uniq_seq, None, False),
560 queue='queue_compare')
508 return response.ok() 561 return response.ok()
509 562
510 post.openapi_doc = ''' 563 post.openapi_doc = '''
...@@ -695,3 +748,59 @@ class DocView(GenericView, DocHandler): ...@@ -695,3 +748,59 @@ class DocView(GenericView, DocHandler):
695 is_priority, enqueue_res)) 748 is_priority, enqueue_res))
696 data = {'excel_path': os.path.join(save_dir_path, '{0}.xlsx'.format(doc.id))} 749 data = {'excel_path': os.path.join(save_dir_path, '{0}.xlsx'.format(doc.id))}
697 return response.ok(data=data) 750 return response.ok(data=data)
751
752
753 class CompareResultView(GenericView):
754
755 # 获取比对结果
756 @use_args(compare_result_args, location='querystring')
757 def get(self, request, args):
758 result_id = args.get('id', None)
759 entity = args.get('entity')
760 scheme = args.get('scheme')
761 case_id = args.get('case_id')
762
763 if entity == consts.HIL_PREFIX:
764 result_table = HILCACompareResult if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else HILSECompareResult
765 else:
766 result_table = AFCCACompareResult if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else AFCSECompareResult
767
768 if result_id is None:
769 result_str_list = result_table.objects.filter(id=result_id).values_list('result', flat=True)
770 else:
771 result_str_list = result_table.objects.filter(application_id=case_id).values_list('result', flat=True)
772
773 if len(result_str_list) == 0:
774 compare_result_list = []
775 else:
776 compare_result_list = json.loads(result_str_list[0])
777
778 if len(compare_result_list) == 0:
779 body_html = "<h1>没有比对结果</h1>"
780 else:
781 head_content = ''.join(['<th>{0}</th>'.format(head_name) for head_name in consts.HEAD_LIST])
782 head_html = '<tr>{0}</tr>'.format(head_content)
783 row_html_list = []
784 for row_dict in compare_result_list:
785 row_list = [row_dict.get(head, '') for head in consts.HEAD_LIST]
786 row_content = ''.join(['<td>{0}</td>'.format(row_str) for row_str in row_list])
787 row_html = '<tr>{0}</tr>'.format(row_content)
788 row_html_list.append(row_html)
789 content_html = ''.join(row_html_list)
790 body_html = '<table border="1">{0}{1}</table>'.format(head_html, content_html)
791
792 html = """
793 <!DOCTYPE html>
794 <html>
795 <head>
796 <meta charset="utf-8">
797 <title>比对结果</title>
798 </head>
799 <body>
800 {0}
801 </body>
802 </html>
803 """.format(body_html)
804 return HttpResponse(html)
805
806 # return response.ok(data=compare_result)
......
...@@ -136,6 +136,85 @@ class Comparison: ...@@ -136,6 +136,85 @@ class Comparison:
136 136
137 return self.build_res(input_str == compare_str), compare_str 137 return self.build_res(input_str == compare_str), compare_str
138 138
139 def se_name_compare(self, input_str, ocr_str, **kwargs):
140 if kwargs.get('is_passport'):
141 input_tmp = input_str.upper().replace(' ', '')
142 ocr_tmp = ocr_str.upper().replace(' ', '')
143 if input_tmp.find(ocr_tmp) == -1:
144 return self.RESULT_N
145 else:
146 return self.RESULT_Y
147 else:
148 # if re.search(r'[a-zA-Z]]', input_str):
149 # return self.RESULT_NA, ocr_str
150 input_s = input_str.translate(self.TRANS)
151 ocr_s = ocr_str.translate(self.TRANS)
152 return self.build_res(input_s == ocr_s)
153
154 def se_common_compare(self, input_str, ocr_str, **kwargs):
155 return self.build_res(input_str == ocr_str)
156
157 def se_date_compare(self, input_str, ocr_str, **kwargs):
158 if kwargs.get('long', False):
159 if '长期' in ocr_str or '永久' in ocr_str:
160 if input_str in ['2099-12-31', '2099-01-01', '2999-12-31', '2999-01-01']:
161 return self.RESULT_Y
162 else:
163 return self.RESULT_N
164 if kwargs.get('ocr_split', False):
165 if '至' in ocr_str:
166 ocr_str = ocr_str.split('至')[-1]
167 elif '-' in ocr_str:
168 ocr_str = ocr_str.split('-')[-1]
169 if kwargs.get('ocr_replace', False):
170 ocr_str = ocr_str.replace('年', '-').replace('月', '-').replace('日', '')
171 if kwargs.get('input_replace') is not None:
172 input_str = input_str.replace('-', kwargs.get('input_replace'))
173 return self.build_res(input_str == ocr_str)
174
175 def se_contain_compare(self, input_str, ocr_str, **kwargs):
176 if ocr_str.find(input_str) == -1:
177 return self.RESULT_N
178 else:
179 return self.RESULT_Y
180
181 def se_amount_compare(self, input_str, ocr_str, **kwargs):
182 if input_str == ocr_str:
183 return self.RESULT_Y
184 else:
185 try:
186 float_input = float(input_str)
187 float_ocr = float(ocr_str)
188 except Exception as e:
189 return self.RESULT_N
190 else:
191 return self.build_res(float_ocr == float_input)
192
193 def se_company_compare(self, input_str, ocr_str, **kwargs):
194 input_tmp = re.sub(self.re_obj, '', input_str).strip()
195 ocr_tmp = re.sub(self.re_obj, '', ocr_str).strip()
196 return self.build_res(input_tmp == ocr_tmp)
197
198 def se_rmb_compare(self, input_str, ocr_str, **kwargs):
199 try:
200 ocr_lower = rmb_handler.to_rmb_lower(ocr_str)
201 res = self.build_res(float(input_str) == ocr_lower)
202 # input_rmb_upper = to_rmb_upper(float(input_str))
203 # res = self.build_res(input_rmb_upper == ocr_str)
204 except Exception as e:
205 return self.RESULT_N
206 else:
207 return res
208
209 def se_type_compare(self, input_str, ocr_str, **kwargs):
210 for map_tuple in self.TYPE_MAPPING:
211 if re.search(map_tuple[0], ocr_str) is not None:
212 compare_str = map_tuple[1]
213 break
214 else:
215 compare_str = self.CSOTH
216 return self.build_res(input_str == compare_str)
217
139 218
140 cp = Comparison() 219 cp = Comparison()
141 220
......
1 import pyodbc
2
3
4 hil_sql = """
5 create table hil_se_comparison_info
6 (
7 id bigint identity primary key,
8 uniq_seq nvarchar(128) not null,
9 application_id nvarchar(64) not null,
10 application_version tinyint default 0 not null,
11 customer_type nvarchar(16) not null,
12 first_submmison_date nvarchar(16) not null,
13 property_doc_policy nvarchar(16),
14
15 individual_cus_info nvarchar(max) not null,
16 corporate_cus_info nvarchar(max),
17 vehicle_info nvarchar(max) not null,
18 insurance_info nvarchar(max) not null,
19 bank_info nvarchar(max) not null,
20 quotationt_info nvarchar(max) not null,
21
22 update_time datetime not null,
23 create_time datetime not null
24 );
25
26 create index hil_se_comparison_info_application_id_index
27 on hil_se_comparison_info (application_id);
28
29 create index hil_se_comparison_info_create_time_index
30 on hil_se_comparison_info (create_time);
31
32 create index hil_se_comparison_info_uniq_seq_index
33 on hil_se_comparison_info (uniq_seq);
34
35 create table hil_se_ocr_result
36 (
37 id int identity primary key,
38 application_id nvarchar(64) not null,
39 bs_ocr nvarchar(max),
40 mvi_ocr nvarchar(max),
41 ic_ocr nvarchar(max),
42 rp_ocr nvarchar(max),
43 bc_ocr nvarchar(max),
44 bl_ocr nvarchar(max),
45 uci_ocr nvarchar(max),
46 eep_ocr nvarchar(max),
47 dl_ocr nvarchar(max),
48 pp_ocr nvarchar(max),
49 mvc_ocr nvarchar(max),
50 vat_ocr nvarchar(max),
51 update_time datetime not null,
52 create_time datetime not null
53 );
54
55 create unique index hil_se_ocr_result_application_id_uindex
56 on hil_se_ocr_result (application_id);
57
58 create table hil_ca_compare_result
59 (
60 id int identity primary key,
61 application_id nvarchar(64) not null,
62 is_finish bit default 0 not null,
63 compare_count smallint default 0 not null,
64 failed_count smallint default 0 not null,
65 reason1_count smallint default 0 not null,
66 reason2_count smallint default 0 not null,
67 reason3_count smallint default 0 not null,
68 reason4_count smallint default 0 not null,
69 reason5_count smallint default 0 not null,
70 reason6_count smallint default 0 not null,
71 reason7_count smallint default 0 not null,
72 reason8_count smallint default 0 not null,
73 reason9_count smallint default 0 not null,
74 reason10_count smallint default 0 not null,
75 result nvarchar(max),
76 update_time datetime not null,
77 create_time datetime not null
78 );
79
80 create unique index hil_ca_compare_result_application_id_uindex
81 on hil_ca_compare_result (application_id);
82
83 create index hil_ca_compare_result_update_time_index
84 on hil_ca_compare_result (update_time);
85
86 create table hil_se_compare_result
87 (
88 id int identity primary key,
89 application_id nvarchar(64) not null,
90 is_finish bit default 0 not null,
91 compare_count smallint default 0 not null,
92 failed_count smallint default 0 not null,
93 reason1_count smallint default 0 not null,
94 reason2_count smallint default 0 not null,
95 reason3_count smallint default 0 not null,
96 reason4_count smallint default 0 not null,
97 reason5_count smallint default 0 not null,
98 reason6_count smallint default 0 not null,
99 reason7_count smallint default 0 not null,
100 reason8_count smallint default 0 not null,
101 reason9_count smallint default 0 not null,
102 reason10_count smallint default 0 not null,
103 result nvarchar(max),
104 update_time datetime not null,
105 create_time datetime not null
106 );
107
108 create unique index hil_se_compare_result_application_id_uindex
109 on hil_se_compare_result (application_id);
110
111 create index hil_se_compare_result_update_time_index
112 on hil_se_compare_result (update_time);
113 """
114
115 afc_sql = """
116 create table afc_se_comparison_info
117 (
118 id bigint identity primary key,
119 uniq_seq nvarchar(128) not null,
120 application_id nvarchar(64) not null,
121 application_version tinyint default 0 not null,
122 customer_type nvarchar(16) not null,
123 first_submmison_date nvarchar(16) not null,
124 property_doc_policy nvarchar(16),
125
126 individual_cus_info nvarchar(max) not null,
127 corporate_cus_info nvarchar(max),
128 vehicle_info nvarchar(max) not null,
129 insurance_info nvarchar(max) not null,
130 bank_info nvarchar(max) not null,
131 quotationt_info nvarchar(max) not null,
132
133 update_time datetime not null,
134 create_time datetime not null
135 );
136
137 create index afc_se_comparison_info_application_id_index
138 on afc_se_comparison_info (application_id);
139
140 create index afc_se_comparison_info_create_time_index
141 on afc_se_comparison_info (create_time);
142
143 create index afc_se_comparison_info_uniq_seq_index
144 on afc_se_comparison_info (uniq_seq);
145
146 create table afc_se_ocr_result
147 (
148 id int identity primary key,
149 application_id nvarchar(64) not null,
150 bs_ocr nvarchar(max),
151 mvi_ocr nvarchar(max),
152 ic_ocr nvarchar(max),
153 rp_ocr nvarchar(max),
154 bc_ocr nvarchar(max),
155 bl_ocr nvarchar(max),
156 uci_ocr nvarchar(max),
157 eep_ocr nvarchar(max),
158 dl_ocr nvarchar(max),
159 pp_ocr nvarchar(max),
160 mvc_ocr nvarchar(max),
161 vat_ocr nvarchar(max),
162 update_time datetime not null,
163 create_time datetime not null
164 );
165
166 create unique index afc_se_ocr_result_application_id_uindex
167 on afc_se_ocr_result (application_id);
168
169 create table afc_ca_compare_result
170 (
171 id int identity primary key,
172 application_id nvarchar(64) not null,
173 is_finish bit default 0 not null,
174 compare_count smallint default 0 not null,
175 failed_count smallint default 0 not null,
176 reason1_count smallint default 0 not null,
177 reason2_count smallint default 0 not null,
178 reason3_count smallint default 0 not null,
179 reason4_count smallint default 0 not null,
180 reason5_count smallint default 0 not null,
181 reason6_count smallint default 0 not null,
182 reason7_count smallint default 0 not null,
183 reason8_count smallint default 0 not null,
184 reason9_count smallint default 0 not null,
185 reason10_count smallint default 0 not null,
186 result nvarchar(max),
187 update_time datetime not null,
188 create_time datetime not null
189 );
190
191 create unique index afc_ca_compare_result_application_id_uindex
192 on afc_ca_compare_result (application_id);
193
194 create index afc_ca_compare_result_update_time_index
195 on afc_ca_compare_result (update_time);
196
197 create table afc_se_compare_result
198 (
199 id int identity primary key,
200 application_id nvarchar(64) not null,
201 is_finish bit default 0 not null,
202 compare_count smallint default 0 not null,
203 failed_count smallint default 0 not null,
204 reason1_count smallint default 0 not null,
205 reason2_count smallint default 0 not null,
206 reason3_count smallint default 0 not null,
207 reason4_count smallint default 0 not null,
208 reason5_count smallint default 0 not null,
209 reason6_count smallint default 0 not null,
210 reason7_count smallint default 0 not null,
211 reason8_count smallint default 0 not null,
212 reason9_count smallint default 0 not null,
213 reason10_count smallint default 0 not null,
214 result nvarchar(max),
215 update_time datetime not null,
216 create_time datetime not null
217 );
218
219 create unique index afc_se_compare_result_application_id_uindex
220 on afc_se_compare_result (application_id);
221
222 create index afc_se_compare_result_update_time_index
223 on afc_se_compare_result (update_time);
224 """
225
226 hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
227 hil_cursor = hil_cnxn.cursor()
228 hil_cursor.execute(hil_sql)
229 hil_cursor.close()
230 hil_cnxn.close()
231
232 afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
233 afc_cursor = afc_cnxn.cursor()
234 afc_cursor.execute(afc_sql)
235 afc_cursor.close()
236 afc_cnxn.close()
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!