Browse Source

Merge branch 'master' into dev

# Conflicts:
#	Controller/EquipmentManager.py
#	Controller/EquipmentManagerV3.py
#	Model/models.py
#	Service/ModelService.py
tanghongbin 4 years ago
parent
commit
78232cf779
4 changed files with 63 additions and 27 deletions
  1. 17 18
      Controller/EquipmentManager.py
  2. 21 6
      Controller/EquipmentManagerV3.py
  3. 1 1
      Controller/UidUser.py
  4. 24 2
      Service/ModelService.py

+ 17 - 18
Controller/EquipmentManager.py

@@ -2,8 +2,7 @@ import re
 import time
 import traceback
 import threading
-
-import requests
+import logging
 import simplejson as json
 from django.utils import timezone
 from Model.models import Device_User, Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidPushModel
@@ -17,7 +16,6 @@ from Object.ETkObject import ETkObject
 import oss2
 from django.http import JsonResponse
 from Object.RedisObject import RedisObject
-import logging
 
 
 #     查询用户设备
@@ -101,8 +99,6 @@ def addNewUserEquipmentInterface(request):
                                            args=(CommonService.get_ip_address(request), userID, 'addV0'))
                     asy.start()
 
-
-
                 # is_bind = Device_Info.objects.filter(UID=UID, isShare=False)
                 # # 判断是否有已绑定用户
                 # if not is_bind.exists():
@@ -210,6 +206,16 @@ def modifyUserEquipmentInterface(request):
         return response.json(309)
     try:
         deviceData = json.loads(deviceContent)
+
+        if deviceData.__contains__('userID_id'):
+            asy = threading.Thread(target=ModelService.update_log,
+                                   args=(CommonService.get_ip_address(request), userID, 'modifyV0', deviceData, id))
+            asy.start()
+            return response.json(10, '110')
+
+        if deviceData.__contains__('UID'):
+            del deviceData['UID']
+
         dev_info_qs = Device_Info.objects.filter(userID_id=userID, id=id)
         dev_info_qs.update(**deviceData)
     except Exception as e:
@@ -220,14 +226,9 @@ def modifyUserEquipmentInterface(request):
         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()) + "; modifyV1")
-                file.write('\n')
-                file.flush()
-                file.close()
+                asy = threading.Thread(target=ModelService.update_log,
+                                       args=(CommonService.get_ip_address(request), userID, 'modifyV0', deviceContent, id))
+                asy.start()
             nickname = qs[0].NickName
             # 增加设备影子信息修改昵称 start
             us_qs = UidSetModel.objects.filter(uid=uid)
@@ -374,12 +375,11 @@ def addInterface(request):
                         return response.json(174)
                     else:
                         is_exist.delete()
-
                 if UID == '98UXAA8BRPA35VAL111A':
                     asy = threading.Thread(target=ModelService.add_log,
                                            args=(CommonService.get_ip_address(request), userID, 'addV1'))
                     asy.start()
-
+                    return response.json(10, 'illegal uid: {uid}'.format(uid=UID))
                 pass
                 # is_bind = Device_Info.objects.filter(UID=UID, isShare=False)
                 # # 判断是否有已绑定用户
@@ -680,10 +680,9 @@ def deleteInterface(request):
         dv_qs = Device_Info.objects.filter(userID_id=userID, id=id)
         if dv_qs.exists():
             uid = dv_qs[0].UID
-            asy = threading.Thread(target=ModelService.add_log,
-                                   args=(CommonService.get_ip_address(request), userID, 'deleteV2'))
+            asy = threading.Thread(target=ModelService.delete_log,
+                                   args=(CommonService.get_ip_address(request), userID, 'deleteV2', uid))
             asy.start()
-
             if dv_qs[0].isShare:
                 dv_qs.delete()
             else:

+ 21 - 6
Controller/EquipmentManagerV3.py

@@ -81,7 +81,7 @@ class EquipmentManagerV3(View):
                         asy = threading.Thread(target=ModelService.add_log,
                                                args=(CommonService.get_ip_address(request), userID, 'addV3'))
                         asy.start()
