فهرست منبع

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

locky 3 سال پیش
والد
کامیت
7038405f4c

+ 34 - 14
AdminController/DeviceManagementController.py

@@ -2,7 +2,9 @@
 # -*- coding: utf-8 -*-
 import json
 import time
+from bisect import bisect_left
 
+import numpy as np
 import oss2
 from django.db import transaction
 from django.db.models import Q, F
@@ -12,7 +14,7 @@ from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, AWS_ACCESS_
     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
+    AppBundle, App_Info, AppDeviceType, DeviceNameLanguage, AppVersionNumber
 from Object.AWS.AmazonS3Util import AmazonS3Util
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
@@ -21,6 +23,7 @@ from Service.EquipmentInfoService import EquipmentInfoService
 from Service.ModelService import ModelService
 
 
+
 class DeviceManagement(View):
     def get(self, request, *args, **kwargs):
         request.encoding = 'utf-8'
@@ -138,9 +141,9 @@ class DeviceManagement(View):
                         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)
+                # 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)
@@ -187,15 +190,15 @@ class DeviceManagement(View):
         try:
             if UID or serialNumber or NickName or username:  # 条件查询
                 if UID:
-                    device_info_qs = Device_Info.objects.filter(UID__contains=UID)
+                    device_info_qs = Device_Info.objects.filter(UID__icontains=UID)
                 if serialNumber:
-                    device_info_qs = Device_Info.objects.filter(serial_number__contains=serialNumber)
+                    device_info_qs = Device_Info.objects.filter(serial_number__icontains=serialNumber)
                 if NickName:
-                    device_info_qs = Device_Info.objects.filter(NickName__contains=NickName)
+                    device_info_qs = Device_Info.objects.filter(NickName__icontains=NickName)
                 if username:
-                    device_info_qs = Device_Info.objects.filter(Q(userID__username__contains=username) |
-                                                                Q(userID__userEmail__contains=username) |
-                                                                Q(userID__phone__contains=username))
+                    device_info_qs = Device_Info.objects.filter(Q(userID__username__icontains=username) |
+                                                                Q(userID__userEmail__icontains=username) |
+                                                                Q(userID__phone__icontains=username))
                 total = device_info_qs.count()
                 if not total:
                     return response.json(0, {'list': {}, 'total': 0})
@@ -450,16 +453,33 @@ class DeviceManagement(View):
     def get_device_icon(request_dict, response):
         lang = request_dict.get('lang', None)
         app_bundle_id = request_dict.get('appBundleId', None)
+        version_number = request_dict.get('versionNumber', None)
 
-        if not all([lang, app_bundle_id]):
+        if not all([lang, app_bundle_id, version_number]):
             return response.json(444)
+        version_number_qs = AppVersionNumber.objects.values('version_number')
+        test_list = [item[key] for item in version_number_qs for key in item]
+        if (version_number > test_list[-1] or version_number < test_list[0]):
+            return False
+        pos = bisect_left(test_list, version_number)
+        if pos == 0:
+            return test_list[0]
+        if pos == len(test_list):
+            return test_list[-1]
+        before = test_list[pos - 1]
+        version_number_qs = AppVersionNumber.objects.filter(version_number=before).values('id')
         try:
+            version_number_id = version_number_qs[0]['id']
             app_bundle_qs = AppBundle.objects.filter(app_bundle_id=app_bundle_id,
-                                                     app_device_type__devicenamelanguage__lang=lang).annotate(
+                                                     app_device_type__devicenamelanguage__lang=lang,
+                                                     app_device_type__app_version_number_id=version_number_id). \
+                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'),
-                sort=F('app_device_type__devicenamelanguage__sort')).order_by(
-                'app_device_type__devicenamelanguage__sort').values('model', 'type', 'icon', 'name', 'sort')
+                sort=F('app_device_type__devicenamelanguage__sort'),
+                app_version_number_id=F('app_device_type__app_version_number_id')).order_by(
+                'app_device_type__devicenamelanguage__sort').values('model', 'type', 'icon', 'name', 'sort',
+                                                                    'app_device_type__app_version_number_id')
             dvr_list = [app_bundle for app_bundle in app_bundle_qs if app_bundle['model'] == 1]
             ipc_list = [app_bundle for app_bundle in app_bundle_qs if app_bundle['model'] == 2]
             print(dvr_list, ipc_list)

