4fb6a0f2 by 冯轩

MOD:发票excel下载 java转python

1 parent 0b7fde9b
No preview for this file type
......@@ -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 get(self, request, args):
@use_args(invoice_download_args, location='data')
def post(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()))
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!