Bladeren bron

定制化推送多个国家

locky 1 jaar geleden
bovenliggende
commit
dedfa8b45d
2 gewijzigde bestanden met toevoegingen van 9 en 7 verwijderingen
  1. 0 2
      Controller/CustomizedPushController.py
  2. 9 5
      Service/CustomizedPushService.py

+ 0 - 2
Controller/CustomizedPushController.py

@@ -59,8 +59,6 @@ class CustomizedPushView(View):
                 kwargs=kwargs)
             push_thread.start()
 
-            # 更新推送状态
-            customized_push_qs.update(push_satus=True)
             return response.json(0)
         except Exception as e:
             return HttpResponse(repr(e), status=500)

+ 9 - 5
Service/CustomizedPushService.py

@@ -6,7 +6,7 @@ import threading
 import time
 from concurrent.futures import ThreadPoolExecutor
 
-from Model.models import DeviceTypeModel, Device_Info, GatewayPush, CountryModel, SysMsgModel
+from Model.models import DeviceTypeModel, Device_Info, GatewayPush, CountryModel, SysMsgModel, CustomizedPush
 from Service.CommonService import CommonService
 from Service.HuaweiPushService.HuaweiPushService import HuaweiPushObject
 from Service.PushService import PushObject
@@ -28,9 +28,10 @@ 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_qs = CountryModel.objects.filter(country_name=country).values('id')
-        country_id = country_qs[0]['id']
-        device_info_qs = Device_Info.objects.filter(Type__in=device_type_list, userID__region_country=country_id)
+        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())
 
@@ -73,6 +74,7 @@ class CustomizedPushObject:
         @param kwargs: 参数
         @return:
         """
+        customized_push_id = kwargs['id']
         user_id_list = kwargs['user_id_list']
         title = kwargs['title']
         msg = kwargs['msg']
@@ -119,7 +121,9 @@ class CustomizedPushObject:
                     target=cls.thr_pool_push,
                     kwargs=pre_push_kwargs)
                 pre_push_thread.start()
-                CUSTOMIZED_PUSH_LOGGER.info('customized_push_id:{}推送完成'.format(kwargs['id']))
+                CUSTOMIZED_PUSH_LOGGER.info('customized_push_id:{}推送完成'.format(customized_push_id))
+            # 更新推送状态
+            CustomizedPush.objects.filter(id=customized_push_id).update(push_satus=True)
         except Exception as e:
             CUSTOMIZED_PUSH_LOGGER.info('定制化推送或保存数据异常,'
                                         'error_line:{},error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))