|
@@ -16,12 +16,14 @@ from Controller.CheckUserData import RandomStr
|
|
|
from Controller.DeviceConfirmRegion import Device_Region
|
|
|
from Controller.SensorGateway.EquipmentFamilyController import EquipmentFamilyView
|
|
|
from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidChannelSetModel, \
|
|
|
- Device_User, iotdeviceInfoModel, UIDCompanySerialModel, UIDModel, UnicomDeviceInfo, CountryModel
|
|
|
+ Device_User, iotdeviceInfoModel, UIDCompanySerialModel, UnicomDeviceInfo, CountryModel, \
|
|
|
+ DeviceCloudPhotoInfo
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
|
from Service.ModelService import ModelService
|
|
|
+from Service.UserDeviceService import UserDeviceService
|
|
|
|
|
|
LOGGER = logging.getLogger('info')
|
|
|
|
|
@@ -606,15 +608,19 @@ class EquipmentManagerV3(View):
|
|
|
UidChannelSetModel.objects.filter(uid__uid=uid).update(channel_name=channel_name)
|
|
|
return response.json(0)
|
|
|
|
|
|
- # 新查询设备字段
|
|
|
def do_query(self, userID, request_dict, response):
|
|
|
+ """
|
|
|
+ 首页查询设备列表
|
|
|
+ @param userID: 用户id
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @param response: 响应结果
|
|
|
+ """
|
|
|
token = request_dict.get('token', None)
|
|
|
page = request_dict.get('page', None)
|
|
|
line = request_dict.get('line', None)
|
|
|
NickName = request_dict.get('NickName', None)
|
|
|
if not token or not page or not line:
|
|
|
return response.json(444)
|
|
|
-
|
|
|
page = int(page)
|
|
|
line = int(line)
|
|
|
uid = request_dict.get('uid', None)
|
|
@@ -625,116 +631,21 @@ class EquipmentManagerV3(View):
|
|
|
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))
|
|
|
- if NickName:
|
|
|
- dvqs = dvqs.filter(NickName=NickName)
|
|
|
- if uid:
|
|
|
- dvqs = dvqs.filter(UID=uid)
|
|
|
- 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')[(page - 1) * line:page * line]
|
|
|
- dvls = CommonService.qs_to_list(dvql)
|
|
|
- uid_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'])
|
|
|
-
|
|
|
- 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')
|
|
|
+ # 查询设备列表以及设备uid集合
|
|
|
+ dv_list, uid_list = UserDeviceService.query_device_list(userID, uid, NickName, page, line)
|
|
|
+ ub_qs = UserDeviceService.query_device_uid_bucket(uid_list) # 根据uid集合查询云存套餐
|
|
|
+ up_qs = UserDeviceService.query_device_preview(uid_list) # 根据uid集合查询设备预览图
|
|
|
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', 'isSupportFourPoint',
|
|
|
- 'region_alexa', 'is_alexa', 'deviceModel',
|
|
|
- 'TimeZone', 'TimeStatus', 'SpaceUsable',
|
|
|
- 'SpaceSum', 'MirrorType', 'RecordType',
|
|
|
- 'OutdoorModel', 'WIFIName', 'isDetector',
|
|
|
- 'DetectorRank', 'is_human', 'is_custom_voice',
|
|
|
- 'is_ptz', 'double_wifi', 'is_ai', 'mobile_4g',
|
|
|
- 'ai_type')
|
|
|
- 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'],
|
|
|
- 'is_ptz': us['is_ptz'],
|
|
|
- 'double_wifi': us['double_wifi'],
|
|
|
- 'mobile4G': us['mobile_4g'],
|
|
|
- 'is_ai': us['is_ai'],
|
|
|
- 'ai_type': us['ai_type'],
|
|
|
- 'isSupportFourPoint': us['isSupportFourPoint'],
|
|
|
- }
|
|
|
- # 从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:
|
|
|
+ uv_dict = UserDeviceService.query_device_channel(uid_list) # 查询设备uid通道配置属性
|
|
|
+ # 遍历设备列表,查询设备关联数据详情
|
|
|
+ for p in dv_list:
|
|
|
p['UID'] = p['UID'].replace('\n', '').replace('\r', '')
|
|
|
p_uid = p['UID'].upper()
|
|
|
- if p['serial_number']:
|
|
|
- u_device_info_qs = UnicomDeviceInfo.objects.filter(serial_no=p['serial_number'])
|
|
|
- if u_device_info_qs.exists():
|
|
|
- p['iccid'] = u_device_info_qs.first().iccid
|
|
|
-
|
|
|
+ UserDeviceService.get_sim_by_serial_number(p) # 获取SIM卡属性
|
|
|
+ p['cloudPhoto'] = self.get_cloud_photo_status(p['UID'])
|
|
|
# 获取iot_deviceInfo表的endpoint和token_iot_number
|
|
|
p['iot'] = []
|
|
|
if p['serial_number']: # 存在序列号根据序列号查询
|
|
@@ -749,60 +660,21 @@ class EquipmentManagerV3(View):
|
|
|
})
|
|
|
|
|
|
p['vod'] = []
|
|
|
- for dm in ubqs:
|
|
|
+ for dm in ub_qs:
|
|
|
if p_uid == dm['uid']:
|
|
|
if dm['endTime'] > nowTime:
|
|
|
p['vod'].append(dm)
|
|
|
p['preview'] = []
|
|
|
- for up in upqs:
|
|
|
+ for up in up_qs:
|
|
|
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)
|
|
|
-
|
|
|
- # 返回设备初始化字符
|
|
|
- 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']
|
|
|
+ UserDeviceService.get_uid_info(p, p_uid) # 获取uid初始化信息
|
|
|
|
|
|
if p_uid in uv_dict:
|
|
|
- # 设备版本号
|
|
|
- uidversion = uv_dict[p_uid]['version']
|
|
|
- if len(uidversion) > 6:
|
|
|
- uidversion = uidversion[0: uidversion.rfind('.')]
|
|
|
- p['uid_version'] = uidversion
|
|
|
- p['ucode'] = '72V201233AA' if uv_dict[p_uid]['mobile4G'] == 1 else 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['is_ptz'] = uv_dict[p_uid]['is_ptz']
|
|
|
- p['channels'] = uv_dict[p_uid]['channels']
|
|
|
- p['double_wifi'] = uv_dict[p_uid]['double_wifi']
|
|
|
- p['mobile4G'] = uv_dict[p_uid]['mobile4G']
|
|
|
- p['isCameraOpenCloud'] = 0 if uv_dict[p_uid]['mobile4G'] == 1 else p['isCameraOpenCloud']
|
|
|
- p['is_ai'] = uv_dict[p_uid]['is_ai']
|
|
|
- p['ai_type'] = uv_dict[p_uid]['ai_type']
|
|
|
- p['isSupportFourPoint'] = uv_dict[p_uid]['isSupportFourPoint']
|
|
|
- # 设备昵称 调用影子信息昵称,先阶段不可
|
|
|
- if uv_dict[p_uid]['nickname']:
|
|
|
- p['NickName'] = uv_dict[p_uid]['nickname']
|
|
|
+ # 获取设备信息DTO
|
|
|
+ UserDeviceService.get_device_info_dto(p, p_uid, uv_dict)
|
|
|
else:
|
|
|
# 设备版本号
|
|
|
p['uid_version'] = ''
|
|
@@ -812,6 +684,18 @@ class EquipmentManagerV3(View):
|
|
|
result = data
|
|
|
return response.json(0, result)
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def get_cloud_photo_status(uid):
|
|
|
+ """
|
|
|
+ 根据UID获取云相册开关状态
|
|
|
+ @param uid: 设备uid
|
|
|
+ @return: 0 or 1
|
|
|
+ """
|
|
|
+ cloud_photo_qs = DeviceCloudPhotoInfo.objects.filter(uid=uid).values('status')
|
|
|
+ if not cloud_photo_qs.exists():
|
|
|
+ return 0
|
|
|
+ return cloud_photo_qs[0]['status']
|
|
|
+
|
|
|
def do_fuzzy_query(self, userID, request_dict, response):
|
|
|
fuzzy = request_dict.get('fuzzy', None)
|
|
|
page = request_dict.get('page', None)
|