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
9b2170ec
authored
2021-05-07 11:21:09 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
prune
1 parent
3ff06858
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
51 deletions
src/apps/doc/management/commands/ocr_process.py
src/apps/doc/ocr/wb.py
src/apps/doc/views.py
src/apps/doc/management/commands/ocr_process.py
View file @
9b2170e
...
...
@@ -837,7 +837,7 @@ class Command(BaseCommand, LoggerMixin):
# 重构Excel文件
# src_excel_path = os.path.join(doc_data_path, 'src.xlsx')
# wb.save(src_excel_path)
count_list
=
wb
.
rebuild
(
merged_bs_summary
,
license_summary
,
res_list
,
doc
.
document_scheme
)
wb
.
rebuild
(
merged_bs_summary
,
license_summary
,
res_list
,
doc
.
document_scheme
)
wb
.
save
(
excel_path
)
except
Exception
as
e
:
...
...
@@ -878,9 +878,9 @@ class Command(BaseCommand, LoggerMixin):
try
:
doc
.
end_time
=
timezone
.
now
()
doc
.
duration
=
min
((
doc
.
end_time
-
doc
.
start_time
)
.
seconds
,
32760
)
for
field
,
count
in
count_list
:
if
hasattr
(
doc
,
field
):
setattr
(
doc
,
field
,
count
)
#
for field, count in count_list:
#
if hasattr(doc, field):
#
setattr(doc, field, count)
doc
.
save
()
except
Exception
as
e
:
self
.
online_log
.
error
(
'{0} [process error (db save)] [task={1}] [error={2}]'
.
format
(
...
...
src/apps/doc/ocr/wb.py
View file @
9b2170e
...
...
@@ -633,12 +633,12 @@ class BSWorkbook(Workbook):
for
sheet
in
sheets_list
:
self
.
remove
(
self
.
get_sheet_by_name
(
sheet
))
def
license_rebuild
(
self
,
license_summary
,
document_scheme
,
count_list
):
for
classify
,
(
_
,
name
,
field_order
,
side_diff
,
scheme_diff
,
field_str
)
in
consts
.
LICENSE_ORDER
:
def
license_rebuild
(
self
,
license_summary
,
document_scheme
):
for
classify
,
(
_
,
name
,
field_order
,
side_diff
,
scheme_diff
,
_
)
in
consts
.
LICENSE_ORDER
:
license_list
=
license_summary
.
get
(
classify
)
if
not
license_list
:
continue
count
=
0
#
count = 0
ws
=
self
.
create_sheet
(
name
)
if
scheme_diff
and
document_scheme
==
consts
.
DOC_SCHEME_LIST
[
1
]:
classify
=
consts
.
MVC_CLASSIFY_SE
...
...
@@ -653,8 +653,8 @@ class BSWorkbook(Workbook):
else
:
ws
.
append
((
write_field
,
field_value
))
ws
.
append
((
None
,
))
count
+=
1
count_list
.
append
((
field_str
,
count
))
#
count += 1
#
count_list.append((field_str, count))
def
simple_license_rebuild
(
self
,
license_summary
,
document_scheme
):
# for ic_license_dict in license_summary.get(consts.IC_CLASSIFY, []):
...
...
@@ -708,13 +708,13 @@ class BSWorkbook(Workbook):
self
.
remove
(
self
.
get_sheet_by_name
(
'Sheet'
))
def
rebuild
(
self
,
bs_summary
,
license_summary
,
res_list
,
document_scheme
):
count_list
=
[(
consts
.
MODEL_FIELD_BS
,
len
(
self
.
sheetnames
)
-
1
)]
#
count_list = [(consts.MODEL_FIELD_BS, len(self.sheetnames) - 1)]
if
document_scheme
==
consts
.
DOC_SCHEME_LIST
[
1
]:
self
.
license_rebuild
(
license_summary
,
document_scheme
,
count_list
)
self
.
license_rebuild
(
license_summary
,
document_scheme
)
self
.
bs_rebuild
(
bs_summary
)
else
:
self
.
bs_rebuild
(
bs_summary
)
self
.
license_rebuild
(
license_summary
,
document_scheme
,
count_list
)
self
.
license_rebuild
(
license_summary
,
document_scheme
)
self
.
res_sheet
(
res_list
)
self
.
remove_base_sheet
()
return
count_list
#
return count_list
...
...
src/apps/doc/views.py
View file @
9b2170e
...
...
@@ -16,7 +16,7 @@ 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
UploadDocRecords
,
DocStatus
,
PriorityApplication
,
GCAPRecords
,
AFCComparisonInfo
,
HILComparisonInfo
from
.models
import
DocStatus
,
PriorityApplication
,
GCAPRecords
,
AFCComparisonInfo
,
HILComparisonInfo
from
.mixins
import
DocHandler
from
.
import
consts
from
apps.account.authentication
import
OAuth2AuthenticationWithUser
...
...
@@ -288,36 +288,36 @@ class UploadDocView(GenericView, DocHandler):
@use_args
(
doc_upload_args
,
location
=
'data'
)
def
post
(
self
,
request
,
args
):
application_data
=
args
.
get
(
'applicationData'
)
applicant_data
=
args
.
get
(
'applicantData'
)
#
applicant_data = args.get('applicantData')
document
=
args
.
get
(
'document'
)
business_type
=
document
.
get
(
'businessType'
)
application_id
=
application_data
.
get
(
'applicationId'
)
document_scheme
=
document
.
get
(
'documentScheme'
)
data_source
=
document
.
get
(
'dataSource'
)
document_name
=
document
.
get
(
'documentName'
)
main_name
=
self
.
get_name
(
applicant_data
,
'mainApplicantName'
,
16
)
co_name
=
self
.
get_name
(
applicant_data
,
'coApplicantName'
,
16
)
g1_name
=
self
.
get_name
(
applicant_data
,
'guarantor1Name'
,
16
)
g2_name
=
self
.
get_name
(
applicant_data
,
'guarantor2Name'
,
16
)
try
:
# 1. 上传信息记录
UploadDocRecords
.
objects
.
create
(
metadata_version_id
=
document
.
get
(
'metadataVersionId'
),
application_id
=
application_id
,
main_applicant
=
main_name
,
co_applicant
=
co_name
,
guarantor_1
=
g1_name
,
guarantor_2
=
g2_name
,
document_name
=
document_name
,
document_scheme
=
document_scheme
,
business_type
=
business_type
,
data_source
=
data_source
,
upload_finish_time
=
document
.
get
(
'uploadFinishTime'
),
)
except
IntegrityError
as
e
:
self
.
running_log
.
info
(
'[doc upload fail] [args={0}] [err={1}]'
.
format
(
args
,
e
))
self
.
invalid_params
(
msg
=
'metadataVersionId repeat'
)
else
:
#
main_name = self.get_name(applicant_data, 'mainApplicantName', 16)
#
co_name = self.get_name(applicant_data, 'coApplicantName', 16)
#
g1_name = self.get_name(applicant_data, 'guarantor1Name', 16)
#
g2_name = self.get_name(applicant_data, 'guarantor2Name', 16)
#
try:
#
# 1. 上传信息记录
#
UploadDocRecords.objects.create(
#
metadata_version_id=document.get('metadataVersionId'),
#
application_id=application_id,
#
main_applicant=main_name,
#
co_applicant=co_name,
#
guarantor_1=g1_name,
#
guarantor_2=g2_name,
#
document_name=document_name,
#
document_scheme=document_scheme,
#
business_type=business_type,
#
data_source=data_source,
#
upload_finish_time=document.get('uploadFinishTime'),
#
)
#
except IntegrityError as e:
#
self.running_log.info('[doc upload fail] [args={0}] [err={1}]'.format(args, e))
#
self.invalid_params(msg='metadataVersionId repeat')
#
else:
data_source
=
self
.
fix_data_source
(
data_source
)
if
data_source
==
consts
.
DATA_SOURCE_LIST
[
1
]:
if
isinstance
(
document_name
,
str
):
...
...
@@ -590,19 +590,19 @@ class DocView(GenericView, DocHandler):
upload_finish_time
=
timezone
.
now
()
document_scheme
=
random
.
choice
(
consts
.
DOC_SCHEME_LIST
)
data_source
=
random
.
choice
(
consts
.
DATA_SOURCE_LIST
)
UploadDocRecords
.
objects
.
create
(
metadata_version_id
=
metadata_version_id
,
application_id
=
application_id
,
main_applicant
=
''
,
co_applicant
=
''
,
guarantor_1
=
''
,
guarantor_2
=
''
,
document_name
=
application_id
,
document_scheme
=
document_scheme
,
business_type
=
business_type
,
data_source
=
data_source
,
upload_finish_time
=
upload_finish_time
,
)
#
UploadDocRecords.objects.create(
#
metadata_version_id=metadata_version_id,
#
application_id=application_id,
#
main_applicant='',
#
co_applicant='',
#
guarantor_1='',
#
guarantor_2='',
#
document_name=application_id,
#
document_scheme=document_scheme,
#
business_type=business_type,
#
data_source=data_source,
#
upload_finish_time=upload_finish_time,
#
)
# 2. 根据业务类型分库存储
doc_class
,
prefix
=
self
.
get_doc_class
(
business_type
)
...
...
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