浏览代码

推送消息和存表打印异常

locky 2 年之前
父节点
当前提交
b60219758b
共有 3 个文件被更改,包括 62 次插入82 次删除
  1. 1 1
      Controller/DetectControllerV2.py
  2. 2 20
      Object/RedisObject.py
  3. 59 61
      Service/DevicePushService.py

+ 1 - 1
Controller/DetectControllerV2.py

@@ -44,7 +44,7 @@ class NotificationV2View(View):
         @param request_dict:electricity 电量值
         @param request_dict:electricity 电量值
         """
         """
         logger = logging.getLogger('info')
         logger = logging.getLogger('info')
-        logger.info("移动侦测V2接口参数:{}".format(request_dict))
+        logger.info('移动侦测V2接口参数:{}'.format(request_dict))
         uidToken = request_dict.get('uidToken', None)
         uidToken = request_dict.get('uidToken', None)
         etk = request_dict.get('etk', None)
         etk = request_dict.get('etk', None)
         channel = request_dict.get('channel', '1')
         channel = request_dict.get('channel', '1')

+ 2 - 20
Object/RedisObject.py

@@ -1,25 +1,7 @@
-#!/usr/bin/env python3  
-# -*- coding: utf-8 -*-  
-"""
-@Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
-@AUTHOR: ASJRD018
-@NAME: AnsjerOA
-@software: PyCharm
-@DATE: 2018/8/8 17:00
-@Version: python3.6
-@MODIFY DECORD:ansjer dev
-@file: RedisObject.py
-@Contact: chanjunkai@163.com
-"""
 import redis
 import redis
-
 from AnsjerPush.config import REDIS_ADDRESS
 from AnsjerPush.config import REDIS_ADDRESS
-
-# SERVER_HOST = '192.168.136.45'
-
-'''
-db=3  -> 统计在线人数用
-'''
+# 本地调试把注释打开
+# REDIS_ADDRESS = '127.0.0.1'
 
 
 
 
 class RedisObject:
 class RedisObject:

+ 59 - 61
Service/DevicePushService.py

@@ -18,21 +18,17 @@ import jpush as jpush
 import requests
 import requests
 from pyfcm import FCMNotification
 from pyfcm import FCMNotification
 
 
-from AnsjerPush.config import JPUSH_CONFIG, FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE, APP_BUNDLE_DICT, \
-    XMPUSH_CONFIG, VIVOPUSH_CONFIG, OPPOPUSH_CONFIG, MEIZUPUSH_CONFIG
+from AnsjerPush.config import JPUSH_CONFIG, FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE, XMPUSH_CONFIG, OPPOPUSH_CONFIG
 from AnsjerPush.config import SERVER_TYPE
 from AnsjerPush.config import SERVER_TYPE
 from Model.models import UidPushModel, SysMsgModel, DeviceSharePermission, DeviceChannelUserSet, \
 from Model.models import UidPushModel, SysMsgModel, DeviceSharePermission, DeviceChannelUserSet, \
     DeviceChannelUserPermission
     DeviceChannelUserPermission
 from Object.ETkObject import ETkObject
 from Object.ETkObject import ETkObject
-from Object.RedisObject import RedisObject
 from Object.UidTokenObject import UidTokenObject
 from Object.UidTokenObject import UidTokenObject
 from Object.utils import LocalDateTimeUtil
 from Object.utils import LocalDateTimeUtil
 from Service.CommonService import CommonService
 from Service.CommonService import CommonService
 from Service.EquipmentInfoService import EquipmentInfoService
 from Service.EquipmentInfoService import EquipmentInfoService
 from Service.HuaweiPushService.HuaweiPushService import HuaweiPushObject
 from Service.HuaweiPushService.HuaweiPushService import HuaweiPushObject
 from Service.PushService import PushObject
 from Service.PushService import PushObject
-from Service.VivoPushService.push_admin.APIMessage import PushMessage
-from Service.VivoPushService.push_admin.APISender import APISender
 
 
 LOGGING = logging.getLogger('info')
 LOGGING = logging.getLogger('info')
 
 
@@ -108,56 +104,60 @@ class DevicePushService:
         code_data = {'do_apns_code': '', 'do_fcm_code': '', 'do_jpush_code': ''}
         code_data = {'do_apns_code': '', 'do_fcm_code': '', 'do_jpush_code': ''}
         local_date_time = ''
         local_date_time = ''
         push_permission = True
         push_permission = True
