feat: enstat2 增加水耗和压缩空气统计
This commit is contained in:
parent
ad9027d888
commit
b31d3937f8
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.2.12 on 2023-08-18 09:21
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('enm', '0018_remove_mpointstat_team'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='enstat2',
|
||||
name='cair_consume',
|
||||
field=models.FloatField(default=0, help_text='m3', verbose_name='压缩空气'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='enstat2',
|
||||
name='water_consume',
|
||||
field=models.FloatField(default=0, help_text='t', verbose_name='水耗'),
|
||||
),
|
||||
]
|
|
@ -103,6 +103,8 @@ class EnStat2(BaseModel):
|
|||
industry_total_val = models.FloatField('工业总产值', default=0, help_text='万元')
|
||||
industry_add_val = models.FloatField('工业增加值', default=0, help_text='万元')
|
||||
elec_consume = models.FloatField('总电耗', default=0, help_text='kw·h')
|
||||
water_consume = models.FloatField('水耗', default=0, help_text='t')
|
||||
cair_consume = models.FloatField('压缩空气', default=0, help_text='m3')
|
||||
elec_coal_consume = models.FloatField('电量折标煤', default=0, help_text='tce')
|
||||
pcoal_consume = models.FloatField('煤粉消耗', default=0, help_text='t')
|
||||
pcoal_coal_consume = models.FloatField('煤粉折标煤', default=0, help_text='tce')
|
||||
|
|
|
@ -495,11 +495,14 @@ def cal_enstat2(year_s: int, month_s: int):
|
|||
|
||||
# 全厂电量
|
||||
enstat_qs = EnStat.objects.filter(type='month_s', year_s=year_s, month_s=month_s)
|
||||
res_elec_pcoal = enstat_qs.aggregate(sum1=Sum('elec_consume'), sum2=Sum('elec_coal_consume'), sum3=Sum('pcoal_consume'), sum4=Sum('pcoal_coal_consume'))
|
||||
res_elec_pcoal = enstat_qs.aggregate(sum1=Sum('elec_consume'), sum2=Sum('elec_coal_consume'), sum3=Sum('pcoal_consume'), sum4=Sum('pcoal_coal_consume'),
|
||||
sum5=Sum('water_consume'), sum6=Sum('cair_consume'))
|
||||
enstat2.elec_consume = res_elec_pcoal['sum1'] if res_elec_pcoal['sum1'] else 0
|
||||
enstat2.elec_coal_consume = enstat2.elec_consume*0.1229/1000
|
||||
enstat2.pcoal_consume = res_elec_pcoal['sum3'] if res_elec_pcoal['sum3'] else 0
|
||||
enstat2.pcoal_coal_consume = res_elec_pcoal['sum4'] if res_elec_pcoal['sum4'] else 0
|
||||
enstat2.water_consume = res_elec_pcoal['sum5'] if res_elec_pcoal['sum5'] else 0
|
||||
enstat2.cair_consume = res_elec_pcoal['sum6'] if res_elec_pcoal['sum6'] else 0
|
||||
enstat2.en_consume = enstat2.pcoal_coal_consume + enstat2.elec_coal_consume
|
||||
try:
|
||||
enstat2.en_consume_unit = enstat2.en_consume/enstat2.industry_total_val
|
||||
|
|
|
@ -70,7 +70,6 @@ class EnStatViewSet(ListModelMixin, CustomGenericViewSet):
|
|||
ordering = ['mgroup__sort', 'year_s', 'month_s', 'day_s', 'hour']
|
||||
|
||||
def handle_data(self, data):
|
||||
print(len(data))
|
||||
for ind, val in enumerate(data):
|
||||
# imaterial_data = i['imaterial_data']
|
||||
# other_cost_data = i['other_cost_data']
|
||||
|
|
|
@ -22,6 +22,7 @@ def cal_enstat_when_priceset_change(pricesetId):
|
|||
mgroups = Mgroup.objects.filter(input_materials__contains=material.id)
|
||||
enstats = EnStat.objects.filter(mgroup__in=mgroups)
|
||||
for enstat in enstats:
|
||||
enstat = EnStat.objects.select_for_update().get(id=enstat.id) # 加锁一下
|
||||
old_cost_unit = 0
|
||||
new_cost_unit = 0
|
||||
imaterial_data = enstat.imaterial_data
|
||||
|
@ -57,6 +58,7 @@ def cal_enstat_when_feeset_change(feesetId):
|
|||
# 受影响的工段
|
||||
enstats = EnStat.objects.filter(mgroup=mgroup)
|
||||
for enstat in enstats:
|
||||
enstat = EnStat.objects.select_for_update().get(id=enstat.id) # 加锁一下
|
||||
old_cost_unit = 0
|
||||
new_cost_unit = 0
|
||||
other_cost_data = enstat.other_cost_data
|
||||
|
|
Loading…
Reference in New Issue