924771cd by 周伟奇

add interface report

1 parent 530a9a8c
......@@ -978,3 +978,22 @@ class GenericOCRReport(models.Model):
class Meta:
managed = False
db_table = 'generic_ocr_report'
class InterfaceReport(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
source = models.CharField(max_length=64, verbose_name="来源")
target = models.CharField(max_length=64, verbose_name="目标")
body = models.TextField(null=True, verbose_name="请求体")
response = models.TextField(null=True, verbose_name="响应")
status = models.BooleanField(default=True, verbose_name="是否成功")
retry_times = models.SmallIntegerField(default=0, verbose_name="重试次数")
duration = models.IntegerField(verbose_name='处理时长')
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
class Meta:
managed = False
db_table = 'interface_report'
......
......@@ -95,3 +95,14 @@ class BSCheckResult(NamedEnum):
class OfflineFailureReason(NamedEnum):
OS_ERROR = (0, 'OS_ERROR')
PROCESS_ERROR = (1, 'PROCESS_ERROR')
class SystemName(NamedEnum):
POS = (0, 'POS')
EAPP = (1, 'EAPP')
ECONTRACT = (2, 'ECONTRACT')
GCAP = (3, 'GCAP')
CMS = (4, 'CMS')
MPOS = (5, 'MPOS')
UNKNOWN = (6, 'Unknown')
OCR = (7, 'OCR')
......
......@@ -31,12 +31,13 @@ from apps.doc.models import (
AFCAutoSettlement,
HILbankVerification,
AFCbankVerification,
InterfaceReport,
)
from apps.doc import consts
from apps.doc.ocr.gcap import gcap
from apps.doc.ocr.cms import cms
from apps.doc.exceptions import GCAPException
from apps.doc.named_enum import RequestTeam, RequestTrigger, ProcessName, ErrorType
from apps.doc.named_enum import RequestTeam, RequestTrigger, ProcessName, ErrorType, SystemName
from common.tools.comparison import cp
from common.tools.des import decode_des
......@@ -748,16 +749,20 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
time.sleep(5)
# 将比对结果发送GCAP
start_time = time.time()
try:
data = gcap.dict_to_xml(comparison_res)
except Exception as e:
compare_log.error('{0} [CA] [dict to xml failed] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'.format(
log_base, application_entity, application_id, ocr_res_id, traceback.format_exc()))
else:
final_times = 0
is_success = True
try:
for times in range(consts.RETRY_TIMES):
final_times = times
try:
res_text = gcap.send(data)
res_text = gcap.send(data) # interface_report ocr to gcap
except Exception as e:
gcap_exc = str(e)
else:
......@@ -765,6 +770,7 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
else:
raise GCAPException(gcap_exc)
except Exception as e:
is_success = False
compare_log.error('{0} [CA] [gcap failed] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'.format(
log_base, application_entity, application_id, ocr_res_id, traceback.format_exc()))
else:
......@@ -772,6 +778,21 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
log_base, application_entity, application_id, ocr_res_id, res_text))
compare_log.info('{0} [CA] [task success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format(
log_base, application_entity, application_id, ocr_res_id))
finally:
end_time = time.time()
duration_second = int(end_time - start_time)
try:
InterfaceReport.objects.create(
source=SystemName.OCR.name,
target=SystemName.GCAP.name,
body=data,
response=res_text if is_success else None,
status=is_success,
retry_times=final_times,
duration=duration_second,
)
except Exception as e:
compare_log.error('{0} [CA] [db save failed] [error={1}]'.format(log_base, traceback.format_exc()))
# report
try:
......@@ -3087,7 +3108,9 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
compare_log.info('{0} [SE] [cms closed] [entity={1}] [id={2}] [ocr_res_id={3}]'.format(
log_base, application_entity, application_id, ocr_res_id))
return successful_at_this_level
try:
is_success = True
start_time = time.time()
application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format(
conf.BASE_URL, application_entity, consts.COMPARE_DOC_SCHEME_LIST[1], application_id)
data = {
......@@ -3103,8 +3126,10 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
"Origin": consts.INFO_SOURCE[1]
}
}
response = cms.send(data)
try:
response = cms.send(data) # interface_report ocr to cms
except Exception as e:
is_success = False
compare_log.error('{0} [SE] [cms error] [entity={1}] [id={2}] [ocr_res_id={3}] '
'[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id,
traceback.format_exc()))
......@@ -3112,6 +3137,21 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
compare_log.info('{0} [SE] [cms success] [entity={1}] [id={2}] [ocr_res_id={3}] [data={4}] '
'[response={5}]'.format(log_base, application_entity, application_id, ocr_res_id,
data, response))
finally:
end_time = time.time()
duration_second = int(end_time - start_time)
try:
InterfaceReport.objects.create(
source=SystemName.OCR.name,
target=SystemName.CMS.name,
body=json.dumps(data),
response=json.dumps(response) if is_success else None,
status=is_success,
# retry_times=None,
duration=duration_second,
)
except Exception as e:
compare_log.error('{0} [SE] [db save failed] [error={1}]'.format(log_base, traceback.format_exc()))
return successful_at_this_level
......
import pyodbc
hil_sql = """
create table interface_report
(
id bigint identity primary key,
source nvarchar(64) not null,
target nvarchar(64) not null,
body nvarchar(max),
response nvarchar(max),
status bit default 1 not null,
retry_times tinyint default 0 not null,
duration smallint not null,
create_time datetime not null
);
"""
afc_sql = """
"""
hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
hil_cursor = hil_cnxn.cursor()
hil_cursor.execute(hil_sql)
hil_cursor.close()
hil_cnxn.close()
afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
afc_cursor = afc_cnxn.cursor()
afc_cursor.execute(afc_sql)
afc_cursor.close()
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!