|
@@ -8,7 +8,7 @@ import time
|
|
import oss2
|
|
import oss2
|
|
import requests
|
|
import requests
|
|
from django.db import transaction
|
|
from django.db import transaction
|
|
-from django.db.models import Q
|
|
|
|
|
|
+from django.db.models import Q, Max
|
|
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, CONFIG_INFO, CONFIG_US
|
|
from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY, CONFIG_INFO, CONFIG_US
|
|
@@ -89,6 +89,8 @@ class EquipmentManagerV3(View):
|
|
return self.verify_code(request_dict, response)
|
|
return self.verify_code(request_dict, response)
|
|
elif operation == 'viewDevicePassword':
|
|
elif operation == 'viewDevicePassword':
|
|
return self.view_device_password(request_dict, response)
|
|
return self.view_device_password(request_dict, response)
|
|
|
|
+ elif operation == 'editSortOrder':
|
|
|
|
+ return self.edit_sort_order(userID, request_dict, response)
|
|
else:
|
|
else:
|
|
return response.json(414)
|
|
return response.json(414)
|
|
|
|
|
|
@@ -321,10 +323,14 @@ class EquipmentManagerV3(View):
|
|
UidChannelSet_bulk.append(UidChannelSet)
|
|
UidChannelSet_bulk.append(UidChannelSet)
|
|
UidChannelSetModel.objects.bulk_create(UidChannelSet_bulk)
|
|
UidChannelSetModel.objects.bulk_create(UidChannelSet_bulk)
|
|
|
|
|
|
|
|
+ # 获取当前用户下最大 sort_order
|
|
|
|
+ max_sort_order = Device_Info.objects.filter(userID_id=userID).aggregate(
|
|
|
|
+ Max('sort_order'))['sort_order__max'] or 0
|
|
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,
|
|
View_Password=View_Password, Type=Type, ChannelIndex=ChannelIndex,
|
|
version=version,
|
|
version=version,
|
|
- vodPrimaryUserID=vodPrimaryUserID, vodPrimaryMaster=vodPrimaryMaster)
|
|
|
|
|
|
+ vodPrimaryUserID=vodPrimaryUserID, vodPrimaryMaster=vodPrimaryMaster,
|
|
|
|
+ sort_order=max_sort_order + 1)
|
|
userDevice.save()
|
|
userDevice.save()
|
|
# 保存用户推送按钮信息
|
|
# 保存用户推送按钮信息
|
|
button_qs = UserAudioVideoPush.objects.filter(uid=UID)
|
|
button_qs = UserAudioVideoPush.objects.filter(uid=UID)
|
|
@@ -823,6 +829,7 @@ class EquipmentManagerV3(View):
|
|
if tko.code != 0:
|
|
if tko.code != 0:
|
|
return response.json(tko.code)
|
|
return response.json(tko.code)
|
|
userID = tko.userID
|
|
userID = tko.userID
|
|
|
|
+ UserDeviceService.init_device_sort_order(userID)
|
|
group_id = int(request_dict.get('groupId', 0))
|
|
group_id = int(request_dict.get('groupId', 0))
|
|
# 查询设备列表以及设备uid集合
|
|
# 查询设备列表以及设备uid集合
|
|
dv_list, uid_list = UserDeviceService.query_device_list(userID, uid, NickName, page, line, group_id)
|
|
dv_list, uid_list = UserDeviceService.query_device_list(userID, uid, NickName, page, line, group_id)
|
|
@@ -1418,3 +1425,52 @@ class EquipmentManagerV3(View):
|
|
return response.json(0, res)
|
|
return response.json(0, res)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def edit_sort_order(user_id, request_dict, response):
|
|
|
|
+ """
|
|
|
|
+ 修改设备排序
|
|
|
|
+ ids: 选中的设备id列表(单选或多选)
|
|
|
|
+ action: 操作类型(move/top/bottom)
|
|
|
|
+ target_id: 拖动目标id(仅单选拖动时用)
|
|
|
|
+ """
|
|
|
|
+ ids = request_dict.get('ids', None)
|
|
|
|
+ action = request_dict.get('action', None)
|
|
|
|
+ target_id = request_dict.get('target_id', None)
|
|
|
|
+ if not ids or not action:
|
|
|
|
+ return response.json(444, 'ids or action missing')
|
|
|
|
+ try:
|
|
|
|
+ ids = ids.split(',')
|
|
|
|
+ # 查询所有设备,按sort_order排序
|
|
|
|
+ all_devices = list(Device_Info.objects.filter(userID_id=user_id).exclude(Type__in=[200, 201]).
|
|
|
|
+ order_by('-sort_order', '-data_joined'))
|
|
|
|
+ id_to_device = {str(d.id): d for d in all_devices}
|
|
|
|
+ # 单选拖动排序
|
|
|
|
+ if action == 'move' and len(ids) == 1 and target_id:
|
|
|
|
+ moving_id = ids[0]
|
|
|
|
+ moving_device = id_to_device.get(str(moving_id))
|
|
|
|
+
|
|
|
|
+ # 如果要移动到最前面,设置target_index为0
|
|
|
|
+ if target_id == 'front':
|
|
|
|
+ target_index = 0
|
|
|
|
+ else:
|
|
|
|
+ target_device = id_to_device.get(str(target_id))
|
|
|
|
+ target_index = all_devices.index(target_device)
|
|
|
|
+
|
|
|
|
+ all_devices.remove(moving_device)
|
|
|
|
+ all_devices.insert(target_index, moving_device)
|
|
|
|
+ # 勾选框批量置顶/置底
|
|
|
|
+ elif action in ('top', 'bottom'):
|
|
|
|
+ selected_devices = [id_to_device[i] for i in ids if i in id_to_device]
|
|
|
|
+ other_devices = [d for d in all_devices if str(d.id) not in ids]
|
|
|
|
+ if action == 'top':
|
|
|
|
+ all_devices = selected_devices + other_devices
|
|
|
|
+ else:
|
|
|
|
+ all_devices = other_devices + list(reversed(selected_devices))
|
|
|
|
+ # 重新赋值sort_order
|
|
|
|
+ for idx, device in enumerate(all_devices):
|
|
|
|
+ device.sort_order = len(all_devices) - idx
|
|
|
|
+ device.save(update_fields=['sort_order'])
|
|
|
|
+ return response.json(0)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|