Example #1
0
    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 add(workflow_type, workflow_id):
        result = {'status': 0, 'msg': '', 'data': []}

        # 检查是否已存在待审核数据
        workflow_info = WorkflowAudit.objects.filter(
            workflow_type=workflow_type,
            workflow_id=workflow_id,
            current_status=WorkflowDict.workflow_status['audit_wait'])
        if len(workflow_info) >= 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
            create_user_display = workflow_detail.user_display
            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
            create_user_display = workflow_detail.engineer_display
            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().get('auto_review', False):
            if workflow_type == WorkflowDict.workflow_type['sqlreview']:
                if is_auto_review(workflow_id):
                    sql_workflow = SqlWorkflow.objects.get(id=int(workflow_id))
                    sql_workflow.audit_auth_groups = '无需审批'
                    sql_workflow.status = 'workflow_review_pass'
                    sql_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 = create_user_display
            audit_detail.save()
            result['data'] = {
                'workflow_status':
                WorkflowDict.workflow_status['audit_success']
            }
            result['msg'] = '无审核配置,直接审核通过'
            # 增加工单日志
            Audit.add_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 = create_user_display
            audit_detail.save()
            result['data'] = {
                'workflow_status': WorkflowDict.workflow_status['audit_wait']
            }
            # 增加工单日志
            audit_auth_group, current_audit_auth_group = Audit.review_info(
                workflow_id, workflow_type)
            Audit.add_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)
        # 返回添加结果
        return result