コード例 #1
0
        /// <summary>
        /// 启动工作流(自由流转)
        /// </summary>
        /// <param name="workFlowManager"></param>
        /// <param name="activityId">丢到第几部审核哪里去了</param>
        /// <param name="objectId"></param>
        /// <param name="objectFullName"></param>
        /// <param name="categoryCode"></param>
        /// <param name="categoryFullName"></param>
        /// <param name="toUserId"></param>
        /// <param name="toDepartmentId"></param>
        /// <param name="toRoleId"></param>
        /// <param name="auditIdea"></param>
        /// <returns></returns>
        public string FreeAudit(IWorkFlowManager workFlowManager, BaseWorkFlowAuditInfo workFlowAuditInfo)
        {
            // 是否提交给用户审批
            if (!string.IsNullOrEmpty(workFlowAuditInfo.ToUserId))
            {
                workFlowAuditInfo.ToUserRealName = BaseUserManager.GetRealNameByCache(workFlowAuditInfo.ToUserId);
            }
            // 是否提交给部门审批
            if (!string.IsNullOrEmpty(workFlowAuditInfo.ToDepartmentId))
            {
                workFlowAuditInfo.ToDepartmentName = BaseOrganizeManager.GetNameByCache(workFlowAuditInfo.ToDepartmentId);
            }
            // 是否提交给角色审批
            if (!string.IsNullOrEmpty(workFlowAuditInfo.ToRoleId))
            {
                workFlowAuditInfo.ToRoleRealName = BaseRoleManager.GetRealNameByCache(this.UserInfo.SystemCode, workFlowAuditInfo.ToRoleId);
            }
            // 计算第几步审核
            if (!string.IsNullOrEmpty(workFlowAuditInfo.ActivityId))
            {
                BaseWorkFlowActivityEntity workFlowActivityEntity = new BaseWorkFlowActivityManager().GetObject(workFlowAuditInfo.ActivityId);
                workFlowAuditInfo.ProcessId        = workFlowActivityEntity.ProcessId;
                workFlowAuditInfo.ActivityCode     = workFlowActivityEntity.Code;
                workFlowAuditInfo.ActivityType     = workFlowActivityEntity.ActivityType;
                workFlowAuditInfo.ActivityFullName = workFlowActivityEntity.FullName;
                BaseWorkFlowProcessEntity workFlowProcessEntity = new BaseWorkFlowProcessManager().GetObject(workFlowActivityEntity.ProcessId.ToString());
                workFlowAuditInfo.ProcessCode   = workFlowProcessEntity.Code;
                workFlowAuditInfo.CallBackClass = workFlowProcessEntity.CallBackClass;
                workFlowAuditInfo.CallBackTable = workFlowProcessEntity.CallBackTable;
                // 若没有分类信息,分类信息可以按流程的信息保存
                if (string.IsNullOrEmpty(workFlowAuditInfo.CategoryCode))
                {
                    workFlowAuditInfo.CategoryCode     = workFlowProcessEntity.Code;
                    workFlowAuditInfo.CategoryFullName = workFlowProcessEntity.FullName;
                }

                // 不需要反复从数据库读取的方法
                workFlowManager = GetWorkFlowManager(workFlowAuditInfo);
            }

            // 获取当前工作流步骤
            BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObjectBy(workFlowAuditInfo.CategoryCode, workFlowAuditInfo.ObjectId);

            // 已经在审批里了,那不需要重新审批,直接进入另外一个审批流程
            if (workFlowCurrentEntity != null && !string.IsNullOrEmpty(workFlowCurrentEntity.Id))
            {
                workFlowAuditInfo.Id = workFlowCurrentEntity.Id;

                // 判断现在是在什么流程节点上?
                int?sortCode = BaseWorkFlowActivityManager.GetEntity(workFlowCurrentEntity.ActivityId.ToString()).SortCode;

                // 与现在发送的流程节点比,是前进了,还是倒退了?
                // 这里是判断是退回还是前进了?排序码小的,就是在前面的步骤里,是退回了,否则是继续通过前进了
                if (BaseWorkFlowActivityManager.GetEntity(workFlowAuditInfo.ActivityId).SortCode <= sortCode)
                {
                    // 自由审批退回
                    this.FreeAuditReject(workFlowManager, workFlowAuditInfo);
                }
                else
                {
                    // 自由审批通过
                    this.FreeAuditPass(workFlowManager, workFlowAuditInfo);
                }
                return(workFlowCurrentEntity.Id);
            }

            // 提交自由审批
            this.FreeAuditStatr(workFlowAuditInfo);

            return(workFlowAuditInfo.Id);
        }
