|
@@ -767,159 +767,161 @@ class EquipmentManagerV3(View):
|
|
|
page = request_dict.get('page', None)
|
|
|
line = request_dict.get('line', None)
|
|
|
|
|
|
- if page and line:
|
|
|
- page = int(page)
|
|
|
- line = int(line)
|
|
|
+ if not all([page, line]):
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ page = int(page)
|
|
|
+ line = int(line)
|
|
|
+ try:
|
|
|
device_qs = Device_Info.objects.filter(userID=userID)
|
|
|
device_qs = device_qs.filter(~Q(isExist=2))
|
|
|
- if device_qs.exists():
|
|
|
- if fuzzy:
|
|
|
- device_qs = device_qs.filter(Q(UID__icontains=fuzzy) | Q(NickName__icontains=fuzzy))
|
|
|
- device_qs = device_qs.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')
|
|
|
-
|
|
|
- dvls = CommonService.qs_to_list(device_qs)
|
|
|
- uid_list = []
|
|
|
- for dvl in dvls:
|
|
|
- uid_list.append(dvl['UID'])
|
|
|
-
|
|
|
- ubqs = UID_Bucket.objects.filter(uid__in=uid_list). \
|
|
|
- values('bucket__content', 'status', 'channel', 'endTime', 'uid')
|
|
|
- upqs = UID_Preview.objects.filter(uid__in=uid_list).order_by('channel').values('id', 'uid', 'channel')
|
|
|
- auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
- bucket = oss2.Bucket(auth, 'oss-cn-hongkong.aliyuncs.com', 'statres')
|
|
|
- nowTime = int(time.time())
|
|
|
- data = []
|
|
|
- # 设备拓展信息表
|
|
|
- us_qs = UidSetModel.objects.filter(uid__in=uid_list).values('id', 'uid', 'version', 'nickname', 'ucode',
|
|
|
- 'detect_status', 'detect_group',
|
|
|
- 'detect_interval',
|
|
|
- 'region_alexa', 'is_alexa', 'deviceModel',
|
|
|
- 'TimeZone', 'TimeStatus', 'SpaceUsable',
|
|
|
- 'SpaceSum', 'MirrorType', 'RecordType',
|
|
|
- 'OutdoorModel', 'WIFIName', 'isDetector',
|
|
|
- 'DetectorRank')
|
|
|
- uv_dict = {}
|
|
|
- for us in us_qs:
|
|
|
- uv_dict[us['uid']] = {
|
|
|
- 'version': us['version'],
|
|
|
- 'nickname': us['nickname'],
|
|
|
- 'ucode': us['ucode'],
|
|
|
- 'detect_interval': us['detect_interval'],
|
|
|
- 'detect_group': us['detect_group'],
|
|
|
- 'detect_status': us['detect_status'],
|
|
|
- 'region_alexa': us['region_alexa'],
|
|
|
- 'is_alexa': us['is_alexa'],
|
|
|
- 'deviceModel': us['deviceModel'],
|
|
|
- 'TimeZone': us['TimeZone'],
|
|
|
- 'TimeStatus': us['TimeStatus'],
|
|
|
- 'SpaceUsable': us['SpaceUsable'],
|
|
|
- 'SpaceSum': us['SpaceSum'],
|
|
|
- 'MirrorType': us['MirrorType'],
|
|
|
- 'RecordType': us['RecordType'],
|
|
|
- 'OutdoorModel': us['OutdoorModel'],
|
|
|
- 'WIFIName': us['WIFIName'],
|
|
|
- 'isDetector': us['isDetector'],
|
|
|
- 'DetectorRank': us['DetectorRank']
|
|
|
- }
|
|
|
- # 从uid_channel里面取出通道配置信息
|
|
|
- ucs_qs = UidChannelSetModel.objects.filter(uid__id=us['id']).values()
|
|
|
- channels = []
|
|
|
- for ucs in ucs_qs:
|
|
|
- channel = {
|
|
|
- 'channel': ucs['channel'],
|
|
|
- 'channel_name': ucs['channel_name'],
|
|
|
- 'pir_audio': ucs['pir_audio'],
|
|
|
- 'mic_audio': ucs['mic_audio'],
|
|
|
- 'battery_status': ucs['battery_status'],
|
|
|
- 'battery_level': ucs['battery_level'],
|
|
|
- 'sleep_status': ucs['sleep_status'],
|
|
|
- 'sleep_time': ucs['sleep_time'],
|
|
|
- 'light_night_model': ucs['light_night_model'],
|
|
|
- 'light_alarm_type': ucs['light_alarm_type'],
|
|
|
- 'light_alarm_level': ucs['light_alarm_level'],
|
|
|
- 'light_alarm_man_en': ucs['light_alarm_man_en'],
|
|
|
- 'light_alarm_vol': ucs['light_alarm_vol'],
|
|
|
- 'light_long_light': ucs['light_long_light']
|
|
|
- }
|
|
|
- channels.append(channel)
|
|
|
- uv_dict[us['uid']]['channels'] = channels
|
|
|
-
|
|
|
- for p in dvls:
|
|
|
- # 获取iot_deviceInfo表的endpoint和token_iot_number
|
|
|
- p['iot'] = []
|
|
|
- if p['serial_number']: # 存在序列号根据序列号查询
|
|
|
- iotdeviceInfo_qs = iotdeviceInfoModel.objects.filter(serial_number=p['serial_number'][0:6])
|
|
|
- else: # 根据uid查询
|
|
|
- iotdeviceInfo_qs = iotdeviceInfoModel.objects.filter(uid=p['UID'])
|
|
|
- if iotdeviceInfo_qs.exists():
|
|
|
- iotdeviceInfo = iotdeviceInfo_qs.values('endpoint', 'token_iot_number')
|
|
|
- p['iot'].append({
|
|
|
- 'endpoint': iotdeviceInfo[0]['endpoint'],
|
|
|
- 'token_iot_number': iotdeviceInfo[0]['token_iot_number']
|
|
|
- })
|
|
|
-
|
|
|
- p['vod'] = []
|
|
|
- for dm in ubqs:
|
|
|
- if p['UID'] == dm['uid']:
|
|
|
- if dm['endTime'] > nowTime:
|
|
|
- p['vod'].append(dm)
|
|
|
- p['preview'] = []
|
|
|
- for up in upqs:
|
|
|
- if p['UID'] == up['uid']:
|
|
|
- obj = 'uid_preview/{uid}/channel_{channel}.png'.format(uid=up['uid'], channel=up['channel'])
|
|
|
- img_sign = bucket.sign_url('GET', obj, 300)
|
|
|
- p['preview'].append(img_sign)
|
|
|
- p_uid = p['UID']
|
|
|
- if p_uid in uv_dict:
|
|
|
- # 设备版本号
|
|
|
- p['uid_version'] = uv_dict[p_uid]['version']
|
|
|
- p['ucode'] = uv_dict[p_uid]['ucode']
|
|
|
- p['detect_interval'] = uv_dict[p_uid]['detect_interval']
|
|
|
- p['detect_status'] = uv_dict[p_uid]['detect_status']
|
|
|
- p['detect_group'] = uv_dict[p_uid]['detect_group']
|
|
|
- p['region_alexa'] = uv_dict[p_uid]['region_alexa']
|
|
|
- p['is_alexa'] = uv_dict[p_uid]['is_alexa']
|
|
|
- p['deviceModel'] = uv_dict[p_uid]['deviceModel']
|
|
|
- p['TimeZone'] = uv_dict[p_uid]['TimeZone']
|
|
|
- p['TimeStatus'] = uv_dict[p_uid]['TimeStatus']
|
|
|
- p['SpaceUsable'] = uv_dict[p_uid]['SpaceUsable']
|
|
|
- p['SpaceSum'] = uv_dict[p_uid]['SpaceSum']
|
|
|
- p['MirrorType'] = uv_dict[p_uid]['MirrorType']
|
|
|
- p['RecordType'] = uv_dict[p_uid]['RecordType']
|
|
|
- p['OutdoorModel'] = uv_dict[p_uid]['OutdoorModel']
|
|
|
- p['WIFIName'] = uv_dict[p_uid]['WIFIName']
|
|
|
- p['isDetector'] = uv_dict[p_uid]['isDetector']
|
|
|
- p['DetectorRank'] = uv_dict[p_uid]['DetectorRank']
|
|
|
- p['channels'] = uv_dict[p_uid]['channels']
|
|
|
- # 设备昵称 调用影子信息昵称,先阶段不可
|
|
|
- if uv_dict[p_uid]['nickname']:
|
|
|
- p['NickName'] = uv_dict[p_uid]['nickname']
|
|
|
- else:
|
|
|
- # 设备版本号
|
|
|
- p['uid_version'] = ''
|
|
|
- p['ucode'] = ''
|
|
|
- data.append(p)
|
|
|
- result = data
|
|
|
- items = []
|
|
|
- # print('缓存分页')
|
|
|
- for index, item in enumerate(result):
|
|
|
- if (page - 1) * line <= index:
|
|
|
- if index < page * line:
|
|
|
- # 加密
|
|
|
- item['View_Password'] = self.encrypt_pwd(item['View_Password'])
|
|
|
- print(item)
|
|
|
- items.append(item)
|
|
|
- print(items)
|
|
|
- return response.json(0, items)
|
|
|
- else:
|
|
|
+ if not device_qs.exists():
|
|
|
return response.json(0, [])
|
|
|
- else:
|
|
|
- return response.json(444)
|
|
|
+ if fuzzy:
|
|
|
+ device_qs = device_qs.filter(Q(UID__icontains=fuzzy) | Q(NickName__icontains=fuzzy))
|
|
|
+ device_qs = device_qs.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')
|
|
|
+
|
|
|
+ dvls = CommonService.qs_to_list(device_qs)
|
|
|
+ uid_list = []
|
|
|
+ for dvl in dvls:
|
|
|
+ uid_list.append(dvl['UID'])
|
|
|
+
|
|
|
+ ubqs = UID_Bucket.objects.filter(uid__in=uid_list). \
|
|
|
+ values('bucket__content', 'status', 'channel', 'endTime', 'uid')
|
|
|
+ upqs = UID_Preview.objects.filter(uid__in=uid_list).order_by('channel').values('id', 'uid', 'channel')
|
|
|
+ auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
+ bucket = oss2.Bucket(auth, 'oss-cn-hongkong.aliyuncs.com', 'statres')
|
|
|
+ nowTime = int(time.time())
|
|
|
+ data = []
|
|
|
+ # 设备拓展信息表
|
|
|
+ us_qs = UidSetModel.objects.filter(uid__in=uid_list).values('id', 'uid', 'version', 'nickname', 'ucode',
|
|
|
+ 'detect_status', 'detect_group',
|
|
|
+ 'detect_interval',
|
|
|
+ 'region_alexa', 'is_alexa', 'deviceModel',
|
|
|
+ 'TimeZone', 'TimeStatus', 'SpaceUsable',
|
|
|
+ 'SpaceSum', 'MirrorType', 'RecordType',
|
|
|
+ 'OutdoorModel', 'WIFIName', 'isDetector',
|
|
|
+ 'DetectorRank')
|
|
|
+ uv_dict = {}
|
|
|
+ for us in us_qs:
|
|
|
+ uv_dict[us['uid']] = {
|
|
|
+ 'version': us['version'],
|
|
|
+ 'nickname': us['nickname'],
|
|
|
+ 'ucode': us['ucode'],
|
|
|
+ 'detect_interval': us['detect_interval'],
|
|
|
+ 'detect_group': us['detect_group'],
|
|
|
+ 'detect_status': us['detect_status'],
|
|
|
+ 'region_alexa': us['region_alexa'],
|
|
|
+ 'is_alexa': us['is_alexa'],
|
|
|
+ 'deviceModel': us['deviceModel'],
|
|
|
+ 'TimeZone': us['TimeZone'],
|
|
|
+ 'TimeStatus': us['TimeStatus'],
|
|
|
+ 'SpaceUsable': us['SpaceUsable'],
|
|
|
+ 'SpaceSum': us['SpaceSum'],
|
|
|
+ 'MirrorType': us['MirrorType'],
|
|
|
+ 'RecordType': us['RecordType'],
|
|
|
+ 'OutdoorModel': us['OutdoorModel'],
|
|
|
+ 'WIFIName': us['WIFIName'],
|
|
|
+ 'isDetector': us['isDetector'],
|
|
|
+ 'DetectorRank': us['DetectorRank']
|
|
|
+ }
|
|
|
+ # 从uid_channel里面取出通道配置信息
|
|
|
+ ucs_qs = UidChannelSetModel.objects.filter(uid__id=us['id']).values()
|
|
|
+ channels = []
|
|
|
+ for ucs in ucs_qs:
|
|
|
+ channel = {
|
|
|
+ 'channel': ucs['channel'],
|
|
|
+ 'channel_name': ucs['channel_name'],
|
|
|
+ 'pir_audio': ucs['pir_audio'],
|
|
|
+ 'mic_audio': ucs['mic_audio'],
|
|
|
+ 'battery_status': ucs['battery_status'],
|
|
|
+ 'battery_level': ucs['battery_level'],
|
|
|
+ 'sleep_status': ucs['sleep_status'],
|
|
|
+ 'sleep_time': ucs['sleep_time'],
|
|
|
+ 'light_night_model': ucs['light_night_model'],
|
|
|
+ 'light_alarm_type': ucs['light_alarm_type'],
|
|
|
+ 'light_alarm_level': ucs['light_alarm_level'],
|
|
|
+ 'light_alarm_man_en': ucs['light_alarm_man_en'],
|
|
|
+ 'light_alarm_vol': ucs['light_alarm_vol'],
|
|
|
+ 'light_long_light': ucs['light_long_light']
|
|
|
+ }
|
|
|
+ channels.append(channel)
|
|
|
+ uv_dict[us['uid']]['channels'] = channels
|
|
|
+
|
|
|
+ for p in dvls:
|
|
|
+ # 获取iot_deviceInfo表的endpoint和token_iot_number
|
|
|
+ p['iot'] = []
|
|
|
+ if p['serial_number']: # 存在序列号根据序列号查询
|
|
|
+ # 摄像头设备返回完整序列号
|
|
|
+ if p['UID'] != p['serial_number']:
|
|
|
+ p['serial_number'] = CommonService.get_full_serial_number(p['UID'], p['serial_number'],
|
|
|
+ p['Type'])
|
|
|
+ iotdeviceInfo_qs = iotdeviceInfoModel.objects.filter(serial_number=p['serial_number'][0:6])
|
|
|
+ else: # 根据uid查询
|
|
|
+ iotdeviceInfo_qs = iotdeviceInfoModel.objects.filter(uid=p['UID'])
|
|
|
+ if iotdeviceInfo_qs.exists():
|
|
|
+ iotdeviceInfo = iotdeviceInfo_qs.values('endpoint', 'token_iot_number')
|
|
|
+ p['iot'].append({
|
|
|
+ 'endpoint': iotdeviceInfo[0]['endpoint'],
|
|
|
+ 'token_iot_number': iotdeviceInfo[0]['token_iot_number']
|
|
|
+ })
|
|
|
+
|
|
|
+ p['vod'] = []
|
|
|
+ for dm in ubqs:
|
|
|
+ if p['UID'] == dm['uid']:
|
|
|
+ if dm['endTime'] > nowTime:
|
|
|
+ p['vod'].append(dm)
|
|
|
+ p['preview'] = []
|
|
|
+ for up in upqs:
|
|
|
+ if p['UID'] == up['uid']:
|
|
|
+ obj = 'uid_preview/{uid}/channel_{channel}.png'.format(uid=up['uid'], channel=up['channel'])
|
|
|
+ img_sign = bucket.sign_url('GET', obj, 300)
|
|
|
+ p['preview'].append(img_sign)
|
|
|
+ p_uid = p['UID']
|
|
|
+ if p_uid in uv_dict:
|
|
|
+ # 设备版本号
|
|
|
+ p['uid_version'] = uv_dict[p_uid]['version']
|
|
|
+ p['ucode'] = uv_dict[p_uid]['ucode']
|
|
|
+ p['detect_interval'] = uv_dict[p_uid]['detect_interval']
|
|
|
+ p['detect_status'] = uv_dict[p_uid]['detect_status']
|
|
|
+ p['detect_group'] = uv_dict[p_uid]['detect_group']
|
|
|
+ p['region_alexa'] = uv_dict[p_uid]['region_alexa']
|
|
|
+ p['is_alexa'] = uv_dict[p_uid]['is_alexa']
|
|
|
+ p['deviceModel'] = uv_dict[p_uid]['deviceModel']
|
|
|
+ p['TimeZone'] = uv_dict[p_uid]['TimeZone']
|
|
|
+ p['TimeStatus'] = uv_dict[p_uid]['TimeStatus']
|
|
|
+ p['SpaceUsable'] = uv_dict[p_uid]['SpaceUsable']
|
|
|
+ p['SpaceSum'] = uv_dict[p_uid]['SpaceSum']
|
|
|
+ p['MirrorType'] = uv_dict[p_uid]['MirrorType']
|
|
|
+ p['RecordType'] = uv_dict[p_uid]['RecordType']
|
|
|
+ p['OutdoorModel'] = uv_dict[p_uid]['OutdoorModel']
|
|
|
+ p['WIFIName'] = uv_dict[p_uid]['WIFIName']
|
|
|
+ p['isDetector'] = uv_dict[p_uid]['isDetector']
|
|
|
+ p['DetectorRank'] = uv_dict[p_uid]['DetectorRank']
|
|
|
+ p['channels'] = uv_dict[p_uid]['channels']
|
|
|
+ # 设备昵称 调用影子信息昵称,先阶段不可
|
|
|
+ if uv_dict[p_uid]['nickname']:
|
|
|
+ p['NickName'] = uv_dict[p_uid]['nickname']
|
|
|
+ else:
|
|
|
+ # 设备版本号
|
|
|
+ p['uid_version'] = ''
|
|
|
+ p['ucode'] = ''
|
|
|
+ data.append(p)
|
|
|
+ items = []
|
|
|
+ for index, item in enumerate(data):
|
|
|
+ if (page - 1) * line <= index:
|
|
|
+ if index < page * line:
|
|
|
+ # 加密
|
|
|
+ item['View_Password'] = self.encrypt_pwd(item['View_Password'])
|
|
|
+ items.append(item)
|
|
|
+ return response.json(0, items)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_ine:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
# 加密
|
|
|
def encrypt_pwd(self, userPwd):
|