tanghongbin 4 лет назад
Родитель
Сommit
bc37951696
3 измененных файлов с 51 добавлено и 39 удалено
  1. 20 18
      Controller/EquipmentManager.py
  2. 16 20
      Controller/EquipmentManagerV3.py
  3. 15 1
      Service/ModelService.py

+ 20 - 18
Controller/EquipmentManager.py

@@ -96,6 +96,12 @@ def addNewUserEquipmentInterface(request):
                 userDevice = Device_Info(id=CommonService.getUserID(getUser=False), userID_id=userID,
                                          **deviceData)
                 userDevice.save()
+                if UID == '98UXAA8BRPA35VAL111A':
+                    asy = threading.Thread(target=ModelService.add_log,
+                                           args=(CommonService.get_ip_address(request), userID, 'addV0'))
+                    asy.start()
+
+
 
                 # is_bind = Device_Info.objects.filter(UID=UID, isShare=False)
                 # # 判断是否有已绑定用户
@@ -158,6 +164,9 @@ def delUserEquipmentInterface(request):
         # redisObj.del_data(key='uid_qs_' + userID)
         if dv_qs.exists():
             uid = dv_qs[0].UID
+            asy = threading.Thread(target=ModelService.add_log, args=(CommonService.get_ip_address(request), userID, 'deleteV1'))
+            asy.start()
+
             print('删除')
             UID_Preview.objects.filter(uid=uid).delete()
             dv_qs.delete()
@@ -367,14 +376,10 @@ def addInterface(request):
                         is_exist.delete()
 
                 if UID == '98UXAA8BRPA35VAL111A':
-                    file_path = '/'.join((BASE_DIR, 'static/add_device.log'))
-                    file = open(file_path, 'a+')
-                    file.write(
-                        CommonService.get_ip_address(request) + "; username:" + userID + "; time:" + time.strftime(
-                            "%Y-%m-%d %H:%M:%S", time.localtime())+"; addV1")
-                    file.write('\n')
-                    file.flush()
-                    file.close()
+                    asy = threading.Thread(target=ModelService.add_log,
+                                           args=(CommonService.get_ip_address(request), userID, 'addV1'))
+                    asy.start()
+
                 pass
                 # is_bind = Device_Info.objects.filter(UID=UID, isShare=False)
                 # # 判断是否有已绑定用户
@@ -526,10 +531,12 @@ def admin_addInterface(request):
                 file_path = '/'.join((BASE_DIR, 'static/test.log'))
 
                 file = open(file_path, 'a+')
-                file.write(ipdizhi+"; username:"+username+"; time:"+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
+                file.write(ipdizhi + "; username:" + username + "; time:" + time.strftime("%Y-%m-%d %H:%M:%S",
+                                                                                          time.localtime()))
                 file.write('\n')
                 file.flush()
                 file.close()
+
                 # is_bind = Device_Info.objects.filter(UID=UID, isShare=False)
                 # # 判断是否有已绑定用户
                 # if not is_bind.exists():
@@ -673,15 +680,10 @@ def deleteInterface(request):
         dv_qs = Device_Info.objects.filter(userID_id=userID, id=id)
         if dv_qs.exists():
             uid = dv_qs[0].UID
-            if uid == '98UXAA8BRPA35VAL111A':
-                file_path = '/'.join((BASE_DIR, 'static/add_device.log'))
-                file = open(file_path, 'a+')
-                file.write(
-                    CommonService.get_ip_address(request) + "; username:" + userID + "; time:" + time.strftime(
-                        "%Y-%m-%d %H:%M:%S", time.localtime()) + "; delete")
-                file.write('\n')
-                file.flush()
-                file.close()
+            asy = threading.Thread(target=ModelService.add_log,
+                                   args=(CommonService.get_ip_address(request), userID, 'deleteV2'))
+            asy.start()
+
             if dv_qs[0].isShare:
                 dv_qs.delete()
             else:

+ 16 - 20
Controller/EquipmentManagerV3.py

@@ -61,8 +61,10 @@ class EquipmentManagerV3(View):
         View_Password = self.decode_pwd(View_Password)
         Type = request_dict.get('Type', None)
         ChannelIndex = request_dict.get('ChannelIndex', None)
+
         if all([UID, NickName, View_Account, Type, ChannelIndex]):
             tko = TokenObject(token)
+
             response.lang = tko.lang
             if tko.code == 0:
                 userID = tko.userID
@@ -76,12 +78,10 @@ class EquipmentManagerV3(View):
                         else:
                             is_exist.delete()
                     if UID == '98UXAA8BRPA35VAL111A':
-                        file_path = '/'.join((BASE_DIR, 'static/add_device.log'))
-                        file = open(file_path, 'a+')
-                        file.write(CommonService.get_ip_address(request) + "; username:" + userID + "; time:" + time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) + "; addV3")
-                        file.write('\n')
-                        file.flush()
-                        file.close()
+                        asy = threading.Thread(target=ModelService.add_log,
+                                               args=(CommonService.get_ip_address(request), userID, 'addV3'))
+                        asy.start()
+
                     # is_bind = Device_Info.objects.filter(UID=UID, isShare=False)
                     # # 判断是否有已绑定用户
                     # if is_bind:
