示例#1
0
    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
示例#2
0
    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
示例#3
0
    def audit(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 = Audit.review_info(
                audit_detail.workflow_id, audit_detail.workflow_type)
            Audit.add_log(audit_id=audit_id,
                          operation_type=1,
                          operation_type_desc='审批通过',
                          operation_info="审批备注:{},下级审批:{}".format(
                              audit_remark, current_audit_auth_group),
                          operator=audit_user,
                          operator_display=Users.objects.get(
                              username=audit_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()
            # 增加工单日志
            Audit.add_log(audit_id=audit_id,
                          operation_type=2,
                          operation_type_desc='审批不通过',
                          operation_info="审批备注:{}".format(audit_remark),
                          operator=audit_user,
                          operator_display=Users.objects.get(
                              username=audit_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()

            # 增加工单日志
            Audit.add_log(audit_id=audit_id,
                          operation_type=3,
                          operation_type_desc='审批取消',
                          operation_info="取消原因:{}".format(audit_remark),
                          operator=audit_user,
                          operator_display=Users.objects.get(
                              username=audit_user).display)
        else:
            result['msg'] = '审核异常'
            raise Exception(result['msg'])

        # 返回审核结果
        result['data'] = {'workflow_status': audit_result.current_status}
        return result