530a9a8c by 周伟奇

report add go

1 parent db4b72a2
...@@ -968,3 +968,13 @@ class AFCOfflineReport(models.Model): ...@@ -968,3 +968,13 @@ class AFCOfflineReport(models.Model):
968 db_table = 'afc_offline_report' 968 db_table = 'afc_offline_report'
969 situ_db_label = 'afc' 969 situ_db_label = 'afc'
970 970
971
972 class GenericOCRReport(models.Model):
973 id = models.AutoField(primary_key=True, verbose_name="id") # 主键
974 status = models.BooleanField(default=True, verbose_name="是否成功")
975 duration = models.IntegerField(null=True, verbose_name='处理时长')
976 create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
977
978 class Meta:
979 managed = False
980 db_table = 'generic_ocr_report'
......
...@@ -46,6 +46,7 @@ from .models import ( ...@@ -46,6 +46,7 @@ from .models import (
46 HILbankVerification, 46 HILbankVerification,
47 AFCbankVerification, 47 AFCbankVerification,
48 MposReport, 48 MposReport,
49 GenericOCRReport,
49 ) 50 )
50 from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult 51 from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult
51 from .mixins import DocHandler, MPOSHandler 52 from .mixins import DocHandler, MPOSHandler
...@@ -1510,14 +1511,34 @@ class GoView(GenericView): ...@@ -1510,14 +1511,34 @@ class GoView(GenericView):
1510 1511
1511 @use_args(go_args, location='files') 1512 @use_args(go_args, location='files')
1512 def post(self, request, args): 1513 def post(self, request, args):
1513 files = [ 1514 result = None
1514 ('img', ('file', args.get('image'), 'application/octet-stream')) 1515 is_success = False
1515 ] 1516 start_time = time.time()
1516 1517 try:
1517 go_result = requests.post(url=conf.GO_OCR_URL, files=files) 1518 files = [
1519 ('img', ('file', args.get('image'), 'application/octet-stream'))
1520 ]
1518 1521
1519 if go_result.status_code == 200: 1522 go_result = requests.post(url=conf.GO_OCR_URL, files=files)
1520 result = go_result.json().get('data', '') 1523 except Exception as e:
1521 return response.ok(data=result) 1524 pass
1522 else: 1525 else:
1523 return response.res_content(3, '识别错误', data=None) 1526 if go_result.status_code == 200:
1527 is_success = True
1528 result = go_result.json().get('data', '')
1529 finally:
1530 end_time = time.time()
1531 duration_second = int(end_time - start_time)
1532
1533 try:
1534 GenericOCRReport.objects.create(
1535 status=is_success,
1536 duration=duration_second,
1537 )
1538 except Exception as e:
1539 self.exception_log.exception('[go view] [db save failed] [error={0}]'.format(traceback.format_exc()))
1540
1541 if is_success:
1542 return response.ok(data=result)
1543 else:
1544 return response.error_msg(msg='识别错误')
......
...@@ -35,6 +35,10 @@ def ok(**kwargs): ...@@ -35,6 +35,10 @@ def ok(**kwargs):
35 return APIResponse(MetaStatus.SUCCESS.value, msg=MetaStatus.SUCCESS.verbose_name, **kwargs) 35 return APIResponse(MetaStatus.SUCCESS.value, msg=MetaStatus.SUCCESS.verbose_name, **kwargs)
36 36
37 37
38 def error_msg(msg='internal error', **kwargs):
39 return APIResponse(MetaStatus.INTERNAL_ERROR.value, msg=msg, **kwargs)
40
41
38 def need_update(**kwargs): 42 def need_update(**kwargs):
39 return APIResponse(MetaStatus.NEED_UPDATE.value, msg=MetaStatus.NEED_UPDATE.verbose_name, **kwargs) 43 return APIResponse(MetaStatus.NEED_UPDATE.value, msg=MetaStatus.NEED_UPDATE.verbose_name, **kwargs)
40 44
......
1 import pyodbc 1 import pyodbc
2 2
3 hil_sql = """ 3 hil_sql = """
4 create table generic_ocr_report
5 (
6 id bigint identity primary key,
7 status bit default 1 not null,
8 duration smallint,
9 create_time datetime not null
10 );
11
4 ALTER TABLE mpos_report ADD source tinyint default 0 not null; 12 ALTER TABLE mpos_report ADD source tinyint default 0 not null;
5 """ 13 """
6 14
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!