瀏覽代碼

修复IPC消息提醒事件类型设置无效问题

zhangdongming 7 月之前
父節點
當前提交
2f764116b9
共有 1 個文件被更改,包括 32 次插入24 次删除
  1. 32 24
      Controller/DetectControllerV2.py

+ 32 - 24
Controller/DetectControllerV2.py

@@ -109,30 +109,38 @@ class DetectControllerViewV2(View):
 
     @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
+        try:
+            # 检查是否是 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
+            elif is_nvr == 0:
+                if 'nvr' in data:
+                    del data['nvr']  # 删除 nvr 键
+
+                return msg_notify
+            return data
+        except Exception as e:
+            # 记录异常信息
+            LOGGER.error('修改消息提醒params: {}: errLine: {}, errMsg: {}'.format(
+                data, e.__traceback__.tb_lineno, repr(e)))
+            return data
 
     def do_change_status(self, userID, request_dict, response):
         token_val = request_dict.get('token_val', None)