|
@@ -22,7 +22,8 @@ from django.http import QueryDict
|
|
from django.views import View
|
|
from django.views import View
|
|
from django.core.paginator import Paginator
|
|
from django.core.paginator import Paginator
|
|
|
|
|
|
-from AgentModel.models import AgentCustomerInfo, AgentDeviceOrder, AgentDevice, AgentCloudServicePackage
|
|
|
|
|
|
+from AgentModel.models import AgentCustomerInfo, AgentDeviceOrder, AgentDevice, AgentCloudServicePackage, CustomUIDPool, \
|
|
|
|
+ DeviceCustomUID
|
|
from Model.models import DeviceTypeModel
|
|
from Model.models import DeviceTypeModel
|
|
|
|
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
@@ -75,6 +76,8 @@ class AgentDeviceView(View):
|
|
return self.get_agent_device_order(userID, request_dict, response)
|
|
return self.get_agent_device_order(userID, request_dict, response)
|
|
elif operation == 'batchBandDevice':
|
|
elif operation == 'batchBandDevice':
|
|
return self.batch_band_device(userID, request, request_dict, response)
|
|
return self.batch_band_device(userID, request, request_dict, response)
|
|
|
|
+ elif operation == 'customUidBind':
|
|
|
|
+ return self.custom_uid_bindings(request_dict, response)
|
|
else:
|
|
else:
|
|
return response.json(444, 'operation')
|
|
return response.json(444, 'operation')
|
|
|
|
|
|
@@ -367,3 +370,83 @@ class AgentDeviceView(View):
|
|
except Exception as e:
|
|
except Exception as e:
|
|
LOGGER.info('*****AgentDeviceView.device_binding_or_unbinding:errLine:{}, errMsg:{}'
|
|
LOGGER.info('*****AgentDeviceView.device_binding_or_unbinding:errLine:{}, errMsg:{}'
|
|
.format(e.__traceback__.tb_lineno, repr(e)))
|
|
.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def custom_uid_bindings(cls, request_dict, response):
|
|
|
|
+ """
|
|
|
|
+ 查询定制UID池及其设备绑定关系
|
|
|
|
+ @param userID: 用户ID
|
|
|
|
+ @param request_dict: 请求参数
|
|
|
|
+ - uid: UID(模糊匹配)
|
|
|
|
+ - customer_name: 客户名称(模糊匹配)
|
|
|
|
+ - status: UID状态(0:未绑,1:绑定,2:弃用)
|
|
|
|
+ - device_mac: 设备MAC(模糊匹配)
|
|
|
|
+ - page: 页码(默认1)
|
|
|
|
+ - page_size: 每页数量(默认10)
|
|
|
|
+ @param response: 响应对象
|
|
|
|
+ @return: JSON响应(包含UID列表及分页信息)
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ # 解析请求参数
|
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
|
+ customer_name = request_dict.get('customer_name', None)
|
|
|
|
+ status = request_dict.get('status', None)
|
|
|
|
+ device_mac = request_dict.get('device_mac', None)
|
|
|
|
+ page = int(request_dict.get('page', 1))
|
|
|
|
+ page_size = int(request_dict.get('pageSize', 20))
|
|
|
|
+
|
|
|
|
+ # 查询 CustomUIDPool(主表)
|
|
|
|
+ custom_uid_pool_qs = CustomUIDPool.objects.all().order_by('-created_time')
|
|
|
|
+
|
|
|
|
+ # 应用筛选条件
|
|
|
|
+ if uid:
|
|
|
|
+ custom_uid_pool_qs = custom_uid_pool_qs.filter(uid__icontains=uid)
|
|
|
|
+ if customer_name:
|
|
|
|
+ custom_uid_pool_qs = custom_uid_pool_qs.filter(customer_name__icontains=customer_name)
|
|
|
|
+ if status:
|
|
|
|
+ custom_uid_pool_qs = custom_uid_pool_qs.filter(status=status)
|
|
|
|
+
|
|
|
|
+ # 如果传了 device_mac,先查 DeviceCustomUID 获取关联的UID,再过滤
|
|
|
|
+ if device_mac:
|
|
|
|
+ bound_uids = DeviceCustomUID.objects.filter(
|
|
|
|
+ device_mac__icontains=device_mac
|
|
|
|
+ ).values_list('uid', flat=True)
|
|
|
|
+ custom_uid_pool_qs = custom_uid_pool_qs.filter(uid__in=bound_uids)
|
|
|
|
+
|
|
|
|
+ # 分页处理
|
|
|
|
+ paginator = Paginator(custom_uid_pool_qs, page_size)
|
|
|
|
+ custom_uid_pool_page = paginator.page(page)
|
|
|
|
+
|
|
|
|
+ # 构造返回数据
|
|
|
|
+ uid_list = []
|
|
|
|
+ for custom_uid in custom_uid_pool_page:
|
|
|
|
+ # 查询关联的设备绑定信息
|
|
|
|
+ device_binding = DeviceCustomUID.objects.filter(uid=custom_uid.uid).first()
|
|
|
|
+ uid_list.append({
|
|
|
|
+ 'id': custom_uid.id,
|
|
|
|
+ 'uid': custom_uid.uid,
|
|
|
|
+ 'type': custom_uid.type,
|
|
|
|
+ 'customer_name': custom_uid.customer_name,
|
|
|
|
+ 'uid_status': custom_uid.status, # UID池状态
|
|
|
|
+ 'created_time': custom_uid.created_time,
|
|
|
|
+ 'updated_time': custom_uid.updated_time,
|
|
|
|
+ # 设备绑定信息(如果有)
|
|
|
|
+ 'device_binding': {
|
|
|
|
+ 'device_mac': device_binding.device_mac if device_binding else None,
|
|
|
|
+ 'binding_status': device_binding.status if device_binding else None,
|
|
|
|
+ 'binding_time': device_binding.created_time if device_binding else None,
|
|
|
|
+ } if device_binding else None,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ # 返回分页结果
|
|
|
|
+ response_data = {
|
|
|
|
+ 'list': uid_list,
|
|
|
|
+ 'total': paginator.count,
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return response.json(0, response_data)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|