def post(self, request): id = request.POST.get('id') envi_desc = request.POST.get('envi_desc') obj = get_object_or_404(AuditContents, pk=id) status, msg = check_db_conn_status(obj.host, obj.port) if status: # 只要审核通过后,才能生成执行任务 if obj.progress in ('2', '3', '4', '6'): if IncepMakeExecTask.objects.filter(related_id=id).first(): taskid = IncepMakeExecTask.objects.filter(related_id=id).first().taskid context = {'status': 0, 'jump_url': f'/projects/pt/perform_records/perform_details/{taskid}'} else: host = obj.host database = obj.database port = obj.port sql_content = obj.contents # 实例化 of_audit = IncepSqlCheck(sql_content, host, port, database, request.user.username) # 对OSC执行的SQL生成sqlsha1 result = of_audit.make_sqlsha1() taskid = datetime.now().strftime("%Y%m%d%H%M%S%f") # 生成执行任务记录 for row in result: IncepMakeExecTask.objects.create( uid=request.user.uid, user=obj.proposer, taskid=taskid, dst_host=host, dst_port=port, dst_database=database, sql_content=row['SQL'], sqlsha1=row['sqlsha1'], affected_row=row['Affected_rows'], type=obj.operate_type, envi_desc=envi_desc, related_id=id ) context = {'status': 0, 'jump_url': f'/projects/pt/perform_records/perform_details/{taskid}'} else: context = {'status': 2, 'msg': '审核未通过或任务已关闭'} else: context = {'status': 2, 'msg': f'无法连接到数据库,请联系DBA\n主机: {obj.host}\n端口: {obj.port}'} return HttpResponse(json.dumps(context))
def post(self, request): id = request.POST.get('id') obj = get_object_or_404(AuditContents, pk=id) data = get_object_or_404(OlAuditDetail, ol=id) # 只要审核通过后,才能执行生成执行任务 if obj.progress in ('2', '3', '4'): if IncepMakeExecTask.objects.filter(related_id=id).first(): taskid = IncepMakeExecTask.objects.filter(related_id=id).first().taskid context = {'status': 0, 'jump_url': f'/projects/pt/incep_perform_records/incep_perform_details/{taskid}'} else: host = obj.host database = obj.database sql_content = data.contents # 实例化 incep_of_audit = IncepSqlCheck(sql_content, host, database, request.user.username) # 对OSC执行的SQL生成sqlsha1 result = incep_of_audit.make_sqlsha1() taskid = datetime.now().strftime("%Y%m%d%H%M%S%f") # 生成执行任务记录 for row in result: IncepMakeExecTask.objects.create( uid=request.user.uid, user=obj.proposer, taskid=taskid, dst_host=host, dst_database=database, sql_content=row['SQL'], sqlsha1=row['sqlsha1'], affected_row=row['Affected_rows'], type=obj.operate_type, category='1', related_id=id, group_id=obj.group_id ) context = {'status': 0, 'jump_url': f'/projects/pt/incep_perform_records/incep_perform_details/{taskid}'} else: context = {'status': 2, 'msg': '审核未通过或任务已关闭'} return HttpResponse(json.dumps(context))
def save(self, request): cleaned_data = super(OflineAuditForm, self).clean() host = cleaned_data['host'] database = cleaned_data['database'] operate_type = cleaned_data.get('operate_type') group_id = cleaned_data['group_id'] sql_content = cleaned_data['contents'] # 实例化 of_audit = IncepSqlCheck(sql_content, host, database, request.user.username) # 生成执行任务 check_result = of_audit.is_check_pass() if check_result['status'] == 2: context = check_result else: # 对OSC执行的SQL生成sqlsha1 result = of_audit.make_sqlsha1() taskid = datetime.now().strftime("%Y%m%d%H%M%S%f") # 生成执行任务记录 for row in result: IncepMakeExecTask.objects.create( uid=request.user.uid, user=request.user.username, taskid=taskid, dst_host=host, group_id=group_id, dst_database=database, sql_content=row['SQL'], sqlsha1=row['sqlsha1'], affected_row=row['Affected_rows'], type=operate_type) context = { 'status': 0, 'msg': '', 'jump_url': f'/projects/pt/perform_records/perform_details/{taskid}' } return context