Browse Source

打印日志

tanghongbin 4 years ago
parent
commit
857fa30854
3 changed files with 26 additions and 2 deletions
  1. 5 2
      Controller/DetectController.py
  2. 4 0
      Controller/ShadowController.py
  3. 17 0
      Object/LogUtil.py

+ 5 - 2
Controller/DetectController.py

@@ -25,6 +25,7 @@ from AnsjerPush.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, DETECT_
     APNS_CONFIG, BASE_DIR, APNS_MODE
 from Model.models import Equipment_Info, UidPushModel, SysMsgModel
 from Object.ETkObject import ETkObject
+from Object.LogUtil import LogUtil
 from Object.RedisObject import RedisObject
 from Object.UidTokenObject import UidTokenObject
 from Service.CommonService import CommonService
@@ -47,6 +48,7 @@ class NotificationView(View):
         return self.validation(request.POST)
 
     def validation(self, request_dict):
+        LogUtil.write_log(log='push----------{time}'.format(time=time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())))
         uidToken = request_dict.get('uidToken', None)
         etk = request_dict.get('etk', None)
         channel = request_dict.get('channel', '1')
@@ -67,7 +69,7 @@ class NotificationView(View):
         else:
             utko = UidTokenObject(uidToken)
             uid = utko.UID
-        pkey = '{uid}_{channel}_ptl'.format(uid=uid, event_type=event_type, channel=channel)
+        pkey = '{uid}_{channel}_{event_type}_ptl'.format(uid=uid, event_type=event_type, channel=channel)
         # ykey = 'MUJ887NLR8K8GBM9111A_redis_qs'.format(uid=uid)
         ykey = '{uid}_redis_qs'.format(uid=uid)
         dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=event_type, channel=channel)
@@ -90,6 +92,7 @@ class NotificationView(View):
         # 数据库读取数据
         if have_ykey:
             redis_list = eval(redisObj.get_data(key=ykey))
+            print(have_ykey)
         else:
             # 从数据库查询出来
             uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid,uid_set__detect_status=1). \
@@ -97,6 +100,7 @@ class NotificationView(View):
                        'push_type', 'userID_id', 'userID__NickName',
                        'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
                        'uid_set__channel')
+            print(uid_push_qs)
             # 新建一个list接收数据
             redis_list = []
             # 把数据库数据追加进redis_list
@@ -240,7 +244,6 @@ class NotificationView(View):
         if is_sys_msg:
             SysMsgModel.objects.bulk_create(sys_msg_list)
         Equipment_Info.objects.bulk_create(eq_list)
-
         if is_st == '0' or is_st == '2':
             print("is_st=0or2")
             for up in redis_list:

+ 4 - 0
Controller/ShadowController.py

@@ -16,6 +16,7 @@
 # 生产环境
 # shadow.dvema.com
 # 设备影子更新
+from Object.LogUtil import LogUtil
 from Object.ResponseObject import ResponseObject
 from Object.ETkObject import ETkObject
 import time
@@ -25,6 +26,7 @@ from django.http import JsonResponse
 from Object.UidTokenObject import UidTokenObject
 
 def generate_utk(request):
+    LogUtil.write_log(log='generate----------{time}'.format(time=time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())))
     request.encoding = 'utf-8'
     response = ResponseObject()
     if request.method == 'GET':
@@ -52,6 +54,8 @@ def generate_utk(request):
 
 # 设备影子更新
 def update_device_shadow(request):
+    LogUtil.write_log(
+        log='shadow----------{time}'.format(time=time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())))
     request.encoding = 'utf-8'
     response = ResponseObject()
     if request.method == 'POST':

+ 17 - 0
Object/LogUtil.py

@@ -0,0 +1,17 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+from AnsjerPush.config import BASE_DIR
+
+
+class LogUtil:
+
+    @staticmethod
+    def write_log(file_path=None, log=''):
+        if not file_path:
+            file_path = '/'.join((BASE_DIR, 'static/test.log'))
+
+        file = open(file_path, 'a+')
+        file.write(log)
+        file.write('\n')
+        file.flush()
+        file.close()