-        for up in uid_set_push_list:
-            appBundleId = up['appBundleId']
-            token_val = up['token_val']
-            lang = up['lang']
-            tz = up['tz']
-            if tz is None or tz == '':
-                tz = 0
-            # 发送标题
-            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'])
-            kwag_args['appBundleId'] = appBundleId
-            kwag_args['token_val'] = token_val
-            kwag_args['msg_title'] = msg_title
-            kwag_args['msg_text'] = msg_text
-            LOGGING.info('推送要的数据: {}'.format(kwag_args))
-            local_date_time = CommonService.get_now_time_str(n_time=params['n_time'], tz=tz, lang='cn')
-            LOGGING.info('<<<<<根据时区计算后日期={},时区={}'.format(local_date_time, tz))
-            local_date_time = local_date_time[0:10]
-            LOGGING.info('<<<<<切片后的日期={}'.format(local_date_time))
-            # 以下是存库
-            userID_id = up["userID_id"]
-            if userID_id not in userID_ids:
-                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,
-                                                    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']))
-                else:
-                    LOGGING.info('分表存数据start------')
-                    params['userID_id'] = userID_id
-                    push_permission = DevicePushService.check_share_permission(userID_id, params['channel'],
-                                                                               params['uid'])
-                    if push_permission:
-                        new_device_info_list.append(cls.created_device_vo(local_date_time, **params))
-                userID_ids.append(userID_id)
-            params['appBundleId'] = appBundleId
-            params['token_val'] = token_val
-            params['lang'] = lang
-            params['tz'] = tz
-            params['kwag_args'] = kwag_args
-            code_data = cls.send_app_msg_push(up['push_type'], **params) if push_permission else code_data
-        return {'code_date': code_data, 'new_device_info_list': new_device_info_list, 'sys_msg_list': sys_msg_list,
-                'local_date_time': local_date_time}
+        try:
+            for up in uid_set_push_list:
+                appBundleId = up['appBundleId']
+                token_val = up['token_val']
+                lang = up['lang']
+                tz = up['tz']
+                if tz is None or tz == '':
+                    tz = 0
+                # 发送标题
+                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'])
+                kwag_args['appBundleId'] = appBundleId
+                kwag_args['token_val'] = token_val
+                kwag_args['msg_title'] = msg_title
+                kwag_args['msg_text'] = msg_text
+                LOGGING.info('推送要的数据: {}'.format(kwag_args))
+                local_date_time = CommonService.get_now_time_str(n_time=params['n_time'], tz=tz, lang='cn')
+                LOGGING.info('<<<<<根据时区计算后日期={},时区={}'.format(local_date_time, tz))
+                local_date_time = local_date_time[0:10]
+                LOGGING.info('<<<<<切片后的日期={}'.format(local_date_time))
+                # 以下是存库
+                userID_id = up["userID_id"]
+                if userID_id not in userID_ids:
+                    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,
+                                                        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']))
+                    else:
+                        LOGGING.info('分表存数据start------')
+                        params['userID_id'] = userID_id
+                        push_permission = DevicePushService.check_share_permission(userID_id, params['channel'],
+                                                                                   params['uid'])
+                        if push_permission:
+                            new_device_info_list.append(cls.created_device_vo(local_date_time, **params))
+                    userID_ids.append(userID_id)
+                params['appBundleId'] = appBundleId
+                params['token_val'] = token_val
+                params['lang'] = lang
+                params['tz'] = tz
+                params['kwag_args'] = kwag_args
+                code_data = cls.send_app_msg_push(up['push_type'], **params) if push_permission else code_data
+            return {'code_date': code_data, 'new_device_info_list': new_device_info_list, 'sys_msg_list': sys_msg_list,
+                    'local_date_time': local_date_time}
+        except Exception as e:
+            LOGGING.info('推送消息或存表异常: errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
 
     @classmethod
     @classmethod
     def send_app_msg_push(cls, push_type, **param):
     def send_app_msg_push(cls, push_type, **param):
@@ -269,9 +269,9 @@ class DevicePushService:
             else:
             else:
                 msg_type = ''
                 msg_type = ''
             if is_sys:
             if is_sys:
-                send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
+                send_text = '{} 通道:{}'.format(msg_type, channel)
             else:
             else:
-                send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
+                send_text = '{} 通道:{} 日期:{}'.format(msg_type, channel, n_date)
         else:
         else:
             if etype == 704:
             if etype == 704:
                 msg_type = 'Battery remaining ' + electricity
                 msg_type = 'Battery remaining ' + electricity
@@ -284,11 +284,9 @@ class DevicePushService:
             else:
             else:
                 msg_type = ''
                 msg_type = ''
             if is_sys:
             if is_sys:
-                send_text = '{msg_type} channel:{channel}'. \
-                    format(msg_type=msg_type, channel=channel)
+                send_text = '{} channel:{}'.format(msg_type, channel)
             else:
             else:
-                send_text = '{msg_type} channel:{channel} date:{date}'. \
-                    format(msg_type=msg_type, channel=channel, date=n_date)
+                send_text = '{} channel:{} date:{}'.format(msg_type, channel, n_date)
         return send_text
         return send_text
 
 
     @staticmethod
     @staticmethod