|
@@ -1236,8 +1236,8 @@ class DeviceManagement(View):
|
|
|
email = request_dict.get('email')
|
|
|
serial_number = request_dict.get('serialNumber')
|
|
|
uid = request_dict.get('uid')
|
|
|
- page = int(request_dict.get('pageNo', 1))
|
|
|
- page_size = int(request_dict.get('pageSize', 10))
|
|
|
+ page = int(request_dict.get('pageNo', 0)) # 默认值设为 0
|
|
|
+ page_size = int(request_dict.get('pageSize', 0)) # 默认值设为 0
|
|
|
|
|
|
try:
|
|
|
# 构建查询条件
|
|
@@ -1264,18 +1264,24 @@ class DeviceManagement(View):
|
|
|
customer_device_qs = customer_device_qs.filter(uid=uid)
|
|
|
|
|
|
# 分页处理
|
|
|
- paginator = Paginator(customer_device_qs, page_size)
|
|
|
- customer_device_page = paginator.get_page(page)
|
|
|
+ if page > 0 and page_size > 0:
|
|
|
+ paginator = Paginator(customer_device_qs, page_size)
|
|
|
+ customer_device_page = paginator.get_page(page)
|
|
|
+ customer_device_list = customer_device_page.object_list
|
|
|
+ total = paginator.count
|
|
|
+ else:
|
|
|
+ customer_device_list = list(customer_device_qs)
|
|
|
+ total = customer_device_qs.count()
|
|
|
|
|
|
# 创建一个字典来映射 c_id 到 CustomCustomerOrderInfo 对象
|
|
|
customer_order_map = {order.id: order for order in custom_customer_qs}
|
|
|
|
|
|
# 构建设备列表
|
|
|
- customer_device_list = []
|
|
|
- for device in customer_device_page.object_list:
|
|
|
+ result_list = []
|
|
|
+ for device in customer_device_list:
|
|
|
customer_order = customer_order_map.get(device.c_id)
|
|
|
if customer_order:
|
|
|
- customer_device_list.append({
|
|
|
+ result_list.append({
|
|
|
'id': device.id,
|
|
|
'serialNumber': device.serial_number,
|
|
|
'uid': device.uid,
|
|
@@ -1287,7 +1293,7 @@ class DeviceManagement(View):
|
|
|
'email': customer_order.email,
|
|
|
})
|
|
|
else:
|
|
|
- customer_device_list.append({
|
|
|
+ result_list.append({
|
|
|
'id': device.id,
|
|
|
'serialNumber': device.serial_number,
|
|
|
'uid': device.uid,
|
|
@@ -1301,9 +1307,9 @@ class DeviceManagement(View):
|
|
|
|
|
|
# 构造返回数据
|
|
|
data = {
|
|
|
- 'total': paginator.count,
|
|
|
+ 'total': total,
|
|
|
'orderDeviceQuantity': total_quantity or 0, # 防止为None
|
|
|
- 'list': customer_device_list, # 当前页的记录列表
|
|
|
+ 'list': result_list,
|
|
|
}
|
|
|
|
|
|
return response.json(0, data)
|