fix: get_total_hour_now_and_shut_hour查询条件用work_date替换

This commit is contained in:
caoqianming 2024-05-08 15:58:08 +08:00
parent 30974d90b0
commit 757c3f4ad8
1 changed files with 4 additions and 5 deletions

View File

@ -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