|
@@ -98,7 +98,9 @@ class DeviceManagement(View):
|
|
@staticmethod
|
|
@staticmethod
|
|
def add_app_device_type(request_dict, response, request):
|
|
def add_app_device_type(request_dict, response, request):
|
|
# 添加APP设备类型
|
|
# 添加APP设备类型
|
|
- app_bundle_name = request_dict.get('appbundleName', None)
|
|
|
|
|
|
+ app_bundle_name = request_dict.get(
|
|
|
|
+ 'appbundleName', '')[
|
|
|
|
+ 1:-1].split(',') # '[1,2]' -> ['1','2']
|
|
app_bundle_id = request_dict.get(
|
|
app_bundle_id = request_dict.get(
|
|
'app_bundle_id', '')[
|
|
'app_bundle_id', '')[
|
|
1:-1].split(',') # '[1,2]' -> ['1','2']
|
|
1:-1].split(',') # '[1,2]' -> ['1','2']
|
|
@@ -119,12 +121,22 @@ class DeviceManagement(View):
|
|
|
|
|
|
try:
|
|
try:
|
|
with transaction.atomic():
|
|
with transaction.atomic():
|
|
-
|
|
|
|
|
|
+ # 判断包是否存在,并创建
|
|
|
|
+ new_bundle_list = []
|
|
|
|
+ for bundle_name in app_bundle_name:
|
|
|
|
+ if not bundle_name == '':
|
|
|
|
+ app_bundle_name_qs = AppBundle.objects.filter(app_bundle_id=bundle_name).values('id')
|
|
|
|
+ if not app_bundle_name_qs.exists():
|
|
|
|
+ app_bundle_name_qs.create(app_bundle_id=bundle_name)
|
|
|
|
+ app_bundle_qs = AppBundle.objects.filter(app_bundle_id=bundle_name).values('id')
|
|
|
|
+ id = app_bundle_qs[0]['id']
|
|
|
|
+ new_bundle_list.append(id)
|
|
for app_id in app_bundle_id:
|
|
for app_id in app_bundle_id:
|
|
- app_bundle_qs = AppBundle.objects.filter(id=app_id).values('id')
|
|
|
|
- if not app_bundle_qs.exists():
|
|
|
|
- AppBundle.objects.create(app_bundle_id=app_bundle_name, id=app_id)
|
|
|
|
- return response.json(0)
|
|
|
|
|
|
+ if not app_id == '':
|
|
|
|
+ app_bundle_qs = AppBundle.objects.filter(id=app_id).values('id')
|
|
|
|
+ if not app_bundle_qs.exists():
|
|
|
|
+ AppBundle.objects.create(app_bundle_id=app_bundle_name, id=app_id)
|
|
|
|
+ #判断数据是否存在,是否上传
|
|
app_device_type_qs = AppDeviceType.objects.filter(type=type).values()
|
|
app_device_type_qs = AppDeviceType.objects.filter(type=type).values()
|
|
if app_device_type_qs.exists():
|
|
if app_device_type_qs.exists():
|
|
return response.json(174)
|
|
return response.json(174)
|
|
@@ -136,15 +148,22 @@ class DeviceManagement(View):
|
|
# 地址:https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/camera_c190.png
|
|
# 地址:https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/camera_c190.png
|
|
s3.upload_file_obj(bucket, file_key, file,
|
|
s3.upload_file_obj(bucket, file_key, file,
|
|
{'ContentType': file.content_type, 'ACL': 'public-read'})
|
|
{'ContentType': file.content_type, 'ACL': 'public-read'})
|
|
- response_url = 'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/'+format(fileName)
|
|
|
|
|
|
+ response_url = 'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/' + format(fileName)
|
|
app_device_type_qs = AppDeviceType.objects.create(model=model, type=type, icon=response_url)
|
|
app_device_type_qs = AppDeviceType.objects.create(model=model, type=type, icon=response_url)
|
|
DeviceNameLanguage.objects.create(lang=lang, name=name, sort=sort,
|
|
DeviceNameLanguage.objects.create(lang=lang, name=name, sort=sort,
|
|
app_device_type_id=app_device_type_qs.id)
|
|
app_device_type_id=app_device_type_qs.id)
|
|
|
|
+ # 关联包
|
|
for app_id in app_bundle_id:
|
|
for app_id in app_bundle_id:
|
|
|
|
+ if app_id == '':
|
|
|
|
+ for app_id in new_bundle_list:
|
|
|
|
+ app_bundle_qs = AppBundle.objects.filter(id=app_id).values('id')
|
|
|
|
+ app_bundle_qs = app_bundle_qs[0]['id']
|
|
|
|
+ app_device_type_qs.appbundle_set.add(app_bundle_qs)
|
|
|
|
+ return response.json(0)
|
|
app_bundle_qs = AppBundle.objects.filter(id=app_id).values('id')
|
|
app_bundle_qs = AppBundle.objects.filter(id=app_id).values('id')
|
|
app_bundle_qs = app_bundle_qs[0]['id']
|
|
app_bundle_qs = app_bundle_qs[0]['id']
|
|
app_device_type_qs.appbundle_set.add(app_bundle_qs)
|
|
app_device_type_qs.appbundle_set.add(app_bundle_qs)
|
|
- return response.json(0)
|
|
|
|
|
|
+ return response.json(0)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print(e)
|
|
print(e)
|
|
return response.json(500, repr(e))
|
|
return response.json(500, repr(e))
|