|
@@ -54,6 +54,10 @@ class GatewayFamilyRoomView(View):
|
|
|
return self.all_devices(request_dict, response)
|
|
|
elif operation == 'devices-sort': # 家庭设备排序
|
|
|
return self.devices_sort(request_dict, response)
|
|
|
+ elif operation == 'device-category': # 获取设备类别
|
|
|
+ return self.device_category(request_dict, response)
|
|
|
+ elif operation == 'category-sort': # 设备类别排序
|
|
|
+ return self.category_sort(request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -234,19 +238,29 @@ class GatewayFamilyRoomView(View):
|
|
|
'device__Type',
|
|
|
'device__NickName',
|
|
|
'room_id',
|
|
|
- 'sub_device').order_by(
|
|
|
+ 'sub_device',
|
|
|
+ 'category',
|
|
|
+ ).order_by(
|
|
|
'sort')
|
|
|
+
|
|
|
if not family_room_device_qs.exists():
|
|
|
return response.json(0, [])
|
|
|
-
|
|
|
+ sort = FamilyRoomDevice.objects.filter(family_id=family_id).values('category').annotate(
|
|
|
+ count=Count('category')).values('category', 'category_sort')
|
|
|
+ for item in sort:
|
|
|
+ if item['category'] == 0:
|
|
|
+ item['category_name'] = '网关子设备类'
|
|
|
+ else:
|
|
|
+ item['category_name'] = '摄像头类'
|
|
|
gateways = []
|
|
|
cameras = []
|
|
|
# 查询房间名称
|
|
|
for device in family_room_device_qs:
|
|
|
room_id = device['room_id']
|
|
|
device_type = device['device__Type']
|
|
|
+ category = device['category']
|
|
|
room_name = FamilyRoom.objects.filter(id=room_id)
|
|
|
- if device_type == 200: # 网关设备
|
|
|
+ if category == 0: # 网关设备
|
|
|
if not device['sub_device']:
|
|
|
device_dict = {
|
|
|
'deviceId': device['device_id'],
|
|
@@ -256,7 +270,7 @@ class GatewayFamilyRoomView(View):
|
|
|
}
|
|
|
else:
|
|
|
sub_device_qs = GatewaySubDevice.objects.filter(id=device['sub_device']).values('device_type',
|
|
|
- 'nickname')
|
|
|
+ 'nickname')
|
|
|
device_dict = {
|
|
|
'deviceId': device['sub_device'],
|
|
|
'deviceType': sub_device_qs[0]['device_type'],
|
|
@@ -265,6 +279,7 @@ class GatewayFamilyRoomView(View):
|
|
|
}
|
|
|
|
|
|
gateways.append(device_dict)
|
|
|
+
|
|
|
else: # 摄像头设备
|
|
|
cameras.append({
|
|
|
'deviceId': device['device_id'],
|
|
@@ -274,7 +289,8 @@ class GatewayFamilyRoomView(View):
|
|
|
})
|
|
|
device_room = {
|
|
|
'gateways': gateways,
|
|
|
- 'cameras': cameras
|
|
|
+ 'cameras': cameras,
|
|
|
+ 'sort': list(sort)
|
|
|
}
|
|
|
return response.json(0, device_room)
|
|
|
except Exception as e:
|
|
@@ -306,3 +322,54 @@ class GatewayFamilyRoomView(View):
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
return response.json(500, repr(e))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def device_category(request_dict, response):
|
|
|
+ """
|
|
|
+ 获取设备类别排序
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @request_dict 家庭id: family_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).values('category').annotate(
|
|
|
+ count=Count('category')).values('category', 'category_sort')
|
|
|
+ for item in family_room_device_qs:
|
|
|
+ if item['category'] == 0:
|
|
|
+ item['category_name'] = '网关子设备类'
|
|
|
+ else:
|
|
|
+ item['category_name'] = '摄像头类'
|
|
|
+ return response.json(0, list(family_room_device_qs))
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, repr(e))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def category_sort(request_dict, response):
|
|
|
+ """
|
|
|
+ 家庭设备排序
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @request_dict 家庭id: family_id
|
|
|
+ @request_dict 排序列表: category_sort
|
|
|
+ @param response: 响应参数
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ family_id = request_dict.get('familyId', None)
|
|
|
+ category_sort = request_dict.get('categorySort', None)
|
|
|
+ if not all([family_id, category_sort]):
|
|
|
+ return response.json(444)
|
|
|
+ try:
|
|
|
+ category_sort_list = eval(category_sort)
|
|
|
+ family_room_device_qs = FamilyRoomDevice.objects.filter(family_id=family_id)
|
|
|
+ if family_room_device_qs.exists():
|
|
|
+ with transaction.atomic():
|
|
|
+ for item in category_sort_list:
|
|
|
+ category = item['category']
|
|
|
+ category_sort = item['category_sort']
|
|
|
+ family_room_device_qs.filter(category=category).update(category_sort=category_sort)
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, repr(e))
|