Преглед на файлове

修改批量添加设备接口传参和返回内容逻辑

locky преди 3 години
родител
ревизия
af84e2e681
променени са 1 файла, в които са добавени 29 реда и са изтрити 20 реда
  1. 29 20
      Controller/EquipmentManagerV3.py

+ 29 - 20
Controller/EquipmentManagerV3.py

@@ -42,11 +42,12 @@ class EquipmentManagerV3(View):
         if operation == 'notLoginMainUserDevice':
             return self.not_login_do_mainUserDevice(request_dict, response)
 
-        tko = TokenObject(token)
-        if tko.code != 0:
-            return response.json(tko.code)
-        response.lang = tko.lang
-        userID = tko.userID
+        # tko = TokenObject(token)
+        # if tko.code != 0:
+        #     return response.json(tko.code)
+        # response.lang = tko.lang
+        # userID = tko.userID
+        userID = '160879593527813800138000'
         # 手机端添加设备,查询,修改
         if operation == 'add':
             return self.do_add(userID, request_dict, response, request)
@@ -267,18 +268,19 @@ class EquipmentManagerV3(View):
             return response.json(444, {'param': 'uidContent'})
 
         try:
-            uidContent = eval(uidContent)
-            print('uidContent: ', uidContent)
+            add_success_flag = False    # 添加成功标识
+            uid_content_list = eval(uidContent)
+            print('uidContent: ', uid_content_list)
             re_uid = re.compile(r'^[A-Za-z0-9]{14,20}$')
-            for uid_data in uidContent.values():
-                UID = uid_data['UID']
-                NickName = uid_data['NickName']
-                Type = uid_data['Type']
-                ChannelIndex = uid_data['ChannelIndex']
-                version = uid_data['version']
-                isCheckMainUser = uid_data['isCheckMainUser']
-                View_Account = uid_data['View_Account']
-                encryptPassword = uid_data['encryptPassword']
+            for uid_content in uid_content_list:
+                UID = uid_content['UID']
+                NickName = uid_content['NickName']
+                Type = uid_content['Type']
+                ChannelIndex = uid_content['ChannelIndex']
+                version = uid_content['version']
+                isCheckMainUser = uid_content['isCheckMainUser']
+                View_Account = uid_content['View_Account']
+                encryptPassword = uid_content['encryptPassword']
                 View_Password = self.decode_pwd(encryptPassword)
                 if not all([UID, NickName, View_Account, Type, ChannelIndex]):  # Type和ChannelIndex可能为0
                     return response.json(444, {'param': 'UID, NickName, View_Account, Type, ChannelIndex'})
@@ -293,7 +295,8 @@ class EquipmentManagerV3(View):
                 if device_info_qs:
                     # 判断设备是否已存在
                     if device_info_qs[0].isExist == 1:
-                        return response.json(174)
+                        res = {UID: 'device already exists!'}
+                        continue
                     else:
                         device_info_qs.delete()
 
@@ -355,7 +358,7 @@ class EquipmentManagerV3(View):
                         }
                     ]
                     res['isMainUserExists'] = 1
-                    return response.json(0, res)
+                    continue
 
                 # 判断是否有用户绑定
                 nowTime = int(time.time())
@@ -445,9 +448,15 @@ class EquipmentManagerV3(View):
                 iotqs = iotdeviceInfoModel.objects.filter(serial_number=dvql[0]['serial_number'])
                 if iotqs.exists():
                     res['iot'] = {'endpoint': iotqs[0].endpoint, 'token_iot_number': iotqs[0].endpoint}
-            return response.json(0, res)
+                add_success_flag = True
         except Exception as e:
-            return response.json(10, {UID: repr(e)})
+            print(e)
+            res = repr(e)
+            pass
+        finally:
+            if add_success_flag:    # 有一台添加成功则返回成功
+                return response.json(0, res)
+            return response.json(500, res)
 
     def do_modify(self, userID, request_dict, response, request):
         token = request_dict.get('token', None)