From dc5be36e78fa0df7955ab37ddc68e1b4348072e5 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 12 Jun 2024 10:45:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20dpm=20checkwork=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dpm/migrations/0002_auto_20240612_1042.py | 23 +++++++++++++ apps/dpm/tasks.py | 32 +++++++++++-------- 2 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 apps/dpm/migrations/0002_auto_20240612_1042.py diff --git a/apps/dpm/migrations/0002_auto_20240612_1042.py b/apps/dpm/migrations/0002_auto_20240612_1042.py new file mode 100644 index 00000000..57d89519 --- /dev/null +++ b/apps/dpm/migrations/0002_auto_20240612_1042.py @@ -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='关闭时间'), + ), + ] diff --git a/apps/dpm/tasks.py b/apps/dpm/tasks.py index 559197d6..33c368d8 100644 --- a/apps/dpm/tasks.py +++ b/apps/dpm/tasks.py @@ -4,25 +4,29 @@ from celery import shared_task from apps.dpm.models import CheckTaskSet, CheckWork from django.utils import timezone from datetime import timedelta +from django.db import transaction @shared_task(base=CustomTask) def dispath_checkwork_task(checktaskset: str): cts = CheckTaskSet.objects.get(id=checktaskset) - cw = CheckWork() - cw.type = 20 - cw.checktaskset = cts - cw.name = '风险点检查(自动派发)' - now = timezone.now() - cw.time_start = now - expire_hour = cts.expire if cts.expire else 24 - cw.time_end = now + timedelta(hours=expire_hour) - cw.user_duty = cts.user_duty - cw.riskpoint = cts.riskpoint - cw.note = cts.note - cw.save() - # 发送通知 - pass + with transaction.atomic(): + CheckWork.objects.filter(checktaskset=cts).update(usable=False) + cw = CheckWork() + cw.type = 20 + cw.checktaskset = cts + now = timezone.now() + cw.time_start = now + local_time = timezone.localtime(now) + cw.name = f'风险点排查_{local_time.strftime('%Y%m%d%H%M%S')}' + if cts.expire: + cw.time_end = now + timedelta(hours=cts.expire) + cw.user_duty = cts.user_duty + cw.riskpoint = cts.riskpoint + cw.note = cts.note + cw.save() + # 发送通知 + pass @shared_task(base=CustomTask)