Browse Source

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

peng 3 years ago
parent
commit
0f38cd2be0

+ 51 - 21
AdminController/DeviceManagementController.py

@@ -8,10 +8,12 @@ from django.db import transaction
 from django.db.models import Q, F
 from django.views.generic.base import View
 
-from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
+from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, \
+    AWS_SES_ACCESS_REGION
 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
+from Object.AWS.AmazonS3Util import AmazonS3Util
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Service.CommonService import CommonService
@@ -40,6 +42,8 @@ class DeviceManagement(View):
         elif operation == 'getDeviceIcon':  # app获取设备图标
             response = ResponseObject(language)
             return self.get_device_icon(request_dict, response)
+        elif operation == 'addAppDeviceType':  # 添加app设备类型数据并上传图标
+            return self.add_app_device_type(request_dict, response, request)
         else:
             tko = TokenObject(
                 request.META.get('HTTP_AUTHORIZATION'),
@@ -72,20 +76,12 @@ 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设备类型数据
-                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, request, response)
             else:
                 return response.json(444, 'operation')
 
-    @staticmethod
-    def up_file(request_dict, request, response):
-        pass
-
-
     @classmethod
     def get_app_bundle(cls, response):
         app_bundle_qs = AppBundle.objects.all().values('id', 'app_bundle_id')
@@ -101,40 +97,74 @@ class DeviceManagement(View):
             return response.json(500, e)
 
     @staticmethod
-    def add_app_device_type(request_dict, response):
+    def add_app_device_type(request_dict, response, request):
         # 添加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', '')[
-                     1:-1].split(',')  # '[1,2]' -> ['1','2']
+                        1:-1].split(',')  # '[1,2]' -> ['1','2']
         # app_device_type表数据
         model = request_dict.get('model', None)
         type = request_dict.get('type', None)
-        icon = request_dict.get('icon', None)
         # device_name_language表数据
         lang = request_dict.get('lang', None)
         name = request_dict.get('name', None)
         sort = request_dict.get('sort', None)
+        # 上传图标
+        file = request.FILES.get('iconFile', None)
+        fileName = file.name
 
-        if not all([model, type, icon, lang, name, sort]):
+        if not all([model, type, lang, name, sort]):
             return response.json(444)
         type = int(type)
 
         try:
             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:
-                    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)
-                app_device_type_qs = AppDeviceType.objects.create(model=model, type=type, icon=icon)
+                    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()
+                if app_device_type_qs.exists():
+                    return response.json(174)
+                # S3下文件夹路径+文件名 组成对象key
+                file_key = 'app/device_type_images/{}'.format(fileName)
+                s3 = AmazonS3Util(AWS_ACCESS_KEY_ID[1], AWS_SECRET_ACCESS_KEY[1], AWS_SES_ACCESS_REGION)
+                # 存储桶
+                bucket = 'ansjerfilemanager'
+                # 地址:https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/camera_c190.png
+                s3.upload_file_obj(bucket, file_key, file,
+                                   {'ContentType': file.content_type, 'ACL': 'public-read'})
+                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)
                 DeviceNameLanguage.objects.create(lang=lang, name=name, sort=sort,
                                                   app_device_type_id=app_device_type_qs.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 = app_bundle_qs[0]['id']
                     app_device_type_qs.appbundle_set.add(app_bundle_qs)
-            return response.json(0)
+                return response.json(0)
         except Exception as e:
             print(e)
             return response.json(500, repr(e))

+ 1 - 1
Controller/SensorGateway/GatewayFamilyMemberController.py

@@ -259,7 +259,7 @@ class GatewayFamilyMemberView(View):
                     'addTime': now_time,
                     'updTime': now_time,
                     'userID_id': family_join['user_id'] if join_type == 1 else family_join['family__user_id'],
-                    'eventType': 0
+                    'eventType': 705
                 }
                 if confirm == 'confirm':
                     msg_text = cls.get_confirm_text(nick_name, family_name, join_type, True, lang)

+ 10 - 6
Controller/SensorGateway/GatewayFamilyRoomController.py

@@ -249,6 +249,11 @@ class GatewayFamilyRoomView(View):
         family_id = request_dict.get('familyId', None)
         if not family_id:
             return response.json(444)
+        device_room = {
+            'gateways': [],
+            'cameras': [],
+            'sort': []
+        }
         try:
             family_room_device_qs = FamilyRoomDevice.objects.filter(family_id=family_id).values('device_id',
                                                                                                 'device__Type',
@@ -260,7 +265,7 @@ class GatewayFamilyRoomView(View):
                 'sort', '-device__data_joined')
 
             if not family_room_device_qs.exists():
-                return response.json(0, [])
+                return response.json(0, device_room)
             sort = FamilyRoomDevice.objects.filter(family_id=family_id).values('category').annotate(
                 count=Count('category')).values('category', 'category_sort').order_by('category_sort')
             for item in sort:
@@ -305,11 +310,10 @@ class GatewayFamilyRoomView(View):
                         'nickName': device['device__NickName'],
                         'roomName': room_name.first().name if room_name.exists() else '',
                     })
-            device_room = {
-                'gateways': gateways,
-                'cameras': cameras,
-                'sort': list(sort)
-            }
+
+            device_room['gateways'] = gateways
+            device_room['cameras'] = cameras
+            device_room['sort'] = list(sort)
             return response.json(0, device_room)
         except Exception as e:
             return response.json(500, repr(e))