feat: runningstate统一修改
This commit is contained in:
parent
7b83cd1095
commit
53ce0ea0f7
|
|
@ -6,14 +6,6 @@ from enum import Enum
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
class RuningState(Enum):
|
|
||||||
RUNING = 10
|
|
||||||
STANDBY = 20
|
|
||||||
STOP = 30
|
|
||||||
FAILURE = 40
|
|
||||||
OFFLINE = 50
|
|
||||||
|
|
||||||
|
|
||||||
etype_choices = ((10, "生产设备"), (20, "计量设备"), (30, "治理设备"), (40, "监测设备"), (50, "监控设备"))
|
etype_choices = ((10, "生产设备"), (20, "计量设备"), (30, "治理设备"), (40, "监测设备"), (50, "监控设备"))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -34,6 +26,12 @@ class Equipment(CommonBModel):
|
||||||
设备台账信息
|
设备台账信息
|
||||||
其中belong_dept是责任部门
|
其中belong_dept是责任部门
|
||||||
"""
|
"""
|
||||||
|
RUNING = 10
|
||||||
|
STANDBY = 20
|
||||||
|
STOP = 30
|
||||||
|
FAILURE = 40
|
||||||
|
OFFLINE = 50
|
||||||
|
|
||||||
|
|
||||||
EQUIP_STATE_OK = 10
|
EQUIP_STATE_OK = 10
|
||||||
EQUIP_STATE_LIMIT = 20
|
EQUIP_STATE_LIMIT = 20
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ from .models import Equipment
|
||||||
from apps.system.models import Dept
|
from apps.system.models import Dept
|
||||||
from apps.mtm.models import Mgroup
|
from apps.mtm.models import Mgroup
|
||||||
import datetime
|
import datetime
|
||||||
from .models import RuningState
|
|
||||||
|
|
||||||
|
|
||||||
def shutdown_or_startup(equipId: str, last_timex: datetime, last_mrs):
|
def shutdown_or_startup(equipId: str, last_timex: datetime, last_mrs):
|
||||||
|
|
@ -22,17 +21,17 @@ def shutdown_or_startup(equipId: str, last_timex: datetime, last_mrs):
|
||||||
|
|
||||||
if mgroup and indicate:
|
if mgroup and indicate:
|
||||||
mrun = None
|
mrun = None
|
||||||
if last_mrs in [RuningState.STOP, RuningState.FAILURE, RuningState.STANDBY]: # 设备停止信号
|
if last_mrs in [Equipment.STOP, Equipment.FAILURE, Equipment.STANDBY]: # 设备停止信号
|
||||||
if indicate in [Equipment.IM_DANDAN, Equipment.IM_DOUDAN]:
|
if indicate in [Equipment.IM_DANDAN, Equipment.IM_DOUDAN]:
|
||||||
mrun= False
|
mrun= False
|
||||||
else:
|
else:
|
||||||
if not Equipment.objects.filter(mgroup=mgroup, indicate_mgroup_running=indicate, running_state=RuningState.RUNING).exists():
|
if not Equipment.objects.filter(mgroup=mgroup, indicate_mgroup_running=indicate, running_state=Equipment.RUNING).exists():
|
||||||
mrun = False
|
mrun = False
|
||||||
elif last_mrs == RuningState.RUNING: # 设备启动信号
|
elif last_mrs == Equipment.RUNING: # 设备启动信号
|
||||||
if indicate in [Equipment.IM_DANDAN, Equipment.IM_DANDOU]:
|
if indicate in [Equipment.IM_DANDAN, Equipment.IM_DANDOU]:
|
||||||
mrun= True
|
mrun= True
|
||||||
else:
|
else:
|
||||||
if not Equipment.objects.filter(mgroup=mgroup, indicate_mgroup_running=indicate, running_state__in=[RuningState.STOP, RuningState.FAILURE, RuningState.STANDBY]).exists():
|
if not Equipment.objects.filter(mgroup=mgroup, indicate_mgroup_running=indicate, running_state__in=[Equipment.STOP, Equipment.FAILURE, Equipment.STANDBY]).exists():
|
||||||
mrun = True
|
mrun = True
|
||||||
|
|
||||||
if mrun is not None:
|
if mrun is not None:
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from __future__ import absolute_import, unicode_literals
|
||||||
from apps.utils.tasks import CustomTask
|
from apps.utils.tasks import CustomTask
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from apps.em.models import Equipment, RuningState
|
from apps.em.models import Equipment
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -23,6 +23,6 @@ def check_equipment_offline(seconds=20):
|
||||||
last_timex = cache_value.get("running_state_timex", None)
|
last_timex = cache_value.get("running_state_timex", None)
|
||||||
if last_timex and (now - last_timex).total_seconds() <= seconds:
|
if last_timex and (now - last_timex).total_seconds() <= seconds:
|
||||||
is_offline = False
|
is_offline = False
|
||||||
if is_offline and equip.running_state != RuningState.OFFLINE:
|
if is_offline and equip.running_state != Equipment.OFFLINE:
|
||||||
equip.running_state = RuningState.OFFLINE
|
equip.running_state = Equipment.OFFLINE
|
||||||
equip.save(update_fields=["running_state"])
|
equip.save(update_fields=["running_state"])
|
||||||
|
|
@ -14,7 +14,7 @@ from django.db import IntegrityError
|
||||||
from apps.utils.tasks import ctask_run
|
from apps.utils.tasks import ctask_run
|
||||||
from .serializers import MpointSerializer
|
from .serializers import MpointSerializer
|
||||||
from apps.enp.models import EnvData
|
from apps.enp.models import EnvData
|
||||||
from apps.em.models import Equipment, RuningState
|
from apps.em.models import Equipment
|
||||||
|
|
||||||
myLogger = logging.getLogger("log")
|
myLogger = logging.getLogger("log")
|
||||||
|
|
||||||
|
|
@ -130,13 +130,13 @@ def update_mpoint_cache(cache_key: str, current_cache_val: dict, last_timex: dat
|
||||||
cache.set(cache_key, current_cache_val, timeout=None)
|
cache.set(cache_key, current_cache_val, timeout=None)
|
||||||
# 更新设备状态缓存值
|
# 更新设备状态缓存值
|
||||||
if ep_belong_id:
|
if ep_belong_id:
|
||||||
cache.set(f"equipment_{ep_belong_id}", {"running_state": RuningState.RUNING, "running_state_timex": last_timex}, timeout=None)
|
cache.set(f"equipment_{ep_belong_id}", {"running_state": Equipment.RUNING, "running_state_timex": last_timex}, timeout=None)
|
||||||
if ep_monitored_id:
|
if ep_monitored_id:
|
||||||
cache.set(f"equipment_{ep_monitored_id}", {"running_state": last_mrs, "running_state_timex": last_timex}, timeout=None)
|
cache.set(f"equipment_{ep_monitored_id}", {"running_state": last_mrs, "running_state_timex": last_timex}, timeout=None)
|
||||||
# 如果state变动则触发函数
|
# 如果state变动则触发函数
|
||||||
if last_data["pre_mrs"] != last_mrs:
|
if last_data["pre_mrs"] != last_mrs:
|
||||||
if ep_belong_id:
|
if ep_belong_id:
|
||||||
ctask_run("apps.em.services.shutdown_or_startup", ep_belong_id, last_timex, RuningState.RUNING)
|
ctask_run("apps.em.services.shutdown_or_startup", ep_belong_id, last_timex, Equipment.RUNING)
|
||||||
if ep_monitored_id:
|
if ep_monitored_id:
|
||||||
ctask_run("apps.em.services.shutdown_or_startup", ep_belong_id, last_timex, last_mrs)
|
ctask_run("apps.em.services.shutdown_or_startup", ep_belong_id, last_timex, last_mrs)
|
||||||
|
|
||||||
|
|
@ -147,15 +147,15 @@ def transfer_mpoint_val_to_ep_running_state(current_val, base_val1: float):
|
||||||
"""
|
"""
|
||||||
if isinstance(current_val, bool):
|
if isinstance(current_val, bool):
|
||||||
if current_val:
|
if current_val:
|
||||||
return RuningState.RUNING
|
return Equipment.RUNING
|
||||||
return RuningState.STOP
|
return Equipment.STOP
|
||||||
rs = RuningState.RUNING
|
rs = Equipment.RUNING
|
||||||
if base_val1:
|
if base_val1:
|
||||||
if current_val < base_val1:
|
if current_val < base_val1:
|
||||||
rs = RuningState.STOP
|
rs = Equipment.STOP
|
||||||
else:
|
else:
|
||||||
if current_val == 0:
|
if current_val == 0:
|
||||||
rs = RuningState.STOP
|
rs = Equipment.STOP
|
||||||
return rs
|
return rs
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -303,7 +303,7 @@ def insert_mplogx_from_king_mqtt_chunk(objs: list, oval, otime_obj: datetime, is
|
||||||
"mpoint": Mpoint.objects.get(id=mpoint_data["id"]),
|
"mpoint": Mpoint.objects.get(id=mpoint_data["id"]),
|
||||||
}
|
}
|
||||||
save_dict[f"val_{val_type}"] = val
|
save_dict[f"val_{val_type}"] = val
|
||||||
val_mrs = RuningState.RUNING
|
val_mrs = Equipment.RUNING
|
||||||
if mpoint_is_rep_ep_running_state:
|
if mpoint_is_rep_ep_running_state:
|
||||||
save_dict["val_mrs"] = transfer_mpoint_val_to_ep_running_state(val, mpoint_ep_base_val1)
|
save_dict["val_mrs"] = transfer_mpoint_val_to_ep_running_state(val, mpoint_ep_base_val1)
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue