feat: cal_exp_duration_hour 添加参数以做测试

This commit is contained in:
caoqianming 2024-05-08 16:07:03 +08:00
parent 035b9b392a
commit b22058d0bb
1 changed files with 11 additions and 9 deletions

View File

@ -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)