|
@@ -87,6 +87,9 @@ class DetectControllerViewV2(View):
|
|
try:
|
|
try:
|
|
msg_data = request_dict.get('msgData', None)
|
|
msg_data = request_dict.get('msgData', None)
|
|
uid = request_dict.get('uid', 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:{}'
|
|
LOGGER.info('*****DetectControllerViewV2.message_notification_set*****api_version:{},uid:{}'
|
|
.format(api_version, uid))
|
|
.format(api_version, uid))
|
|
if not all([msg_data, uid]):
|
|
if not all([msg_data, uid]):
|
|
@@ -95,13 +98,42 @@ class DetectControllerViewV2(View):
|
|
uid_set_qs = UidSetModel.objects.filter(uid=uid)
|
|
uid_set_qs = UidSetModel.objects.filter(uid=uid)
|
|
if not uid_set_qs.exists():
|
|
if not uid_set_qs.exists():
|
|
return response.json(173)
|
|
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()))
|
|
uid_set_qs.update(msg_notify=data, updTime=int(time.time()))
|
|
return response.json(0)
|
|
return response.json(0)
|
|
except Exception as e:
|
|
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)))
|
|
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}'
|
|
|
|
+ # 初始化存在标志
|
|
|
|
+ channel_found = False
|
|
|
|
+ new_data = {target_key: list(map(int, event_types.split(',')))}
|
|
|
|
+ # 检查 msg_notify 是否存在且包含 'nvr'
|
|
|
|
+ if msg_notify and 'nvr' in msg_notify:
|
|
|
|
+
|
|
|
|
+ # 遍历 nvr 列表中的每个字典
|
|
|
|
+ for item in msg_notify['nvr']:
|
|
|
|
+ # 检查当前通道的键是否在 item 中
|
|
|
|
+ if target_key in item:
|
|
|
|
+ # 替换对应通道的值为 data 中的值
|
|
|
|
+ item[target_key] = new_data[target_key]
|
|
|
|
+ # 由于目标键是唯一的,可以找到后退出循环
|
|
|
|
+ channel_found = True
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+ if not channel_found:
|
|
|
|
+ msg_notify['nvr'].append(new_data)
|
|
|
|
+ return msg_notify
|
|
|
|
+ return data
|
|
|
|
+
|
|
def do_change_status(self, userID, request_dict, response):
|
|
def do_change_status(self, userID, request_dict, response):
|
|
token_val = request_dict.get('token_val', None)
|
|
token_val = request_dict.get('token_val', None)
|
|
jg_token_val = request_dict.get('jg_token_val', '')
|
|
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:国内
|
|
region = request_dict.get('region', None) # app必须传:1:国外,2:国内
|
|
electricity_status = request_dict.get('electricity_status', None)
|
|
electricity_status = request_dict.get('electricity_status', None)
|
|
domain_name = request_dict.get('domain_name', None)
|
|
domain_name = request_dict.get('domain_name', None)
|
|
|
|
+ is_nvr = int(request_dict.get('isNVR', 0))
|
|
if not region:
|
|
if not region:
|
|
return response.json(444, 'region')
|
|
return response.json(444, 'region')
|
|
region = int(region)
|
|
region = int(region)
|
|
@@ -195,7 +228,19 @@ class DetectControllerViewV2(View):
|
|
'startTime': 0},
|
|
'startTime': 0},
|
|
'eventTypes': {'device': 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}': 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_data['msg_notify'] = msg_data
|
|
|
|
+
|
|
uid_set_id = uid_set_qs[0].id
|
|
uid_set_id = uid_set_qs[0].id
|
|
uid_set_data['updTime'] = nowTime
|
|
uid_set_data['updTime'] = nowTime
|
|
uid_set_qs.update(**uid_set_data)
|
|
uid_set_qs.update(**uid_set_data)
|