feat: cal_exp_duration_hour 添加参数以做测试
This commit is contained in:
parent
035b9b392a
commit
b22058d0bb
|
@ -58,20 +58,22 @@ def get_total_hour_now(sflogId: str=''):
|
||||||
|
|
||||||
|
|
||||||
@shared_task(base=CustomTask)
|
@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:
|
if stlogId:
|
||||||
stlogs = StLog.objects.filter(id=stlogId)
|
stlogs = StLog.objects.filter(id=stlogId)
|
||||||
else: # 不传就默认更新所有的
|
elif all:
|
||||||
|
stlogs = StLog.objects.all()
|
||||||
|
else: # 不传就默认更新未结束的
|
||||||
stlogs = StLog.objects.filter(end_time=None)
|
stlogs = StLog.objects.filter(end_time=None)
|
||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
for stlog in stlogs:
|
for stlog in stlogs:
|
||||||
need_cal_enstat = True
|
is_shutdown_stlog = True
|
||||||
if stlog.is_shutdown is False:
|
if stlog.is_shutdown is False:
|
||||||
need_cal_enstat = False
|
is_shutdown_stlog = False
|
||||||
st_start = stlog.start_time
|
st_start = stlog.start_time
|
||||||
if st_start >= now:
|
if st_start >= now:
|
||||||
break
|
break
|
||||||
|
@ -96,7 +98,7 @@ def cal_exp_duration_hour(stlogId: str):
|
||||||
duration_item = total_seconds/3600
|
duration_item = total_seconds/3600
|
||||||
sflogexp.duration = duration_item
|
sflogexp.duration = duration_item
|
||||||
sflogexp.save()
|
sflogexp.save()
|
||||||
if need_cal_enstat:
|
if is_shutdown_stlog:
|
||||||
# 计算每班的总停机时间
|
# 计算每班的总停机时间
|
||||||
ret = SfLogExp.objects.filter(
|
ret = SfLogExp.objects.filter(
|
||||||
sflog=sflog, stlog__is_shutdown=True).aggregate(sum=Sum('duration'))
|
sflog=sflog, stlog__is_shutdown=True).aggregate(sum=Sum('duration'))
|
||||||
|
@ -106,9 +108,9 @@ def cal_exp_duration_hour(stlogId: str):
|
||||||
# 更新sflog总时长
|
# 更新sflog总时长
|
||||||
if sflog.end_time > now:
|
if sflog.end_time > now:
|
||||||
get_total_hour_now(sflog.id)
|
get_total_hour_now(sflog.id)
|
||||||
if stlogId:
|
# if stlogId:
|
||||||
cal_enstat('sflog', sflog.id, sflog.mgroup.id, None, None, None,
|
# cal_enstat('sflog', sflog.id, sflog.mgroup.id, None, None, None,
|
||||||
None, None, None, None, cascade=True, cal_attrs=['run_hour'])
|
# None, None, None, None, cascade=True, cal_attrs=['run_hour'])
|
||||||
|
|
||||||
|
|
||||||
@shared_task(base=CustomTask)
|
@shared_task(base=CustomTask)
|
||||||
|
|
Loading…
Reference in New Issue