9e45e68d by 周伟奇

add mpos report

1 parent e1915d08
...@@ -1902,8 +1902,6 @@ class Command(BaseCommand, LoggerMixin): ...@@ -1902,8 +1902,6 @@ class Command(BaseCommand, LoggerMixin):
1902 self.online_log.info('{0} [process complete] [task={1}]'.format(self.log_base, task_str)) 1902 self.online_log.info('{0} [process complete] [task={1}]'.format(self.log_base, task_str))
1903 os.remove(excel_path) 1903 os.remove(excel_path)
1904 finally: 1904 finally:
1905 # TODO 识别结果存一张表,方便跑报表
1906
1907 self.rebuild_contract(license_summary, contract_result_compare) 1905 self.rebuild_contract(license_summary, contract_result_compare)
1908 1906
1909 bs_rebuild = self.rebuild_bs(merged_bs_summary) 1907 bs_rebuild = self.rebuild_bs(merged_bs_summary)
......
1 from django.db import models 1 from django.db import models
2 from .named_enum import DocStatus, KeywordsType, RequestTeam, RequestTrigger, FailureReason, ProcessName, WorkflowName 2 from .named_enum import DocStatus, KeywordsType, RequestTeam, RequestTrigger, FailureReason, ProcessName, WorkflowName
3 from consts import IC_CLASSIFY
3 4
4 # Create your models here. 5 # Create your models here.
5 6
...@@ -454,6 +455,13 @@ class HILOCRReport(models.Model): ...@@ -454,6 +455,13 @@ class HILOCRReport(models.Model):
454 workflow_name = models.SmallIntegerField(null=True, verbose_name="工作流程") 455 workflow_name = models.SmallIntegerField(null=True, verbose_name="工作流程")
455 notes = models.CharField(null=True, max_length=2048, verbose_name="备注") 456 notes = models.CharField(null=True, max_length=2048, verbose_name="备注")
456 457
458 # 1. bank_name string eg. '农业银行-交易清单'
459 # 2. is_ebank boolean eg. 1
460
461 # 1. is_bs_check boolean eg. 1
462 # 2. bs_check_result int eg. 2(电子-author)
463 #
464
457 class Meta: 465 class Meta:
458 managed = False 466 managed = False
459 db_table = 'hil_ocr_report' 467 db_table = 'hil_ocr_report'
...@@ -905,3 +913,42 @@ class AFCbankVerification(models.Model): ...@@ -905,3 +913,42 @@ class AFCbankVerification(models.Model):
905 managed = False 913 managed = False
906 db_table = 'afc_bank_verification' 914 db_table = 'afc_bank_verification'
907 situ_db_label = 'afc' 915 situ_db_label = 'afc'
916
917
918 class MposReport(models.Model):
919 id = models.AutoField(primary_key=True, verbose_name="id") # 主键
920
921 doc_type = models.SmallIntegerField(default=IC_CLASSIFY, verbose_name="文件类型")
922 image_count = models.SmallIntegerField(default=0, verbose_name="图片数目")
923 # status = models.SmallIntegerField(default=, verbose_name="请求状态")
924 status = models.BooleanField(default=True, verbose_name="是否成功")
925
926 duration = models.IntegerField(null=True, verbose_name='处理时长')
927
928 create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
929
930 class Meta:
931 managed = False
932 db_table = 'mpos_report'
933
934
935 # class HILOfflineReport(models.Model):
936 # id = models.AutoField(primary_key=True, verbose_name="id") # 主键
937 #
938 # update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
939 # create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
940 #
941 # class Meta:
942 # managed = False
943 # db_table = 'hil_offline_report'
944
945
946 # new teble: hil/afc_offline_ocr_report
947 # 1. file_name string eg. 'CH-B2432.pdf'
948 # 2. doc_type int eg. 2(VAT Invoice)
949 # 3. successful_at_this_level boolean eg. 0
950 # 4. failure_reason int eg. 2(PDF)
951 # 5. duration int eg. 100
952 #
953 # id/input_folder/start_time/end_time/create_time
954
......
...@@ -4,6 +4,7 @@ import time ...@@ -4,6 +4,7 @@ import time
4 import json 4 import json
5 import random 5 import random
6 import datetime 6 import datetime
7 import traceback
7 import fitz 8 import fitz
8 import shutil 9 import shutil
9 import requests 10 import requests
...@@ -44,6 +45,7 @@ from .models import ( ...@@ -44,6 +45,7 @@ from .models import (
44 AFCAutoSettlement, 45 AFCAutoSettlement,
45 HILbankVerification, 46 HILbankVerification,
46 AFCbankVerification, 47 AFCbankVerification,
48 MposReport,
47 ) 49 )
48 from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult 50 from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult
49 from .mixins import DocHandler, MPOSHandler 51 from .mixins import DocHandler, MPOSHandler
...@@ -1467,15 +1469,37 @@ class MPOSView(GenericView, MPOSHandler): ...@@ -1467,15 +1469,37 @@ class MPOSView(GenericView, MPOSHandler):
1467 # MPOS 1469 # MPOS
1468 @use_args(mpos_args, location='data') 1470 @use_args(mpos_args, location='data')
1469 def post(self, request, args): 1471 def post(self, request, args):
1472 start_time = time.time()
1473
1470 classify = args.get('type') 1474 classify = args.get('type')
1471 result_list = [] 1475 result_list = []
1476 image_count = 0
1477 all_success = True
1472 for img_base64 in args.get('file_base64_content', []): 1478 for img_base64 in args.get('file_base64_content', []):
1473 if classify in consts.LICENSE_CLASSIFY_SET_1: 1479 image_count += 1
1474 result = self.ocr1_process(conf.MPOS_URL1, img_base64) 1480 try:
1475 else: 1481 if classify in consts.LICENSE_CLASSIFY_SET_1:
1476 result = self.ocr2_process(conf.MPOS_URL2, classify, img_base64) 1482 result = self.ocr1_process(conf.MPOS_URL1, img_base64)
1483 else:
1484 result = self.ocr2_process(conf.MPOS_URL2, classify, img_base64)
1485
1486 result_list.extend(result)
1487 except Exception as e:
1488 all_success = False
1489 continue
1477 1490
1478 result_list.extend(result) 1491 end_time = time.time()
1492 duration_second = int(end_time - start_time)
1493
1494 try:
1495 MposReport.objects.create(
1496 doc_type=classify,
1497 image_count=image_count,
1498 status=all_success,
1499 duration=duration_second,
1500 )
1501 except Exception as e:
1502 self.exception_log.exception('[mpos view] [db save failed] [error={0}]'.format(traceback.format_exc()))
1479 1503
1480 return response.ok(data=result_list) 1504 return response.ok(data=result_list)
1481 1505
......
1 import pyodbc
2
3 hil_sql = """
4 create table mpos_report
5 (
6 id bigint identity primary key,
7 doc_type tinyint default 0 not null,
8 image_count tinyint default 0 not null,
9 status bit default 1 not null,
10 duration smallint,
11 create_time datetime not null
12 );
13 """
14
15 # afc_sql = """
16 #
17 # """
18
19 hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
20
21 hil_cursor = hil_cnxn.cursor()
22 hil_cursor.execute(hil_sql)
23
24 hil_cursor.close()
25 hil_cnxn.close()
26
27 # afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True)
28 #
29 # afc_cursor = afc_cnxn.cursor()
30 # afc_cursor.execute(afc_sql)
31 #
32 # afc_cursor.close()
33 # 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!