From b22058d0bb7fc8025337deb8cbdfbb50332d3766 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 8 May 2024 16:07:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20cal=5Fexp=5Fduration=5Fhour=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=8F=82=E6=95=B0=E4=BB=A5=E5=81=9A=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/tasks.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/wpm/tasks.py b/apps/wpm/tasks.py index 307b1a7d..39f1087f 100644 --- a/apps/wpm/tasks.py +++ b/apps/wpm/tasks.py @@ -58,20 +58,22 @@ def get_total_hour_now(sflogId: str=''): @shared_task(base=CustomTask) -def cal_exp_duration_hour(stlogId: str): +def cal_exp_duration_hour(stlogId: str, all=False): """ 计算异常记录对应的每班持续时间 """ - from apps.enm.tasks import cal_enstat # 如果是停机需要进行统计停机时长 + # from apps.enm.tasks import cal_enstat # 如果是停机需要进行统计停机时长 if stlogId: stlogs = StLog.objects.filter(id=stlogId) - else: # 不传就默认更新所有的 + elif all: + stlogs = StLog.objects.all() + else: # 不传就默认更新未结束的 stlogs = StLog.objects.filter(end_time=None) now = timezone.now() for stlog in stlogs: - need_cal_enstat = True + is_shutdown_stlog = True if stlog.is_shutdown is False: - need_cal_enstat = False + is_shutdown_stlog = False st_start = stlog.start_time if st_start >= now: break @@ -96,7 +98,7 @@ def cal_exp_duration_hour(stlogId: str): duration_item = total_seconds/3600 sflogexp.duration = duration_item sflogexp.save() - if need_cal_enstat: + if is_shutdown_stlog: # 计算每班的总停机时间 ret = SfLogExp.objects.filter( sflog=sflog, stlog__is_shutdown=True).aggregate(sum=Sum('duration')) @@ -106,9 +108,9 @@ def cal_exp_duration_hour(stlogId: str): # 更新sflog总时长 if sflog.end_time > now: get_total_hour_now(sflog.id) - if stlogId: - cal_enstat('sflog', sflog.id, sflog.mgroup.id, None, None, None, - None, None, None, None, cascade=True, cal_attrs=['run_hour']) + # if stlogId: + # cal_enstat('sflog', sflog.id, sflog.mgroup.id, None, None, None, + # None, None, None, None, cascade=True, cal_attrs=['run_hour']) @shared_task(base=CustomTask)