MOD:发票excel下载 java转python
Showing
2 changed files
with
22 additions
and
4 deletions
src-20240521-5.zip
0 → 100644
No preview for this file type
... | @@ -63,6 +63,8 @@ from celery_compare.tasks import compare, fsm_compare | ... | @@ -63,6 +63,8 @@ from celery_compare.tasks import compare, fsm_compare |
63 | from prese.compare import get_empty_result | 63 | from prese.compare import get_empty_result |
64 | 64 | ||
65 | import time | 65 | import time |
66 | from django.http import HttpResponse | ||
67 | from django.utils.encoding import escape_uri_path | ||
66 | 68 | ||
67 | 69 | ||
68 | class CustomDate(fields.Date): | 70 | class CustomDate(fields.Date): |
... | @@ -561,6 +563,10 @@ mpos_args = { | ... | @@ -561,6 +563,10 @@ mpos_args = { |
561 | 'file_base64_content': fields.List(fields.Str(), required=True, validate=validate.Length(min=1)), | 563 | 'file_base64_content': fields.List(fields.Str(), required=True, validate=validate.Length(min=1)), |
562 | } | 564 | } |
563 | 565 | ||
566 | invoice_download_args = { | ||
567 | 'application_entity': fields.Int(required=True), | ||
568 | 'application_ids': fields.Str(required=True), | ||
569 | } | ||
564 | 570 | ||
565 | class UploadDocView(GenericView, DocHandler): | 571 | class UploadDocView(GenericView, DocHandler): |
566 | # permission_classes = [] | 572 | # permission_classes = [] |
... | @@ -1851,8 +1857,8 @@ class InvoiceExcelView(GenericView): | ... | @@ -1851,8 +1857,8 @@ class InvoiceExcelView(GenericView): |
1851 | authentication_classes = [OAuth2AuthenticationWithUser] | 1857 | authentication_classes = [OAuth2AuthenticationWithUser] |
1852 | 1858 | ||
1853 | # 下载发票excel | 1859 | # 下载发票excel |
1854 | # @use_args(doc_list_args, location='data') | 1860 | @use_args(invoice_download_args, location='data') |
1855 | def get(self, request, args): | 1861 | def post(self, request, args): |
1856 | application_ids = args.get('application_ids') | 1862 | application_ids = args.get('application_ids') |
1857 | application_entity = args.get('application_entity') | 1863 | application_entity = args.get('application_entity') |
1858 | 1864 | ||
... | @@ -1866,8 +1872,20 @@ class InvoiceExcelView(GenericView): | ... | @@ -1866,8 +1872,20 @@ class InvoiceExcelView(GenericView): |
1866 | headers = { | 1872 | headers = { |
1867 | 'Content-Type': 'application/json' | 1873 | 'Content-Type': 'application/json' |
1868 | } | 1874 | } |
1869 | requests.post(url, headers=headers, json=body) | 1875 | resp = requests.post(url, headers=headers, json=body) |
1870 | self.running_log.info("java invoice excel api finish, void") | 1876 | self.running_log.info("java invoice excel api finish, applicationIds:{0},{1}".format(application_ids, resp.text)) |
1877 | res_json = json.loads(resp.text) | ||
1878 | file_path = res_json.get('result') | ||
1879 | self.running_log.info("java invoice excel after process, filePath:{0}".format(file_path)) | ||
1880 | current_time = time.strftime('%Y-%m-%d_%H_%M_%S', time.localtime()) | ||
1881 | download_file_name = "发票信息提取-" + current_time + ".xlsx" | ||
1882 | f = open(file_path,"rb") | ||
1883 | response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') | ||
1884 | response['Content-Disposition'] = 'attachment; filename="{0}"'.format(escape_uri_path(download_file_name)) | ||
1885 | response['Access-Control-Expose-Headers'] = 'content-disposition' | ||
1886 | response.write(f.read()) | ||
1887 | f.close() | ||
1888 | return response | ||
1871 | except Exception as e: | 1889 | except Exception as e: |
1872 | self.running_log.error("invoice excel request to java error, url:{0}, param:{1}, errorMsg:{2}".format( | 1890 | self.running_log.error("invoice excel request to java error, url:{0}, param:{1}, errorMsg:{2}".format( |
1873 | url, json.dumps(body), traceback.format_exc())) | 1891 | url, json.dumps(body), traceback.format_exc())) | ... | ... |
-
Please register or sign in to post a comment