Browse Source

移动侦测推送单机设备类型消息内容不返回通道数

locky 2 năm trước cách đây
mục cha
commit
90d496d2c4
3 tập tin đã thay đổi với 62 bổ sung55 xóa
  1. 2 0
      AnsjerPush/config.py
  2. 6 6
      Controller/DetectControllerV2.py
  3. 54 49
      Service/DevicePushService.py

+ 2 - 0
AnsjerPush/config.py

@@ -130,3 +130,5 @@ APP_BUNDLE_DICT = {
     'com.ansjer.customizeda_a': 'Guardian365',
     'com.ansjer.customizedc_a': 'PatrolSecure',
 }
+
+MULTI_CHANNEL_TYPE_LIST = [1, 2, 3, 4, 10001]

+ 6 - 6
Controller/DetectControllerV2.py

@@ -94,9 +94,9 @@ class NotificationV2View(View):
             redisObj.set_data(key=req_limiting, val=1, expire=60)  # 当缓存不存在限流数据 重新设置一分钟请求一次
             uid_push_qs = DevicePushService.query_uid_push(uid, event_type)  # 查询uid_set与push数据列表
             if not uid_push_qs.exists():
-                logger.info('消息推送-uid_push 数据不存在')
+                logger.info('消息推送-{}uid_push数据不存在'.format(uid))
                 return JsonResponse(status=200, data={'code': 176, 'msg': 'no uid_push data'})
-            ai_type = uid_push_qs.first()['uid_set__ai_type']
+            ai_type, device_type = uid_push_qs.first()['uid_set__ai_type'], uid_push_qs.first()['uid_set__device_type']
             # 将uid_set以及uid_push 转数组列表
             uid_set_push_list = DevicePushService.cache_uid_push(uid_push_qs)
             nickname = uid_set_push_list[0]['uid_set__nickname']
@@ -124,12 +124,12 @@ class NotificationV2View(View):
             params = {'nickname': nickname, 'uid': uid, 'kwag_args': kwag_args, 'is_st': is_st, 'region': region,
                       'is_sys_msg': is_sys_msg, 'channel': channel, 'event_type': event_type, 'n_time': n_time,
                       'electricity': electricity, 'bucket': bucket, 'aws_s3_client': aws_s3_client,
-                      'app_push': cache_app_push, 'storage_location': 2, 'ai_type': ai_type,
+                      'app_push': cache_app_push, 'storage_location': 2, 'ai_type': ai_type, 'device_type': device_type,
                       'dealings_type': int(dealings_type)}
-            logger.info('已创建s3对象,推送数据为:{}'.format(params))
-            # APP消息推送与获取报警消息数据列表
+            logger.info('推送数据参数:{}'.format(params))
+            # 推送消息,生成推送数据列表
             result = DevicePushService.save_msg_push(uid_set_push_list, **params)
-            # 批量系统消息&报警消息数据存库
+            # 保存推送数据
             DevicePushService.save_sys_msg(is_sys_msg, result['local_date_time'],
                                            result['sys_msg_list'], result['new_device_info_list'])
             params['aws_s3_client'] = aws_s3_client

+ 54 - 49
Service/DevicePushService.py

@@ -19,12 +19,11 @@ import requests
 from pyfcm import FCMNotification
 
 from AnsjerPush.Config.aiConfig import DEVICE_EVENT_TYPE
-from AnsjerPush.config import CONFIG_INFO, CONFIG_CN
+from AnsjerPush.config import CONFIG_INFO, CONFIG_CN, MULTI_CHANNEL_TYPE_LIST
 from AnsjerPush.config import JPUSH_CONFIG, FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE, XMPUSH_CONFIG, OPPOPUSH_CONFIG
 from Model.models import UidPushModel, SysMsgModel, DeviceSharePermission, DeviceChannelUserSet, \
     DeviceChannelUserPermission, UidSetModel
 from Object.ETkObject import ETkObject
-from Object.RedisObject import RedisObject
 from Object.UidTokenObject import UidTokenObject
 from Object.utils import LocalDateTimeUtil
 from Service.CommonService import CommonService
@@ -61,12 +60,12 @@ 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__new_detect_interval')
+                       'uid_set__channel', 'uid_set__ai_type', 'uid_set__device_type', 'uid_set__new_detect_interval')
         else:
             uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid). \
                 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__new_detect_interval')
+                       'uid_set__channel', 'uid_set__ai_type', 'uid_set__device_type', 'uid_set__new_detect_interval')
         return uid_push_qs
 
     @staticmethod
@@ -100,10 +99,10 @@ class DevicePushService:
     @classmethod
     def save_msg_push(cls, uid_set_push_list, **params):
         """
-        APP消息推送以及报警消息存库
-        @nickname 设备名称
-        @channel 通道
-        @event_type 事件类型
+        推送消息,返回推送数据列表
+        @param uid_set_push_list: redis对象
+        @param params: 推送参数
+        @return: dict
         """
         new_device_info_list = []
         sys_msg_list = []
@@ -124,10 +123,11 @@ class DevicePushService:
                 # 发送标题
                 msg_title = cls.get_msg_title(nickname=params['nickname'])
                 # 发送内容
