Explorar o código

Merge remote-tracking branch 'remotes/origin/Zhuo' into test

Ansjer hai 4 días
pai
achega
87d029cc5f

+ 11 - 44
AdminController/DeviceManagementController.py

@@ -1592,32 +1592,11 @@ 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,
@@ -1627,6 +1606,10 @@ 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)
@@ -1687,38 +1670,22 @@ 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:
             now_time = int(time.time())
             ai_type = int(ai_type)
+            if other_features:
+                other_features = json.loads(other_features)
+            else:
+                other_features = None
+
             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)

+ 25 - 27
Controller/UserDevice/DeviceVersionInfoController.py

@@ -146,15 +146,35 @@ class DeviceVersionInfoView(View):
                 return response.json(173)  # 错误代码:未找到设备版本信息
 
             # 从QuerySet中获取设备信息
-            device_info = device_version_qs
+            device_info = device_version_qs.first()
+
+            other_features_fields = [
+                'supports_lighting',
+                'is_support_multi_speed',
+                'supports_algorithm_switch',
+                'supports_playback_filtering'
+            ]
+
+            if not device_info.get("other_features"):
+                device_info["other_features"] = {field: -1 for field in other_features_fields}
+            else:
+                try:
+                    if isinstance(device_info["other_features"], str):
+                        device_info["other_features"] = json.loads(device_info["other_features"])
+
+                    for field in other_features_fields:
+                        if field not in device_info["other_features"] or device_info["other_features"][field] in (None, ''):
+                            device_info["other_features"][field] = -1
+                except json.JSONDecodeError:
+                    device_info["other_features"] = {field: -1 for field in other_features_fields}
 
             # 将设备信息序列化为JSON
-            device_json = json.dumps(device_info[0])
+            device_json = json.dumps(device_info)
 
             # 将数据写入Redis,以便后续使用
             redis.set_data(version_key, device_json, 60 * 60 * 24)  # 设置TTL为24小时
             # 返回设备信息
-            return response.json(0, device_info[0])
+            return response.json(0, device_info)
 
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
@@ -264,29 +284,6 @@ class DeviceVersionInfoView(View):
             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,  # 字符串类型,添加默认空字符串
@@ -310,7 +307,8 @@ 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': other_features,
+                'other_features': json.loads(request_dict['otherFeatures']) if request_dict.get(
+                    'otherFeatures') else None,  # 保持不变
                 'electricity_statistics': int(request_dict.get('electricityStatistics', 0)),  # 使用get()添加默认值0
                 'supports_pet_tracking': int(request_dict.get('supportsPetTracking', 0)),  # 使用get()添加默认值0
             }