|
@@ -20,7 +20,7 @@ import requests
|
|
from obs import ObsClient
|
|
from obs import ObsClient
|
|
|
|
|
|
from AnsjerPush.Config.aiConfig import DEVICE_EVENT_TYPE, ALGORITHM_COMBO_TYPES
|
|
from AnsjerPush.Config.aiConfig import DEVICE_EVENT_TYPE, ALGORITHM_COMBO_TYPES
|
|
-from AnsjerPush.MessageConfig import EVENT_CONFIGS, DEFAULT_TEXTS, CHANNEL_MAP, MSG_CONFIG
|
|
|
|
|
|
+from AnsjerPush.MessageConfig import EVENT_CONFIGS, DEFAULT_TEXTS, MSG_CONFIG
|
|
from AnsjerPush.config import CONFIG_INFO, CONFIG_CN, MULTI_CHANNEL_TYPE_LIST, SYS_EVENT_TYPE_LIST, AWS_ACCESS_KEY_ID, \
|
|
from AnsjerPush.config import CONFIG_INFO, CONFIG_CN, MULTI_CHANNEL_TYPE_LIST, SYS_EVENT_TYPE_LIST, AWS_ACCESS_KEY_ID, \
|
|
AWS_SECRET_ACCESS_KEY, EVENT_DICT, EVENT_DICT_CN, CONFIG_TEST, HUAWEICLOUD_AK, HUAWEICLOUD_SK, \
|
|
AWS_SECRET_ACCESS_KEY, EVENT_DICT, EVENT_DICT_CN, CONFIG_TEST, HUAWEICLOUD_AK, HUAWEICLOUD_SK, \
|
|
HUAWEICLOUD_OBS_SERVER, HUAWEICLOUD_PUSH_BUKET, OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, JPUSH_UID_LIST, \
|
|
HUAWEICLOUD_OBS_SERVER, HUAWEICLOUD_PUSH_BUKET, OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, JPUSH_UID_LIST, \
|
|
@@ -232,8 +232,8 @@ class DevicePushService:
|
|
msg_text = cls.get_msg_text_v2(channel=params['channel'], n_time=params['n_time'], lang=lang, tz=tz,
|
|
msg_text = cls.get_msg_text_v2(channel=params['channel'], n_time=params['n_time'], lang=lang, tz=tz,
|
|
event_type=params['event_type'], ai_type=params['ai_type'],
|
|
event_type=params['event_type'], ai_type=params['ai_type'],
|
|
device_type=params['device_type'], electricity=params['electricity'],
|
|
device_type=params['device_type'], electricity=params['electricity'],
|
|
- dealings_type=params['dealings_type'], event_tag=params['event_tag']
|
|
|
|
- )
|
|
|
|
|
|
+ dealings_type=params['dealings_type'], event_tag=params['event_tag'],
|
|
|
|
+ redis_obj=params['redis_obj'])
|
|
|
|
|
|
# 补齐推送参数
|
|
# 补齐推送参数
|
|
push_kwargs['appBundleId'] = appBundleId
|
|
push_kwargs['appBundleId'] = appBundleId
|
|
@@ -698,7 +698,7 @@ class DevicePushService:
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def get_msg_text_v2(channel, n_time, lang, tz, event_type, electricity='', is_sys=0, dealings_type=0, ai_type=0,
|
|
def get_msg_text_v2(channel, n_time, lang, tz, event_type, electricity='', is_sys=0, dealings_type=0, ai_type=0,
|
|
- device_type=0, event_tag='', is_save_msg=0):
|
|
|
|
|
|
+ device_type=0, event_tag='', is_save_msg=0, redis_obj=None):
|
|
"""
|
|
"""
|
|
获取消息文案V2
|
|
获取消息文案V2
|
|
"""
|
|
"""
|
|
@@ -716,13 +716,6 @@ class DevicePushService:
|
|
if event in event_list:
|
|
if event in event_list:
|
|
event_list.remove(event)
|
|
event_list.remove(event)
|
|
|
|
|
|
- # 简体中文、英文、西班牙语、法语、德语、繁体中文、葡萄牙语、俄语、日语、意大利语、波兰语、韩语、阿拉伯语
|
|
|
|
- SUPPORTED_LANGS = {'cn', 'en', 'es', 'fr', 'de', 'cn_tw', 'pt', 'ru', 'ja', 'it', 'pl', 'nl', 'kr', 'ar'}
|
|
|
|
- MIN_EVENT_TYPE, MAX_EVENT_TYPE = 51, 65
|
|
|
|
- # 根据语言获取对应单个事件文案
|
|
|
|
- if lang in SUPPORTED_LANGS and MIN_EVENT_TYPE <= event_type <= MAX_EVENT_TYPE:
|
|
|
|
- msg_type = MSG_CONFIG[event_type].get(lang, '')
|
|
|
|
-
|
|
|
|
if event_type == 1022:
|
|
if event_type == 1022:
|
|
msg_type = MSG_CONFIG[1022].get(lang, '')
|
|
msg_type = MSG_CONFIG[1022].get(lang, '')
|
|
elif event_type == 1023:
|
|
elif event_type == 1023:
|
|
@@ -746,7 +739,11 @@ class DevicePushService:
|
|
# 组合事件处理文案
|
|
# 组合事件处理文案
|
|
if event_type not in DATA_PUSH_EVENT_TYPE_LIST and ai_type > 0 and event_list:
|
|
if event_type not in DATA_PUSH_EVENT_TYPE_LIST and ai_type > 0 and event_list:
|
|
msg_type = ''.join(
|
|
msg_type = ''.join(
|
|
- [DevicePushService.get_event_type_text_v2(lang, item, dealings_type) for item in event_list])
|
|
|
|
|
|
+ DevicePushService.get_event_type_text_v2(lang, item, dealings_type, redis_obj)
|
|
|
|
+ for item in event_list
|
|
|
|
+ )
|
|
|
|
+ elif not msg_type and event_type not in DATA_PUSH_EVENT_TYPE_LIST:
|
|
|
|
+ msg_type = DevicePushService.get_event_type_text_v2(lang, event_type, None, redis_obj)
|
|
|
|
|
|
if is_sys:
|
|
if is_sys:
|
|
if device_type in MULTI_CHANNEL_TYPE_LIST:
|
|
if device_type in MULTI_CHANNEL_TYPE_LIST:
|
|
@@ -755,32 +752,64 @@ class DevicePushService:
|
|
send_text = msg_type
|
|
send_text = msg_type
|
|
else:
|
|
else:
|
|
if device_type in MULTI_CHANNEL_TYPE_LIST: # NVR多通道文案
|
|
if device_type in MULTI_CHANNEL_TYPE_LIST: # NVR多通道文案
|
|
- prefix = CHANNEL_MAP.get(lang, CHANNEL_MAP['en'])
|
|
|
|
|
|
+ channel_dict = {
|
|
|
|
+ 'cn': '通道', # 简体中文
|
|
|
|
+ 'en': 'Channel', # 英语
|
|
|
|
+ 'es': 'Canal', # 西班牙语
|
|
|
|
+ 'fr': 'Canal', # 法语
|
|
|
|
+ 'de': 'Kanal ', # 德语
|
|
|
|
+ 'cn_tw': '通道', # 繁体中文
|
|
|
|
+ 'pt': 'Canal', # 葡萄牙语
|
|
|
|
+ 'ru': 'Канал', # 俄语
|
|
|
|
+ 'ja': 'チャンネル', # 日语
|
|
|
|
+ 'it': 'Canale', # 意大利语
|
|
|
|
+ 'pl': 'Kanał', # 波兰语
|
|
|
|
+ 'nl': 'Kanaal', # 荷兰语
|
|
|
|
+ 'ko': '채널', # 韩语
|
|
|
|
+ 'ar': 'قناة' # 阿拉伯语
|
|
|
|
+ }
|
|
|
|
+ prefix = channel_dict.get(lang, channel_dict['en'])
|
|
send_text = f'{msg_type} {prefix}:{channel}'
|
|
send_text = f'{msg_type} {prefix}:{channel}'
|
|
else:
|
|
else:
|
|
send_text = f'{msg_type}'
|
|
send_text = f'{msg_type}'
|
|
return send_text
|
|
return send_text
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- ERROR_INFO_LOGGER.info('time:{},event_tag:{},error行数:{},内容:{}'
|
|
|
|
- .format(n_time, event_tag, e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
+ ERROR_INFO_LOGGER.error('文案异常time:{},event_tag:{},error行数:{},内容:{}'
|
|
|
|
+ .format(n_time, event_tag, e.__traceback__.tb_lineno, repr(e)))
|
|
return msg_type
|
|
return msg_type
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
- def get_event_type_text_v2(lang, event_type, dealings_type):
|
|
|
|
- """统一处理多语言事件类型文案"""
|
|
|
|
- # 获取对应语言的配置(默认用英文)
|
|
|
|
- config = EVENT_CONFIGS.get(lang, EVENT_CONFIGS['en'])
|
|
|
|
- default_msg = DEFAULT_TEXTS.get(lang, DEFAULT_TEXTS['en'])
|
|
|
|
-
|
|
|
|
- # 链式查询逻辑
|
|
|
|
- event_data = config.get(event_type)
|
|
|
|
-
|
|
|
|
- if isinstance(event_data, dict):
|
|
|
|
- return event_data.get(dealings_type, default_msg)
|
|
|
|
- elif event_data is not None:
|
|
|
|
- return event_data
|
|
|
|
- else:
|
|
|
|
- return default_msg
|
|
|
|
|
|
+ def get_event_type_text_v2(lang, event_type, dealings_type, redis_obj):
|
|
|
|
+ """ 改造后:优先读缓存,无缓存时读配置并写入 """
|
|
|
|
+ msg = ''
|
|
|
|
+ try:
|
|
|
|
+ # 生成缓存键(示例:event_msg:en:66:1)
|
|
|
|
+ cache_key = f"event_msg:{lang}:{event_type}"
|
|
|
|
+ field = str(dealings_type) if dealings_type else 'default'
|
|
|
|
+
|
|
|
|
+ # 1. 先尝试从 Redis 读取
|
|
|
|
+ cached_msg = redis_obj.hget_data(cache_key, field)
|
|
|
|
+ if cached_msg:
|
|
|
|
+ return cached_msg
|
|
|
|
+
|
|
|
|
+ # 2. 缓存未命中,从原配置读取
|
|
|
|
+ config = EVENT_CONFIGS.get(lang, EVENT_CONFIGS['en'])
|
|
|
|
+ default_msg = DEFAULT_TEXTS.get(lang, DEFAULT_TEXTS['en'])
|
|
|
|
+ event_data = config.get(event_type)
|
|
|
|
+
|
|
|
|
+ # 处理子类型
|
|
|
|
+ if isinstance(event_data, dict):
|
|
|
|
+ msg = event_data.get(dealings_type, default_msg)
|
|
|
|
+ else:
|
|
|
|
+ msg = event_data if event_data is not None else default_msg
|
|
|
|
+
|
|
|
|
+ redis_obj.hset_data(cache_key, field, msg, 3600 * 24 * 7)
|
|
|
|
+ return msg
|
|
|
|
+ except Exception as e:
|
|
|
|
+ ERROR_INFO_LOGGER.error('redis写入文案异常lang:{},event_type:{},error行数:{},内容:{}'
|
|
|
|
+ .format(lang, event_type, e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
+ return msg
|
|
|
|
+
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def do_xmpush(channel_id, uid, channel, appBundleId, token_val, event_type, n_time,
|
|
def do_xmpush(channel_id, uid, channel, appBundleId, token_val, event_type, n_time,
|