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
4fb6a0f2
authored
2024-05-21 11:22:56 +0800
by
冯轩
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
MOD:发票excel下载 java转python
1 parent
0b7fde9b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
4 deletions
src-20240521-5.zip
src/apps/doc/views.py
src-20240521-5.zip
0 → 100644
View file @
4fb6a0f
No preview for this file type
src/apps/doc/views.py
View file @
4fb6a0f
...
...
@@ -63,6 +63,8 @@ from celery_compare.tasks import compare, fsm_compare
from
prese.compare
import
get_empty_result
import
time
from
django.http
import
HttpResponse
from
django.utils.encoding
import
escape_uri_path
class
CustomDate
(
fields
.
Date
):
...
...
@@ -561,6 +563,10 @@ mpos_args = {
'file_base64_content'
:
fields
.
List
(
fields
.
Str
(),
required
=
True
,
validate
=
validate
.
Length
(
min
=
1
)),
}
invoice_download_args
=
{
'application_entity'
:
fields
.
Int
(
required
=
True
),
'application_ids'
:
fields
.
Str
(
required
=
True
),
}
class
UploadDocView
(
GenericView
,
DocHandler
):
# permission_classes = []
...
...
@@ -1851,8 +1857,8 @@ class InvoiceExcelView(GenericView):
authentication_classes
=
[
OAuth2AuthenticationWithUser
]
# 下载发票excel
# @use_args(doc_list
_args, location='data')
def
ge
t
(
self
,
request
,
args
):
@use_args
(
invoice_download
_args
,
location
=
'data'
)
def
pos
t
(
self
,
request
,
args
):
application_ids
=
args
.
get
(
'application_ids'
)
application_entity
=
args
.
get
(
'application_entity'
)
...
...
@@ -1866,8 +1872,20 @@ class InvoiceExcelView(GenericView):
headers
=
{
'Content-Type'
:
'application/json'
}
requests
.
post
(
url
,
headers
=
headers
,
json
=
body
)
self
.
running_log
.
info
(
"java invoice excel api finish, void"
)
resp
=
requests
.
post
(
url
,
headers
=
headers
,
json
=
body
)
self
.
running_log
.
info
(
"java invoice excel api finish, applicationIds:{0},{1}"
.
format
(
application_ids
,
resp
.
text
))
res_json
=
json
.
loads
(
resp
.
text
)
file_path
=
res_json
.
get
(
'result'
)
self
.
running_log
.
info
(
"java invoice excel after process, filePath:{0}"
.
format
(
file_path
))
current_time
=
time
.
strftime
(
'
%
Y-
%
m-
%
d_
%
H_
%
M_
%
S'
,
time
.
localtime
())
download_file_name
=
"发票信息提取-"
+
current_time
+
".xlsx"
f
=
open
(
file_path
,
"rb"
)
response
=
HttpResponse
(
content_type
=
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
response
[
'Content-Disposition'
]
=
'attachment; filename="{0}"'
.
format
(
escape_uri_path
(
download_file_name
))
response
[
'Access-Control-Expose-Headers'
]
=
'content-disposition'
response
.
write
(
f
.
read
())
f
.
close
()
return
response
except
Exception
as
e
:
self
.
running_log
.
error
(
"invoice excel request to java error, url:{0}, param:{1}, errorMsg:{2}"
.
format
(
url
,
json
.
dumps
(
body
),
traceback
.
format_exc
()))
...
...
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