Эх сурвалжийг харах

批量编辑APP设备类型

linhaohong 1 жил өмнө
parent
commit
2c744e09bf

+ 44 - 0
AdminController/DeviceManagementController.py

@@ -78,6 +78,8 @@ class DeviceManagement(View):
                 return self.get_app_bundle_id_list(response)
             elif operation == 'editAppDeviceType':  # 编辑app设备类型数据
                 return self.edit_app_device_type(request_dict, request, response)
+            elif operation == 'batchEditAppDeviceType':  # 批量编辑app设备类型数据
+                return self.batch_edit_app_device_type(request_dict, request, response)
             elif operation == 'deleteAppDeviceType':  # 删除app设备类型数据
                 return self.delete_app_device_type(request_dict, response)
             elif operation == 'getAppBundle':  # 获取app版本包
@@ -532,6 +534,48 @@ class DeviceManagement(View):
             print(e)
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
+    @staticmethod
+    def batch_edit_app_device_type(request_dict, request, response):
+        # app_device_type表数据
+        app_device_type_id = request_dict.get('app_device_type__id',None)
+        model = request_dict.get('model', None)
+        type = request_dict.get('type', None)
+        icon = request.FILES.get('icon', 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)
+        if not all([app_device_type_id,device_name_language_id, model, type, sort,version_number]):
+             return response.json(444)
+
+        #强制类型转换
+        list_app_device_type_id = [int(item) for item in eval(app_device_type_id)]
+        list_device_name_language_id = [int(item) for item in eval(device_name_language_id)]
+
+        try:
+            with transaction.atomic():
+                if icon:
+                    icon_path = 'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{}'.format(icon)
+                    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'})
+                else:
+                    AppDeviceType.objects.filter(id__in=list_app_device_type_id) \
+                        .update(model=model, type=type, app_version_number_id=version_number)
+                DeviceNameLanguage.objects.filter(id__in=list_device_name_language_id).update(sort=sort)
+            return response.json(0)
+        except Exception as e:
+            print(e)
+            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+
     @staticmethod
     def edit_app_device_type(request_dict, request, response):
         # app_device_type表数据