|
@@ -5,18 +5,18 @@ import time
|
|
|
|
|
|
import oss2
|
|
import oss2
|
|
from django.db import transaction
|
|
from django.db import transaction
|
|
-from django.db.models import Q
|
|
|
|
|
|
+from django.db.models import Q, F
|
|
|
|
+from django.views.generic.base import View
|
|
|
|
|
|
from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
|
|
from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
|
|
|
|
+from Model.models import Device_Info, UidSetModel, LogModel, UID_Bucket, Unused_Uid_Meal, Order_Model, StsCrdModel, \
|
|
|
|
+ VodHlsModel, ExperienceContextModel, DeviceTypeModel, Equipment_Info, UidUserModel, ExperienceAiModel, AiService, \
|
|
|
|
+ AppBundle, App_Info, AppDeviceType, DeviceNameLanguage
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
-from django.views.generic.base import View
|
|
|
|
-
|
|
|
|
|
|
+from Service.CommonService import CommonService
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
from Service.ModelService import ModelService
|
|
from Service.ModelService import ModelService
|
|
-from Service.CommonService import CommonService
|
|
|
|
-from Model.models import Device_Info, UidSetModel, LogModel, UID_Bucket, Unused_Uid_Meal, Order_Model, StsCrdModel, \
|
|
|
|
- VodHlsModel, ExperienceContextModel, DeviceTypeModel, Equipment_Info, UidUserModel, ExperienceAiModel, AiService
|
|
|
|
|
|
|
|
|
|
|
|
class DeviceManagement(View):
|
|
class DeviceManagement(View):
|
|
@@ -37,6 +37,9 @@ class DeviceManagement(View):
|
|
return self.addDeviceType(request, request_dict, response)
|
|
return self.addDeviceType(request, request_dict, response)
|
|
elif operation == 'delDeviceData': # 删除设备数据
|
|
elif operation == 'delDeviceData': # 删除设备数据
|
|
return self.del_device_data(request_dict, response)
|
|
return self.del_device_data(request_dict, response)
|
|
|
|
+ elif operation == 'getDeviceIcon': # app获取设备图标
|
|
|
|
+ response = ResponseObject(language)
|
|
|
|
+ return self.get_device_icon(request_dict, response)
|
|
else:
|
|
else:
|
|
tko = TokenObject(
|
|
tko = TokenObject(
|
|
request.META.get('HTTP_AUTHORIZATION'),
|
|
request.META.get('HTTP_AUTHORIZATION'),
|
|
@@ -47,13 +50,13 @@ class DeviceManagement(View):
|
|
userID = tko.userID
|
|
userID = tko.userID
|
|
if not userID:
|
|
if not userID:
|
|
return response.json(444, 'userID')
|
|
return response.json(444, 'userID')
|
|
- if operation == 'getDeviceInfoList': # 获取设备信息数据
|
|
|
|
|
|
+ if operation == 'getDeviceInfoList': # 获取设备信息数据
|
|
return self.get_device_info_list(request_dict, response)
|
|
return self.get_device_info_list(request_dict, response)
|
|
elif operation == 'deleteDevice':
|
|
elif operation == 'deleteDevice':
|
|
return self.deleteDevice(request_dict, response)
|
|
return self.deleteDevice(request_dict, response)
|
|
- elif operation == 'resetVod': # 重置云存
|
|
|
|
|
|
+ elif operation == 'resetVod': # 重置云存
|
|
return self.resetVod(request, request_dict, response)
|
|
return self.resetVod(request, request_dict, response)
|
|
- elif operation == 'resetAi': # 重置AI
|
|
|
|
|
|
+ elif operation == 'resetAi': # 重置AI
|
|
return self.reset_ai(request, request_dict, response)
|
|
return self.reset_ai(request, request_dict, response)
|
|
elif operation == 'resetPrimaryUser':
|
|
elif operation == 'resetPrimaryUser':
|
|
return self.resetPrimaryUser(request, request_dict, response)
|
|
return self.resetPrimaryUser(request, request_dict, response)
|
|
@@ -61,6 +64,14 @@ class DeviceManagement(View):
|
|
return self.getDeviceTypeList(request_dict, response)
|
|
return self.getDeviceTypeList(request_dict, response)
|
|
elif operation == 'deleteDeviceType':
|
|
elif operation == 'deleteDeviceType':
|
|
return self.deleteDeviceType(request_dict, response)
|
|
return self.deleteDeviceType(request_dict, response)
|
|
|
|
+ elif operation == 'getAppDeviceTypeList': # 获取app设备类型数据
|
|
|
|
+ return self.get_app_device_type_list(request_dict, response)
|
|
|
|
+ elif operation == 'getAppBundleIdList': # 获取app包id数据
|
|
|
|
+ return self.get_app_bundle_id_list(response)
|
|
|
|
+ elif operation == 'editAppDeviceType': # 编辑app设备类型数据
|
|
|
|
+ return self.edit_app_device_type(request_dict, response)
|
|
|
|
+ elif operation == 'deleteAppDeviceType': # 删除app设备类型数据
|
|
|
|
+ return self.delete_app_device_type(request_dict, response)
|
|
else:
|
|
else:
|
|
return response.json(444, 'operation')
|
|
return response.json(444, 'operation')
|
|
|
|
|
|
@@ -80,7 +91,7 @@ class DeviceManagement(View):
|
|
line = int(pageSize)
|
|
line = int(pageSize)
|
|
|
|
|
|
try:
|
|
try:
|
|
- if UID or serialNumber or NickName or username: # 条件查询
|
|
|
|
|
|
+ if UID or serialNumber or NickName or username: # 条件查询
|
|
if UID:
|
|
if UID:
|
|
device_info_qs = Device_Info.objects.filter(UID__contains=UID)
|
|
device_info_qs = Device_Info.objects.filter(UID__contains=UID)
|
|
if serialNumber:
|
|
if serialNumber:
|
|
@@ -95,7 +106,7 @@ class DeviceManagement(View):
|
|
if not total:
|
|
if not total:
|
|
return response.json(0, {'list': {}, 'total': 0})
|
|
return response.json(0, {'list': {}, 'total': 0})
|
|
device_info_qs = device_info_qs[(page - 1) * line:page * line]
|
|
device_info_qs = device_info_qs[(page - 1) * line:page * line]
|
|
- else: # 查询全部
|
|
|
|
|
|
+ else: # 查询全部
|
|
total = Device_Info.objects.filter().count()
|
|
total = Device_Info.objects.filter().count()
|
|
device_info_qs = Device_Info.objects.filter()[(page - 1) * line:page * line]
|
|
device_info_qs = Device_Info.objects.filter()[(page - 1) * line:page * line]
|
|
if not device_info_qs.exists():
|
|
if not device_info_qs.exists():
|
|
@@ -108,13 +119,15 @@ class DeviceManagement(View):
|
|
# 设备的用户名和主用户
|
|
# 设备的用户名和主用户
|
|
username = ModelService.get_user_name(device_info_list["datas"][k]['fields']['userID'])
|
|
username = ModelService.get_user_name(device_info_list["datas"][k]['fields']['userID'])
|
|
device_info_list["datas"][k]['fields']['username'] = username
|
|
device_info_list["datas"][k]['fields']['username'] = username
|
|
- device_info_list["datas"][k]['fields']['vodPrimaryMaster'] = device_info_list["datas"][k]['fields']['vodPrimaryMaster']
|
|
|
|
|
|
+ device_info_list["datas"][k]['fields']['vodPrimaryMaster'] = \
|
|
|
|
+ device_info_list["datas"][k]['fields']['vodPrimaryMaster']
|
|
# 设备类型,是否支持Alexa和ip
|
|
# 设备类型,是否支持Alexa和ip
|
|
type = device_info_list["datas"][k]['fields']['Type']
|
|
type = device_info_list["datas"][k]['fields']['Type']
|
|
device_type_qs = DeviceTypeModel.objects.filter(type=type).values('name')
|
|
device_type_qs = DeviceTypeModel.objects.filter(type=type).values('name')
|
|
if device_type_qs.exists():
|
|
if device_type_qs.exists():
|
|
device_info_list["datas"][k]['fields']['Type'] = device_type_qs[0]['name']
|
|
device_info_list["datas"][k]['fields']['Type'] = device_type_qs[0]['name']
|
|
- uid_set_qs = UidSetModel.objects.filter(uid=device_info_list["datas"][k]['fields']['UID']).values('is_alexa', 'ip', 'version')
|
|
|
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(
|
|
|
|
+ uid=device_info_list["datas"][k]['fields']['UID']).values('is_alexa', 'ip', 'version')
|
|
if uid_set_qs.exists():
|
|
if uid_set_qs.exists():
|
|
isAlexa = '是' if uid_set_qs[0]['is_alexa'] else '否'
|
|
isAlexa = '是' if uid_set_qs[0]['is_alexa'] else '否'
|
|
device_info_list["datas"][k]['fields']['isAlexa'] = isAlexa
|
|
device_info_list["datas"][k]['fields']['isAlexa'] = isAlexa
|
|
@@ -138,7 +151,7 @@ class DeviceManagement(View):
|
|
Device_Info.objects.filter(id=deviceID).delete()
|
|
Device_Info.objects.filter(id=deviceID).delete()
|
|
# 删除推送消息
|
|
# 删除推送消息
|
|
for val in range(1, 8):
|
|
for val in range(1, 8):
|
|
- EquipmentInfoService.get_equipment_info_model('', val).\
|
|
|
|
|
|
+ EquipmentInfoService.get_equipment_info_model('', val). \
|
|
filter(device_user_id=userID, device_uid=uid).delete()
|
|
filter(device_user_id=userID, device_uid=uid).delete()
|
|
return response.json(0)
|
|
return response.json(0)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -294,7 +307,7 @@ class DeviceManagement(View):
|
|
# 上传文件到阿里云OSS
|
|
# 上传文件到阿里云OSS
|
|
auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'ansjer-static-resources')
|
|
bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'ansjer-static-resources')
|
|
- key = 'device_type/' + icon # 图片文件存放于 device_type 目录下
|
|
|
|
|
|
+ key = 'device_type/' + icon # 图片文件存放于 device_type 目录下
|
|
# https://oss.console.aliyun.com/bucket/oss-cn-shenzhen/ansjer-static-resources/object?path=device_type%2F
|
|
# https://oss.console.aliyun.com/bucket/oss-cn-shenzhen/ansjer-static-resources/object?path=device_type%2F
|
|
bucket.put_object(key=key, data=iconFile)
|
|
bucket.put_object(key=key, data=iconFile)
|
|
DeviceTypeModel.objects.create(name=name, model=model, type=type, ptz_type=ptz_type, icon=icon,
|
|
DeviceTypeModel.objects.create(name=name, model=model, type=type, ptz_type=ptz_type, icon=icon,
|
|
@@ -313,7 +326,7 @@ class DeviceManagement(View):
|
|
return response.json(444)
|
|
return response.json(444)
|
|
try:
|
|
try:
|
|
with transaction.atomic():
|
|
with transaction.atomic():
|
|
- uidList = uidList.splitlines() # 按行('\r', '\r\n', \n')切割字符串返回列表
|
|
|
|
|
|
+ uidList = uidList.splitlines() # 按行('\r', '\r\n', \n')切割字符串返回列表
|
|
# 根据删除项删除相关数据
|
|
# 根据删除项删除相关数据
|
|
if '设备信息数据' in delDataOptions:
|
|
if '设备信息数据' in delDataOptions:
|
|
Device_Info.objects.filter(UID__in=uidList).delete()
|
|
Device_Info.objects.filter(UID__in=uidList).delete()
|
|
@@ -338,3 +351,118 @@ class DeviceManagement(View):
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print(e)
|
|
print(e)
|
|
return response.json(500, repr(e))
|
|
return response.json(500, repr(e))
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_device_icon(request_dict, response):
|
|
|
|
+ lang = request_dict.get('lang', None)
|
|
|
|
+ app_bundle_id = request_dict.get('appBundleId', None)
|
|
|
|
+
|
|
|
|
+ if not all([lang, app_bundle_id]):
|
|
|
|
+ return response.json(444)
|
|
|
|
+ try:
|
|
|
|
+ app_bundle_qs = AppBundle.objects.filter(app_bundle_id=app_bundle_id,
|
|
|
|
+ app_device_type__devicenamelanguage__lang=lang).annotate(
|
|
|
|
+ model=F('app_device_type__model'), type=F('app_device_type__type'), icon=F('app_device_type__icon'),
|
|
|
|
+ name=F('app_device_type__devicenamelanguage__name'),
|
|
|
|
+ sort=F('app_device_type__devicenamelanguage__sort')).order_by(
|
|
|
|
+ 'app_device_type__devicenamelanguage__sort').values('model', 'type', 'icon', 'name', 'sort')
|
|
|
|
+ dvr_list = [app_bundle for app_bundle in app_bundle_qs if app_bundle['model'] == 1]
|
|
|
|
+ ipc_list = [app_bundle for app_bundle in app_bundle_qs if app_bundle['model'] == 2]
|
|
|
|
+ print(dvr_list, ipc_list)
|
|
|
|
+ res = {
|
|
|
|
+ 'deviceDvr': dvr_list,
|
|
|
|
+ 'deviceIpc': ipc_list,
|
|
|
|
+ }
|
|
|
|
+ return response.json(0, res)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_app_device_type_list(request_dict, response):
|
|
|
|
+ app_bundle_id = request_dict.get('appBundleId', None)
|
|
|
|
+ lang = request_dict.get('lang', 'cn')
|
|
|
|
+
|
|
|
|
+ pageNo = request_dict.get('pageNo', None)
|
|
|
|
+ pageSize = request_dict.get('pageSize', None)
|
|
|
|
+
|
|
|
|
+ if not all([pageNo, pageSize]):
|
|
|
|
+ return response.json(444)
|
|
|
|
+
|
|
|
|
+ page = int(pageNo)
|
|
|
|
+ line = int(pageSize)
|
|
|
|
+ try:
|
|
|
|
+ if not app_bundle_id:
|
|
|
|
+ app_bundle_id = 'com.ansjer.zccloud'
|
|
|
|
+ app_bundle_qs = AppBundle.objects.filter(app_bundle_id=app_bundle_id)
|
|
|
|
+ if lang:
|
|
|
|
+ app_bundle_qs = app_bundle_qs.filter(app_device_type__devicenamelanguage__lang=lang)
|
|
|
|
+
|
|
|
|
+ app_bundle_qs = app_bundle_qs.annotate(
|
|
|
|
+ model=F('app_device_type__model'), type=F('app_device_type__type'), icon=F('app_device_type__icon'),
|
|
|
|
+ lang=F('app_device_type__devicenamelanguage__lang'),
|
|
|
|
+ name=F('app_device_type__devicenamelanguage__name'),
|
|
|
|
+ sort=F('app_device_type__devicenamelanguage__sort')).values('id', 'app_device_type__id', 'model',
|
|
|
|
+ 'type', 'icon',
|
|
|
|
+ 'app_device_type__devicenamelanguage__id',
|
|
|
|
+ 'lang', 'name', 'sort').order_by(
|
|
|
|
+ 'app_device_type__devicenamelanguage__sort')
|
|
|
|
+ if not app_bundle_qs.exists():
|
|
|
|
+ return response.json(0)
|
|
|
|
+ total = app_bundle_qs.count()
|
|
|
|
+ app_bundle_qs = app_bundle_qs[(page - 1) * line:page * line]
|
|
|
|
+ app_device_type_list = [app_bundle for app_bundle in app_bundle_qs]
|
|
|
|
+ return response.json(0, {'list': app_device_type_list, 'total': total})
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_app_bundle_id_list(response):
|
|
|
|
+ try:
|
|
|
|
+ app_info_qs = App_Info.objects.filter().values('id', 'appBundleId', 'appName')
|
|
|
|
+ appBundleIdList = list(app_info_qs)
|
|
|
|
+ return response.json(0, {'list': appBundleIdList})
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def edit_app_device_type(request_dict, response):
|
|
|
|
+ # app_device_type表数据
|
|
|
|
+ app_device_type_id = request_dict.get('app_device_type__id', None)
|
|
|
|
+ model = request_dict.get('model', None)
|
|
|
|
+ type = request_dict.get('type', None)
|
|
|
|
+ icon = request_dict.get('icon', None)
|
|
|
|
+ # device_name_language表数据
|
|
|
|
+ device_name_language_id = request_dict.get('app_device_type__devicenamelanguage__id', None)
|
|
|
|
+ lang = request_dict.get('lang', None)
|
|
|
|
+ name = request_dict.get('name', None)
|
|
|
|
+ sort = request_dict.get('sort', None)
|
|
|
|
+
|
|
|
|
+ if not all([app_device_type_id, model, type, icon, device_name_language_id, lang, name, sort]):
|
|
|
|
+ return response.json(444)
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ with transaction.atomic():
|
|
|
|
+ AppDeviceType.objects.filter(id=app_device_type_id).update(model=model, type=type, icon=icon)
|
|
|
|
+ DeviceNameLanguage.objects.filter(id=device_name_language_id).update(lang=lang, name=name, sort=sort)
|
|
|
|
+ return response.json(0)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def delete_app_device_type(request_dict, response):
|
|
|
|
+ app_bundle_id = request_dict.get('appBundleId', None)
|
|
|
|
+ app_device_type_id = request_dict.get('appDeviceTypeId', None)
|
|
|
|
+ if not all([app_bundle_id, app_device_type_id]):
|
|
|
|
+ return response.json(444)
|
|
|
|
+ try:
|
|
|
|
+ app_bundle_qs = AppBundle.objects.get(id=app_bundle_id)
|
|
|
|
+ app_device_type_qs = AppDeviceType.objects.filter(id=app_device_type_id)
|
|
|
|
+ app_bundle_qs.app_device_type.remove(*app_device_type_qs)
|
|
|
|
+ return response.json(0)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+ return response.json(500, repr(e))
|