|
@@ -3,31 +3,30 @@
|
|
|
import json
|
|
|
import operator
|
|
|
import time
|
|
|
-import requests
|
|
|
|
|
|
import oss2
|
|
|
+import requests
|
|
|
from django.core.paginator import Paginator
|
|
|
from django.db import transaction
|
|
|
from django.db.models import Q, F, Sum
|
|
|
-from django.views.generic.base import View
|
|
|
from django.forms.models import model_to_dict
|
|
|
+from django.views.generic.base import View
|
|
|
|
|
|
+from Ansjer.config import LOGGER
|
|
|
from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, \
|
|
|
- AWS_SES_ACCESS_REGION, UNUSED_SERIAL_REDIS_LIST
|
|
|
-from Model.models import Device_Info, UidSetModel, LogModel, UID_Bucket, Unused_Uid_Meal, Order_Model, StsCrdModel, \
|
|
|
- VodHlsModel, ExperienceContextModel, DeviceTypeModel, Equipment_Info, UidUserModel, ExperienceAiModel, AiService, \
|
|
|
- AppBundle, App_Info, AppDeviceType, DeviceNameLanguage, AppVersionNumber, UIDCompanySerialModel, UIDModel, \
|
|
|
- CompanySerialModel, UidPushModel, CustomCustomerDevice, CustomCustomerOrderInfo
|
|
|
+ AWS_SES_ACCESS_REGION
|
|
|
+from Ansjer.config import SERVER_DOMAIN_TEST, SERVER_DOMAIN_CN, SERVER_DOMAIN_US, SERVER_DOMAIN_EUR
|
|
|
+from Model.models import Device_Info, UidSetModel, LogModel, UID_Bucket, Unused_Uid_Meal, StsCrdModel, \
|
|
|
+ VodHlsModel, ExperienceContextModel, DeviceTypeModel, UidUserModel, ExperienceAiModel, AiService, \
|
|
|
+ AppBundle, App_Info, AppDeviceType, DeviceNameLanguage, UIDCompanySerialModel, UidPushModel, \
|
|
|
+ CustomCustomerOrderInfo, CustomCustomerDevice
|
|
|
from Object.AWS.AmazonS3Util import AmazonS3Util
|
|
|
-from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
|
from Service.ModelService import ModelService
|
|
|
from Service.VodHlsService import SplitVodHlsObject
|
|
|
-from Ansjer.config import SERVER_DOMAIN_TEST, SERVER_DOMAIN_CN, SERVER_DOMAIN_US, SERVER_DOMAIN_EUR
|
|
|
-from Ansjer.config import LOGGER
|
|
|
|
|
|
|
|
|
class DeviceManagement(View):
|
|
@@ -550,10 +549,10 @@ class DeviceManagement(View):
|
|
|
app_bundle_qs = app_bundle_qs.filter(app_device_type__devicenamelanguage__lang=lang)
|
|
|
app_bundle_qs = app_bundle_qs.annotate(
|
|
|
model=F('app_device_type__model'), type=F('app_device_type__type'), icon=F('app_device_type__icon'),
|
|
|
- lang=F('app_device_type__devicenamelanguage__lang'),
|
|
|
+ lang=F('app_device_type__devicenamelanguage__lang'), iconV2=F('app_device_type__iconV2'),
|
|
|
name=F('app_device_type__devicenamelanguage__name'),
|
|
|
sort=F('app_device_type__devicenamelanguage__sort')).values('id', 'app_device_type__id', 'model',
|
|
|
- 'type', 'icon', 'app_bundle_id',
|
|
|
+ 'type', 'icon', 'iconV2', 'app_bundle_id',
|
|
|
'app_device_type__devicenamelanguage__id',
|
|
|
'lang', 'name', 'sort',
|
|
|
'app_device_type__app_version_number_id',
|
|
@@ -595,12 +594,13 @@ class DeviceManagement(View):
|
|
|
model = request_dict.get('model', None)
|
|
|
type = request_dict.get('type', None)
|
|
|
icon = request.FILES.get('icon', None)
|
|
|
+ iconV2 = request.FILES.get('iconV2', None)
|
|
|
# device_name_language表数据
|
|
|
device_name_language_id = request_dict.get('app_device_type__devicenamelanguage__id', None)
|
|
|
sort = request_dict.get('sort', None)
|
|
|
version_number = request_dict.get('version_number', None)
|
|
|
config = request_dict.get('config', None)
|
|
|
-
|
|
|
+ now_time = int(time.time())
|
|
|
if not all([app_device_type_id, device_name_language_id, model, type, sort, version_number]):
|
|
|
return response.json(444)
|
|
|
|
|
@@ -610,40 +610,69 @@ class DeviceManagement(View):
|
|
|
|
|
|
try:
|
|
|
with transaction.atomic():
|
|
|
- if icon:
|
|
|
- icon_path = 'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{}'.format(icon)
|
|
|
+ if icon or iconV2:
|
|
|
+ bucket_name = 'ansjerfilemanager'
|
|
|
+ s3 = AmazonS3Util(AWS_ACCESS_KEY_ID[1], AWS_SECRET_ACCESS_KEY[1], AWS_SES_ACCESS_REGION)
|
|
|
+ icon_path = ""
|
|
|
+ icon_v2_path = ""
|
|
|
+
|
|
|
+ # 处理 icon
|
|
|
+ if icon:
|
|
|
+ file_key = f'app/device_type_images/{now_time}_{icon.name}'
|
|
|
+ icon_path = f'https://{bucket_name}.s3.amazonaws.com/{file_key}'
|
|
|
+ s3.upload_file_obj(
|
|
|
+ bucket_name,
|
|
|
+ file_key,
|
|
|
+ icon,
|
|
|
+ {'ContentType': icon.content_type, 'ACL': 'public-read'}
|
|
|
+ )
|
|
|
+
|
|
|
+ # 处理 iconV2
|
|
|
+ if iconV2:
|
|
|
+ file_v2_key = f'app/device_type_images/{now_time}_v2_{iconV2.name}'
|
|
|
+ icon_v2_path = f'https://{bucket_name}.s3.amazonaws.com/{file_v2_key}'
|
|
|
+ s3.upload_file_obj(
|
|
|
+ bucket_name,
|
|
|
+ file_v2_key,
|
|
|
+ iconV2,
|
|
|
+ {'ContentType': iconV2.content_type, 'ACL': 'public-read'}
|
|
|
+ )
|
|
|
+ # 更新数据库
|
|
|
+ update_fields = {
|
|
|
+ 'model': model,
|
|
|
+ 'type': type,
|
|
|
+ 'app_version_number_id': version_number,
|
|
|
+ }
|
|
|
if config:
|
|
|
try:
|
|
|
config = json.loads(config)
|
|
|
- except:
|
|
|
+ update_fields['config'] = config
|
|
|
+ except ValueError:
|
|
|
return response.json(444, 'config必须是一个json数据')
|
|
|
- AppDeviceType.objects.filter(id__in=list_app_device_type_id) \
|
|
|
- .update(model=model, type=type, icon=icon_path, app_version_number_id=version_number,
|
|
|
- config=config)
|
|
|
- else:
|
|
|
- AppDeviceType.objects.filter(id__in=list_app_device_type_id) \
|
|
|
- .update(model=model, type=type, icon=icon_path, app_version_number_id=version_number)
|
|
|
- bucket_name = 'ansjerfilemanager'
|
|
|
- file_key = 'app/device_type_images/{}'.format(icon)
|
|
|
- s3 = AmazonS3Util(AWS_ACCESS_KEY_ID[1], AWS_SECRET_ACCESS_KEY[1], AWS_SES_ACCESS_REGION)
|
|
|
- # 地址:https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/camera_c190.png
|
|
|
- s3.upload_file_obj(
|
|
|
- bucket_name,
|
|
|
- file_key,
|
|
|
- icon,
|
|
|
- {'ContentType': icon.content_type, 'ACL': 'public-read'})
|
|
|
+
|
|
|
+ if icon_path:
|
|
|
+ update_fields['icon'] = icon_path
|
|
|
+
|
|
|
+ if icon_v2_path:
|
|
|
+ update_fields['iconV2'] = icon_v2_path
|
|
|
+
|
|
|
+ AppDeviceType.objects.filter(id__in=list_app_device_type_id).update(**update_fields)
|
|
|
+
|
|
|
else:
|
|
|
+ # 没有上传文件的情况,只更新配置或基本信息
|
|
|
+ update_fields = {
|
|
|
+ 'model': model,
|
|
|
+ 'type': type,
|
|
|
+ 'app_version_number_id': version_number,
|
|
|
+ }
|
|
|
if config:
|
|
|
try:
|
|
|
config = json.loads(config)
|
|
|
- except:
|
|
|
+ update_fields['config'] = config
|
|
|
+ except ValueError:
|
|
|
return response.json(444, 'config必须是一个json数据')
|
|
|
- AppDeviceType.objects.filter(id__in=list_app_device_type_id) \
|
|
|
- .update(model=model, type=type, app_version_number_id=version_number,
|
|
|
- config=config)
|
|
|
- else:
|
|
|
- AppDeviceType.objects.filter(id__in=list_app_device_type_id) \
|
|
|
- .update(model=model, type=type, app_version_number_id=version_number)
|
|
|
+
|
|
|
+ AppDeviceType.objects.filter(id__in=list_app_device_type_id).update(**update_fields)
|
|
|
DeviceNameLanguage.objects.filter(id__in=list_device_name_language_id).update(sort=sort)
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
@@ -657,6 +686,7 @@ class DeviceManagement(View):
|
|
|
model = request_dict.get('model', None)
|
|
|
type = request_dict.get('type', None)
|
|
|
icon = request.FILES.get('icon', None)
|
|
|
+ iconV2 = request.FILES.get('iconV2', None)
|
|
|
# device_name_language表数据
|
|
|
device_name_language_id = request_dict.get('app_device_type__devicenamelanguage__id', None)
|
|
|
lang = request_dict.get('lang', None)
|
|
@@ -664,33 +694,45 @@ class DeviceManagement(View):
|
|
|
sort = request_dict.get('sort', None)
|
|
|
version_number = request_dict.get('version_number', None)
|
|
|
config = request_dict.get('config', None)
|
|
|
-
|
|
|
+ now_time = int(time.time())
|
|
|
if not all([app_device_type_id, model, type, device_name_language_id, lang, name, sort]):
|
|
|
return response.json(444)
|
|
|
try:
|
|
|
with transaction.atomic():
|
|
|
- if icon:
|
|
|
- icon_path = 'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{}'.format(icon)
|
|
|
+ app_device_type = AppDeviceType.objects.filter(id=app_device_type_id).first()
|
|
|
+ if icon or iconV2:
|
|
|
+ bucket_name = 'ansjerfilemanager'
|
|
|
+ s3 = AmazonS3Util(AWS_ACCESS_KEY_ID[1], AWS_SECRET_ACCESS_KEY[1], AWS_SES_ACCESS_REGION)
|
|
|
+ icon_path = app_device_type.icon
|
|
|
+ icon_v2_path = app_device_type.iconV2
|
|
|
+ if icon:
|
|
|
+ icon_path = f'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{now_time}_{icon.name}'
|
|
|
+ file_key = f'app/device_type_images/{now_time}_{icon.name}'
|
|
|
+ s3.upload_file_obj(
|
|
|
+ bucket_name,
|
|
|
+ file_key,
|
|
|
+ icon,
|
|
|
+ {'ContentType': icon.content_type, 'ACL': 'public-read'})
|
|
|
+ if iconV2:
|
|
|
+ icon_v2_path = f'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{now_time}_v2_{iconV2.name}'
|
|
|
+ file_v2_key = f'app/device_type_images/{now_time}_v2_{iconV2.name}'
|
|
|
+ s3.upload_file_obj(
|
|
|
+ bucket_name,
|
|
|
+ file_v2_key,
|
|
|
+ iconV2,
|
|
|
+ {'ContentType': iconV2.content_type, 'ACL': 'public-read'})
|
|
|
if config:
|
|
|
try:
|
|
|
config = json.loads(config)
|
|
|
except:
|
|
|
return response.json(444, 'config必须是一个json数据')
|
|
|
AppDeviceType.objects.filter(id=app_device_type_id) \
|
|
|
- .update(model=model, type=type, icon=icon_path, app_version_number_id=version_number,
|
|
|
- config=config)
|
|
|
+ .update(model=model, type=type, icon=icon_path, iconV2=icon_v2_path,
|
|
|
+ app_version_number_id=version_number, config=config)
|
|
|
else:
|
|
|
AppDeviceType.objects.filter(id=app_device_type_id) \
|
|
|
- .update(model=model, type=type, icon=icon_path, app_version_number_id=version_number)
|
|
|
- bucket_name = 'ansjerfilemanager'
|
|
|
- file_key = 'app/device_type_images/{}'.format(icon)
|
|
|
- s3 = AmazonS3Util(AWS_ACCESS_KEY_ID[1], AWS_SECRET_ACCESS_KEY[1], AWS_SES_ACCESS_REGION)
|
|
|
- # 地址:https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/camera_c190.png
|
|
|
- s3.upload_file_obj(
|
|
|
- bucket_name,
|
|
|
- file_key,
|
|
|
- icon,
|
|
|
- {'ContentType': icon.content_type, 'ACL': 'public-read'})
|
|
|
+ .update(model=model, type=type, icon=icon_path, iconV2=icon_v2_path,
|
|
|
+ app_version_number_id=version_number)
|
|
|
else:
|
|
|
if config:
|
|
|
try:
|
|
@@ -716,9 +758,22 @@ class DeviceManagement(View):
|
|
|
if not all([app_bundle_id, app_device_type_id]):
|
|
|
return response.json(444)
|
|
|
try:
|
|
|
+ # 删除语言表
|
|
|
+ DeviceNameLanguage.objects.filter(app_device_type_id=app_device_type_id).delete()
|
|
|
+ # 删除保存的图片
|
|
|
+ app_device_type = AppDeviceType.objects.filter(id=app_device_type_id).first()
|
|
|
+ if app_device_type:
|
|
|
+ path = app_device_type.icon.split('/')[-1]
|
|
|
+ pathV2 = app_device_type.iconV2.split('/')[-1]
|
|
|
+ s3 = AmazonS3Util(AWS_ACCESS_KEY_ID[1], AWS_SECRET_ACCESS_KEY[1], AWS_SES_ACCESS_REGION)
|
|
|
+ bucket_name = 'ansjerfilemanager'
|
|
|
+ s3.delete_obj(bucket_name, f"app/device_type_images/{path}")
|
|
|
+ s3.delete_obj(bucket_name, f"app/device_type_images/{pathV2}")
|
|
|
+ # 删除多对多关系
|
|
|
app_bundle_qs = AppBundle.objects.get(id=app_bundle_id)
|
|
|
- app_device_type_qs = AppDeviceType.objects.filter(id=app_device_type_id)
|
|
|
- app_bundle_qs.app_device_type.remove(*app_device_type_qs)
|
|
|
+ app_bundle_qs.app_device_type.remove(app_device_type_id)
|
|
|
+ # 删除app类型表
|
|
|
+ AppDeviceType.objects.filter(id=app_device_type_id).delete()
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
@@ -790,6 +845,7 @@ class DeviceManagement(View):
|
|
|
config = request_dict.get('config', None)
|
|
|
# 上传图标
|
|
|
file = request.FILES.get('iconFile', None)
|
|
|
+ file_v2 = request.FILES.get('iconV2File', None)
|
|
|
if config:
|
|
|
config = json.loads(config)
|
|
|
try:
|
|
@@ -822,14 +878,25 @@ class DeviceManagement(View):
|
|
|
# 如果需要上传文件
|
|
|
if need_upload:
|
|
|
with transaction.atomic():
|
|
|
- fileName = file.name
|
|
|
- now_time = int(time.time())
|
|
|
- response_url = f'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{now_time}_{fileName}'
|
|
|
- bucket_name = 'ansjerfilemanager'
|
|
|
- file_key = f'app/device_type_images/{now_time}_{fileName}'
|
|
|
- s3 = AmazonS3Util(AWS_ACCESS_KEY_ID[1], AWS_SECRET_ACCESS_KEY[1], AWS_SES_ACCESS_REGION)
|
|
|
- s3.upload_file_obj(bucket_name, file_key, file,
|
|
|
- {'ContentType': file.content_type, 'ACL': 'public-read'})
|
|
|
+ if file:
|
|
|
+ fileName = file.name
|
|
|
+ now_time = int(time.time())
|
|
|
+ icon = f'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{now_time}_{fileName}'
|
|
|
+ bucket_name = 'ansjerfilemanager'
|
|
|
+ file_key = f'app/device_type_images/{now_time}_{fileName}'
|
|
|
+ s3 = AmazonS3Util(AWS_ACCESS_KEY_ID[1], AWS_SECRET_ACCESS_KEY[1], AWS_SES_ACCESS_REGION)
|
|
|
+ s3.upload_file_obj(bucket_name, file_key, file,
|
|
|
+ {'ContentType': file.content_type, 'ACL': 'public-read'})
|
|
|
+ if file_v2:
|
|
|
+ fileV2Name = file_v2.name
|
|
|
+ now_time = int(time.time())
|
|
|
+ iconV2 = f'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{now_time}_v2_{fileV2Name}'
|
|
|
+ bucket_name = 'ansjerfilemanager'
|
|
|
+ file_v2_key = f'app/device_type_images/{now_time}_v2_{fileV2Name}'
|
|
|
+ s3 = AmazonS3Util(AWS_ACCESS_KEY_ID[1], AWS_SECRET_ACCESS_KEY[1], AWS_SES_ACCESS_REGION)
|
|
|
+ s3.upload_file_obj(bucket_name, file_v2_key, file_v2,
|
|
|
+ {'ContentType': file_v2.content_type, 'ACL': 'public-read'})
|
|
|
+
|
|
|
for app_id in app_bundle_id:
|
|
|
for k, v in data_name.items():
|
|
|
record_key = {"app_bundle_id": app_id, "type": type, "version_number": version_number,
|
|
@@ -838,7 +905,8 @@ class DeviceManagement(View):
|
|
|
if not any(rec == record_key for rec in existing_records):
|
|
|
app_bundle = AppBundle.objects.filter(id=app_id).values('id', 'app_bundle_id').first()
|
|
|
app_device_type_qs = AppDeviceType.objects.create(model=model, type=type,
|
|
|
- icon=response_url,
|
|
|
+ icon=icon if file else "",
|
|
|
+ iconV2=iconV2 if file_v2 else "",
|
|
|
app_version_number_id=version_number,
|
|
|
config=config)
|
|
|
DeviceNameLanguage.objects.create(lang=k, name=v, sort=sort,
|
|
@@ -873,6 +941,9 @@ class DeviceManagement(View):
|
|
|
lang = request_dict.get('lang', 'en')
|
|
|
app_bundle_id = request_dict.get('appBundleId', None)
|
|
|
version_number = request_dict.get('versionNumber', None)
|
|
|
+ # 查询设备信息图标
|
|
|
+ api_version = request_dict.get('apiVersion', None)
|
|
|
+
|
|
|
if not all([lang, app_bundle_id, version_number]):
|
|
|
return response.json(444)
|
|
|
try:
|
|
@@ -897,22 +968,37 @@ class DeviceManagement(View):
|
|
|
app_device_type__app_version_number_id=version_number). \
|
|
|
annotate(
|
|
|
model=F('app_device_type__model'), type=F('app_device_type__type'), icon=F('app_device_type__icon'),
|
|
|
- name=F('app_device_type__devicenamelanguage__name'),
|
|
|
+ name=F('app_device_type__devicenamelanguage__name'), iconV2=F('app_device_type__iconV2'),
|
|
|
sort=F('app_device_type__devicenamelanguage__sort'),
|
|
|
config=F('app_device_type__config'),
|
|
|
app_version_number_id=F('app_device_type__app_version_number_id')).values('model', 'type', 'icon',
|
|
|
'name', 'sort', 'config',
|
|
|
+ 'iconV2',
|
|
|
'app_device_type__app_version_number_id')
|
|
|
- for app_bundle in app_bundle_qs:
|
|
|
- app_bundle_list.append({
|
|
|
- 'model': app_bundle['model'],
|
|
|
- 'type': app_bundle['type'],
|
|
|
- 'icon': app_bundle['icon'],
|
|
|
- 'name': app_bundle['name'],
|
|
|
- 'sort': app_bundle['sort'],
|
|
|
- 'config': app_bundle['config'],
|
|
|
- 'app_device_type__app_version_number_id': app_bundle['app_device_type__app_version_number_id'],
|
|
|
- })
|
|
|
+ if api_version == "V2":
|
|
|
+ for app_bundle in app_bundle_qs:
|
|
|
+ app_bundle_list.append({
|
|
|
+ 'model': app_bundle['model'],
|
|
|
+ 'type': app_bundle['type'],
|
|
|
+ 'icon': app_bundle['iconV2'] if app_bundle['iconV2'] != "" else app_bundle['icon'],
|
|
|
+ 'name': app_bundle['name'],
|
|
|
+ 'sort': app_bundle['sort'],
|
|
|
+ 'config': app_bundle['config'],
|
|
|
+ 'app_device_type__app_version_number_id': app_bundle[
|
|
|
+ 'app_device_type__app_version_number_id'],
|
|
|
+ })
|
|
|
+ else:
|
|
|
+ for app_bundle in app_bundle_qs:
|
|
|
+ app_bundle_list.append({
|
|
|
+ 'model': app_bundle['model'],
|
|
|
+ 'type': app_bundle['type'],
|
|
|
+ 'icon': app_bundle['icon'],
|
|
|
+ 'name': app_bundle['name'],
|
|
|
+ 'sort': app_bundle['sort'],
|
|
|
+ 'config': app_bundle['config'],
|
|
|
+ 'app_device_type__app_version_number_id': app_bundle[
|
|
|
+ 'app_device_type__app_version_number_id'],
|
|
|
+ })
|
|
|
dvr_list = [app_bundle for app_bundle in app_bundle_list if app_bundle['model'] == 1]
|
|
|
ipc_list = [app_bundle for app_bundle in app_bundle_list if app_bundle['model'] == 2]
|
|
|
res = {
|
|
@@ -1036,13 +1122,16 @@ class DeviceManagement(View):
|
|
|
config = request_dict.get('config', None)
|
|
|
# 上传图标
|
|
|
files = request.FILES.get('iconFile', None)
|
|
|
+ # 上传图标
|
|
|
+ files_v2 = request.FILES.get('iconV2File', None)
|
|
|
# 需要添加到哪一个服
|
|
|
region = request_dict.get("region", None) # 获取需要同步的区域
|
|
|
|
|
|
# 检查必需参数
|
|
|
- if not all([model, type, name, sort, version_number, files, app_bundle_name, region]):
|
|
|
+ if not all([model, type, name, sort, version_number, app_bundle_name, region]):
|
|
|
+ return response.json(444, 'Missing required parameters')
|
|
|
+ if files is None and files_v2 is None:
|
|
|
return response.json(444, 'Missing required parameters')
|
|
|
-
|
|
|
regions = region.split(",") # 将同步区域拆分为列表
|
|
|
return_value_list = []
|
|
|
for region in regions:
|
|
@@ -1075,7 +1164,7 @@ class DeviceManagement(View):
|
|
|
# 发送 POST 请求调用 add_app_device_type 方法
|
|
|
response_value = requests.post(url + "/deviceManagement/addAppDeviceType",
|
|
|
data=form_data,
|
|
|
- files={'iconFile': files})
|
|
|
+ files={'iconFile': files, 'iconV2File': files_v2})
|
|
|
return_value = {region: response_value.json()["data"]}
|
|
|
return_value_list.append(return_value)
|
|
|
except Exception as e:
|
|
@@ -1147,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:
|
|
|
# 构建查询条件
|
|
@@ -1175,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,
|
|
@@ -1198,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,
|
|
@@ -1212,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)
|