@@ -162,20 +162,14 @@ class EquipmentManagerV3(View):
             print(e)
             return response.json(177, repr(e))
         else:
-            # qs = Device_Info.objects.filter(userID_id=userID, id=id)
-            qs = dev_info_qs
+            qs = Device_Info.objects.filter(userID_id=userID, id=id)
             res = CommonService.qs_to_dict(qs)
             if qs.exists():
                 uid = qs[0].UID
                 if uid == '98UXAA8BRPA35VAL111A':
-                    file_path = '/'.join((BASE_DIR, 'static/add_device.log'))
-                    file = open(file_path, 'a+')
-                    file.write(
-                        CommonService.get_ip_address(request) + "; username:" + userID + "; time:" + time.strftime(
-                            "%Y-%m-%d %H:%M:%S", time.localtime()) + "; modifyV3")
-                    file.write('\n')
-                    file.flush()
-                    file.close()
+                    asy = threading.Thread(target=ModelService.add_log,
+                                           args=(CommonService.get_ip_address(request), userID, 'modifyV3'))
+                    asy.start()
 
                 nickname = qs[0].NickName
                 # 增加设备影子信息修改昵称 start
@@ -197,6 +191,10 @@ class EquipmentManagerV3(View):
                     UidSetModel.objects.create(**uid_set_create_dict)
                 di_qs = Device_Info.objects.filter(UID=uid)
                 di_qs.update(NickName=nickname)
+                if deviceData is not None and deviceData.__contains__('NickName') and us_qs[0].is_alexa == 1:
+
+                    asy = threading.Thread(target=ModelService.notify_alexa_add, args=(uid, userID, nickname))
+                    asy.start()
             # redisObj = RedisObject(db=8)
             # redisObj.del_data(key='uid_qs_' + userID)
             return response.json(0, res)
@@ -350,7 +348,7 @@ class EquipmentManagerV3(View):
                 for index, item in enumerate(result):
                     if uid == item['UID']:
                         # 加密
-                        item['View_Password'] = self.encrypt_pwd(item['View_Password']) 
+                        item['View_Password'] = self.encrypt_pwd(item['View_Password'])
                         data.append(item)
                         return response.json(0, data)
             items = []
@@ -402,6 +400,4 @@ class EquipmentManagerV3(View):
                 password = password.decode('utf-8')
                 # 去前3位,后3位
                 password = password[3:-3]
-        return password
-
-
+        return password

+ 15 - 1
Service/ModelService.py

@@ -1,5 +1,9 @@
+import logging
+import time
+
 import requests
 
+from Ansjer.config import BASE_DIR
 from Model.models import *
 from Service.CommonService import CommonService
 import json
@@ -157,7 +161,7 @@ class ModelService:
 
     @staticmethod
     def notify_alexa_add(uid, userID, nickname):
-        url = 'https://www.zositech.xyz/deviceStatus/addOrupdate'
+        url = 'https://www.zositech.xyz/deviceStatus/addOrUpdate'
         data = {
             'UID': uid,
             'userID': userID,
@@ -168,6 +172,16 @@ class ModelService:
         except Exception as e:
             print(repr(e))
 
+    @staticmethod
+    def add_log(ip, userID, operation):
+        file_path = '/'.join((BASE_DIR, 'static/delete_device.log'))
+        file = open(file_path, 'a+')
+        file.write(ip + "; username:" + userID + "; time:" + time.strftime(
+                "%Y-%m-%d %H:%M:%S", time.localtime()) + "; " + operation)
+        file.write('\n')
+        file.flush()
+        file.close()
+
 
 def notify_alexa_delete(userID, UID):
     url = 'https://www.zositech.xyz/deviceStatus/delete'