+ 98 - 102
AdminController/dataSystemManagement/DeviceDataController.py

@@ -203,117 +203,112 @@ class DeviceDataView(View):
         time_list = CommonService.cutting_time(start_time, end_time, unit_time)
         try:
             device_info_qs = Device_Info.objects.filter(data_joined__range=(start_time, end_time))
-            device_count_qs = device_info_qs.count()
-            device_type_qs = device_info_qs.values('UID').order_by('UID').distinct()
+            device_test_qs = Device_Info.objects.filter(data_joined__lt=start_time)
+            device_test = list(device_test_qs.values('UID').order_by('UID').distinct())
+            device_info = list(device_info_qs.values('UID').order_by('UID').distinct())
+            test_list = [item[key] for item in device_test for key in item]
+            device_info_list = [item[key] for item in device_info for key in item]
+            part_only_list = list(set(device_info_list) - set(test_list))
+            count_all = len(part_only_list)
+            count_all = int(count_all)
+            # 统计该时间段的设备数量(已去重)
+            res = {
+                'addDevice': '',
+                'region': '',
+                'type': '',
+                'version': '',
+            }
             info_list = []
-            count_unique = device_type_qs.count()
-            # 统计该时间段的设备数量(去重)
+            region_list = []
+            type_list = []
+            version_list = []
             for item in time_list:
                 start_time = datetime.datetime.fromtimestamp(int(item[0]))
                 end_time = datetime.datetime.fromtimestamp(int(item[1]))
+                device_qs = device_info_qs.filter(data_joined__range=(start_time, end_time))
+                device_test_qs = Device_Info.objects.filter(data_joined__lt=start_time)
+                device_test = list(device_test_qs.values('UID').order_by('UID').distinct())
+                device_info = list(device_qs.values('UID').order_by('UID').distinct())
+                test_list = [item[key] for item in device_test for key in item]
+                device_info_list = [item[key] for item in device_info for key in item]
+                part_only_list = list(set(device_info_list) - set(test_list))
+                count_part = len(part_only_list)
+                rate = round(count_part / count_all * 100, 2)
                 info_dict = {
+                    'count': len(part_only_list),
                     'startTime': item[0],
-                    'endTime': item[1]
+                    'endTime': item[1],
+                    'rate': rate
                 }
-                count = 0
-                for device_type in device_type_qs:
-                    uid = device_type['UID']
-                    device_test_qs = Device_Info.objects.filter(data_joined__lt=start_time, UID=uid).values()
-                    if device_test_qs.exists():
-                        continue
-                    else:
-                        count += 1
-                        device_only_qs = device_info_qs.filter(UID=uid).values()
-                        device_only = device_only_qs[0]
-                        # res = {
-                        #     'country': '',
-                        #     'count': ''
-                        # }
-                        #
-                        # for country in device_only:
-
-
-                info_dict['count'] = count
                 info_list.append(info_dict)
