fix: mpointserializer获取last_data优化

This commit is contained in:
caoqianming 2024-06-24 16:45:05 +08:00
parent 499e5732aa
commit 643efa448e
1 changed files with 12 additions and 2 deletions

View File

@ -25,10 +25,20 @@ class MpointSerializer(CustomModelSerializer):
read_only_fields = EXCLUDE_FIELDS + ["belong_dept", "cate"]
def get_last_data(self, obj):
return cache.get(Mpoint.cache_key(obj.code), {}).get('last_data', {})
cache_mp = cache.get(Mpoint.cache_key(obj.code))
if isinstance(cache_mp, dict):
last_data = cache_mp.get('last_data', {})
else:
last_data = {}
return last_data
def get_gather_state(self, obj):
return cache.get(Mpoint.cache_key(obj.code), {}).get('gather_state', -2)
cache_mp = cache.get(Mpoint.cache_key(obj.code))
if isinstance(cache_mp, dict):
gather_state = cache_mp.get('gather_state', -2)
else:
gather_state = -2
return gather_state
def validate(self, attrs):
if "material" in attrs and attrs["material"]: