InitController.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # @Author : Rocky
  2. # @File : InitController.py
  3. # @Time : 2023/4/11 17:26
  4. from django.http import HttpResponse
  5. from django.views import View
  6. from Model.models import Device_Info, SceneLog
  7. from Object.ResponseObject import ResponseObject
  8. class InitView(View):
  9. def get(self, request, *args, **kwargs):
  10. request.encoding = 'utf-8'
  11. operation = kwargs.get('operation')
  12. return self.validation(request.GET, operation)
  13. def post(self, request, *args, **kwargs):
  14. request.encoding = 'utf-8'
  15. operation = kwargs.get('operation')
  16. return self.validation(request.POST, operation)
  17. def validation(self, request_dict, operation):
  18. if operation == 'health-check': # 负载均衡器健康检测接口
  19. return self.health_check(request_dict)
  20. @staticmethod
  21. def health_check(request_dict):
  22. try:
  23. response = ResponseObject()
  24. Device_Info.objects.filter().values('id').first()
  25. SceneLog.objects.filter().values('id').first()
  26. return response.json(0)
  27. except Exception as e:
  28. return HttpResponse(repr(e), status=500)