|
@@ -19,7 +19,7 @@ from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY
|
|
|
from Controller.DeviceConfirmRegion import Device_Region
|
|
|
from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidChannelSetModel, \
|
|
|
iotdeviceInfoModel, UIDModel, Device_User, UserFamily, FamilyMember, FamilyMemberPermission, \
|
|
|
- FamilyRoomDevice, FamilyRoom, FamilyMemberJoin
|
|
|
+ FamilyRoomDevice, FamilyRoom, FamilyMemberJoin, GatewaySubDevice
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
@@ -90,6 +90,9 @@ class EquipmentFamilyView(View):
|
|
|
return self.changes_member_permission(user_id, request_dict, response)
|
|
|
elif operation == 'family/del':
|
|
|
return self.family_family_del(user_id, request_dict, response)
|
|
|
+ # 首页设备列表
|
|
|
+ elif operation == 'query-device':
|
|
|
+ return self.get_device(user_id, request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -734,6 +737,7 @@ class EquipmentFamilyView(View):
|
|
|
@param family_id: 家庭id
|
|
|
@param room_id: 房间id
|
|
|
@param device_id: 设备id
|
|
|
+ @param device_type: 设备类型
|
|
|
@return: Boole
|
|
|
"""
|
|
|
now_time = int(time.time())
|
|
@@ -778,11 +782,16 @@ class EquipmentFamilyView(View):
|
|
|
device_list = []
|
|
|
for item in device_info_qs:
|
|
|
device_id = item['id']
|
|
|
+ device_type = item['Type']
|
|
|
+ if device_type == 200:
|
|
|
+ category = 0
|
|
|
+ else:
|
|
|
+ category = 1
|
|
|
family_device_qs = FamilyRoomDevice.objects.filter(device_id=device_id)
|
|
|
if not family_device_qs.exists():
|
|
|
# 设备绑定家庭
|
|
|
device_list.append(FamilyRoomDevice(family_id=family_id, device_id=device_id,
|
|
|
- created_time=not_time,
|
|
|
+ created_time=not_time, category=category,
|
|
|
updated_time=not_time))
|
|
|
if device_list:
|
|
|
FamilyRoomDevice.objects.bulk_create(device_list)
|
|
@@ -956,3 +965,161 @@ class EquipmentFamilyView(View):
|
|
|
if user_family_qs.exists():
|
|
|
return True
|
|
|
return False
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def get_device(cls, user_id, request_dict, response):
|
|
|
+ """
|
|
|
+ 首页设备查询
|
|
|
+ @param user_id: 用户id
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @request_dict page: 页数
|
|
|
+ @request_dict line: 分页大小
|
|
|
+ @request_dict familyId: 家庭id
|
|
|
+ @request_dict roomId: 房间id
|
|
|
+ @param response: 响应对象
|
|
|
+ @return: response
|
|
|
+ """
|
|
|
+ page = request_dict.get('page', None)
|
|
|
+ line = request_dict.get('line', None)
|
|
|
+ family_id = request_dict.get('familyId', None)
|
|
|
+ room_id = request_dict.get('roomId', None)
|
|
|
+
|
|
|
+ if not all([page, line, family_id]):
|
|
|
+ return response.json(444, {'error param': 'page or line or family_id'})
|
|
|
+ page = int(page)
|
|
|
+ line = int(line)
|
|
|
+ permission = cls.get_member_permission_details(user_id, int(family_id))
|
|
|
+ if not permission or permission == '003':
|
|
|
+ return response.json(404)
|
|
|
+ family_room_device_qs = FamilyRoomDevice.objects.filter(Q(family_id=family_id), ~Q(device_id__isExist=2),
|
|
|
+ Q(device__userID=user_id)).values().order_by('sort')
|
|
|
+ if not family_room_device_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ gateways = []
|
|
|
+ cameras = []
|
|
|
+ sensors = []
|
|
|
+ device_dict = {}
|
|
|
+ try:
|
|
|
+ category_sort = family_room_device_qs.values('category').annotate(
|
|
|
+ count=Count('category')).values('category', 'category_sort').order_by('category_sort')
|
|
|
+ for item in category_sort:
|
|
|
+ if item['category'] == 0:
|
|
|
+ item['category_name'] = '网关子设备类'
|
|
|
+ else:
|
|
|
+ item['category_name'] = '摄像头类'
|
|
|
+ if room_id:
|
|
|
+ family_room = FamilyRoom.objects.filter(id=room_id)
|
|
|
+ if not family_room.exists():
|
|
|
+ return response.json(173)
|
|
|
+ family_room_device_qs = family_room_device_qs.filter(room_id=room_id)
|
|
|
+ family_room_device_qs = family_room_device_qs[(page - 1) * line:page * line]
|
|
|
+ for item in family_room_device_qs:
|
|
|
+ if not item['sub_device']: # 查询网关、摄像头
|
|
|
+ device_qs = Device_Info.objects.filter(id=item['device_id']).values(
|
|
|
+ 'id', 'userID', 'NickName', 'UID', 'View_Account', 'View_Password',
|
|
|
+ 'ChannelIndex',
|
|
|
+ 'Type', 'isShare', 'primaryUserID', 'primaryMaster', 'data_joined',
|
|
|
+ 'vodPrimaryUserID',
|
|
|
+ 'vodPrimaryMaster', 'userID__userEmail', 'version', 'isVod',
|
|
|
+ 'isExist', 'NotificationMode',
|
|
|
+ 'isCameraOpenCloud', 'serial_number'
|
|
|
+ ).first()
|
|
|
+ if device_qs:
|
|
|
+ device_qs['sensorStatus'] = 0
|
|
|
+ if device_qs['primaryUserID'] and device_qs['id'] == device_qs['primaryUserID']:
|
|
|
+ device_qs['isPrimaryUser'] = 1
|
|
|
+ else:
|
|
|
+ device_qs['isPrimaryUser'] = 0
|
|
|
+ if 'data_joined' in device_qs:
|
|
|
+ if device_qs['data_joined']:
|
|
|
+ device_qs['data_joined'] = device_qs['data_joined'].strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ else:
|
|
|
+ device_qs['data_joined'] = ''
|
|
|
+ if device_qs['Type'] == 200:
|
|
|
+ gateways.append(device_qs)
|
|
|
+ else:
|
|
|
+ cameras.append(device_qs)
|
|
|
+ else: # 查询传感器
|
|
|
+ sub_device_qs = GatewaySubDevice.objects.filter(id=item['sub_device']).values()
|
|
|
+ if sub_device_qs.exists():
|
|
|
+ created_time = time.localtime(sub_device_qs[0]['created_time'])
|
|
|
+ created_time = time.strftime('%Y-%m-%d %H:%M:%S', created_time)
|
|
|
+ sub_device_dict = {
|
|
|
+ "id": sub_device_qs[0]['id'],
|
|
|
+ "userID": user_id,
|
|
|
+ "NickName": sub_device_qs[0]['nickname'],
|
|
|
+ "UID": "",
|
|
|
+ "View_Account": "",
|
|
|
+ "View_Password": "",
|
|
|
+ "ChannelIndex": 0,
|
|
|
+ "Type": sub_device_qs[0]['device_type'],
|
|
|
+ 'sensorStatus': sub_device_qs[0]['status'],
|
|
|
+ "isShare": False,
|
|
|
+ "primaryUserID": "",
|
|
|
+ "primaryMaster": "",
|
|
|
+ "data_joined": created_time,
|
|
|
+ "vodPrimaryUserID": "",
|
|
|
+ "vodPrimaryMaster": "",
|
|
|
+ "userID__userEmail": "",
|
|
|
+ "version": "",
|
|
|
+ "isVod": 0,
|
|
|
+ "isExist": 0,
|
|
|
+ "NotificationMode": 0,
|
|
|
+ "isCameraOpenCloud": 0,
|
|
|
+ "serial_number": sub_device_qs[0]['sensor_serial'],
|
|
|
+ "isPrimaryUser": 0,
|
|
|
+ "iot": [],
|
|
|
+ "vod": [],
|
|
|
+ "preview": [],
|
|
|
+ "platform": "",
|
|
|
+ "initString": "",
|
|
|
+ "initStringApp": "",
|
|
|
+ "uid_version": "",
|
|
|
+ "ucode": "",
|
|
|
+ "detect_interval": 0,
|
|
|
+ "detect_status": 0,
|
|
|
+ "detect_group": "",
|
|
|
+ "region_alexa": "",
|
|
|
+ "is_alexa": 0,
|
|
|
+ "deviceModel": "",
|
|
|
+ "TimeZone": "",
|
|
|
+ "TimeStatus": 0,
|
|
|
+ "SpaceUsable": "",
|
|
|
+ "SpaceSum": "",
|
|
|
+ "MirrorType": 0,
|
|
|
+ "RecordType": 0,
|
|
|
+ "OutdoorModel": 0,
|
|
|
+ "WIFIName": "",
|
|
|
+ "isDetector": 0,
|
|
|
+ "DetectorRank": 0,
|
|
|
+ "is_human": 0,
|
|
|
+ "is_custom_voice": 0,
|
|
|
+ "is_ptz": 0,
|
|
|
+ "channels": [],
|
|
|
+ "double_wifi": 0,
|
|
|
+ "is_ai": 0
|
|
|
+ }
|
|
|
+ sensors.append(sub_device_dict)
|
|
|
+
|
|
|
+ device_list = [gateways, cameras]
|
|
|
+ for item in device_list:
|
|
|
+ uid_list = []
|
|
|
+ for dvl in item:
|
|
|
+ uid_list.append(dvl['UID'])
|
|
|
+ # 设备关联套餐,设备预览图
|
|
|
+ uid_bucket_qs, uid_preview_qs = cls.get_bucket_and_preview_by_uid(uid_list)
|
|
|
+ # 设备配置信息
|
|
|
+ uid_set_dict = cls.get_uid_set_dict(uid_list)
|
|
|
+ # 设备详情信息
|
|
|
+ result = cls.get_device_details(item, uid_bucket_qs, uid_preview_qs, uid_set_dict)
|
|
|
+ if device_list.index(item) == 0:
|
|
|
+ device_dict['gateways'] = result
|
|
|
+ else:
|
|
|
+ device_dict['cameras'] = result
|
|
|
+
|
|
|
+ device_dict['sort'] = list(category_sort)
|
|
|
+ device_dict['gateways'].extend(sensors)
|
|
|
+
|
|
|
+ return response.json(0, device_dict)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, repr(e))
|