feat: sflog增加total_hour字段
This commit is contained in:
parent
a7204ec897
commit
dd2189900f
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.2.12 on 2023-11-20 10:57
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wpm', '0032_auto_20231120_1623'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='sflog',
|
||||
name='total_hour',
|
||||
field=models.FloatField(default=12, verbose_name='总时长'),
|
||||
),
|
||||
]
|
|
@ -40,6 +40,7 @@ class SfLog(CommonADModel):
|
|||
'wpm.stlog', verbose_name='关联停机记录', through='wpm.sflogexp')
|
||||
last_test_time = models.DateTimeField('最后质检时间', null=True, blank=True)
|
||||
total_hour_now = models.FloatField('总时长动', default=0)
|
||||
total_hour = models.FloatField('总时长', default=12)
|
||||
shut_hour = models.FloatField('停机时长', default=0)
|
||||
pcoal_heat = models.FloatField('煤粉热值', null=True, blank=True)
|
||||
|
||||
|
|
|
@ -29,14 +29,15 @@ def make_sflogs(mgroup: Mgroup, start_date: datetime.date, end_date: datetime.da
|
|||
if start_time > end_time:
|
||||
start_time -= datetime.timedelta(days=1)
|
||||
duration = end_time - start_time
|
||||
total_hours_now = duration.total_seconds() / 3600
|
||||
total_hour = duration.total_seconds() / 3600
|
||||
SfLog.objects.get_or_create(mgroup=mgroup, shift=shift, start_time=start_time, defaults={
|
||||
"mgroup": mgroup,
|
||||
"shift": shift,
|
||||
"work_date": current_date,
|
||||
"start_time": start_time,
|
||||
"end_time": end_time,
|
||||
"total_hour_now": total_hours_now,
|
||||
"total_hour_now": total_hour,
|
||||
"total_hour": total_hour,
|
||||
"create_by": create_by
|
||||
})
|
||||
current_date = current_date + datetime.timedelta(days=1)
|
||||
|
|
|
@ -41,8 +41,7 @@ def get_total_hour_now(sflogId: str):
|
|||
if sflogId:
|
||||
sflog = SfLog.objects.get(id=sflogId)
|
||||
if sflog.end_time <= now:
|
||||
sflog.total_hour_now = (
|
||||
sflog.end_time-sflog.start_time).total_seconds()/3600 # 写死的数据不是很好
|
||||
sflog.total_hour_now = sflog.total_hour
|
||||
else:
|
||||
total_hour_now = (now-sflog.start_time).total_seconds()/3600
|
||||
sflog.total_hour_now = total_hour_now if total_hour_now > 0 else 0
|
||||
|
@ -50,7 +49,7 @@ def get_total_hour_now(sflogId: str):
|
|||
return sflog.total_hour_now
|
||||
else:
|
||||
SfLog.objects.filter(end_time__lte=now).exclude(
|
||||
total_hour_now=12).update(total_hour_now=12)
|
||||
total_hour_now__lt=F('total_hour')).update(total_hour_now=F('total_hour'))
|
||||
sf_qs = SfLog.objects.filter(end_time__gt=now)
|
||||
for i in sf_qs:
|
||||
total_hour_now = (now-i.start_time).total_seconds()/3600
|
||||
|
|
Loading…
Reference in New Issue