|
@@ -18,11 +18,13 @@ import traceback
|
|
import threading
|
|
import threading
|
|
|
|
|
|
from django.db import transaction
|
|
from django.db import transaction
|
|
|
|
+from django.db.models import Q
|
|
from django.http import QueryDict
|
|
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 +77,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')
|
|
|
|
|
|
@@ -357,13 +361,91 @@ class AgentDeviceView(View):
|
|
device_info = AgentDevice.objects.filter(serial_number=serial_number)
|
|
device_info = AgentDevice.objects.filter(serial_number=serial_number)
|
|
if not device_info.exists():
|
|
if not device_info.exists():
|
|
return
|
|
return
|
|
|
|
+ LOGGER.info('同步更新设备激活状态serial:{},type:{}'.format(serial_number, bind_type))
|
|
n_time = int(time.time())
|
|
n_time = int(time.time())
|
|
if bind_type == 1:
|
|
if bind_type == 1:
|
|
# 绑定设备
|
|
# 绑定设备
|
|
- device_info.update(status=1, updated_time=n_time)
|
|
|
|
|
|
+ device_info.update(status=1, updated_time=n_time, at_time=n_time)
|
|
elif bind_type == 2:
|
|
elif bind_type == 2:
|
|
# 解绑设备
|
|
# 解绑设备
|
|
device_info.update(status=0, updated_time=n_time)
|
|
device_info.update(status=0, updated_time=n_time)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- LOGGER.info('*****AgentDeviceView.device_binding_or_unbinding:errLine:{}, errMsg:{}'
|
|
|
|
|
|
+ LOGGER.error('*****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):
|
|
|
|
+ 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))
|
|
|
|
+
|
|
|
|
+ filters = Q()
|
|
|
|
+ if uid:
|
|
|
|
+ filters &= Q(uid__icontains=uid)
|
|
|
|
+ if customer_name:
|
|
|
|
+ filters &= Q(customer_name__icontains=customer_name)
|
|
|
|
+ if status is not None:
|
|
|
|
+ filters &= Q(status=status)
|
|
|
|
+
|
|
|
|
+ if device_mac:
|
|
|
|
+ bound_uids = DeviceCustomUID.objects.filter(
|
|
|
|
+ device_mac__icontains=device_mac
|
|
|
|
+ ).values_list('uid', flat=True)
|
|
|
|
+ filters &= Q(uid__in=list(bound_uids))
|
|
|
|
+
|
|
|
|
+ custom_uid_pool_qs = CustomUIDPool.objects.filter(filters).order_by('-updated_time')
|
|
|
|
+ paginator = Paginator(custom_uid_pool_qs, page_size)
|
|
|
|
+ page_obj = paginator.page(page)
|
|
|
|
+
|
|
|
|
+ uid_list = [obj.uid for obj in page_obj]
|
|
|
|
+ bindings = DeviceCustomUID.objects.filter(uid__in=uid_list)
|
|
|
|
+
|
|
|
|
+ # 构建 uid -> 多条绑定记录 map
|
|
|
|
+ binding_map = {}
|
|
|
|
+ for b in bindings:
|
|
|
|
+ binding_map.setdefault(b.uid, []).append(b)
|
|
|
|
+
|
|
|
|
+ # 构建结果列表
|
|
|
|
+ result_list = []
|
|
|
|
+ for obj in page_obj:
|
|
|
|
+ uid_bindings = binding_map.get(obj.uid, [])
|
|
|
|
+ if uid_bindings:
|
|
|
|
+ for bind in uid_bindings:
|
|
|
|
+ result_list.append({
|
|
|
|
+ 'id': obj.id,
|
|
|
|
+ 'uid': obj.uid,
|
|
|
|
+ 'type': obj.type,
|
|
|
|
+ 'customer_name': obj.customer_name,
|
|
|
|
+ 'uid_status': obj.status,
|
|
|
|
+ 'created_time': obj.created_time,
|
|
|
|
+ 'updated_time': obj.updated_time,
|
|
|
|
+ 'device_mac': bind.device_mac,
|
|
|
|
+ 'device_status': bind.status,
|
|
|
|
+ 'bind_time': bind.created_time,
|
|
|
|
+ })
|
|
|
|
+ else:
|
|
|
|
+ result_list.append({
|
|
|
|
+ 'id': obj.id,
|
|
|
|
+ 'uid': obj.uid,
|
|
|
|
+ 'type': obj.type,
|
|
|
|
+ 'customer_name': obj.customer_name,
|
|
|
|
+ 'uid_status': obj.status,
|
|
|
|
+ 'created_time': obj.created_time,
|
|
|
|
+ 'updated_time': obj.updated_time,
|
|
|
|
+ 'device_mac': '',
|
|
|
|
+ 'device_status': None,
|
|
|
|
+ 'bind_time': None,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ return response.json(0, {
|
|
|
|
+ 'list': result_list,
|
|
|
|
+ 'total': paginator.count
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+ return response.json(500, f'error_line:{e.__traceback__.tb_lineno}, error_msg:{repr(e)}')
|