瀏覽代碼

上传uid添加操作日志

locky 4 年之前
父節點
當前提交
0fe0772642
共有 3 個文件被更改,包括 20 次插入6 次删除
  1. 2 3
      Controller/IotCoreController.py
  2. 2 2
      Controller/SerialNumberController.py
  3. 16 1
      Controller/VPGController.py

+ 2 - 3
Controller/IotCoreController.py

@@ -229,7 +229,7 @@ class IotCoreView(View):
             return response.json(444)
 
     def request_publish_message(self, request_dict, response, request):
-        # Alexa请求IoT Core下发MQTT消息
+        # Alexa请求IoT Core下发MQTT消息通知设备开始或停止推流
         UID = request_dict.get('UID', None)
         MSG = request_dict.get('MSG', None)
 
@@ -258,9 +258,8 @@ class IotCoreView(View):
             # Token = '297a601b3925e04daab5a60280650e09'
             topic_name = thing_name + '_rtsp_topic'     # MQTT主题
 
-            # rtsp://rtsp.zositech.org:8554/ZFdqWldXRFpMTkVaYVZEaEJXRXhUV0RFeE1VRT1B
             # api doc: https://docs.aws.amazon.com/zh_cn/iot/latest/developerguide/http.html
-            # https://IoT_data_endpoint/topics/url_encoded_topic_name?qos=1
+            # url: https://IoT_data_endpoint/topics/url_encoded_topic_name?qos=1
             # post请求url来发布MQTT消息
             url = 'https://{}/topics/{}'.format(endpoint, topic_name)
             authorizer_name = 'Ansjer_Iot_Auth'

+ 2 - 2
Controller/SerialNumberController.py

@@ -273,9 +273,9 @@ class SerialNumberView(View):
                         'user_id': 1,
                         'status': 200,
                         'time': now_time,
-                        'operation': '序列号{}绑定uid{}'.format(serial, uid.uid),
                         'content': json.dumps(content),
                         'url': 'serialNumber/attachUID',
+                        'operation': '序列号{}绑定uid: {}'.format(serial, uid.uid),
                     }
                     LogModel.objects.create(**log)
 
@@ -399,9 +399,9 @@ class SerialNumberView(View):
             'user_id': 1,
             'status': 200,
             'time': now_time,
-            'operation': '序列号{}解绑uid{}'.format(serial, uid),
             'content': json.dumps(content),
             'url': 'serialNumber/detachUID',
+            'operation': '序列号{}解绑uid: {}'.format(serial, uid),
         }
         LogModel.objects.create(**log)
         return response.json(0)

+ 16 - 1
Controller/VPGController.py

@@ -1,5 +1,6 @@
 #!/usr/bin/env python3
 # -*- coding: utf-8 -*-
+import json
 import os
 import re
 import time
@@ -9,7 +10,7 @@ from django.views import View
 from django.views.decorators.csrf import csrf_exempt
 
 from Ansjer.config import BASE_DIR
-from Model.models import RegionModel, CompanyModel, VPGModel, UIDModel, MacModel, UIDCompanySerialModel
+from Model.models import RegionModel, CompanyModel, VPGModel, UIDModel, MacModel, UIDCompanySerialModel, LogModel
 from Object.uidManageResponseObject import uidManageResponseObject
 from Object.TokenObject import TokenObject
 from Service.CommonService import CommonService
@@ -269,7 +270,21 @@ def do_upload_uid(request):
                 else:
                     temp_mac = current_mac  # 赋值为FF写入mac表
                     break
+
+        ip = CommonService.get_ip_address(request)
+        content = json.loads(json.dumps(request_dict))
+        log = {
+            'ip': ip,
+            'user_id': 1,
+            'status': 200,
+            'time': add_time,
+            'url': 'vpgUid/uid',
+            'content': json.dumps(content),
+            'operation': '上传{}个uid到VPG ID {}'.format(len(uid_list), vpg_id),
+        }
+        
         with transaction.atomic():
+            LogModel.objects.create(**log)  # 记录操作日志
             UIDModel.objects.bulk_create(bulk)  # 批量写入uid数据
             uid_count = UIDModel.objects.filter(vpg_id=vpg_id).count()  # 获取族群下uid的数量
             VPGModel.objects.filter(id=vpg_id).update(uid_count=uid_count)   # 更新vgp表的uid_count