Przeglądaj źródła

设备智能算法APP推送文案改为通过配置文件获取

zhangdongming 2 lat temu
rodzic
commit
243489eda8
2 zmienionych plików z 87 dodań i 36 usunięć
  1. 34 0
      AnsjerPush/config.py
  2. 53 36
      Service/DevicePushService.py

+ 34 - 0
AnsjerPush/config.py

@@ -137,3 +137,37 @@ APP_BUNDLE_DICT = {
 
 SYS_EVENT_TYPE_LIST = [702, 703, 704]
 MULTI_CHANNEL_TYPE_LIST = [1, 2, 3, 4, 10001]
+
+EVENT_DICT_CN = {
+    51: '检测到画面变化 ',
+    57: '有人出现 ',
+    58: '有车出现 ',
+    59: '有宠物出现 ',
+    60: '发现人脸 ',
+    61: '有异响 ',
+    62: '区域闯入 ',
+    63: '区域离开 ',
+    64: '有人徘徊 ',
+    65: '长时间无人出现 ',
+    66: {
+        1: '有人进入 ',
+        2: '有人离开 '
+    }
+}
+
+EVENT_DICT = {
+    51: 'Screen change detected ',
+    57: 'Someone showed up ',
+    58: 'A car appeared ',
+    59: 'There are pets present ',
+    60: 'Discover faces ',
+    61: 'There is a strange noise ',
+    62: 'Area break-in ',
+    63: 'Area departure ',
+    64: 'Someone wanders ',
+    65: 'No one shows up for a long time ',
+    66: {
+        1: 'Someone entered ',
+        2: 'Someone left '
+    }
+}

+ 53 - 36
Service/DevicePushService.py

@@ -22,7 +22,7 @@ from pyfcm import FCMNotification
 
 from AnsjerPush.Config.aiConfig import DEVICE_EVENT_TYPE
 from AnsjerPush.config import CONFIG_INFO, CONFIG_CN, MULTI_CHANNEL_TYPE_LIST, SYS_EVENT_TYPE_LIST, AWS_ACCESS_KEY_ID, \
-    AWS_SECRET_ACCESS_KEY
+    AWS_SECRET_ACCESS_KEY, EVENT_DICT, EVENT_DICT_CN
 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, Device_Info
@@ -171,7 +171,7 @@ class DevicePushService:
                 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']
+                                            dealings_type=params['dealings_type'], event_tag=params['event_tag']
                                             )
                 kwag_args['appBundleId'] = appBundleId
                 kwag_args['token_val'] = token_val
@@ -368,15 +368,52 @@ 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,
-                     device_type=0):
+    def get_event_type_text(lang, event_type, dealings_type):
         """
-        获取推送消息内容
+        事件类型文案键值查找
+        """
+        if lang == 'cn':
+            if event_type in EVENT_DICT_CN:
+                if isinstance(EVENT_DICT_CN[event_type], dict):
+                    msg_type = EVENT_DICT_CN[event_type][dealings_type]
+                else:
+                    msg_type = EVENT_DICT_CN[event_type]
+            else:
+                msg_type = '未知事件类型 '
+            return msg_type
+        else:
+            if event_type in EVENT_DICT:
+                if isinstance(EVENT_DICT[event_type], dict):
+                    msg_type = EVENT_DICT[event_type][dealings_type]
+                else:
+                    msg_type = EVENT_DICT[event_type]
+            else:
+                msg_type = 'Unknown event type'
+            return msg_type
+
+    @staticmethod
+    def get_msg_text(channel, n_time, lang, tz, event_type, electricity='', is_sys=0, dealings_type=0, ai_type=0,
+                     device_type=0, event_tag=''):
+        """
+        获取消息文本
+        @param: channel 通道号
+        @param: n_time 触发事件
+        @param: lang 语言
+        @param: tz 时区
+        @param: event_type 事件类型
+        @param: electricity 电量
+        @param: is_sys 是否系统消息
+        @param: dealings_type 往来类型 1 进 1 离开
+        @param: ai_type 设备本地AI只能算法 事件类型
+        @param: device_type 设备类型
+        @param: event_tag 设备算法事件标签
         """
-        n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
         msg_type = ''
         event_type = int(event_type)
         device_type = int(device_type)
+        event_list = []
+        if event_tag:
+            event_list = [int(event) for event in event_tag.split(',') if event]
         if lang == 'cn':
             if event_type == 51:
                 msg_type = '检测到画面变化'
@@ -407,19 +444,9 @@ class DevicePushService:
                 msg_type = '摄像头唤醒'
             elif event_type == 606:
                 msg_type = '有人呼叫,请点击查看'
-            elif ai_type > 0:
-                if event_type == 1024 and dealings_type == 1:
-                    msg_type = '有人进入'
-                elif event_type == 1024 and dealings_type == 2:
-                    msg_type = '有人离开'
-                elif event_type == 512:
-                    msg_type = '长时间无人出现'
-                elif event_type == 256:
-                    msg_type = '有人徘徊'
-                elif event_type == 128:
-                    msg_type = '区域离开'
-                elif event_type == 64:
-                    msg_type = '区域闯入'
+            elif ai_type > 0 and event_list:
+                msg_type = ''.join([DevicePushService.get_event_type_text(lang, item, dealings_type)
+                                    for item in event_list])
             if is_sys:
                 if device_type in MULTI_CHANNEL_TYPE_LIST:
                     send_text = '{} 通道:{}'.format(msg_type, channel)
@@ -427,9 +454,9 @@ class DevicePushService:
                     send_text = msg_type
             else:
                 if device_type in MULTI_CHANNEL_TYPE_LIST:
-                    send_text = '{} 通道:{} 日期:{}'.format(msg_type, channel, n_date)
+                    send_text = '{} 通道:{}'.format(msg_type, channel)
                 else:
-                    send_text = '{} 日期:{}'.format(msg_type, n_date)
+                    send_text = '{}'.format(msg_type)
         else:
             if event_type == 51:
                 msg_type = 'Screen change detected'
@@ -460,19 +487,9 @@ class DevicePushService:
                 msg_type = 'Camera wake'
             elif event_type == 606:
                 msg_type = 'Someone is calling, please click to view'
-            elif ai_type > 0:
-                if event_type == 1024 and int(dealings_type) == 1:
-                    msg_type = 'Someone entered'
-                elif event_type == 1024 and int(dealings_type) == 2:
-                    msg_type = 'Someone left'
-                elif event_type == 512:
-                    msg_type = 'No one shows up for a long time'
-                elif event_type == 256:
-                    msg_type = 'Someone wanders'
-                elif event_type == 128:
-                    msg_type = 'Area departure'
-                elif event_type == 64:
-                    msg_type = 'Area break-in'
+            elif ai_type > 0 and event_list:
+                msg_type = ''.join([DevicePushService.get_event_type_text(lang, item, dealings_type)
+                                    for item in event_list])
             if is_sys:
                 if device_type in MULTI_CHANNEL_TYPE_LIST:
                     send_text = '{} channel:{}'.format(msg_type, channel)
@@ -480,9 +497,9 @@ class DevicePushService:
                     send_text = msg_type
             else:
                 if device_type in MULTI_CHANNEL_TYPE_LIST:
-                    send_text = '{} channel:{} date:{}'.format(msg_type, channel, n_date)
+                    send_text = '{} channel:{}'.format(msg_type, channel)
                 else:
-                    send_text = '{} date:{}'.format(msg_type, n_date)
+                    send_text = '{}'.format(msg_type)
         return send_text
 
     @staticmethod