Bläddra i källkod

新增PC无登录获取主用户信息,及添加主用户修复

chenshibin 4 år sedan
förälder
incheckning
94700c66af
2 ändrade filer med 331 tillägg och 241 borttagningar
  1. 82 33
      Controller/EquipmentManager.py
  2. 249 208
      Controller/EquipmentManagerV3.py

+ 82 - 33
Controller/EquipmentManager.py

@@ -392,45 +392,31 @@ def addInterface(request):
                 pass
 
                 pk = CommonService.getUserID(getUser=False)
-
-
-
                 userName = Device_User.objects.get(userID=userID).username
                 main_exist = Device_Info.objects.filter(UID=UID)
                 main_exist = main_exist.filter(~Q(vodPrimaryUserID='')).values('vodPrimaryUserID', 'vodPrimaryMaster')
+
                 vodPrimaryUserID = userID
                 vodPrimaryMaster = userName
+                primaryUserID = ''
+                primaryMaster = ''
+                isShare = False
+
+                is_bind = Device_Info.objects.filter(UID=UID, isShare=False).values('userID__userID', 'primaryUserID', 'primaryMaster')
+
                 if main_exist.exists():
                     vodPrimaryUserID = main_exist[0]['vodPrimaryUserID']
                     vodPrimaryMaster = main_exist[0]['vodPrimaryMaster']
 
-                is_bind = Device_Info.objects.filter(UID=UID, isShare=False).values('userID__userID', 'vodPrimaryUserID')
-                # 判断是否有已绑定用户
-                isvodPrimaryUserID = ''
-                for forbind in is_bind:
-                    if forbind['vodPrimaryUserID'] != '':
-                        isvodPrimaryUserID = forbind['vodPrimaryUserID']
-
-                if isCheckMainUser != '1':
-                    if main_exist.exists():
-                        vodPrimaryUserID = main_exist[0]['vodPrimaryUserID']
-                        vodPrimaryMaster = main_exist[0]['vodPrimaryMaster']
-                    else:
-                        vodPrimaryUserID = ''
-                        vodPrimaryMaster = ''
+                if is_bind.exists():
+                    primaryUserID = is_bind[0]['primaryUserID']
+                    primaryMaster = is_bind[0]['primaryMaster']
+                    isShare = True
 
                 isusermain = False
-                if is_bind and isvodPrimaryUserID != userID and isvodPrimaryUserID != '':
+                if (vodPrimaryUserID != userID and vodPrimaryUserID != '') or (primaryUserID != userID and primaryUserID != ''):
                     isusermain = True
 
