feat: SfLogExp添加约束及cal_exp_duration_sec优化
This commit is contained in:
parent
5a07b6f889
commit
e1172c2fcf
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 3.2.12 on 2024-05-15 04:56
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('wpm', '0046_auto_20240515_1037'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='sflogexp',
|
||||||
|
unique_together={('sflog', 'stlog')},
|
||||||
|
),
|
||||||
|
]
|
|
@ -81,6 +81,8 @@ class SfLogExp(CommonADModel):
|
||||||
duration_sec = models.PositiveIntegerField('持续时长(s)', null=True, blank=True)
|
duration_sec = models.PositiveIntegerField('持续时长(s)', null=True, blank=True)
|
||||||
note = models.TextField('处理备注', default='', blank=True)
|
note = models.TextField('处理备注', default='', blank=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = ('sflog', 'stlog')
|
||||||
|
|
||||||
class WMaterial(CommonBDModel):
|
class WMaterial(CommonBDModel):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -60,7 +60,7 @@ def get_total_sec_now(sflogId: str=''):
|
||||||
@shared_task(base=CustomTask)
|
@shared_task(base=CustomTask)
|
||||||
def cal_exp_duration_sec(stlogId: str='', all=False):
|
def cal_exp_duration_sec(stlogId: str='', all=False):
|
||||||
"""
|
"""
|
||||||
计算异常记录对应的每班持续时间
|
计算异常记录对应的每班持续时间(只针对工段)
|
||||||
"""
|
"""
|
||||||
# from apps.enm.tasks import cal_enstat # 如果是停机需要进行统计停机时长
|
# from apps.enm.tasks import cal_enstat # 如果是停机需要进行统计停机时长
|
||||||
if stlogId:
|
if stlogId:
|
||||||
|
@ -84,7 +84,7 @@ def cal_exp_duration_sec(stlogId: str='', all=False):
|
||||||
sf_qs = SfLog.objects.filter(mgroup=stlog.mgroup)
|
sf_qs = SfLog.objects.filter(mgroup=stlog.mgroup)
|
||||||
sf_qs = (sf_qs.filter(start_time__gte=st_start, start_time__lt=st_end) | sf_qs.filter(end_time__gt=st_start,
|
sf_qs = (sf_qs.filter(start_time__gte=st_start, start_time__lt=st_end) | sf_qs.filter(end_time__gt=st_start,
|
||||||
end_time__lte=st_end) | sf_qs.filter(start_time__lte=st_start, end_time__gte=st_end)).order_by('start_time').distinct()
|
end_time__lte=st_end) | sf_qs.filter(start_time__lte=st_start, end_time__gte=st_end)).order_by('start_time').distinct()
|
||||||
SfLogExp.objects.filter(stlog=stlog, sflog__in=sf_qs).delete()
|
SfLogExp.objects.filter(stlog=stlog).exclude(sflog__in=sf_qs).delete()
|
||||||
for ind, sflog in enumerate(sf_qs):
|
for ind, sflog in enumerate(sf_qs):
|
||||||
sflogexp, _ = SfLogExp.objects.get_or_create(stlog=stlog, sflog=sflog, defaults={
|
sflogexp, _ = SfLogExp.objects.get_or_create(stlog=stlog, sflog=sflog, defaults={
|
||||||
'stlog': stlog, 'sflog': sflog})
|
'stlog': stlog, 'sflog': sflog})
|
||||||
|
|
Loading…
Reference in New Issue