diff --git a/apps/enm/views.py b/apps/enm/views.py index 9be28b55..c7fa715d 100644 --- a/apps/enm/views.py +++ b/apps/enm/views.py @@ -1,4 +1,5 @@ from django.conf import settings +from rest_framework.exceptions import ParseError from apps.enm.models import Mpoint, MpointStat, EnStat, EnStat2, MpLogx, Xscript from apps.utils.viewsets import CustomModelViewSet, CustomGenericViewSet from apps.utils.mixins import BulkCreateModelMixin, BulkDestroyModelMixin, CustomListModelMixin, BulkUpdateModelMixin @@ -186,9 +187,21 @@ class MpointStatViewSet(BulkCreateModelMixin, BulkDestroyModelMixin, CustomListM 修正测点统计记录及统计值 """ + instance_id = kwargs.get("pk") + if not instance_id: + return Response({"detail": "ID not provided in the URL"}, status=400) instance: MpointStat = self.get_object() sr = MpointStatCorrectSerializer(data=request.data) sr.is_valid(raise_exception=True) + last_record = MpointStat.objects.filter(mpoint=instance.mpoint, + type=instance.type, + mgroup=instance.mgroup, + year_s=instance.year_s, + month_s=instance.month_s, + ).order_by(instance.type).values("id").last() + last_id = last_record["id"] if last_record else None + if str(last_id) == str(instance_id): + raise ParseError("不能修正当日或当月数据") vdata = sr.validated_data val_correct = vdata["val_correct"] instance.val_correct = val_correct