MOD:invoice-api
Showing
2 changed files
with
56 additions
and
5 deletions
... | @@ -17,6 +17,7 @@ from webargs import fields, validate | ... | @@ -17,6 +17,7 @@ from webargs import fields, validate |
17 | from webargs.djangoparser import use_args, parser | 17 | from webargs.djangoparser import use_args, parser |
18 | from settings import conf | 18 | from settings import conf |
19 | from common import response | 19 | from common import response |
20 | from common import response2 | ||
20 | from common.mixins import GenericView,DocGenericView | 21 | from common.mixins import GenericView,DocGenericView |
21 | from common.tools.file_tools import file_write | 22 | from common.tools.file_tools import file_write |
22 | from common.redis_cache import redis_handler as rh | 23 | from common.redis_cache import redis_handler as rh |
... | @@ -1964,8 +1965,8 @@ class InvoiceExcelView(GenericView): | ... | @@ -1964,8 +1965,8 @@ class InvoiceExcelView(GenericView): |
1964 | #authentication_classes = [OAuth2AuthenticationWithUser] | 1965 | #authentication_classes = [OAuth2AuthenticationWithUser] |
1965 | 1966 | ||
1966 | # 下载发票excel | 1967 | # 下载发票excel |
1967 | @use_args(invoice_download_args, location='querystring') | 1968 | @use_args(invoice_download_args, location='data') |
1968 | def get(self, request, args): | 1969 | def post(self, request, args): |
1969 | application_ids = args.get('application_ids') | 1970 | application_ids = args.get('application_ids') |
1970 | application_entity = args.get('application_entity') | 1971 | application_entity = args.get('application_entity') |
1971 | self.running_log.info('[InvoiceExcelView] [user_role={0}] '.format('111222333')) | 1972 | self.running_log.info('[InvoiceExcelView] [user_role={0}] '.format('111222333')) |
... | @@ -2009,8 +2010,8 @@ class InvoiceQueryInfoView(GenericView): | ... | @@ -2009,8 +2010,8 @@ class InvoiceQueryInfoView(GenericView): |
2009 | #permission_classes = [IsAuthenticated] | 2010 | #permission_classes = [IsAuthenticated] |
2010 | #authentication_classes = [OAuth2AuthenticationWithUser] | 2011 | #authentication_classes = [OAuth2AuthenticationWithUser] |
2011 | 2012 | ||
2012 | @use_args(invoice_download_args, location='querystring') | 2013 | @use_args(invoice_download_args, location='data') |
2013 | def get(self, request, args): | 2014 | def post(self, request, args): |
2014 | application_ids = args.get('application_ids') | 2015 | application_ids = args.get('application_ids') |
2015 | application_entity = args.get('application_entity') | 2016 | application_entity = args.get('application_entity') |
2016 | self.running_log.info('[InvoiceExcelView] [user_role={0}] '.format('111222333')) | 2017 | self.running_log.info('[InvoiceExcelView] [user_role={0}] '.format('111222333')) |
... | @@ -2037,7 +2038,7 @@ class InvoiceQueryInfoView(GenericView): | ... | @@ -2037,7 +2038,7 @@ class InvoiceQueryInfoView(GenericView): |
2037 | self.running_log.info("java invoice info api finish, applicationIds:{0},{1}".format(application_ids, resp.text)) | 2038 | self.running_log.info("java invoice info api finish, applicationIds:{0},{1}".format(application_ids, resp.text)) |
2038 | res_json = json.loads(resp.text) | 2039 | res_json = json.loads(resp.text) |
2039 | java_result = res_json.get('result') | 2040 | java_result = res_json.get('result') |
2040 | return response.ok(data=java_result) | 2041 | return response2.ok(data=java_result) |
2041 | except Exception as e: | 2042 | except Exception as e: |
2042 | self.running_log.error("invoice info request to java error, url:{0}, param:{1}, errorMsg:{2}".format( | 2043 | self.running_log.error("invoice info request to java error, url:{0}, param:{1}, errorMsg:{2}".format( |
2043 | url, json.dumps(body), traceback.format_exc())) | 2044 | url, json.dumps(body), traceback.format_exc())) | ... | ... |
src/common/response2.py
0 → 100644
1 | import enum | ||
2 | from django.http import JsonResponse, HttpResponse | ||
3 | from .named_enum import NamedEnum | ||
4 | |||
5 | |||
6 | def res_content(meta_status, msg, data=None): | ||
7 | res = {'code': meta_status, 'msg': msg} | ||
8 | if data is not None: | ||
9 | res['result'] = data | ||
10 | return res | ||
11 | |||
12 | |||
13 | @enum.unique | ||
14 | class MetaStatus(NamedEnum): | ||
15 | SUCCESS = (0, 'success') | ||
16 | NEED_LOGIN = (1, 'need login') | ||
17 | INVALID_PARAMS = (2, 'invalid params') | ||
18 | INTERNAL_ERROR = (3, 'internal error') | ||
19 | NOT_EXIST = (4, 'object not exist') | ||
20 | ASYNC_WAIT = (5, 'async wait') | ||
21 | NO_PERMISSION = (6, 'no permission') | ||
22 | ILLEGAL_OPERATION = (7, 'illegal operation') | ||
23 | NEED_UPDATE = (8, 'need update') | ||
24 | |||
25 | |||
26 | class APIResponse(JsonResponse): | ||
27 | def __init__(self, meta_status, data=None, msg='', json_dumps_params=None, **kwargs): | ||
28 | data = res_content(meta_status, msg, data) | ||
29 | json_dumps_params = json_dumps_params or {'ensure_ascii': False} | ||
30 | kwargs['json_dumps_params'] = json_dumps_params | ||
31 | super().__init__(data, **kwargs) | ||
32 | |||
33 | |||
34 | def ok(**kwargs): | ||
35 | return APIResponse(10000, msg=MetaStatus.SUCCESS.verbose_name, **kwargs) | ||
36 | |||
37 | |||
38 | def error_msg(msg='internal error', **kwargs): | ||
39 | return APIResponse(MetaStatus.INTERNAL_ERROR.value, msg=msg, **kwargs) | ||
40 | |||
41 | |||
42 | def need_update(**kwargs): | ||
43 | return APIResponse(MetaStatus.NEED_UPDATE.value, msg=MetaStatus.NEED_UPDATE.verbose_name, **kwargs) | ||
44 | |||
45 | |||
46 | def excel_response(file_name, io_content): | ||
47 | http_response = HttpResponse(content_type="application/vnd.ms-excel") | ||
48 | http_response['Content-Disposition'] = 'attachment;filename={0}.xlsx'.format(file_name) | ||
49 | http_response.write(io_content.getvalue()) | ||
50 | return http_response |
-
Please register or sign in to post a comment