-                # uid_main_exist = UIDMainUser.objects.filter(UID=UID).values('UID', 'user_id')
-                # if uid_main_exist.exists():
-                #     vodPrimaryUserID = uid_main_exist[0]['user_id']
-                #     vodPrimaryMaster = Device_User.objects.get(userID=vodPrimaryUserID).username
-                #
-                #     if vodPrimaryUserID != userID:
-                #         isusermain = True
-
                 # 判断是否有已绑定用户
                 if isCheckMainUser == '1' and isusermain:
                     res = {
@@ -442,9 +428,9 @@ def addInterface(request):
                         'View_Password': View_Password,
                         'ChannelIndex': ChannelIndex,
                         'Type': Type,
-                        'isShare': False,
-                        'primaryUserID': '',
-                        'primaryMaster': '',
+                        'isShare': isShare,
+                        'primaryUserID': primaryUserID,
+                        'primaryMaster': primaryMaster,
                         'vodPrimaryUserID': vodPrimaryUserID,
                         'vodPrimaryMaster': vodPrimaryMaster,
                         'data_joined': '',
@@ -812,10 +798,8 @@ def deleteInterface(request):
                         redisObj.del_data(key=ykey)
                 else:
                     up_qs.delete()
-                # b.分享获得用户假删除
-                ud_dv_qs = Device_Info.objects.filter(UID=uid, isShare=True, primaryUserID=userID)
-                if ud_dv_qs.exists():
-                    ud_dv_qs.update(isExist=0)
+                # b.删除次用户设备
+                Device_Info.objects.filter(UID=uid, isShare=True, primaryUserID=userID).delete()
                 # 异步删除推送消息
             asy = threading.Thread(target=ModelService.del_eq_info, args=(userID, uid))
             asy.start()
@@ -830,6 +814,71 @@ def deleteInterface(request):
     else:
         return response.json(0)
 
+# 批量删除设备
+def batchDeleteInterface(request):
+    '''
+    批量删除用户设备
+    :param request: token,ids
+    :return:
+    '''
+    response = ResponseObject()
+    request.encoding = 'utf-8'
+    if request.method == 'POST':
+        request_dict = request.POST
+    elif request.method == 'GET':
+        request_dict = request.GET
+    else:
+        return response.json(444)
+    token = request_dict.get('token', None)
+    ids = request_dict.get('ids', None)
+    if not ids:
+        return response.json(444, 'ids')
+    tko = TokenObject(token)
+    response.lang = tko.lang
+    if tko.code != 0:
+        return response.json(tko.code)
+    userID = tko.userID
+    # userID = request_dict.get('userID', None)   # 调试
+    # 主用户删除设备全部删除
+    if not userID:
+        return response.json(309)
+    try:
+        deviceInfo_qs = Device_Info.objects.filter(userID_id=userID, id__in=ids.split(','))
+        if not deviceInfo_qs.exists():
+            return response.json(14)
+        for deviceInfo in deviceInfo_qs:
+            uid = deviceInfo.UID
+            asy = threading.Thread(target=ModelService.delete_log,
+                                   args=(CommonService.get_ip_address(request), userID, 'deleteV2', uid))
+            asy.start()
+            if userID == deviceInfo.vodPrimaryUserID:
+                Device_Info.objects.filter(UID=uid).update(vodPrimaryUserID='', vodPrimaryMaster='')
+
+            deviceInfo.delete()
+            if not deviceInfo.isShare:
+                # a.主用户删除设备
+                # 删除设备影子信息uid_set   外键关联删除设备推送配置信息 uid_push
+                up_qs = UidPushModel.objects.filter(uid_set__uid=uid)
+                DetectControllerView().do_delete_redis(uid)
+                if up_qs.count() > 1:
+                    UidPushModel.objects.filter(uid_set__uid=uid, userID_id=userID).delete()
+                    redisObj = RedisObject(db=6, SERVER_HOST='push.dvema.com')
+                    ykey = '{uid}_redis_qs'.format(uid=uid)
+                    if ykey:
+                        redisObj.del_data(key=ykey)
+                else:
+                    up_qs.delete()
+                # b.删除次用户设备
+                Device_Info.objects.filter(UID=uid, isShare=True, primaryUserID=userID).delete()
+                    # 异步删除推送消息
+            asy = threading.Thread(target=ModelService.del_eq_info, args=(userID, uid))
+            asy.start()
+    except Exception as e:
+        errorInfo = traceback.format_exc()
+        print('删除数据库记录错误: %s' % errorInfo)
+        return response.json(176, repr(e))
+    else:
+        return response.json(0)
 
 # 新查询设备字段
 def queryInterface(request):

+ 249 - 208
Controller/EquipmentManagerV3.py

@@ -9,12 +9,11 @@ from Controller.CheckUserData import RandomStr
 import oss2, base64
 from django.db.models import Q
 from django.views.generic.base import View
-
 from Controller.DeviceConfirmRegion import Device_Region
 from Object.RedisObject import RedisObject
 from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY, BASE_DIR
 from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidPushModel, UidChannelSetModel, \
-    Device_User, iotdeviceInfoModel, UIDCompanySerialModel, UIDMainUser
+    Device_User, iotdeviceInfoModel, UIDCompanySerialModel, UIDMainUser, UIDModel
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Service.CommonService import CommonService
@@ -39,6 +38,10 @@ class EquipmentManagerV3(View):
         response = ResponseObject()
         token = request_dict.get('token', None)
         # 设备主键uid
+
+        if operation == 'notLoginMainUserDevice':
+            return self.not_login_do_mainUserDevice(request_dict, response)
+
         tko = TokenObject(token)
         if tko.code != 0:
             return response.json(tko.code)
@@ -74,7 +77,7 @@ class EquipmentManagerV3(View):
         ChannelIndex = request_dict.get('ChannelIndex', None)
         version = request_dict.get('version', '')
         isCheckMainUser = request_dict.get('isCheckMainUser', None)
-        isMainUserExists = False
+
         if not all([UID, NickName, View_Account, Type, ChannelIndex]):  # Type和ChannelIndex可能为0
             return response.json(444, {'param': 'UID, NickName, View_Account, Type, ChannelIndex'})
 
@@ -97,29 +100,28 @@ class EquipmentManagerV3(View):
         userName = Device_User.objects.get(userID=userID).username
         main_exist = Device_Info.objects.filter(UID=UID)
         main_exist = main_exist.filter(~Q(vodPrimaryUserID='')).values('vodPrimaryUserID', 'vodPrimaryMaster')
+
         vodPrimaryUserID = userID
         vodPrimaryMaster = userName
+        primaryUserID = ''
+        primaryMaster = ''
+        isShare = False
+
+        is_bind = Device_Info.objects.filter(UID=UID, isShare=False).values('userID__userID', 'primaryUserID', 'primaryMaster')
+
         if main_exist.exists():
             vodPrimaryUserID = main_exist[0]['vodPrimaryUserID']
             vodPrimaryMaster = main_exist[0]['vodPrimaryMaster']
 
-        is_bind = Device_Info.objects.filter(UID=UID, isShare=False).values('userID__userID', 'vodPrimaryUserID')
-        isvodPrimaryUserID = ''
 
-        for forbind in is_bind:
-            if forbind['vodPrimaryUserID'] != '':
-                isvodPrimaryUserID = forbind['vodPrimaryUserID']
+        if is_bind.exists():
+            primaryUserID = is_bind[0]['primaryUserID']
+            primaryMaster = is_bind[0]['primaryMaster']
+            isShare = True
 
-        if isCheckMainUser != '1' :
-            if main_exist.exists():
-                vodPrimaryUserID = main_exist[0]['vodPrimaryUserID']
-                vodPrimaryMaster = main_exist[0]['vodPrimaryMaster']
-            else:
-                vodPrimaryUserID = ''
-                vodPrimaryMaster = ''
 
         isusermain = False
-        if is_bind and isvodPrimaryUserID != userID and isvodPrimaryUserID != '':
+        if (vodPrimaryUserID != userID and vodPrimaryUserID != '') or (primaryUserID != userID and primaryUserID != ''):
             isusermain = True
 
         # 判断是否有已绑定用户
@@ -133,9 +135,9 @@ class EquipmentManagerV3(View):
                 'View_Password': View_Password,
                 'ChannelIndex': ChannelIndex,
                 'Type': Type,
-                'isShare': False,
-                'primaryUserID': '',
-                'primaryMaster': '',
+                'isShare': isShare,
+                'primaryUserID': primaryUserID,
+                'primaryMaster': primaryMaster,
                 'vodPrimaryUserID': vodPrimaryUserID,
                 'vodPrimaryMaster': vodPrimaryMaster,
                 'data_joined': '',
@@ -339,194 +341,199 @@ class EquipmentManagerV3(View):
         response.lang = tko.lang
         if page <= 0:
             return response.json(0)
-        if tko.code == 0:
-            userID = tko.userID
-            dvqs = Device_Info.objects.filter(userID_id=userID)
-            # # 过滤已重置的设备
-            dvqs = dvqs.filter(~Q(isExist=2))
-            dvql = dvqs.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(dvql)
-            uid_list = []
-            serial_number_list = []
-            for dvl in dvls:
-                if dvl['primaryUserID'] and dvl['id'] == dvl['primaryUserID']:
-                    dvl['isPrimaryUser'] = 1
-                else:
-                    dvl['isPrimaryUser'] = 0
-                uid_list.append(dvl['UID'])
-                serial_number_list.append(dvl['serial_number'][0:6])
-
-            # 新增获取IOT证书内容
-            iotqs = iotdeviceInfoModel.objects.filter(serial_number__in=serial_number_list)
-
-            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', 'is_human', 'is_custom_voice')
-            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'],
-                    'is_human': us['is_human'],
-                    'is_custom_voice': us['is_custom_voice']
+        if tko.code != 0:
+            return response.json(tko.code)
+        userID = tko.userID
+        dvqs = Device_Info.objects.filter(userID_id=userID)
+        # # 过滤已重置的设备
+        dvqs = dvqs.filter(~Q(isExist=2))
+        dvql = dvqs.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(dvql)
+        uid_list = []
+        serial_number_list = []
+        for dvl in dvls:
+            if dvl['primaryUserID'] and dvl['id'] == dvl['primaryUserID']:
+                dvl['isPrimaryUser'] = 1
+            else:
+                dvl['isPrimaryUser'] = 0
+            uid_list.append(dvl['UID'])
+            serial_number_list.append(dvl['serial_number'][0:6])
+
+        # 新增获取IOT证书内容
+        iotqs = iotdeviceInfoModel.objects.filter(serial_number__in=serial_number_list)
+
+        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', 'is_human', 'is_custom_voice')
+        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'],
+                'is_human': us['is_human'],
+                'is_custom_voice': us['is_custom_voice']
+            }
+            # 从uid_channel里面取出通道配置信息
+            ucs_qs = UidChannelSetModel.objects.filter(uid__id=us['id']).values('channel', 'channel_name',
+                                                                                'pir_audio', 'mic_audio',
+                                                                                'battery_status', 'battery_level',
+                                                                                'sleep_status', 'sleep_time',
+                                                                                'light_night_model',
+                                                                                'light_alarm_type',
+                                                                                'light_alarm_level',
+                                                                                'light_alarm_man_en',
+                                                                                'light_alarm_vol',
+                                                                                'light_long_light'
+                                                                                )
+            channels = []
+            for ucs in ucs_qs:
+                channels_dict = {
+                    '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']
                 }
