feat: 修改采集时候出现0的处理

This commit is contained in:
zty 2024-10-09 09:26:29 +08:00
parent 924d7f2b61
commit 66af6475d9
2 changed files with 12 additions and 2 deletions

View File

@ -390,6 +390,16 @@ class TestViewSet(CustomGenericViewSet):
test_snap_list.append(task_id)
cache.set('test_snap_task', test_snap_list)
return Response({'test_snap_task': task_id})
@action(methods=['post'], detail=False, serializer_class=Serializer)
def stop_celery_task(self, request, pk=None):
""""
关闭重跑重跑能源计算任务
"""
from server.celery import celery_control
celery_control.revoke(request.data['task_id'], terminate=True)
return Response()
@action(methods=['post'], detail=False, serializer_class=Serializer)
def close_snap_task(self, request, pk=None):

View File

@ -158,7 +158,7 @@ class MpointCache:
mpoint_data["last_data"] = {"last_val": None, "last_timex": None, "last_mrs": None} # 初始化
if update_mplogx:
now = timezone.now()
last_mplogx = MpLogx.objects.filter(mpoint=mpoint, timex__gte=now - timedelta(minutes=5)).order_by("-timex").first()
last_mplogx = MpLogx.objects.filter(mpoint=mpoint, timex__gte=now - timedelta(minutes=10)).order_by("-timex").first()
if last_mplogx: # 核心数据
mpoint_data["last_data"] = {"last_val": getattr(last_mplogx, "val_" + mpoint_data["val_type"]), "last_timex": last_mplogx.timex}
cache.set(key, mpoint_data, timeout=None)
@ -190,7 +190,7 @@ class MpointCache:
current_cache_val.get('is_rep_ep_running_state', None) is False and
get_sysconfig('enm.use_cache_when_w_el_0', False) is True and
current_cache_val.get("material_name", "") in ["动力电", "工业水"]): # 如果电表断电
pass
last_val = last_data["last_val"] if last_data["last_val"] is not None else 0
else:
last_data["last_val"] = last_val
last_data["last_timex"] = last_timex