浏览代码

Merge branch 'test' of http://192.168.136.99:3000/servers/ASJServer into peng

peng 1 年之前
父节点
当前提交
9ca2be2d49
共有 3 个文件被更改,包括 116 次插入49 次删除
  1. 114 48
      AdminController/DeviceManagementController.py
  2. 1 1
      AdminController/VersionManagementController.py
  3. 1 0
      Model/models.py

+ 114 - 48
AdminController/DeviceManagementController.py

@@ -545,10 +545,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',
@@ -590,12 +590,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)
 
@@ -605,28 +606,40 @@ 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 = ""
+                    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__in=list_app_device_type_id) \
-                            .update(model=model, type=type, icon=icon_path, app_version_number_id=version_number,
+                            .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__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'})
+                            .update(model=model, type=type, icon=icon_path, iconV2=icon_v2_path,
+                                    app_version_number_id=version_number)
                 else:
                     if config:
                         try:
@@ -652,6 +665,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)
@@ -659,33 +673,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)
+                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 = ""
+                    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,
+                            .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:
@@ -711,9 +737,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)
@@ -785,6 +824,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:
@@ -818,13 +858,18 @@ class DeviceManagement(View):
             if need_upload:
                 with transaction.atomic():
                     fileName = file.name
+                    fileV2Name = file_v2.name
                     now_time = int(time.time())
-                    response_url = f'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{now_time}_{fileName}'
+                    icon = f'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{now_time}_{fileName}'
+                    iconV2 = f'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/{now_time}_v2_{fileV2Name}'
                     bucket_name = 'ansjerfilemanager'
                     file_key = f'app/device_type_images/{now_time}_{fileName}'
+                    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_key, file,
                                        {'ContentType': file.content_type, 'ACL': 'public-read'})
+                    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,
@@ -833,7 +878,7 @@ 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, iconV2=iconV2,
                                                                                   app_version_number_id=version_number,
                                                                                   config=config)
                                 DeviceNameLanguage.objects.create(lang=k, name=v, sort=sort,
@@ -868,6 +913,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:
@@ -892,22 +940,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 = {
@@ -1031,13 +1094,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:
@@ -1070,7 +1136,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:

+ 1 - 1
AdminController/VersionManagementController.py

@@ -102,7 +102,7 @@ class VersionManagement(View):
         line = int(pageSize)
 
         try:
-            equipment_version_qs = Equipment_Version.objects.filter()
+            equipment_version_qs = Equipment_Version.objects.filter().order_by('-update_time')
             if mci:
                 equipment_version_qs = equipment_version_qs.filter(mci=mci)
             if lang:

+ 1 - 0
Model/models.py

@@ -2875,6 +2875,7 @@ class AppDeviceType(models.Model):
     model = models.SmallIntegerField(default=0, verbose_name='设备类型')
     type = models.IntegerField(default=0, verbose_name='设备型号')
     icon = models.CharField(default='', max_length=200, verbose_name='图标文件路径')
+    iconV2 = models.CharField(default='', max_length=200, verbose_name='新版APP图标文件路径')
     config = models.JSONField(null=True, verbose_name='关联配网方式、网络频段配置json')
     app_version_number_id = models.CharField(default='', max_length=32, verbose_name='关联APP版本号表id')