Browse Source

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

peng 2 years ago
parent
commit
2f1862bb63

+ 37 - 34
AdminController/DeviceManagementController.py

@@ -632,48 +632,52 @@ class DeviceManagement(View):
         model = request_dict.get('model', None)
         type = request_dict.get('type', 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)
+        if not all([model, type, name, sort, version_number, file]):
+            return response.json(444, 'model, type, file, name, sort, version_number')
         fileName = file.name
-        if not all([model, type, lang, name, sort, version_number]):
-            return response.json(444, 'model, type, lang, name, sort, version_number')
         type = int(type)
+        data_name = eval(name)
         try:
             with transaction.atomic():
-                app_bundle_qs = AppBundle.objects.filter(id__in=app_bundle_id,
-                                                         app_device_type__devicenamelanguage__lang=lang,
-                                                         app_device_type__app_version_number_id=version_number,
-                                                         app_device_type__type=type,
-                                                         app_device_type__model=model)
-                #  数据是否重复
-                if app_bundle_qs.exists():
-                    return response.json(174)
-                # 是否存在相同的url
-                response_url = 'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/' + format(fileName)
-                app_bundle_qs = AppDeviceType.objects.filter(appbundle__id__in=app_bundle_id, type=type, model=model)
-                if not app_bundle_qs.exists():
-                    #  上传设备图标至存储桶
-                    bucket_name = 'ansjerfilemanager'
-                    file_key = 'app/device_type_images/{}'.format(fileName)
-                    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,
-                        file,
-                        {'ContentType': file.content_type, 'ACL': 'public-read'})
+                for k, v in data_name.items():
+                    app_bundle_qs = AppBundle.objects.filter(id__in=app_bundle_id,
+                                                             app_device_type__devicenamelanguage__lang=k,
+                                                             app_device_type__app_version_number_id=version_number,
+                                                             app_device_type__type=type,
+                                                             app_device_type__model=model)
+                    #  数据是否重复
+                    if app_bundle_qs.exists():
+                        return response.json(174)
+                    # 是否存在相同的url
+                    response_url = 'https://ansjerfilemanager.s3.amazonaws.com/app/device_type_images/' + format(
+                        fileName)
+                    app_bundle_qs = AppDeviceType.objects.filter(appbundle__id__in=app_bundle_id, type=type,
+                                                                 model=model, icon=response_url)
+                    if not app_bundle_qs.exists():
+                        # 上传设备图标至存储桶
+                        bucket_name = 'ansjerfilemanager'
+                        file_key = 'app/device_type_images/{}'.format(fileName)
+                        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,
+                            file,
+                            {'ContentType': file.content_type, 'ACL': 'public-read'})
                 #  创建
-                for app_id in app_bundle_id:
-                    app_bundle_qs = AppBundle.objects.filter(id=app_id).values('id')
-                    app_device_type_qs = AppDeviceType.objects.create(model=model, type=type, icon=response_url,
-                                                                      app_version_number_id=version_number)
-                    DeviceNameLanguage.objects.create(lang=lang, name=name, sort=sort,
-                                                      app_device_type_id=app_device_type_qs.id)
-                    #  关联app包
-                    app_device_type_qs.appbundle_set.add(app_bundle_qs[0]['id'])
+                for k, v in data_name.items():
+                    for app_id in app_bundle_id:
+                        app_bundle_qs = AppBundle.objects.filter(id=app_id).values('id')
+                        app_device_type_qs = AppDeviceType.objects.create(model=model, type=type, icon=response_url,
+                                                                          app_version_number_id=version_number)
+                        DeviceNameLanguage.objects.create(lang=k, name=v, sort=sort,
+                                                          app_device_type_id=app_device_type_qs.id)
+                        #  关联app包
+                        app_device_type_qs.appbundle_set.add(app_bundle_qs[0]['id'])
                 return response.json(0)
         except Exception as e:
             print(e)
@@ -729,7 +733,6 @@ class DeviceManagement(View):
                     })
             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]