-                # 从uid_channel里面取出通道配置信息
-                ucs_qs = UidChannelSetModel.objects.filter(uid__id=us['id']).values('channel', 'channel_name',
-                                                                                    'pir_audio', 'mic_audio',
-                                                                                    'battery_status', 'battery_level',
-                                                                                    'sleep_status', 'sleep_time',
-                                                                                    'light_night_model',
-                                                                                    'light_alarm_type',
-                                                                                    'light_alarm_level',
-                                                                                    'light_alarm_man_en',
-                                                                                    'light_alarm_vol',
-                                                                                    'light_long_light'
-                                                                                    )
-                channels = []
-                for ucs in ucs_qs:
-                    channels_dict = {
-                        '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(channels_dict)
-                uv_dict[us['uid']]['channels'] = channels
-
-            for p in dvls:
-                # 新增IOT
-                p['iot'] = []
-                for iot in iotqs:
-                    if p['serial_number'][0:6] == iot.serial_number:
-                        p['iot'].append(
-                            {
-                                'endpoint': iot.endpoint,
-                                'token_iot_number': iot.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['is_human'] = uv_dict[p_uid]['is_human']
-                    p['is_custom_voice'] = uv_dict[p_uid]['is_custom_voice']
-                    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
-
-            if NickName:
-                # print('NickName搜索缓存')
-                data = []
-                for index, item in enumerate(result):
-                    if NickName == item['NickName']:
-                        # 加密
-                        item['View_Password'] = self.encrypt_pwd(item['View_Password'])
-                        data.append(item)
-                        return response.json(0, data)
-            if uid:
-                # print('uid搜索缓存')
-                data = []
-                for index, item in enumerate(result):
-                    if uid == item['UID']:
-                        # 加密
-                        item['View_Password'] = self.encrypt_pwd(item['View_Password'])
-                        data.append(item)
-                        return response.json(0, data)
-            items = []
-            # print('缓存分页')
+                channels.append(channels_dict)
+            uv_dict[us['uid']]['channels'] = channels
+
+        for p in dvls:
+            # 新增IOT
+            p['iot'] = []
+            for iot in iotqs:
+                if p['serial_number'][0:6] == iot.serial_number:
+                    p['iot'].append(
+                        {
+                            'endpoint': iot.endpoint,
+                            'token_iot_number': iot.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']
+
+            # 返回设备初始化字符
+            uid_qs = UIDModel.objects.filter(uid=p_uid).values('platform', 'init_string', 'init_string_app')
+            if uid_qs.exists():
+                p['platform'] = uid_qs[0]['platform']
+                p['initString'] = uid_qs[0]['init_string']
+                p['initStringApp'] = uid_qs[0]['init_string_app']
+
+            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['is_human'] = uv_dict[p_uid]['is_human']
+                p['is_custom_voice'] = uv_dict[p_uid]['is_custom_voice']
+                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
+
+        if NickName:
+            # print('NickName搜索缓存')
+            data = []
             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:
-            return response.json(tko.code)
+                if NickName == item['NickName']:
+                    # 加密
+                    item['View_Password'] = self.encrypt_pwd(item['View_Password'])
+                    data.append(item)
+                    return response.json(0, data)
+        if uid:
+            # print('uid搜索缓存')
+            data = []
+            for index, item in enumerate(result):
+                if uid == item['UID']:
+                    # 加密
+                    item['View_Password'] = self.encrypt_pwd(item['View_Password'])
+                    data.append(item)
+                    return response.json(0, 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)
 
     def do_fuzzy_query(self, userID, request_dict, response):
         fuzzy = request_dict.get('fuzzy', None)
@@ -740,15 +747,16 @@ class EquipmentManagerV3(View):
             phone = qs[0]['phone']
             username = qs[0]['username']
             qs = CommonService.qs_to_list(qs)
-            if NickName == '':
+            if NickName =='':
                 qs[0]['NickName'] = username
 
-            # if userEmail == '':
+            # if userEmail =='':
             #     qs[0]['userEmail'] = NickName
 
-            if phone == '':
+            if phone =='':
                 qs[0]['phone'] = NickName
 
+
         # if not qs:
         #     uidq = UIDMainUser.objects.filter(UID=UID).values('user_id')
         #     if uidq.exists():
@@ -757,6 +765,39 @@ class EquipmentManagerV3(View):
 
         return response.json(0, qs)
 
+    def not_login_do_mainUserDevice(self, request_dict, response):
+        UID = request_dict.get('UID')
+        token = request_dict.get('token', None)
+        time_stamp = request_dict.get('time_stamp', None)
+
+        if not all([token, time_stamp]):
+            return response.json(444)
+
+        token = int(CommonService.decode_data(token))
+        time_stamp = int(time_stamp)
+
+        now_time = int(time.time())
+        distance = now_time - time_stamp
+
+        if token != time_stamp or distance > 60000 or distance < -60000:  # 为了全球化时间控制在一天内
+            return response.json(404)
+
+        dvq = Device_Info.objects.filter(UID=UID)
+        dvq = dvq.filter(~Q(vodPrimaryUserID='')).values('vodPrimaryUserID')
+        qs = {}
+        if dvq.exists():
+            qs = Device_User.objects.filter(userID=dvq[0]['vodPrimaryUserID']).values('userID', 'NickName', 'username',
+                                                                                      'userEmail', 'phone')
+            NickName = qs[0]['username']
+            phone = qs[0]['phone']
+            username = qs[0]['username']
+            qs = CommonService.qs_to_list(qs)
+            if NickName =='':
+                qs[0]['NickName'] = username
+            if phone =='':
+                qs[0]['phone'] = NickName
+        return response.json(0, qs)
+
     def do_get_device_features(self, request_dict, response):
         uid = request_dict.get('uid', None)