|
@@ -6,22 +6,14 @@
|
|
|
@Email : zhangdongming@asj6.wecom.work
|
|
|
@Software: PyCharm
|
|
|
"""
|
|
|
-import time
|
|
|
|
|
|
-import oss2
|
|
|
-from django.db import connection
|
|
|
-from django.db import transaction
|
|
|
-from django.db.models import Q, Count
|
|
|
+from django.db.models import Q
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
-from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY
|
|
|
-from Controller.DeviceConfirmRegion import Device_Region
|
|
|
-from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidChannelSetModel, \
|
|
|
- iotdeviceInfoModel, UIDModel, Device_User, UserFamily, FamilyMember, FamilyMemberPermission, \
|
|
|
- FamilyRoomDevice, FamilyRoom, GatewaySubDevice
|
|
|
+from Controller.SensorGateway.EquipmentFamilyController import EquipmentFamilyView
|
|
|
+from Model.models import FamilyRoomDevice, FamilyRoom, GatewaySubDevice
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
-from Service.CommonService import CommonService
|
|
|
|
|
|
|
|
|
class GatewayDeviceView(View):
|
|
@@ -46,12 +38,61 @@ class GatewayDeviceView(View):
|
|
|
return response.json(token.code)
|
|
|
user_id = token.userID
|
|
|
|
|
|
- # 手机端添加设备,查询,修改
|
|
|
+ # 网关设备
|
|
|
if operation == 'list':
|
|
|
return self.gateway_device_list(request_dict, response)
|
|
|
+ if operation == 'del':
|
|
|
+ return self.gateway_device_del(user_id, request_dict, response)
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def gateway_device_del(cls, user_id, request_dict, response):
|
|
|
+ """
|
|
|
+ 网关设备删除或删除子设备
|
|
|
+ @param user_id:
|
|
|
+ @param request_dict:
|
|
|
+ @param response:
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ device_id = request_dict.get('deviceId')
|
|
|
+ family_id = request_dict.get('familyId')
|
|
|
+ # 1 删除网关 否则删除子设备
|
|
|
+ is_gateway = request_dict.get('isGateway', None)
|
|
|
+ sub_ids = request_dict.get('subIds')
|
|
|
+ if not all([is_gateway, family_id]):
|
|
|
+ return response.json(444)
|
|
|
+ permission = EquipmentFamilyView.get_member_permission_details(user_id, family_id)
|
|
|
+ if not permission or permission == '003':
|
|
|
+ return response.json(404)
|
|
|
+ is_gateway = int(is_gateway)
|
|
|
+ if is_gateway == 1 and device_id:
|
|
|
+ family_device_qs = FamilyRoomDevice.objects.filter(device_id=device_id)
|
|
|
+ if family_device_qs.exists():
|
|
|
+ family_device_qs.delete()
|
|
|
+ gateway_qs = GatewaySubDevice.objects.filter(device_id=device_id)
|
|
|
+ if gateway_qs.exists():
|
|
|
+ gateway_qs.delete()
|
|
|
+ elif sub_ids:
|
|
|
+ sub_ids = sub_ids.split(',')
|
|
|
+ ids = []
|
|
|
+ for item in sub_ids:
|
|
|
+ sub_id = int(item)
|
|
|
+ ids.append(sub_id)
|
|
|
+ family_device_qs = FamilyRoomDevice.objects.filter(sub_device__in=ids)
|
|
|
+ if family_device_qs.exists():
|
|
|
+ family_device_qs.delete()
|
|
|
+ gateway_sub_qs = GatewaySubDevice.objects.filter(id__in=ids)
|
|
|
+ if gateway_sub_qs.exists():
|
|
|
+ gateway_sub_qs.delete()
|
|
|
+ return response.json(0)
|
|
|
|
|
|
@classmethod
|
|
|
def gateway_device_list(cls, request_dict, response):
|
|
|
+ """
|
|
|
+ 网关设备列表
|
|
|
+ @param request_dict:
|
|
|
+ @param response:
|
|
|
+ @return:
|
|
|
+ """
|
|
|
device_id = request_dict.get('deviceId', None)
|
|
|
if not device_id:
|
|
|
return response.json(444)
|