feat: 可以不用间隔运行get_total_hour_now
This commit is contained in:
parent
40ecd52fee
commit
67d04a9a41
|
@ -435,29 +435,31 @@ 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()
|
||||
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).aggregate(
|
||||
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(
|
||||
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).aggregate(
|
||||
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(
|
||||
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).aggregate(
|
||||
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')
|
||||
)
|
||||
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).aggregate(
|
||||
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')
|
||||
)
|
||||
|
|
|
@ -20,6 +20,7 @@ def make_sflogs(mgroup: Mgroup, start_date: datetime.date, end_date: datetime.da
|
|||
"shift": shift,
|
||||
"start_time": start_time,
|
||||
"end_time": end_time,
|
||||
"total_hour_now": 12
|
||||
})
|
||||
current_date = current_date + datetime.timedelta(days=1)
|
||||
|
||||
|
|
|
@ -91,7 +91,11 @@ def cal_shut_hour(stlogId: str):
|
|||
if ret.get('sum', 0):
|
||||
sflog.shut_hour = ret['sum']
|
||||
sflog.save()
|
||||
cal_enstat('sflog')
|
||||
# 更新sflog总时长
|
||||
if localtime(sflog.end_time) > now:
|
||||
get_total_hour_now(sflog.id)
|
||||
if stlogId:
|
||||
cal_enstat('sflog', sflog.id, sflog.mgroup.id, None, None, None, None, None, None, None, cascade=True, cal_attrs=['run_hour'])
|
||||
|
||||
|
||||
@shared_task(base=CustomTask)
|
||||
|
|
Loading…
Reference in New Issue