From 4254e226d37e1cd61babaed1819aa628099f59df Mon Sep 17 00:00:00 2001 From: zty Date: Tue, 21 Jan 2025 12:45:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20enm/view=20=E4=BF=AE=E6=94=B9correct=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=8D=E8=83=BD=E6=A0=A1=E6=AD=A3=E5=BD=93?= =?UTF-8?q?=E6=97=A5=E6=88=96=E5=BD=93=E6=9C=88=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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