Ver Fonte

定制化推送测试和国内服推给所有用户

locky há 11 meses atrás
pai
commit
d746921419
1 ficheiros alterados com 18 adições e 11 exclusões
  1. 18 11
      Service/CustomizedPushService.py

+ 18 - 11
Service/CustomizedPushService.py

@@ -6,11 +6,12 @@ import threading
 import time
 from concurrent.futures import ThreadPoolExecutor
 
+from AnsjerPush.config import CONFIG_INFO, CONFIG_TEST, CONFIG_CN, XM_PUSH_CHANNEL_ID
 from Model.models import DeviceTypeModel, Device_Info, GatewayPush, CountryModel, SysMsgModel
 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')
 
 
@@ -28,15 +29,21 @@ class CustomizedPushObject:
         # 设备型号和国家
         device_name_list = device_name.split(',')
         device_type_list = DeviceTypeModel.objects.filter(name__in=device_name_list).values_list('type', flat=True)
-        country_name_list = country.split(',')
-        country_id_list = CountryModel.objects.filter(country_name__in=country_name_list).values_list('id', flat=True)
-        device_info_qs = Device_Info.objects.filter(Type__in=device_type_list,
-                                                    userID__region_country__in=country_id_list)
+        # 测试和国内服推给所有用户
+        if CONFIG_INFO in [CONFIG_TEST, CONFIG_CN]:
+            device_info_qs = Device_Info.objects.filter(Type__in=device_type_list)
+        else:
+            country_name_list = country.split(',')
+            country_id_list = CountryModel.objects.filter(country_name__in=country_name_list).\
+                values_list('id', flat=True)
+            device_info_qs = Device_Info.objects.filter(Type__in=device_type_list,
+                                                        userID__region_country__in=country_id_list)
         # 获取时间范围
         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 +55,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 +63,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)