Эх сурвалжийг харах

增加重置设备主用户接口

locky 4 жил өмнө
parent
commit
0c6b3d3c1d

+ 1 - 1
Controller/TestApi.py

@@ -744,7 +744,7 @@ class testView(View):
                             content_type="application/json,charset=utf-8")
 
     def delete_device(self, response):
-        # 每两周删除一次tech01@ansjer.com~tech10@ansjer.com账号下的设备
+        # 定时删除tech01@ansjer.com~tech10@ansjer.com账号下的设备
         try:
             userID_list = ['tech01@ansjer.com', 'tech02@ansjer.com', 'tech03@ansjer.com',
                            'tech04@ansjer.com', 'tech05@ansjer.com', 'tech06@ansjer.com',

+ 22 - 4
Controller/UidSetController.py

@@ -92,6 +92,8 @@ class UidSetView(View):
             return self.do_set_voice(userID, request_dict, response)
         elif operation == 'vod_reset':
             return self.vod_reset(request_dict, response)
+        elif operation == 'primary_user_reset':
+            return self.primary_user_reset(request_dict, response)
         # elif operation == 'test':
         #     return self.do_test(response)
         else:
@@ -380,7 +382,7 @@ class UidSetView(View):
         token = request_dict.get('token', None)
         print(channelContent)
         if not channelContent or not uid or not channel:
-            return response.json(444, 'content,uid, chan')
+            return response.json(444, 'content,uid, channel')
         tko = TokenObject(token)
         response.lang = tko.lang
         if tko.code != 0:
@@ -393,12 +395,10 @@ class UidSetView(View):
         if channel < 1:
             return response.json(444, 'channel')
         try:
-            # redisObj = RedisObject(db=8)
-            # redisObj.del_data(key='uid_qs_' + userID)
             deviceData = json.loads(channelContent)
             uid_channel_set_qs = UidChannelSetModel.objects.filter(uid__uid=uid, channel=channel)
+            uidObject = UidSetModel.objects.filter(uid=uid)
             if not uid_channel_set_qs.exists():
-                uidObject = UidSetModel.objects.filter(uid=uid)
                 ucs = {
                     'channel': channel,
                     'uid': uidObject[0]
@@ -410,6 +410,13 @@ class UidSetView(View):
             else:
                 uid_channel_set_qs.update(**deviceData)
 
+            if uidObject[0].is_alexa == 1 and 'channel_name' in deviceData.keys():
+                # 请求Alexa服务器更新事件网关
+                data_list = [{'userID': userID, 'UID': uid, 'uid_nick': deviceData['channel_name'], 'password': ''}]
+                data_list = json.dumps(data_list)
+                data = {'data_list': data_list}
+                url = 'https://www.zositech.xyz/deviceStatus/addOrUpdateV2'
+                requests.post(url, data=data, timeout=2)
         except Exception as e:
             return response.json(177, repr(e))
         else:
@@ -508,6 +515,17 @@ class UidSetView(View):
             else:
                 return response.json(0)
 
+    # 重置设备主用户
+    def primary_user_reset(self, request_dict, response):
+        uid = request_dict.get('uid', None)
+        if not uid:
+            return response.json(404)
+        try:
+            Device_Info.objects.filter(UID=uid).update(vodPrimaryUserID='', vodPrimaryMaster='')
+            return response.json(0)
+        except Exception as e:
+            return response.json(500, repr(e))
+
     # def do_test(self, response):
     #     di_qs = Device_Info.objects.values('Type').annotate(c=Count('UID', distinct=True)).order_by()
     #     for di in di_qs: