aa782a35 by 王聪

pre settlement pos 接口提交

1 parent e1915d08
1 ID_EN = 'PRC ID'
2 PP_EN = 'Passport'
3 EEP_EN = 'Resident Permit to Mainland'
4 RP_EN = 'Resident ID'
5 BL_EN = 'Business permit'
6 SME_BL_EN = 'SME Business permit'
7 MVI_EN = 'newCar Invoice'
8 UCI_EN = 'usedCar Invoice'
9 MVC_EN = 'Green Book(1/2)'
10 MVC34_EN = 'Green Book(3/4)'
11 BC_EN = 'Bank Card'
12 DDA_EN = 'DDA'
13 HMH_EN = 'Mortgage Waiver Letter'
14 JYPZ_EN = 'Used Car Document'
15 AFC_CONTRACT_EN = 'AFC Contract'
16 BD_EN = 'Insurance'
17 BS_EN = 'Bank Statement'
18 HIL_CONTRACT_1_EN = '售后回租合同'
19 HIL_CONTRACT_2_EN = '车辆租赁抵押合同'
20 HIL_CONTRACT_3_EN = '车辆处置协议'
21
22
23 OCR_COMPARE_COMMENT = {
24
25 }
...\ No newline at end of file ...\ No newline at end of file
...@@ -49,7 +49,7 @@ from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult ...@@ -49,7 +49,7 @@ from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult
49 from .mixins import DocHandler, MPOSHandler 49 from .mixins import DocHandler, MPOSHandler
50 from . import consts 50 from . import consts
51 from apps.account.authentication import OAuth2AuthenticationWithUser 51 from apps.account.authentication import OAuth2AuthenticationWithUser
52 from celery_compare.tasks import compare 52 from celery_compare.tasks import compare, pos_compare
53 53
54 54
55 class CustomDate(fields.Date): 55 class CustomDate(fields.Date):
...@@ -222,6 +222,7 @@ se_compare_content = { ...@@ -222,6 +222,7 @@ se_compare_content = {
222 'applicationId': fields.Str(required=True, validate=validate.Length(max=64)), 222 'applicationId': fields.Str(required=True, validate=validate.Length(max=64)),
223 "applicationVersion": fields.Int(required=True), 223 "applicationVersion": fields.Int(required=True),
224 'applicationEntity': fields.Str(required=True, validate=validate.OneOf(consts.ENTITY)), 224 'applicationEntity': fields.Str(required=True, validate=validate.OneOf(consts.ENTITY)),
225
225 'customerType': fields.Str(required=True, validate=validate.OneOf(consts.CUSTOMER_TYPE)), 226 'customerType': fields.Str(required=True, validate=validate.OneOf(consts.CUSTOMER_TYPE)),
226 "firstSubmmisonDate": CustomDate(required=True), 227 "firstSubmmisonDate": CustomDate(required=True),
227 'propertyDocumentPolicy': fields.Str(required=False, validate=validate.Length(max=16)), 228 'propertyDocumentPolicy': fields.Str(required=False, validate=validate.Length(max=16)),
...@@ -264,7 +265,7 @@ document_args = { ...@@ -264,7 +265,7 @@ document_args = {
264 'documentName': fields.Str(required=True, validate=validate.Length(max=255)), 265 'documentName': fields.Str(required=True, validate=validate.Length(max=255)),
265 # Acceptance/Settlement/Contract Management 266 # Acceptance/Settlement/Contract Management
266 'documentScheme': fields.Str(required=True, validate=validate.Length(max=64)), 267 'documentScheme': fields.Str(required=True, validate=validate.Length(max=64)),
267 'businessType': fields.Str(required=True, validate=validate.Length(max=64)), # CO00001/CO00002 268 'businessType': fields.Str(required=True, validate=validate.Length(max=64)), # CO00001/CO00002
268 'uploadFinishTime': fields.DateTime(required=True), 269 'uploadFinishTime': fields.DateTime(required=True),
269 'dataSource': fields.Str(required=True, validate=validate.Length(max=64)), # POS/EAPP/Econtract 270 'dataSource': fields.Str(required=True, validate=validate.Length(max=64)), # POS/EAPP/Econtract
270 'metadataVersionId': fields.Str(required=True, validate=validate.Length(max=64)), 271 'metadataVersionId': fields.Str(required=True, validate=validate.Length(max=64)),
...@@ -529,6 +530,7 @@ class UploadDocView(GenericView, DocHandler): ...@@ -529,6 +530,7 @@ class UploadDocView(GenericView, DocHandler):
529 # authentication_classes = [] 530 # authentication_classes = []
530 permission_classes = [IsAuthenticated] 531 permission_classes = [IsAuthenticated]
531 authentication_classes = [OAuth2AuthenticationWithUser] 532 authentication_classes = [OAuth2AuthenticationWithUser]
533
532 # required_scopes = ['write'] 534 # required_scopes = ['write']
533 535
534 # 上传(接收)文件接口 536 # 上传(接收)文件接口
...@@ -573,7 +575,7 @@ class UploadDocView(GenericView, DocHandler): ...@@ -573,7 +575,7 @@ class UploadDocView(GenericView, DocHandler):
573 # if document_name.endswith('.zip'): 575 # if document_name.endswith('.zip'):
574 # self.running_log.info('[doc upload success] [zip file skip] [args={0}]'.format(args)) 576 # self.running_log.info('[doc upload success] [zip file skip] [args={0}]'.format(args))
575 # return response.ok() 577 # return response.ok()
576 578
577 if data_source == consts.DATA_SOURCE_LIST[1]: 579 if data_source == consts.DATA_SOURCE_LIST[1]:
578 if document_name.endswith('-证书.pdf') or document_name.endswith('-证书'): 580 if document_name.endswith('-证书.pdf') or document_name.endswith('-证书'):
579 self.running_log.info('[doc upload success] [eapp license skip] [args={0}]'.format(args)) 581 self.running_log.info('[doc upload success] [eapp license skip] [args={0}]'.format(args))
...@@ -779,7 +781,21 @@ class SECompareView(GenericView): ...@@ -779,7 +781,21 @@ class SECompareView(GenericView):
779 bank_obj.on_off = False 781 bank_obj.on_off = False
780 bank_obj.save() 782 bank_obj.save()
781 783
782 return response.ok() 784 # compare_result = pos_compare()
785 compare_result = {
786 "is_pass": True,
787 "particulars": [{
788 "object_name": "PRC ID",
789 "fields": [{
790 "input": "张三",
791 "ocr": "张三",
792 "field_is_pass": True,
793 "comments": "身份证姓名与系统不一致"
794 }]
795 }]
796 }
797
798 return response.ok(data=compare_result)
783 799
784 post.openapi_doc = ''' 800 post.openapi_doc = '''
785 tags: [info] 801 tags: [info]
...@@ -865,10 +881,10 @@ class DocView(GenericView, DocHandler): ...@@ -865,10 +881,10 @@ class DocView(GenericView, DocHandler):
865 application_id_query = Q(application_id__contains=application_id) if application_id is not None else Q() 881 application_id_query = Q(application_id__contains=application_id) if application_id is not None else Q()
866 data_source_query = Q(data_source=data_source) if data_source is not None else Q() 882 data_source_query = Q(data_source=data_source) if data_source is not None else Q()
867 upload_finish_time_query = Q(upload_finish_time__gte=upload_time_start, 883 upload_finish_time_query = Q(upload_finish_time__gte=upload_time_start,
868 upload_finish_time__lt=upload_time_end + datetime.timedelta(days=1))\ 884 upload_finish_time__lt=upload_time_end + datetime.timedelta(days=1)) \
869 if upload_time_start is not None and upload_time_end is not None else Q() 885 if upload_time_start is not None and upload_time_end is not None else Q()
870 create_time_query = Q(create_time__gte=create_time_start, 886 create_time_query = Q(create_time__gte=create_time_start,
871 create_time__lt=create_time_end + datetime.timedelta(days=1))\ 887 create_time__lt=create_time_end + datetime.timedelta(days=1)) \
872 if create_time_start is not None and create_time_end is not None else Q() 888 if create_time_start is not None and create_time_end is not None else Q()
873 query = application_id_query & status_query & data_source_query & upload_finish_time_query & create_time_query 889 query = application_id_query & status_query & data_source_query & upload_finish_time_query & create_time_query
874 val_tuple = ('id', 'application_id', 'upload_finish_time', 'create_time', 'document_scheme', 'data_source', 890 val_tuple = ('id', 'application_id', 'upload_finish_time', 'create_time', 'document_scheme', 'data_source',
...@@ -880,10 +896,11 @@ class DocView(GenericView, DocHandler): ...@@ -880,10 +896,11 @@ class DocView(GenericView, DocHandler):
880 if start_index >= total > 0: 896 if start_index >= total > 0:
881 raise self.invalid_params('页数不存在') 897 raise self.invalid_params('页数不存在')
882 898
883 doc_queryset = doc_class.objects.filter(query).values(*val_tuple).order_by('-create_time')[start_index: end_index] 899 doc_queryset = doc_class.objects.filter(query).values(*val_tuple).order_by('-create_time')[
900 start_index: end_index]
884 # doc_list = self.get_doc_list(doc_queryset, prefix) 901 # doc_list = self.get_doc_list(doc_queryset, prefix)
885 for doc_dict in doc_queryset: 902 for doc_dict in doc_queryset:
886 tmp_scheme = consts.COMPARE_DOC_SCHEME_LIST[0] if doc_dict['document_scheme'] == consts.DOC_SCHEME_LIST[0]\ 903 tmp_scheme = consts.COMPARE_DOC_SCHEME_LIST[0] if doc_dict['document_scheme'] == consts.DOC_SCHEME_LIST[0] \
887 else consts.COMPARE_DOC_SCHEME_LIST[1] 904 else consts.COMPARE_DOC_SCHEME_LIST[1]
888 application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format( 905 application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format(
889 conf.BASE_URL, prefix, tmp_scheme, doc_dict['application_id']) 906 conf.BASE_URL, prefix, tmp_scheme, doc_dict['application_id'])
...@@ -930,7 +947,6 @@ class DocView(GenericView, DocHandler): ...@@ -930,7 +947,6 @@ class DocView(GenericView, DocHandler):
930 # os.remove(tmp_save_path) 947 # os.remove(tmp_save_path)
931 # raise self.invalid_params(msg='invalid params: PDF file XSS') 948 # raise self.invalid_params(msg='invalid params: PDF file XSS')
932 949
933
934 file.close() 950 file.close()
935 # 1. 上传信息记录 951 # 1. 上传信息记录
936 application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id) 952 application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id)
...@@ -1013,7 +1029,8 @@ class CompareResultView(GenericView): ...@@ -1013,7 +1029,8 @@ class CompareResultView(GenericView):
1013 latest_compared_time = '' 1029 latest_compared_time = ''
1014 else: 1030 else:
1015 whole_result = consts.RESULT_Y if result_obj.ocr_auto_result_pass else consts.RESULT_N 1031 whole_result = consts.RESULT_Y if result_obj.ocr_auto_result_pass else consts.RESULT_N
1016 latest_compared_time = '' if result_obj.ocr_latest_comparison_time is None else result_obj.ocr_latest_comparison_time.strftime('%Y-%m-%d %H:%M') 1032 latest_compared_time = '' if result_obj.ocr_latest_comparison_time is None else result_obj.ocr_latest_comparison_time.strftime(
1033 '%Y-%m-%d %H:%M')
1017 1034
1018 source = consts.INFO_SOURCE[1] 1035 source = consts.INFO_SOURCE[1]
1019 version = comments = '' 1036 version = comments = ''
...@@ -1029,7 +1046,8 @@ class CompareResultView(GenericView): ...@@ -1029,7 +1046,8 @@ class CompareResultView(GenericView):
1029 'source': source, 1046 'source': source,
1030 'version': version, 1047 'version': version,
1031 'comments': comments, 1048 'comments': comments,
1032 'result': [] if result_obj is None or not result_obj.ocr_auto_result else json.loads(result_obj.ocr_auto_result) 1049 'result': [] if result_obj is None or not result_obj.ocr_auto_result else json.loads(
1050 result_obj.ocr_auto_result)
1033 } 1051 }
1034 1052
1035 return response.ok(data=compare_result) 1053 return response.ok(data=compare_result)
...@@ -1064,7 +1082,8 @@ class CompareResultView(GenericView): ...@@ -1064,7 +1082,8 @@ class CompareResultView(GenericView):
1064 'id': 0 if result_obj is None else result_obj.id, 1082 'id': 0 if result_obj is None else result_obj.id,
1065 'application_id': case_id, 1083 'application_id': case_id,
1066 'entity': entity, 1084 'entity': entity,
1067 'scheme': consts.DOC_SCHEME_LIST[0] if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else consts.DOC_SCHEME_LIST[1], 1085 'scheme': consts.DOC_SCHEME_LIST[0] if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else
1086 consts.DOC_SCHEME_LIST[1],
1068 'whole_result': whole_result, 1087 'whole_result': whole_result,
1069 'latest_compared_time': '' if result_obj is None else result_obj.update_time.strftime('%Y-%m-%d %H:%M'), 1088 'latest_compared_time': '' if result_obj is None else result_obj.update_time.strftime('%Y-%m-%d %H:%M'),
1070 'source': source, 1089 'source': source,
...@@ -1235,7 +1254,8 @@ class SECMSView(GenericView): ...@@ -1235,7 +1254,8 @@ class SECMSView(GenericView):
1235 def post(self, request): 1254 def post(self, request):
1236 args = request.data 1255 args = request.data
1237 cms_info = args.get('content', {}) 1256 cms_info = args.get('content', {})
1238 business_type = consts.AFC_PREFIX if cms_info.get('financeCompany', '').startswith('宝马') else consts.HIL_PREFIX 1257 business_type = consts.AFC_PREFIX if cms_info.get('financeCompany', '').startswith(
1258 '宝马') else consts.HIL_PREFIX
1239 src_application_id = cms_info.get('settlemnetVerification', {}).get('applicationNo', '') 1259 src_application_id = cms_info.get('settlemnetVerification', {}).get('applicationNo', '')
1240 application_id = src_application_id[:src_application_id.rfind('-')] 1260 application_id = src_application_id[:src_application_id.rfind('-')]
1241 1261
...@@ -1350,7 +1370,7 @@ class AutoSettlementView(GenericView): ...@@ -1350,7 +1370,7 @@ class AutoSettlementView(GenericView):
1350 whole_result_query = Q(ocr_whole_result_pass=whole_result) if not isinstance(whole_result, str) else Q() 1370 whole_result_query = Q(ocr_whole_result_pass=whole_result) if not isinstance(whole_result, str) else Q()
1351 rpa_result_query = Q(rpa_result=rpa_result) if not isinstance(rpa_result, str) else Q() 1371 rpa_result_query = Q(rpa_result=rpa_result) if not isinstance(rpa_result, str) else Q()
1352 time1_query = Q(rpa_get_case_from_ocr_time__gte=get_case_from_ocr_time_start, 1372 time1_query = Q(rpa_get_case_from_ocr_time__gte=get_case_from_ocr_time_start,
1353 rpa_get_case_from_ocr_time__lt=get_case_from_ocr_time_end + datetime.timedelta(days=1))\ 1373 rpa_get_case_from_ocr_time__lt=get_case_from_ocr_time_end + datetime.timedelta(days=1)) \
1354 if get_case_from_ocr_time_start is not None and get_case_from_ocr_time_end is not None else Q() 1374 if get_case_from_ocr_time_start is not None and get_case_from_ocr_time_end is not None else Q()
1355 time2_query = Q(rpa_activated_time__gte=activated_time_start, 1375 time2_query = Q(rpa_activated_time__gte=activated_time_start,
1356 rpa_activated_time__lt=activated_time_end + datetime.timedelta(days=1)) \ 1376 rpa_activated_time__lt=activated_time_end + datetime.timedelta(days=1)) \
......
...@@ -3179,3 +3179,125 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True ...@@ -3179,3 +3179,125 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
3179 compare_log.error('{0} [Auto SE] [result save error] [entity={1}] [id={2}] [ocr_res_id={3}] ' 3179 compare_log.error('{0} [Auto SE] [result save error] [entity={1}] [id={2}] [ocr_res_id={3}] '
3180 '[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id, 3180 '[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id,
3181 traceback.format_exc())) 3181 traceback.format_exc()))
3182
3183
3184 def pos_compare(application_id, application_entity, uniq_seq, ocr_res_id=None, is_ca=True, is_cms=False):
3185 # POS: application_id, application_entity, uniq_seq, None
3186 # OCR: application_id, business_type(application_entity), None, ocr_res_id
3187
3188 compare_log.info('{0} [pos_compare] [entity={1}] [id={2}] [uniq_seq={3}] [is_ca={4}] '
3189 '[is_cms={5}]'.format(log_base, application_entity, application_id, uniq_seq,
3190 is_ca, is_cms))
3191
3192 # 根据application_id查找最新的比对信息,如果没有,结束
3193 if is_ca:
3194 comparison_class = HILComparisonInfo if application_entity == consts.HIL_PREFIX else AFCComparisonInfo
3195 else:
3196 if application_entity == consts.HIL_PREFIX:
3197 comparison_class = HILSECMSInfo if is_cms else HILSEComparisonInfo
3198 else:
3199 comparison_class = AFCSECMSInfo if is_cms else AFCSEComparisonInfo
3200 last_obj = comparison_class.objects.filter(application_id=application_id).last()
3201 if last_obj is None:
3202 compare_log.info('{0} [comparison info empty] [entity={1}] [id={2}] [uniq_seq={3}] '
3203 '[is_ca={4}] [is_cms]={5}'.format(log_base, application_entity, application_id, uniq_seq,
3204 is_ca, is_cms))
3205 return
3206
3207 # 根据application_id查找OCR累计结果指定license字段,如果没有,结束
3208 if is_ca:
3209 result_class = HILOCRResult if application_entity == consts.HIL_PREFIX else AFCOCRResult
3210 ca_ocr_res_dict = dict()
3211 else:
3212 result_class = HILSEOCRResult if application_entity == consts.HIL_PREFIX else AFCSEOCRResult
3213 ca_result_class = HILOCRResult if application_entity == consts.HIL_PREFIX else AFCOCRResult
3214 # if ocr_res_id is None:
3215 ca_ocr_res_dict = ca_result_class.objects.filter(application_id=application_id).values(
3216 *consts.CA_ADD_COMPARE_FIELDS).first()
3217 # else:
3218 # ca_ocr_res_dict = ca_result_class.objects.filter(id=ocr_res_id).values(
3219 # *consts.CA_ADD_COMPARE_FIELDS).first()
3220 ocr_res_dict = result_class.objects.filter(application_id=application_id).values(*consts.COMPARE_FIELDS).first()
3221 if ocr_res_dict is None:
3222 compare_log.info('{0} [ocr info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
3223 '[is_ca={5}] [is_cms]={6}'.format(log_base, application_entity, application_id,
3224 uniq_seq, ocr_res_id, is_ca, is_cms))
3225 return
3226
3227 if is_ca:
3228 ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict)
3229 else:
3230 id_res_list = []
3231 for field_name in consts.CA_ADD_COMPARE_FIELDS:
3232 if field_name == consts.IC_OCR_FIELD:
3233 id_res_list.append(ocr_res_dict.get(field_name))
3234 id_res_list.append(ca_ocr_res_dict.get(field_name) if isinstance(ca_ocr_res_dict, dict) else None)
3235
3236 if isinstance(ca_ocr_res_dict, dict) and isinstance(ca_ocr_res_dict.get(field_name), str):
3237 tmp_ca_result = json.loads(ca_ocr_res_dict.get(field_name))
3238 if isinstance(ocr_res_dict.get(field_name), str):
3239 tmp_se_result = json.loads(ocr_res_dict.get(field_name))
3240 tmp_ca_result.extend(tmp_se_result)
3241 ocr_res_dict[field_name] = json.dumps(tmp_ca_result)
3242 # auto settlement
3243 auto_class = HILAutoSettlement if application_entity == consts.HIL_PREFIX else AFCAutoSettlement
3244 auto_obj = auto_class.objects.filter(application_id=application_id, on_off=True).first()
3245 bank_class = HILbankVerification if application_entity == consts.HIL_PREFIX else AFCbankVerification
3246 ignore_bank = bank_class.objects.filter(application_id=application_id, on_off=True).exists()
3247 if auto_obj is not None:
3248 auto_result = se_compare_auto(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict, auto_obj, ignore_bank, id_res_list)
3249 else:
3250 auto_result = None
3251
3252 full_result = se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict, is_cms, auto_result, ignore_bank, id_res_list)
3253
3254 if auto_obj is not None:
3255 try:
3256 auto_obj.ocr_whole_result_pass = full_result
3257 auto_obj.save()
3258 compare_log.info('{0} [Auto SE] [result save success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format(
3259 log_base, application_entity, application_id, ocr_res_id))
3260 except Exception as e:
3261 compare_log.error('{0} [Auto SE] [result save error] [entity={1}] [id={2}] [ocr_res_id={3}] '
3262 '[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id,
3263 traceback.format_exc()))
3264
3265 result_table = HILCACompareResult if application_entity == consts.HIL_PREFIX else AFCCACompareResult
3266 res_obj = result_table.objects.filter(application_id=application_id).first()
3267 return pos_result_output(res_obj.result)
3268
3269
3270 # pos输出解析
3271 def pos_result_output(compare_result):
3272 result_obj = json.loads(compare_result)
3273 license_map = dict()
3274 for item in result_obj:
3275 license_en = item.get("License")
3276 if license_map.get(license_en):
3277 license_map.get(license_en).append(item)
3278 else:
3279 info_items = [item]
3280 license_map[license_en] = info_items
3281
3282 is_pass = True
3283 particulars = []
3284 for license, license_items in license_map.items():
3285 particular = {"object_name": license}
3286 fields = []
3287 particular["fields"] = fields
3288 for license_item in license_items:
3289 field = dict()
3290 field["input"] = license_item.get("Input")
3291 field["ocr"] = license_item.get("OCR")
3292 field["field_is_pass"] = license_item.get("Result") == 'Y'
3293 if not field["field_is_pass"]:
3294 is_pass = False
3295 field["comments"] = ''
3296 fields.append(field)
3297 particular["fields"] = fields
3298 particulars.append(particular)
3299
3300 return {
3301 "is_pass": is_pass,
3302 "particulars": particulars
3303 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!