From cc5b521f5dd2da63a9f09817f8f09ff9cf17ca0b Mon Sep 17 00:00:00 2001 From: zty Date: Mon, 30 Sep 2024 16:21:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=85=A4=E7=B2=89=E7=83=AD=E5=80=BC?= =?UTF-8?q?=E6=A0=A1=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/serializers.py | 64 +++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index dca9ef6b..1f54b89a 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -19,6 +19,8 @@ from django.core.cache import cache from django.utils.timezone import localdate from apps.qm.models import NotOkOption from apps.wf.serializers import TicketSimpleSerializer +import logging +mylogger = logging.getLogger("log") class OtherLogSerializer(CustomModelSerializer): class Meta: @@ -57,8 +59,8 @@ class StLogSerializer(CustomModelSerializer): def update(self, instance, validated_data): if instance.is_shutdown: # 停机不可编辑end_time validated_data.pop('end_time', None) - if instance.end_time: - raise ParseError('该异常已结束无需编辑') + # if instance.end_time: + # raise ParseError('该异常已结束无需编辑') with transaction.atomic(): validated_data.pop('mgroup', None) validated_data.pop('start_time', None) @@ -70,7 +72,7 @@ class StLogSerializer(CustomModelSerializer): cal_exp_duration_sec(instance.id) try: sflogexp = SfLogExp.objects.get( - stlog=instance.stlog, sflog=current_sflog) + stlog=instance, sflog=current_sflog) sflogexp.note = current_note sflogexp.save() except SfLogExp.DoesNotExist: @@ -111,36 +113,36 @@ class SfLogSerializer(CustomModelSerializer): } def update(self, instance, validated_data): - with transaction.atomic(): - old_pcoal_heat = instance.pcoal_heat - old_team = instance.team - instance: SfLog = super().update(instance, validated_data) - new_pcoal_heat = instance.pcoal_heat - new_team = instance.team - mgroup: Mgroup = instance.mgroup + old_pcoal_heat = instance.pcoal_heat + old_team = instance.team + instance: SfLog = super().update(instance, validated_data) + new_pcoal_heat = instance.pcoal_heat + new_team = instance.team + mgroup: Mgroup = instance.mgroup - # 更新煤粉热值触发计算 - if instance.mgroup == '回转窑' and instance.shift.name in ['早班', '白班']: - year_s, month_s, day_s = instance.get_ymd - if new_pcoal_heat: # 更新一下缓存 - cache.set(f'pcoal_heat_{year_s}_{month_s}_{day_s}', new_pcoal_heat) - if new_pcoal_heat != old_pcoal_heat: - cal_enstat_when_pcoal_heat_change.delay(year_s, month_s, day_s) + # 更新煤粉热值触发计算 + 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 + if 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: + cal_enstat_when_pcoal_heat_change.delay(year_s, month_s, day_s) - # 更新班组触发计算 - if new_team != old_team: - default_state = 'pending' - if timezone.now() > instance.end_time: - default_state = 'normal' - # 分配班组时创建人员到岗情况 - for item in TeamMember.objects.filter(team=new_team, mgroup=instance.mgroup): - 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}) - if mgroup.need_enm: - from apps.qm.tasks import cal_quastat_sflog - cal_enstat_when_team_change.delay(instance.id) - cal_quastat_sflog.delay(instance.id) - return instance + # 更新班组触发计算 + if new_team != old_team: + default_state = 'pending' + if timezone.now() > instance.end_time: + default_state = 'normal' + # 分配班组时创建人员到岗情况 + for item in TeamMember.objects.filter(team=new_team, mgroup=instance.mgroup): + 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}) + if mgroup.need_enm: + from apps.qm.tasks import cal_quastat_sflog + cal_enstat_when_team_change.delay(instance.id) + cal_quastat_sflog.delay(instance.id) + return instance def to_representation(self, instance): ret = super().to_representation(instance)