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
9e45e68d
authored
2022-09-13 11:06:58 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add mpos report
1 parent
e1915d08
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
7 deletions
src/apps/doc/management/commands/ocr_process.py
src/apps/doc/models.py
src/apps/doc/views.py
src/common/tools/mssql_script19.py
src/apps/doc/management/commands/ocr_process.py
View file @
9e45e68
...
...
@@ -1902,8 +1902,6 @@ class Command(BaseCommand, LoggerMixin):
self
.
online_log
.
info
(
'{0} [process complete] [task={1}]'
.
format
(
self
.
log_base
,
task_str
))
os
.
remove
(
excel_path
)
finally
:
# TODO 识别结果存一张表,方便跑报表
self
.
rebuild_contract
(
license_summary
,
contract_result_compare
)
bs_rebuild
=
self
.
rebuild_bs
(
merged_bs_summary
)
...
...
src/apps/doc/models.py
View file @
9e45e68
from
django.db
import
models
from
.named_enum
import
DocStatus
,
KeywordsType
,
RequestTeam
,
RequestTrigger
,
FailureReason
,
ProcessName
,
WorkflowName
from
consts
import
IC_CLASSIFY
# Create your models here.
...
...
@@ -454,6 +455,13 @@ class HILOCRReport(models.Model):
workflow_name
=
models
.
SmallIntegerField
(
null
=
True
,
verbose_name
=
"工作流程"
)
notes
=
models
.
CharField
(
null
=
True
,
max_length
=
2048
,
verbose_name
=
"备注"
)
# 1. bank_name string eg. '农业银行-交易清单'
# 2. is_ebank boolean eg. 1
# 1. is_bs_check boolean eg. 1
# 2. bs_check_result int eg. 2(电子-author)
#
class
Meta
:
managed
=
False
db_table
=
'hil_ocr_report'
...
...
@@ -905,3 +913,42 @@ class AFCbankVerification(models.Model):
managed
=
False
db_table
=
'afc_bank_verification'
situ_db_label
=
'afc'
class
MposReport
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
doc_type
=
models
.
SmallIntegerField
(
default
=
IC_CLASSIFY
,
verbose_name
=
"文件类型"
)
image_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"图片数目"
)
# status = models.SmallIntegerField(default=, verbose_name="请求状态")
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
=
'mpos_report'
# class HILOfflineReport(models.Model):
# id = models.AutoField(primary_key=True, verbose_name="id") # 主键
#
# update_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
# create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
#
# class Meta:
# managed = False
# db_table = 'hil_offline_report'
# new teble: hil/afc_offline_ocr_report
# 1. file_name string eg. 'CH-B2432.pdf'
# 2. doc_type int eg. 2(VAT Invoice)
# 3. successful_at_this_level boolean eg. 0
# 4. failure_reason int eg. 2(PDF)
# 5. duration int eg. 100
#
# id/input_folder/start_time/end_time/create_time
...
...
src/apps/doc/views.py
View file @
9e45e68
...
...
@@ -4,6 +4,7 @@ import time
import
json
import
random
import
datetime
import
traceback
import
fitz
import
shutil
import
requests
...
...
@@ -44,6 +45,7 @@ from .models import (
AFCAutoSettlement
,
HILbankVerification
,
AFCbankVerification
,
MposReport
,
)
from
.named_enum
import
ErrorType
,
AutoResult
,
WholeResult
,
RPAResult
from
.mixins
import
DocHandler
,
MPOSHandler
...
...
@@ -1467,15 +1469,37 @@ class MPOSView(GenericView, MPOSHandler):
# MPOS
@use_args
(
mpos_args
,
location
=
'data'
)
def
post
(
self
,
request
,
args
):
start_time
=
time
.
time
()
classify
=
args
.
get
(
'type'
)
result_list
=
[]
image_count
=
0
all_success
=
True
for
img_base64
in
args
.
get
(
'file_base64_content'
,
[]):
if
classify
in
consts
.
LICENSE_CLASSIFY_SET_1
:
result
=
self
.
ocr1_process
(
conf
.
MPOS_URL1
,
img_base64
)
else
:
result
=
self
.
ocr2_process
(
conf
.
MPOS_URL2
,
classify
,
img_base64
)
image_count
+=
1
try
:
if
classify
in
consts
.
LICENSE_CLASSIFY_SET_1
:
result
=
self
.
ocr1_process
(
conf
.
MPOS_URL1
,
img_base64
)
else
:
result
=
self
.
ocr2_process
(
conf
.
MPOS_URL2
,
classify
,
img_base64
)
result_list
.
extend
(
result
)
except
Exception
as
e
:
all_success
=
False
continue
result_list
.
extend
(
result
)
end_time
=
time
.
time
()
duration_second
=
int
(
end_time
-
start_time
)
try
:
MposReport
.
objects
.
create
(
doc_type
=
classify
,
image_count
=
image_count
,
status
=
all_success
,
duration
=
duration_second
,
)
except
Exception
as
e
:
self
.
exception_log
.
exception
(
'[mpos view] [db save failed] [error={0}]'
.
format
(
traceback
.
format_exc
()))
return
response
.
ok
(
data
=
result_list
)
...
...
src/common/tools/mssql_script19.py
0 → 100644
View file @
9e45e68
import
pyodbc
hil_sql
=
"""
create table mpos_report
(
id bigint identity primary key,
doc_type tinyint default 0 not null,
image_count tinyint default 0 not null,
status bit default 1 not null,
duration smallint,
create_time datetime not null
);
"""
# afc_sql = """
#
# """
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()
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