Bläddra i källkod

修改查询消息数据异常

zhangdongming 9 månader sedan
förälder
incheckning
21abc339d0
1 ändrade filer med 24 tillägg och 20 borttagningar
  1. 24 20
      Controller/EquipmentManager.py

+ 24 - 20
Controller/EquipmentManager.py

@@ -12,7 +12,6 @@ from django.db.models import Q
 from django.utils import timezone
 
 from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY, BASE_DIR, ALGORITHM_COMBO_TYPES
-from Ansjer.config import PUSH_REDIS_ADDRESS
 from Controller.DetectController import DetectControllerView
 from Controller.DeviceShare import DeviceShareView
 from Model.models import Device_User, Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidPushModel, \
@@ -1149,26 +1148,31 @@ def uid_status(request):
             'msgData': qs[0]['msg_notify']
         }
 
-        # 检查 channel 有效性和 msg_notify 是否存在
-        if channel > 0 and is_nvr == 1 and qs[0].get('msg_notify'):
-            # 获取 msg_notify 数据
-            msg_notify = qs[0]['msg_notify']
-            nvr_entries = msg_notify.get('nvr', [])
-            channel_key = f'channel{channel}'
-
-            # 查找匹配的 channel_entry
-            matching_entry = next((entry for entry in nvr_entries if channel_key in entry), None)
-
-            if matching_entry:
-                # 更新 nvr 值
-                data['msgData']['nvr'] = matching_entry[channel_key]
+        try:
+            # 检查 channel 有效性和 msg_notify 是否存在
+            if channel > 0 and is_nvr == 1 and qs[0].get('msg_notify'):
+                # 获取 msg_notify 数据
+                msg_notify = qs[0]['msg_notify']
+                nvr_entries = msg_notify.get('nvr', [])
+                channel_key = f'channel{channel}'
+
+                # 查找匹配的 channel_entry
+                matching_entry = next((entry for entry in nvr_entries if channel_key in entry), None)
+
+                if matching_entry:
+                    # 更新 nvr 值
+                    data['msgData']['nvr'] = matching_entry[channel_key]
+                else:
+                    # 没有找到匹配的 channel,使用默认值替换 nvr
+                    available_types = [t for t in ALGORITHM_COMBO_TYPES if t != 51]
+                    data['msgData']['nvr'] = available_types
             else:
-                # 没有找到匹配的 channel,使用默认值替换 nvr
-                available_types = [t for t in ALGORITHM_COMBO_TYPES if t != 51]
-                data['msgData']['nvr'] = available_types
-        else:
-            if 'nvr' in qs[0].get('msg_notify'):
-                data['msgData']['nvr'] = []
+                msg_notify = qs[0].get('msg_notify')
+                if msg_notify and 'nvr' in msg_notify:
+                    data['msgData']['nvr'] = []
+        except Exception as e:
+            logger.error(f'查询消息提醒异常uid:{uid},error:{repr(e)}')
+
 
         # 调试
         debugTwos = int(time.time())