瀏覽代碼

设备版本查询编辑同步操作新增响应结果增加默认值

zhuojiaxuan 4 天之前
父節點
當前提交
11d36ceaf4
共有 2 個文件被更改,包括 73 次插入12 次删除
  1. 48 10
      AdminController/DeviceManagementController.py
  2. 25 2
      Controller/UserDevice/DeviceVersionInfoController.py

+ 48 - 10
AdminController/DeviceManagementController.py

@@ -1592,10 +1592,33 @@ class DeviceManagement(View):
         supports_night_vision = request_dict.get('supportsNightVision', 0)
         screen_channels = request_dict.get('screenChannels', None)
         network_type = request_dict.get('networkType', None)
-        other_features = request_dict.get('otherFeatures', None)
         electricity_statistics = request_dict.get('electricityStatistics', 0)
         supports_pet_tracking = request_dict.get('supportsPetTracking', 0)
         has_4g_cloud = request_dict.get('has4gCloud', -1)
+
+        other_features_fields = [
+            'supports_lighting',
+            'is_support_multi_speed',
+            'supports_algorithm_switch',
+            'supports_playback_filtering'
+        ]
+
+        check_other_features = request_dict.get('otherFeatures', None)
+        if check_other_features:
+            try:
+                other_features = json.loads(check_other_features)
+                for field in other_features_fields:
+                    if field not in other_features or other_features[field] in (None, '', []):
+                        other_features[field] = -1
+                        LOGGER.info(f'设置 {field} 为默认值 -1')
+
+            except json.JSONDecodeError:
+                LOGGER.error(f"otherFeatures JSON 解析失败: {check_other_features}")
+                return response.json(500, "json无效")
+        else:
+            other_features = {field: -1 for field in other_features_fields}
+            LOGGER.info(f'未传入otherFeatures,创建默认值字典: {other_features}')
+
         if not all([d_code, software_ver, video_code,
                     device_type, supports_alarm,
                     screen_channels, network_type]
@@ -1604,10 +1627,7 @@ class DeviceManagement(View):
         try:
             now_time = int(time.time())
             ai_type = int(ai_type)
-            if other_features:
-                other_features = json.loads(other_features)
-            else:
-                other_features = None
+
             if DeviceVersionInfo.objects.filter(d_code=d_code, software_ver=software_ver).exists():
                 return response.json(174)
 
@@ -1667,11 +1687,33 @@ class DeviceManagement(View):
         supports_night_vision = request_dict.get('supportsNightVision', 0)
         screen_channels = request_dict.get('screenChannels', None)
         network_type = request_dict.get('networkType', None)
-        other_features = request_dict.get('otherFeatures', None)
         electricity_statistics = request_dict.get('electricityStatistics', 0)
         supports_pet_tracking = request_dict.get('supportsPetTracking', 0)
         has_4g_cloud = request_dict.get('has4gCloud', -1)
 
+        other_features_fields = [
+            'supports_lighting',
+            'is_support_multi_speed',
+            'supports_algorithm_switch',
+            'supports_playback_filtering'
+        ]
+
+        check_other_features = request_dict.get('otherFeatures', None)
+        if check_other_features:
+            try:
+                other_features = json.loads(check_other_features)
+                for field in other_features_fields:
+                    if field not in other_features or other_features[field] in (None, '', []):
+                        other_features[field] = -1
+                        LOGGER.info(f'设置 {field} 为默认值 -1')
+
+            except json.JSONDecodeError:
+                LOGGER.error(f"otherFeatures JSON 解析失败: {check_other_features}")
+                return response.json(500, "json无效")
+        else:
+            other_features = {field: -1 for field in other_features_fields}
+            LOGGER.info(f'未传入otherFeatures,创建默认值字典: {other_features}')
+
         if not all([device_ver_id, video_code, device_type, supports_alarm, screen_channels, network_type]):
             return response.json(444)
         try:
@@ -1680,10 +1722,6 @@ class DeviceManagement(View):
             device_version_info_qs = DeviceVersionInfo.objects.filter(id=device_ver_id).values('d_code', 'software_ver')
             if not device_version_info_qs.exists():
                 return response.json(173)
-            if other_features:
-                other_features = json.loads(other_features)
-            else:
-                other_features = None
 
             d_code = device_version_info_qs[0]['d_code']
             software_ver = device_version_info_qs[0]['software_ver']

+ 25 - 2
Controller/UserDevice/DeviceVersionInfoController.py

@@ -263,6 +263,30 @@ class DeviceVersionInfoView(View):
         try:
             d_code = request_dict.get('dCode', '')
             ver = request_dict.get('softwareVer', '')
+
+            other_features_fields = [
+                'supports_lighting',
+                'is_support_multi_speed',
+                'supports_algorithm_switch',
+                'supports_playback_filtering'
+            ]
+
+            check_other_features = request_dict.get('otherFeatures', None)
+            if check_other_features:
+                try:
+                    other_features = json.loads(check_other_features)
+                    for field in other_features_fields:
+                        if field not in other_features or other_features[field] in (None, '', []):
+                            other_features[field] = -1
+                            LOGGER.info(f'设置 {field} 为默认值 -1')
+
+                except json.JSONDecodeError:
+                    LOGGER.error(f"otherFeatures JSON 解析失败: {check_other_features}")
+                    return response.json(500, "json无效")
+            else:
+                other_features = {field: -1 for field in other_features_fields}
+                LOGGER.info(f'未传入otherFeatures,创建默认值字典: {other_features}')
+
             # 提取参数并设置默认值(添加必要字段的类型转换)
             params = {
                 'd_code': d_code,  # 字符串类型,添加默认空字符串
@@ -286,8 +310,7 @@ class DeviceVersionInfoView(View):
                 'supports_night_vision': int(request_dict.get('supportsNightVision', -1)),  # 使用get()添加默认值-1
                 'screen_channels': int(request_dict.get('screenChannels', 1)),  # 匹配模型默认值1
                 'network_type': int(request_dict.get('networkType', 1)),  # 匹配模型默认值1
-                'other_features': json.loads(request_dict['otherFeatures']) if request_dict.get(
-                    'otherFeatures') else None,  # 保持不变
+                'other_features': other_features,
                 'electricity_statistics': int(request_dict.get('electricityStatistics', 0)),  # 使用get()添加默认值0
                 'supports_pet_tracking': int(request_dict.get('supportsPetTracking', 0)),  # 使用get()添加默认值0
             }