Sfoglia il codice sorgente

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

peng 1 anno fa
parent
commit
2dcae795de

+ 3 - 0
AdminController/UserManageController.py

@@ -336,6 +336,7 @@ class UserManagement(View):
         @return:
         """
         print('request_dict: ', request_dict)
+        user_id = request_dict.get('userId', '').strip()
         username = request_dict.get('username', '').strip()  # 移除字符串头尾的空格
         NickName = request_dict.get('NickName', '').strip()
         phone = request_dict.get('phone', '').strip()
@@ -353,6 +354,8 @@ class UserManagement(View):
         try:
             device_user_qs = Device_User.objects.all()
             # 条件查询
+            if user_id:
+                device_user_qs = device_user_qs.filter(userID=user_id)
             if username:
                 device_user_qs = device_user_qs.filter(username__icontains=username)
             if NickName:

+ 10 - 6
Controller/EquipmentManager.py

@@ -257,12 +257,14 @@ def modifyUserEquipmentInterface(request):
                 encrypt_pwd = ''
                 if deviceData.__contains__('View_Password'):
                     encrypt_pwd = deviceData['View_Password']
-                # 请求Alexa服务器更新事件网关
-                url = 'https://www.zositech.xyz/deviceStatus/addOrUpdateV2'
+                # 异步请求Alexa服务器更新事件网关
                 data_list = [{'userID': userID, 'UID': uid, 'uid_nick': nickname, 'password': encrypt_pwd}]
                 data_list = json.dumps(data_list)
                 data = {'data_list': data_list}
-                requests.post(url, data=data, timeout=2)
+                alexa_thread = threading.Thread(
+                    target=CommonService.update_alexa_events,
+                    kwargs=data)
+                alexa_thread.start()
         return response.json(0, res)
 
 
@@ -520,11 +522,13 @@ def addInterface(request):
                             data_list = [
                                 {'userID': userID, 'UID': UID, 'uid_nick': NickName, 'password': View_Password}]
 
-                        # 请求Alexa服务器更新事件网关
+                        # 异步请求Alexa服务器更新事件网关
                         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)
+                        alexa_thread = threading.Thread(
+                            target=CommonService.update_alexa_events,
+                            kwargs=data)
+                        alexa_thread.start()
                 except Exception as e:
                     return response.json(10, repr(e))
                 else:

+ 16 - 9
Controller/EquipmentManagerV3.py

@@ -350,11 +350,13 @@ class EquipmentManagerV3(View):
                     else:
                         data_list = [{'userID': userID, 'UID': UID, 'uid_nick': NickName, 'password': encrypt_pass}]
 
-                    # 请求Alexa服务器更新事件网关
+                    # 异步请求Alexa服务器更新事件网关
                     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)
+                    alexa_thread = threading.Thread(
+                        target=CommonService.update_alexa_events,
+                        kwargs=data)
+                    alexa_thread.start()
 
                 # 记录添加日志
                 LogModel.objects.create(**log)
@@ -612,11 +614,14 @@ class EquipmentManagerV3(View):
                     else:
                         data_list = [{'userID': userID, 'UID': UID, 'uid_nick': NickName, 'password': encryptPassword}]
 
-                    # 请求Alexa服务器更新事件网关
+                    # 异步请求Alexa服务器更新事件网关
                     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)
+                    alexa_thread = threading.Thread(
+                        target=CommonService.update_alexa_events,
+                        kwargs=data)
+                    alexa_thread.start()
+
                 dvqs = Device_Info.objects.filter(id=id).values('id', 'userID', 'NickName', 'UID',
                                                                 'View_Account',
                                                                 'View_Password', 'ChannelIndex', 'Type',
@@ -720,13 +725,15 @@ class EquipmentManagerV3(View):
                 di_qs.update(NickName=nickname)
 
                 if deviceData is not None and deviceData.__contains__('NickName') and us_qs[0].is_alexa == 1:
-                    # 请求Alexa服务器更新事件网关
-                    url = 'https://www.zositech.xyz/deviceStatus/addOrUpdateV2'
+                    # 异步请求Alexa服务器更新事件网关
                     password = encrypt_pwd if deviceData.__contains__('View_Password') else ''
                     data_list = [{'userID': userID, 'UID': uid, 'uid_nick': nickname, 'password': password}]
                     data_list = json.dumps(data_list)
                     data = {'data_list': data_list}
-                    requests.post(url, data=data, timeout=2)
+                    alexa_thread = threading.Thread(
+                        target=CommonService.update_alexa_events,
+                        kwargs=data)
+                    alexa_thread.start()
 
             return response.json(0, res)
 

+ 7 - 3
Controller/UidSetController.py

@@ -11,6 +11,7 @@
 @file: AliPayObject.py
 @Contact: pzb3076@163.com
 """
+import threading
 import time
 import traceback
 
@@ -401,12 +402,15 @@ class UidSetView(View):
                 uid_channel_set_qs.update(**deviceData)
 
             if uidObject[0].is_alexa == 1 and 'channel_name' in deviceData.keys():
-                # 请求Alexa服务器更新事件网关
+                # 异步请求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)
+                alexa_thread = threading.Thread(
+                    target=CommonService.update_alexa_events,
+                    kwargs=data)
+                alexa_thread.start()
+
         except Exception as e:
             return response.json(177, repr(e))
         else:

+ 18 - 1
Service/CommonService.py

@@ -19,10 +19,11 @@ from django.utils.crypto import constant_time_compare
 from pyipip import IPIPDatabase
 
 from Ansjer.config import BASE_DIR, SERVER_DOMAIN_SSL, CONFIG_INFO, CONFIG_TEST, CONFIG_CN, SERVER_DOMAIN_TEST, \
-    SERVER_DOMAIN_CN, SERVER_DOMAIN_US, CONFIG_US, CONFIG_EUR, SERVER_DOMAIN_LIST, SERVER_DOMAIN_EUR
+    SERVER_DOMAIN_CN, SERVER_DOMAIN_US, CONFIG_US, CONFIG_EUR, SERVER_DOMAIN_LIST, SERVER_DOMAIN_EUR, ALEXA_DOMAIN
 from Controller.CheckUserData import RandomStr
 from Model.models import iotdeviceInfoModel, Device_Info, UIDModel, AppDeviceType, UIDCompanySerialModel, GatewayPush, \
     Device_User
+from Object.AWS.S3Email import S3Email
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 
@@ -892,3 +893,19 @@ GCqvlyw5dfxNA+EtxNE2wCW/LW7ENJlACgcfgPlBZtpLheWoZB/maw4=
             # 截掉.00然后转为浮点型
             tz = float(gateway_push_qs.tz[:-3])
         return tz
+
+    @staticmethod
+    def update_alexa_events(data):
+        """
+        请求Alexa服务器更新事件网关
+        邮件提醒捕获的异常
+        @param data: 请求参数
+        @return:
+        """
+        try:
+            url = ALEXA_DOMAIN + 'deviceStatus/addOrUpdateV2'
+            requests.post(url, data=data, timeout=30)
+        except Exception as e:
+            S3Email().faEmail(
+                '请求Alexa服务器更新事件网关异常:error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)),
+                'servers@ansjer.com')