14adf361 by 周伟奇

se compare part 2

1 parent beebba6a
...@@ -488,3 +488,16 @@ class IDBCRecords(models.Model): ...@@ -488,3 +488,16 @@ class IDBCRecords(models.Model):
488 db_table = 'idbc_records' 488 db_table = 'idbc_records'
489 489
490 490
491 class AFCSECompareResult(models.Model):
492 id = models.AutoField(primary_key=True, verbose_name="id") # 主键
493 application_id = models.CharField(max_length=64, verbose_name="申请id") # 索引
494
495 update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
496 create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
497
498 class Meta:
499 managed = False
500 db_table = 'afc_se_compare_result'
501 situ_db_label = 'afc'
502
503
......
...@@ -149,34 +149,7 @@ def usedcar_info_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_s ...@@ -149,34 +149,7 @@ def usedcar_info_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_s
149 return is_find and key_right, no_match_vino 149 return is_find and key_right, no_match_vino
150 150
151 151
152 @app.task 152 def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict):
153 def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True):
154 # POS: application_id, application_entity, uniq_seq, None
155 # OCR: application_id, business_type(application_entity), None, ocr_res_id
156
157 compare_log.info('{0} [receive task] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format(
158 log_base, application_entity, application_id, uniq_seq, ocr_res_id))
159
160 # 根据application_id查找最新的比对信息,如果没有,结束
161 comparison_class = HILComparisonInfo if application_entity == consts.HIL_PREFIX else AFCComparisonInfo
162 last_obj = comparison_class.objects.filter(application_id=application_id).last()
163 if last_obj is None:
164 compare_log.info('{0} [comparison info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format(
165 log_base, application_entity, application_id, uniq_seq, ocr_res_id))
166 return
167
168 # 根据application_id查找OCR累计结果指定license字段,如果没有,结束
169 result_class = HILOCRResult if application_entity == consts.HIL_PREFIX else AFCOCRResult
170 if ocr_res_id is None:
171 ocr_res_dict = result_class.objects.filter(application_id=application_id).values(*consts.COMPARE_FIELDS).first()
172 else:
173 ocr_res_dict = result_class.objects.filter(id=ocr_res_id).values(*consts.COMPARE_FIELDS).first()
174 if ocr_res_dict is None:
175 compare_log.info('{0} [ocr info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format(
176 log_base, application_entity, application_id, uniq_seq, ocr_res_id
177 ))
178 return
179
180 start_time = datetime.now() 153 start_time = datetime.now()
181 compare_failed = False 154 compare_failed = False
182 155
...@@ -300,38 +273,36 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True ...@@ -300,38 +273,36 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
300 273
301 comparison_res['OCR_Input']['corporateCusInfo'] = order_corporate_cus_info 274 comparison_res['OCR_Input']['corporateCusInfo'] = order_corporate_cus_info
302 275
303 comparison_res['OCR_Input']['wholeResult'] = consts.RESULT_N if consts.RESULT_N in res_set or consts.RESULT_NA in res_set else consts.RESULT_Y 276 comparison_res['OCR_Input'][
277 'wholeResult'] = consts.RESULT_N if consts.RESULT_N in res_set or consts.RESULT_NA in res_set else consts.RESULT_Y
304 278
305 except Exception as e: 279 except Exception as e:
306 compare_failed = True 280 compare_failed = True
307 compare_log.error('{0} [compare error] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] ' 281 compare_log.error('{0} [CA] [compare error] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'.format(
308 '[error={5}]'.format(log_base, application_entity, application_id, uniq_seq, ocr_res_id, 282 log_base, application_entity, application_id, ocr_res_id, traceback.format_exc()))
309 traceback.format_exc()))
310 else: 283 else:
311 compare_log.info('{0} [compare success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] ' 284 compare_log.info('{0} [CA] [compare success] [entity={1}] [id={2}] [ocr_res_id={3}] [compare_res={4}]'.format(
312 '[compare_res={5}]'.format(log_base, application_entity, application_id, uniq_seq, 285 log_base, application_entity, application_id, ocr_res_id, comparison_res))
313 ocr_res_id, comparison_res))
314 286
315 is_gcap_send = Configs.objects.filter(id=1).first() 287 is_gcap_send = Configs.objects.filter(id=1).first()
316 if is_gcap_send is not None and is_gcap_send.value == 'N': 288 if is_gcap_send is not None and is_gcap_send.value == 'N':
317 compare_log.info('{0} [gcap closed] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format( 289 compare_log.info('{0} [CA] [gcap closed] [entity={1}] [id={2}] [ocr_res_id={3}]'.format(
318 log_base, application_entity, application_id, uniq_seq, ocr_res_id)) 290 log_base, application_entity, application_id, ocr_res_id))
319 return 291 return
320 292
321 # 时间延迟 293 # 时间延迟
322 send_time = last_obj.create_time + timedelta(seconds=15) 294 send_time = last_obj.create_time + timedelta(seconds=15)
323 while datetime.now() < send_time: 295 while datetime.now() < send_time:
324 compare_log.info('{0} [time wait 5s] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format( 296 compare_log.info('{0} [CA] [time wait 5s] [entity={1}] [id={2}] [ocr_res_id={3}]'.format(
325 log_base, application_entity, application_id, uniq_seq, ocr_res_id)) 297 log_base, application_entity, application_id, ocr_res_id))
326 time.sleep(5) 298 time.sleep(5)
327 299
328 # 将比对结果发送GCAP 300 # 将比对结果发送GCAP
329 try: 301 try:
330 data = gcap.dict_to_xml(comparison_res) 302 data = gcap.dict_to_xml(comparison_res)
331 except Exception as e: 303 except Exception as e:
332 compare_log.error('{0} [dict to xml failed] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] ' 304 compare_log.error('{0} [CA] [dict to xml failed] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'.format(
333 '[error={5}]'.format(log_base, application_entity, application_id, uniq_seq, ocr_res_id, 305 log_base, application_entity, application_id, ocr_res_id, traceback.format_exc()))
334 traceback.format_exc()))
335 else: 306 else:
336 try: 307 try:
337 for times in range(consts.RETRY_TIMES): 308 for times in range(consts.RETRY_TIMES):
...@@ -344,16 +315,15 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True ...@@ -344,16 +315,15 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
344 else: 315 else:
345 raise GCAPException(gcap_exc) 316 raise GCAPException(gcap_exc)
346 except Exception as e: 317 except Exception as e:
347 compare_log.error('{0} [gcap failed] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] ' 318 compare_log.error('{0} [CA] [gcap failed] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'.format(
348 '[error={5}]'.format(log_base, application_entity, application_id, uniq_seq, 319 log_base, application_entity, application_id, ocr_res_id, traceback.format_exc()))
349 ocr_res_id, traceback.format_exc()))
350 else: 320 else:
351 compare_log.info('{0} [gcap success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] ' 321 compare_log.info('{0} [CA] [gcap success] [entity={1}] [id={2}] [ocr_res_id={3}] [response={4}]'.format(
352 '[response={5}]'.format(log_base, application_entity, application_id, uniq_seq, 322 log_base, application_entity, application_id, ocr_res_id, res_text))
353 ocr_res_id, res_text)) 323 compare_log.info('{0} [CA] [task success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format(
354 compare_log.info('{0} [task success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format( 324 log_base, application_entity, application_id, ocr_res_id))
355 log_base, application_entity, application_id, uniq_seq, ocr_res_id)) 325
356 finally: 326 # report
357 try: 327 try:
358 end_time = datetime.now() 328 end_time = datetime.now()
359 if compare_failed: 329 if compare_failed:
...@@ -361,7 +331,8 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True ...@@ -361,7 +331,8 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
361 failure_reason = 'Compare process error' 331 failure_reason = 'Compare process error'
362 total_fields = 0 332 total_fields = 0
363 else: 333 else:
364 successful_at_this_level = True if comparison_res['OCR_Input']['wholeResult'] == consts.RESULT_Y else False 334 successful_at_this_level = True if comparison_res['OCR_Input'][
335 'wholeResult'] == consts.RESULT_Y else False
365 field_failed = { 336 field_failed = {
366 'individualCusInfo': [], 337 'individualCusInfo': [],
367 'corporateCusInfo': [], 338 'corporateCusInfo': [],
...@@ -427,7 +398,6 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True ...@@ -427,7 +398,6 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
427 else: 398 else:
428 failure_reason = '' 399 failure_reason = ''
429 400
430
431 request_trigger = RequestTrigger.SUBMITING.value if ocr_res_id is None else RequestTrigger.UPLOADING.value 401 request_trigger = RequestTrigger.SUBMITING.value if ocr_res_id is None else RequestTrigger.UPLOADING.value
432 report_class = HILCompareReport if application_entity == consts.HIL_PREFIX else AFCCompareReport 402 report_class = HILCompareReport if application_entity == consts.HIL_PREFIX else AFCCompareReport
433 report_class.objects.create( 403 report_class.objects.create(
...@@ -442,10 +412,84 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True ...@@ -442,10 +412,84 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True
442 total_fields=total_fields, 412 total_fields=total_fields,
443 workflow_name=last_obj.customer_type, 413 workflow_name=last_obj.customer_type,
444 ) 414 )
445 compare_log.info('{0} [report save success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format( 415 compare_log.info(
446 log_base, application_entity, application_id, uniq_seq, ocr_res_id)) 416 '{0} [CA] [report save success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format(
417 log_base, application_entity, application_id, ocr_res_id))
418 except Exception as e:
419 compare_log.error('{0} [CA] [report save error] [entity={1}] [id={2}] [ocr_res_id={3}] '
420 '[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id,
421 traceback.format_exc()))
422
423
424 def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict):
425 try:
426 # 比对逻辑
427 pass
428 except Exception as e:
429 pass
430 else:
431 # 将比对结果写入数据库
432 try:
433 pass
434 except Exception as e:
435 pass
436
437 # report
438 try:
439 request_trigger = RequestTrigger.SUBMITING.value if ocr_res_id is None else RequestTrigger.UPLOADING.value
440 report_class = HILCompareReport if application_entity == consts.HIL_PREFIX else AFCCompareReport
441 report_class.objects.create(
442 case_number=application_id,
443 request_team=RequestTeam.SETTLEMENT.value,
444 request_trigger=request_trigger,
445 transaction_start=start_time,
446 transaction_end=end_time,
447 successful_at_this_level=successful_at_this_level,
448 failure_reason=failure_reason,
449 process_name=ProcessName.CACOMPARE.value,
450 total_fields=total_fields,
451 workflow_name=customer_type,
452 )
453 compare_log.info(
454 '{0} [SE] [report save success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format(
455 log_base, application_entity, application_id, ocr_res_id))
447 except Exception as e: 456 except Exception as e:
448 compare_log.error('{0} [report save success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] ' 457 compare_log.error('{0} [SE] [report save error] [entity={1}] [id={2}] [ocr_res_id={3}] '
449 '[error={5}]'.format(log_base, application_entity, application_id, uniq_seq, 458 '[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id,
450 ocr_res_id, traceback.format_exc())) 459 traceback.format_exc()))
460
461
462 @app.task
463 def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True):
464 # POS: application_id, application_entity, uniq_seq, None
465 # OCR: application_id, business_type(application_entity), None, ocr_res_id
466
467 compare_log.info('{0} [receive task] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] [is_ca={5}]'.format(
468 log_base, application_entity, application_id, uniq_seq, ocr_res_id, is_ca))
469
470 # 根据application_id查找最新的比对信息,如果没有,结束
471 comparison_class = HILComparisonInfo if application_entity == consts.HIL_PREFIX else AFCComparisonInfo
472 last_obj = comparison_class.objects.filter(application_id=application_id).last()
473 if last_obj is None:
474 compare_log.info('{0} [comparison info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
475 '[is_ca={5}]'.format(log_base, application_entity, application_id, uniq_seq, ocr_res_id, is_ca))
476 return
477
478 # 根据application_id查找OCR累计结果指定license字段,如果没有,结束
479 result_class = HILOCRResult if application_entity == consts.HIL_PREFIX else AFCOCRResult
480 if ocr_res_id is None:
481 ocr_res_dict = result_class.objects.filter(application_id=application_id).values(*consts.COMPARE_FIELDS).first()
482 else:
483 ocr_res_dict = result_class.objects.filter(id=ocr_res_id).values(*consts.COMPARE_FIELDS).first()
484 if ocr_res_dict is None:
485 compare_log.info('{0} [ocr info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
486 '[is_ca={5}]'.format(log_base, application_entity, application_id, uniq_seq, ocr_res_id, is_ca))
487 return
488
489 if is_ca:
490 ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict)
491 else:
492 se_compare()
493
494
451 495
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!