merge
Showing
4 changed files
with
160 additions
and
30 deletions
| ... | @@ -28,34 +28,35 @@ client_id_base64 = base64.b64encode('{0}:{1}'.format( | ... | @@ -28,34 +28,35 @@ client_id_base64 = base64.b64encode('{0}:{1}'.format( |
| 28 | conf.IWA_CLIENT_ID, conf.IWA_CLIENT_SECRET).encode('utf-8')).decode('utf-8') | 28 | conf.IWA_CLIENT_ID, conf.IWA_CLIENT_SECRET).encode('utf-8')).decode('utf-8') |
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | class LoginView(ObtainJSONWebToken, GenericView): | 31 | # class LoginView(ObtainJSONWebToken, GenericView): |
| 32 | 32 | ||
| 33 | def post(self, request, *args, **kwargs): | 33 | # def post(self, request, *args, **kwargs): |
| 34 | # 登录次数限制 | 34 | # # 登录次数限制 |
| 35 | remote_ip = request.META.get('HTTP_X_REAL_IP', '') | 35 | # remote_ip = request.META.get('HTTP_X_REAL_IP', '') |
| 36 | user_name = request.data.get('username', '') | 36 | # user_name = request.data.get('username', '') |
| 37 | times = rh.get_login_times(remote_ip) | 37 | # times = rh.get_login_times(remote_ip) |
| 38 | if isinstance(times, str) and int(times) >= LOGIN_TIMES_LIMIT: | 38 | # if isinstance(times, str) and int(times) >= LOGIN_TIMES_LIMIT: |
| 39 | raise self.invalid_params(msg="重试次数限制") | 39 | # raise self.invalid_params(msg="重试次数限制") |
| 40 | 40 | ||
| 41 | res = super(LoginView, self).post(request, *args, **kwargs) | 41 | # res = super(LoginView, self).post(request, *args, **kwargs) |
| 42 | self.running_log.info('[users.login] username: {0}'.format(user_name)) | 42 | # self.running_log.info('[users.login] username: {0}'.format(user_name)) |
| 43 | 43 | ||
| 44 | if res.status_code == status.HTTP_400_BAD_REQUEST: | 44 | # if res.status_code == status.HTTP_400_BAD_REQUEST: |
| 45 | rh.set_login_times(remote_ip, LOGIN_TIMES_LIMIT_EXPIRES) | 45 | # rh.set_login_times(remote_ip, LOGIN_TIMES_LIMIT_EXPIRES) |
| 46 | raise self.invalid_params(msg="用户名或密码错误") | 46 | # raise self.invalid_params(msg="用户名或密码错误") |
| 47 | serializer = self.get_serializer(data=request.data) | 47 | # serializer = self.get_serializer(data=request.data) |
| 48 | serializer.is_valid() | 48 | # serializer.is_valid() |
| 49 | user = serializer.object.get('user') | 49 | # user = serializer.object.get('user') |
| 50 | user_role = UserRole.objects.filter(auth_user_id=user.id).first() | 50 | # user_role = UserRole.objects.filter(auth_user_id=user.id).first() |
| 51 | data = { | 51 | # data = { |
| 52 | 'user_id': user.id, | 52 | # 'user_id': user.id, |
| 53 | 'user_name': user.username, | 53 | # 'user_name': user.username, |
| 54 | 'token': res.data.get('token'), | 54 | # 'token': res.data.get('token'), |
| 55 | 'role': user_role.role if user_role else -1 | 55 | # 'role': user_role.role if user_role else -1 |
| 56 | } | 56 | # } |
| 57 | rh.set_token(res.data.get('token')[-10:], user.username) | 57 | # rh.set_token(res.data.get('token')[-10:], user.username) |
| 58 | return response.ok(data=data) | 58 | # rh.set_token(res.data.get('token')[-11:], user_role.role if user_role else -1) |
| 59 | # return response.ok(data=data) | ||
| 59 | 60 | ||
| 60 | 61 | ||
| 61 | class IWALoginView(IWABaseView, GenericView): | 62 | class IWALoginView(IWABaseView, GenericView): |
| ... | @@ -85,9 +86,10 @@ class IWALoginView(IWABaseView, GenericView): | ... | @@ -85,9 +86,10 @@ class IWALoginView(IWABaseView, GenericView): |
| 85 | is_valid, data = self.validate(q_number) | 86 | is_valid, data = self.validate(q_number) |
| 86 | 87 | ||
| 87 | if is_valid: | 88 | if is_valid: |
| 88 | rh.set_token(data.get('token')[-10:], data.get('user_name')) | ||
| 89 | user_role = UserRole.objects.filter(auth_user_id=data.get('user_id')).first() | 89 | user_role = UserRole.objects.filter(auth_user_id=data.get('user_id')).first() |
| 90 | data['role'] = user_role.role if user_role else -1 | 90 | data['role'] = user_role.role if user_role else -1 |
| 91 | rh.set_token(data.get('token')[-10:], data.get('user_name')) | ||
| 92 | rh.set_token(data.get('token')[-11:], user_role.role if user_role else -1) | ||
| 91 | return response.ok(data=data) | 93 | return response.ok(data=data) |
| 92 | else: | 94 | else: |
| 93 | self.no_permission(data) | 95 | self.no_permission(data) | ... | ... |
| ... | @@ -5,5 +5,7 @@ from . import views | ... | @@ -5,5 +5,7 @@ from . import views |
| 5 | urlpatterns = [ | 5 | urlpatterns = [ |
| 6 | path(r'', views.DocView.as_view()), | 6 | path(r'', views.DocView.as_view()), |
| 7 | path(r'query/employee', views.EmployeeView.as_view()), | 7 | path(r'query/employee', views.EmployeeView.as_view()), |
| 8 | path(r'invoice/downloadExcel', views.InvoiceExcelView.as_view()), | ||
| 9 | path(r'invoice/queryInfo', views.InvoiceQueryInfoView.as_view()), | ||
| 8 | path(r'contract/v1', views.SEContractView.as_view()), | 10 | path(r'contract/v1', views.SEContractView.as_view()), |
| 9 | ] | 11 | ] | ... | ... |
| ... | @@ -57,6 +57,7 @@ from .models import ( | ... | @@ -57,6 +57,7 @@ from .models import ( |
| 57 | AFCCmsStatusInfo, | 57 | AFCCmsStatusInfo, |
| 58 | Configs | 58 | Configs |
| 59 | ) | 59 | ) |
| 60 | from common.exceptions import (NoPermissionException) | ||
| 60 | from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult, SystemName, RequestTeam | 61 | from .named_enum import ErrorType, AutoResult, WholeResult, RPAResult, SystemName, RequestTeam |
| 61 | from .mixins import DocHandler, MPOSHandler, PreSEHandler | 62 | from .mixins import DocHandler, MPOSHandler, PreSEHandler |
| 62 | from . import consts | 63 | from . import consts |
| ... | @@ -65,6 +66,8 @@ from celery_compare.tasks import compare, fsm_compare | ... | @@ -65,6 +66,8 @@ from celery_compare.tasks import compare, fsm_compare |
| 65 | from prese.compare import get_empty_result | 66 | from prese.compare import get_empty_result |
| 66 | 67 | ||
| 67 | import time | 68 | import time |
| 69 | from django.http import HttpResponse | ||
| 70 | from django.utils.encoding import escape_uri_path | ||
| 68 | 71 | ||
| 69 | 72 | ||
| 70 | class CustomDate(fields.Date): | 73 | class CustomDate(fields.Date): |
| ... | @@ -567,6 +570,10 @@ mpos_args = { | ... | @@ -567,6 +570,10 @@ mpos_args = { |
| 567 | 'file_base64_content': fields.List(fields.Str(), required=True, validate=validate.Length(min=1)), | 570 | 'file_base64_content': fields.List(fields.Str(), required=True, validate=validate.Length(min=1)), |
| 568 | } | 571 | } |
| 569 | 572 | ||
| 573 | invoice_download_args = { | ||
| 574 | 'application_entity': fields.Int(required=True), | ||
| 575 | 'application_ids': fields.Str(required=True), | ||
| 576 | } | ||
| 570 | 577 | ||
| 571 | class UploadDocView(GenericView, DocHandler): | 578 | class UploadDocView(GenericView, DocHandler): |
| 572 | # permission_classes = [] | 579 | # permission_classes = [] |
| ... | @@ -1065,6 +1072,18 @@ class DocView(DocGenericView, DocHandler): | ... | @@ -1065,6 +1072,18 @@ class DocView(DocGenericView, DocHandler): |
| 1065 | create_time_start = args.get('create_time_start') | 1072 | create_time_start = args.get('create_time_start') |
| 1066 | create_time_end = args.get('create_time_end') | 1073 | create_time_end = args.get('create_time_end') |
| 1067 | 1074 | ||
| 1075 | # 角色权限不符,返回空列表 | ||
| 1076 | token = request.META.get("HTTP_AUTHORIZATION") | ||
| 1077 | user_role = rh.get_token(token[-11:]) | ||
| 1078 | self.running_log.info('[api doc] [user_role={0} business_type={1}] '.format(user_role, business_type)) | ||
| 1079 | if user_role or user_role == '-1' or (user_role == '1' and business_type == 'HIL') or (user_role == '2' and business_type == 'AFC'): | ||
| 1080 | pagination = {'current': page, 'total': 0, 'page_size': page_size} | ||
| 1081 | res = { | ||
| 1082 | 'pagination': pagination, | ||
| 1083 | 'doc_list': [] | ||
| 1084 | } | ||
| 1085 | return response.ok(data=res) | ||
| 1086 | |||
| 1068 | status_query = Q(status=status) if status is not None else Q() | 1087 | status_query = Q(status=status) if status is not None else Q() |
| 1069 | application_id_query = Q(application_id__contains=application_id) if application_id is not None else Q() | 1088 | application_id_query = Q(application_id__contains=application_id) if application_id is not None else Q() |
| 1070 | data_source_query = Q(data_source=data_source) if data_source is not None else Q() | 1089 | data_source_query = Q(data_source=data_source) if data_source is not None else Q() |
| ... | @@ -1230,6 +1249,14 @@ class CompareResultView(GenericView): | ... | @@ -1230,6 +1249,14 @@ class CompareResultView(GenericView): |
| 1230 | scheme = args.get('scheme') | 1249 | scheme = args.get('scheme') |
| 1231 | case_id = args.get('case_id') | 1250 | case_id = args.get('case_id') |
| 1232 | is_auto = args.get('auto') | 1251 | is_auto = args.get('auto') |
| 1252 | |||
| 1253 | # 角色权限不符,返回异常 | ||
| 1254 | token = request.META.get("HTTP_AUTHORIZATION") | ||
| 1255 | user_role = rh.get_token(token[-11:]) | ||
| 1256 | self.running_log.info('[CompareResultView] [user_role={0}] '.format(user_role)) | ||
| 1257 | if user_role or user_role == '-1' or (user_role == '1' and entity == 'HIL') or (user_role == '2' and entity == 'AFC'): | ||
| 1258 | raise NoPermissionException('no permission') | ||
| 1259 | |||
| 1233 | if is_auto == 1: | 1260 | if is_auto == 1: |
| 1234 | result_table = HILAutoSettlement if entity == consts.HIL_PREFIX else AFCAutoSettlement | 1261 | result_table = HILAutoSettlement if entity == consts.HIL_PREFIX else AFCAutoSettlement |
| 1235 | 1262 | ||
| ... | @@ -1628,6 +1655,18 @@ class AutoSettlementView(GenericView): | ... | @@ -1628,6 +1655,18 @@ class AutoSettlementView(GenericView): |
| 1628 | 1655 | ||
| 1629 | is_fsm = args.get('is_fsm') | 1656 | is_fsm = args.get('is_fsm') |
| 1630 | 1657 | ||
| 1658 | # 角色权限不符,返回空列表 | ||
| 1659 | token = request.META.get("HTTP_AUTHORIZATION") | ||
| 1660 | user_role = rh.get_token(token[-11:]) | ||
| 1661 | self.running_log.info('[AutoSettlementView] [user_role={0}] '.format(user_role)) | ||
| 1662 | if user_role or user_role == '-1' or (user_role == '1' and business_type == 'HIL') or (user_role == '2' and business_type == 'AFC'): | ||
| 1663 | pagination = {'current': page, 'total': 0, 'page_size': page_size} | ||
| 1664 | res = { | ||
| 1665 | 'pagination': pagination, | ||
| 1666 | 'doc_list': [] | ||
| 1667 | } | ||
| 1668 | return response.ok(data=res) | ||
| 1669 | |||
| 1631 | if isinstance(auto_result, int): | 1670 | if isinstance(auto_result, int): |
| 1632 | auto_result = consts.RESULT_MAP.get(auto_result) | 1671 | auto_result = consts.RESULT_MAP.get(auto_result) |
| 1633 | if isinstance(whole_result, int): | 1672 | if isinstance(whole_result, int): |
| ... | @@ -1712,6 +1751,13 @@ class AutoSettlementExcelView(GenericView): | ... | @@ -1712,6 +1751,13 @@ class AutoSettlementExcelView(GenericView): |
| 1712 | 1751 | ||
| 1713 | is_fsm = args.get('is_fsm') | 1752 | is_fsm = args.get('is_fsm') |
| 1714 | 1753 | ||
| 1754 | # 角色权限不符,返回异常 | ||
| 1755 | token = request.META.get("HTTP_AUTHORIZATION") | ||
| 1756 | user_role = rh.get_token(token[-11:]) | ||
| 1757 | self.running_log.info('[AutoSettlementExcelView] [user_role={0}] '.format(user_role)) | ||
| 1758 | if user_role or user_role == '-1' or (user_role == '1' and business_type == 'HIL') or (user_role == '2' and business_type == 'AFC'): | ||
| 1759 | raise NoPermissionException('no permission') | ||
| 1760 | |||
| 1715 | if isinstance(auto_result, int): | 1761 | if isinstance(auto_result, int): |
| 1716 | auto_result = consts.RESULT_MAP.get(auto_result) | 1762 | auto_result = consts.RESULT_MAP.get(auto_result) |
| 1717 | if isinstance(whole_result, int): | 1763 | if isinstance(whole_result, int): |
| ... | @@ -1860,6 +1906,86 @@ class GoView(GenericView): | ... | @@ -1860,6 +1906,86 @@ class GoView(GenericView): |
| 1860 | else: | 1906 | else: |
| 1861 | return response.error_msg(msg='识别错误') | 1907 | return response.error_msg(msg='识别错误') |
| 1862 | 1908 | ||
| 1909 | class InvoiceExcelView(GenericView): | ||
| 1910 | permission_classes = [IsAuthenticated] | ||
| 1911 | authentication_classes = [OAuth2AuthenticationWithUser] | ||
| 1912 | |||
| 1913 | # 下载发票excel | ||
| 1914 | @use_args(invoice_download_args, location='data') | ||
| 1915 | def post(self, request, args): | ||
| 1916 | application_ids = args.get('application_ids') | ||
| 1917 | application_entity = args.get('application_entity') | ||
| 1918 | |||
| 1919 | # 角色权限不符,返回异常 | ||
| 1920 | token = request.META.get("HTTP_AUTHORIZATION") | ||
| 1921 | user_role = rh.get_token(token[-11:]) | ||
| 1922 | self.running_log.info('[InvoiceExcelView] [user_role={0}] '.format(user_role)) | ||
| 1923 | if user_role or user_role == '-1' or (user_role == '1' and application_entity == 'HIL') or (user_role == '2' and application_entity == 'AFC'): | ||
| 1924 | raise NoPermissionException('no permission') | ||
| 1925 | |||
| 1926 | url = 'http://127.0.0.1:8088/napi/invoice/downloadExcelOri' | ||
| 1927 | body = { | ||
| 1928 | 'applicationIds': application_ids, | ||
| 1929 | 'applicationEntity': application_entity | ||
| 1930 | } | ||
| 1931 | try: | ||
| 1932 | self.running_log.info("request java invoice excel api, url:{0}, body:{1}".format(url, json.dumps(body))) | ||
| 1933 | headers = { | ||
| 1934 | 'Content-Type': 'application/json' | ||
| 1935 | } | ||
| 1936 | resp = requests.post(url, headers=headers, json=body) | ||
| 1937 | self.running_log.info("java invoice excel api finish, applicationIds:{0},{1}".format(application_ids, resp.text)) | ||
| 1938 | res_json = json.loads(resp.text) | ||
| 1939 | file_path = res_json.get('result') | ||
| 1940 | self.running_log.info("java invoice excel after process, filePath:{0}".format(file_path)) | ||
| 1941 | current_time = time.strftime('%Y-%m-%d_%H_%M_%S', time.localtime()) | ||
| 1942 | download_file_name = "发票信息提取-" + current_time + ".xlsx" | ||
| 1943 | f = open(file_path,"rb") | ||
| 1944 | response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') | ||
| 1945 | response['Content-Disposition'] = 'attachment; filename="{0}"'.format(escape_uri_path(download_file_name)) | ||
| 1946 | response['Access-Control-Expose-Headers'] = 'content-disposition' | ||
| 1947 | response.write(f.read()) | ||
| 1948 | f.close() | ||
| 1949 | return response | ||
| 1950 | except Exception as e: | ||
| 1951 | self.running_log.error("invoice excel request to java error, url:{0}, param:{1}, errorMsg:{2}".format( | ||
| 1952 | url, json.dumps(body), traceback.format_exc())) | ||
| 1953 | |||
| 1954 | class InvoiceQueryInfoView(GenericView): | ||
| 1955 | permission_classes = [IsAuthenticated] | ||
| 1956 | authentication_classes = [OAuth2AuthenticationWithUser] | ||
| 1957 | |||
| 1958 | @use_args(invoice_download_args, location='data') | ||
| 1959 | def post(self, request, args): | ||
| 1960 | application_ids = args.get('application_ids') | ||
| 1961 | application_entity = args.get('application_entity') | ||
| 1962 | |||
| 1963 | # 角色权限不符,返回异常 | ||
| 1964 | token = request.META.get("HTTP_AUTHORIZATION") | ||
| 1965 | user_role = rh.get_token(token[-11:]) | ||
| 1966 | self.running_log.info('[InvoiceQueryInfoView] [user_role={0}] '.format(user_role)) | ||
| 1967 | if user_role or user_role == '-1' or (user_role == '1' and application_entity == 'HIL') or (user_role == '2' and application_entity == 'AFC'): | ||
| 1968 | raise NoPermissionException('no permission') | ||
| 1969 | |||
| 1970 | url = 'http://127.0.0.1:8088/napi/invoice/queryInfoOri' | ||
| 1971 | body = { | ||
| 1972 | 'applicationIds': application_ids, | ||
| 1973 | 'applicationEntity': application_entity | ||
| 1974 | } | ||
| 1975 | try: | ||
| 1976 | self.running_log.info("request java invoice info api, url:{0}, body:{1}".format(url, json.dumps(body))) | ||
| 1977 | headers = { | ||
| 1978 | 'Content-Type': 'application/json' | ||
| 1979 | } | ||
| 1980 | resp = requests.post(url, headers=headers, json=body) | ||
| 1981 | self.running_log.info("java invoice info api finish, applicationIds:{0},{1}".format(application_ids, resp.text)) | ||
| 1982 | res_json = json.loads(resp.text) | ||
| 1983 | java_result = res_json.get('result') | ||
| 1984 | return response.ok(data=java_result) | ||
| 1985 | except Exception as e: | ||
| 1986 | self.running_log.error("invoice info request to java error, url:{0}, param:{1}, errorMsg:{2}".format( | ||
| 1987 | url, json.dumps(body), traceback.format_exc())) | ||
| 1988 | |||
| 1863 | def notifyCmsPass(self, request): | 1989 | def notifyCmsPass(self, request): |
| 1864 | args = request.data | 1990 | args = request.data |
| 1865 | cms_info = args.get('content', {}) | 1991 | cms_info = args.get('content', {}) | ... | ... |
| ... | @@ -100,7 +100,7 @@ DATABASES = { | ... | @@ -100,7 +100,7 @@ DATABASES = { |
| 100 | for db_setting in DATABASES.values(): | 100 | for db_setting in DATABASES.values(): |
| 101 | db_setting['OPTIONS'] = { | 101 | db_setting['OPTIONS'] = { |
| 102 | 'driver': 'ODBC Driver 17 for SQL Server', | 102 | 'driver': 'ODBC Driver 17 for SQL Server', |
| 103 | 'extra_params': "odbc_cursortype=2" | 103 | 'extra_params': "odbc_cursortype=2;TrustServerCertificate=yes;Encrypt=yes" |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | # set this to False if you want to turn off pyodbc's connection pooling | 106 | # set this to False if you want to turn off pyodbc's connection pooling | ... | ... |
-
Please register or sign in to post a comment