From 757c3f4ad803c3cb0e57b6b3cca8635df3f7daec Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 8 May 2024 15:58:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20get=5Ftotal=5Fhour=5Fnow=5Fand=5Fshut=5F?= =?UTF-8?q?hour=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6=E7=94=A8work=5Fdate?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/tasks.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/enm/tasks.py b/apps/enm/tasks.py index b3cc3886..c1a480eb 100644 --- a/apps/enm/tasks.py +++ b/apps/enm/tasks.py @@ -526,25 +526,24 @@ def get_total_hour_now_and_shut_hour(enstat: EnStat): # shut_hour = 1 - run_hour # shut_hour = shut_hour + # return 1, 0 - now = datetime.datetime.now().replace(tzinfo=tz.gettz(settings.TIME_ZONE)) if enstat.type == "sflog": sflog = enstat.sflog return sflog.total_hour_now, sflog.shut_hour elif enstat.type == "day_s": - res = SfLog.objects.filter(end_time__year=enstat.year_s, end_time__month=enstat.month_s, end_time__day=enstat.day_s, mgroup=enstat.mgroup, end_time__lt=now).aggregate( + res = SfLog.objects.filter(work_date__year=enstat.year_s, work_date__month=enstat.month_s, work_date__day=enstat.day_s, mgroup=enstat.mgroup).aggregate( sum1=Sum("total_hour_now"), sum2=Sum("shut_hour") ) return res["sum1"] if res["sum1"] else 0, res["sum2"] if res["sum2"] else 0 elif enstat.type == "month_st": - res = SfLog.objects.filter(end_time__year=enstat.year_s, end_time__month=enstat.month_s, mgroup=enstat.mgroup, team=enstat.team, end_time__lt=now).aggregate( + res = SfLog.objects.filter(work_date__year=enstat.year_s, work_date__month=enstat.month_s, mgroup=enstat.mgroup, team=enstat.team).aggregate( sum1=Sum("total_hour_now"), sum2=Sum("shut_hour") ) return res["sum1"] if res["sum1"] else 0, res["sum2"] if res["sum2"] else 0 elif enstat.type == "month_s": - res = SfLog.objects.filter(end_time__year=enstat.year_s, end_time__month=enstat.month_s, mgroup=enstat.mgroup, end_time__lt=now).aggregate(sum1=Sum("total_hour_now"), sum2=Sum("shut_hour")) + res = SfLog.objects.filter(work_date__year=enstat.year_s, work_date__month=enstat.month_s, mgroup=enstat.mgroup).aggregate(sum1=Sum("total_hour_now"), sum2=Sum("shut_hour")) return res["sum1"] if res["sum1"] else 0, res["sum2"] if res["sum2"] else 0 elif enstat.type == "year_s": - res = SfLog.objects.filter(end_time__year=enstat.year_s, mgroup=enstat.mgroup, end_time__lt=now).aggregate(sum1=Sum("total_hour_now"), sum2=Sum("shut_hour")) + res = SfLog.objects.filter(work_date__year=enstat.year_s, mgroup=enstat.mgroup).aggregate(sum1=Sum("total_hour_now"), sum2=Sum("shut_hour")) return res["sum1"] if res["sum1"] else 0, res["sum2"] if res["sum2"] else 0