feat: 煤粉热值校正

This commit is contained in:
zty 2024-09-30 16:21:44 +08:00
parent 9c6e8f5992
commit cc5b521f5d
1 changed files with 33 additions and 31 deletions

View File

@ -19,6 +19,8 @@ from django.core.cache import cache
from django.utils.timezone import localdate from django.utils.timezone import localdate
from apps.qm.models import NotOkOption from apps.qm.models import NotOkOption
from apps.wf.serializers import TicketSimpleSerializer from apps.wf.serializers import TicketSimpleSerializer
import logging
mylogger = logging.getLogger("log")
class OtherLogSerializer(CustomModelSerializer): class OtherLogSerializer(CustomModelSerializer):
class Meta: class Meta:
@ -57,8 +59,8 @@ class StLogSerializer(CustomModelSerializer):
def update(self, instance, validated_data): def update(self, instance, validated_data):
if instance.is_shutdown: # 停机不可编辑end_time if instance.is_shutdown: # 停机不可编辑end_time
validated_data.pop('end_time', None) validated_data.pop('end_time', None)
if instance.end_time: # if instance.end_time:
raise ParseError('该异常已结束无需编辑') # raise ParseError('该异常已结束无需编辑')
with transaction.atomic(): with transaction.atomic():
validated_data.pop('mgroup', None) validated_data.pop('mgroup', None)
validated_data.pop('start_time', None) validated_data.pop('start_time', None)
@ -70,7 +72,7 @@ class StLogSerializer(CustomModelSerializer):
cal_exp_duration_sec(instance.id) cal_exp_duration_sec(instance.id)
try: try:
sflogexp = SfLogExp.objects.get( sflogexp = SfLogExp.objects.get(
stlog=instance.stlog, sflog=current_sflog) stlog=instance, sflog=current_sflog)
sflogexp.note = current_note sflogexp.note = current_note
sflogexp.save() sflogexp.save()
except SfLogExp.DoesNotExist: except SfLogExp.DoesNotExist:
@ -111,7 +113,6 @@ class SfLogSerializer(CustomModelSerializer):
} }
def update(self, instance, validated_data): def update(self, instance, validated_data):
with transaction.atomic():
old_pcoal_heat = instance.pcoal_heat old_pcoal_heat = instance.pcoal_heat
old_team = instance.team old_team = instance.team
instance: SfLog = super().update(instance, validated_data) instance: SfLog = super().update(instance, validated_data)
@ -120,10 +121,11 @@ class SfLogSerializer(CustomModelSerializer):
mgroup: Mgroup = instance.mgroup mgroup: Mgroup = instance.mgroup
# 更新煤粉热值触发计算 # 更新煤粉热值触发计算
if instance.mgroup == '回转窑' and instance.shift.name in ['早班', '白班']: if instance.mgroup.name == '回转窑' and instance.shift.name in ['早班', '白班']:
mylogger.info(f'回转窑白班/早班{instance.get_ymd}更新{new_pcoal_heat}-{old_pcoal_heat}')
year_s, month_s, day_s = instance.get_ymd year_s, month_s, day_s = instance.get_ymd
if new_pcoal_heat: # 更新一下缓存 if new_pcoal_heat: # 更新一下缓存
cache.set(f'pcoal_heat_{year_s}_{month_s}_{day_s}', new_pcoal_heat) cache.set(f'pcoal_heat_{year_s}_{month_s}_{day_s}', new_pcoal_heat, timeout=60 * 60 * 48)
if new_pcoal_heat != old_pcoal_heat: if new_pcoal_heat != old_pcoal_heat:
cal_enstat_when_pcoal_heat_change.delay(year_s, month_s, day_s) cal_enstat_when_pcoal_heat_change.delay(year_s, month_s, day_s)