add interface report
Showing
5 changed files
with
233 additions
and
44 deletions
... | @@ -978,3 +978,22 @@ class GenericOCRReport(models.Model): | ... | @@ -978,3 +978,22 @@ class GenericOCRReport(models.Model): |
978 | class Meta: | 978 | class Meta: |
979 | managed = False | 979 | managed = False |
980 | db_table = 'generic_ocr_report' | 980 | db_table = 'generic_ocr_report' |
981 | |||
982 | |||
983 | class InterfaceReport(models.Model): | ||
984 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | ||
985 | |||
986 | source = models.CharField(max_length=64, verbose_name="来源") | ||
987 | target = models.CharField(max_length=64, verbose_name="目标") | ||
988 | |||
989 | body = models.TextField(null=True, verbose_name="请求体") | ||
990 | response = models.TextField(null=True, verbose_name="响应") | ||
991 | |||
992 | status = models.BooleanField(default=True, verbose_name="是否成功") | ||
993 | retry_times = models.SmallIntegerField(default=0, verbose_name="重试次数") | ||
994 | duration = models.IntegerField(verbose_name='处理时长') | ||
995 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | ||
996 | |||
997 | class Meta: | ||
998 | managed = False | ||
999 | db_table = 'interface_report' | ... | ... |
... | @@ -95,3 +95,14 @@ class BSCheckResult(NamedEnum): | ... | @@ -95,3 +95,14 @@ class BSCheckResult(NamedEnum): |
95 | class OfflineFailureReason(NamedEnum): | 95 | class OfflineFailureReason(NamedEnum): |
96 | OS_ERROR = (0, 'OS_ERROR') | 96 | OS_ERROR = (0, 'OS_ERROR') |
97 | PROCESS_ERROR = (1, 'PROCESS_ERROR') | 97 | PROCESS_ERROR = (1, 'PROCESS_ERROR') |
98 | |||
99 | |||
100 | class SystemName(NamedEnum): | ||
101 | POS = (0, 'POS') | ||
102 | EAPP = (1, 'EAPP') | ||
103 | ECONTRACT = (2, 'ECONTRACT') | ||
104 | GCAP = (3, 'GCAP') | ||
105 | CMS = (4, 'CMS') | ||
106 | MPOS = (5, 'MPOS') | ||
107 | UNKNOWN = (6, 'Unknown') | ||
108 | OCR = (7, 'OCR') | ... | ... |
... | @@ -47,8 +47,9 @@ from .models import ( | ... | @@ -47,8 +47,9 @@ from .models import ( |
47 | AFCbankVerification, | 47 | AFCbankVerification, |
48 | MposReport, | 48 | MposReport, |
49 | GenericOCRReport, | 49 | GenericOCRReport, |
50 | InterfaceReport, | ||
50 | ) | 51 | ) |
51 | from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult | 52 | from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult, SystemName |
52 | from .mixins import DocHandler, MPOSHandler | 53 | from .mixins import DocHandler, MPOSHandler |
53 | from . import consts | 54 | from . import consts |
54 | from apps.account.authentication import OAuth2AuthenticationWithUser | 55 | from apps.account.authentication import OAuth2AuthenticationWithUser |
... | @@ -536,7 +537,9 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -536,7 +537,9 @@ class UploadDocView(GenericView, DocHandler): |
536 | 537 | ||
537 | # 上传(接收)文件接口 | 538 | # 上传(接收)文件接口 |
538 | @use_args(doc_upload_args, location='data') | 539 | @use_args(doc_upload_args, location='data') |
539 | def post(self, request, args): | 540 | def post(self, request, args): # interface_report pos/eapp/econtract to ocr |
541 | start_time = time.time() | ||
542 | |||
540 | application_data = args.get('applicationData') | 543 | application_data = args.get('applicationData') |
541 | # applicant_data = args.get('applicantData') | 544 | # applicant_data = args.get('applicantData') |
542 | document = args.get('document') | 545 | document = args.get('document') |
... | @@ -545,38 +548,10 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -545,38 +548,10 @@ class UploadDocView(GenericView, DocHandler): |
545 | document_scheme = document.get('documentScheme') | 548 | document_scheme = document.get('documentScheme') |
546 | data_source = document.get('dataSource') | 549 | data_source = document.get('dataSource') |
547 | document_name = document.get('documentName', '') | 550 | document_name = document.get('documentName', '') |
548 | # main_name = self.get_name(applicant_data, 'mainApplicantName', 16) | ||
549 | # co_name = self.get_name(applicant_data, 'coApplicantName', 16) | ||
550 | # g1_name = self.get_name(applicant_data, 'guarantor1Name', 16) | ||
551 | # g2_name = self.get_name(applicant_data, 'guarantor2Name', 16) | ||
552 | |||
553 | # try: | ||
554 | # # 1. 上传信息记录 | ||
555 | # UploadDocRecords.objects.create( | ||
556 | # metadata_version_id=document.get('metadataVersionId'), | ||
557 | # application_id=application_id, | ||
558 | # main_applicant='main_name', | ||
559 | # co_applicant='co_name', | ||
560 | # guarantor_1='g1_name', | ||
561 | # guarantor_2='g2_name', | ||
562 | # document_name=document_name, | ||
563 | # document_scheme=document_scheme, | ||
564 | # business_type=business_type, | ||
565 | # data_source=data_source, | ||
566 | # upload_finish_time=document.get('uploadFinishTime'), | ||
567 | # ) | ||
568 | # except Exception as e: | ||
569 | # self.running_log.info('[doc upload success] [same file skip] [args={0}]'.format(args)) | ||
570 | # # self.invalid_params(msg='metadataVersionId repeat') | ||
571 | # return response.ok() | ||
572 | 551 | ||
573 | data_source = self.fix_data_source(data_source) | 552 | data_source = self.fix_data_source(data_source) |
574 | document_scheme = self.fix_scheme(document_scheme) | 553 | document_scheme = self.fix_scheme(document_scheme) |
575 | 554 | ||
576 | # if document_name.endswith('.zip'): | ||
577 | # self.running_log.info('[doc upload success] [zip file skip] [args={0}]'.format(args)) | ||
578 | # return response.ok() | ||
579 | |||
580 | if data_source == consts.DATA_SOURCE_LIST[1]: | 555 | if data_source == consts.DATA_SOURCE_LIST[1]: |
581 | if document_name.endswith('-证书.pdf') or document_name.endswith('-证书'): | 556 | if document_name.endswith('-证书.pdf') or document_name.endswith('-证书'): |
582 | self.running_log.info('[doc upload success] [eapp license skip] [args={0}]'.format(args)) | 557 | self.running_log.info('[doc upload success] [eapp license skip] [args={0}]'.format(args)) |
... | @@ -587,10 +562,6 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -587,10 +562,6 @@ class UploadDocView(GenericView, DocHandler): |
587 | doc = doc_class.objects.create( | 562 | doc = doc_class.objects.create( |
588 | metadata_version_id=document.get('metadataVersionId'), | 563 | metadata_version_id=document.get('metadataVersionId'), |
589 | application_id=application_id, | 564 | application_id=application_id, |
590 | # main_applicant=applicant_data.get('mainApplicantName'), | ||
591 | # co_applicant=applicant_data.get('coApplicantName'), | ||
592 | # guarantor_1=applicant_data.get('guarantor1Name'), | ||
593 | # guarantor_2=applicant_data.get('guarantor2Name'), | ||
594 | document_name=document_name, | 565 | document_name=document_name, |
595 | document_scheme=document_scheme, | 566 | document_scheme=document_scheme, |
596 | data_source=data_source, | 567 | data_source=data_source, |
... | @@ -617,6 +588,22 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -617,6 +588,22 @@ class UploadDocView(GenericView, DocHandler): |
617 | self.running_log.info('[doc upload success] [args={0}] [business_type={1}] [doc_id={2}] ' | 588 | self.running_log.info('[doc upload success] [args={0}] [business_type={1}] [doc_id={2}] ' |
618 | '[is_priority={3}] [enqueue_res={4}]'.format(args, prefix, doc.id, | 589 | '[is_priority={3}] [enqueue_res={4}]'.format(args, prefix, doc.id, |
619 | is_priority, enqueue_res)) | 590 | is_priority, enqueue_res)) |
591 | |||
592 | try: | ||
593 | end_time = time.time() | ||
594 | duration_second = int(end_time - start_time) | ||
595 | InterfaceReport.objects.create( | ||
596 | source=data_source, | ||
597 | target=SystemName.OCR.name, | ||
598 | body=json.dumps(args), | ||
599 | response=None, | ||
600 | status=True, | ||
601 | # retry_times=None, | ||
602 | duration=duration_second, | ||
603 | ) | ||
604 | except Exception as e: | ||
605 | self.exception_log.exception('[upload view] [db save failed] [error={0}]'.format(traceback.format_exc())) | ||
606 | |||
620 | return response.ok() | 607 | return response.ok() |
621 | 608 | ||
622 | post.openapi_doc = ''' | 609 | post.openapi_doc = ''' |
... | @@ -645,7 +632,9 @@ class PriorityDocView(GenericView, DocHandler): | ... | @@ -645,7 +632,9 @@ class PriorityDocView(GenericView, DocHandler): |
645 | 632 | ||
646 | # 优先级订单接口 | 633 | # 优先级订单接口 |
647 | @use_args(priority_doc_args, location='data') | 634 | @use_args(priority_doc_args, location='data') |
648 | def post(self, request, args): | 635 | def post(self, request, args): # interface_report gcap to ocr |
636 | start_time = time.time() | ||
637 | |||
649 | application_info = args.get('APPLICATION_INFORMATION') | 638 | application_info = args.get('APPLICATION_INFORMATION') |
650 | application_id = application_info.get('APPLICATION_ID') | 639 | application_id = application_info.get('APPLICATION_ID') |
651 | submit_datetime = application_info.get('SUBMIT_DATETIME') | 640 | submit_datetime = application_info.get('SUBMIT_DATETIME') |
... | @@ -681,6 +670,22 @@ class PriorityDocView(GenericView, DocHandler): | ... | @@ -681,6 +670,22 @@ class PriorityDocView(GenericView, DocHandler): |
681 | enqueue_res = rh.enqueue(tasks_list, is_priority=True) # TODO 可能把压缩文件放入优先队列 | 670 | enqueue_res = rh.enqueue(tasks_list, is_priority=True) # TODO 可能把压缩文件放入优先队列 |
682 | self.running_log.info('[priority doc success] [args={0}] [tasks_list={1}] [enqueue_res={2}]'.format( | 671 | self.running_log.info('[priority doc success] [args={0}] [tasks_list={1}] [enqueue_res={2}]'.format( |
683 | args, tasks_list, enqueue_res)) | 672 | args, tasks_list, enqueue_res)) |
673 | |||
674 | try: | ||
675 | end_time = time.time() | ||
676 | duration_second = int(end_time - start_time) | ||
677 | InterfaceReport.objects.create( | ||
678 | source=SystemName.GCAP.name, | ||
679 | target=SystemName.OCR.name, | ||
680 | body=json.dumps(args), | ||
681 | response=None, | ||
682 | status=True, | ||
683 | # retry_times=None, | ||
684 | duration=duration_second, | ||
685 | ) | ||
686 | except Exception as e: | ||
687 | self.exception_log.exception('[gcap view] [db save failed] [error={0}]'.format(traceback.format_exc())) | ||
688 | |||
684 | return response.ok() | 689 | return response.ok() |
685 | 690 | ||
686 | post.openapi_doc = ''' | 691 | post.openapi_doc = ''' |
... | @@ -709,7 +714,9 @@ class CompareView(GenericView): | ... | @@ -709,7 +714,9 @@ class CompareView(GenericView): |
709 | 714 | ||
710 | # pos上传比对信息接口 CA | 715 | # pos上传比对信息接口 CA |
711 | @use_args(compare_args, location='data') | 716 | @use_args(compare_args, location='data') |
712 | def post(self, request, args): | 717 | def post(self, request, args): # interface_report pos to ocr |
718 | start_time = time.time() | ||
719 | |||
713 | # 存库 | 720 | # 存库 |
714 | content = args.get('content', {}) | 721 | content = args.get('content', {}) |
715 | uniq_seq = content.get('uniqSeq') | 722 | uniq_seq = content.get('uniqSeq') |
... | @@ -733,6 +740,22 @@ class CompareView(GenericView): | ... | @@ -733,6 +740,22 @@ class CompareView(GenericView): |
733 | # 触发比对 | 740 | # 触发比对 |
734 | compare.apply_async((application_id, business_type, uniq_seq, None, True, False), | 741 | compare.apply_async((application_id, business_type, uniq_seq, None, True, False), |
735 | queue='queue_compare') | 742 | queue='queue_compare') |
743 | |||
744 | try: | ||
745 | end_time = time.time() | ||
746 | duration_second = int(end_time - start_time) | ||
747 | InterfaceReport.objects.create( | ||
748 | source=SystemName.POS.name, | ||
749 | target=SystemName.OCR.name, | ||
750 | body=json.dumps(args), | ||
751 | response=None, | ||
752 | status=True, | ||
753 | # retry_times=None, | ||
754 | duration=duration_second, | ||
755 | ) | ||
756 | except Exception as e: | ||
757 | self.exception_log.exception('[pos ca view] [db save failed] [error={0}]'.format(traceback.format_exc())) | ||
758 | |||
736 | return response.ok() | 759 | return response.ok() |
737 | 760 | ||
738 | post.openapi_doc = ''' | 761 | post.openapi_doc = ''' |
... | @@ -761,7 +784,9 @@ class SECompareView(GenericView): | ... | @@ -761,7 +784,9 @@ class SECompareView(GenericView): |
761 | 784 | ||
762 | # pos上传比对信息接口 SE | 785 | # pos上传比对信息接口 SE |
763 | @use_args(se_compare_args, location='data') | 786 | @use_args(se_compare_args, location='data') |
764 | def post(self, request, args): | 787 | def post(self, request, args): # interface_report pos to ocr |
788 | start_time = time.time() | ||
789 | |||
765 | # 存库 | 790 | # 存库 |
766 | content = args.get('content', {}) | 791 | content = args.get('content', {}) |
767 | business_type = content.get('applicationEntity') | 792 | business_type = content.get('applicationEntity') |
... | @@ -782,6 +807,21 @@ class SECompareView(GenericView): | ... | @@ -782,6 +807,21 @@ class SECompareView(GenericView): |
782 | bank_obj.on_off = False | 807 | bank_obj.on_off = False |
783 | bank_obj.save() | 808 | bank_obj.save() |
784 | 809 | ||
810 | try: | ||
811 | end_time = time.time() | ||
812 | duration_second = int(end_time - start_time) | ||
813 | InterfaceReport.objects.create( | ||
814 | source=SystemName.POS.name, | ||
815 | target=SystemName.OCR.name, | ||
816 | body=json.dumps(args), | ||
817 | response=None, | ||
818 | status=True, | ||
819 | # retry_times=None, | ||
820 | duration=duration_second, | ||
821 | ) | ||
822 | except Exception as e: | ||
823 | self.exception_log.exception('[pos pre view] [db save failed] [error={0}]'.format(traceback.format_exc())) | ||
824 | |||
785 | return response.ok() | 825 | return response.ok() |
786 | 826 | ||
787 | post.openapi_doc = ''' | 827 | post.openapi_doc = ''' |
... | @@ -1235,7 +1275,9 @@ class SECMSView(GenericView): | ... | @@ -1235,7 +1275,9 @@ class SECMSView(GenericView): |
1235 | 1275 | ||
1236 | # CMS上传比对信息接口 SE | 1276 | # CMS上传比对信息接口 SE |
1237 | # @use_args(se_cms_args, location='data') | 1277 | # @use_args(se_cms_args, location='data') |
1238 | def post(self, request): | 1278 | def post(self, request): # interface_report cms to ocr |
1279 | start_time = time.time() | ||
1280 | |||
1239 | args = request.data | 1281 | args = request.data |
1240 | cms_info = args.get('content', {}) | 1282 | cms_info = args.get('content', {}) |
1241 | business_type = consts.AFC_PREFIX if cms_info.get('financeCompany', '').startswith('宝马') else consts.HIL_PREFIX | 1283 | business_type = consts.AFC_PREFIX if cms_info.get('financeCompany', '').startswith('宝马') else consts.HIL_PREFIX |
... | @@ -1277,6 +1319,21 @@ class SECMSView(GenericView): | ... | @@ -1277,6 +1319,21 @@ class SECMSView(GenericView): |
1277 | compare.apply_async((application_id, business_type, None, None, False, True), | 1319 | compare.apply_async((application_id, business_type, None, None, False, True), |
1278 | queue='queue_compare') | 1320 | queue='queue_compare') |
1279 | 1321 | ||
1322 | try: | ||
1323 | end_time = time.time() | ||
1324 | duration_second = int(end_time - start_time) | ||
1325 | InterfaceReport.objects.create( | ||
1326 | source=SystemName.CMS.name, | ||
1327 | target=SystemName.OCR.name, | ||
1328 | body=json.dumps(args), | ||
1329 | response=None, | ||
1330 | status=True, | ||
1331 | # retry_times=None, | ||
1332 | duration=duration_second, | ||
1333 | ) | ||
1334 | except Exception as e: | ||
1335 | self.exception_log.exception('[cms view] [db save failed] [error={0}]'.format(traceback.format_exc())) | ||
1336 | |||
1280 | return response.ok() | 1337 | return response.ok() |
1281 | 1338 | ||
1282 | post.openapi_doc = ''' | 1339 | post.openapi_doc = ''' |
... | @@ -1469,7 +1526,7 @@ class MPOSView(GenericView, MPOSHandler): | ... | @@ -1469,7 +1526,7 @@ class MPOSView(GenericView, MPOSHandler): |
1469 | 1526 | ||
1470 | # MPOS | 1527 | # MPOS |
1471 | @use_args(mpos_args, location='data') | 1528 | @use_args(mpos_args, location='data') |
1472 | def post(self, request, args): | 1529 | def post(self, request, args): # interface_report mpos to ocr |
1473 | start_time = time.time() | 1530 | start_time = time.time() |
1474 | 1531 | ||
1475 | classify = args.get('type') | 1532 | classify = args.get('type') |
... | @@ -1502,6 +1559,19 @@ class MPOSView(GenericView, MPOSHandler): | ... | @@ -1502,6 +1559,19 @@ class MPOSView(GenericView, MPOSHandler): |
1502 | except Exception as e: | 1559 | except Exception as e: |
1503 | self.exception_log.exception('[mpos view] [db save failed] [error={0}]'.format(traceback.format_exc())) | 1560 | self.exception_log.exception('[mpos view] [db save failed] [error={0}]'.format(traceback.format_exc())) |
1504 | 1561 | ||
1562 | try: | ||
1563 | InterfaceReport.objects.create( | ||
1564 | source=SystemName.MPOS.name, | ||
1565 | target=SystemName.OCR.name, | ||
1566 | body=None, | ||
1567 | response=json.dumps(result_list), | ||
1568 | status=True, | ||
1569 | # retry_times=None, | ||
1570 | duration=duration_second, | ||
1571 | ) | ||
1572 | except Exception as e: | ||
1573 | self.exception_log.exception('[go view] [db save failed] [error={0}]'.format(traceback.format_exc())) | ||
1574 | |||
1505 | return response.ok(data=result_list) | 1575 | return response.ok(data=result_list) |
1506 | 1576 | ||
1507 | 1577 | ||
... | @@ -1510,7 +1580,7 @@ class GoView(GenericView): | ... | @@ -1510,7 +1580,7 @@ class GoView(GenericView): |
1510 | authentication_classes = [OAuth2AuthenticationWithUser] | 1580 | authentication_classes = [OAuth2AuthenticationWithUser] |
1511 | 1581 | ||
1512 | @use_args(go_args, location='files') | 1582 | @use_args(go_args, location='files') |
1513 | def post(self, request, args): | 1583 | def post(self, request, args): # interface_report unknown to ocr |
1514 | result = None | 1584 | result = None |
1515 | is_success = False | 1585 | is_success = False |
1516 | start_time = time.time() | 1586 | start_time = time.time() |
... | @@ -1538,6 +1608,19 @@ class GoView(GenericView): | ... | @@ -1538,6 +1608,19 @@ class GoView(GenericView): |
1538 | except Exception as e: | 1608 | except Exception as e: |
1539 | self.exception_log.exception('[go view] [db save failed] [error={0}]'.format(traceback.format_exc())) | 1609 | self.exception_log.exception('[go view] [db save failed] [error={0}]'.format(traceback.format_exc())) |
1540 | 1610 | ||
1611 | try: | ||
1612 | InterfaceReport.objects.create( | ||
1613 | source=SystemName.UNKNOWN.name, | ||
1614 | target=SystemName.OCR.name, | ||
1615 | body=None, | ||
1616 | response=json.dumps(result) if is_success else None, | ||
1617 | status=is_success, | ||
1618 | # retry_times=None, | ||
1619 | duration=duration_second, | ||
1620 | ) | ||
1621 | except Exception as e: | ||
1622 | self.exception_log.exception('[go view] [db save failed] [error={0}]'.format(traceback.format_exc())) | ||
1623 | |||
1541 | if is_success: | 1624 | if is_success: |
1542 | return response.ok(data=result) | 1625 | return response.ok(data=result) |
1543 | else: | 1626 | else: | ... | ... |
... | @@ -31,12 +31,13 @@ from apps.doc.models import ( | ... | @@ -31,12 +31,13 @@ from apps.doc.models import ( |
31 | AFCAutoSettlement, | 31 | AFCAutoSettlement, |
32 | HILbankVerification, | 32 | HILbankVerification, |
33 | AFCbankVerification, | 33 | AFCbankVerification, |
34 | InterfaceReport, | ||
34 | ) | 35 | ) |
35 | from apps.doc import consts | 36 | from apps.doc import consts |
36 | from apps.doc.ocr.gcap import gcap | 37 | from apps.doc.ocr.gcap import gcap |
37 | from apps.doc.ocr.cms import cms | 38 | from apps.doc.ocr.cms import cms |
38 | from apps.doc.exceptions import GCAPException | 39 | from apps.doc.exceptions import GCAPException |
39 | from apps.doc.named_enum import RequestTeam, RequestTrigger, ProcessName, ErrorType | 40 | from apps.doc.named_enum import RequestTeam, RequestTrigger, ProcessName, ErrorType, SystemName |
40 | from common.tools.comparison import cp | 41 | from common.tools.comparison import cp |
41 | from common.tools.des import decode_des | 42 | from common.tools.des import decode_des |
42 | 43 | ||
... | @@ -748,16 +749,20 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res | ... | @@ -748,16 +749,20 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res |
748 | time.sleep(5) | 749 | time.sleep(5) |
749 | 750 | ||
750 | # 将比对结果发送GCAP | 751 | # 将比对结果发送GCAP |
752 | start_time = time.time() | ||
751 | try: | 753 | try: |
752 | data = gcap.dict_to_xml(comparison_res) | 754 | data = gcap.dict_to_xml(comparison_res) |
753 | except Exception as e: | 755 | except Exception as e: |
754 | compare_log.error('{0} [CA] [dict to xml failed] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'.format( | 756 | compare_log.error('{0} [CA] [dict to xml failed] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'.format( |
755 | log_base, application_entity, application_id, ocr_res_id, traceback.format_exc())) | 757 | log_base, application_entity, application_id, ocr_res_id, traceback.format_exc())) |
756 | else: | 758 | else: |
759 | final_times = 0 | ||
760 | is_success = True | ||
757 | try: | 761 | try: |
758 | for times in range(consts.RETRY_TIMES): | 762 | for times in range(consts.RETRY_TIMES): |
763 | final_times = times | ||
759 | try: | 764 | try: |
760 | res_text = gcap.send(data) | 765 | res_text = gcap.send(data) # interface_report ocr to gcap |
761 | except Exception as e: | 766 | except Exception as e: |
762 | gcap_exc = str(e) | 767 | gcap_exc = str(e) |
763 | else: | 768 | else: |
... | @@ -765,6 +770,7 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res | ... | @@ -765,6 +770,7 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res |
765 | else: | 770 | else: |
766 | raise GCAPException(gcap_exc) | 771 | raise GCAPException(gcap_exc) |
767 | except Exception as e: | 772 | except Exception as e: |
773 | is_success = False | ||
768 | compare_log.error('{0} [CA] [gcap failed] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'.format( | 774 | compare_log.error('{0} [CA] [gcap failed] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'.format( |
769 | log_base, application_entity, application_id, ocr_res_id, traceback.format_exc())) | 775 | log_base, application_entity, application_id, ocr_res_id, traceback.format_exc())) |
770 | else: | 776 | else: |
... | @@ -772,6 +778,21 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res | ... | @@ -772,6 +778,21 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res |
772 | log_base, application_entity, application_id, ocr_res_id, res_text)) | 778 | log_base, application_entity, application_id, ocr_res_id, res_text)) |
773 | compare_log.info('{0} [CA] [task success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format( | 779 | compare_log.info('{0} [CA] [task success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format( |
774 | log_base, application_entity, application_id, ocr_res_id)) | 780 | log_base, application_entity, application_id, ocr_res_id)) |
781 | finally: | ||
782 | end_time = time.time() | ||
783 | duration_second = int(end_time - start_time) | ||
784 | try: | ||
785 | InterfaceReport.objects.create( | ||
786 | source=SystemName.OCR.name, | ||
787 | target=SystemName.GCAP.name, | ||
788 | body=data, | ||
789 | response=res_text if is_success else None, | ||
790 | status=is_success, | ||
791 | retry_times=final_times, | ||
792 | duration=duration_second, | ||
793 | ) | ||
794 | except Exception as e: | ||
795 | compare_log.error('{0} [CA] [db save failed] [error={1}]'.format(log_base, traceback.format_exc())) | ||
775 | 796 | ||
776 | # report | 797 | # report |
777 | try: | 798 | try: |
... | @@ -3087,7 +3108,9 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res | ... | @@ -3087,7 +3108,9 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res |
3087 | compare_log.info('{0} [SE] [cms closed] [entity={1}] [id={2}] [ocr_res_id={3}]'.format( | 3108 | compare_log.info('{0} [SE] [cms closed] [entity={1}] [id={2}] [ocr_res_id={3}]'.format( |
3088 | log_base, application_entity, application_id, ocr_res_id)) | 3109 | log_base, application_entity, application_id, ocr_res_id)) |
3089 | return successful_at_this_level | 3110 | return successful_at_this_level |
3090 | try: | 3111 | |
3112 | is_success = True | ||
3113 | start_time = time.time() | ||
3091 | application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format( | 3114 | application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format( |
3092 | conf.BASE_URL, application_entity, consts.COMPARE_DOC_SCHEME_LIST[1], application_id) | 3115 | conf.BASE_URL, application_entity, consts.COMPARE_DOC_SCHEME_LIST[1], application_id) |
3093 | data = { | 3116 | data = { |
... | @@ -3103,8 +3126,10 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res | ... | @@ -3103,8 +3126,10 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res |
3103 | "Origin": consts.INFO_SOURCE[1] | 3126 | "Origin": consts.INFO_SOURCE[1] |
3104 | } | 3127 | } |
3105 | } | 3128 | } |
3106 | response = cms.send(data) | 3129 | try: |
3130 | response = cms.send(data) # interface_report ocr to cms | ||
3107 | except Exception as e: | 3131 | except Exception as e: |
3132 | is_success = False | ||
3108 | compare_log.error('{0} [SE] [cms error] [entity={1}] [id={2}] [ocr_res_id={3}] ' | 3133 | compare_log.error('{0} [SE] [cms error] [entity={1}] [id={2}] [ocr_res_id={3}] ' |
3109 | '[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id, | 3134 | '[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id, |
3110 | traceback.format_exc())) | 3135 | traceback.format_exc())) |
... | @@ -3112,6 +3137,21 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res | ... | @@ -3112,6 +3137,21 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res |
3112 | compare_log.info('{0} [SE] [cms success] [entity={1}] [id={2}] [ocr_res_id={3}] [data={4}] ' | 3137 | compare_log.info('{0} [SE] [cms success] [entity={1}] [id={2}] [ocr_res_id={3}] [data={4}] ' |
3113 | '[response={5}]'.format(log_base, application_entity, application_id, ocr_res_id, | 3138 | '[response={5}]'.format(log_base, application_entity, application_id, ocr_res_id, |
3114 | data, response)) | 3139 | data, response)) |
3140 | finally: | ||
3141 | end_time = time.time() | ||
3142 | duration_second = int(end_time - start_time) | ||
3143 | try: | ||
3144 | InterfaceReport.objects.create( | ||
3145 | source=SystemName.OCR.name, | ||
3146 | target=SystemName.CMS.name, | ||
3147 | body=json.dumps(data), | ||
3148 | response=json.dumps(response) if is_success else None, | ||
3149 | status=is_success, | ||
3150 | # retry_times=None, | ||
3151 | duration=duration_second, | ||
3152 | ) | ||
3153 | except Exception as e: | ||
3154 | compare_log.error('{0} [SE] [db save failed] [error={1}]'.format(log_base, traceback.format_exc())) | ||
3115 | 3155 | ||
3116 | return successful_at_this_level | 3156 | return successful_at_this_level |
3117 | 3157 | ... | ... |
src/common/tools/mssql_script21.py
0 → 100644
1 | import pyodbc | ||
2 | |||
3 | hil_sql = """ | ||
4 | create table interface_report | ||
5 | ( | ||
6 | id bigint identity primary key, | ||
7 | source nvarchar(64) not null, | ||
8 | target nvarchar(64) not null, | ||
9 | body nvarchar(max), | ||
10 | response nvarchar(max), | ||
11 | status bit default 1 not null, | ||
12 | retry_times tinyint default 0 not null, | ||
13 | duration smallint not null, | ||
14 | create_time datetime not null | ||
15 | ); | ||
16 | """ | ||
17 | |||
18 | afc_sql = """ | ||
19 | |||
20 | """ | ||
21 | |||
22 | hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | ||
23 | |||
24 | hil_cursor = hil_cnxn.cursor() | ||
25 | hil_cursor.execute(hil_sql) | ||
26 | |||
27 | hil_cursor.close() | ||
28 | hil_cnxn.close() | ||
29 | |||
30 | afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | ||
31 | |||
32 | afc_cursor = afc_cnxn.cursor() | ||
33 | afc_cursor.execute(afc_sql) | ||
34 | |||
35 | afc_cursor.close() | ||
36 | afc_cnxn.close() |
-
Please register or sign in to post a comment