From f5fd9558ba9ea044bd8286d6826996da6be17032 Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 24 Dec 2024 15:49:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=20task=20bill=5Fdate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/tasks.py | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index 1bfa0f90..5fda51ab 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -132,6 +132,9 @@ def cal_mpointstats_duration(start_time: str, end_time: str, m_code_list=[], cal @shared_task(base=CustomTask) def correct_bill_date(): + """ + 定时更新bill_date时间为前一天 + """ now_time = datetime.datetime.now() update_time = now_time - datetime.timedelta(hours=24) bill_date = make_aware(update_time) @@ -620,16 +623,16 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s, # 综合电耗 if enstat.type in ["hour_s", "day_s", "year_s", "month_s"]: pre_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="原料磨").first() - pre_enstat2 = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="煤磨").first() + # pre_enstat2 = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="煤磨").first() if pre_enstat: - enstat.celec_consume_unit = enstat.elec_consume_unit + get_sysconfig('enm.enm_lhxs') * pre_enstat.elec_consume_unit - if pre_enstat2: - try: - pre_enstat2.production_elec_consume_unit = pre_enstat2.elec_consume / enstat.total_production - except ZeroDivisionError: - pre_enstat2.production_elec_consume_unit = 0 - pre_enstat2.save(update_fields=["production_elec_consume_unit"]) - enstat.celec_consume_unit += pre_enstat2.production_elec_consume_unit + enstat.celec_consume_unit = (enstat.elec_consume + pre_enstat.elec_consume)/enstat.total_production + # if pre_enstat2: + # try: + # pre_enstat2.production_elec_consume_unit = pre_enstat2.elec_consume / enstat.total_production + # except ZeroDivisionError: + # pre_enstat2.production_elec_consume_unit = 0 + # pre_enstat2.save(update_fields=["production_elec_consume_unit"]) + # enstat.celec_consume_unit += pre_enstat2.production_elec_consume_unit enstat.save() # 算总煤耗 if "pcoal" in this_cal_attrs: @@ -648,6 +651,8 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s, if enstat.pcoal_coal_consume is None: enstat.pcoal_coal_consume = 0 + # 加柴油消耗量 todo + # 算单位产品标煤耗 try: enstat.coal_consume_unit = enstat.pcoal_coal_consume * 1000 / enstat.total_production @@ -657,12 +662,17 @@ def cal_enstat(type, sflogId, mgroupId, year, month, day, hour, year_s, month_s, # 综合能耗 enstat.cen_consume_unit = enstat.coal_consume_unit + 0.1229 * enstat.elec_consume_unit enstat.save() - elif enstat.mgroup.name == "水泥磨" and enstat.type not in ["month_st", "sflog"] and "pcoal" in this_cal_attrs: - pre_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="回转窑").first() - if pre_enstat: + elif enstat.mgroup.name == "水泥包装" and enstat.type not in ["month_st", "sflog"] and "pcoal" in this_cal_attrs: + hzy_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="回转窑").first() + snm_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="水泥磨").first() + if snm_enstat: # 综合能耗 - enstat.cen_consume_unit = enstat.elec_consume_unit * 0.1229 + 0.7 * pre_enstat.cen_consume_unit - enstat.save() + + # 熟料配比 用 入磨熟料/水泥磨产量 todo + + snm_enstat.cen_consume_unit = ((snm_enstat.elec_consume + enstat.elec_consume)/snm_enstat.total_production) * 0.1229 + 0.7 * hzy_enstat.cen_consume_unit + snm_enstat.save() + elif enstat.mgroup.name == '余热发电': pre_enstat = EnStat.objects.filter(type=enstat.type, year_s=enstat.year_s, month_s=enstat.month_s, day_s=enstat.day_s, hour=enstat.hour, mgroup__name="回转窑").first() if pre_enstat: