fix /enm/service.py 停机时间短 无班组 加入异常原因
This commit is contained in:
parent
038e7f86cd
commit
c4607e1608
|
@ -40,7 +40,7 @@ def set_eq_rs(equipId, last_timex: datetime, last_mrs: int):
|
||||||
ctask_run.delay("apps.em.services.shutdown_or_startup", equipId, last_timex, last_mrs)
|
ctask_run.delay("apps.em.services.shutdown_or_startup", equipId, last_timex, last_mrs)
|
||||||
|
|
||||||
|
|
||||||
def shutdown_or_startup(equipId: str, last_timex: datetime, last_mrs):
|
def shutdown_or_startup(equipId: str, last_timex: datetime, last_mrs, note: str = ""):
|
||||||
"""
|
"""
|
||||||
last_mrs 设备运行状态值
|
last_mrs 设备运行状态值
|
||||||
"""
|
"""
|
||||||
|
@ -57,9 +57,11 @@ def shutdown_or_startup(equipId: str, last_timex: datetime, last_mrs):
|
||||||
if last_mrs in [Equipment.STOP, Equipment.FAILURE, Equipment.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]:
|
||||||
new_run = False
|
new_run = False
|
||||||
|
note += f'{equip.number}-{equip.name}停止-'
|
||||||
else:
|
else:
|
||||||
if not Equipment.objects.filter(mgroup=mgroup, indicate_mgroup_running=indicate, running_state=Equipment.RUNING).exists():
|
if not Equipment.objects.filter(mgroup=mgroup, indicate_mgroup_running=indicate, running_state=Equipment.RUNING).exists():
|
||||||
new_run = False
|
new_run = False
|
||||||
|
note += f'{equip.number}-{equip.name}停止-'
|
||||||
elif last_mrs == Equipment.RUNING: # 设备启动信号
|
elif last_mrs == Equipment.RUNING: # 设备启动信号
|
||||||
if indicate in [Equipment.IM_DANDAN, Equipment.IM_DANDOU]:
|
if indicate in [Equipment.IM_DANDAN, Equipment.IM_DANDOU]:
|
||||||
new_run = True
|
new_run = True
|
||||||
|
@ -68,7 +70,7 @@ def shutdown_or_startup(equipId: str, last_timex: datetime, last_mrs):
|
||||||
new_run = True
|
new_run = True
|
||||||
|
|
||||||
if new_run is not None:
|
if new_run is not None:
|
||||||
mgroup_run_change(mgroup, new_run, last_timex)
|
mgroup_run_change(mgroup, new_run, last_timex, note)
|
||||||
|
|
||||||
|
|
||||||
def daoru_equipment(path: str):
|
def daoru_equipment(path: str):
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.12 on 2024-09-09 02:17
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('enm', '0043_xscript'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='enstat',
|
||||||
|
name='imaterial_data_dict',
|
||||||
|
field=models.JSONField(blank=True, default=list, verbose_name='成本物料数据'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -134,6 +134,7 @@ class EnStat(BaseModel):
|
||||||
ccr_consume = models.FloatField("电石渣消耗", default=0, help_text="t")
|
ccr_consume = models.FloatField("电石渣消耗", default=0, help_text="t")
|
||||||
kiln_end_heat = models.FloatField("窑尾余热", default=0, help_text="tce")
|
kiln_end_heat = models.FloatField("窑尾余热", default=0, help_text="tce")
|
||||||
imaterial_data = models.JSONField("成本物料数据", default=list, blank=True)
|
imaterial_data = models.JSONField("成本物料数据", default=list, blank=True)
|
||||||
|
imaterial_data_dict = models.JSONField("成本物料数据", default=dict, blank=True)
|
||||||
other_cost_data = models.JSONField("其他成本数据", default=list, blank=True)
|
other_cost_data = models.JSONField("其他成本数据", default=list, blank=True)
|
||||||
qua_data = models.JSONField("质检数据", default=list, blank=True)
|
qua_data = models.JSONField("质检数据", default=list, blank=True)
|
||||||
equip_elec_data = models.JSONField("设备电耗数据", default=list, blank=True)
|
equip_elec_data = models.JSONField("设备电耗数据", default=list, blank=True)
|
||||||
|
|
|
@ -148,12 +148,21 @@ class EnStatSerializer(CustomModelSerializer):
|
||||||
for key in my_dic_keys:
|
for key in my_dic_keys:
|
||||||
ret_one_val = ret[key]
|
ret_one_val = ret[key]
|
||||||
if isinstance(ret_one_val, float):
|
if isinstance(ret_one_val, float):
|
||||||
ret[key] = "{:.2f}".format(round(ret_one_val, 2))
|
if key in ["en_consume_unit"]:
|
||||||
|
ret[key] = "{:.4f}".format(round(ret_one_val, 4))
|
||||||
|
else:
|
||||||
|
ret[key] = "{:.2f}".format(round(ret_one_val, 2))
|
||||||
qua_data = ret.get("qua_data", {})
|
qua_data = ret.get("qua_data", {})
|
||||||
equip_elec_data = ret.get("equip_elec_data", {})
|
equip_elec_data = ret.get("equip_elec_data", {})
|
||||||
if qua_data:
|
if qua_data:
|
||||||
for item in qua_data:
|
for item in qua_data:
|
||||||
ret[f'{item["material_name"]}_{item["testitem_name"].replace("-", "")}_rate_pass'] = "{:.2f}".format(round(item["rate_pass"], 4))
|
if item.get("rate_pass" )is None:
|
||||||
|
ret[f'{item["material_name"]}_{item["testitem_name"].replace("-", "")}_rate_pass'] = 0
|
||||||
|
else:
|
||||||
|
value = item["rate_pass"]
|
||||||
|
rounded_value = round(value) if value is not None else 0
|
||||||
|
formatted_value = "{:.2f}".format(rounded_value)
|
||||||
|
ret[f'{item["material_name"]}_{item["testitem_name"].replace("-", "")}_rate_pass'] = formatted_value
|
||||||
if equip_elec_data:
|
if equip_elec_data:
|
||||||
for item in equip_elec_data:
|
for item in equip_elec_data:
|
||||||
val = item.get("consume_unit", None)
|
val = item.get("consume_unit", None)
|
||||||
|
|
|
@ -441,6 +441,7 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s,
|
||||||
has_product = True
|
has_product = True
|
||||||
imaterial_cost_unit = 0
|
imaterial_cost_unit = 0
|
||||||
imaterial_data = []
|
imaterial_data = []
|
||||||
|
imaterial_data_dict = {}
|
||||||
for ind, mid in enumerate(input_materials):
|
for ind, mid in enumerate(input_materials):
|
||||||
material = Material.objects.get(id=mid)
|
material = Material.objects.get(id=mid)
|
||||||
if type == "hour_s":
|
if type == "hour_s":
|
||||||
|
@ -504,7 +505,9 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s,
|
||||||
"cost_unit": cost_unit,
|
"cost_unit": cost_unit,
|
||||||
}
|
}
|
||||||
imaterial_data.append(imaterial_item)
|
imaterial_data.append(imaterial_item)
|
||||||
|
imaterial_data_dict.setdefault(material.name, imaterial_item)
|
||||||
enstat.imaterial_data = imaterial_data
|
enstat.imaterial_data = imaterial_data
|
||||||
|
enstat.imaterial_data_dict = imaterial_data_dict
|
||||||
# 其他成本数据
|
# 其他成本数据
|
||||||
other_cost_data = []
|
other_cost_data = []
|
||||||
other_cost_unit = 0
|
other_cost_unit = 0
|
||||||
|
|
|
@ -46,5 +46,5 @@ class FeeSetViewSet(CustomModelViewSet):
|
||||||
queryset = FeeSet.objects.all()
|
queryset = FeeSet.objects.all()
|
||||||
serializer_class = FeeSetSerializer
|
serializer_class = FeeSetSerializer
|
||||||
select_related_fields = ['fee', 'mgroup']
|
select_related_fields = ['fee', 'mgroup']
|
||||||
filterset_fields = ['fee', 'mgroup', 'year', 'month']
|
filterset_fields = ['fee', 'mgroup', 'year', 'month', 'mgroup__cate']
|
||||||
search_fields = ['fee__name', 'mgroup__name']
|
search_fields = ['fee__name', 'mgroup__name']
|
||||||
|
|
|
@ -110,7 +110,7 @@ def daoru_material(path: str):
|
||||||
print(number, type, name, specification, model, unit, '导入成功')
|
print(number, type, name, specification, model, unit, '导入成功')
|
||||||
|
|
||||||
|
|
||||||
def mgroup_run_change(mgroup: Mgroup, new_run: bool, last_timex: datetime):
|
def mgroup_run_change(mgroup: Mgroup, new_run: bool, last_timex: datetime, note: str = ''):
|
||||||
"""
|
"""
|
||||||
调用工段运行变动
|
调用工段运行变动
|
||||||
"""
|
"""
|
||||||
|
@ -128,11 +128,11 @@ def mgroup_run_change(mgroup: Mgroup, new_run: bool, last_timex: datetime):
|
||||||
last_stlog.end_time = last_timex
|
last_stlog.end_time = last_timex
|
||||||
last_stlog.duration_sec = (last_stlog.end_time - last_stlog.start_time).total_seconds()
|
last_stlog.duration_sec = (last_stlog.end_time - last_stlog.start_time).total_seconds()
|
||||||
last_stlog.save()
|
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: # 从开到停
|
elif last_stlog.end_time and new_run is False and last_timex > last_stlog.end_time: # 从开到停
|
||||||
StLog.objects.get_or_create(
|
last_stlog, _ = StLog.objects.get_or_create(
|
||||||
mgroup=mgroup,
|
mgroup=mgroup,
|
||||||
is_shutdown=True,
|
is_shutdown=True,
|
||||||
|
reason = note,
|
||||||
start_time=last_timex,
|
start_time=last_timex,
|
||||||
defaults={
|
defaults={
|
||||||
'title': '停机',
|
'title': '停机',
|
||||||
|
@ -141,9 +141,11 @@ def mgroup_run_change(mgroup: Mgroup, new_run: bool, last_timex: datetime):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
elif new_run is False:
|
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))
|
last_stlog = StLog.objects.create(title="停机", is_shutdown=True, mgroup=mgroup, end_time=None, start_time=last_timex, sflog=get_sflog(mgroup, last_timex), reason = note)
|
||||||
mgroup.is_running = False
|
mgroup.is_running = False
|
||||||
mgroup.save()
|
mgroup.save()
|
||||||
|
if last_stlog:
|
||||||
|
cal_exp_duration_sec(last_stlog.id) # 触发时间分配
|
||||||
|
|
||||||
def bind_routepack(ticket: Ticket, transition, new_ticket_data: dict):
|
def bind_routepack(ticket: Ticket, transition, new_ticket_data: dict):
|
||||||
routepack = RoutePack.objects.get(id=new_ticket_data['t_id'])
|
routepack = RoutePack.objects.get(id=new_ticket_data['t_id'])
|
||||||
|
|
|
@ -56,7 +56,10 @@ class QuaStatUpdateSerializer(CustomModelSerializer):
|
||||||
'required': True, 'allow_null': False}, 'num_ok': {'required': True, 'allow_null': False}}
|
'required': True, 'allow_null': False}, 'num_ok': {'required': True, 'allow_null': False}}
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
attrs['rate_pass'] = attrs['num_ok']/attrs['num_test']
|
if attrs['num_test'] != 0:
|
||||||
|
attrs['rate_pass'] = attrs['num_ok']/attrs['num_test']
|
||||||
|
else:
|
||||||
|
attrs['rate_pass'] = 0
|
||||||
return super().validate(attrs)
|
return super().validate(attrs)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class StLogFilter(filters.FilterSet):
|
||||||
fields = {
|
fields = {
|
||||||
"mgroup": ["exact"],
|
"mgroup": ["exact"],
|
||||||
"mgroup__name": ["exact"],
|
"mgroup__name": ["exact"],
|
||||||
"start_time": ["day", "month", "year"],
|
"start_time": ["day", "month", "year", "gte", "lte"],
|
||||||
"end_time": ["isnull"],
|
"end_time": ["isnull"],
|
||||||
"sflog": ["exact"],
|
"sflog": ["exact"],
|
||||||
"sflogs": ["exact"]
|
"sflogs": ["exact"]
|
||||||
|
|
Loading…
Reference in New Issue