|
@@ -1,24 +1,23 @@
|
|
|
|
+import json
|
|
import re
|
|
import re
|
|
import threading
|
|
import threading
|
|
import time
|
|
import time
|
|
-import traceback
|
|
|
|
|
|
|
|
|
|
+import base64
|
|
|
|
+import oss2
|
|
import requests
|
|
import requests
|
|
-
|
|
|
|
-from Controller.CheckUserData import RandomStr
|
|
|
|
-import oss2, base64
|
|
|
|
from django.db.models import Q
|
|
from django.db.models import Q
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
|
|
+
|
|
|
|
+from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY
|
|
|
|
+from Controller.CheckUserData import RandomStr
|
|
from Controller.DeviceConfirmRegion import Device_Region
|
|
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, UIDModel
|
|
|
|
|
|
+from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidChannelSetModel, \
|
|
|
|
+ Device_User, iotdeviceInfoModel, UIDCompanySerialModel, UIDModel, UnicomDeviceInfo
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
class EquipmentManagerV3(View):
|
|
class EquipmentManagerV3(View):
|
|
@@ -61,7 +60,7 @@ class EquipmentManagerV3(View):
|
|
elif operation == 'fuzzyQuery':
|
|
elif operation == 'fuzzyQuery':
|
|
return self.do_fuzzy_query(userID, request_dict, response)
|
|
return self.do_fuzzy_query(userID, request_dict, response)
|
|
elif operation == 'mainUserDevice':
|
|
elif operation == 'mainUserDevice':
|
|
- return self.do_mainUserDevice( request_dict, response)
|
|
|
|
|
|
+ return self.do_mainUserDevice(request_dict, response)
|
|
elif operation == 'getDeviceFeatures':
|
|
elif operation == 'getDeviceFeatures':
|
|
return self.do_get_device_features(request_dict, response)
|
|
return self.do_get_device_features(request_dict, response)
|
|
else:
|
|
else:
|
|
@@ -111,19 +110,18 @@ class EquipmentManagerV3(View):
|
|
primaryMaster = ''
|
|
primaryMaster = ''
|
|
isShare = False
|
|
isShare = False
|
|
|
|
|
|
- is_bind = Device_Info.objects.filter(UID=UID, isShare=False).values('userID__userID', 'primaryUserID', 'primaryMaster')
|
|
|
|
|
|
+ is_bind = Device_Info.objects.filter(UID=UID, isShare=False).values('userID__userID', 'primaryUserID',
|
|
|
|
+ 'primaryMaster')
|
|
|
|
|
|
if main_exist.exists():
|
|
if main_exist.exists():
|
|
vodPrimaryUserID = main_exist[0]['vodPrimaryUserID']
|
|
vodPrimaryUserID = main_exist[0]['vodPrimaryUserID']
|
|
vodPrimaryMaster = main_exist[0]['vodPrimaryMaster']
|
|
vodPrimaryMaster = main_exist[0]['vodPrimaryMaster']
|
|
|
|
|
|
-
|
|
|
|
if is_bind.exists():
|
|
if is_bind.exists():
|
|
primaryUserID = is_bind[0]['primaryUserID']
|
|
primaryUserID = is_bind[0]['primaryUserID']
|
|
primaryMaster = is_bind[0]['primaryMaster']
|
|
primaryMaster = is_bind[0]['primaryMaster']
|
|
isShare = True
|
|
isShare = True
|
|
|
|
|
|
-
|
|
|
|
isusermain = False
|
|
isusermain = False
|
|
if (vodPrimaryUserID != userID and vodPrimaryUserID != '') or (primaryUserID != userID and primaryUserID != ''):
|
|
if (vodPrimaryUserID != userID and vodPrimaryUserID != '') or (primaryUserID != userID and primaryUserID != ''):
|
|
isusermain = True
|
|
isusermain = True
|
|
@@ -192,8 +190,8 @@ class EquipmentManagerV3(View):
|
|
# 多通道设备设置通道名
|
|
# 多通道设备设置通道名
|
|
if Type in dvr_type_list:
|
|
if Type in dvr_type_list:
|
|
UidChannelSet_bulk = []
|
|
UidChannelSet_bulk = []
|
|
- for i in range(1, ChannelIndex+1):
|
|
|
|
- channel_name = 'channel'+str(i) # channel1,channel2...
|
|
|
|
|
|
+ for i in range(1, ChannelIndex + 1):
|
|
|
|
+ channel_name = 'channel' + str(i) # channel1,channel2...
|
|
UidChannelSet = UidChannelSetModel(uid_id=UidSet_id, channel=i, channel_name=channel_name)
|
|
UidChannelSet = UidChannelSetModel(uid_id=UidSet_id, channel=i, channel_name=channel_name)
|
|
UidChannelSet_bulk.append(UidChannelSet)
|
|
UidChannelSet_bulk.append(UidChannelSet)
|
|
UidChannelSetModel.objects.bulk_create(UidChannelSet_bulk)
|
|
UidChannelSetModel.objects.bulk_create(UidChannelSet_bulk)
|
|
@@ -218,7 +216,7 @@ class EquipmentManagerV3(View):
|
|
if us_qs.exists() and us_qs[0].is_alexa == 1:
|
|
if us_qs.exists() and us_qs[0].is_alexa == 1:
|
|
if us_qs[0].channel > 1:
|
|
if us_qs[0].channel > 1:
|
|
data_list = []
|
|
data_list = []
|
|
- uid_channel_set_qs = UidChannelSetModel.objects.filter(uid_id=us_qs[0].id).\
|
|
|
|
|
|
+ uid_channel_set_qs = UidChannelSetModel.objects.filter(uid_id=us_qs[0].id). \
|
|
values('channel', 'channel_name')
|
|
values('channel', 'channel_name')
|
|
if uid_channel_set_qs.exists():
|
|
if uid_channel_set_qs.exists():
|
|
# 多通道设备名为 UidChannelSetModel 的 channel_name
|
|
# 多通道设备名为 UidChannelSetModel 的 channel_name
|
|
@@ -255,8 +253,8 @@ class EquipmentManagerV3(View):
|
|
iotqs = iotdeviceInfoModel.objects.filter(serial_number=dvql[0]['serial_number'])
|
|
iotqs = iotdeviceInfoModel.objects.filter(serial_number=dvql[0]['serial_number'])
|
|
if iotqs.exists():
|
|
if iotqs.exists():
|
|
res['iot'] = {
|
|
res['iot'] = {
|
|
- 'endpoint': iotqs[0].endpoint,
|
|
|
|
- 'token_iot_number': iotqs[0].endpoint
|
|
|
|
|
|
+ 'endpoint': iotqs[0].endpoint,
|
|
|
|
+ 'token_iot_number': iotqs[0].endpoint
|
|
}
|
|
}
|
|
|
|
|
|
# 除C1的序列号暂时返回''
|
|
# 除C1的序列号暂时返回''
|
|
@@ -275,16 +273,16 @@ class EquipmentManagerV3(View):
|
|
return response.json(444, {'param': 'uidContent'})
|
|
return response.json(444, {'param': 'uidContent'})
|
|
|
|
|
|
try:
|
|
try:
|
|
- deviceNumber = 0 # 添加成功数量
|
|
|
|
- add_success_flag = False # 添加成功标识
|
|
|
|
- exception_flag = False # 异常标识
|
|
|
|
- exists_flag = False # 已存在标识
|
|
|
|
|
|
+ deviceNumber = 0 # 添加成功数量
|
|
|
|
+ add_success_flag = False # 添加成功标识
|
|
|
|
+ exception_flag = False # 异常标识
|
|
|
|
+ exists_flag = False # 已存在标识
|
|
uid_content_list = eval(uidContent)
|
|
uid_content_list = eval(uidContent)
|
|
print('uidContent: ', uid_content_list)
|
|
print('uidContent: ', uid_content_list)
|
|
re_uid = re.compile(r'^[A-Za-z0-9]{14,20}$')
|
|
re_uid = re.compile(r'^[A-Za-z0-9]{14,20}$')
|
|
for uid_content in uid_content_list:
|
|
for uid_content in uid_content_list:
|
|
exception_flag = False # 重置异常标识
|
|
exception_flag = False # 重置异常标识
|
|
- exists_flag = False # 已存在标识
|
|
|
|
|
|
+ exists_flag = False # 已存在标识
|
|
UID = uid_content['uid']
|
|
UID = uid_content['uid']
|
|
NickName = uid_content['nickName']
|
|
NickName = uid_content['nickName']
|
|
Type = uid_content['type']
|
|
Type = uid_content['type']
|
|
@@ -297,7 +295,7 @@ class EquipmentManagerV3(View):
|
|
if not all([UID, NickName, View_Account]): # Type和ChannelIndex可能为0
|
|
if not all([UID, NickName, View_Account]): # Type和ChannelIndex可能为0
|
|
return response.json(444, {'param': 'UID, NickName, View_Account'})
|
|
return response.json(444, {'param': 'UID, NickName, View_Account'})
|
|
|
|
|
|
- if not re_uid.match(UID): # 检查uid长度
|
|
|
|
|
|
+ if not re_uid.match(UID): # 检查uid长度
|
|
return response.json(444, {'error uid length': UID})
|
|
return response.json(444, {'error uid length': UID})
|
|
|
|
|
|
device_info_qs = Device_Info.objects.filter(UID=UID, userID_id=userID)
|
|
device_info_qs = Device_Info.objects.filter(UID=UID, userID_id=userID)
|
|
@@ -321,7 +319,8 @@ class EquipmentManagerV3(View):
|
|
primaryMaster = ''
|
|
primaryMaster = ''
|
|
isShare = False
|
|
isShare = False
|
|
|
|
|
|
- is_bind = Device_Info.objects.filter(UID=UID, isShare=False).values('userID__userID', 'primaryUserID', 'primaryMaster')
|
|
|
|
|
|
+ is_bind = Device_Info.objects.filter(UID=UID, isShare=False).values('userID__userID', 'primaryUserID',
|
|
|
|
+ 'primaryMaster')
|
|
|
|
|
|
if main_exist.exists():
|
|
if main_exist.exists():
|
|
vodPrimaryUserID = main_exist[0]['vodPrimaryUserID']
|
|
vodPrimaryUserID = main_exist[0]['vodPrimaryUserID']
|
|
@@ -333,7 +332,8 @@ class EquipmentManagerV3(View):
|
|
isShare = True
|
|
isShare = True
|
|
|
|
|
|
isusermain = False
|
|
isusermain = False
|
|
- if (vodPrimaryUserID != userID and vodPrimaryUserID != '') or (primaryUserID != userID and primaryUserID != ''):
|
|
|
|
|
|
+ if (vodPrimaryUserID != userID and vodPrimaryUserID != '') or (
|
|
|
|
+ primaryUserID != userID and primaryUserID != ''):
|
|
isusermain = True
|
|
isusermain = True
|
|
|
|
|
|
# 判断是否有已绑定用户
|
|
# 判断是否有已绑定用户
|
|
@@ -400,14 +400,15 @@ class EquipmentManagerV3(View):
|
|
multi_channel_list = [1, 2, 3, 4, 10001]
|
|
multi_channel_list = [1, 2, 3, 4, 10001]
|
|
if Type in multi_channel_list:
|
|
if Type in multi_channel_list:
|
|
UidChannelSet_bulk = []
|
|
UidChannelSet_bulk = []
|
|
- for i in range(1, ChannelIndex+1):
|
|
|
|
- channel_name = 'channel'+str(i) # channel1,channel2...
|
|
|
|
|
|
+ for i in range(1, ChannelIndex + 1):
|
|
|
|
+ channel_name = 'channel' + str(i) # channel1,channel2...
|
|
UidChannelSet = UidChannelSetModel(uid_id=UidSet_id, channel=i, channel_name=channel_name)
|
|
UidChannelSet = UidChannelSetModel(uid_id=UidSet_id, channel=i, channel_name=channel_name)
|
|
UidChannelSet_bulk.append(UidChannelSet)
|
|
UidChannelSet_bulk.append(UidChannelSet)
|
|
UidChannelSetModel.objects.bulk_create(UidChannelSet_bulk)
|
|
UidChannelSetModel.objects.bulk_create(UidChannelSet_bulk)
|
|
|
|
|
|
userDevice = Device_Info(id=id, userID_id=userID, UID=UID, NickName=NickName, View_Account=View_Account,
|
|
userDevice = Device_Info(id=id, userID_id=userID, UID=UID, NickName=NickName, View_Account=View_Account,
|
|
- View_Password=View_Password, Type=Type, ChannelIndex=ChannelIndex, version=version,
|
|
|
|
|
|
+ View_Password=View_Password, Type=Type, ChannelIndex=ChannelIndex,
|
|
|
|
+ version=version,
|
|
vodPrimaryUserID=vodPrimaryUserID, vodPrimaryMaster=vodPrimaryMaster)
|
|
vodPrimaryUserID=vodPrimaryUserID, vodPrimaryMaster=vodPrimaryMaster)
|
|
userDevice.save()
|
|
userDevice.save()
|
|
uid_serial_qs = UIDCompanySerialModel.objects.filter(uid__uid=UID)
|
|
uid_serial_qs = UIDCompanySerialModel.objects.filter(uid__uid=UID)
|
|
@@ -426,13 +427,14 @@ class EquipmentManagerV3(View):
|
|
if us_qs.exists() and us_qs[0].is_alexa == 1:
|
|
if us_qs.exists() and us_qs[0].is_alexa == 1:
|
|
if us_qs[0].channel > 1:
|
|
if us_qs[0].channel > 1:
|
|
data_list = []
|
|
data_list = []
|
|
- uid_channel_set_qs = UidChannelSetModel.objects.filter(uid_id=us_qs[0].id).\
|
|
|
|
|
|
+ uid_channel_set_qs = UidChannelSetModel.objects.filter(uid_id=us_qs[0].id). \
|
|
values('channel', 'channel_name')
|
|
values('channel', 'channel_name')
|
|
if uid_channel_set_qs.exists():
|
|
if uid_channel_set_qs.exists():
|
|
# 多通道设备名为 UidChannelSetModel 的 channel_name
|
|
# 多通道设备名为 UidChannelSetModel 的 channel_name
|
|
for uid_channel_set in uid_channel_set_qs:
|
|
for uid_channel_set in uid_channel_set_qs:
|
|
- data_list.append({'userID': userID, 'UID': UID, 'uid_nick': uid_channel_set['channel_name'],
|
|
|
|
- 'channel': uid_channel_set['channel'], 'password': encryptPassword})
|
|
|
|
|
|
+ data_list.append(
|
|
|
|
+ {'userID': userID, 'UID': UID, 'uid_nick': uid_channel_set['channel_name'],
|
|
|
|
+ 'channel': uid_channel_set['channel'], 'password': encryptPassword})
|
|
else:
|
|
else:
|
|
data_list = [{'userID': userID, 'UID': UID, 'uid_nick': NickName, 'password': encryptPassword}]
|
|
data_list = [{'userID': userID, 'UID': UID, 'uid_nick': NickName, 'password': encryptPassword}]
|
|
|
|
|
|
@@ -449,7 +451,8 @@ class EquipmentManagerV3(View):
|
|
'vodPrimaryUserID', 'vodPrimaryMaster',
|
|
'vodPrimaryUserID', 'vodPrimaryMaster',
|
|
'userID__userEmail',
|
|
'userID__userEmail',
|
|
'data_joined', 'version',
|
|
'data_joined', 'version',
|
|
- 'isVod', 'isExist', 'isCameraOpenCloud', 'serial_number')
|
|
|
|
|
|
+ 'isVod', 'isExist', 'isCameraOpenCloud',
|
|
|
|
+ 'serial_number')
|
|
dvql = CommonService.qs_to_list(dvqs)
|
|
dvql = CommonService.qs_to_list(dvqs)
|
|
ubqs = UID_Bucket.objects.filter(uid=UID). \
|
|
ubqs = UID_Bucket.objects.filter(uid=UID). \
|
|
values('bucket__content', 'status', 'channel', 'endTime', 'uid')
|
|
values('bucket__content', 'status', 'channel', 'endTime', 'uid')
|
|
@@ -467,9 +470,9 @@ class EquipmentManagerV3(View):
|
|
exception_flag = True
|
|
exception_flag = True
|
|
pass
|
|
pass
|
|
finally:
|
|
finally:
|
|
- if add_success_flag: # 有一台添加成功则返回成功
|
|
|
|
|
|
+ if add_success_flag: # 有一台添加成功则返回成功
|
|
return response.json(0, success_res)
|
|
return response.json(0, success_res)
|
|
- if exists_flag: # 全部设备已存在
|
|
|
|
|
|
+ if exists_flag: # 全部设备已存在
|
|
return response.json(174, exists_res)
|
|
return response.json(174, exists_res)
|
|
if exception_flag:
|
|
if exception_flag:
|
|
return response.json(500, error_res)
|
|
return response.json(500, error_res)
|
|
@@ -579,7 +582,7 @@ class EquipmentManagerV3(View):
|
|
dvqs = Device_Info.objects.filter(userID_id=userID)
|
|
dvqs = Device_Info.objects.filter(userID_id=userID)
|
|
# # 过滤已重置的设备
|
|
# # 过滤已重置的设备
|
|
dvqs = dvqs.filter(~Q(isExist=2))
|
|
dvqs = dvqs.filter(~Q(isExist=2))
|
|
- dvql = dvqs.values('id', 'userID', 'NickName', 'UID', 'View_Account','View_Password', 'ChannelIndex',
|
|
|
|
|
|
+ dvql = dvqs.values('id', 'userID', 'NickName', 'UID', 'View_Account', 'View_Password', 'ChannelIndex',
|
|
'Type', 'isShare', 'primaryUserID', 'primaryMaster', 'data_joined', 'vodPrimaryUserID',
|
|
'Type', 'isShare', 'primaryUserID', 'primaryMaster', 'data_joined', 'vodPrimaryUserID',
|
|
'vodPrimaryMaster', 'userID__userEmail', 'version', 'isVod', 'isExist', 'NotificationMode',
|
|
'vodPrimaryMaster', 'userID__userEmail', 'version', 'isVod', 'isExist', 'NotificationMode',
|
|
'isCameraOpenCloud', 'serial_number')
|
|
'isCameraOpenCloud', 'serial_number')
|
|
@@ -672,6 +675,10 @@ class EquipmentManagerV3(View):
|
|
uv_dict[us['uid']]['channels'] = channels
|
|
uv_dict[us['uid']]['channels'] = channels
|
|
|
|
|
|
for p in dvls:
|
|
for p in dvls:
|
|
|
|
+ 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
|
|
# C1返回序列号
|
|
# C1返回序列号
|
|
if p['Type'] != 101:
|
|
if p['Type'] != 101:
|
|
p['serial_number'] = ''
|
|
p['serial_number'] = ''
|
|
@@ -679,7 +686,7 @@ class EquipmentManagerV3(View):
|
|
p['iot'] = []
|
|
p['iot'] = []
|
|
if p['serial_number']: # 存在序列号根据序列号查询
|
|
if p['serial_number']: # 存在序列号根据序列号查询
|
|
iotdeviceInfo_qs = iotdeviceInfoModel.objects.filter(serial_number=p['serial_number'][0:6])
|
|
iotdeviceInfo_qs = iotdeviceInfoModel.objects.filter(serial_number=p['serial_number'][0:6])
|
|
- else: # 根据uid查询
|
|
|
|
|
|
+ else: # 根据uid查询
|
|
iotdeviceInfo_qs = iotdeviceInfoModel.objects.filter(uid=p['UID'])
|
|
iotdeviceInfo_qs = iotdeviceInfoModel.objects.filter(uid=p['UID'])
|
|
if iotdeviceInfo_qs.exists():
|
|
if iotdeviceInfo_qs.exists():
|
|
iotdeviceInfo = iotdeviceInfo_qs.values('endpoint', 'token_iot_number')
|
|
iotdeviceInfo = iotdeviceInfo_qs.values('endpoint', 'token_iot_number')
|
|
@@ -712,8 +719,8 @@ class EquipmentManagerV3(View):
|
|
if p_uid in uv_dict:
|
|
if p_uid in uv_dict:
|
|
# 设备版本号
|
|
# 设备版本号
|
|
uidversion = uv_dict[p_uid]['version']
|
|
uidversion = uv_dict[p_uid]['version']
|
|
- if len(uidversion) >6:
|
|
|
|
- uidversion = uidversion[0 : uidversion.rfind('.')]
|
|
|
|
|
|
+ if len(uidversion) > 6:
|
|
|
|
+ uidversion = uidversion[0: uidversion.rfind('.')]
|
|
p['uid_version'] = uidversion
|
|
p['uid_version'] = uidversion
|
|
p['ucode'] = uv_dict[p_uid]['ucode']
|
|
p['ucode'] = uv_dict[p_uid]['ucode']
|
|
p['detect_interval'] = uv_dict[p_uid]['detect_interval']
|
|
p['detect_interval'] = uv_dict[p_uid]['detect_interval']
|
|
@@ -990,16 +997,15 @@ class EquipmentManagerV3(View):
|
|
phone = qs[0]['phone']
|
|
phone = qs[0]['phone']
|
|
username = qs[0]['username']
|
|
username = qs[0]['username']
|
|
qs = CommonService.qs_to_list(qs)
|
|
qs = CommonService.qs_to_list(qs)
|
|
- if NickName =='':
|
|
|
|
|
|
+ if NickName == '':
|
|
qs[0]['NickName'] = username
|
|
qs[0]['NickName'] = username
|
|
|
|
|
|
# if userEmail =='':
|
|
# if userEmail =='':
|
|
# qs[0]['userEmail'] = NickName
|
|
# qs[0]['userEmail'] = NickName
|
|
|
|
|
|
- if phone =='':
|
|
|
|
|
|
+ if phone == '':
|
|
qs[0]['phone'] = NickName
|
|
qs[0]['phone'] = NickName
|
|
|
|
|
|
-
|
|
|
|
# if not qs:
|
|
# if not qs:
|
|
# uidq = UIDMainUser.objects.filter(UID=UID).values('user_id')
|
|
# uidq = UIDMainUser.objects.filter(UID=UID).values('user_id')
|
|
# if uidq.exists():
|
|
# if uidq.exists():
|
|
@@ -1030,9 +1036,9 @@ class EquipmentManagerV3(View):
|
|
phone = qs[0]['phone']
|
|
phone = qs[0]['phone']
|
|
username = qs[0]['username']
|
|
username = qs[0]['username']
|
|
qs = CommonService.qs_to_list(qs)
|
|
qs = CommonService.qs_to_list(qs)
|
|
- if NickName =='':
|
|
|
|
|
|
+ if NickName == '':
|
|
qs[0]['NickName'] = username
|
|
qs[0]['NickName'] = username
|
|
- if phone =='':
|
|
|
|
|
|
+ if phone == '':
|
|
qs[0]['phone'] = NickName
|
|
qs[0]['phone'] = NickName
|
|
return response.json(0, qs)
|
|
return response.json(0, qs)
|
|
|
|
|