|
@@ -0,0 +1,62 @@
|
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
|
+"""
|
|
|
|
+@Time : 2020/12/16 8:44
|
|
|
|
+@Auth : Locky
|
|
|
|
+@File :CloudTest.py
|
|
|
|
+@IDE :PyCharm
|
|
|
|
+"""
|
|
|
|
+from django.views.generic.base import View
|
|
|
|
+
|
|
|
|
+from Model.models import Device_Info
|
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class cloudTestView(View):
|
|
|
|
+
|
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ operation = kwargs.get('operation')
|
|
|
|
+ return self.validation(request.GET, request, operation)
|
|
|
|
+
|
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ operation = kwargs.get('operation')
|
|
|
|
+ return self.validation(request.POST, request, operation)
|
|
|
|
+
|
|
|
|
+ def validation(self, request_dict, request, operation):
|
|
|
|
+ response = ResponseObject()
|
|
|
|
+ # if operation == 'deviceTransfer':
|
|
|
|
+ # return self.deviceTransfer(request_dict, response)
|
|
|
|
+ if operation is None:
|
|
|
|
+ return response.json(444, 'error path')
|
|
|
|
+ else:
|
|
|
|
+ token = request_dict.get('token', None)
|
|
|
|
+ # 设备主键uid
|
|
|
|
+ tko = TokenObject(token)
|
|
|
|
+ response.lang = tko.lang
|
|
|
|
+ if tko.code != 0:
|
|
|
|
+ return response.json(tko.code)
|
|
|
|
+ userID = tko.userID
|
|
|
|
+ if operation == 'deviceTransfer':
|
|
|
|
+ return self.deviceTransfer(request_dict, response)
|
|
|
|
+
|
|
|
|
+ def deviceTransfer(self, request_dict, response):
|
|
|
|
+ # 设备转移
|
|
|
|
+ userID = request_dict.get("userID", None)
|
|
|
|
+ oldUID = request_dict.get('oldUID', None)
|
|
|
|
+ newUID = request_dict.get('newUID', None)
|
|
|
|
+
|
|
|
|
+ # 查询设备是否存在且支持云存功能
|
|
|
|
+ oldUIDdevice_qs = Device_Info.objects.filter(userID_id=userID, UID=oldUID, isVod=1, isExist=1)
|
|
|
|
+ newUIDdevice_qs = Device_Info.objects.filter(userID_id=userID, UID=newUID, isVod=1, isExist=1)
|
|
|
|
+ try:
|
|
|
|
+ if oldUIDdevice_qs[0] and newUIDdevice_qs[0]:
|
|
|
|
+ # 更新UID
|
|
|
|
+ oldUIDdevice_qs.update(UID=newUID)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print('更新失败')
|
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
+ else:
|
|
|
|
+ return response.json(0)
|
|
|
|
+
|