refector: mgroup_on_change时创建stlog优化

This commit is contained in:
caoqianming 2024-08-20 08:56:08 +08:00
parent d102f01c26
commit 592e34c07e
1 changed files with 10 additions and 3 deletions

View File

@ -127,9 +127,16 @@ def mgroup_run_change(mgroup: Mgroup, new_run: bool, last_timex: datetime):
last_stlog.save()
cal_exp_duration_sec(last_stlog.id) # 触发时间分配
elif last_stlog.end_time and new_run is False and last_timex > last_stlog.end_time: # 从开到停
has_same_stlog =StLog.objects.filter(mgroup=mgroup, is_shutdown=True, start_time=last_timex).exists()
if not has_same_stlog:
StLog.objects.create(title="停机", is_shutdown=True, mgroup=mgroup, end_time=None, start_time=last_timex, sflog=get_sflog(mgroup, last_timex))
StLog.objects.get_or_create(
mgroup=mgroup,
is_shutdown=True,
start_time=last_timex,
defaults={
'title': '停机',
'end_time': None,
'sflog': get_sflog(mgroup, last_timex)
}
)
elif new_run is False:
StLog.objects.create(title="停机", is_shutdown=True, mgroup=mgroup, end_time=None, start_time=last_timex, sflog=get_sflog(mgroup, last_timex))
mgroup.is_running = False