feat: dpm checkwork增加字段

This commit is contained in:
caoqianming 2024-06-12 10:45:12 +08:00
parent 63dbc00a12
commit dc5be36e78
2 changed files with 41 additions and 14 deletions

View File

@ -0,0 +1,23 @@
# Generated by Django 3.2.12 on 2024-06-12 02:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dpm', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='checkwork',
name='usable',
field=models.BooleanField(default=True, verbose_name='是否可用'),
),
migrations.AlterField(
model_name='checkwork',
name='time_end',
field=models.DateTimeField(blank=True, null=True, verbose_name='关闭时间'),
),
]

View File

@ -4,25 +4,29 @@ from celery import shared_task
from apps.dpm.models import CheckTaskSet, CheckWork from apps.dpm.models import CheckTaskSet, CheckWork
from django.utils import timezone from django.utils import timezone
from datetime import timedelta from datetime import timedelta
from django.db import transaction
@shared_task(base=CustomTask) @shared_task(base=CustomTask)
def dispath_checkwork_task(checktaskset: str): def dispath_checkwork_task(checktaskset: str):
cts = CheckTaskSet.objects.get(id=checktaskset) cts = CheckTaskSet.objects.get(id=checktaskset)
cw = CheckWork() with transaction.atomic():
cw.type = 20 CheckWork.objects.filter(checktaskset=cts).update(usable=False)
cw.checktaskset = cts cw = CheckWork()
cw.name = '风险点检查(自动派发)' cw.type = 20
now = timezone.now() cw.checktaskset = cts
cw.time_start = now now = timezone.now()
expire_hour = cts.expire if cts.expire else 24 cw.time_start = now
cw.time_end = now + timedelta(hours=expire_hour) local_time = timezone.localtime(now)
cw.user_duty = cts.user_duty cw.name = f'风险点排查_{local_time.strftime('%Y%m%d%H%M%S')}'
cw.riskpoint = cts.riskpoint if cts.expire:
cw.note = cts.note cw.time_end = now + timedelta(hours=cts.expire)
cw.save() cw.user_duty = cts.user_duty
# 发送通知 cw.riskpoint = cts.riskpoint
pass cw.note = cts.note
cw.save()
# 发送通知
pass
@shared_task(base=CustomTask) @shared_task(base=CustomTask)