فهرست منبع

定制化推送云存设备用户

locky 18 ساعت پیش
والد
کامیت
252e86a0e8
3فایلهای تغییر یافته به همراه64 افزوده شده و 13 حذف شده
  1. 16 0
      Model/models.py
  2. 19 1
      Service/CommonService.py
  3. 29 12
      Service/CustomizedPushService.py

+ 16 - 0
Model/models.py

@@ -310,6 +310,22 @@ class Access_Log(models.Model):
         verbose_name_plural = verbose_name
 
 
+class AppDeviceType(models.Model):
+    id = models.AutoField(primary_key=True)
+    # 1:DVR, 2:IPC
+    model = models.SmallIntegerField(default=0, verbose_name='设备类型')
+    type = models.IntegerField(default=0, verbose_name='设备型号')
+    icon = models.CharField(default='', max_length=200, verbose_name='图标文件路径')
+    iconV2 = models.CharField(default='', max_length=200, verbose_name='新版APP图标文件路径')
+    config = models.JSONField(null=True, verbose_name='关联配网方式、网络频段配置json')
+    app_version_number_id = models.CharField(default='', max_length=32, verbose_name='关联APP版本号表id')
+
+    class Meta:
+        db_table = 'app_device_type'
+        verbose_name = 'APP设备类型表'
+        verbose_name_plural = verbose_name
+
+
 class EquipmentInfo1(models.Model):
     id = models.BigAutoField(primary_key=True, verbose_name='主键')
     device_user_id = models.CharField(default='', max_length=32, db_index=True, verbose_name='用户id')

+ 19 - 1
Service/CommonService.py

@@ -17,7 +17,7 @@ import OpenSSL.crypto as ct
 from base64 import encodebytes
 
 from AnsjerPush.config import BASE_DIR, REGION_NAME, PUSH_BUCKET, SYS_EVENT_TYPE_LIST, DATA_PUSH_EVENT_TYPE_LIST
-from Model.models import iotdeviceInfoModel, Device_User
+from Model.models import iotdeviceInfoModel, Device_User, AppDeviceType
 from django.conf import settings
 ACCESS_KEY_ID = settings.ACCESS_KEY_ID
 SECRET_ACCESS_KEY = settings.SECRET_ACCESS_KEY
@@ -456,3 +456,21 @@ GCqvlyw5dfxNA+EtxNE2wCW/LW7ENJlACgcfgPlBZtpLheWoZB/maw4=
                 elif device_user_qs[0]['phone']:
                     return device_user_qs[0]['phone']
         return ''
+
+    @staticmethod
+    def is_cloud_device(ucode, device_type):
+        """
+        设备是否支持云存
+        @param ucode: 设备版本
+        @param device_type: 设备类型
+        """
+        if len(ucode) > 4:
+            number = ucode[-4]
+        else:
+            return False
+        device_type_qs = AppDeviceType.objects.filter(type=device_type).values('model')
+        model = device_type_qs[0]['model'] if device_type_qs.exists() else ''
+        #  判断设备是否为ipc设备和是否支持云存
+        if model == 2 and number in ['4', '5']:
+            return True
+        return False

+ 29 - 12
Service/CustomizedPushService.py

@@ -6,8 +6,11 @@ import threading
 import time
 from concurrent.futures import ThreadPoolExecutor
 
+from django.db.models.functions import Substr, Length
+
 from AnsjerPush.config import CONFIG_INFO, CONFIG_TEST, CONFIG_CN, XM_PUSH_CHANNEL_ID
-from Model.models import DeviceTypeModel, Device_Info, GatewayPush, CountryModel, SysMsgModel, UserEmailSubscriptions
+from Model.models import DeviceTypeModel, Device_Info, GatewayPush, CountryModel, SysMsgModel, UserEmailSubscriptions, \
+    AppDeviceType, UidSetModel
 from Service.CommonService import CommonService
 from Service.HuaweiPushService.HuaweiPushService import HuaweiPushObject
 from Service.PushService import PushObject
@@ -26,18 +29,32 @@ class CustomizedPushObject:
         @param register_period: 用户注册年限
         @return: uid_id_list
         """
-        # 设备型号和国家
-        device_name_list = device_name.split(',')
-        device_type_list = DeviceTypeModel.objects.filter(name__in=device_name_list).values_list('type', flat=True)
-        # 测试和国内服推给所有用户
-        if CONFIG_INFO in [CONFIG_TEST, CONFIG_CN]:
-            device_info_qs = Device_Info.objects.filter(Type__in=device_type_list)
+        # 查询云存设备
+        if device_name == 'cloud_storage':
+            ipc_types = list(AppDeviceType.objects.filter(model=2).values_list('type', flat=True).distinct())
+            uid_list = (UidSetModel.objects.annotate(ucode_char=Substr('ucode', Length('ucode') - 3, 1)).
+                        filter(device_type__in=ipc_types, ucode_char__in=['4', '5']).values_list('uid', flat=True))
+            device_info_qs = Device_Info.objects.filter(UID__in=list(uid_list))
+            # 国外服推给指定国家用户
+            if CONFIG_INFO not in [CONFIG_TEST, CONFIG_CN]:
+                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_qs.filter(userID__region_country__in=country_id_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)
+            # 设备型号和国家
+            device_name_list = device_name.split(',')
+            device_type_list = DeviceTypeModel.objects.filter(name__in=device_name_list).values_list('type', flat=True)
+            # 测试和国内服推给所有用户
+            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())