-                msg_text = cls.get_msg_text(channel=params['channel'], n_time=params['n_time'], lang=lang,
-                                            tz=tz, event_type=params['event_type'],
-                                            electricity=params['electricity'], dealings_type=params['dealings_type'],
-                                            ai_type=params['ai_type'])
+                msg_text = cls.get_msg_text(channel=params['channel'], n_time=params['n_time'], lang=lang, tz=tz,
+                                            event_type=params['event_type'], ai_type=params['ai_type'],
+                                            device_type=params['device_type'], electricity=params['electricity'],
+                                            dealings_type=params['dealings_type']
+                                            )
                 kwag_args['appBundleId'] = appBundleId
                 kwag_args['token_val'] = token_val
                 kwag_args['msg_title'] = msg_title
@@ -143,10 +143,10 @@ class DevicePushService:
                     now_time = int(time.time())
                     if params['is_sys_msg']:
                         sys_msg_text = cls.get_msg_text(channel=params['channel'], n_time=params['n_time'], lang=lang,
-                                                        tz=tz,
+                                                        tz=tz, is_sys=1, device_type=params['device_type'],
                                                         event_type=params['event_type'],
                                                         electricity=params['electricity'],
-                                                        is_sys=1)
+                                                        )
                         sys_msg_list.append(SysMsgModel(userID_id=userID_id, msg=sys_msg_text, addTime=now_time,
                                                         updTime=now_time, uid=params['uid'],
                                                         eventType=params['event_type']))
@@ -316,73 +316,78 @@ class DevicePushService:
         return nickname
 
     @staticmethod
-    def get_msg_text(channel, n_time, lang, tz, event_type, electricity='', is_sys=0, dealings_type=0,
-                     ai_type=0):
+    def get_msg_text(channel, n_time, lang, tz, event_type, electricity='', is_sys=0, dealings_type=0, ai_type=0,
+                     device_type=0):
         """
         获取消息文本
         """
         n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
-        etype = int(event_type)
+        msg_type = ''
+        event_type, device_type = int(event_type), int(device_type)
         if lang == 'cn':
-            if etype == 704:
+            if event_type == 704:
                 msg_type = '剩余电量 ' + electricity
-            elif etype == 702:
+            elif event_type == 702:
                 msg_type = '摄像头休眠'
-            elif etype == 703:
+            elif event_type == 703:
                 msg_type = '摄像头唤醒'
-            elif etype == 606:
+            elif event_type == 606:
                 msg_type = '有人呼叫,请点击查看'
             elif ai_type > 0:
-                if etype == 1024 and dealings_type == 1:
+                if event_type == 1024 and dealings_type == 1:
                     msg_type = '有人进入'
-                elif etype == 1024 and dealings_type == 2:
+                elif event_type == 1024 and dealings_type == 2:
                     msg_type = '有人离开'
-                elif etype == 512:
+                elif event_type == 512:
                     msg_type = '长时间无人出现'
-                elif etype == 256:
+                elif event_type == 256:
                     msg_type = '有人徘徊'
-                elif etype == 128:
+                elif event_type == 128:
                     msg_type = '区域离开'
-                elif etype == 64:
+                elif event_type == 64:
                     msg_type = '区域闯入'
-                else:
-                    msg_type = ''
-            else:
-                msg_type = ''
             if is_sys:
-                send_text = '{} 通道:{}'.format(msg_type, channel)
+                if device_type in MULTI_CHANNEL_TYPE_LIST:
+                    send_text = '{} 通道:{}'.format(msg_type, channel)
+                else:
+                    send_text = msg_type
             else:
-                send_text = '{} 通道:{} 日期:{}'.format(msg_type, channel, n_date)
+                if device_type in MULTI_CHANNEL_TYPE_LIST:
+                    send_text = '{} 通道:{} 日期:{}'.format(msg_type, channel, n_date)
+                else:
+                    send_text = '{} 日期:{}'.format(msg_type, channel, n_date)
         else:
-            if etype == 704:
+            if event_type == 704:
                 msg_type = 'Battery remaining ' + electricity
-            elif etype == 702:
+            elif event_type == 702:
                 msg_type = 'Camera sleep'
-            elif etype == 703:
+            elif event_type == 703:
                 msg_type = 'Camera wake'
-            elif etype == 606:
+            elif event_type == 606:
                 msg_type = 'Someone is calling, please click to view'
             elif ai_type > 0:
-                if etype == 1024 and int(dealings_type) == 1:
+                if event_type == 1024 and int(dealings_type) == 1:
                     msg_type = 'Someone entered'
-                elif etype == 1024 and int(dealings_type) == 2:
+                elif event_type == 1024 and int(dealings_type) == 2:
                     msg_type = 'Someone left'
-                elif etype == 512:
+                elif event_type == 512:
                     msg_type = 'No one shows up for a long time'
-                elif etype == 256:
+                elif event_type == 256:
                     msg_type = 'Someone wanders'
-                elif etype == 128:
+                elif event_type == 128:
                     msg_type = 'Area departure'
-                elif etype == 64:
+                elif event_type == 64:
                     msg_type = 'Area break-in'
-                else:
-                    msg_type = ''
-            else:
-                msg_type = ''
             if is_sys:
-                send_text = '{} channel:{}'.format(msg_type, channel)
+                if device_type in MULTI_CHANNEL_TYPE_LIST:
+                    send_text = '{} channel:{}'.format(msg_type, channel)
+                else:
+                    send_text = msg_type
             else:
-                send_text = '{} channel:{} date:{}'.format(msg_type, channel, n_date)
+                if device_type in MULTI_CHANNEL_TYPE_LIST:
+                    send_text = '{} channel:{} date:{}'.format(msg_type, channel, n_date)
+                else:
+                    send_text = '{} date:{}'.format(msg_type, channel, n_date)
         return send_text
 
     @staticmethod