feat: 二代灯有count数据则返回,否则用一代数据
This commit is contained in:
parent
270096da2d
commit
e773252d17
|
@ -32,6 +32,7 @@ def get_device_latest_by_cache(device_id, key="device_latest_{}"):
|
|||
latest = cache.get(latest_key)
|
||||
if latest:
|
||||
return latest
|
||||
|
||||
latest = DeviceCount.objects.filter(device_id=device_id).order_by('-data_time').first()
|
||||
if latest is None:
|
||||
return None
|
||||
|
@ -235,6 +236,13 @@ class DeviceInfoSerializer(serializers.ModelSerializer):
|
|||
|
||||
def get_count(self, obj) -> str:
|
||||
self.latest = get_device_latest_by_cache(obj.device_id)
|
||||
|
||||
# 区分一代和二代设备
|
||||
if obj.chip_type == 'AIR-V2':
|
||||
mosq_device_info = MosquitoDeviceInfo.objects.filter(device_id=obj.device_id).first()
|
||||
if mosq_device_info and mosq_device_info.count:
|
||||
return mosq_device_info.count
|
||||
|
||||
if self.latest:
|
||||
return self.latest['count']
|
||||
return '0'
|
||||
|
|
Loading…
Reference in New Issue