|
@@ -44,7 +44,7 @@ class NotificationView(View):
|
|
|
is_st = request_dict.get('is_st', None)
|
|
|
if not all([channel, n_time]):
|
|
|
return JsonResponse(status=200, data={'code': 444, 'msg': 'error channel or n_time'})
|
|
|
- redisObj = RedisObject(db=6)
|
|
|
+ redis_obj = RedisObject()
|
|
|
try:
|
|
|
uid = DevicePushService.decode_uid(etk, uidToken) # 解密uid
|
|
|
if len(uid) != 20 and len(uid) != 14:
|
|
@@ -61,9 +61,9 @@ class NotificationView(View):
|
|
|
else:
|
|
|
dkey = '{}_{}_flag'.format(uid, channel)
|
|
|
|
|
|
- have_ykey = redisObj.get_data(key=ykey) # uid_set 数据库缓存
|
|
|
- have_pkey = redisObj.get_data(key=pkey) # 一分钟限制key
|
|
|
- have_dkey = redisObj.get_data(key=dkey) # 推送类型限制
|
|
|
+ have_ykey = redis_obj.get_data(key=ykey) # uid_set 数据库缓存
|
|
|
+ have_pkey = redis_obj.get_data(key=pkey) # 一分钟限制key
|
|
|
+ have_dkey = redis_obj.get_data(key=dkey) # 推送类型限制
|
|
|
|
|
|
# 一分钟外,推送开启状态
|
|
|
detect_med_type = 0 # 0推送旧机制 1存库不推送,2推送存库
|
|
@@ -74,7 +74,7 @@ class NotificationView(View):
|
|
|
|
|
|
# 数据库读取数据
|
|
|
if have_ykey:
|
|
|
- uid_push_list = eval(redisObj.get_data(key=ykey))
|
|
|
+ uid_push_list = eval(redis_obj.get_data(key=ykey))
|
|
|
else:
|
|
|
# 从数据库查询出来
|
|
|
uid_push_qs = DevicePushService.query_uid_push(uid, event_type)
|
|
@@ -83,7 +83,7 @@ class NotificationView(View):
|
|
|
return JsonResponse(status=200, data={'code': 176, 'msg': 'no uid_push data'})
|
|
|
# 修改redis数据,并设置过期时间为10分钟
|
|
|
uid_push_list = DevicePushService.qs_to_list(uid_push_qs)
|
|
|
- redisObj.set_data(key=ykey, val=str(uid_push_list), expire=600)
|
|
|
+ redis_obj.set_data(key=ykey, val=str(uid_push_list), expire=600)
|
|
|
if not uid_push_list:
|
|
|
res_data = {'code': 404, 'msg': 'error !'}
|
|
|
return JsonResponse(status=200, data=res_data)
|
|
@@ -107,11 +107,11 @@ class NotificationView(View):
|
|
|
new_detect_interval = uid_push_list[0]['uid_set__new_detect_interval']
|
|
|
detect_interval = new_detect_interval if new_detect_interval > 0 else detect_interval
|
|
|
detect_interval = 60 if detect_interval < 60 else detect_interval
|
|
|
- redisObj.set_data(key=dkey, val=1, expire=detect_interval - 5)
|
|
|
- redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
+ redis_obj.set_data(key=dkey, val=1, expire=detect_interval - 5)
|
|
|
+ redis_obj.set_data(key=pkey, val=1, expire=60)
|
|
|
# 旧模式并且没有pkey,重新创建一个
|
|
|
if not detect_group and not have_pkey:
|
|
|
- redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
+ redis_obj.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')
|
|
|
|
|
@@ -126,7 +126,7 @@ class NotificationView(View):
|
|
|
'is_sys_msg': is_sys_msg, 'channel': channel, 'event_type': event_type, 'n_time': n_time,
|
|
|
'electricity': '', 'bucket': bucket, 'app_push': have_dkey, 'storage_location': 1, 'ai_type': 0,
|
|
|
'dealings_type': 0, 'detection': 0, 'device_type': 1, 'app_push_config': '',
|
|
|
- 'uid_set_push_list': uid_push_list}
|
|
|
+ 'uid_set_push_list': uid_push_list, 'redis_obj': redis_obj}
|
|
|
|
|
|
# 异步推送消息和保存数据
|
|
|
push_thread = threading.Thread(
|