+                res['addDevice'] = info_list
+                # 统计地区设备数量
+                device_info_country_qs = device_info_qs.filter(UID__in=part_only_list).values('userID__region_country').annotate(
+                    count=Count('userID__region_country')).order_by('-count')
+                for item in device_info_country_qs:
+                    country_id = item['userID__region_country']
+                    country_qs = CountryModel.objects.filter(id=country_id).values('country_name', 'id')
+                    country_name = country_qs[0]['country_name'] if country_qs.exists() else '未知区域'
+                    country_qs = device_info_qs.filter(UID__in=part_only_list).values('UID').order_by('UID').distinct().values(
+                        'userID__region_country')
+                    total_list = [item[key] for item in country_qs for key in item]
+                    country_count = total_list.count(country_id)
+                    rate = round(country_count / count_part * 100, 2)
+                    country_dict = {
+                        'countryName': country_name,
+                        'count': country_count,
+                        'rate': rate
+                        # 'rate': rate
+                    }
+                    region_list.append(country_dict)
+                    res['region'] = CommonService.list_sort(region_list)
+                # 统计设备类型数量
+                device_info_type_qs = device_info_qs.filter(UID__in=part_only_list).values('Type').annotate(
+                    count=Count('Type', distinct=True)).order_by('-count').distinct()
+                count = device_info_type_qs.count()
+                for device_type in device_info_type_qs:
+                    type = device_type['Type']
+                    name = DEVICE_TYPE.get(type, '未知类型')
+                    name = name if name != 'UNKOWN' else '未知类型'
+                    type_qs = device_info_qs.filter(UID__in=part_only_list).values('UID').order_by('UID').distinct().values(
+                        'Type')
+                    # rate = round(total / count_unique * 100, 2)  # count_unique 有误,跟device_info_type_qs 总数合不上 (可以看151行)
+                    test_list = [item[key] for item in type_qs for key in item]
+                    type_count = test_list.count(type)
+                    rate = round(type_count / count_part * 100, 2)
+                    type_dict = {
+                        'type': name,
+                        'count': type_count,
+                        'rate': rate
+                        # 'rate': rate
+                    }
+                    type_list.append(type_dict)
+                    res['type'] = CommonService.list_sort(type_list)
+                # 统计设备版本数量
+                order_model_qs = Order_Model.objects.filter(UID__in=part_only_list).values('UID').annotate(
+                    count=Count('UID', distinct=True))
+                uid_qs = order_model_qs.values('UID').order_by('UID').distinct()
+                order_model_qs = order_model_qs.values('order_type').order_by('order_type')
+                # count = order_model_qs.count()
+                order_type_list = []
+                for order_model in order_model_qs:
+                    orderType = order_model['order_type']
+                    order_type_list.append(orderType)
+                res_part = {}
+                if order_type == 0:
+                    res_part['name'] = '云存'
+                elif order_type == 1:
+                    res_part['name'] = 'AI'
+                elif order_type == 2:
+                    res_part['name'] = '联通4G'
+                res_part['total'] = order_type_list.count(order_type)
+                res_part['rate'] = round(res_part['total'] / count_part * 100, 2)
+                version_list.append(res_part)
+                res['version'] = version_list
 
-
-
-
-        #         info_list.append(info_dict)
-        #     # 统计地区设备数量
-        #     device_info_country_qs = device_info_qs.values('userID__region_country').annotate(
-        #         count=Count('userID__region_country')).order_by('-count')
-        #     region_list = []
-        #     for item in device_info_country_qs:
-        #         country_id = item['userID__region_country']
-        #         country_qs = CountryModel.objects.filter(id=country_id).values('country_name', 'id')
-        #         country_name = country_qs[0]['country_name'] if country_qs.exists() else '未知区域'
-        #         count = device_info_qs.filter(userID__region_country=item['userID__region_country']).values(
-        #             'UID').annotate(count=Count('UID', distinct=True)).order_by('-count').count()
-        #         rate = round(count / count_unique * 100, 2)
-        #         country_dict = {
-        #             'countryName': country_name,
-        #             'count': count,
-        #             'rate': rate
-        #         }
-        #         region_list.append(country_dict)
-        #     # 统计设备类型数量
-        #     device_info_type_qs = device_info_qs.values('Type').annotate(
-        #         count=Count('Type', distinct=True)).order_by('-count')
-        #     count = device_info_type_qs.count()
-        #     # count_list = []
-        #     # for device_info_country in device_info_type_qs:
-        #     #     type = device_info_country['Type']
-        #     #     count_list.append(type)
-        #     device_info_type_qs = device_info_type_qs.values('Type').distinct()
-        #     type_list = []
-        #     for device_type in device_info_type_qs:
-        #         type = device_type['Type']
-        #         name = DEVICE_TYPE.get(type, '未知类型')
-        #         name = name if name != 'UNKOWN' else '未知类型'
-        #         total = device_info_qs.filter(Type=device_type['Type']).values('UID').annotate(
-        #             count=Count('UID', distinct=True)).order_by('-count').count()
-        #         rate = round(total / count_unique * 100, 2)  # count_unique 有误,跟device_info_type_qs 总数合不上 (可以看151行)
-        #         type_dict = {
-        #             'type': name,
-        #             'count': total,
-        #             'rate': rate
-        #         }
-        #         type_list.append(type_dict)
-        #     # 统计设备版本数量
-        #     device_info_type_qs = device_info_qs.values('UID').annotate(
-        #         count=Count('UID', distinct=True)).order_by('-count')
-        #     count = device_info_type_qs.count()
-        #     uid_list = []
-        #     for device_clound in device_info_type_qs:
-        #         uid = device_clound['UID']
-        #         uid_list.append(uid)
-        #     order_model_qs = Order_Model.objects.filter(UID__in=uid_list).values('UID').annotate(
-        #         count=Count('UID', distinct=True)).values('order_type').order_by('order_type')
-        #     count = order_model_qs.count()
-        #     order_type_list = []
-        #     for order_model in order_model_qs:
-        #         orderType = order_model['order_type']
-        #         order_type_list.append(orderType)
-        #     version_list = []
-        #     res = {}
-        #     if order_type == 0:
-        #         res['name'] = '云存'
-        #     elif order_type == 1:
-        #         res['name'] = 'AI'
-        #     elif order_type == 2:
-        #         res['name'] = '联通4G'
-        #     res['total'] = order_type_list.count(order_type)
-        #     version_list.append(res)
-        #
-        #     res = {
-        #         'info': info_list,
-        #         'region': region_list,
-        #         'type': type_list,
-        #         'version': version_list
-        #     }
-            return response.json(0, info_list)
+            return response.json(0, res)
         except Exception as e:
