47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
from apps.wpm.models import SfLog, SfLogExp
|
|
from apps.mtm.models import Shift, Mgroup
|
|
import datetime
|
|
from django.utils.timezone import localtime
|
|
from django.db.models import Sum
|
|
from django.core.cache import cache
|
|
|
|
def make_sflogs(mgroup: Mgroup, start_date: datetime.date, end_date: datetime.date):
|
|
for shift in Shift.objects.all():
|
|
start_time_o = shift.start_time_o
|
|
end_time_o = shift.end_time_o
|
|
current_date = start_date
|
|
while current_date <= end_date:
|
|
start_time = datetime.datetime.combine(current_date, start_time_o)
|
|
end_time = datetime.datetime.combine(current_date, end_time_o)
|
|
if start_time > end_time:
|
|
start_time -= datetime.timedelta(days=1)
|
|
SfLog.objects.get_or_create(mgroup=mgroup, shift=shift, start_time=start_time, defaults={
|
|
"mgroup": mgroup,
|
|
"shift": shift,
|
|
"start_time": start_time,
|
|
"end_time": end_time,
|
|
"total_hour_now": 12
|
|
})
|
|
current_date = current_date + datetime.timedelta(days=1)
|
|
|
|
def get_pcoal_heat(year_s: int, month_s: int, day_s: int):
|
|
"""
|
|
获取煤粉热值
|
|
只有回转窑需要录入煤粉热值
|
|
"""
|
|
key = f'pgoal_val_{year_s}_{month_s}_{day_s}'
|
|
pcoal_heat = cache.get(key, None)
|
|
if pcoal_heat is not None:
|
|
return pcoal_heat
|
|
else:
|
|
try:
|
|
qs = SfLog.objects.get(end_time__year=year_s, end_time__month=month_s, end_time__day=day_s,
|
|
mgroup__name='回转窑', shift__name='夜班')
|
|
if qs.pcoal_heat is None:
|
|
qs.pcoal_heat = 0
|
|
qs.save()
|
|
cache.set(f'pgoal_val_{year_s}_{month_s}_{day_s}', qs.pcoal_heat)
|
|
return qs.pcoal_heat
|
|
except:
|
|
return 0
|