コード例 #2
0
        /// <summary>
        /// 自由审批退回
        /// </summary>
        /// <param name="workFlowManager">流程控制管理器</param>
        /// <param name="workFlowAuditInfo">流程信息</param>
        /// <returns>影响行数</returns>
        public int FreeAuditReject(IWorkFlowManager workFlowManager, BaseWorkFlowAuditInfo workFlowAuditInfo)
        {
            // 返回值
            int result = 0;

            // 这里用锁的机制,提高并发控制能力
            lock (WorkFlowCurrentLock)
            {
                try
                {
                    // 开始事务
                    this.DbHelper.BeginTransaction();
                    BaseWorkFlowStepEntity workFlowStepEntity = new BaseWorkFlowStepEntity();
                    if (!string.IsNullOrEmpty(workFlowAuditInfo.ActivityId))
                    {
                        workFlowStepEntity.ActivityId       = int.Parse(workFlowAuditInfo.ActivityId);
                        workFlowStepEntity.ActivityCode     = workFlowAuditInfo.ActivityCode;
                        workFlowStepEntity.ActivityFullName = workFlowAuditInfo.ActivityFullName;
                    }
                    // 是否提交给用户审批
                    if (!string.IsNullOrEmpty(workFlowAuditInfo.ToUserId))
                    {
                        workFlowStepEntity.AuditUserId       = workFlowAuditInfo.ToUserId;
                        workFlowStepEntity.AuditUserRealName = BaseUserManager.GetRealNameByCache(workFlowAuditInfo.ToUserId);
                    }
                    // 是否提交给部门审批
                    if (!string.IsNullOrEmpty(workFlowAuditInfo.ToDepartmentId))
                    {
                        workFlowStepEntity.AuditDepartmentId   = workFlowAuditInfo.ToDepartmentId;
                        workFlowStepEntity.AuditDepartmentName = BaseOrganizeManager.GetNameByCache(workFlowAuditInfo.ToDepartmentId);
                    }
                    // 是否提交给角色审批
                    if (!string.IsNullOrEmpty(workFlowAuditInfo.ToRoleId))
                    {
                        workFlowStepEntity.AuditRoleId       = workFlowAuditInfo.ToRoleId;
                        workFlowStepEntity.AuditRoleRealName = BaseRoleManager.GetRealNameByCache(this.UserInfo.SystemCode, workFlowAuditInfo.ToRoleId);
                    }
                    // 获取排序码
                    workFlowStepEntity.SortCode = int.Parse(new BaseSequenceManager().Increment("WorkFlow", 10000000));
                    // 进行更新操作
                    result = this.StepAuditReject(workFlowAuditInfo.Id, workFlowAuditInfo.AuditIdea, workFlowStepEntity);
                    if (result == 0)
                    {
                        // 数据可能被删除
                        this.StatusCode = Status.ErrorDeleted.ToString();
                    }
                    BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(workFlowAuditInfo.Id);
                    // 发送提醒信息
                    if (workFlowManager != null)
                    {
                        if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId))
                        {
                            workFlowStepEntity.AuditDepartmentId = null;
                            workFlowStepEntity.AuditRoleId       = null;
                        }
                        workFlowManager.OnAutoAuditReject(workFlowCurrentEntity);
                        workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditReject, new string[] { workFlowCurrentEntity.CreateUserId, workFlowStepEntity.AuditUserId }, workFlowStepEntity.AuditDepartmentId, workFlowStepEntity.AuditRoleId);
                    }
                    this.StatusMessage = this.GetStateMessage(this.StatusCode);
                    this.DbHelper.CommitTransaction();
                }
                catch (Exception ex)
                {
                    this.DbHelper.RollbackTransaction();
                    BaseExceptionManager.LogException(dbHelper, this.UserInfo, ex);
                    this.StatusCode = Status.Error.ToString();
                    // throw;
                }
                finally
                {
                    this.DbHelper.Close();
                }
                return(result);
            }
        }
