def auditworkflow(self, request, audit_id, audit_status, audit_user, audit_remark): result = {'status': 0, 'msg': 'ok', 'data': 0} audit_detail = WorkflowAudit.objects.get(audit_id=audit_id) # 不同审核状态 if audit_status == WorkflowDict.workflow_status['audit_success']: # 判断当前工单是否为待审核状态 if audit_detail.current_status != WorkflowDict.workflow_status[ 'audit_wait']: result['msg'] = '工单不是待审核状态,请返回刷新' raise Exception(result['msg']) # 判断是否还有下一级审核 if audit_detail.next_audit == '-1': # 更新主表审核状态为审核通过 audit_result = WorkflowAudit() audit_result.audit_id = audit_id audit_result.current_audit = '-1' audit_result.current_status = WorkflowDict.workflow_status[ 'audit_success'] audit_result.save( update_fields=['current_audit', 'current_status']) else: # 更新主表审核下级审核组和当前审核组 audit_result = WorkflowAudit() audit_result.audit_id = audit_id audit_result.current_status = WorkflowDict.workflow_status[ 'audit_wait'] audit_result.current_audit = audit_detail.next_audit # 判断后续是否还有下下一级审核组 audit_auth_groups_list = audit_detail.audit_auth_groups.split( ',') for index, auth_group in enumerate(audit_auth_groups_list): if auth_group == audit_detail.next_audit: # 无下下级审核组 if index == len(audit_auth_groups_list) - 1: audit_result.next_audit = '-1' break # 存在下下级审核组 else: audit_result.next_audit = audit_auth_groups_list[ index + 1] audit_result.save(update_fields=[ 'current_audit', 'next_audit', 'current_status' ]) # 插入审核明细数据 audit_detail_result = WorkflowAuditDetail() audit_detail_result.audit_id = audit_id audit_detail_result.audit_user = audit_user audit_detail_result.audit_status = WorkflowDict.workflow_status[ 'audit_success'] audit_detail_result.audit_time = timezone.now() audit_detail_result.remark = audit_remark audit_detail_result.save() # 增加工单日志 audit_auth_group, current_audit_auth_group = self.review_info( audit_detail.workflow_id, audit_detail.workflow_type) self.add_workflow_log(audit_id=audit_id, operation_type=1, operation_type_desc='审批通过', operation_info="审批备注:{},下级审批:{}".format( audit_remark, current_audit_auth_group), operator=request.user.username, operator_display=request.user.display) elif audit_status == WorkflowDict.workflow_status['audit_reject']: # 判断当前工单是否为待审核状态 if audit_detail.current_status != WorkflowDict.workflow_status[ 'audit_wait']: result['msg'] = '工单不是待审核状态,请返回刷新' raise Exception(result['msg']) # 更新主表审核状态 audit_result = WorkflowAudit() audit_result.audit_id = audit_id audit_result.current_audit = '-1' audit_result.next_audit = '-1' audit_result.current_status = WorkflowDict.workflow_status[ 'audit_reject'] audit_result.save(update_fields=[ 'current_audit', 'next_audit', 'current_status' ]) # 插入审核明细数据 audit_detail_result = WorkflowAuditDetail() audit_detail_result.audit_id = audit_id audit_detail_result.audit_user = audit_user audit_detail_result.audit_status = WorkflowDict.workflow_status[ 'audit_reject'] audit_detail_result.audit_time = timezone.now() audit_detail_result.remark = audit_remark audit_detail_result.save() # 增加工单日志 self.add_workflow_log( audit_id=audit_id, operation_type=2, operation_type_desc='审批不通过', operation_info="审批备注:{}".format(audit_remark), operator=request.user.username, operator_display=request.user.display) elif audit_status == WorkflowDict.workflow_status['audit_abort']: # 判断当前工单是否为待审核/审核通过状态 if audit_detail.current_status != WorkflowDict.workflow_status['audit_wait'] and \ audit_detail.current_status != WorkflowDict.workflow_status['audit_success']: result['msg'] = '工单不是待审核态/审核通过状态,请返回刷新' raise Exception(result['msg']) # 更新主表审核状态 audit_result = WorkflowAudit() audit_result.audit_id = audit_id audit_result.current_status = WorkflowDict.workflow_status[ 'audit_abort'] audit_result.save(update_fields=['current_status']) # 插入审核明细数据 audit_detail_result = WorkflowAuditDetail() audit_detail_result.audit_id = audit_id audit_detail_result.audit_user = audit_user audit_detail_result.audit_status = WorkflowDict.workflow_status[ 'audit_abort'] audit_detail_result.audit_time = timezone.now() audit_detail_result.remark = audit_remark audit_detail_result.save() # 增加工单日志 self.add_workflow_log( audit_id=audit_id, operation_type=3, operation_type_desc='审批取消', operation_info="取消原因:{}".format(audit_remark), operator=request.user.username, operator_display=request.user.display) else: result['msg'] = '审核异常' raise Exception(result['msg']) # 消息通知 sys_config = SysConfig().sys_config if sys_config.get('mail') or sys_config.get('ding'): workflow_url = "{}://{}/workflow/{}".format( request.scheme, request.get_host(), audit_detail.audit_id) send_msg(audit_id=audit_detail.audit_id, msg_type=0, audit_info=audit_detail, workflow_url=workflow_url) # 返回审核结果 result['data'] = {'workflow_status': audit_result.current_status} return result
def addworkflowaudit(self, request, workflow_type, workflow_id, **kwargs): result = {'status': 0, 'msg': '', 'data': []} # 检查是否已存在待审核数据 workflowInfo = WorkflowAudit.objects.filter( workflow_type=workflow_type, workflow_id=workflow_id, current_status=WorkflowDict.workflow_status['audit_wait']) if len(workflowInfo) >= 1: result['msg'] = '该工单当前状态为待审核,请勿重复提交' raise Exception(result['msg']) # 获取工单信息 if workflow_type == WorkflowDict.workflow_type['query']: workflow_detail = QueryPrivilegesApply.objects.get( apply_id=workflow_id) workflow_title = workflow_detail.title group_id = workflow_detail.group_id group_name = workflow_detail.group_name create_user = workflow_detail.user_name audit_auth_groups = workflow_detail.audit_auth_groups workflow_remark = '' elif workflow_type == WorkflowDict.workflow_type['sqlreview']: workflow_detail = SqlWorkflow.objects.get(pk=workflow_id) workflow_title = workflow_detail.workflow_name group_id = workflow_detail.group_id group_name = workflow_detail.group_name create_user = workflow_detail.engineer audit_auth_groups = workflow_detail.audit_auth_groups workflow_remark = '' else: result['msg'] = '工单类型不存在' raise Exception(result['msg']) # 校验是否配置审批流程 if audit_auth_groups is None: result['msg'] = '审批流程不能为空,请先配置审批流程' raise Exception(result['msg']) else: audit_auth_groups_list = audit_auth_groups.split(',') # 判断是否无需审核,并且修改审批人为空 if SysConfig().sys_config.get('auto_review', False): if workflow_type == WorkflowDict.workflow_type['sqlreview']: if is_autoreview(workflow_id): Workflow = SqlWorkflow.objects.get(id=int(workflow_id)) Workflow.audit_auth_groups = '无需审批' Workflow.status = '审核通过' Workflow.save() audit_auth_groups_list = None # 无审核配置则无需审核,直接通过 if audit_auth_groups_list is None: # 向审核主表插入审核通过的数据 audit_detail = WorkflowAudit() audit_detail.group_id = group_id audit_detail.group_name = group_name audit_detail.workflow_id = workflow_id audit_detail.workflow_type = workflow_type audit_detail.workflow_title = workflow_title audit_detail.workflow_remark = workflow_remark audit_detail.audit_auth_groups = '' audit_detail.current_audit = '-1' audit_detail.next_audit = '-1' audit_detail.current_status = WorkflowDict.workflow_status[ 'audit_success'] # 审核通过 audit_detail.create_user = create_user audit_detail.create_user_display = request.user.display audit_detail.save() result['data'] = { 'workflow_status': WorkflowDict.workflow_status['audit_success'] } result['msg'] = '无审核配置,直接审核通过' # 增加工单日志 self.add_workflow_log( audit_id=audit_detail.audit_id, operation_type=0, operation_type_desc='提交', operation_info='无需审批,系统直接审核通过', operator=audit_detail.create_user, operator_display=audit_detail.create_user_display) else: # 向审核主表插入待审核数据 audit_detail = WorkflowAudit() audit_detail.group_id = group_id audit_detail.group_name = group_name audit_detail.workflow_id = workflow_id audit_detail.workflow_type = workflow_type audit_detail.workflow_title = workflow_title audit_detail.workflow_remark = workflow_remark audit_detail.audit_auth_groups = ','.join(audit_auth_groups_list) audit_detail.current_audit = audit_auth_groups_list[0] # 判断有无下级审核 if len(audit_auth_groups_list) == 1: audit_detail.next_audit = '-1' else: audit_detail.next_audit = audit_auth_groups_list[1] audit_detail.current_status = WorkflowDict.workflow_status[ 'audit_wait'] audit_detail.create_user = create_user audit_detail.create_user_display = request.user.display audit_detail.save() result['data'] = { 'workflow_status': WorkflowDict.workflow_status['audit_wait'] } # 增加工单日志 audit_auth_group, current_audit_auth_group = self.review_info( workflow_id, workflow_type) self.add_workflow_log( audit_id=audit_detail.audit_id, operation_type=0, operation_type_desc='提交', operation_info='等待审批,审批流程:{}'.format(audit_auth_group), operator=audit_detail.create_user, operator_display=audit_detail.create_user_display) # 消息通知 sys_config = SysConfig().sys_config if sys_config.get('mail') or sys_config.get('ding'): workflow_url = "{}://{}/workflow/{}".format( request.scheme, request.get_host(), audit_detail.audit_id) email_cc = kwargs.get('list_cc_addr', []) send_msg(audit_id=audit_detail.audit_id, msg_type=0, audit_info=audit_detail, workflow_url=workflow_url, email_cc=email_cc) # 返回添加结果 return result
def auditworkflow(self, request, audit_id, audit_status, audit_user, audit_remark): result = {'status': 0, 'msg': 'ok', 'data': 0} auditInfo = WorkflowAudit.objects.get(audit_id=audit_id) # 不同审核状态 if audit_status == WorkflowDict.workflow_status['audit_success']: # 判断当前工单是否为待审核状态 if auditInfo.current_status != WorkflowDict.workflow_status[ 'audit_wait']: result['msg'] = '工单不是待审核状态,请返回刷新' raise Exception(result['msg']) # 判断是否还有下一级审核 if auditInfo.next_audit == '-1': # 更新主表审核状态为审核通过 auditresult = WorkflowAudit() auditresult.audit_id = audit_id auditresult.current_audit = '-1' auditresult.current_status = WorkflowDict.workflow_status[ 'audit_success'] auditresult.save( update_fields=['current_audit', 'current_status']) else: # 更新主表审核下级审核组和当前审核组 auditresult = WorkflowAudit() auditresult.audit_id = audit_id auditresult.current_status = WorkflowDict.workflow_status[ 'audit_wait'] auditresult.current_audit = auditInfo.next_audit # 判断后续是否还有下下一级审核组 audit_auth_groups_list = auditInfo.audit_auth_groups.split(',') for index, auth_group in enumerate(audit_auth_groups_list): if auth_group == auditInfo.next_audit: # 无下下级审核组 if index == len(audit_auth_groups_list) - 1: auditresult.next_audit = '-1' break # 存在下下级审核组 else: auditresult.next_audit = audit_auth_groups_list[ index + 1] auditresult.save(update_fields=[ 'current_audit', 'next_audit', 'current_status' ]) # 插入审核明细数据 audit_detail_result = WorkflowAuditDetail() audit_detail_result.audit_id = audit_id audit_detail_result.audit_user = audit_user audit_detail_result.audit_status = WorkflowDict.workflow_status[ 'audit_success'] audit_detail_result.audit_time = timezone.now() audit_detail_result.remark = audit_remark audit_detail_result.save() elif audit_status == WorkflowDict.workflow_status['audit_reject']: # 判断当前工单是否为待审核状态 if auditInfo.current_status != WorkflowDict.workflow_status[ 'audit_wait']: result['msg'] = '工单不是待审核状态,请返回刷新' raise Exception(result['msg']) # 更新主表审核状态 auditresult = WorkflowAudit() auditresult.audit_id = audit_id auditresult.current_audit = '-1' auditresult.next_audit = '-1' auditresult.current_status = WorkflowDict.workflow_status[ 'audit_reject'] auditresult.save(update_fields=[ 'current_audit', 'next_audit', 'current_status' ]) # 插入审核明细数据 audit_detail_result = WorkflowAuditDetail() audit_detail_result.audit_id = audit_id audit_detail_result.audit_user = audit_user audit_detail_result.audit_status = WorkflowDict.workflow_status[ 'audit_reject'] audit_detail_result.audit_time = timezone.now() audit_detail_result.remark = audit_remark audit_detail_result.save() elif audit_status == WorkflowDict.workflow_status['audit_abort']: # 判断当前工单是否为待审核/审核通过状态 if auditInfo.current_status != WorkflowDict.workflow_status['audit_wait'] and \ auditInfo.current_status != WorkflowDict.workflow_status['audit_success']: result['msg'] = '工单不是待审核态/审核通过状态,请返回刷新' raise Exception(result['msg']) # 更新主表审核状态 auditresult = WorkflowAudit() auditresult.audit_id = audit_id auditresult.current_status = WorkflowDict.workflow_status[ 'audit_abort'] auditresult.save(update_fields=['current_status']) # 插入审核明细数据 audit_detail_result = WorkflowAuditDetail() audit_detail_result.audit_id = audit_id audit_detail_result.audit_user = audit_user audit_detail_result.audit_status = WorkflowDict.workflow_status[ 'audit_abort'] audit_detail_result.audit_time = timezone.now() audit_detail_result.remark = audit_remark audit_detail_result.save() else: result['msg'] = '审核异常' raise Exception(result['msg']) # 消息通知 workflow_url = "{}://{}/workflow/{}".format(request.scheme, request.get_host(), auditInfo.audit_id) send_msg(auditInfo.audit_id, 0, workflow_url=workflow_url) # 返回审核结果 result['data'] = {'workflow_status': auditresult.current_status} return result