Merge branch 'master' into feature/pres
Showing
9 changed files
with
110 additions
and
27 deletions
... | @@ -20,7 +20,7 @@ from common.tools.pdf_to_img import PDFHandler | ... | @@ -20,7 +20,7 @@ from common.tools.pdf_to_img import PDFHandler |
20 | from apps.doc import consts | 20 | from apps.doc import consts |
21 | from apps.doc.exceptions import OCR1Exception, OCR2Exception, LTGTException | 21 | from apps.doc.exceptions import OCR1Exception, OCR2Exception, LTGTException |
22 | from apps.doc.ocr.wb import BSWorkbook | 22 | from apps.doc.ocr.wb import BSWorkbook |
23 | from apps.doc.models import OfflineReport | 23 | from apps.doc.models import OfflineReport, AFCOfflineReport |
24 | from apps.doc.named_enum import OfflineFailureReason | 24 | from apps.doc.named_enum import OfflineFailureReason |
25 | 25 | ||
26 | 26 | ||
... | @@ -447,7 +447,8 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -447,7 +447,8 @@ class Command(BaseCommand, LoggerMixin): |
447 | finally: | 447 | finally: |
448 | end_time = time.time() | 448 | end_time = time.time() |
449 | try: | 449 | try: |
450 | OfflineReport.objects.create( | 450 | report_table = OfflineReport if input_dir.find(consts.HIL_PREFIX) != -1 else AFCOfflineReport |
451 | report_table.objects.create( | ||
451 | input_folder=input_dir, | 452 | input_folder=input_dir, |
452 | doc_type=consts.DDA_CLASSIFY, | 453 | doc_type=consts.DDA_CLASSIFY, |
453 | file_name=name, | 454 | file_name=name, | ... | ... |
... | @@ -21,7 +21,7 @@ from common.electronic_afc_contract.afc_contract_ocr import predict as afc_predi | ... | @@ -21,7 +21,7 @@ from common.electronic_afc_contract.afc_contract_ocr import predict as afc_predi |
21 | from apps.doc import consts | 21 | from apps.doc import consts |
22 | from apps.doc.exceptions import OCR1Exception, OCR2Exception, LTGTException | 22 | from apps.doc.exceptions import OCR1Exception, OCR2Exception, LTGTException |
23 | from apps.doc.ocr.wb import BSWorkbook | 23 | from apps.doc.ocr.wb import BSWorkbook |
24 | from apps.doc.models import OfflineReport | 24 | from apps.doc.models import OfflineReport, AFCOfflineReport |
25 | from apps.doc.named_enum import OfflineFailureReason | 25 | from apps.doc.named_enum import OfflineFailureReason |
26 | 26 | ||
27 | 27 | ||
... | @@ -769,7 +769,8 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -769,7 +769,8 @@ class Command(BaseCommand, LoggerMixin): |
769 | finally: | 769 | finally: |
770 | end_time = time.time() | 770 | end_time = time.time() |
771 | try: | 771 | try: |
772 | OfflineReport.objects.create( | 772 | report_table = OfflineReport if input_dir.find(consts.HIL_PREFIX) != -1 else AFCOfflineReport |
773 | report_table.objects.create( | ||
773 | input_folder=input_dir, | 774 | input_folder=input_dir, |
774 | doc_type=classify, | 775 | doc_type=classify, |
775 | file_name=name, | 776 | file_name=name, | ... | ... |
... | @@ -18,7 +18,7 @@ from common.tools.pdf_to_img import PDFHandler | ... | @@ -18,7 +18,7 @@ from common.tools.pdf_to_img import PDFHandler |
18 | from apps.doc import consts | 18 | from apps.doc import consts |
19 | from apps.doc.exceptions import OCR1Exception, OCR4Exception | 19 | from apps.doc.exceptions import OCR1Exception, OCR4Exception |
20 | from apps.doc.ocr.wb import BSWorkbook | 20 | from apps.doc.ocr.wb import BSWorkbook |
21 | from apps.doc.models import OfflineReport | 21 | from apps.doc.models import OfflineReport, AFCOfflineReport |
22 | from apps.doc.named_enum import OfflineFailureReason | 22 | from apps.doc.named_enum import OfflineFailureReason |
23 | 23 | ||
24 | 24 | ||
... | @@ -385,7 +385,8 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -385,7 +385,8 @@ class Command(BaseCommand, LoggerMixin): |
385 | finally: | 385 | finally: |
386 | end_time = time.time() | 386 | end_time = time.time() |
387 | try: | 387 | try: |
388 | OfflineReport.objects.create( | 388 | report_table = OfflineReport if input_dir.find(consts.HIL_PREFIX) != -1 else AFCOfflineReport |
389 | report_table.objects.create( | ||
389 | input_folder=input_dir, | 390 | input_folder=input_dir, |
390 | doc_type=classify, | 391 | doc_type=classify, |
391 | file_name=name, | 392 | file_name=name, | ... | ... |
... | @@ -21,7 +21,7 @@ from common.tools.pdf_to_img import PDFHandler | ... | @@ -21,7 +21,7 @@ from common.tools.pdf_to_img import PDFHandler |
21 | from apps.doc import consts | 21 | from apps.doc import consts |
22 | from apps.doc.exceptions import OCR1Exception, OCR4Exception | 22 | from apps.doc.exceptions import OCR1Exception, OCR4Exception |
23 | from apps.doc.ocr.wb import BSWorkbook, PatternFill | 23 | from apps.doc.ocr.wb import BSWorkbook, PatternFill |
24 | from apps.doc.models import OfflineReport | 24 | from apps.doc.models import OfflineReport, AFCOfflineReport |
25 | from apps.doc.named_enum import OfflineFailureReason | 25 | from apps.doc.named_enum import OfflineFailureReason |
26 | 26 | ||
27 | 27 | ||
... | @@ -632,7 +632,8 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -632,7 +632,8 @@ class Command(BaseCommand, LoggerMixin): |
632 | finally: | 632 | finally: |
633 | end_time = time.time() | 633 | end_time = time.time() |
634 | try: | 634 | try: |
635 | OfflineReport.objects.create( | 635 | report_table = OfflineReport if input_dir.find(consts.HIL_PREFIX) != -1 else AFCOfflineReport |
636 | report_table.objects.create( | ||
636 | input_folder=input_dir, | 637 | input_folder=input_dir, |
637 | doc_type=consts.FOLDER_WSC_CLASSIFY, | 638 | doc_type=consts.FOLDER_WSC_CLASSIFY, |
638 | file_name=name, | 639 | file_name=name, | ... | ... |
... | @@ -923,6 +923,7 @@ class MposReport(models.Model): | ... | @@ -923,6 +923,7 @@ class MposReport(models.Model): |
923 | image_count = models.SmallIntegerField(default=0, verbose_name="图片数目") | 923 | image_count = models.SmallIntegerField(default=0, verbose_name="图片数目") |
924 | # status = models.SmallIntegerField(default=, verbose_name="请求状态") | 924 | # status = models.SmallIntegerField(default=, verbose_name="请求状态") |
925 | status = models.BooleanField(default=True, verbose_name="是否成功") | 925 | status = models.BooleanField(default=True, verbose_name="是否成功") |
926 | source = models.SmallIntegerField(default=0, verbose_name="来源") # 默认0,代表MPOS | ||
926 | 927 | ||
927 | duration = models.IntegerField(null=True, verbose_name='处理时长') | 928 | duration = models.IntegerField(null=True, verbose_name='处理时长') |
928 | 929 | ||
... | @@ -950,20 +951,30 @@ class OfflineReport(models.Model): | ... | @@ -950,20 +951,30 @@ class OfflineReport(models.Model): |
950 | db_table = 'offline_report' | 951 | db_table = 'offline_report' |
951 | 952 | ||
952 | 953 | ||
953 | # class AFCOfflineReport(models.Model): | 954 | class AFCOfflineReport(models.Model): |
954 | # id = models.AutoField(primary_key=True, verbose_name="id") # 主键 | 955 | id = models.AutoField(primary_key=True, verbose_name="id") # 主键 |
955 | # | 956 | |
956 | # input_folder = models.CharField(max_length=512, verbose_name="文件夹路径") | 957 | input_folder = models.CharField(max_length=512, verbose_name="文件夹路径") |
957 | # doc_type = models.SmallIntegerField(default=0, verbose_name="文件类型") | 958 | doc_type = models.SmallIntegerField(default=0, verbose_name="文件类型") |
958 | # file_name = models.CharField(max_length=1024, verbose_name="文件名") | 959 | file_name = models.CharField(max_length=1024, verbose_name="文件名") |
959 | # status = models.BooleanField(default=True, verbose_name="是否成功") | 960 | status = models.BooleanField(default=True, verbose_name="是否成功") |
960 | # failure_reason = models.SmallIntegerField(default=0, verbose_name="失败原因") | 961 | failure_reason = models.SmallIntegerField(default=0, verbose_name="失败原因") |
961 | # duration = models.IntegerField(verbose_name='处理时长') | 962 | duration = models.IntegerField(verbose_name='处理时长') |
962 | # | 963 | |
963 | # create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') | 964 | create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') |
964 | # | 965 | |
965 | # class Meta: | 966 | class Meta: |
966 | # managed = False | 967 | managed = False |
967 | # db_table = 'afc_offline_report' | 968 | db_table = 'afc_offline_report' |
968 | # situ_db_label = 'afc' | 969 | situ_db_label = 'afc' |
969 | 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, PreSEHandler | 52 | from .mixins import DocHandler, MPOSHandler, PreSEHandler |
... | @@ -1538,14 +1539,34 @@ class GoView(GenericView): | ... | @@ -1538,14 +1539,34 @@ class GoView(GenericView): |
1538 | 1539 | ||
1539 | @use_args(go_args, location='files') | 1540 | @use_args(go_args, location='files') |
1540 | def post(self, request, args): | 1541 | def post(self, request, args): |
1542 | result = None | ||
1543 | is_success = False | ||
1544 | start_time = time.time() | ||
1545 | try: | ||
1541 | files = [ | 1546 | files = [ |
1542 | ('img', ('file', args.get('image'), 'application/octet-stream')) | 1547 | ('img', ('file', args.get('image'), 'application/octet-stream')) |
1543 | ] | 1548 | ] |
1544 | 1549 | ||
1545 | go_result = requests.post(url=conf.GO_OCR_URL, files=files) | 1550 | go_result = requests.post(url=conf.GO_OCR_URL, files=files) |
1546 | 1551 | except Exception as e: | |
1552 | pass | ||
1553 | else: | ||
1547 | if go_result.status_code == 200: | 1554 | if go_result.status_code == 200: |
1555 | is_success = True | ||
1548 | result = go_result.json().get('data', '') | 1556 | result = go_result.json().get('data', '') |
1557 | finally: | ||
1558 | end_time = time.time() | ||
1559 | duration_second = int(end_time - start_time) | ||
1560 | |||
1561 | try: | ||
1562 | GenericOCRReport.objects.create( | ||
1563 | status=is_success, | ||
1564 | duration=duration_second, | ||
1565 | ) | ||
1566 | except Exception as e: | ||
1567 | self.exception_log.exception('[go view] [db save failed] [error={0}]'.format(traceback.format_exc())) | ||
1568 | |||
1569 | if is_success: | ||
1549 | return response.ok(data=result) | 1570 | return response.ok(data=result) |
1550 | else: | 1571 | else: |
1551 | return response.res_content(3, '识别错误', data=None) | 1572 | 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 | ... | ... |
src/common/tools/mssql_script20.py
0 → 100644
1 | import pyodbc | ||
2 | |||
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 | |||
12 | ALTER TABLE mpos_report ADD source tinyint default 0 not null; | ||
13 | """ | ||
14 | |||
15 | afc_sql = """ | ||
16 | create table afc_offline_report | ||
17 | ( | ||
18 | id bigint identity primary key, | ||
19 | input_folder nvarchar(512) not null, | ||
20 | doc_type tinyint default 0 not null, | ||
21 | file_name nvarchar(1024) not null, | ||
22 | status bit default 1 not null, | ||
23 | failure_reason tinyint default 0 not null, | ||
24 | duration smallint not null, | ||
25 | create_time datetime not null | ||
26 | ); | ||
27 | """ | ||
28 | |||
29 | hil_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | ||
30 | |||
31 | hil_cursor = hil_cnxn.cursor() | ||
32 | hil_cursor.execute(hil_sql) | ||
33 | |||
34 | hil_cursor.close() | ||
35 | hil_cnxn.close() | ||
36 | |||
37 | afc_cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};', autocommit=True) | ||
38 | |||
39 | afc_cursor = afc_cnxn.cursor() | ||
40 | afc_cursor.execute(afc_sql) | ||
41 | |||
42 | afc_cursor.close() | ||
43 | afc_cnxn.close() |
... | @@ -12,6 +12,6 @@ EDMS_DOWNLOAD_URL = http://sccn0637.bmwgroup.net/FH/FileHold/DocumentRepository/ | ... | @@ -12,6 +12,6 @@ EDMS_DOWNLOAD_URL = http://sccn0637.bmwgroup.net/FH/FileHold/DocumentRepository/ |
12 | EDMS_UPLOAD_URL = http://sccn0637.bmwgroup.net/FH/FileHold/DocumentRepository/UploadHandler.ashx | 12 | EDMS_UPLOAD_URL = http://sccn0637.bmwgroup.net/FH/FileHold/DocumentRepository/UploadHandler.ashx |
13 | DEALER_CODE = ocr_situ_group | 13 | DEALER_CODE = ocr_situ_group |
14 | 14 | ||
15 | BASE_URL = https://li19dkocruat01vm.bmwgroup.net | 15 | BASE_URL = https://sfocr-uat.bmwgroup.net |
16 | 16 | ||
17 | DELAY_SECONDS = 60 | 17 | DELAY_SECONDS = 60 |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment