feat: shutdown_or_startup 优化

This commit is contained in:
caoqianming 2023-09-01 17:32:24 +08:00
parent 4fa33a7252
commit a0955c401f
2 changed files with 4 additions and 3 deletions

View File

@ -81,18 +81,17 @@ def shutdown_or_startup(mplog: MpLog):
from apps.wpm.tasks import cal_shut_hour
mpoint = mplog.mpoint
mgroup = mpoint.mgroup
now = timezone.now()
if mplog.tag_val == 1 and mgroup.is_runing is False:
# 从停到开
stlog = StLog.objects.filter(mgroup=mgroup).order_by('start_time').last()
stlog.end_time = now
stlog.end_time = mplog.tag_update
stlog.save()
mgroup.is_runing = True
mgroup.save()
cal_shut_hour(stlog.id) # 触发停机时间分配
elif mplog.tag_val == 0 and mgroup.is_runing is True:
# 从开到停
StLog.objects.create(mgroup=mgroup, start_time=now)
StLog.objects.get_or_create(mgroup=mgroup, end_time=None, defaults={'mgroup': mgroup, 'start_time': mplog.tag_update})
mgroup.is_runing = False
mgroup.save()

View File

@ -66,6 +66,8 @@ def cal_shut_hour(stlogId: str):
for stlog in stlogs:
now = datetime.datetime.now()
st_start = stlog.start_time
if st_start >= now:
break
if stlog.end_time is None: # 说明停机还未结束,此时也需要计算duration
st_end = now
else: