|
@@ -102,7 +102,8 @@ class DevicePushService:
|
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
|
values('token_val', 'app_type', 'appBundleId', 'm_code', 'push_type', 'userID_id', 'userID__NickName',
|
|
|
'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
|
|
|
- 'uid_set__channel', 'uid_set__ai_type', 'uid_set__device_type', 'uid_set__new_detect_interval')
|
|
|
+ 'uid_set__channel', 'uid_set__ai_type', 'uid_set__device_type', 'uid_set__new_detect_interval',
|
|
|
+ 'uid_set__msg_notify')
|
|
|
else:
|
|
|
# 一键通话只推主用户
|
|
|
device_info_qs = Device_Info.objects.filter(UID=uid).values('vodPrimaryUserID')
|
|
@@ -110,7 +111,8 @@ class DevicePushService:
|
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, userID_id=primary_user_id). \
|
|
|
values('token_val', 'app_type', 'appBundleId', 'm_code', 'push_type', 'userID_id', 'userID__NickName',
|
|
|
'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
|
|
|
- 'uid_set__channel', 'uid_set__ai_type', 'uid_set__device_type', 'uid_set__new_detect_interval')
|
|
|
+ 'uid_set__channel', 'uid_set__ai_type', 'uid_set__device_type', 'uid_set__new_detect_interval',
|
|
|
+ 'uid_set__msg_notify')
|
|
|
return uid_push_qs
|
|
|
|
|
|
@staticmethod
|
|
@@ -154,9 +156,11 @@ class DevicePushService:
|
|
|
kwag_args = params['kwag_args']
|
|
|
code_data = {'do_apns_code': '', 'do_fcm_code': '', 'do_jpush_code': ''}
|
|
|
local_date_time = ''
|
|
|
- # push_permission = True
|
|
|
+ # push_permission = True 多通道权限限制接收
|
|
|
try:
|
|
|
params['event_tag'] = cls.get_event_tag(params['ai_type'], params['event_type'], params['detection'])
|
|
|
+ is_app_push = True if params['event_tag'] == 606 else \
|
|
|
+ cls.is_send_app_push(params['event_type'], params['event_tag'], params['app_push_config'])
|
|
|
for up in uid_set_push_list:
|
|
|
appBundleId = up['appBundleId']
|
|
|
token_val = up['token_val']
|
|
@@ -202,7 +206,7 @@ class DevicePushService:
|
|
|
params['lang'] = lang
|
|
|
params['tz'] = tz
|
|
|
params['kwag_args'] = kwag_args
|
|
|
- code_data = cls.send_app_msg_push(up['push_type'], **params)
|
|
|
+ code_data = cls.send_app_msg_push(up['push_type'], **params) if is_app_push else code_data
|
|
|
return {'code_date': code_data, 'new_device_info_list': new_device_info_list, 'sys_msg_list': sys_msg_list,
|
|
|
'local_date_time': local_date_time}
|
|
|
except Exception as e:
|
|
@@ -817,3 +821,103 @@ class DevicePushService:
|
|
|
return False
|
|
|
c = [x for x in event_types if x in event_types2]
|
|
|
return True if c else False
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def is_send_app_push(event_type, event_tag, app_push_config):
|
|
|
+ """
|
|
|
+ 是否进行APP消息提醒
|
|
|
+ @return: True|False
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ if not app_push_config:
|
|
|
+ return True
|
|
|
+
|
|
|
+ is_push = app_push_config['appPush']
|
|
|
+ if is_push != 1: # 1:进行APP提醒,其它则不执行APP提醒
|
|
|
+ return False
|
|
|
+
|
|
|
+ all_day = app_push_config['pushTime']['allDay']
|
|
|
+ # 允许设备类型APP提醒列表
|
|
|
+ app_event_types = app_push_config['eventTypes']['device']
|
|
|
+
|
|
|
+ if all_day == 0: # 1:全天提醒,0:自定义时间提醒
|
|
|
+ push_time_config = app_push_config['pushTime']
|
|
|
+ # 计算当前时间是否在自定义消息提醒范围内
|
|
|
+ if not DevicePushService.is_push_notify_allowed_now(push_time_config):
|
|
|
+ LOGGING.info('APP推送提醒不在自定义时间内:{}'.format(push_time_config))
|
|
|
+ return False
|
|
|
+ # APP接收提醒,判断识别类型是否勾选提醒
|
|
|
+ push_result = DevicePushService.is_type_push(event_type, event_tag, app_event_types)
|
|
|
+ LOGGING.info('APP推送提醒是否执行:{}'.format(push_result))
|
|
|
+ return push_result
|
|
|
+ except Exception as e:
|
|
|
+ LOGGING.info('判断是否执行APP推送异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return True
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def is_type_push(event_type, event_tag, app_event_types):
|
|
|
+ # 检查事件标签和应用事件类型是否都存在
|
|
|
+ if event_tag and app_event_types:
|
|
|
+ # 将事件标签按逗号分割成列表,并转换为整数类型
|
|
|
+ tag_list = [int(event) for event in event_tag.split(',') if event]
|
|
|
+ # 判断是否有任一标签允许应用提醒
|
|
|
+ return any(item in app_event_types for item in tag_list)
|
|
|
+
|
|
|
+ # 检查事件类型和用户所选事件类型是否都存在,并判断事件类型在用户所选事件类型列表中
|
|
|
+ return event_type and app_event_types and event_type in app_event_types
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def is_push_notify_allowed_now(push_time_config):
|
|
|
+ """
|
|
|
+ 判断当前时间是否在允许APP推送提醒
|
|
|
+ """
|
|
|
+ now_time = int(time.time())
|
|
|
+ start_time = push_time_config['startTime']
|
|
|
+ end_time = push_time_config['endTime']
|
|
|
+ repeat = push_time_config['repeat']
|
|
|
+ tz = push_time_config['timeZone']
|
|
|
+
|
|
|
+ # 获取当前日期和周几
|
|
|
+ now_date, week = DevicePushService.get_now_date_and_week(now_time, tz)
|
|
|
+
|
|
|
+ # 判断是否在重复日范围内
|
|
|
+ if not DevicePushService.is_repeated(week, repeat):
|
|
|
+ return False
|
|
|
+
|
|
|
+ # 计算当前日期在一天中的秒数
|
|
|
+ seconds = LocalDateTimeUtil.convert_time_to_seconds(now_date)
|
|
|
+
|
|
|
+ # 判断是否在APP推送提醒范围内
|
|
|
+ return DevicePushService.is_in_effect(start_time, end_time, seconds)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def is_in_effect(start, end, now_seconds):
|
|
|
+ """
|
|
|
+ 判断是否在提醒时间范围内
|
|
|
+ @params: 开始时间秒
|
|
|
+ @params: 结束时间秒
|
|
|
+ @params: 当前时间秒
|
|
|
+ @return: 当前时间是在范围内返回True 否则False
|
|
|
+ """
|
|
|
+ if start < end:
|
|
|
+ return start <= now_seconds <= end
|
|
|
+ else:
|
|
|
+ return start <= now_seconds or now_seconds <= end
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def is_repeated(week_day, repeat_day):
|
|
|
+ """
|
|
|
+ 判断是否重复日
|
|
|
+ @params: week_day 周几
|
|
|
+ @params: 重复日1-127
|
|
|
+ @return: 如果当前日期在重复日则返回True否则False
|
|
|
+ """
|
|
|
+ # 判断对应位置上的值是否为 1
|
|
|
+ is_repeat = (repeat_day >> (week_day - 1)) & 1 == 1
|
|
|
+ return is_repeat
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def get_now_date_and_week(now_time, tz):
|
|
|
+ now_data = CommonService.get_now_time_str(now_time, tz, 'cn')
|
|
|
+ week = LocalDateTimeUtil.date_to_week(now_data)
|
|
|
+ return now_data, week
|