Selaa lähdekoodia

修复旧模式每隔一分钟推送但一分钟后一直推送bug

WuYiPei 5 vuotta sitten
vanhempi
commit
4751d627e2
1 muutettua tiedostoa jossa 5 lisäystä ja 10 poistoa
  1. 5 10
      Controller/DetectController.py

+ 5 - 10
Controller/DetectController.py

@@ -50,6 +50,7 @@ class NotificationView(View):
         uidToken = request_dict.get('uidToken', None)
         etk = request_dict.get('etk', None)
         channel = request_dict.get('channel', '1')
+        channel = request_dict.get('channel', '1')
         n_time = request_dict.get('n_time', None)
         event_type = request_dict.get('event_type', None)
         is_st = request_dict.get('is_st', None)
@@ -68,7 +69,6 @@ class NotificationView(View):
         else:
             utko = UidTokenObject(uidToken)
             uid = utko.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)
@@ -79,8 +79,6 @@ class NotificationView(View):
         have_dkey = redisObj.get_data(key=dkey)  # 推送类型限制
         # 一分钟外,推送开启状态
         detect_med_type = 0  # 0推送旧机制 1存库不推送,2推送存库
-        # 旧机制推送与否的判断
-        first_in = ''
         if have_pkey:
             res_data = {'code': 0, 'msg': 'success!'}
             return JsonResponse(status=200, data=res_data)
@@ -88,9 +86,6 @@ class NotificationView(View):
         if have_ykey:
             redis_list = eval(redisObj.get_data(key=ykey))
         else:
-            # 设置推送时间为60秒一次
-            redisObj.set_data(key=pkey, val=1, expire=60)
-            first_in = 1
             # 从数据库查询出来
             uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid,uid_set__detect_status=1). \
                 values('token_val', 'app_type', 'appBundleId',
@@ -121,9 +116,10 @@ class NotificationView(View):
                 detect_group_list = detect_group.split(',')
                 if event_type in detect_group_list:
                     redisObj.set_data(key=dkey, val=1, expire=detect_interval)
-        # 旧模式除第一次进来都不推送所以设置为1
-        if not detect_group and not first_in:
-            detect_med_type = 1
+        # 旧模式并且没有pkey,重新创建一个
+        if not detect_group and not have_pkey:
+            # 设置推送时间为60秒一次
+            redisObj.set_data(key=pkey, val=1, expire=60)
         auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
         bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
         kwag_args = {
@@ -188,7 +184,6 @@ class NotificationView(View):
                         uid=uid,
                         eventType=event_type))
                 userID_ids.append(userID_id)
-
         if is_sys_msg:
             SysMsgModel.objects.bulk_create(sys_msg_list)
         Equipment_Info.objects.bulk_create(eq_list)