|
@@ -87,6 +87,9 @@ class DetectControllerViewV2(View):
|
|
|
try:
|
|
|
msg_data = request_dict.get('msgData', None)
|
|
|
uid = request_dict.get('uid', None)
|
|
|
+ channel = int(request_dict.get('channel', 0))
|
|
|
+ is_nvr = int(request_dict.get('isNVR', 0))
|
|
|
+ event_types = request_dict.get('eventTypes', None)
|
|
|
LOGGER.info('*****DetectControllerViewV2.message_notification_set*****api_version:{},uid:{}'
|
|
|
.format(api_version, uid))
|
|
|
if not all([msg_data, uid]):
|
|
@@ -95,13 +98,42 @@ class DetectControllerViewV2(View):
|
|
|
uid_set_qs = UidSetModel.objects.filter(uid=uid)
|
|
|
if not uid_set_qs.exists():
|
|
|
return response.json(173)
|
|
|
+ data = cls.update_nvr_app_msg(channel, is_nvr, uid_set_qs[0].msg_notify, data, event_types)
|
|
|
+
|
|
|
uid_set_qs.update(msg_notify=data, updTime=int(time.time()))
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
- LOGGER.info('*****DetectControllerViewV2.message_notification_set:errLine:{}, errMsg:{}'
|
|
|
- .format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ LOGGER.error('*****DetectControllerViewV2.message_notification_set:errLine:{}, errMsg:{}'
|
|
|
+ .format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def update_nvr_app_msg(cls, channel, is_nvr, msg_notify, data, event_types):
|
|
|
+ # 检查是否是 NVR 且通道大于 0
|
|
|
+ if is_nvr == 1 and channel > 0:
|
|
|
+ # 构建目标键,例如 'channel1' 或 'channel2'
|
|
|
+ target_key = f'channel{channel}'
|
|
|
+
|
|
|
+ # 使用条件表达式构建 new_data
|
|
|
+ new_data = {target_key: list(map(int, event_types.split(','))) if event_types else []}
|
|
|
+
|
|
|
+ # 获取 nvr 列表并准备标志
|
|
|
+ nvr_list = msg_notify.get('nvr', [])
|
|
|
+
|
|
|
+ # 尝试在 nvr 列表中找到匹配的通道
|
|
|
+ for item in nvr_list:
|
|
|
+ if target_key in item:
|
|
|
+ item[target_key] = new_data[target_key]
|
|
|
+ return msg_notify # 找到匹配后直接返回
|
|
|
+
|
|
|
+ # 如果没有找到匹配,添加 new_data
|
|
|
+ nvr_list.append(new_data)
|
|
|
+ msg_notify['nvr'] = nvr_list
|
|
|
+
|
|
|
+ return msg_notify
|
|
|
+
|
|
|
+ return data
|
|
|
+
|
|
|
def do_change_status(self, userID, request_dict, response):
|
|
|
token_val = request_dict.get('token_val', None)
|
|
|
jg_token_val = request_dict.get('jg_token_val', '')
|
|
@@ -117,6 +149,7 @@ class DetectControllerViewV2(View):
|
|
|
region = request_dict.get('region', None) # app必须传:1:国外,2:国内
|
|
|
electricity_status = request_dict.get('electricity_status', None)
|
|
|
domain_name = request_dict.get('domain_name', None)
|
|
|
+ is_nvr = int(request_dict.get('isNVR', 0))
|
|
|
if not region:
|
|
|
return response.json(444, 'region')
|
|
|
region = int(region)
|
|
@@ -188,12 +221,26 @@ class DetectControllerViewV2(View):
|
|
|
uid_set_data['msg_notify'] = msg_data
|
|
|
elif status == 1 and uid_set_qs.first().detect_status == 0:
|
|
|
uid_set_data['detect_interval'] = 60
|
|
|
+ types = ALGORITHM_COMBO_TYPES
|
|
|
+ types = [x for x in types if x != 51]
|
|
|
msg_data = {'appPush': 1,
|
|
|
'pushTime': {'allDay': 1, 'repeat': 127, 'endTime': 0, 'timeZone': '+08.00',
|
|
|
'startTime': 0},
|
|
|
- 'eventTypes': {'device': ALGORITHM_COMBO_TYPES, 'aiCloud': 1}
|
|
|
+ 'eventTypes': {'device': types, 'aiCloud': 1}
|
|
|
}
|
|
|
+
|
|
|
+ if is_nvr == 1: # 检查NVR版本是否存在
|
|
|
+
|
|
|
+ # 确定通道数量,如果channel大于0则使用其值,否则默认使用4
|
|
|
+ channel_count = uid_set_qs[0].channel if uid_set_qs[0].channel > 0 else 4
|
|
|
+ # 生成通道的列表,每个频道对应一个字典,格式为 "channelX": [types]
|
|
|
+ channel_list = [{f'channel{index + 1}': ALGORITHM_COMBO_TYPES} for index in range(channel_count)]
|
|
|
+ # 将NVR字典赋值给msg_data中的'nvr'键
|
|
|
+ msg_data['nvr'] = channel_list
|
|
|
+ msg_data['eventTypes']['device'] = [] # 将IPC允许推送类型设为空
|
|
|
+
|
|
|
uid_set_data['msg_notify'] = msg_data
|
|
|
+
|
|
|
uid_set_id = uid_set_qs[0].id
|
|
|
uid_set_data['updTime'] = nowTime
|
|
|
uid_set_qs.update(**uid_set_data)
|
|
@@ -302,6 +349,7 @@ class DetectControllerViewV2(View):
|
|
|
else:
|
|
|
return response.json(173)
|
|
|
except Exception as e:
|
|
|
+ LOGGER.info('消息推送设置error,uid:{},line:{},msg:{}'.format(uid, e.__traceback__.tb_lineno, repr(e)))
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
def do_delete_redis(self, uid, detect_interval=0):
|