From a2429fc0ca4b443f890d9e99e4ce330d7e0933bf Mon Sep 17 00:00:00 2001 From: yingzy <546188155@qq.com> Date: Thu, 6 Jun 2019 21:59:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0sql=E4=B8=8A=E7=BA=BF?= =?UTF-8?q?=E5=8F=AF=E6=89=A7=E8=A1=8C=E6=97=B6=E9=97=B4=E9=80=89=E6=8B=A9?= =?UTF-8?q?=EF=BC=8C=E4=B8=94=E5=AE=A1=E6=A0=B8=E4=BA=BA=E5=8F=AF=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=BF=99=E4=B8=AA=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/models.py | 2 + sql/sql_workflow.py | 42 ++++++++++++++++- sql/templates/detail.html | 91 ++++++++++++++++++++++++++++++++++++ sql/templates/sqlsubmit.html | 50 ++++++++++++++++++++ sql/urls.py | 1 + sql/utils/sql_review.py | 22 +++++++++ 6 files changed, 206 insertions(+), 2 deletions(-) diff --git a/sql/models.py b/sql/models.py index 2daf745570..9a2d05ebc4 100644 --- a/sql/models.py +++ b/sql/models.py @@ -180,6 +180,8 @@ class SqlWorkflow(models.Model): engineer_display = models.CharField('发起人中文名', max_length=50, default='') status = models.CharField(max_length=50, choices=SQL_WORKFLOW_CHOICES) audit_auth_groups = models.CharField('审批权限组列表', max_length=255) + starttime = models.DateTimeField('可执行起始时间', null=True, blank=True) + endtime = models.DateTimeField('可执行结束时间', null=True, blank=True) create_time = models.DateTimeField('创建时间', auto_now_add=True) finish_time = models.DateTimeField('结束时间', null=True, blank=True) is_manual = models.IntegerField('是否原生执行', choices=((0, '否'), (1, '是')), default=0) diff --git a/sql/sql_workflow.py b/sql/sql_workflow.py index 42a3ad5784..b598fe7d2f 100644 --- a/sql/sql_workflow.py +++ b/sql/sql_workflow.py @@ -22,7 +22,7 @@ from sql.models import ResourceGroup, Users from sql.utils.resource_group import user_groups, user_instances from sql.utils.tasks import add_sql_schedule, del_schedule -from sql.utils.sql_review import can_timingtask, can_cancel, can_execute +from sql.utils.sql_review import can_timingtask, can_cancel, can_execute, on_Correct_time_period from sql.utils.workflow_audit import Audit from .models import SqlWorkflow, SqlWorkflowContent, Instance from django_q.tasks import async_task @@ -126,6 +126,8 @@ def submit(request): is_backup = True if request.POST.get('is_backup') == 'True' else False notify_users = request.POST.getlist('notify_users') list_cc_addr = [email['email'] for email in Users.objects.filter(username__in=notify_users).values('email')] + starttime = request.POST['run_date_start'] + endtime = request.POST['run_date_end'] # 服务器端参数验证 if None in [sql_content, db_name, instance_name, db_name, is_backup]: @@ -178,7 +180,9 @@ def submit(request): db_name=db_name, is_manual=0, syntax_type=check_result.syntax_type, - create_time=timezone.now() + create_time=timezone.now(), + starttime=starttime, + endtime=endtime ) SqlWorkflowContent.objects.create(workflow=sql_workflow, sql_content=sql_content, @@ -204,6 +208,36 @@ def submit(request): return HttpResponseRedirect(reverse('sql:detail', args=(workflow_id,))) +@permission_required('sql.sql_review', raise_exception=True) +def alter_time(request): + """ + 审核人修改可执行时间 + :param request: + :return: + """ + workflow_id = int(request.POST.get('workflow_id', 0)) + starttime = request.POST['run_date_start'] + endtime = request.POST['run_date_end'] + if workflow_id == 0: + context = {'errMsg': 'workflow_id参数为空.'} + return render(request, 'error.html', context) + + user = request.user + if Audit.can_review(user, workflow_id, 2) is False: + context = {'errMsg': '你无权操作当前工单!'} + return render(request, 'error.html', context) + + try: + # 存进数据库里 + alterworkflow = SqlWorkflow.objects.get(id=workflow_id) + alterworkflow.starttime = starttime + alterworkflow.endtime = endtime + alterworkflow.save() + except Exception as msg: + context = {'errMsg': msg} + return render(request, 'error.html', context) + + return HttpResponseRedirect(reverse('sql:detail', args=(workflow_id,))) @permission_required('sql.sql_review', raise_exception=True) def passed(request): @@ -264,6 +298,10 @@ def execute(request): if can_execute(request.user, workflow_id) is False: context = {'errMsg': '你无权操作当前工单!'} return render(request, 'error.html', context) + + if on_Correct_time_period(workflow_id) is False: + context = {'errMsg': '请在正确的时间执行上线!'} + return render(request, 'error.html', context) # 根据执行模式进行对应修改 mode = request.POST.get('mode') if mode == "auto": diff --git a/sql/templates/detail.html b/sql/templates/detail.html index 143bca4e79..7047e520e6 100644 --- a/sql/templates/detail.html +++ b/sql/templates/detail.html @@ -35,6 +35,12 @@