コード例 #3
0
        /// <summary>
        /// 自由审批通过
        /// </summary>
        /// <param name="workFlowManager">流程控制管理器</param>
        /// <param name="workFlowAuditInfo">流程信息</param>
        /// <returns>影响行数</returns>
        public int FreeAuditPass(IWorkFlowManager workFlowManager, BaseWorkFlowAuditInfo workFlowAuditInfo)
        {
            // 返回值
            int result = 0;

            // 这里用锁的机制,提高并发控制能力
            lock (WorkFlowCurrentLock)
            {
                try
                {
                    // 开始事务
                    this.DbHelper.BeginTransaction();

                    // 这里需要循环产生前面的没有审批的人的记录,默认都要让他们审批通过才可以?
                    // 在这里处理连续跳过好几个审批的,自动能生成审批记录的功能?
                    BaseWorkFlowCurrentEntity workFlowCurrentEntity = null;
                    workFlowCurrentEntity = this.GetObject(workFlowAuditInfo.Id);
                    // 当前是什么步骤主键?
                    int?startSortCode = BaseWorkFlowActivityManager.GetEntity(workFlowCurrentEntity.ActivityId).SortCode;
                    // 现在要到什么步骤主键?
                    int?endSortCode = BaseWorkFlowActivityManager.GetEntity(workFlowAuditInfo.ActivityId).SortCode;
                    // 中间还有几个步骤被跳过了?
                    var listEntity = BaseWorkFlowActivityManager.GetEntities().Where(entity => entity.SortCode > startSortCode && entity.SortCode <= endSortCode && entity.Enabled == 1 && entity.DeletionStateCode == 0).OrderBy(entity => entity.SortCode);
                    int i          = 0;
                    foreach (var entity in listEntity)
                    {
                        // 这里是需要自动模拟产生的审批用的
                        BaseWorkFlowAuditInfo workFlowInfo = new BaseWorkFlowAuditInfo();
                        // 是最后一步了
                        if (entity.SortCode == endSortCode)
                        {
                            workFlowInfo           = workFlowAuditInfo;
                            workFlowInfo.AuditDate = DateTime.Now.AddMinutes(i * 10);
                        }
                        else
                        {
                            workFlowInfo.Id               = workFlowAuditInfo.Id;
                            workFlowInfo.ActivityId       = entity.Id.ToString();
                            workFlowInfo.ActivityCode     = entity.Code;
                            workFlowInfo.ActivityFullName = entity.FullName;
                            // 这个是默认写入的审核意见
                            workFlowInfo.AuditIdea         = "通过";
                            workFlowInfo.AuditUserId       = entity.DefaultAuditUserId;
                            workFlowInfo.AuditUserCode     = BaseUserManager.GetUserCodeByCache(entity.DefaultAuditUserId);
                            workFlowInfo.AuditUserRealName = BaseUserManager.GetRealNameByCache(entity.DefaultAuditUserId);
                            i++;
                            // 这里是生成不一样的审核人日期的方法
                            workFlowInfo.AuditDate       = DateTime.Now.AddMinutes(i * 10);
                            workFlowInfo.AuditStatus     = AuditStatus.AuditPass.ToString();
                            workFlowInfo.AuditStatusName = AuditStatus.AuditPass.ToDescription();
                            // workFlowInfo.ToUserId = entity.DefaultAuditUserId;
                            // workFlowInfo.ToRoleId = string.Empty;
                            // workFlowInfo.ToDepartmentId = string.Empty;
                        }

                        BaseWorkFlowStepEntity workFlowStepEntity = new BaseWorkFlowStepEntity();
                        if (!string.IsNullOrEmpty(workFlowInfo.ActivityId))
                        {
                            workFlowStepEntity.ActivityId       = int.Parse(workFlowInfo.ActivityId);
                            workFlowStepEntity.ActivityCode     = workFlowInfo.ActivityCode;
                            workFlowStepEntity.ActivityFullName = workFlowInfo.ActivityFullName;
                        }
                        // 是否提交给用户审批
                        if (!string.IsNullOrEmpty(workFlowInfo.ToUserId))
                        {
                            workFlowStepEntity.AuditUserId       = workFlowInfo.ToUserId;
                            workFlowStepEntity.AuditUserCode     = BaseUserManager.GetUserCodeByCache(workFlowInfo.ToUserId);
                            workFlowStepEntity.AuditUserRealName = BaseUserManager.GetRealNameByCache(workFlowInfo.ToUserId);
                        }
                        // 是否提交给部门审批
                        if (!string.IsNullOrEmpty(workFlowInfo.ToDepartmentId))
                        {
                            workFlowStepEntity.AuditDepartmentId   = workFlowInfo.ToDepartmentId;
                            workFlowStepEntity.AuditDepartmentName = BaseOrganizeManager.GetNameByCache(workFlowInfo.ToDepartmentId);
                        }
                        // 是否提交给角色审批
                        if (!string.IsNullOrEmpty(workFlowInfo.ToRoleId))
                        {
                            workFlowStepEntity.AuditRoleId       = workFlowInfo.ToRoleId;
                            workFlowStepEntity.AuditRoleRealName = BaseRoleManager.GetRealNameByCache(this.UserInfo.SystemCode, workFlowInfo.ToRoleId);
                        }
                        // 获取排序码
                        workFlowStepEntity.SortCode = int.Parse(new BaseSequenceManager().Increment("WorkFlow", 10000000));
                        // 进行更新操作,这里有时候需要模拟别人登录
                        result = this.StepAuditPass(workFlowInfo.Id, workFlowInfo.AuditIdea, workFlowStepEntity, workFlowInfo);
                        if (result == 0)
                        {
                            // 数据可能被删除
                            this.StatusCode = Status.ErrorDeleted.ToString();
                        }
                        workFlowCurrentEntity = this.GetObject(workFlowInfo.Id);
                        // 发送提醒信息
                        if (workFlowManager != null)
                        {
                            if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId))
                            {
                                workFlowStepEntity.AuditDepartmentId = null;
                                workFlowStepEntity.AuditRoleId       = null;
                            }
                            workFlowManager.OnAutoAuditPass(workFlowCurrentEntity);
                            workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditPass, new string[] { workFlowCurrentEntity.CreateUserId, workFlowStepEntity.AuditUserId }, workFlowStepEntity.AuditDepartmentId, workFlowStepEntity.AuditRoleId);
                        }
                    }
                    this.StatusMessage = this.GetStateMessage(this.StatusCode);
                    this.DbHelper.CommitTransaction();
                }
                catch (Exception ex)
                {
                    this.DbHelper.RollbackTransaction();
                    BaseExceptionManager.LogException(dbHelper, this.UserInfo, ex);
                    this.StatusCode = Status.Error.ToString();
                    // throw;
                }
                finally
                {
                    this.DbHelper.Close();
                }

                return(result);
            }
        }