-            print(dvr_list, ipc_list)
             res = {
                 'deviceDvr': sorted(dvr_list, key=operator.itemgetter('sort')),
                 'deviceIpc': sorted(ipc_list, key=operator.itemgetter('sort')),

+ 1 - 1
Ansjer/urls.py

@@ -230,7 +230,7 @@ urlpatterns = [
     re_path('^sales', SalesController.SalesView.as_view()),
     re_path('device/online', SalesController.DeviceOnlineView.as_view()),
     re_path('serialNumber/(?P<operation>.*)', SerialNumberController.SerialNumberView.as_view()),
-    re_path('deviceShadow/update', ShadowController.update_device_shadow),
+    re_path('deviceShadow/updateV2', ShadowController.update_device_shadow),
     re_path('company/(?P<operation>.*)', CompanyController.CompanyView.as_view()),
     re_path('region/(?P<operation>.*)', RegionController.RegionView.as_view()),
     re_path('vpg/(?P<operation>.*)', VPGController.VPGView.as_view()),

+ 50 - 64
Controller/SensorGateway/SmartSceneController.py

@@ -182,8 +182,8 @@ class SmartSceneView(View):
         }
         return res
 
-    @staticmethod
-    def create_smart_scene(request_dict, user_id, response):
+    @classmethod
+    def create_smart_scene(cls, request_dict, user_id, response):
         """
         创建智能场景
         @param request_dict: 请求参数
@@ -246,6 +246,7 @@ class SmartSceneView(View):
                 if not device_info_qs.exists():
                     return response.json(173)
                 serial_number = device_info_qs[0]['serial_number']
+                msg['sensor_status'] = 2002
             else:  # 子设备设置场景
                 if not sub_device_id:
                     return response.json(444, {'error param': 'subDeviceId'})
@@ -322,36 +323,9 @@ class SmartSceneView(View):
 
                 msg['time'] = time_dict
                 msg['scene_id'] = smart_scene_qs.id
-                task_list = []
-                for task in tasks_list:
-                    sensor_type = int(task['device_type'])
-                    task_temp = {
-                        'sensor_type': sensor_type
-                    }
-                    if sensor_type != -1:   # 不为-1时需要其他数据
-                        task_temp['sensor_action'] = int(task['event_type'])
-
-                        # 延时
-                        if 'delay_time' in task and task['delay_time'] != 0:
-                            task_temp['sensor_delay'] = task['delay_time']
-
-                        # 子设备返回长地址
-                        sub_device_id = task.get('subDeviceId', None)
-                        if sub_device_id:
-                            sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('ieee_addr').first()
-                            task_temp['sensor_ieee_addr'] = sub_device_qs['ieee_addr']
-                        # 网关添加报警类型数据
-                        else:
-                            task_temp['voice_type'] = task.get('voice_type')
-                            task_temp['voice_id'] = task.get('voice_id')
-                            task_temp['count'] = task.get('count')
-                            task_temp['delay_time'] = task.get('delay_time')
-                            task_temp['duration'] = task.get('duration')
-                            task_temp['value_type'] = task.get('value_type')
-
-                    task_list.append(task_temp)
-
-                msg['task'] = task_list
+
+                # 获取设备任务数据
+                msg['task'] = cls.get_msg_task_list(tasks_list)
 
                 smart_scene_qs.device_data = json.dumps(msg)
                 smart_scene_qs.save()
@@ -561,8 +535,8 @@ class SmartSceneView(View):
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
-    @staticmethod
-    def edit_smart_scene(request_dict, user_id, response):
+    @classmethod
+    def edit_smart_scene(cls, request_dict, user_id, response):
         """
         编辑智能场景
         @param request_dict: 请求参数
@@ -654,37 +628,10 @@ class SmartSceneView(View):
                 if not device_qs.exists():
                     return response.json(173)
                 serial_number = device_qs[0]['serial_number']
+                msg['sensor_status'] = 2002
 
-            task_list = []
-            for task in tasks_list:
-                sensor_type = int(task['device_type'])
-                task_temp = {
-                    'sensor_type': sensor_type
-                }
-                if sensor_type != -1:   # 不为-1时需要其他数据
-                    task_temp['sensor_action'] = int(task['event_type'])
-
-                    # 延时
-                    if 'delay_time' in task and task['delay_time'] != 0:
-                        task_temp['sensor_delay'] = task['delay_time']
-
-                    # 子设备返回长地址
-                    task_sub_device_id = task.get('subDeviceId', None)
-                    if task_sub_device_id:
-                        sub_device_qs = GatewaySubDevice.objects.filter(id=task_sub_device_id).values('ieee_addr').first()
-                        task_temp['sensor_ieee_addr'] = sub_device_qs['ieee_addr']
-                    # 网关添加报警类型数据
-                    else:
-                        task_temp['voice_type'] = task.get('voice_type')
-                        task_temp['voice_id'] = task.get('voice_id')
-                        task_temp['count'] = task.get('count')
-                        task_temp['delay_time'] = task.get('delay_time')
-                        task_temp['duration'] = task.get('duration')
-                        task_temp['value_type'] = task.get('value_type')
-
-                task_list.append(task_temp)
-
-            msg['task'] = task_list
+            # 获取设备任务数据
+            msg['task'] = cls.get_msg_task_list(tasks_list)
 
             with transaction.atomic():
                 smart_scene_qs.update(scene_name=scene_name, conditions=conditions, tasks=tasks,
@@ -1019,6 +966,45 @@ class SmartSceneView(View):
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
+    @staticmethod
+    def get_msg_task_list(tasks_list):
+        """
+        获取设备任务数据
+        @param tasks_list: app任务列表
+        @return: task_list
+        """
+        task_list = []
+        # 下发最后一个任务;如果最后一个任务有延时,则下发最后两个任务
+        # task_temp = tasks_list[-1:]
+        for task in tasks_list:
+            sensor_type = int(task['device_type'])
+            task_temp = {
+                'sensor_type': sensor_type
+            }
+            if sensor_type != -1:  # 不为-1时需要其他数据
+                task_temp['sensor_action'] = int(task['event_type'])
+
+                # 延时
+                if 'delay_time' in task and task['delay_time'] != 0:
+                    task_temp['sensor_delay'] = task['delay_time']
+
+                # 子设备返回长地址
+                sub_device_id = task.get('subDeviceId', None)
+                if sub_device_id:
+                    sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('ieee_addr').first()
+                    task_temp['sensor_ieee_addr'] = sub_device_qs['ieee_addr']
+                # 网关长地址返回'FFFFFFFFFFFFFFFF',添加报警类型数据
+                else:
+                    task_temp['sensor_ieee_addr'] = 'FFFFFFFFFFFFFFFF'
+                    task_temp['voice_type'] = task.get('voice_type')
+                    task_temp['voice_id'] = task.get('voice_id')
+                    task_temp['count'] = task.get('count')
+                    task_temp['delay_time'] = task.get('delay_time')
+                    task_temp['duration'] = task.get('duration')
+                    task_temp['value_type'] = task.get('value_type')
+            task_list.append(task_temp)
+        return task_list
+
 
 #
 #                   ___====-_  _-====___

+ 3 - 2
Controller/ShadowController.py

@@ -50,7 +50,7 @@ def update_device_shadow(request):
             uid_bucket = UID_Bucket.objects.filter(uid=uid, endTime__gte=nowTime).values('id', 'has_unused').order_by(
                 'addTime')
             if not uid_bucket.exists():
-                Device_Info.objects.filter(UID=uid).update(isExist=2)
+                Device_Info.objects.filter(UID=uid).update(isExist=2, vodPrimaryUserID='', vodPrimaryMaster='')
             # 删除预览图
             uid_pre_qs = UID_Preview.objects.filter(uid=uid)
             if uid_pre_qs.exists():
@@ -61,7 +61,8 @@ def update_device_shadow(request):
             if voice_qs.exists():
                 voice_qs.delete()
 
-            # 关闭移动侦测的消息提醒
+            # 关闭移动侦测推送
+            UidSetModel.objects.filter(uid=uid).update(detect_status=0)
             Device_Info.objects.filter(UID=uid).update(NotificationMode=0)
 
             # 关闭AI