+            print(e)
             return response.json(500, repr(e))
 
     @classmethod
@@ -402,7 +397,8 @@ class DeviceDataView(View):
                     country_name = '未知地区'
                 else:
                     country_name = country_qs[0]['country_name']
-                device_type_qs = Device_Info.objects.filter(userID__region_country=country_id).values('Type').annotate(count=Count('Type', distinct=True)).order_by('-count')
+                device_type_qs = Device_Info.objects.filter(userID__region_country=country_id).values('Type').annotate(
+                    count=Count('Type', distinct=True)).order_by('-count')
                 country_type_list = []
                 for device_type in device_type_qs:
                     type = device_type['Type']

+ 15 - 0
Ansjer/server_urls/algorithm_shop_url.py

@@ -0,0 +1,15 @@
+# -*- encoding: utf-8 -*-
+"""
+@File    : algorithm_shop_url.py
+@Time    : 2022/8/26 14:38
+@Author  : stephen
+@Email   : zhangdongming@asj6.wecom.work
+@Software: PyCharm
+"""
+from django.urls import re_path
+
+from Controller.AlgorithmShop import AlgorithmShopController
+
+urlpatterns = [
+    re_path(r'^api/(?P<operation>.*)$', AlgorithmShopController.AlgorithmShopView.as_view()),
+]

+ 2 - 0
Ansjer/urls.py

