瀏覽代碼

新增first_in变量用于,旧机制推送与否的判断
以及一段if判断

WuYiPei 5 年之前
父節點
當前提交
cfb0517a06
共有 1 個文件被更改,包括 11 次插入4 次删除
  1. 11 4
      Controller/DetectController.py

+ 11 - 4
Controller/DetectController.py

@@ -77,7 +77,10 @@ class NotificationView(View):
         have_ykey = redisObj.get_data(key=ykey)  # uid_set 数据库缓存
         have_pkey = redisObj.get_data(key=pkey)  # 一分钟限制key
         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)
@@ -87,7 +90,7 @@ class NotificationView(View):
         else:
             # 设置推送时间为60秒一次
             redisObj.set_data(key=pkey, val=1, expire=60)
-            print("从数据库查到数据")
+            first_in = 1
             # 从数据库查询出来
             uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid,uid_set__detect_status=1). \
                 values('token_val', 'app_type', 'appBundleId',
@@ -103,8 +106,6 @@ class NotificationView(View):
         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']
@@ -120,6 +121,9 @@ 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
         auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
         bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
         kwag_args = {
@@ -189,8 +193,10 @@ class NotificationView(View):
             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")
             return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
         elif is_st == '1':
+            print("is_st=1")
             # Endpoint以杭州为例,其它Region请按实际情况填写。
             obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
             # 设置此签名URL在60秒内有效。
@@ -198,6 +204,7 @@ class NotificationView(View):
             res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
             return JsonResponse(status=200, data=res_data)
         elif is_st == '3':
+            print("is_st=3")
             # 人形检测带动图
             # Endpoint以杭州为例,其它Region请按实际情况填写。
             img_url_list = []