feat: em/filter apps 修改设备字段信息

This commit is contained in:
zty 2024-11-25 18:14:12 +08:00
parent 1010a6b86f
commit 9db524dfdb
5 changed files with 40 additions and 11 deletions

View File

@ -2,6 +2,7 @@ from django_filters import rest_framework as filters
from apps.em.models import Equipment from apps.em.models import Equipment
from datetime import datetime, timedelta from datetime import datetime, timedelta
from apps.utils.filters import MyJsonListFilter from apps.utils.filters import MyJsonListFilter
from django.db.models import F
class EquipFilterSet(filters.FilterSet): class EquipFilterSet(filters.FilterSet):
@ -23,17 +24,17 @@ class EquipFilterSet(filters.FilterSet):
"cate__code": ['exact', 'in', 'contains'], "cate__code": ['exact', 'in', 'contains'],
"cate__is_for_safe": ['exact'], "cate__is_for_safe": ['exact'],
"cate__is_for_enp": ['exact'], "cate__is_for_enp": ['exact'],
"cate__is_car": ['exact'], "cate__is_car": ['exact']
"is_deleted": ['exact']
} }
def filter_tag(self, queryset, name, value): def filter_tag(self, queryset, name, value):
now = datetime.now() now = datetime.now()
day7_after = now + timedelta(days=7)
if value == 'near_check': if value == 'near_check':
queryset = queryset.filter( queryset = queryset.filter(
next_check_date__lt=datetime.date(day7_after), next_check_date__gte=datetime.date(now)) next_check_date__lt=datetime.date(now + timedelta(days=F('remind_day_number'))), next_check_date__gte=datetime.date(now))
elif value == 'out_check': elif value == 'out_check':
queryset = queryset.filter( queryset = queryset.filter(
next_check_date__lte=datetime.date(now)) next_check_date__lte=datetime.date(now))
return queryset return queryset

View File

@ -0,0 +1,23 @@
# Generated by Django 3.2.12 on 2024-11-25 10:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('em', '0018_alter_equipment_mgroup'),
]
operations = [
migrations.AddField(
model_name='equipment',
name='importance',
field=models.PositiveSmallIntegerField(choices=[(10, 'A'), (20, 'B'), (30, 'C')], default=10, verbose_name='重要程度'),
),
migrations.AlterField(
model_name='equipment',
name='power_kw',
field=models.FloatField(blank=True, null=True, verbose_name='功率'),
),
]

View File

@ -80,6 +80,7 @@ class Equipment(CommonBModel):
model = models.CharField("规格型号", max_length=60, default="", blank=True) model = models.CharField("规格型号", max_length=60, default="", blank=True)
factory = models.CharField("生产厂", max_length=50, default="", blank=True) factory = models.CharField("生产厂", max_length=50, default="", blank=True)
production_date = models.DateField("生产日期", null=True, blank=True) production_date = models.DateField("生产日期", null=True, blank=True)
importance = models.PositiveSmallIntegerField("重要程度", default=10, choices=((10, "A"), (20, "B"), (30, "C")))
buy_date = models.DateField("购置日期", null=True, blank=True) buy_date = models.DateField("购置日期", null=True, blank=True)
state = models.PositiveIntegerField("设备状态", choices=state_choices, default=EQUIP_STATE_OK) state = models.PositiveIntegerField("设备状态", choices=state_choices, default=EQUIP_STATE_OK)
parameter = models.TextField("技术参数", default="", blank=True) parameter = models.TextField("技术参数", default="", blank=True)
@ -102,7 +103,7 @@ class Equipment(CommonBModel):
cycle = models.PositiveSmallIntegerField("校准或检定周期(月)", null=True, blank=True) cycle = models.PositiveSmallIntegerField("校准或检定周期(月)", null=True, blank=True)
check_date = models.DateField("最近校准检查日期", blank=True, null=True) check_date = models.DateField("最近校准检查日期", blank=True, null=True)
next_check_date = models.DateField("预计下次校准检查日期", blank=True, null=True) next_check_date = models.DateField("预计下次校准检查日期", blank=True, null=True)
power_kw = models.PositiveSmallIntegerField("功率", null=True, blank=True) power_kw = models.FloatField("功率", null=True, blank=True)
coordinates = models.JSONField("坐标", default=dict, blank=True) coordinates = models.JSONField("坐标", default=dict, blank=True)

View File

@ -848,7 +848,11 @@ def cal_enstat_pcoal_change(enstat: EnStat, new_pcoal_heat):
next_enstat.save(update_fields=["cen_consume_unit"]) next_enstat.save(update_fields=["cen_consume_unit"])
enm_alarms_list = [["回转窑", "celec_consume_unit", "单位产品综合电耗"], ["回转窑", "coal_consume_unit", "单位产品标煤耗"], ["水泥磨", "elec_consume_unit", "单位产品分布电耗"]] enm_alarms_list = [
["回转窑", "celec_consume_unit", "单位产品综合电耗"],
["回转窑", "coal_consume_unit", "单位产品标煤耗"],
["水泥磨", "elec_consume_unit", "单位产品分布电耗"]
]
@shared_task(base=CustomTask) @shared_task(base=CustomTask)
@ -869,6 +873,7 @@ def enm_alarm(year_s: int, month_s: int, day_s: int):
if enstat: if enstat:
mgroup_name = item[0] mgroup_name = item[0]
goal_cate_str = item[1] goal_cate_str = item[1]
goal_cate_str_chin = item[2]
real_val = getattr(enstat, goal_cate_str, None) real_val = getattr(enstat, goal_cate_str, None)
goal = Goal.objects.filter(goal_cate__code=goal_cate_str, year=year_s, mgroup=mgroup).first() goal = Goal.objects.filter(goal_cate__code=goal_cate_str, year=year_s, mgroup=mgroup).first()
if goal: if goal:
@ -882,6 +887,7 @@ def enm_alarm(year_s: int, month_s: int, day_s: int):
"mgroup": mgroup.id, "mgroup": mgroup.id,
"mgroup_name": mgroup.name, "mgroup_name": mgroup.name,
"type": f"{goal_cate_str}.exceed", "type": f"{goal_cate_str}.exceed",
"type_chin": f"{goal_cate_str_chin}-超过设定目标值",
"year_s": year_s, "year_s": year_s,
"month_s": month_s, "month_s": month_s,
"day_s": day_s, "day_s": day_s,

View File

@ -41,10 +41,8 @@ class SfLog(CommonADModel):
""" """
返回值班记录所属年月日 返回值班记录所属年月日
""" """
end_time_local = localtime(self.end_time) start_time_local = localtime(self.start_time)
if end_time_local.hour == 0 and end_time_local.minute == 0 and end_time_local.second == 0: # 如果结束时间为00:00:00 return start_time_local.year, start_time_local.month, start_time_local.day
end_time_local = localtime(self.start_time)
return end_time_local.year, end_time_local.month, end_time_local.day
class StLog(CommonADModel): class StLog(CommonADModel):