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