|
@@ -11,12 +11,14 @@ from django.db.models import Q
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
from Object.RedisObject import RedisObject
|
|
from Object.RedisObject import RedisObject
|
|
from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY, BASE_DIR
|
|
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
|
|
|
|
|
|
+from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidPushModel, UidChannelSetModel, \
|
|
|
|
+ Device_User
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
from Service.ModelService import ModelService
|
|
from Service.ModelService import ModelService
|
|
-import time,json
|
|
|
|
|
|
+import time, json
|
|
|
|
+
|
|
|
|
|
|
class EquipmentManagerV3(View):
|
|
class EquipmentManagerV3(View):
|
|
|
|
|
|
@@ -46,6 +48,8 @@ class EquipmentManagerV3(View):
|
|
return self.do_query(userID, request_dict, response)
|
|
return self.do_query(userID, request_dict, response)
|
|
elif operation == 'modify':
|
|
elif operation == 'modify':
|
|
return self.do_modify(userID, request_dict, response, request)
|
|
return self.do_modify(userID, request_dict, response, request)
|
|
|
|
+ elif operation == 'fuzzyQuery':
|
|
|
|
+ return self.do_fuzzy_query(userID, request_dict, response)
|
|
else:
|
|
else:
|
|
return response.json(414)
|
|
return response.json(414)
|
|
else:
|
|
else:
|
|
@@ -85,6 +89,18 @@ class EquipmentManagerV3(View):
|
|
# # 判断是否有已绑定用户
|
|
# # 判断是否有已绑定用户
|
|
# if is_bind:
|
|
# if is_bind:
|
|
# return response.json(15)
|
|
# return response.json(15)
|
|
|
|
+
|
|
|
|
+ main_exist = Device_Info.objects.filter(UID=UID, vodPrimaryUserID='', vodPrimaryMaster='')
|
|
|
|
+ pk = CommonService.getUserID(getUser=False)
|
|
|
|
+ vodPrimaryUserID = ''
|
|
|
|
+ vodPrimaryMaster = ''
|
|
|
|
+ if not main_exist:
|
|
|
|
+
|
|
|
|
+ duq = Device_User.objects.filter(userID=userID).values('username')
|
|
|
|
+ if duq.exists():
|
|
|
|
+ username = duq[0]['username']
|
|
|
|
+ vodPrimaryUserID = userID
|
|
|
|
+ vodPrimaryMaster = username
|
|
try:
|
|
try:
|
|
# 判断是否有用户绑定
|
|
# 判断是否有用户绑定
|
|
nowTime = int(time.time())
|
|
nowTime = int(time.time())
|
|
@@ -101,10 +117,11 @@ class EquipmentManagerV3(View):
|
|
UidSetModel.objects.create(**uid_set_create_dict)
|
|
UidSetModel.objects.create(**uid_set_create_dict)
|
|
else:
|
|
else:
|
|
us_qs.update(nickname=NickName)
|
|
us_qs.update(nickname=NickName)
|
|
- pk = CommonService.getUserID(getUser=False)
|
|
|
|
|
|
+
|
|
userDevice = Device_Info(id=pk, userID_id=userID, UID=UID,
|
|
userDevice = Device_Info(id=pk, userID_id=userID, UID=UID,
|
|
NickName=NickName, View_Account=View_Account,
|
|
NickName=NickName, View_Account=View_Account,
|
|
- View_Password=View_Password, Type=Type, ChannelIndex=ChannelIndex)
|
|
|
|
|
|
+ View_Password=View_Password, Type=Type, ChannelIndex=ChannelIndex,
|
|
|
|
+ vodPrimaryUserID=vodPrimaryUserID, vodPrimaryMaster=vodPrimaryMaster)
|
|
userDevice.save()
|
|
userDevice.save()
|
|
|
|
|
|
if not us_qs.exists():
|
|
if not us_qs.exists():
|
|
@@ -124,6 +141,8 @@ class EquipmentManagerV3(View):
|
|
'View_Password', 'ChannelIndex', 'Type',
|
|
'View_Password', 'ChannelIndex', 'Type',
|
|
'isShare',
|
|
'isShare',
|
|
'primaryUserID', 'primaryMaster',
|
|
'primaryUserID', 'primaryMaster',
|
|
|
|
+ 'vodPrimaryUserID', 'vodPrimaryMaster',
|
|
|
|
+ 'userID__userEmail',
|
|
'data_joined', 'version',
|
|
'data_joined', 'version',
|
|
'isVod', 'isExist')
|
|
'isVod', 'isExist')
|
|
dvql = CommonService.qs_to_list(dvqs)
|
|
dvql = CommonService.qs_to_list(dvqs)
|
|
@@ -202,7 +221,6 @@ class EquipmentManagerV3(View):
|
|
di_qs = Device_Info.objects.filter(UID=uid)
|
|
di_qs = Device_Info.objects.filter(UID=uid)
|
|
di_qs.update(NickName=nickname)
|
|
di_qs.update(NickName=nickname)
|
|
if deviceData is not None and deviceData.__contains__('NickName') and us_qs[0].is_alexa == 1:
|
|
if deviceData is not None and deviceData.__contains__('NickName') and us_qs[0].is_alexa == 1:
|
|
-
|
|
|
|
asy = threading.Thread(target=ModelService.notify_alexa_add, args=(uid, userID, nickname))
|
|
asy = threading.Thread(target=ModelService.notify_alexa_add, args=(uid, userID, nickname))
|
|
asy.start()
|
|
asy.start()
|
|
# redisObj = RedisObject(db=8)
|
|
# redisObj = RedisObject(db=8)
|
|
@@ -232,7 +250,8 @@ class EquipmentManagerV3(View):
|
|
dvqs = dvqs.filter(~Q(isExist=2))
|
|
dvqs = dvqs.filter(~Q(isExist=2))
|
|
dvql = dvqs.values('id', 'userID', 'NickName', 'UID', 'View_Account',
|
|
dvql = dvqs.values('id', 'userID', 'NickName', 'UID', 'View_Account',
|
|
'View_Password', 'ChannelIndex', 'Type', 'isShare',
|
|
'View_Password', 'ChannelIndex', 'Type', 'isShare',
|
|
- 'primaryUserID', 'primaryMaster', 'data_joined',
|
|
|
|
|
|
+ 'primaryUserID', 'primaryMaster', 'data_joined', 'vodPrimaryUserID', 'vodPrimaryMaster',
|
|
|
|
+ 'userID__userEmail',
|
|
'version', 'isVod', 'isExist', 'NotificationMode')
|
|
'version', 'isVod', 'isExist', 'NotificationMode')
|
|
dvls = CommonService.qs_to_list(dvql)
|
|
dvls = CommonService.qs_to_list(dvql)
|
|
uid_list = []
|
|
uid_list = []
|
|
@@ -278,10 +297,19 @@ class EquipmentManagerV3(View):
|
|
'DetectorRank': us['DetectorRank']
|
|
'DetectorRank': us['DetectorRank']
|
|
}
|
|
}
|
|
# 从uid_channel里面取出通道配置信息
|
|
# 从uid_channel里面取出通道配置信息
|
|
- ucs_qs = UidChannelSetModel.objects.filter(uid__id=us['id']).values()
|
|
|
|
|
|
+ ucs_qs = UidChannelSetModel.objects.filter(uid__id=us['id']).values('channel', '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 = []
|
|
channels = []
|
|
for ucs in ucs_qs:
|
|
for ucs in ucs_qs:
|
|
- channel = {
|
|
|
|
|
|
+ channels_dict = {
|
|
'channel': ucs['channel'],
|
|
'channel': ucs['channel'],
|
|
'pir_audio': ucs['pir_audio'],
|
|
'pir_audio': ucs['pir_audio'],
|
|
'mic_audio': ucs['mic_audio'],
|
|
'mic_audio': ucs['mic_audio'],
|
|
@@ -296,7 +324,7 @@ class EquipmentManagerV3(View):
|
|
'light_alarm_vol': ucs['light_alarm_vol'],
|
|
'light_alarm_vol': ucs['light_alarm_vol'],
|
|
'light_long_light': ucs['light_long_light']
|
|
'light_long_light': ucs['light_long_light']
|
|
}
|
|
}
|
|
- channels.append(channel)
|
|
|
|
|
|
+ channels.append(channels_dict)
|
|
uv_dict[us['uid']]['channels'] = channels
|
|
uv_dict[us['uid']]['channels'] = channels
|
|
|
|
|
|
for p in dvls:
|
|
for p in dvls:
|
|
@@ -375,17 +403,161 @@ class EquipmentManagerV3(View):
|
|
else:
|
|
else:
|
|
return response.json(tko.code)
|
|
return response.json(tko.code)
|
|
|
|
|
|
|
|
+ def do_fuzzy_query(self, userID, request_dict, response):
|
|
|
|
+ fuzzy = request_dict.get('fuzzy', None)
|
|
|
|
+ page = request_dict.get('page', None)
|
|
|
|
+ line = request_dict.get('line', None)
|
|
|
|
+
|
|
|
|
+ if page and line:
|
|
|
|
+ page = int(page)
|
|
|
|
+ line = int(line)
|
|
|
|
+ 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__contains=fuzzy) | Q(NickName__contains=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')
|
|
|
|
+
|
|
|
|
+ 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'],
|
|
|
|
+ '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:
|
|
|
|
+ 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:
|
|
|
|
+ return response.json(0, [])
|
|
|
|
+ else:
|
|
|
|
+ return response.json(444)
|
|
|
|
+
|
|
# 加密
|
|
# 加密
|
|
- def encrypt_pwd(self,userPwd):
|
|
|
|
|
|
+ def encrypt_pwd(self, userPwd):
|
|
for i in range(1, 4):
|
|
for i in range(1, 4):
|
|
if i == 1:
|
|
if i == 1:
|
|
- userPwd = RandomStr(3, False)+userPwd+RandomStr(3, False)
|
|
|
|
|
|
+ userPwd = RandomStr(3, False) + userPwd + RandomStr(3, False)
|
|
userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
|
|
userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
|
|
if i == 2:
|
|
if i == 2:
|
|
- userPwd = RandomStr(2, False)+str(userPwd)+RandomStr(2, False)
|
|
|
|
|
|
+ userPwd = RandomStr(2, False) + str(userPwd) + RandomStr(2, False)
|
|
userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
|
|
userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
|
|
if i == 3:
|
|
if i == 3:
|
|
- userPwd = RandomStr(1, False)+str(userPwd)+RandomStr(1, False)
|
|
|
|
|
|
+ userPwd = RandomStr(1, False) + str(userPwd) + RandomStr(1, False)
|
|
userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
|
|
userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
|
|
return userPwd
|
|
return userPwd
|
|
|
|
|
|
@@ -410,4 +582,4 @@ class EquipmentManagerV3(View):
|
|
password = password.decode('utf-8')
|
|
password = password.decode('utf-8')
|
|
# 去前3位,后3位
|
|
# 去前3位,后3位
|
|
password = password[3:-3]
|
|
password = password[3:-3]
|
|
- return password
|
|
|
|
|
|
+ return password
|