소스 검색

测试app推送间隔,修改部分代码

WuYiPei 5 년 전
부모
커밋
3798c00d2b
1개의 변경된 파일8개의 추가작업 그리고 19개의 파일을 삭제
  1. 8 19
      Controller/DetectController.py

+ 8 - 19
Controller/DetectController.py

@@ -69,14 +69,12 @@ class NotificationView(View):
             utko = UidTokenObject(uidToken)
             uid = utko.UID
 
-        # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
-        pkey = '{uid}_ptl'.format(uid=uid)
+        pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
         ykey = '{uid}_redis_qs'.format(uid=uid)
         dkey = '{uid}_{event_type}_flag'.format(uid=uid, event_type=event_type)
         # 判断redisObj.get_data(key=pkey):不为空
         redisObj = RedisObject(db=6)
         have_ykey = redisObj.get_data(key=ykey)  # uid_set 数据库缓存
-
         have_pkey = redisObj.get_data(key=pkey)  # 一分钟限制key
         have_dkey = redisObj.get_data(key=dkey)  # 推送类型限制
         # 一分钟内不存也不推送
@@ -91,7 +89,7 @@ class NotificationView(View):
             redisObj.set_data(key=pkey, val=1, expire=60)
             print("从数据库查到数据")
             # 从数据库查询出来
-            uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid). \
+            uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid,uid_set__detect_status=1). \
                 values('token_val', 'app_type', 'appBundleId',
                        'push_type', 'userID_id', 'userID__NickName',
                        'lang', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group')
@@ -102,17 +100,11 @@ class NotificationView(View):
                 redis_list.append(qs)
             # 修改redis数据,并设置过期时间为10分钟
             redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
-        # 一分钟内不推,不存
-        if not have_pkey:
-            res_data = {'code': 0, 'msg': 'success!'}
-            return JsonResponse(status=200, data=res_data)
-        # 一分钟外,推送关闭
         if not redis_list:
             res_data = {'code': 0, 'msg': 'success!'}
             return JsonResponse(status=200, data=res_data)
         # 一分钟外,推送开启状态
         detect_med_type = 0  # 0推送旧机制 1存库不推送,2推送存库
-
         is_sys_msg = self.is_sys_msg(int(event_type))
         nickname = redis_list[0]['uid_set__nickname']
         detect_interval = redis_list[0]['uid_set__detect_interval']
@@ -123,11 +115,11 @@ class NotificationView(View):
         if detect_group:
             if have_dkey:
                 detect_med_type = 1
-            detect_med_type = 2
-            detect_group_list = detect_group.split(',')
-            if event_type in detect_group_list:
-                redisObj.set_data(key=dkey, val=1, expire=detect_interval)
-
+            else:
+                detect_med_type = 2
+                detect_group_list = detect_group.split(',')
+                if event_type in detect_group_list:
+                    redisObj.set_data(key=dkey, val=1, expire=detect_interval)
         auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
         bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
         kwag_args = {
@@ -143,7 +135,6 @@ class NotificationView(View):
         eq_list = []
         sys_msg_list = []
         userID_ids = []
-
         for up in redis_list:
             push_type = up['push_type']
             appBundleId = up['appBundleId']
@@ -159,8 +150,6 @@ class NotificationView(View):
             kwag_args['token_val'] = token_val
             kwag_args['msg_title'] = msg_title
             kwag_args['msg_text'] = msg_text
-            # 第一次进来,才推送
-            print("第一次进来推送")
             if detect_med_type == 2 or detect_med_type == 0:
                 if push_type == 0:  # ios apns
                     self.do_apns(**kwag_args)
@@ -168,6 +157,7 @@ class NotificationView(View):
                     self.do_fcm(**kwag_args)
                 elif push_type == 2:  # android jpush
                     self.do_jpush(**kwag_args)
+            # 以下是存库
             userID_id = up["userID_id"]
             int_is_st = int(is_st)
             if userID_id not in userID_ids:
@@ -198,7 +188,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':
             return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
         elif is_st == '1':