|
@@ -8,7 +8,7 @@
|
|
|
"""
|
|
|
|
|
|
from django.db import transaction
|
|
|
-from django.db.models import Q, Count
|
|
|
+from django.db.models import Q, Count, F
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
from Controller.SensorGateway.EquipmentFamilyController import EquipmentFamilyView
|
|
@@ -50,6 +50,8 @@ class GatewayFamilyRoomView(View):
|
|
|
# 房间详情
|
|
|
elif operation == 'details':
|
|
|
return self.get_room_details(app_user_id, request_dict, response)
|
|
|
+ elif operation == 'all-devices': # 家庭所有设备
|
|
|
+ return self.all_devices(request_dict, response)
|
|
|
|
|
|
@classmethod
|
|
|
def room_device_save(cls, app_user_id, request_dict, response):
|
|
@@ -136,9 +138,8 @@ class GatewayFamilyRoomView(View):
|
|
|
return response.json(444)
|
|
|
items = ids.split(',')
|
|
|
for item in items:
|
|
|
- vals = item.split('-')
|
|
|
- room_id = vals[0]
|
|
|
- sort = vals[1]
|
|
|
+ item = item.split('-')
|
|
|
+ room_id, sort = item[0], item[1]
|
|
|
family_room = FamilyRoom.objects.filter(id=int(room_id))
|
|
|
if family_room.exists():
|
|
|
family_room.update(sort=int(sort))
|
|
@@ -193,3 +194,34 @@ class GatewayFamilyRoomView(View):
|
|
|
'roomName': name
|
|
|
})
|
|
|
return response.json(0, {'deviceRooms': device_room, 'deviceNotRooms': device_not_room})
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def all_devices(request_dict, response):
|
|
|
+ """
|
|
|
+ 家庭所有设备(网关和摄像头设备)
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @request_dict familyId: 家庭id
|
|
|
+ @param response: 响应参数
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ family_id = request_dict.get('familyId', None)
|
|
|
+ if not family_id:
|
|
|
+ return response.json(444)
|
|
|
+ try:
|
|
|
+ family_room_device_qs = FamilyRoomDevice.objects.filter(family_id=family_id, sub_device=0).\
|
|
|
+ annotate(device_id=F('device__id'), type=F('device__Type'), nickname=F('device__NickName')).\
|
|
|
+ values('device_id', 'type', 'nickname', 'room_id').order_by('sort')
|
|
|
+ if not family_room_device_qs.exists():
|
|
|
+ return response.json(0)
|
|
|
+ # 查询房间名称
|
|
|
+ for device in family_room_device_qs:
|
|
|
+ room_id = device['room_id']
|
|
|
+ if room_id == 0:
|
|
|
+ device['room'] = ''
|
|
|
+ else:
|
|
|
+ family_room_qs = FamilyRoom.objects.filter(id=room_id).values('name')
|
|
|
+ device['room'] = family_room_qs[0]['name'] if family_room_qs.exists() else ''
|
|
|
+ device.pop('room_id')
|
|
|
+ return response.json(0, list(family_room_device_qs))
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, repr(e))
|