add interface report
Showing
5 changed files
with
110 additions
and
4 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') | ... | ... |
This diff is collapsed.
Click to expand it.
... | @@ -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