|
@@ -11,7 +11,8 @@ from django.db.models import Q
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
|
|
|
|
from Controller.SensorGateway.EquipmentFamilyController import EquipmentFamilyView
|
|
from Controller.SensorGateway.EquipmentFamilyController import EquipmentFamilyView
|
|
-from Model.models import FamilyRoomDevice, FamilyRoom, GatewaySubDevice, Device_Info, UserFamily, FamilyMember
|
|
|
|
|
|
+from Model.models import FamilyRoomDevice, FamilyRoom, GatewaySubDevice, Device_Info, UserFamily, FamilyMember, \
|
|
|
|
+ UidSetModel
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
|
|
|
|
@@ -145,26 +146,37 @@ class GatewayDeviceView(View):
|
|
permission = EquipmentFamilyView.get_member_permission_details(user_id, family_id)
|
|
permission = EquipmentFamilyView.get_member_permission_details(user_id, family_id)
|
|
if not permission or permission == '003':
|
|
if not permission or permission == '003':
|
|
return response.json(404)
|
|
return response.json(404)
|
|
- if 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)
|
|
|
|
|
|
+ try:
|
|
|
|
+ with transaction.atomic():
|
|
|
|
+ if device_id:
|
|
|
|
+ device_qs = Device_Info.objects.filter(id=device_id)
|
|
|
|
+ if device_qs.exists():
|
|
|
|
+ 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()
|
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid=device_qs.first().UID)
|
|
|
|
+ if uid_set_qs.exists():
|
|
|
|
+ uid_set_qs.delete()
|
|
|
|
+ device_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)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+ return response.json(177, repr(e))
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def gateway_device_list(cls, request_dict, response):
|
|
def gateway_device_list(cls, request_dict, response):
|