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
0c7454b6
authored
2021-07-08 20:00:58 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
se compare part 3
1 parent
14adf361
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
297 additions
and
6 deletions
src/apps/doc/compare_urls.py
src/apps/doc/consts.py
src/apps/doc/models.py
src/apps/doc/views.py
src/celery_compare/tasks.py
src/common/tools/mssql_script6.py
src/apps/doc/compare_urls.py
View file @
0c7454b
...
...
@@ -6,4 +6,5 @@ urlpatterns = [
path
(
r'v1'
,
views
.
CompareView
.
as_view
()),
path
(
r'settlement/v1'
,
views
.
SECompareView
.
as_view
()),
path
(
r'offline/v1'
,
views
.
CompareOfflineView
.
as_view
()),
path
(
r'result'
,
views
.
CompareResultView
.
as_view
()),
]
...
...
src/apps/doc/consts.py
View file @
0c7454b
...
...
@@ -12,6 +12,7 @@ FIXED_APPLICATION_ID_PREFIX = 'CH-S'
DOC_SCHEME_LIST
=
[
'ACCEPTANCE'
,
'SETTLEMENT'
,
'CONTRACTMANAGEMENT'
]
DATA_SOURCE_LIST
=
[
'POS'
,
'EAPP'
,
'ECONTRACT'
]
COMPARE_DOC_SCHEME_LIST
=
[
'CA'
,
'SE'
]
HIL_PREFIX
=
'HIL'
AFC_PREFIX
=
'AFC'
...
...
src/apps/doc/models.py
View file @
0c7454b
...
...
@@ -490,9 +490,22 @@ class IDBCRecords(models.Model):
class
AFCSECompareResult
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
# 索引
update_time
=
models
.
DateTimeField
(
auto_now
=
True
,
verbose_name
=
'修改时间'
)
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
# 索引
is_finish
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
"是否完成"
)
compare_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"比对字段总数"
)
failed_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"比对失败数目"
)
reason1_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因1数目"
)
reason2_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因2数目"
)
reason3_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因3数目"
)
reason4_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因4数目"
)
reason5_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因5数目"
)
reason6_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因6数目"
)
reason7_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因7数目"
)
reason8_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因8数目"
)
reason9_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因9数目"
)
reason10_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因10数目"
)
result
=
models
.
TextField
(
null
=
True
,
verbose_name
=
"比对结果"
)
update_time
=
models
.
DateTimeField
(
auto_now
=
True
,
verbose_name
=
'修改时间'
)
# 索引
create_time
=
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
'创建时间'
)
class
Meta
:
...
...
@@ -501,3 +514,79 @@ class AFCSECompareResult(models.Model):
situ_db_label
=
'afc'
class
AFCCACompareResult
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
# 索引
is_finish
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
"是否完成"
)
compare_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"比对字段总数"
)
failed_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"比对失败数目"
)
reason1_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因1数目"
)
reason2_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因2数目"
)
reason3_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因3数目"
)
reason4_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因4数目"
)
reason5_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因5数目"
)
reason6_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因6数目"
)
reason7_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因7数目"
)
reason8_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因8数目"
)
reason9_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因9数目"
)
reason10_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因10数目"
)
result
=
models
.
TextField
(
null
=
True
,
verbose_name
=
"比对结果"
)
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
=
'afc_ca_compare_result'
situ_db_label
=
'afc'
class
HILSECompareResult
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
# 索引
is_finish
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
"是否完成"
)
compare_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"比对字段总数"
)
failed_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"比对失败数目"
)
reason1_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因1数目"
)
reason2_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因2数目"
)
reason3_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因3数目"
)
reason4_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因4数目"
)
reason5_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因5数目"
)
reason6_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因6数目"
)
reason7_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因7数目"
)
reason8_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因8数目"
)
reason9_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因9数目"
)
reason10_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因10数目"
)
result
=
models
.
TextField
(
null
=
True
,
verbose_name
=
"比对结果"
)
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_se_compare_result'
class
HILCACompareResult
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
application_id
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
# 索引
is_finish
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
"是否完成"
)
compare_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"比对字段总数"
)
failed_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"比对失败数目"
)
reason1_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因1数目"
)
reason2_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因2数目"
)
reason3_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因3数目"
)
reason4_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因4数目"
)
reason5_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因5数目"
)
reason6_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因6数目"
)
reason7_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因7数目"
)
reason8_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因8数目"
)
reason9_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因9数目"
)
reason10_count
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"原因10数目"
)
result
=
models
.
TextField
(
null
=
True
,
verbose_name
=
"比对结果"
)
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_ca_compare_result'
...
...
src/apps/doc/views.py
View file @
0c7454b
...
...
@@ -6,7 +6,7 @@ import datetime
import
fitz
import
shutil
from
django.utils
import
timezone
from
django.
db.utils
import
IntegrityError
from
django.
http
import
HttpResponse
from
django.db.models
import
Q
from
rest_framework.permissions
import
IsAuthenticated
from
webargs
import
fields
,
validate
...
...
@@ -16,7 +16,19 @@ from common import response
from
common.mixins
import
GenericView
from
common.tools.file_tools
import
file_write
from
common.redis_cache
import
redis_handler
as
rh
from
.models
import
DocStatus
,
PriorityApplication
,
GCAPRecords
,
AFCComparisonInfo
,
HILComparisonInfo
,
AFCCompareOfflineReport
,
HILCompareOfflineReport
from
.models
import
(
DocStatus
,
PriorityApplication
,
GCAPRecords
,
AFCComparisonInfo
,
HILComparisonInfo
,
AFCCompareOfflineReport
,
HILCompareOfflineReport
,
AFCCACompareResult
,
AFCSECompareResult
,
HILCACompareResult
,
HILSECompareResult
,
)
from
.mixins
import
DocHandler
from
.
import
consts
from
apps.account.authentication
import
OAuth2AuthenticationWithUser
...
...
@@ -257,6 +269,13 @@ doc_list_args = {
'create_time_end'
:
fields
.
Date
(
required
=
False
),
}
compare_result_args
=
{
'entity'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
OneOf
(
consts
.
BUSINESS_TYPE_LIST
)),
'scheme'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
OneOf
(
consts
.
COMPARE_DOC_SCHEME_LIST
)),
'id'
:
fields
.
Int
(
required
=
False
,
validate
=
lambda
val
:
val
>=
1
),
'case_id'
:
fields
.
Str
(
required
=
True
,
validate
=
validate
.
Length
(
max
=
64
)),
}
upload_pdf_args
=
{
'pdf_file'
:
fields
.
Raw
(
required
=
True
),
}
...
...
@@ -696,3 +715,60 @@ class DocView(GenericView, DocHandler):
is_priority
,
enqueue_res
))
data
=
{
'excel_path'
:
os
.
path
.
join
(
save_dir_path
,
'{0}.xlsx'
.
format
(
doc
.
id
))}
return
response
.
ok
(
data
=
data
)
class
CompareResultView
(
GenericView
):
# 获取比对结果
@use_args
(
compare_result_args
,
location
=
'querystring'
)
def
get
(
self
,
request
,
args
):
result_id
=
args
.
get
(
'id'
,
None
)
entity
=
args
.
get
(
'entity'
)
scheme
=
args
.
get
(
'scheme'
)
case_id
=
args
.
get
(
'case_id'
)
if
entity
==
consts
.
HIL_PREFIX
:
result_table
=
HILCACompareResult
if
scheme
==
consts
.
COMPARE_DOC_SCHEME_LIST
[
0
]
else
HILSECompareResult
else
:
result_table
=
AFCCACompareResult
if
scheme
==
consts
.
COMPARE_DOC_SCHEME_LIST
[
0
]
else
AFCSECompareResult
if
result_id
is
None
:
result_str_list
=
result_table
.
objects
.
filter
(
id
=
result_id
)
.
values_list
(
'result'
,
flat
=
True
)
else
:
result_str_list
=
result_table
.
objects
.
filter
(
application_id
=
case_id
)
.
values_list
(
'result'
,
flat
=
True
)
if
len
(
result_str_list
)
==
0
:
compare_result_list
=
[]
else
:
compare_result_list
=
json
.
loads
(
result_str_list
[
0
])
if
len
(
compare_result_list
)
==
0
:
body_html
=
"<h1>没有比对结果</h1>"
else
:
head_list
=
[
'Info'
,
'Index'
,
'License'
,
'Field'
,
'Result'
,
'Input'
,
'OCR'
,
'Position'
,
'Image'
,
'errorType'
]
head_content
=
''
.
join
([
'<th>{0}</th>'
.
format
(
head_name
)
for
head_name
in
head_list
])
head_html
=
'<tr>{0}</tr>'
.
format
(
head_content
)
row_html_list
=
[]
for
row_dict
in
compare_result_list
:
row_list
=
[
row_dict
.
get
(
head
,
''
)
for
head
in
head_list
]
row_content
=
''
.
join
([
'<td>{0}</td>'
.
format
(
row_str
)
for
row_str
in
row_list
])
row_html
=
'<tr>{0}</tr>'
.
format
(
row_content
)
row_html_list
.
append
(
row_html
)
content_html
=
''
.
join
(
row_html_list
)
body_html
=
'<table border="1">{0}{1}</table>'
.
format
(
head_html
,
content_html
)
html
=
"""
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>比对结果</title>
</head>
<body>
{0}
</body>
</html>
"""
.
format
(
body_html
)
return
HttpResponse
(
html
)
# return response.ok(data=compare_result)
...
...
src/celery_compare/tasks.py
View file @
0c7454b
...
...
@@ -5,7 +5,17 @@ import traceback
from
datetime
import
datetime
,
timedelta
from
collections
import
OrderedDict
from
.
import
app
from
apps.doc.models
import
AFCOCRResult
,
HILOCRResult
,
AFCComparisonInfo
,
HILComparisonInfo
,
Configs
,
HILCompareReport
,
AFCCompareReport
from
apps.doc.models
import
(
AFCOCRResult
,
HILOCRResult
,
AFCComparisonInfo
,
HILComparisonInfo
,
Configs
,
HILCompareReport
,
AFCCompareReport
,
AFCSECompareResult
,
HILSECompareResult
,
)
from
apps.doc
import
consts
from
apps.doc.ocr.gcap
import
gcap
from
apps.doc.exceptions
import
GCAPException
...
...
src/common/tools/mssql_script6.py
View file @
0c7454b
...
...
@@ -21,8 +21,65 @@ hil_sql = """
update_time datetime not null,
create_time datetime not null
);
create unique index hil_se_ocr_result_application_id_uindex
on hil_se_ocr_result (application_id);
create table hil_ca_compare_result
(
id int identity primary key,
application_id nvarchar(64) not null,
is_finish bit default 0 not null,
compare_count smallint default 0 not null,
failed_count smallint default 0 not null,
reason1_count smallint default 0 not null,
reason2_count smallint default 0 not null,
reason3_count smallint default 0 not null,
reason4_count smallint default 0 not null,
reason5_count smallint default 0 not null,
reason6_count smallint default 0 not null,
reason7_count smallint default 0 not null,
reason8_count smallint default 0 not null,
reason9_count smallint default 0 not null,
reason10_count smallint default 0 not null,
result nvarchar(max),
update_time datetime not null,
create_time datetime not null
);
create unique index hil_ca_compare_result_application_id_uindex
on hil_ca_compare_result (application_id);
create index hil_ca_compare_result_update_time_index
on hil_ca_compare_result (update_time);
create table hil_se_compare_result
(
id int identity primary key,
application_id nvarchar(64) not null,
is_finish bit default 0 not null,
compare_count smallint default 0 not null,
failed_count smallint default 0 not null,
reason1_count smallint default 0 not null,
reason2_count smallint default 0 not null,
reason3_count smallint default 0 not null,
reason4_count smallint default 0 not null,
reason5_count smallint default 0 not null,
reason6_count smallint default 0 not null,
reason7_count smallint default 0 not null,
reason8_count smallint default 0 not null,
reason9_count smallint default 0 not null,
reason10_count smallint default 0 not null,
result nvarchar(max),
update_time datetime not null,
create_time datetime not null
);
create unique index hil_se_compare_result_application_id_uindex
on hil_se_compare_result (application_id);
create index hil_se_compare_result_update_time_index
on hil_se_compare_result (update_time);
"""
afc_sql
=
"""
...
...
@@ -45,8 +102,65 @@ afc_sql = """
update_time datetime not null,
create_time datetime not null
);
create unique index afc_se_ocr_result_application_id_uindex
on afc_se_ocr_result (application_id);
create table afc_ca_compare_result
(
id int identity primary key,
application_id nvarchar(64) not null,
is_finish bit default 0 not null,
compare_count smallint default 0 not null,
failed_count smallint default 0 not null,
reason1_count smallint default 0 not null,
reason2_count smallint default 0 not null,
reason3_count smallint default 0 not null,
reason4_count smallint default 0 not null,
reason5_count smallint default 0 not null,
reason6_count smallint default 0 not null,
reason7_count smallint default 0 not null,
reason8_count smallint default 0 not null,
reason9_count smallint default 0 not null,
reason10_count smallint default 0 not null,
result nvarchar(max),
update_time datetime not null,
create_time datetime not null
);
create unique index afc_ca_compare_result_application_id_uindex
on afc_ca_compare_result (application_id);
create index afc_ca_compare_result_update_time_index
on afc_ca_compare_result (update_time);
create table afc_se_compare_result
(
id int identity primary key,
application_id nvarchar(64) not null,
is_finish bit default 0 not null,
compare_count smallint default 0 not null,
failed_count smallint default 0 not null,
reason1_count smallint default 0 not null,
reason2_count smallint default 0 not null,
reason3_count smallint default 0 not null,
reason4_count smallint default 0 not null,
reason5_count smallint default 0 not null,
reason6_count smallint default 0 not null,
reason7_count smallint default 0 not null,
reason8_count smallint default 0 not null,
reason9_count smallint default 0 not null,
reason10_count smallint default 0 not null,
result nvarchar(max),
update_time datetime not null,
create_time datetime not null
);
create unique index afc_se_compare_result_application_id_uindex
on afc_se_compare_result (application_id);
create index afc_se_compare_result_update_time_index
on afc_se_compare_result (update_time);
"""
hil_cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};'
,
autocommit
=
True
)
...
...
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