ソースを参照

推送文案通过config获取

zhangdongming 2 年 前
コミット
2a0a969b72
2 ファイル変更57 行追加51 行削除
  1. 34 0
      AnsjerPush/config.py
  2. 23 51
      Service/DevicePushService.py

+ 34 - 0
AnsjerPush/config.py

@@ -143,4 +143,38 @@ AI_IDENTIFICATION_TAGS_DICT = {
     '2': 'Pet',
     '3': 'Vehicle',
     '4': 'Package'
+}
+
+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 '
+    }
 }

+ 23 - 51
Service/DevicePushService.py

@@ -20,7 +20,8 @@ from pyfcm import FCMNotification
 
 from AnsjerPush.Config.aiConfig import DEVICE_EVENT_TYPE
 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 AnsjerPush.config import JPUSH_CONFIG, FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE, XMPUSH_CONFIG, OPPOPUSH_CONFIG, \
+    EVENT_DICT, EVENT_DICT_CN
 from Model.models import UidPushModel, SysMsgModel, DeviceSharePermission, DeviceChannelUserSet, \
     DeviceChannelUserPermission, UidSetModel, Device_Info
 from Object.ETkObject import ETkObject
@@ -133,7 +134,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
@@ -335,61 +336,27 @@ class DevicePushService:
         事件类型文案键值查找
         """
         if lang == 'cn':
-            event_dict_cn = {
-                1024: {
-                    1: '有人进入',
-                    2: '有人离开'
-                },
-                512: '长时间无人出现',
-                256: '有人徘徊',
-                128: '区域离开',
-                4: '有车出现',
-                3: '检测到画面变化,有人出现',
-                2: '有人出现',
-                1: '检测到画面变化',
-                5: '检测到画面变化,有车出现',
-                9: '检测到画面变化,发现人脸',
-                10: '发现人脸,有人出现'
-            }
-
-            if event_type in event_dict_cn:
-                if isinstance(event_dict_cn[event_type], dict):
-                    msg_type = event_dict_cn[event_type][dealings_type]
+            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]
+                    msg_type = EVENT_DICT_CN[event_type]
             else:
-                msg_type = '未知事件类型'
+                msg_type = '未知事件类型 '
             return msg_type
         else:
-            event_dict = {
-                1024: {
-                    1: 'Someone entered',
-                    2: 'Someone left'
-                },
-                512: 'No one shows up for a long time',
-                256: 'Someone wanders',
-                128: 'Area departure',
-                4: 'A car appeared',
-                3: 'Screen change detected and someone appears',
-                2: 'Someone showed up',
-                1: 'Screen change detected',
-                5: 'Screen change detected,A car appeared',
-                9: 'Screen change detected,Discover faces',
-                10: 'A human face is found, Someone showed up'
-            }
-
-            if event_type in event_dict:
-                if isinstance(event_dict[event_type], dict):
-                    msg_type = event_dict[event_type][dealings_type]
+            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]
+                    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):
+                     device_type=0, event_tag=''):
         """
         获取消息文本
         @param: channel 通道号
@@ -402,11 +369,14 @@ class DevicePushService:
         @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 = '检测到画面变化'
@@ -437,8 +407,9 @@ class DevicePushService:
                 msg_type = '摄像头唤醒'
             elif event_type == 606:
                 msg_type = '有人呼叫,请点击查看'
-            elif ai_type > 0:
-                msg_type = DevicePushService.get_event_type_text(lang, event_type, dealings_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)
@@ -479,8 +450,9 @@ class DevicePushService:
                 msg_type = 'Camera wake'
             elif event_type == 606:
                 msg_type = 'Someone is calling, please click to view'
-            elif ai_type > 0:
-                msg_type = DevicePushService.get_event_type_text(lang, event_type, dealings_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 = '{} channel:{}'.format(msg_type, channel)