fix: enm以team做统计不是shift
This commit is contained in:
parent
6e98ec57ee
commit
e15cc2f9ce
|
@ -38,6 +38,7 @@ class EnStatFilter(filters.FilterSet):
|
|||
"mgroup__belong_dept": ["exact"],
|
||||
"type": ["exact"],
|
||||
"sflog": ["exact"],
|
||||
"team": ["exact"],
|
||||
"day_s": ["exact"],
|
||||
"month_s": ["exact"],
|
||||
"year_s": ["exact"],
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
# Generated by Django 3.2.12 on 2023-07-25 03:12
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mtm', '0005_auto_20230706_1032'),
|
||||
('enm', '0011_auto_20230718_1357'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='enstat',
|
||||
name='shift',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='enstat',
|
||||
name='qua_data',
|
||||
field=models.JSONField(blank=True, default=list, verbose_name='质检数据'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='enstat',
|
||||
name='team',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='mtm.team', verbose_name='关联班组'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='enstat',
|
||||
name='type',
|
||||
field=models.CharField(default='hour', help_text='year_s/month_s/month_st/day_s/sflog/hour_s', max_length=50, verbose_name='统计维度'),
|
||||
),
|
||||
]
|
|
@ -1,7 +1,7 @@
|
|||
from django.db import models
|
||||
from apps.utils.models import BaseModel, CommonBModel, CommonADModel
|
||||
from apps.wpm.models import SfLog
|
||||
from apps.mtm.models import Material, Mgroup, Shift
|
||||
from apps.mtm.models import Material, Mgroup, Team
|
||||
|
||||
|
||||
class Mpoint(CommonBModel):
|
||||
|
@ -54,9 +54,9 @@ class EnStat(BaseModel):
|
|||
"""
|
||||
能源数据统计表
|
||||
"""
|
||||
type = models.CharField('统计维度', max_length=50, default='hour', help_text='year_s/month_s/month_sf/day_s/sflog/hour_s')
|
||||
type = models.CharField('统计维度', max_length=50, default='hour', help_text='year_s/month_s/month_st/day_s/sflog/hour_s')
|
||||
sflog = models.ForeignKey(SfLog, verbose_name='关联值班记录', on_delete=models.CASCADE, null=True, blank=True)
|
||||
shift = models.ForeignKey(Shift, verbose_name='关联班组', on_delete=models.CASCADE, null=True, blank=True)
|
||||
team = models.ForeignKey(Team, verbose_name='关联班组', on_delete=models.CASCADE, null=True, blank=True)
|
||||
mgroup = models.ForeignKey(Mgroup, verbose_name='关联工段', on_delete=models.CASCADE)
|
||||
year = models.PositiveSmallIntegerField('年', null=True, blank=True)
|
||||
month = models.PositiveSmallIntegerField('月', null=True, blank=True)
|
||||
|
@ -69,6 +69,7 @@ class EnStat(BaseModel):
|
|||
elec_consume = models.FloatField('总电耗', null=True, blank=True, help_text='kw·h')
|
||||
imaterial_data = models.JSONField('成本物料数据', default=list, blank=True)
|
||||
other_cost_data = models.JSONField('其他成本数据', default=list, blank=True)
|
||||
qua_data = models.JSONField('质检数据', default=list, blank=True)
|
||||
production_cost_unit = models.FloatField('单位产品成本', null=True, blank=True, help_text='y/t')
|
||||
elec_consume_unit = models.FloatField('单位产品分布电耗', null=True, blank=True, help_text='kw·h/t')
|
||||
celec_consume_unit = models.FloatField('单位产品综合电耗', null=True, blank=True, help_text='kw·h/t')
|
||||
|
|
|
@ -195,7 +195,7 @@ def cal_mpointstat_manual(mpointId: str, sflogId: str, mgroupId: str, year: int,
|
|||
compute_enstat('hour_s', sflogId, mgroupId, year, month, day, hour, year_s, month_s, day_s)
|
||||
compute_enstat('sflog', sflogId, mgroupId, year, month, day, hour, year_s, month_s, day_s)
|
||||
compute_enstat('day_s', sflogId, mgroupId, year, month, day, hour, year_s, month_s, day_s)
|
||||
compute_enstat('month_sf', sflogId, mgroupId, year, month, day, hour, year_s, month_s, day_s)
|
||||
compute_enstat('month_st', sflogId, mgroupId, year, month, day, hour, year_s, month_s, day_s)
|
||||
compute_enstat('month_s', sflogId, mgroupId, year, month, day, hour, year_s, month_s, day_s)
|
||||
compute_enstat('year_s', sflogId, mgroupId, year, month, day, hour, year_s, month_s, day_s)
|
||||
|
||||
|
@ -206,7 +206,7 @@ def compute_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, mont
|
|||
"""
|
||||
mgroup = Mgroup.objects.get(id=mgroupId)
|
||||
sflog = SfLog.objects.get(id=sflogId)
|
||||
shift = sflog.shift
|
||||
team = sflog.team
|
||||
if type == 'hour_s':
|
||||
enstat, _ = EnStat.objects.get_or_create(type="hour_s", mgroup=mgroup, year=year, month=month, day=day, hour=hour,
|
||||
defaults={'type': 'hour_s', 'mgroup': mgroup, 'year_s': year_s, 'month_s': month_s, 'day_s': day_s,
|
||||
|
@ -218,9 +218,9 @@ def compute_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, mont
|
|||
elif type == 'day_s':
|
||||
enstat, _ = EnStat.objects.get_or_create(type="day_s", mgroup=mgroup, year_s=year_s, month_s=month_s, day_s=day_s,
|
||||
defaults={'type': 'day_s', 'mgroup': mgroup, 'year_s': year_s, 'month_s': month_s, 'day_s': day_s, 'total_production': 0, 'elec_consume': 0})
|
||||
elif type == 'month_sf':
|
||||
enstat, _ = EnStat.objects.get_or_create(type="month_sf", mgroup=mgroup, shift=shift, year_s=year_s, month_s=month_s,
|
||||
defaults={'type': 'month_sf', 'mgroup': mgroup, 'year_s': year_s, 'month_s': month_s, 'shift': shift, 'total_production': 0, 'elec_consume': 0})
|
||||
elif type == 'month_st':
|
||||
enstat, _ = EnStat.objects.get_or_create(type="month_st", mgroup=mgroup, team=team, year_s=year_s, month_s=month_s,
|
||||
defaults={'type': 'month_sf', 'mgroup': mgroup, 'year_s': year_s, 'month_s': month_s, 'team': team, 'total_production': 0, 'elec_consume': 0})
|
||||
elif type == 'month_s':
|
||||
enstat, _ = EnStat.objects.get_or_create(type="month_s", mgroup=mgroup, year_s=year_s, month_s=month_s,
|
||||
defaults={'type': 'month_s', 'mgroup': mgroup, 'year_s': year_s, 'month_s': month_s, 'total_production': 0, 'elec_consume': 0})
|
||||
|
@ -242,8 +242,8 @@ def compute_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, mont
|
|||
mps = MpointStat.objects.filter(type='sflog', sflog=sflog, mpoint__material=material)
|
||||
elif type == 'day_s':
|
||||
mps = MpointStat.objects.filter(type='day_s', mgroup=mgroup, year_s=year_s, month_s=month_s, day_s=day_s, mpoint__material=material)
|
||||
elif type == 'month_sf':
|
||||
mps = MpointStat.objects.filter(type='sflog', mgroup=mgroup, sflog__shift=shift, year_s=year_s, month_s=month_s, mpoint__material=material)
|
||||
elif type == 'month_st':
|
||||
mps = MpointStat.objects.filter(type='sflog', mgroup=mgroup, sflog__team=team, year_s=year_s, month_s=month_s, mpoint__material=material)
|
||||
elif type == 'month_s':
|
||||
mps = MpointStat.objects.filter(type='month_s', mgroup=mgroup, year_s=year_s, month_s=month_s, mpoint__material=material)
|
||||
elif type == 'year_s':
|
||||
|
|
Loading…
Reference in New Issue