-
+                        return response.json(10, 'illegal uid: {uid}'.format(uid=UID))
                     # is_bind = Device_Info.objects.filter(UID=UID, isShare=False)
                     # # 判断是否有已绑定用户
                     # if is_bind:
@@ -107,8 +107,14 @@ class EquipmentManagerV3(View):
                                                  NickName=NickName, View_Account=View_Account,
                                                  View_Password=View_Password, Type=Type, ChannelIndex=ChannelIndex)
                         userDevice.save()
-                        asy = threading.Thread(target=ModelService.notify_alexa_add, args=(UID, userID, NickName))
-                        asy.start()
+
+                        if not us_qs.exists():
+                            us_qs = UidSetModel.objects.filter(uid=UID)
+
+                        if us_qs.exists() 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)
                     except Exception as e:
@@ -153,6 +159,16 @@ class EquipmentManagerV3(View):
         try:
             # deviceData = json.loads(deviceContent)
             deviceData = eval(deviceContent)
+
+            if deviceData.__contains__('userID_id'):
+                asy = threading.Thread(target=ModelService.update_log,
+                                       args=(CommonService.get_ip_address(request), userID, 'modifyV3', deviceData, id))
+                asy.start()
+                return response.json(10, '110')
+
+            if deviceData.__contains__('UID'):
+                del deviceData['UID']
+
             # print(deviceData['View_Password'])
             if deviceData.__contains__('View_Password'):
                 deviceData['View_Password'] = self.decode_pwd(deviceData['View_Password'])
@@ -167,10 +183,9 @@ class EquipmentManagerV3(View):
             if qs.exists():
                 uid = qs[0].UID
                 if uid == '98UXAA8BRPA35VAL111A':
-                    asy = threading.Thread(target=ModelService.add_log,
-                                           args=(CommonService.get_ip_address(request), userID, 'modifyV3'))
+                    asy = threading.Thread(target=ModelService.update_log,
+                                           args=(CommonService.get_ip_address(request), userID, 'modifyV3', deviceData, id))
                     asy.start()
-
                 nickname = qs[0].NickName
                 # 增加设备影子信息修改昵称 start
                 us_qs = UidSetModel.objects.filter(uid=uid)

+ 1 - 1
Controller/UidUser.py

@@ -540,7 +540,7 @@ def v3queryInterface(request):
     else:
         return response.json(tko.code)
 
-# 加密
+# #加密
 def encrypt_pwd(userPwd):
     for i in range(1, 4):
         if i == 1:

+ 24 - 2
Service/ModelService.py

@@ -159,6 +159,7 @@ class ModelService:
         uid_list = Device_Info.objects.filter(userID_id=userID).values_list('UID', flat=True)
         return list(uid_list)
 
+
     @staticmethod
     def notify_alexa_add(uid, userID, nickname):
         url = 'https://www.zositech.xyz/deviceStatus/addOrUpdate'
@@ -168,16 +169,37 @@ class ModelService:
             'uid_nick': nickname
         }
         try:
-            requests.post(url, data=data, timeout=5)
+            res = requests.post(url, data=data, timeout=10)
         except Exception as e:
             print(repr(e))
 
     @staticmethod
     def add_log(ip, userID, operation):
+        file_path = '/'.join((BASE_DIR, 'static/add_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()
+
+    @staticmethod
+    def update_log(ip, userID, operation, content, id):
+        content['xid'] = id
+        file_path = '/'.join((BASE_DIR, 'static/update_device.log'))
+        file = open(file_path, 'a+')
+        file.write(ip + "; username:" + userID + "; time:" + time.strftime(
+            "%Y-%m-%d %H:%M:%S", time.localtime()) + "; content:" + json.dumps(content) + "; " + operation)
+        file.write('\n')
+        file.flush()
+        file.close()
+
+    @staticmethod
+    def delete_log(ip, userID, operation, UID):
         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)
+            "%Y-%m-%d %H:%M:%S", time.localtime()) + "; " + operation + "; uid:" + UID)
         file.write('\n')
         file.flush()
         file.close()