Răsfoiți Sursa

优化打开状态下设置接收推送类型

zhangdongming 10 luni în urmă
părinte
comite
eae93002cd
1 a modificat fișierele cu 17 adăugiri și 18 ștergeri
  1. 17 18
      Controller/DetectControllerV2.py

+ 17 - 18
Controller/DetectControllerV2.py

@@ -113,26 +113,25 @@ class DetectControllerViewV2(View):
         if is_nvr == 1 and channel > 0:
             # 构建目标键,例如 'channel1' 或 'channel2'
             target_key = f'channel{channel}'
-            # 初始化存在标志
-            channel_found = False
-            # 使用 map() 和条件表达式
+
+            # 使用条件表达式构建 new_data
             new_data = {target_key: list(map(int, event_types.split(','))) if event_types else []}
-            # 检查 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)
+
+            # 获取 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):