530a9a8c by 周伟奇

report add go

1 parent db4b72a2
......@@ -968,3 +968,13 @@ class AFCOfflineReport(models.Model):
db_table = 'afc_offline_report'
situ_db_label = 'afc'
class GenericOCRReport(models.Model):
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
status = models.BooleanField(default=True, verbose_name="是否成功")
duration = models.IntegerField(null=True, verbose_name='处理时长')
create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
class Meta:
managed = False
db_table = 'generic_ocr_report'
......
......@@ -46,6 +46,7 @@ from .models import (
HILbankVerification,
AFCbankVerification,
MposReport,
GenericOCRReport,
)
from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult
from .mixins import DocHandler, MPOSHandler
......@@ -1510,14 +1511,34 @@ class GoView(GenericView):
@use_args(go_args, location='files')
def post(self, request, args):
files = [
('img', ('file', args.get('image'), 'application/octet-stream'))
]
go_result = requests.post(url=conf.GO_OCR_URL, files=files)
result = None
is_success = False
start_time = time.time()
try:
files = [
('img', ('file', args.get('image'), 'application/octet-stream'))
]
if go_result.status_code == 200:
result = go_result.json().get('data', '')
return response.ok(data=result)
go_result = requests.post(url=conf.GO_OCR_URL, files=files)
except Exception as e:
pass
else:
return response.res_content(3, '识别错误', data=None)
if go_result.status_code == 200:
is_success = True
result = go_result.json().get('data', '')
finally:
end_time = time.time()
duration_second = int(end_time - start_time)
try:
GenericOCRReport.objects.create(
status=is_success,
duration=duration_second,
)
except Exception as e:
self.exception_log.exception('[go view] [db save failed] [error={0}]'.format(traceback.format_exc()))
if is_success:
return response.ok(data=result)
else:
return response.error_msg(msg='识别错误')
......
......@@ -35,6 +35,10 @@ def ok(**kwargs):
return APIResponse(MetaStatus.SUCCESS.value, msg=MetaStatus.SUCCESS.verbose_name, **kwargs)
def error_msg(msg='internal error', **kwargs):
return APIResponse(MetaStatus.INTERNAL_ERROR.value, msg=msg, **kwargs)
def need_update(**kwargs):
return APIResponse(MetaStatus.NEED_UPDATE.value, msg=MetaStatus.NEED_UPDATE.verbose_name, **kwargs)
......
import pyodbc
hil_sql = """
create table generic_ocr_report
(
id bigint identity primary key,
status bit default 1 not null,
duration smallint,
create_time datetime not null
);
ALTER TABLE mpos_report ADD source tinyint default 0 not null;
"""
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!