Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
78f0a596
authored
2022-10-18 16:24:44 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'master' into feature/pres
2 parents
520cb3bb
530a9a8c
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
117 additions
and
34 deletions
src/apps/doc/management/commands/folder_dda_process.py
src/apps/doc/management/commands/folder_ltgt_process.py
src/apps/doc/management/commands/folder_ocr_process.py
src/apps/doc/management/commands/folder_wsc_process.py
src/apps/doc/models.py
src/apps/doc/views.py
src/common/response.py
src/common/tools/mssql_script20.py
src/settings/conf/uat.ini
src/apps/doc/management/commands/folder_dda_process.py
View file @
78f0a59
...
...
@@ -20,7 +20,7 @@ from common.tools.pdf_to_img import PDFHandler
from
apps.doc
import
consts
from
apps.doc.exceptions
import
OCR1Exception
,
OCR2Exception
,
LTGTException
from
apps.doc.ocr.wb
import
BSWorkbook
from
apps.doc.models
import
OfflineReport
from
apps.doc.models
import
OfflineReport
,
AFCOfflineReport
from
apps.doc.named_enum
import
OfflineFailureReason
...
...
@@ -447,7 +447,8 @@ class Command(BaseCommand, LoggerMixin):
finally
:
end_time
=
time
.
time
()
try
:
OfflineReport
.
objects
.
create
(
report_table
=
OfflineReport
if
input_dir
.
find
(
consts
.
HIL_PREFIX
)
!=
-
1
else
AFCOfflineReport
report_table
.
objects
.
create
(
input_folder
=
input_dir
,
doc_type
=
consts
.
DDA_CLASSIFY
,
file_name
=
name
,
...
...
src/apps/doc/management/commands/folder_ltgt_process.py
View file @
78f0a59
...
...
@@ -21,7 +21,7 @@ from common.electronic_afc_contract.afc_contract_ocr import predict as afc_predi
from
apps.doc
import
consts
from
apps.doc.exceptions
import
OCR1Exception
,
OCR2Exception
,
LTGTException
from
apps.doc.ocr.wb
import
BSWorkbook
from
apps.doc.models
import
OfflineReport
from
apps.doc.models
import
OfflineReport
,
AFCOfflineReport
from
apps.doc.named_enum
import
OfflineFailureReason
...
...
@@ -769,7 +769,8 @@ class Command(BaseCommand, LoggerMixin):
finally
:
end_time
=
time
.
time
()
try
:
OfflineReport
.
objects
.
create
(
report_table
=
OfflineReport
if
input_dir
.
find
(
consts
.
HIL_PREFIX
)
!=
-
1
else
AFCOfflineReport
report_table
.
objects
.
create
(
input_folder
=
input_dir
,
doc_type
=
classify
,
file_name
=
name
,
...
...
src/apps/doc/management/commands/folder_ocr_process.py
View file @
78f0a59
...
...
@@ -18,7 +18,7 @@ from common.tools.pdf_to_img import PDFHandler
from
apps.doc
import
consts
from
apps.doc.exceptions
import
OCR1Exception
,
OCR4Exception
from
apps.doc.ocr.wb
import
BSWorkbook
from
apps.doc.models
import
OfflineReport
from
apps.doc.models
import
OfflineReport
,
AFCOfflineReport
from
apps.doc.named_enum
import
OfflineFailureReason
...
...
@@ -385,7 +385,8 @@ class Command(BaseCommand, LoggerMixin):
finally
:
end_time
=
time
.
time
()
try
:
OfflineReport
.
objects
.
create
(
report_table
=
OfflineReport
if
input_dir
.
find
(
consts
.
HIL_PREFIX
)
!=
-
1
else
AFCOfflineReport
report_table
.
objects
.
create
(
input_folder
=
input_dir
,
doc_type
=
classify
,
file_name
=
name
,
...
...
src/apps/doc/management/commands/folder_wsc_process.py
View file @
78f0a59
...
...
@@ -21,7 +21,7 @@ from common.tools.pdf_to_img import PDFHandler
from
apps.doc
import
consts
from
apps.doc.exceptions
import
OCR1Exception
,
OCR4Exception
from
apps.doc.ocr.wb
import
BSWorkbook
,
PatternFill
from
apps.doc.models
import
OfflineReport
from
apps.doc.models
import
OfflineReport
,
AFCOfflineReport
from
apps.doc.named_enum
import
OfflineFailureReason
...
...
@@ -632,7 +632,8 @@ class Command(BaseCommand, LoggerMixin):
finally
:
end_time
=
time
.
time
()
try
:
OfflineReport
.
objects
.
create
(
report_table
=
OfflineReport
if
input_dir
.
find
(
consts
.
HIL_PREFIX
)
!=
-
1
else
AFCOfflineReport
report_table
.
objects
.
create
(
input_folder
=
input_dir
,
doc_type
=
consts
.
FOLDER_WSC_CLASSIFY
,
file_name
=
name
,
...
...
src/apps/doc/models.py
View file @
78f0a59
...
...
@@ -923,6 +923,7 @@ class MposReport(models.Model):
image_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"图片数目"
)
# status = models.SmallIntegerField(default=, verbose_name="请求状态")
status
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
"是否成功"
)
source
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"来源"
)
# 默认0,代表MPOS
duration
=
models
.
IntegerField
(
null
=
True
,
verbose_name
=
'处理时长'
)
...
...
@@ -950,20 +951,30 @@ class OfflineReport(models.Model):
db_table
=
'offline_report'
#
class AFCOfflineReport(models.Model):
#
id = models.AutoField(primary_key=True, verbose_name="id") # 主键
#
#
input_folder = models.CharField(max_length=512, verbose_name="文件夹路径")
#
doc_type = models.SmallIntegerField(default=0, verbose_name="文件类型")
#
file_name = models.CharField(max_length=1024, verbose_name="文件名")
#
status = models.BooleanField(default=True, verbose_name="是否成功")
#
failure_reason = 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 = 'afc_offline_report'
#
situ_db_label = 'afc'
class
AFCOfflineReport
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
input_folder
=
models
.
CharField
(
max_length
=
512
,
verbose_name
=
"文件夹路径"
)
doc_type
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"文件类型"
)
file_name
=
models
.
CharField
(
max_length
=
1024
,
verbose_name
=
"文件名"
)
status
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
"是否成功"
)
failure_reason
=
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
=
'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'
...
...
src/apps/doc/views.py
View file @
78f0a59
...
...
@@ -46,6 +46,7 @@ from .models import (
HILbankVerification
,
AFCbankVerification
,
MposReport
,
GenericOCRReport
,
)
from
.named_enum
import
ErrorType
,
AutoResult
,
WholeResult
,
RPAResult
from
.mixins
import
DocHandler
,
MPOSHandler
,
PreSEHandler
...
...
@@ -1538,14 +1539,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
=
'识别错误'
)
...
...
src/common/response.py
View file @
78f0a59
...
...
@@ -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
)
...
...
src/common/tools/mssql_script20.py
0 → 100644
View file @
78f0a59
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;
"""
afc_sql
=
"""
create table afc_offline_report
(
id bigint identity primary key,
input_folder nvarchar(512) not null,
doc_type tinyint default 0 not null,
file_name nvarchar(1024) not null,
status bit default 1 not null,
failure_reason tinyint default 0 not null,
duration smallint not null,
create_time datetime not null
);
"""
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
()
src/settings/conf/uat.ini
View file @
78f0a59
...
...
@@ -12,6 +12,6 @@ EDMS_DOWNLOAD_URL = http://sccn0637.bmwgroup.net/FH/FileHold/DocumentRepository/
EDMS_UPLOAD_URL
=
http://sccn0637.bmwgroup.net/FH/FileHold/DocumentRepository/UploadHandler.ashx
DEALER_CODE
=
ocr_situ_group
BASE_URL
=
https://
li19dkocruat01vm
.bmwgroup.net
BASE_URL
=
https://
sfocr-uat
.bmwgroup.net
DELAY_SECONDS
=
60
\ No newline at end of file
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment