feat: 更新煤粉热值触发计算的bug

This commit is contained in:
caoqianming 2024-05-16 16:26:33 +08:00
parent e81cfbe10d
commit 5093eb7b29
3 changed files with 18 additions and 14 deletions

View File

@ -14,6 +14,7 @@ from apps.mtm.models import Mgroup, TeamMember, Shift, Material
from apps.mtm.serializers import MaterialSimpleSerializer from apps.mtm.serializers import MaterialSimpleSerializer
from django.db import transaction from django.db import transaction
from django.utils import timezone from django.utils import timezone
from django.core.cache import cache
class OtherLogSerializer(CustomModelSerializer): class OtherLogSerializer(CustomModelSerializer):
@ -114,8 +115,16 @@ class SfLogSerializer(CustomModelSerializer):
new_pcoal_heat = instance.pcoal_heat new_pcoal_heat = instance.pcoal_heat
new_team = instance.team new_team = instance.team
mgroup: Mgroup = instance.mgroup mgroup: Mgroup = instance.mgroup
# 更新煤粉热值触发计算
if new_pcoal_heat: # 更新一下缓存
year_s, month_s, day_s = instance.get_ymd
cache.set(f'pgoal_val_{year_s}_{month_s}_{day_s}', new_pcoal_heat)
if new_pcoal_heat != old_pcoal_heat and mgroup.need_enm: if new_pcoal_heat != old_pcoal_heat and mgroup.need_enm:
cal_enstat_when_pcoal_heat_change.delay(instance.id) year_s, month_s, day_s = instance.get_ymd
cal_enstat_when_pcoal_heat_change.delay(year_s, month_s, day_s)
# 更新班组触发计算
if new_team != old_team: if new_team != old_team:
default_state = 'pending' default_state = 'pending'
if timezone.now() > instance.end_time: if timezone.now() > instance.end_time:

View File

@ -63,20 +63,20 @@ def get_pcoal_heat(year_s: int, month_s: int, day_s: int):
只有回转窑需要录入煤粉热值 只有回转窑需要录入煤粉热值
""" """
key = f'pgoal_val_{year_s}_{month_s}_{day_s}' key = f'pgoal_val_{year_s}_{month_s}_{day_s}'
pcoal_heat = cache.get(key, None) pcoal_heat = cache.get(key)
if pcoal_heat is not None: if pcoal_heat:
return pcoal_heat return pcoal_heat
else: else:
try: try:
qs = SfLog.objects.get(work_date__year=year_s, work_date__month=month_s, work_date__day=day_s, qs = SfLog.objects.get(work_date__year=year_s, work_date__month=month_s, work_date__day=day_s,
mgroup__name='回转窑', shift__name__in=['白班', '早班']) # hardcode mgroup__name='回转窑', shift__name__in=['白班', '早班']) # hardcode
if qs.pcoal_heat is None: if qs.pcoal_heat is None:
qs.pcoal_heat = 0 qs.pcoal_heat = 6000
qs.save() qs.save(update_fields=['pcoal_heat'])
cache.set(f'pgoal_val_{year_s}_{month_s}_{day_s}', qs.pcoal_heat) cache.set(f'pgoal_val_{year_s}_{month_s}_{day_s}', qs.pcoal_heat)
return qs.pcoal_heat return qs.pcoal_heat
except Exception: except Exception:
return 0 return 6000
def do_out(mio: MIO): def do_out(mio: MIO):

View File

@ -2,10 +2,6 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
from apps.utils.tasks import CustomTask from apps.utils.tasks import CustomTask
from celery import shared_task from celery import shared_task
from apps.utils.sql import DbConnection
from server.settings import get_sysconfig
from django.core.cache import cache
from apps.wpm.models import SfLog
from apps.mtm.models import Mgroup from apps.mtm.models import Mgroup
import datetime import datetime
from django.db.models import Sum from django.db.models import Sum
@ -13,6 +9,7 @@ from apps.wpm.services import make_sflogs
from apps.wpm.models import SfLog, StLog, SfLogExp from apps.wpm.models import SfLog, StLog, SfLogExp
from django.utils import timezone from django.utils import timezone
from django.db.models import F from django.db.models import F
from apps.wpm.services import get_pcoal_heat
@shared_task(base=CustomTask) @shared_task(base=CustomTask)
@ -110,13 +107,11 @@ def cal_exp_duration_sec(stlogId: str='', all=False):
@shared_task(base=CustomTask) @shared_task(base=CustomTask)
def cal_enstat_when_pcoal_heat_change(sflogId): def cal_enstat_when_pcoal_heat_change(year_s, month_s, day_s):
from apps.enm.models import EnStat from apps.enm.models import EnStat
from apps.enm.tasks import cal_enstat_pcoal_change, cal_enstat2 from apps.enm.tasks import cal_enstat_pcoal_change, cal_enstat2
sflog = SfLog.objects.get(id=sflogId)
pcoal_heat = sflog.pcoal_heat pcoal_heat = get_pcoal_heat(year_s, month_s, day_s)
year_s, month_s, day_s = sflog.get_ymd
# 只会影响到回转窑及水泥磨数据 # 只会影响到回转窑及水泥磨数据
enstats = EnStat.objects.filter(mgroup__name='回转窑', year_s=year_s, enstats = EnStat.objects.filter(mgroup__name='回转窑', year_s=year_s,
month_s=month_s, day_s=day_s, type__in=['hour_s', 'sflog', 'day_s']) month_s=month_s, day_s=day_s, type__in=['hour_s', 'sflog', 'day_s'])