Procházet zdrojové kódy

优化设备查询代码,detectV2接口修改状态代码

zhangdongming před 3 roky
rodič
revize
6b6c7637fa

+ 9 - 3
Controller/DetectControllerV2.py

@@ -55,10 +55,14 @@ class DetectControllerViewV2(View):
         return self.validation(request.POST, operation)
 
     def validation(self, request_dict, operation):
+
         response = ResponseObject()
         if operation is None:
             return response.json(444, 'error path')
         token = request_dict.get('token', None)
+        lang = request_dict.get('lang', None)
+        if lang:
+            response = ResponseObject(lang)
         tko = TokenObject(token)
         if tko.code == 0:
             userID = tko.userID
@@ -132,7 +136,9 @@ class DetectControllerViewV2(View):
             # 判断用户是否拥有设备
             device_info_qs = Device_Info.objects.filter(userID_id=userID, UID=uid)
             if not device_info_qs.exists():
-                return response.json(14)
+                device_info_qs = Device_Info.objects.filter(userID_id=userID, serial_number=uid)
+                if not device_info_qs.exists():
+                    return response.json(14)
 
             # 更新或创建uid_set数据
             nowTime = int(time.time())
@@ -437,9 +443,9 @@ class DetectControllerViewV2(View):
             else:
                 p['uid_type'] = ''
 
-            p['borderCoords'] = '' if p['borderCoords'] == '' else json.loads(p['borderCoords']) # ai消息坐标信息
+            p['borderCoords'] = '' if p['borderCoords'] == '' else json.loads(p['borderCoords'])  # ai消息坐标信息
             p['ai_event_type_list'] = []
-            if p['eventType'] in ai_all_event_type: #如果是ai消息类型,则分解eventType, 如:123 -> [1,2,3]
+            if p['eventType'] in ai_all_event_type:  # 如果是ai消息类型,则分解eventType, 如:123 -> [1,2,3]
                 p['ai_event_type_list'] = list(map(int, str(p['eventType'])))
             res.append(p)
         return response.json(0, {'datas': res, 'count': count})

+ 1 - 45
SensorGateway/EquipmentFamilyManager.py

@@ -7,7 +7,6 @@
 @Software: PyCharm
 """
 
-import base64
 import time
 
 import oss2
@@ -16,7 +15,6 @@ from django.db.models import Q
 from django.views.generic.base import View
 
 from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY
-from Controller.CheckUserData import RandomStr
 from Controller.DeviceConfirmRegion import Device_Region
 from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidChannelSetModel, \
     iotdeviceInfoModel, UIDModel
@@ -167,12 +165,8 @@ class EquipmentFamilyManager(View):
         page = int(page)
         line = int(line)
         uid = request_dict.get('uid', None)
-        device_start = time.time()
         device_info_list = cls.get_device_info_list(user_id, nick_name, uid,
                                                     page, line)
-        device_end = time.time()
-        print("设备信息代码执行时间")
-        print(device_end - device_start)
         uid_list = []
         # 判断是否是主用户 isPrimaryUser=0:否,1:是
         for dvl in device_info_list:
@@ -181,37 +175,18 @@ class EquipmentFamilyManager(View):
             else:
                 dvl['isPrimaryUser'] = 0
             uid_list.append(dvl['UID'])
-        print(uid_list)
         # 设备关联套餐,设备预览图
-        bucket_start = time.time()
         uid_bucket_qs, uid_preview_qs = cls.get_bucket_and_preview_by_uid(uid_list)
-        bucket_end = time.time()
-        print("设备套餐代码执行时间")
-        print(bucket_end - bucket_start)
         # 设备配置信息
-        uid_set_start = time.time()
         uid_set_dict = cls.get_uid_set_dict(uid_list)
-        uid_set_end = time.time()
-        print("设备配置详情代码执行时间")
-        print(uid_set_end - uid_set_start)
         # 设备详情信息
-        details_start = time.time()
         result = cls.get_device_details(device_info_list, uid_bucket_qs, uid_preview_qs, uid_set_dict)
-        details_end = time.time()
-        print("设备uid详情代码执行时间")
-        print(details_end - details_start)
-        # print('NickName搜索缓存')
-        # print('缓存分页')
         items = []
-        pwd_start = time.time()
         for index, item in enumerate(result):
             # 加密
             if item['View_Password']:
-                item['View_Password'] = cls.encrypt_pwd(item['View_Password'])
+                item['View_Password'] = CommonService.encode_data(item['View_Password'], 1, 4)
             items.append(item)
-        pwd_end = time.time()
-        print("加密代码执行时间")
-        print(pwd_end - pwd_start)
         return response.json(0, items)
 
     @classmethod
@@ -428,25 +403,6 @@ class EquipmentFamilyManager(View):
             data.append(p)
         return data
 
-    @classmethod
-    def encrypt_pwd(cls, user_pwd):
-        """
-        用户密码加密
-        @param user_pwd:用户密码
-        @return: user_pwd 加密后的pwd
-        """
-        for i in range(1, 4):
-            if i == 1:
-                user_pwd = RandomStr(3, False) + user_pwd + RandomStr(3, False)
-                user_pwd = base64.b64encode(str(user_pwd).encode("utf-8")).decode('utf8')
-            if i == 2:
-                user_pwd = RandomStr(2, False) + str(user_pwd) + RandomStr(2, False)
-                user_pwd = base64.b64encode(str(user_pwd).encode("utf-8")).decode('utf8')
-            if i == 3:
-                user_pwd = RandomStr(1, False) + str(user_pwd) + RandomStr(1, False)
-                user_pwd = base64.b64encode(str(user_pwd).encode("utf-8")).decode('utf8')
-        return user_pwd
-
     # @classmethod
     # def family_save(cls, user_id, save_type, lang):
     #     # 0:默认创建家庭,1:新增,2:修改