feat: 支持多种开停信号联动
This commit is contained in:
parent
a8fb69d747
commit
196209d60c
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 3.2.12 on 2024-04-19 05:01
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('em', '0016_auto_20240416_1454'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='equipment',
|
||||
name='is_core_for_mgroup',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='equipment',
|
||||
name='indicate_mgroup_running',
|
||||
field=models.PositiveSmallIntegerField(blank=True, choices=[(10, '单开为开/单停为停'), (20, '单开为开/都停为停'), (30, '都开为开/单停为停')], null=True, verbose_name='表明工段运行的方式'),
|
||||
),
|
||||
]
|
|
@ -57,13 +57,23 @@ class Equipment(CommonBModel):
|
|||
# (1, '专用'),
|
||||
# (2, '公用'),
|
||||
# )
|
||||
IM_DANDAN = 10
|
||||
IM_DANDOU = 20
|
||||
IM_DOUDAN = 30
|
||||
|
||||
IM_CHOICES = (
|
||||
(10, '单开为开/单停为停'),
|
||||
(20, '单开为开/都停为停'),
|
||||
(30, '都开为开/单停为停')
|
||||
)
|
||||
|
||||
running_state = models.PositiveSmallIntegerField("运行状态", default=50)
|
||||
ip = models.GenericIPAddressField("IP地址", null=True, blank=True)
|
||||
port = models.PositiveSmallIntegerField("端口号", null=True, blank=True)
|
||||
login_name = models.CharField("登录名", max_length=100, null=True, blank=True)
|
||||
login_pwd = models.CharField("登录密码", max_length=100, null=True, blank=True)
|
||||
mgroup = models.ForeignKey("mtm.mgroup", on_delete=models.SET_NULL, null=True, blank=True)
|
||||
is_core_for_mgroup = models.BooleanField("是否工段核心设备", default=False)
|
||||
indicate_mgroup_running = models.PositiveSmallIntegerField("表明工段运行的方式", choices=IM_CHOICES, null=True, blank=True)
|
||||
type = models.PositiveSmallIntegerField("类型", choices=etype_choices, default=10)
|
||||
cate = models.ForeignKey(Ecate, verbose_name="设备分类", on_delete=models.SET_NULL, null=True, blank=True, related_name="cate")
|
||||
tags = models.JSONField("设备标签", default=list, blank=True)
|
||||
|
|
|
@ -17,27 +17,43 @@ def shutdown_or_startup(equipId: str, last_timex: datetime, last_mrs):
|
|||
equip.running_state = last_mrs
|
||||
equip.save(update_fields=["running_state"])
|
||||
|
||||
mgroup = equip.mgroup
|
||||
is_core_for_mgroup = equip.is_core_for_mgroup
|
||||
if mgroup and is_core_for_mgroup:
|
||||
last_stlog = StLog.objects.filter(mgroup=mgroup, is_shutdown=True).order_by("-start_time").first() # 找到最后一次停机记录
|
||||
if last_stlog:
|
||||
if last_timex >= last_stlog.start_time: # 认为是有效信号
|
||||
if last_stlog.end_time is None and last_mrs == RuningState.RUNING: # 从停到开
|
||||
last_stlog.end_time = last_timex
|
||||
last_stlog.duration = (last_stlog.end_time - last_stlog.start_time).total_seconds() / 3600
|
||||
last_stlog.save()
|
||||
mgroup.is_runing = True
|
||||
mgroup.save()
|
||||
cal_exp_duration_hour(last_stlog.id) # 触发时间分配
|
||||
elif last_stlog.end_time and last_mrs != RuningState.RUNING and last_timex > last_stlog.end_time: # 从开到停
|
||||
StLog.objects.create(title="停机", is_shutdown=True, mgroup=mgroup, end_time=None, start_time=last_timex, sflog=get_sflog(mgroup, last_timex))
|
||||
mgroup.is_runing = False
|
||||
mgroup.save()
|
||||
else:
|
||||
StLog.objects.create(title="停机", is_shutdown=True, mgroup=mgroup, end_time=None, start_time=last_timex, sflog=get_sflog(mgroup, last_timex))
|
||||
mgroup.is_runing = False
|
||||
mgroup.save()
|
||||
mgroup: Mgroup = equip.mgroup
|
||||
indicate = equip.indicate_mgroup_running
|
||||
|
||||
if mgroup and indicate:
|
||||
mrun = None
|
||||
if last_mrs in [RuningState.STOP, RuningState.FAILURE, RuningState.STANDBY]: # 设备停止信号
|
||||
if indicate in [Equipment.IM_DANDAN, Equipment.IM_DOUDAN]:
|
||||
mrun= False
|
||||
else:
|
||||
if not Equipment.objects.filter(mgroup=mgroup, indicate_mgroup_running=indicate, running_state=RuningState.RUNING).exists():
|
||||
mrun = False
|
||||
elif last_mrs == RuningState.RUNING: # 设备启动信号
|
||||
if indicate in [Equipment.IM_DANDAN, Equipment.IM_DANDOU]:
|
||||
mrun= True
|
||||
else:
|
||||
if not Equipment.objects.filter(mgroup=mgroup, indicate_mgroup_running=indicate, running_state__in=[RuningState.STOP, RuningState.FAILURE, RuningState.STANDBY]).exists():
|
||||
mrun = True
|
||||
|
||||
if mrun is not None:
|
||||
mgroup.is_runing = mrun
|
||||
mgroup.save(update_fields=["is_runing"])
|
||||
|
||||
last_stlog = StLog.objects.filter(mgroup=mgroup, is_shutdown=True).order_by("-start_time").first() # 找到最后一次停机记录
|
||||
|
||||
if last_stlog:
|
||||
if last_timex >= last_stlog.start_time: # 认为是有效信号
|
||||
if last_stlog.end_time is None and mrun: # 从停到开
|
||||
last_stlog.end_time = last_timex
|
||||
last_stlog.duration = (last_stlog.end_time - last_stlog.start_time).total_seconds() / 3600
|
||||
last_stlog.save()
|
||||
cal_exp_duration_hour(last_stlog.id) # 触发时间分配
|
||||
elif last_stlog.end_time and mrun is False and last_timex > last_stlog.end_time: # 从开到停
|
||||
StLog.objects.create(title="停机", is_shutdown=True, mgroup=mgroup, end_time=None, start_time=last_timex, sflog=get_sflog(mgroup, last_timex))
|
||||
elif mrun 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_runing = False
|
||||
mgroup.save()
|
||||
|
||||
|
||||
def daoru_equipment(path: str):
|
||||
|
|
Loading…
Reference in New Issue