|
@@ -6,7 +6,7 @@
|
|
@Email : zhangdongming@asj6.wecom.work
|
|
@Email : zhangdongming@asj6.wecom.work
|
|
@Software: PyCharm
|
|
@Software: PyCharm
|
|
"""
|
|
"""
|
|
-
|
|
|
|
|
|
+from django.db import transaction
|
|
from django.db.models import Q
|
|
from django.db.models import Q
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
|
|
|
|
@@ -42,12 +42,54 @@ class GatewayDeviceView(View):
|
|
# 网关设备
|
|
# 网关设备
|
|
if operation == 'list':
|
|
if operation == 'list':
|
|
return self.gateway_device_list(request_dict, response)
|
|
return self.gateway_device_list(request_dict, response)
|
|
- if operation == 'del':
|
|
|
|
|
|
+ elif operation == 'del':
|
|
return self.gateway_device_del(user_id, request_dict, response)
|
|
return self.gateway_device_del(user_id, request_dict, response)
|
|
- if operation == 'update':
|
|
|
|
|
|
+ elif operation == 'update':
|
|
return self.gateway_device_update(user_id, request_dict, response)
|
|
return self.gateway_device_update(user_id, request_dict, response)
|
|
- if operation == 'my/family/list':
|
|
|
|
|
|
+ elif operation == 'my/family/list':
|
|
return self.my_family_list(user_id, response)
|
|
return self.my_family_list(user_id, response)
|
|
|
|
+ elif operation == 'location-setting':
|
|
|
|
+ return self.device_location_setting(user_id, request_dict, response)
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def device_location_setting(cls, user_id, request_dict, response):
|
|
|
|
+ """
|
|
|
|
+ 网关位置迁移
|
|
|
|
+ @param user_id: 用户id
|
|
|
|
+ @param request_dict: 请求参数字典
|
|
|
|
+ @param response: 响应对象
|
|
|
|
+ @return: []
|
|
|
|
+ """
|
|
|
|
+ device_id = request_dict.get('deviceId', None)
|
|
|
|
+ family_id = request_dict.get('familyId', None)
|
|
|
|
+ room_id = request_dict.get('roomId', None)
|
|
|
|
+ if not all([device_id, family_id, room_id]):
|
|
|
|
+ return response.json(444)
|
|
|
|
+ device_id = int(device_id)
|
|
|
|
+ family_id = int(family_id)
|
|
|
|
+ room_id = int(room_id)
|
|
|
|
+ permission = EquipmentFamilyView.get_member_permission_details(user_id, family_id)
|
|
|
|
+ if not permission or permission == '003':
|
|
|
|
+ return response.json(404)
|
|
|
|
+ try:
|
|
|
|
+ with transaction.atomic():
|
|
|
|
+ family_room_device_qs = FamilyRoomDevice.objects.filter(device_id=device_id, family_id=family_id)
|
|
|
|
+ if family_room_device_qs.exists():
|
|
|
|
+ family_room_device_qs = family_room_device_qs.filter(sub_device=0)
|
|
|
|
+ if family_room_device_qs.exists():
|
|
|
|
+ family_room_device_qs.update(room_id=room_id)
|
|
|
|
+ else:
|
|
|
|
+ family_room_qs = FamilyRoom.objects.filter(family_id=family_id, id=room_id)
|
|
|
|
+ if not family_room_qs.exists():
|
|
|
|
+ return response.json(173)
|
|
|
|
+ if family_room_qs.exists():
|
|
|
|
+ family_room_device_qs = FamilyRoomDevice.objects.filter(device_id=device_id)
|
|
|
|
+ if family_room_device_qs.exists():
|
|
|
|
+ family_room_device_qs.update(family_id=family_id, room_id=room_id)
|
|
|
|
+ return response.json(0)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+ return response.json(177, repr(e))
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def gateway_device_update(cls, user_id, request_dict, response):
|
|
def gateway_device_update(cls, user_id, request_dict, response):
|