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,36 +113,36 @@ 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) 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 instance.mgroup == '回转窑' and instance.shift.name in ['早班', '白班']: if instance.mgroup.name == '回转窑' and instance.shift.name in ['早班', '白班']:
year_s, month_s, day_s = instance.get_ymd mylogger.info(f'回转窑白班/早班{instance.get_ymd}更新{new_pcoal_heat}-{old_pcoal_heat}')
if new_pcoal_heat: # 更新一下缓存 year_s, month_s, day_s = instance.get_ymd
cache.set(f'pcoal_heat_{year_s}_{month_s}_{day_s}', new_pcoal_heat) if new_pcoal_heat: # 更新一下缓存
if new_pcoal_heat != old_pcoal_heat: cache.set(f'pcoal_heat_{year_s}_{month_s}_{day_s}', new_pcoal_heat, timeout=60 * 60 * 48)
cal_enstat_when_pcoal_heat_change.delay(year_s, month_s, day_s) if new_pcoal_heat != old_pcoal_heat:
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:
default_state = 'normal' default_state = 'normal'
# 分配班组时创建人员到岗情况 # 分配班组时创建人员到岗情况
for item in TeamMember.objects.filter(team=new_team, mgroup=instance.mgroup): for item in TeamMember.objects.filter(team=new_team, mgroup=instance.mgroup):
AttLog.objects.get_or_create(sflog=instance, user=item.user, defaults={ AttLog.objects.get_or_create(sflog=instance, user=item.user, defaults={
'sflog': instance, 'user': item.user, 'post': item.post, 'state': default_state, 'create_by': self.context['request'].user}) 'sflog': instance, 'user': item.user, 'post': item.post, 'state': default_state, 'create_by': self.context['request'].user})
if mgroup.need_enm: if mgroup.need_enm:
from apps.qm.tasks import cal_quastat_sflog from apps.qm.tasks import cal_quastat_sflog
cal_enstat_when_team_change.delay(instance.id) cal_enstat_when_team_change.delay(instance.id)
cal_quastat_sflog.delay(instance.id) cal_quastat_sflog.delay(instance.id)
return instance return instance
def to_representation(self, instance): def to_representation(self, instance):
ret = super().to_representation(instance) ret = super().to_representation(instance)