@@ -353,6 +353,8 @@ urlpatterns = [
     url(r'^loocam/', include("Ansjer.server_urls.loocam_url")),
     # 联通4G套餐模块
     url(r'^unicom/', include("Ansjer.server_urls.unicom_url")),
+    # 算法小店
+    url(r'^algorithm-shop/', include("Ansjer.server_urls.algorithm_shop_url")),
 
     # 传感器网关
     re_path('sensorGateway/(?P<operation>.*)', SensorGatewayController.SensorGateway.as_view()),

+ 185 - 0
Controller/AlgorithmShop/AlgorithmShopController.py

@@ -0,0 +1,185 @@
+# -*- encoding: utf-8 -*-
+"""
+@File    : AlgorithmShopController.py
+@Time    : 2022/8/24 20:02
+@Author  : stephen
+@Email   : zhangdongming@asj6.wecom.work
+@Software: PyCharm
+"""
+import logging
+import time
+
+from django.views.generic.base import View
+
+from Model.models import DeviceAlgorithmExplain, DeviceAlgorithmBanner, DeviceUidAlgorithmType
+from Object.ResponseObject import ResponseObject
+from Object.TokenObject import TokenObject
+
+logger = logging.getLogger('info')
+
+
+class AlgorithmShopView(View):
+    def get(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation')
+        return self.validation(request.GET, request, operation)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation')
+        return self.validation(request.POST, request, operation)
+
+    def validation(self, request_dict, request, operation):
+        token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
+        lang = request_dict.get('lang', token.lang)
+        response = ResponseObject(lang)
+        if token.code != 0:
+            return response.json(token.code)
+        if operation == 'list':
+            return self.algorithm_list(request_dict, response)
+        elif operation == 'banner-list':
+            return self.get_algorithm_banner(response)
+        elif operation == 'uid-details':
+            return self.get_algorithm_details(request_dict, response)
+        elif operation == 'save':
+            return self.algorithm_setting_save(request_dict, response)
+
+    @classmethod
+    def get_algorithm_banner(cls, response):
+        """
+        获取算法小店banner
+        """
+        banner_qs = DeviceAlgorithmBanner.objects.all()
+        banner_vs = banner_qs.order_by('sort') \
+            .values('algorithm_type__type', 'algorithm_type__id', 'image_url')
+        banner_list = []
+        if not banner_vs.exists():
+            return response.json(0, banner_list)
+        for item in banner_vs:
+            banner_list.append({
+                'typeId': item['algorithm_type__id'],
+                'type': item['algorithm_type__type'],
+                'imageUrl': item['image_url'],
+            })
+        return response.json(0, banner_list)
+
+    @classmethod
+    def algorithm_list(cls, request_dict, response):
+        """
+        获取算法小店列表
+        """
+        try:
+            lang = request_dict.get('lang', 'en')
+            uid = request_dict.get('uid', None)
+            algorithm_qs = DeviceAlgorithmExplain.objects.filter(lang=lang).order_by('algorithm_type__sort') \
+                .values('algorithm_type__id', 'algorithm_type__type',
+                        'algorithm_type__icon_url',
+                        'title', 'subtitle', 'algorithm_type__image_url',
+                        'algorithm_type__basic_function')
+            algorithm_list = []
+            if not algorithm_qs.exists():
+                return response.json(0, algorithm_list)
+            for item in algorithm_qs:
+                setting = ''
+                if uid:
+                    setting = cls.get_uid_algorithm_info(item['algorithm_type__id'], uid)
+                    setting = setting if setting else {'status': 0, 'function': {}}
+                algorithm_list.append({
+                    'typeId': item['algorithm_type__id'],
+                    'type': item['algorithm_type__type'],
+                    'iconUrl': item['algorithm_type__icon_url'],
+                    'imageUrl': item['algorithm_type__image_url'],
+                    'title': item['title'],
+                    'subtitle': item['subtitle'],
+                    'setting': setting,
+                    'basicFunction': item['algorithm_type__basic_function']
+                })
+            return response.json(0, algorithm_list)
+        except Exception as e:
+            print('查询算法小店列表异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+            return response.json(177, repr(e))
+
+    @classmethod
+    def get_algorithm_details(cls, request_dict, response):
+        """
+        获取算法小店类型详情
+        """
+        try:
+            lang = request_dict.get('lang', 'en')
+            type_id = request_dict.get('typeId', None)
+            if not type_id:
+                return response.json(444, 'typeId not null')
+            type_id = int(type_id)
+            uid = request_dict.get('uid', None)
+            explain_qs = DeviceAlgorithmExplain.objects.filter(lang=lang).filter(algorithm_type__id=type_id) \
+                .values('algorithm_type__id', 'algorithm_type__type',
+                        'algorithm_type__down_count',
+                        'algorithm_type__details_img_url',
+                        'algorithm_type__icon_url',
+                        'title', 'subtitle', 'introduction',
+                        'install_explain', 'risk_warning',
+                        'algorithm_type__basic_function')
+            if not explain_qs.exists():
+                return response.json(0, {})
+            item = explain_qs.first()
+            algorithm_dict = {
+                'typeId': item['algorithm_type__id'],
+                'type': item['algorithm_type__type'],
+                'downCount': item['algorithm_type__down_count'],
+                'detailsImgUrl': item['algorithm_type__details_img_url'],
+                'iconUrl': item['algorithm_type__icon_url'],
+                'title': item['title'],
+                'subtitle': item['subtitle'],
+                'introduction': item['introduction'],
+                'installExplain': item['install_explain'],
+                'riskWarning': item['risk_warning'],
+                'basicFunction': item['algorithm_type__basic_function'],
+            }
+            if uid:
+                setting = cls.get_uid_algorithm_info(item['algorithm_type__id'], uid)
+                algorithm_dict['setting'] = setting if setting else {'status': 0, 'function': {}}
+            return response.json(0, algorithm_dict)
+        except Exception as e:
+            print('查询算法详情异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+            return response.json(177, repr(e))
+
+    @staticmethod
+    def get_uid_algorithm_info(type_id, uid):
+        """
+        获取当前设备使用算法状态信息
+        @param type_id: 算法类型ID
+        @param uid: 设备唯一标识
+        @return: dict
+        """
+        uid_algorithm_qs = DeviceUidAlgorithmType.objects.filter(algorithm_type_id=type_id, device_uid=uid) \
+            .values('status', 'function')
+        if not uid_algorithm_qs.exists():
+            return None
+        return uid_algorithm_qs.first()
+
+    @classmethod
+    def algorithm_setting_save(cls, request_dict, response):
+        """
+        算法设置保存
+        """
+        try:
+            type_id = request_dict.get('typeId', None)
+            uid = request_dict.get('uid', None)
+            status = request_dict.get('status', None)
+            setting_json = request_dict.get('function')
+            if not all([type_id, uid, status, setting_json]):
+                return response.json(444)
+            status = int(status)
+            type_id = int(type_id)
+            now_time = int(time.time())
+            uid_algorithm_qs = DeviceUidAlgorithmType.objects.filter(algorithm_type_id=type_id, device_uid=uid)
+            if not uid_algorithm_qs.exists():
+                param = {'algorithm_type_id': int(type_id), 'uid': uid, 'function': setting_json,
+                         'status': status, 'updated_time': now_time, 'created_time': now_time}
+                DeviceUidAlgorithmType.objects.create(**param)
+                return response.json(0)
+            uid_algorithm_qs.update(status=status, function=setting_json, updated_time=now_time)
+            return response.json(0)
+        except Exception as e:
+            print('保存算法设置异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+            return response.json(177, repr(e))

+ 7 - 33
Controller/EquipmentManagerV3.py

@@ -605,10 +605,14 @@ class EquipmentManagerV3(View):
         dvqs = Device_Info.objects.filter(userID_id=userID)
         # # 过滤已重置的设备
         dvqs = dvqs.filter(~Q(isExist=2))
+        if NickName:
+            dvqs.filter(NickName=NickName)
+        if uid:
+            dvqs.filter(UID=uid)
         dvql = dvqs.values('id', 'userID', 'NickName', 'UID', 'View_Account', 'View_Password', 'ChannelIndex',
                            'Type', 'isShare', 'primaryUserID', 'primaryMaster', 'data_joined', 'vodPrimaryUserID',
                            'vodPrimaryMaster', 'userID__userEmail', 'version', 'isVod', 'isExist', 'NotificationMode',
-                           'isCameraOpenCloud', 'serial_number')
+                           'isCameraOpenCloud', 'serial_number')[(page - 1) * line:page * line]
         dvls = CommonService.qs_to_list(dvql)
         uid_list = []
         for dvl in dvls:
@@ -776,40 +780,10 @@ class EquipmentManagerV3(View):
                 # 设备版本号
                 p['uid_version'] = ''
                 p['ucode'] = ''
+            p['View_Password'] = self.encrypt_pwd(p['View_Password'])
             data.append(p)
         result = data
-
-        if NickName:
-            # print('NickName搜索缓存')
-            data = []
-            for index, item in enumerate(result):
-                if NickName == item['NickName']:
-                    # 加密
-                    item['View_Password'] = self.encrypt_pwd(item['View_Password'])
-                    data.append(item)
-                    return response.json(0, data)
-        if uid:
-            # print('uid搜索缓存')
-            data = []
-            for index, item in enumerate(result):
-                if uid != item['UID']:
-                    continue
-                else:
-                    item['View_Password'] = self.encrypt_pwd(item['View_Password'])  # 加密
-                    data.append(item)
-                    return response.json(0, data)
-                return response.json(0, data)
-        items = []
-        # print('缓存分页')
-        for index, item in enumerate(result):
-            if (page - 1) * line <= index:
-                if index < page * line:
-                    # 加密
-                    item['View_Password'] = self.encrypt_pwd(item['View_Password'])
-                    print(item)
-                    items.append(item)
-        print(items)
-        return response.json(0, items)
+        return response.json(0, result)
 
     def do_fuzzy_query(self, userID, request_dict, response):
         fuzzy = request_dict.get('fuzzy', None)

+ 5 - 4
Controller/SensorGateway/SmartSceneController.py

@@ -111,14 +111,15 @@ class SmartSceneView(View):
 
                 if device_type != SENSOR_TYPE['smart_button']:  # 非智能按钮只返回网关
                     res = [cls.get_gateway_data(device_id)]
-                else:
+                else:   # 智能按钮返回网关,门磁和人体传感器(如果存在)
                     gateway_data = cls.get_gateway_data(device_id)
                     sub_device_qs = GatewaySubDevice.objects.filter(
                         Q(device_id=device_id) & Q(device_type=SENSOR_TYPE['door_magnet']) | Q(
                             device_type=SENSOR_TYPE['body_sensor'])).values('id', 'nickname', 'status', 'device_type')
-                    if not sub_device_qs.exists():
-                        return response.json(173)
-                    res = cls.get_sub_device_room_name(sub_device_qs, gateway_data)
+                    if sub_device_qs.exists():
+                        res = cls.get_sub_device_room_name(sub_device_qs, gateway_data)
+                    else:
+                        res = [gateway_data]
 
             return response.json(0, res)
         except Exception as e:

+ 86 - 2
Model/models.py

@@ -1184,7 +1184,7 @@ class UidSetModel(models.Model):
     is_human = models.IntegerField(default=0, verbose_name='是否支持人形追踪。0:不支持,1:支持')
     is_custom_voice = models.IntegerField(default=0, verbose_name='是否支持自定义语音。0:不支持,1:支持')
     double_wifi = models.IntegerField(default=0, verbose_name='是否支持双频wifi。0:不支持,1:支持')
-    isSupportFourPoint = models.SmallIntegerField(default=0, verbose_name='是否支持预置点')    # 0:不支持, 1:支持
+    isSupportFourPoint = models.SmallIntegerField(default=0, verbose_name='是否支持预置点')  # 0:不支持, 1:支持
     mobile_4g = models.IntegerField(default=0, verbose_name='是否支持4g。0:不支持,1:支持')
     is_ptz = models.IntegerField(default=0, verbose_name='是否支持云台。0:不支持,1:支持')
     is_vod = models.IntegerField(default=0, verbose_name='是否支持云存储。0:不支持,1:支持')
@@ -1714,11 +1714,25 @@ class AppBundle(models.Model):
         verbose_name_plural = verbose_name
 
 
+class AppVersionNumber(models.Model):
+    id = models.AutoField(primary_key=True)
+    app_bundle = models.ForeignKey(AppBundle, to_field='id', default='', on_delete=models.DO_NOTHING,
+                                   verbose_name='关联APP版本表')
+    version_number = models.CharField(max_length=32, verbose_name='版本号', default='')
+
+    class Meta:
+        db_table = 'app_version_number'
+        verbose_name = 'APP版本号表'
+        verbose_name_plural = verbose_name
+
+
 class AppDeviceType(models.Model):
     id = models.AutoField(primary_key=True)
-    model = models.SmallIntegerField(default=0, verbose_name='设备类型')  # 1:DVR, 2:IPC
+    # 1:DVR, 2:IPC
+    model = models.SmallIntegerField(default=0, verbose_name='设备类型')
     type = models.IntegerField(default=0, verbose_name='设备型号')
     icon = models.CharField(default='', max_length=200, verbose_name='图标文件路径')
+    app_version_number_id = models.CharField(default='', max_length=32, verbose_name='关联APP版本号表id')
 
     class Meta:
         db_table = 'app_device_type'
@@ -2803,3 +2817,73 @@ class UnicomFlowPush(models.Model):
         verbose_name = '联通流量用量推送'
         verbose_name_plural = verbose_name
         app_label = "PushModel"
+
+
+class DeviceAlgorithmType(models.Model):
+    id = models.AutoField(primary_key=True)
+    # 0:移动侦测,1:人形检测,2:挥手识别,3:人脸检测,4:异声感知,5:车辆检测,6:宠物检测,7:绊线入侵,8:离岗检测,9:徘徊检测
+    type = models.SmallIntegerField(default=0, verbose_name='算法类型')
+    memory = models.CharField(max_length=32, default='', verbose_name='所需内存')
+    down_count = models.IntegerField(default=0, verbose_name='下载次数')
+    sort = models.IntegerField(default=0, verbose_name=u'排序,越小越靠前')
+    basic_function = models.TextField(blank=True, default='', verbose_name=u'基础功能(json格式)')
+    image_url = models.CharField(max_length=255, default='', verbose_name='图片地址')
+    details_img_url = models.CharField(max_length=255, default='', verbose_name='详情图')
+    icon_url = models.CharField(max_length=255, default='', verbose_name='图标地址')
+    created_time = models.IntegerField(default=0, verbose_name='创建时间')
+
+    class Meta:
+        db_table = 'device_algorithm_type'
+        verbose_name = '设备算法类型'
+        verbose_name_plural = verbose_name
+
+
+class DeviceAlgorithmBanner(models.Model):
+    id = models.AutoField(primary_key=True)
+    algorithm_type = models.ForeignKey(DeviceAlgorithmType, to_field='id', default='', on_delete=models.CASCADE,
+                                       verbose_name=u'关联算法类型')
+    image_url = models.CharField(max_length=255, default='', verbose_name='横幅图')
+    sort = models.IntegerField(default=0, verbose_name=u'排序,越小越靠前')
+    updated_time = models.IntegerField(default=0, verbose_name='更新时间')
+    created_time = models.IntegerField(default=0, verbose_name='创建时间')
+
+    class Meta:
+        db_table = 'device_algorithm_banner'
+        verbose_name = '设备算法横幅广告'
+        verbose_name_plural = verbose_name
+
+
+class DeviceAlgorithmExplain(models.Model):
+    id = models.AutoField(primary_key=True)
+    algorithm_type = models.ForeignKey(DeviceAlgorithmType, to_field='id', default='', on_delete=models.CASCADE,
+                                       verbose_name=u'关联算法类型')
+    title = models.CharField(max_length=32, default='', verbose_name='标题')
+    subtitle = models.CharField(max_length=100, default='', verbose_name='副标题')
+    introduction = models.TextField(blank=True, default='', verbose_name='功能介绍')
+    install_explain = models.TextField(blank=True, default='', verbose_name=u'安装说明')
+    risk_warning = models.TextField(blank=True, default='', verbose_name=u'风险提示')
+    lang = models.CharField(default='', max_length=20, db_index=True, verbose_name='语言/国家')
+    updated_time = models.IntegerField(default=0, verbose_name='更新时间')
+    created_time = models.IntegerField(default=0, verbose_name='创建时间')
+
+    class Meta:
+        db_table = 'device_algorithm_explain'
+        verbose_name = '设备算法详情'
+        verbose_name_plural = verbose_name
+
+
+class DeviceUidAlgorithmType(models.Model):
+    id = models.AutoField(primary_key=True)
+    status = models.SmallIntegerField(default=0, verbose_name=u'状态{0:关闭,1:开启}')
+    memory = models.CharField(max_length=32, default='', verbose_name='设备内存')
+    function = models.TextField(blank=True, default='', verbose_name='功能设置')
+    device_uid = models.CharField(max_length=32, db_index=True, default='', verbose_name='设备uid')
+    algorithm_type = models.ForeignKey(DeviceAlgorithmType, to_field='id', default='', on_delete=models.CASCADE,
+                                       verbose_name=u'关联算法类型')
+    updated_time = models.IntegerField(default=0, verbose_name='更新时间')
+    created_time = models.IntegerField(default=0, verbose_name='创建时间')
+
+    class Meta:
+        db_table = 'device_uid_algorithm_type'
+        verbose_name = '设备uid关联算法类型'
+        verbose_name_plural = verbose_name