|
@@ -128,6 +128,13 @@ class DeviceVersionInfoView(View):
|
|
|
ver, d_code = version.rsplit('.', 1) # 使用从右到左分割
|
|
|
ver = ver.replace('V', '') # 移除版本前的'V'
|
|
|
|
|
|
+ other_features_fields = [
|
|
|
+ 'supports_lighting',
|
|
|
+ 'is_support_multi_speed',
|
|
|
+ 'supports_algorithm_switch',
|
|
|
+ 'supports_playback_filtering'
|
|
|
+ ]
|
|
|
+
|
|
|
# 创建Redis对象
|
|
|
redis = RedisObject()
|
|
|
# 构建Redis键
|
|
@@ -136,8 +143,24 @@ class DeviceVersionInfoView(View):
|
|
|
# 尝试从Redis中获取数据
|
|
|
version_info = redis.get_data(version_key)
|
|
|
if version_info:
|
|
|
- # 如果在Redis中找到了数据,直接返回
|
|
|
- return response.json(0, json.loads(version_info))
|
|
|
+ device_info = json.loads(version_info)
|
|
|
+ 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}
|
|
|
+
|
|
|
+ # 更新Redis中的数据
|
|
|
+ redis.set_data(version_key, json.dumps(device_info), 60 * 60 * 24) # 设置TTL为24小时
|
|
|
+ return response.json(0, device_info)
|
|
|
|
|
|
# 从数据库查询设备版本信息
|
|
|
device_version_qs = DeviceVersionInfo.objects.filter(d_code=d_code, software_ver=ver).values()
|
|
@@ -148,13 +171,6 @@ class DeviceVersionInfoView(View):
|
|
|
# 从QuerySet中获取设备信息
|
|
|
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:
|
|
@@ -163,7 +179,8 @@ class DeviceVersionInfoView(View):
|
|
|
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, ''):
|
|
|
+ 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}
|