|
@@ -6,11 +6,13 @@ import threading
|
|
|
import time
|
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
|
|
|
|
-from Model.models import DeviceTypeModel, Device_Info, GatewayPush, CountryModel, SysMsgModel, CustomizedPush
|
|
|
+from Model.models import DeviceTypeModel, Device_Info, GatewayPush, CountryModel, SysMsgModel, CustomizedPush, \
|
|
|
+ UserEmailSubscriptions
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.HuaweiPushService.HuaweiPushService import HuaweiPushObject
|
|
|
from Service.PushService import PushObject
|
|
|
from AnsjerPush.config import XM_PUSH_CHANNEL_ID
|
|
|
+
|
|
|
CUSTOMIZED_PUSH_LOGGER = logging.getLogger('customized_push')
|
|
|
|
|
|
|
|
@@ -36,7 +38,8 @@ class CustomizedPushObject:
|
|
|
now_time = int(time.time())
|
|
|
|
|
|
index = register_period.find('-')
|
|
|
- n, m = register_period[:index], register_period[index+1:]
|
|
|
+ n, m = register_period[:index], register_period[index + 1:]
|
|
|
+
|
|
|
if m == '':
|
|
|
# 0-,所有时间
|
|
|
if n == '0':
|
|
@@ -48,7 +51,7 @@ class CustomizedPushObject:
|
|
|
n_year_ago_timestamp = now_time - n_years_seconds
|
|
|
n_year_ago = CommonService.timestamp_to_str(n_year_ago_timestamp)
|
|
|
# 注册时间越小越早
|
|
|
- device_info_qs = device_info_qs.filter(userID__data_joined__lte=n_year_ago).\
|
|
|
+ device_info_qs = device_info_qs.filter(userID__data_joined__lte=n_year_ago). \
|
|
|
values_list('userID_id', flat=True)
|
|
|
else:
|
|
|
# n-m年,(如2-3年)
|
|
@@ -56,11 +59,11 @@ class CustomizedPushObject:
|
|
|
n_year_ago_timestamp = now_time - n_years_seconds
|
|
|
m_year_ago_timestamp = now_time - m_years_seconds
|
|
|
# 时间戳转时间字符串
|
|
|
- n_year_ago = CommonService.timestamp_to_str(n_year_ago_timestamp) # 2021
|
|
|
- m_year_ago = CommonService.timestamp_to_str(m_year_ago_timestamp) # 2020
|
|
|
+ n_year_ago = CommonService.timestamp_to_str(n_year_ago_timestamp) # 2021
|
|
|
+ m_year_ago = CommonService.timestamp_to_str(m_year_ago_timestamp) # 2020
|
|
|
# 2020 <= 注册时间 <= 2021
|
|
|
- device_info_qs = device_info_qs.\
|
|
|
- filter(userID__data_joined__gte=m_year_ago, userID__data_joined__lte=n_year_ago).\
|
|
|
+ device_info_qs = device_info_qs. \
|
|
|
+ filter(userID__data_joined__gte=m_year_ago, userID__data_joined__lte=n_year_ago). \
|
|
|
values_list('userID_id', flat=True)
|
|
|
|
|
|
user_id_list = list(device_info_qs)
|
|
@@ -97,7 +100,7 @@ class CustomizedPushObject:
|
|
|
|
|
|
try:
|
|
|
gateway_push_qs = GatewayPush.objects.filter(
|
|
|
- user_id__in=user_id_list, app_bundle_id__in=app_bundle_id_list).\
|
|
|
+ user_id__in=user_id_list, app_bundle_id__in=app_bundle_id_list). \
|
|
|
values('user_id', 'app_bundle_id', 'push_type', 'token_val')
|
|
|
if gateway_push_qs.exists():
|
|
|
sys_msg_list = []
|
|
@@ -106,11 +109,14 @@ class CustomizedPushObject:
|
|
|
for gateway_push in gateway_push_qs:
|
|
|
# user_id保存列表,避免重复写入数据
|
|
|
user_id = gateway_push['user_id']
|
|
|
+ user_email_sub_qs = UserEmailSubscriptions.objects.filter(
|
|
|
+ user_id=user_id, push_sub_status=0)
|
|
|
if user_id not in saved_user_id_list:
|
|
|
saved_user_id_list.append(user_id)
|
|
|
sys_msg_list.append(SysMsgModel(
|
|
|
userID_id=user_id, title=title, msg=msg, jumpLink=link, addTime=n_time, updTime=n_time))
|
|
|
- gateway_push_list.append(gateway_push)
|
|
|
+ if not user_email_sub_qs.exists():
|
|
|
+ gateway_push_list.append(gateway_push)
|
|
|
# 保存系统消息和异步推送消息
|
|
|
SysMsgModel.objects.bulk_create(sys_msg_list)
|
|
|
pre_push_kwargs = {
|