瀏覽代碼

app设备类型的添加功能和获取app版本表

guanhailong 3 年之前
父節點
當前提交
36db8bcf61
共有 1 個文件被更改,包括 56 次插入4 次删除
  1. 56 4
      AdminController/DeviceManagementController.py

+ 56 - 4
AdminController/DeviceManagementController.py

@@ -72,13 +72,52 @@ class DeviceManagement(View):
                 return self.edit_app_device_type(request_dict, response)
             elif operation == 'deleteAppDeviceType':  # 删除app设备类型数据
                 return self.delete_app_device_type(request_dict, response)
-            elif operation == 'addAppDeviceType':# 添加app设备类型数据
+            elif operation == 'addAppDeviceType':  # 添加app设备类型数据
                 return self.add_app_device_type(request_dict, response)
+            elif operation == 'getAppBundle':  # 获取app版本包
+                return self.get_app_bundle(response)
+            elif operation == 'upFile':
+                return self.up_file(request_dict, response)
             else:
                 return response.json(444, 'operation')
 
+    @staticmethod
+    def up_file(request_dict, response):
+
+        model = request_dict.get('model', None)
+        type = request_dict.get('type', None)
+        icon = request_dict.get('icon', None)
+        lang = request_dict.get('lang', None)
+        name = request_dict.get('name', None)
+        sort = request_dict.get('sort', None)
+
+        if not all([model, type, icon, lang, name, sort]):
+            return response.json(444)
+        model = int(model)
+        auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
+        bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'ansjer-static-resources')
+        key = '' + icon  # 选择存放图片的位置
+        # 地址:
+        pass
+
+    @classmethod
+    def get_app_bundle(cls, response):
+        app_bundle_qs = AppBundle.objects.all().values('id', 'app_bundle_id')
+        if not app_bundle_qs.exists():
+            return response.json(444)
+        try:
+            app_bundle_list = []
+            for app_bundle in app_bundle_qs:
+                app_bundle_qs.exists()
+                app_bundle_list.append(app_bundle)
+            return response.json(0, app_bundle_list)
+        except Exception as e:
+            return response.json(500, e)
+
     @staticmethod
     def add_app_device_type(request_dict, response):
+        # 添加APP设备类型
+        id = request_dict.get('id', None)
         # app_device_type表数据
         model = request_dict.get('model', None)
         type = request_dict.get('type', None)
@@ -91,12 +130,15 @@ class DeviceManagement(View):
         if not all([model, type, icon, lang, name, sort]):
             return response.json(444)
         type = int(type)
-        model = int(model)
 
         try:
             with transaction.atomic():
-                app_device_qs = AppDeviceType.objects.create(model=model, type=type, icon=icon)
-                DeviceNameLanguage.objects.create(lang=lang, name=name, sort=sort, app_device_type_id=app_device_qs.id)
+                app_device_type_qs = AppDeviceType.objects.create(model=model, type=type, icon=icon)
+                DeviceNameLanguage.objects.create(lang=lang, name=name, sort=sort,
+                                                  app_device_type_id=app_device_type_qs.id)
+                app_bundle_qs = AppBundle.objects.filter(id=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)
         except Exception as e:
             print(e)
@@ -409,6 +451,9 @@ class DeviceManagement(View):
     def get_app_device_type_list(request_dict, response):
         app_bundle_id = request_dict.get('appBundleId', None)
         lang = request_dict.get('lang', 'cn')
+        model = request_dict.get('model', None)
+        type = request_dict.get('type', None)
+        name = request_dict.get('name', None)
 
         pageNo = request_dict.get('pageNo', None)
         pageSize = request_dict.get('pageSize', None)
@@ -418,12 +463,19 @@ class DeviceManagement(View):
 
         page = int(pageNo)
         line = int(pageSize)
+
         try:
             if not app_bundle_id:
                 app_bundle_id = 'com.ansjer.zccloud'
             app_bundle_qs = AppBundle.objects.filter(app_bundle_id=app_bundle_id)
             if lang:
                 app_bundle_qs = app_bundle_qs.filter(app_device_type__devicenamelanguage__lang=lang)
+            if name:
+                app_bundle_qs = app_bundle_qs.filter(app_device_type__devicenamelanguage__name=name)
+            if model:
+                app_bundle_qs = app_bundle_qs.filter(app_device_type__model=model)
+            if type:
+                app_bundle_qs = app_bundle_qs.filter(app_device_type__type=type)
 
             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'),