/// <summary>
 /// 审核通过
 /// </summary>
 /// <param name="id">当前主键</param>
 /// <param name="auditIdea">批示</param>
 /// <returns>影响行数</returns>
 public int AuditPass(IWorkFlowManager workFlowManager, string currentId, string auditIdea, BaseWorkFlowActivityEntity workFlowActivityEntity)
 {
     int returnValue = 0;
     // 进行更新操作
     returnValue = this.StepAuditPass(currentId, auditIdea, workFlowActivityEntity);
     if (returnValue == 0)
     {
         // 数据可能被删除
         this.ReturnStatusCode = StatusCode.ErrorDeleted.ToString();
     }
     BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId);
     // 发送提醒信息
     if (workFlowManager != null)
     {
         if (!string.IsNullOrEmpty(workFlowActivityEntity.AuditUserId))
         {
             workFlowActivityEntity.AuditDepartmentId = null;
             workFlowActivityEntity.AuditRoleId = null;
         }
         workFlowManager.OnAutoAuditPass(workFlowCurrentEntity);
         workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditPass, new string[] { workFlowCurrentEntity.CreateUserId, workFlowActivityEntity.AuditUserId }, workFlowActivityEntity.AuditDepartmentId, workFlowActivityEntity.AuditRoleId);
     }
     this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
     return returnValue;
 }
Example #2
0
        /// <summary>
        /// 审核通过
        /// </summary>
        /// <param name="id">当前主键</param>
        /// <param name="auditIdea">批示</param>
        /// <returns>影响行数</returns>
        public int AuditPass(IWorkFlowManager workFlowManager, string currentId, string auditIdea, BaseWorkFlowActivityEntity workFlowActivityEntity)
        {
            int returnValue = 0;

            // 进行更新操作
            returnValue = this.StepAuditPass(currentId, auditIdea, workFlowActivityEntity);
            if (returnValue == 0)
            {
                // 数据可能被删除
                this.ReturnStatusCode = StatusCode.ErrorDeleted.ToString();
            }
            BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId);

            // 发送提醒信息
            if (workFlowManager != null)
            {
                if (!string.IsNullOrEmpty(workFlowActivityEntity.AuditUserId))
                {
                    workFlowActivityEntity.AuditDepartmentId = null;
                    workFlowActivityEntity.AuditRoleId       = null;
                }
                workFlowManager.OnAutoAuditPass(workFlowCurrentEntity);
                workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditPass, new string[] { workFlowCurrentEntity.CreateUserId, workFlowActivityEntity.AuditUserId }, workFlowActivityEntity.AuditDepartmentId, workFlowActivityEntity.AuditRoleId);
            }
            this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
            return(returnValue);
        }
Example #3
0
        /// <summary>
        /// 撤消审批流程中的单据(撤销的没必要发送提醒信息)
        /// </summary>
        /// <param name="currentId">当前主键</param>
        /// <param name="auditIdea">批示</param>
        /// <returns>影响行数</returns>
        public int AuditQuash(IWorkFlowManager workFlowManager, string currentId, string auditIdea)
        {
            int returnValue = 0;

            if (!string.IsNullOrEmpty(currentId))
            {
                // using (TransactionScope transactionScope = new TransactionScope())
                // {
                try
                {
                    BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId);
                    // 只有待审核状态的,才可以撤销,被退回的也可以废弃
                    if (workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.AuditComplete.ToString()) ||
                        workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.AuditQuash.ToString()))
                    {
                        return(returnValue);
                    }
                    // 是超级管理员,或者创建者自己才可以撤销
                    if (!UserInfo.IsAdministrator && !workFlowCurrentEntity.CreateUserId.Equals(UserInfo.Id))
                    {
                        return(returnValue);
                    }
                    // 是自己的的单子需要被审核
                    // 最后修改人是自己,表明是自己发出的
                    // if ((baseWorkFlowCurrentEntity.ModifiedUserId == UserInfo.Id) || (baseWorkFlowCurrentEntity.CreateUserId == UserInfo.Id))
                    //{
                    // 进行更新操作
                    workFlowCurrentEntity = this.StepAuditQuash(currentId, auditIdea);
                    if (!string.IsNullOrEmpty(workFlowCurrentEntity.Id))
                    {
                        // 发送提醒信息
                        if (workFlowManager != null)
                        {
                            workFlowManager.OnAuditQuash(workFlowCurrentEntity);
                            returnValue = workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditQuash, new string[] { workFlowCurrentEntity.CreateUserId }, null, null);
                        }
                    }
                    else
                    {
                        // 数据可能被删除
                        this.ReturnStatusCode = StatusCode.ErrorDeleted.ToString();
                    }
                    // }
                    this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
                }
                catch (System.Exception ex)
                {
                    // 在本地记录异常
                    FileUtil.WriteException(UserInfo, ex);
                }
                finally
                {
                }
                // transactionScope.Complete();
                // }
            }
            return(returnValue);
        }
        /// <summary>
        /// 自由审批
        /// </summary>
        /// <param name="workFlowManager"></param>
        /// <param name="currentId"></param>
        /// <param name="toUserId"></param>
        /// <param name="toDepartmentId"></param>
        /// <param name="toRoleId"></param>
        /// <param name="auditIdea"></param>
        /// <returns></returns>
        public int FreeAuditPass(IWorkFlowManager workFlowManager, string currentId, string toUserId, string toDepartmentId = null, string toRoleId = null, string auditIdea = null)
        {
            // 返回值
            int returnValue = 0;

            // 这里用锁的机制,提高并发控制能力
            lock (WorkFlowCurrentLock)
            {
                BaseWorkFlowActivityEntity workFlowActivityEntity = new BaseWorkFlowActivityEntity();
                // FreeWorkFlow 自由工作流
                workFlowActivityEntity.WorkFlowId = 0;
                // 获取排序码
                workFlowActivityEntity.SortCode = int.Parse(new BaseSequenceManager().GetSequence("FreeWorkFlow", 10000000));
                // 是否提交给用户审批
                if (!string.IsNullOrEmpty(toUserId))
                {
                    workFlowActivityEntity.AuditUserId       = toUserId;
                    workFlowActivityEntity.AuditUserRealName = new BaseUserManager().GetEntity(toUserId).RealName;
                }
                // 是否提交给部门审批
                if (!string.IsNullOrEmpty(toDepartmentId))
                {
                    workFlowActivityEntity.AuditDepartmentId   = toDepartmentId;
                    workFlowActivityEntity.AuditDepartmentName = new BaseOrganizeManager().GetEntity(toDepartmentId).FullName;
                }
                // 是否提交给角色审批
                if (!string.IsNullOrEmpty(toRoleId))
                {
                    workFlowActivityEntity.AuditRoleId       = toRoleId;
                    workFlowActivityEntity.AuditRoleRealName = new BaseRoleManager().GetEntity(toRoleId).RealName;
                }
                // 进行更新操作
                returnValue = this.StepAuditPass(currentId, auditIdea, workFlowActivityEntity);
                if (returnValue == 0)
                {
                    // 数据可能被删除
                    this.ReturnStatusCode = StatusCode.ErrorDeleted.ToString();
                }
                BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId);
                // 发送提醒信息
                if (workFlowManager != null)
                {
                    if (!string.IsNullOrEmpty(workFlowActivityEntity.AuditUserId))
                    {
                        workFlowActivityEntity.AuditDepartmentId = null;
                        workFlowActivityEntity.AuditRoleId       = null;
                    }
                    workFlowManager.OnAutoAuditPass(workFlowCurrentEntity);
                    workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditPass, new string[] { workFlowCurrentEntity.CreateUserId, workFlowActivityEntity.AuditUserId }, workFlowActivityEntity.AuditDepartmentId, workFlowActivityEntity.AuditRoleId);
                }
                this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
                return(returnValue);
            }
        }
Example #5
0
        /// <summary>
        /// 自由审批完成
        /// </summary>
        /// <param name="workFlowManager">流程控制管理器</param>
        /// <param name="workFlowAuditInfo">流程信息</param>
        /// <returns>影响行数</returns>
        public string FreeAuditComplete(IWorkFlowManager workFlowManager, BaseWorkFlowAuditInfo workFlowAuditInfo)
        {
            // 返回值
            string result = string.Empty;

            // 这里用锁的机制,提高并发控制能力
            lock (WorkFlowCurrentLock)
            {
                try
                {
                    // 开始事务
                    this.DbHelper.BeginTransaction();
                    // 进行更新操作
                    this.StepAuditComplete(workFlowAuditInfo.Id, workFlowAuditInfo.AuditIdea);
                    BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(workFlowAuditInfo.Id);
                    // 发送提醒信息
                    if (workFlowManager != null)
                    {
                        workFlowManager.OnAutoAuditComplete(workFlowCurrentEntity);
                        workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditComplete, new string[] { workFlowCurrentEntity.CreateUserId, workFlowAuditInfo.ToUserId }, workFlowAuditInfo.ToDepartmentId, workFlowAuditInfo.ToRoleId);
                    }
                    this.StatusMessage = this.GetStateMessage(this.StatusCode);
                    result             = workFlowAuditInfo.Id;
                    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);
            }
        }
        /// <summary>
        /// 最终审核通过(完成)
        /// </summary>
        /// <param name="workFlowManager">当前审批流程接口</param>
        /// <param name="currentId">当前主键</param>
        /// <param name="auditIdea">批示</param>
        /// <returns>影响行数</returns>
        public int AuditComplete(IWorkFlowManager workFlowManager, string currentId, string auditIdea)
        {
            int returnValue = 0;
            // 1:进行更新操作
            BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.StepAuditComplete(currentId, auditIdea);

            if (workFlowCurrentEntity.Id != null)
            {
                // 2:对当前审批流程接口进行处理
                if (workFlowManager != null)
                {
                    // 3:进行审批处理完毕动作
                    workFlowManager.OnAuditComplete(workFlowCurrentEntity);
                    string[] userIds = null;

                    /*
                     * // 4:这里给所有相关的人发一个消息,告诉他们审批完成了
                     * BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo);
                     * userIds = workFlowStepManager.GetProperties(new KeyValuePair<string, object>(BaseWorkFlowStepEntity.FieldCategoryCode, workFlowCurrentEntity.CategoryCode)
                     *  , new KeyValuePair<string, object>(BaseWorkFlowStepEntity.FieldObjectId, workFlowCurrentEntity.ObjectId)
                     *  , BaseWorkFlowStepEntity.FieldAuditUserId);
                     */
                    // 把创建人加上,发出者也需要获得提醒信息
                    userIds = StringUtil.Concat(userIds, workFlowCurrentEntity.CreateUserId);
                    // 当前操作者没必要参与进来,可以少发一个没必要的提示信息,减少没必要的提醒信息
                    userIds = StringUtil.Remove(userIds, this.UserInfo.Id);
                    workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditComplete, userIds, null, null);
                    returnValue = 1;
                }
            }
            else
            {
                // 数据可能被删除
                this.ReturnStatusCode = StatusCode.ErrorDeleted.ToString();
            }
            // 应该给创建者一个提醒消息
            this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
            return(returnValue);
        }
 /// <summary>
 /// 最终审核通过(完成)
 /// </summary>
 /// <param name="workFlowManager">当前审批流程接口</param>
 /// <param name="currentId">当前主键</param>
 /// <param name="auditIdea">批示</param>
 /// <returns>影响行数</returns>
 public int AuditComplete(IWorkFlowManager workFlowManager, string currentId, string auditIdea)
 {
     int returnValue = 0;
     // 1:进行更新操作
     BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.StepAuditComplete(currentId, auditIdea);
     if (workFlowCurrentEntity.Id != null)
     {
         // 2:对当前审批流程接口进行处理
         if (workFlowManager != null)
         {
             // 3:进行审批处理完毕动作
             workFlowManager.OnAuditComplete(workFlowCurrentEntity);
             string[] userIds = null;
             /*
             // 4:这里给所有相关的人发一个消息,告诉他们审批完成了
             BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo);
             userIds = workFlowStepManager.GetProperties(new KeyValuePair<string, object>(BaseWorkFlowStepEntity.FieldCategoryCode, workFlowCurrentEntity.CategoryCode)
                 , new KeyValuePair<string, object>(BaseWorkFlowStepEntity.FieldObjectId, workFlowCurrentEntity.ObjectId)
                 , BaseWorkFlowStepEntity.FieldAuditUserId);
             */
             // 把创建人加上,发出者也需要获得提醒信息
             userIds = StringUtil.Concat(userIds, workFlowCurrentEntity.CreateUserId);
             // 当前操作者没必要参与进来,可以少发一个没必要的提示信息,减少没必要的提醒信息
             userIds = StringUtil.Remove(userIds, this.UserInfo.Id);
             workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditComplete, userIds, null, null);
             returnValue = 1;
         }
     }
     else
     {
         // 数据可能被删除
         this.ReturnStatusCode = StatusCode.ErrorDeleted.ToString();
     }
     // 应该给创建者一个提醒消息
     this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
     return returnValue;
 }
 //-----------------------------------------------------
 //                  启动工作流 自由流
 //-----------------------------------------------------
 /// <summary>
 /// 启动工作流(自由流转)
 /// </summary>
 /// <param name="workFlowManager"></param>
 /// <param name="objectId"></param>
 /// <param name="objectFullName"></param>
 /// <param name="categoryCode"></param>
 /// <param name="categoryFullName"></param>
 /// <param name="workFlowCode"></param>
 /// <param name="toUserId"></param>
 /// <param name="toDepartmentId"></param>
 /// <param name="toRoleId"></param>
 /// <param name="auditIdea"></param>
 /// <returns></returns>
 public string FreeStart(IWorkFlowManager workFlowManager, string objectId, string objectFullName, string categoryCode, string categoryFullName, string workFlowCode, string toUserId, string toDepartmentId = null, string toRoleId = null, string auditIdea = null)
 {
     // 获取当前工作流步骤
     string currentId = this.GetCurrentId(categoryCode, objectId);
     // 定义步骤实体
     BaseWorkFlowStepEntity workFlowStepEntity = new BaseWorkFlowStepEntity();
     // FreeWorkFlow 自由工作流
     workFlowStepEntity.WorkFlowId = 0;
     // 获取排序码
     workFlowStepEntity.SortCode = int.Parse(new BaseSequenceManager().GetSequence(workFlowCode, 10000000));
     // 是否提交给用户审批
     if (!string.IsNullOrEmpty(toUserId))
     {
         workFlowStepEntity.AuditUserId = toUserId;
         workFlowStepEntity.AuditUserRealName = new BaseUserManager().GetEntity(toUserId).RealName;
     }
     // 是否提交给部门审批
     if (!string.IsNullOrEmpty(toDepartmentId))
     {
         workFlowStepEntity.AuditDepartmentId = toDepartmentId;
         workFlowStepEntity.AuditDepartmentName = new BaseOrganizeManager().GetEntity(toDepartmentId).FullName;
     }
     // 是否提交给角色审批
     if (!string.IsNullOrEmpty(toRoleId))
     {
         workFlowStepEntity.AuditRoleId = toRoleId;
         workFlowStepEntity.AuditRoleRealName = new BaseRoleManager().GetEntity(toRoleId).RealName;
     }
     if (workFlowManager != null)
     {
         workFlowManager.BeforeAutoStatr(objectId);
     }
     // 如果已经存在
     if (currentId.Length > 0)
     {
         // 获取当前处于什么状态
         string auditstatus = this.GetProperty(currentId, BaseWorkFlowCurrentEntity.FieldAuditStatus);
         // 如果还是开始审批状态的话,允许他再次提交把原来的覆盖掉
         if (auditstatus == AuditStatus.StartAudit.ToString()
             || auditstatus == AuditStatus.AuditReject.ToString())
         {
             // 更新
             this.UpdataAuditStatr(currentId, categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity);
         }
         // 不是的话则返回
         else
         {
             // 该单据已进入审核状态不能在次提交
             this.ReturnStatusCode = StatusCode.ErrorChanged.ToString();
             // 返回为空可以判断
             currentId = null;
             return currentId;
         }
     }
     else
     {
         // 新增
         currentId = this.StepAuditStatr(categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity);
     }
     BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId);
     // 发送提醒信息,若发给指定的某个人了,就不发给部门的提示信息了
     if (workFlowManager != null)
     {
         if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId))
         {
             workFlowStepEntity.AuditDepartmentId = null;
             workFlowStepEntity.AuditRoleId = null;
         }
         workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.StartAudit, new string[] { workFlowCurrentEntity.CreateUserId, workFlowStepEntity.AuditUserId }, workFlowStepEntity.AuditDepartmentId, workFlowStepEntity.AuditRoleId);
     }
     // 成功工作流后的处理
     if (workFlowManager != null && !string.IsNullOrEmpty(objectId))
     {
         workFlowManager.AfterAutoStatr(objectId);
     }
     // 运行成功
     this.ReturnStatusCode = StatusCode.OK.ToString();
     this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
     return currentId;
 }
 /// <summary>
 /// 撤消审批流程中的单据(撤销的没必要发送提醒信息)
 /// </summary>
 /// <param name="currentId">当前主键</param>
 /// <param name="auditIdea">批示</param>
 /// <returns>影响行数</returns>
 public int AuditQuash(IWorkFlowManager workFlowManager, string currentId, string auditIdea)
 {
     int returnValue = 0;
     if (!string.IsNullOrEmpty(currentId))
     {
         // using (TransactionScope transactionScope = new TransactionScope())
         // {
         try
         {
             BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId);
             // 只有待审核状态的,才可以撤销,被退回的也可以废弃
             if (workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.AuditComplete.ToString())
                 || workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.AuditQuash.ToString()))
             {
                 return returnValue;
             }
             // 是超级管理员,或者创建者自己才可以撤销
             if (!UserInfo.IsAdministrator && !workFlowCurrentEntity.CreateUserId.Equals(UserInfo.Id))
             {
                 return returnValue;
             }
             // 是自己的的单子需要被审核
             // 最后修改人是自己,表明是自己发出的
             // if ((baseWorkFlowCurrentEntity.ModifiedUserId == UserInfo.Id) || (baseWorkFlowCurrentEntity.CreateUserId == UserInfo.Id))
             //{
             // 进行更新操作
             workFlowCurrentEntity = this.StepAuditQuash(currentId, auditIdea);
             if (!string.IsNullOrEmpty(workFlowCurrentEntity.Id))
             {
                 // 发送提醒信息
                 if (workFlowManager != null)
                 {
                     workFlowManager.OnAuditQuash(workFlowCurrentEntity);
                     returnValue = workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditQuash, new string[] { workFlowCurrentEntity.CreateUserId }, null, null);
                 }
             }
             else
             {
                 // 数据可能被删除
                 this.ReturnStatusCode = StatusCode.ErrorDeleted.ToString();
             }
             // }
             this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
         }
         catch (System.Exception ex)
         {
             // 在本地记录异常
             FileUtil.WriteException(UserInfo, ex);
         }
         finally
         {
         }
         // transactionScope.Complete();
         // }
     }
     return returnValue;
 }
Example #10
0
        //-----------------------------------------------------
        //                  启动工作流 步骤流
        //-----------------------------------------------------

        /// <summary>
        /// 启动工作流(步骤流转)
        /// </summary>
        /// <param name="workFlowManager">审批流程管理器</param>
        /// <param name="objectId">单据主键</param>
        /// <param name="objectFullName">单据名称</param>
        /// <param name="categoryCode">单据分类</param>
        /// <param name="categoryFullName">单据分类名称</param>
        /// <param name="workFlowCode">工作流程</param>
        /// <param name="auditIdea">审批意见</param>
        /// <param name="dtWorkFlowActivity">需要走的流程</param>
        /// <returns>主键</returns>
        public string AutoStatr(IWorkFlowManager workFlowManager, string objectId, string objectFullName, string categoryCode, string categoryFullName = null, string workFlowCode = null, string auditIdea = null, DataTable dtWorkFlowActivity = null)
        {
            string currentId = string.Empty;

            if (dtWorkFlowActivity == null || dtWorkFlowActivity.Rows.Count == 0)
            {
                return(currentId);
            }
            lock (WorkFlowCurrentLock)
            {
                BaseWorkFlowStepEntity workFlowStepEntity = null;
                // 这里需要读取一下
                if (dtWorkFlowActivity == null)
                {
                }
                workFlowStepEntity = new BaseWorkFlowStepEntity(dtWorkFlowActivity.Rows[0]);
                if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId))
                {
                    // 若是任意人可以审核的,需要进行一次人工选任的工作
                    if (workFlowStepEntity.AuditUserId.Equals("Anyone"))
                    {
                        return(null);
                    }
                }
                // 1. 先把已有的流程设置功能都删除掉
                BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo);
                workFlowStepManager.Delete(
                    new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldCategoryCode, categoryCode)
                    , new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldObjectId, objectId));
                // 2. 把当前的流程设置保存好
                foreach (DataRow dataRow in dtWorkFlowActivity.Rows)
                {
                    workFlowStepEntity              = new BaseWorkFlowStepEntity(dataRow);
                    workFlowStepEntity.ActivityId   = workFlowStepEntity.Id;
                    workFlowStepEntity.CategoryCode = categoryCode;
                    workFlowStepEntity.ObjectId     = objectId;
                    workFlowStepEntity.Id           = null;
                    workFlowStepManager.Add(workFlowStepEntity);
                }
                workFlowStepEntity = new BaseWorkFlowStepEntity(dtWorkFlowActivity.Rows[0]);

                // 3. 启动审核流程
                currentId = this.GetCurrentId(categoryCode, objectId);
                BaseWorkFlowCurrentEntity workFlowCurrentEntity = null;
                if (currentId.Length > 0)
                {
                    // 获取当前处于什么状态
                    string auditstatus = this.GetProperty(currentId, BaseWorkFlowCurrentEntity.FieldAuditStatus);
                    // 如果还是开始审批状态的话,允许他再次提交把原来的覆盖掉
                    if (auditstatus == AuditStatus.StartAudit.ToString())
                    {
                        this.UpdataAuditStatr(currentId, categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity);
                    }
                    // 不是的话则返回
                    else
                    {
                        // 该单据已进入审核状态不能在次提交
                        this.ReturnStatusCode = StatusCode.ErrorChanged.ToString();
                        // 返回为空可以判断
                        currentId = null;
                    }
                }
                else
                {
                    workFlowManager.BeforeAutoStatr(objectId);
                    currentId             = this.StepAuditStatr(categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity);
                    workFlowCurrentEntity = this.GetEntity(currentId);
                    // 发送提醒信息,若发给指定的某个人了,就不发给部门的提示信息了
                    if (workFlowManager != null)
                    {
                        if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId))
                        {
                            workFlowStepEntity.AuditDepartmentId = null;
                            workFlowStepEntity.AuditRoleId       = null;
                        }
                        workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.StartAudit, new string[] { workFlowCurrentEntity.CreateUserId, workFlowStepEntity.AuditUserId }, workFlowStepEntity.AuditDepartmentId, workFlowStepEntity.AuditRoleId);
                    }
                    // 成功工作流后的处理
                    if (!string.IsNullOrEmpty(objectId))
                    {
                        workFlowManager.AfterAutoStatr(objectId);
                    }
                    // 运行成功
                    this.ReturnStatusCode    = StatusCode.OK.ToString();
                    this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
                }
            }
            return(currentId);
        }
 /// <summary>
 /// 自由审批
 /// </summary>
 /// <param name="workFlowManager"></param>
 /// <param name="currentId"></param>
 /// <param name="toUserId"></param>
 /// <param name="toDepartmentId"></param>
 /// <param name="toRoleId"></param>
 /// <param name="auditIdea"></param>
 /// <returns></returns>
 public int FreeAuditPass(IWorkFlowManager workFlowManager, string currentId, string toUserId, string toDepartmentId = null, string toRoleId = null, string auditIdea = null)
 {
     // 返回值
     int returnValue = 0;
     // 这里用锁的机制,提高并发控制能力
     lock (WorkFlowCurrentLock)
     {
         BaseWorkFlowActivityEntity workFlowActivityEntity = new BaseWorkFlowActivityEntity();
         // FreeWorkFlow 自由工作流
         workFlowActivityEntity.WorkFlowId = 0;
         // 获取排序码
         workFlowActivityEntity.SortCode = int.Parse(new BaseSequenceManager().GetSequence("FreeWorkFlow", 10000000));
         // 是否提交给用户审批
         if (!string.IsNullOrEmpty(toUserId))
         {
             workFlowActivityEntity.AuditUserId = toUserId;
             workFlowActivityEntity.AuditUserRealName = new BaseUserManager().GetEntity(toUserId).RealName;
         }
         // 是否提交给部门审批
         if (!string.IsNullOrEmpty(toDepartmentId))
         {
             workFlowActivityEntity.AuditDepartmentId = toDepartmentId;
             workFlowActivityEntity.AuditDepartmentName = new BaseOrganizeManager().GetEntity(toDepartmentId).FullName;
         }
         // 是否提交给角色审批
         if (!string.IsNullOrEmpty(toRoleId))
         {
             workFlowActivityEntity.AuditRoleId = toRoleId;
             workFlowActivityEntity.AuditRoleRealName = new BaseRoleManager().GetEntity(toRoleId).RealName;
         }
         // 进行更新操作
         returnValue = this.StepAuditPass(currentId, auditIdea, workFlowActivityEntity);
         if (returnValue == 0)
         {
             // 数据可能被删除
             this.ReturnStatusCode = StatusCode.ErrorDeleted.ToString();
         }
         BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId);
         // 发送提醒信息
         if (workFlowManager != null)
         {
             if (!string.IsNullOrEmpty(workFlowActivityEntity.AuditUserId))
             {
                 workFlowActivityEntity.AuditDepartmentId = null;
                 workFlowActivityEntity.AuditRoleId = null;
             }
             workFlowManager.OnAutoAuditPass(workFlowCurrentEntity);
             workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditPass, new string[] { workFlowCurrentEntity.CreateUserId, workFlowActivityEntity.AuditUserId }, workFlowActivityEntity.AuditDepartmentId, workFlowActivityEntity.AuditRoleId);
         }
         this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
         return returnValue;
     }
 }
        /// <summary>
        /// 审核退回
        /// </summary>
        /// <param name="currentId">当前主键</param>
        /// <param name="auditIdea">批示</param>
        /// <param name="historyId">退回到第几步</param>
        /// <returns>影响行数</returns>
        public int AuditReject(IWorkFlowManager workFlowManager, string currentId, string auditIdea, string historyId = null)
        {
            int returnValue = 0;

            lock (WorkFlowCurrentLock)
            {
                // using (TransactionScope transactionScope = new TransactionScope())
                //{
                try
                {
                    BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId);
                    // 判断是是否是自由流(自由流这个为空)
                    if (workFlowCurrentEntity.WorkFlowId != null && workFlowCurrentEntity.WorkFlowId != 0)
                    {
                        // 若都已经被退回到彻底了,不能再被退回了,意思是已经退回到创建人了
                        if (workFlowCurrentEntity.ActivityId == null)
                        {
                            return returnValue;
                        }
                    }

                    // 只有待审核状态的,才可以退回,还需要能持续退回
                    if ( //workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.AuditComplete.ToString()) ||
                        workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.AuditQuash.ToString()))
                    {
                        return returnValue;
                    }

                    /* 彻底退回的处理
                    if (activityId == null)
                    {
                        // 发送给当初发起这个工作流的创建者
                        sendToUserId = workFlowCurrentEntity.CreateUserId;
                    }
                    else
                    {
                        BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(this.DbHelper, this.UserInfo);
                        BaseWorkFlowActivityEntity workFlowActivityEntity = workFlowActivityManager.GetEntity(activityId.ToString());
                        sendToUserId = workFlowActivityEntity.AuditUserId.ToString();
                    }
                    */

                    if (!string.IsNullOrEmpty(workFlowCurrentEntity.ToUserId))
                    {
                        // 若不是自己应该审核的,不应该能退回,在审核历史里需要控制一下
                        if (!this.UserInfo.IsAdministrator
                            &&(!workFlowCurrentEntity.AuditUserId.ToString().Equals(this.UserInfo.Id)
                             || workFlowCurrentEntity.ToUserId.ToString().Equals(this.UserInfo.Id)))
                        {
                            return returnValue;
                        }

                        // 一个审核者不能持续退回,但是发给自己的,还可以持续退回
                        if (workFlowCurrentEntity.AuditUserId.ToString().Equals(this.UserInfo.Id)
                            && workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.AuditReject.ToString())
                            && (!workFlowCurrentEntity.ToUserId.ToString().Equals(this.UserInfo.Id)))
                        {
                            return returnValue;
                        }
                    }

                    // 默认是自由工作流
                    string workFlowId = "0";
                    List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
                    DataTable dataTable = null;
                    BaseWorkFlowHistoryManager workFlowHistoryManager = new BaseWorkFlowHistoryManager(this.DbHelper, this.UserInfo);
                    string rejectToActivityId = string.Empty;
                    // 工作流主键
                    if (workFlowCurrentEntity.WorkFlowId != null && workFlowCurrentEntity.WorkFlowId != 0)
                    {
                        workFlowId = workFlowCurrentEntity.WorkFlowId.ToString();
                        BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo);
                        parameters.Add(new KeyValuePair<string, object>(BaseWorkFlowStepEntity.FieldCategoryCode, workFlowCurrentEntity.CategoryCode));
                        parameters.Add(new KeyValuePair<string, object>(BaseWorkFlowStepEntity.FieldObjectId, workFlowCurrentEntity.ObjectId));
                        parameters.Add(new KeyValuePair<string, object>(BaseWorkFlowStepEntity.FieldWorkFlowId, workFlowId));
                        parameters.Add(new KeyValuePair<string, object>(BaseWorkFlowStepEntity.FieldEnabled, 1));
                        parameters.Add(new KeyValuePair<string, object>(BaseWorkFlowStepEntity.FieldDeletionStateCode, 0));
                        dataTable = workFlowStepManager.GetDataTable(parameters, BaseWorkFlowStepEntity.FieldSortCode);
                        if (dataTable.Rows.Count > 0)
                        {
                            dataTable.Columns.Remove(BaseWorkFlowStepEntity.FieldId);
                            dataTable.Columns[BaseWorkFlowStepEntity.FieldActivityId].ColumnName = BaseWorkFlowStepEntity.FieldId;
                        }
                        else
                        {
                            // 判断是是否是自由流(自由流这个为空)
                            if (workFlowCurrentEntity.WorkFlowId != null && workFlowCurrentEntity.WorkFlowId != 0)
                            {
                                return returnValue;
                            }
                        }

                        if (!string.IsNullOrEmpty(historyId))
                        {
                            BaseWorkFlowHistoryEntity workFlowHistoryEntity = workFlowHistoryManager.GetEntity(historyId);
                            rejectToActivityId = workFlowHistoryEntity.ActivityId.ToString();
                        }
                        else
                        {
                            // 2. 从工作流审核模板里选取审核步骤 下一步是多少?按工作流进行查找审核步骤
                            // 3. 下一步是多少?按工作流进行查找审核步骤
                            BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(this.DbHelper, this.UserInfo);
                            parameters = new List<KeyValuePair<string, object>>();
                            parameters.Add(new KeyValuePair<string, object>(BaseWorkFlowActivityEntity.FieldWorkFlowId, workFlowId));
                            parameters.Add(new KeyValuePair<string, object>(BaseWorkFlowActivityEntity.FieldEnabled, 1));
                            parameters.Add(new KeyValuePair<string, object>(BaseWorkFlowActivityEntity.FieldDeletionStateCode, 0));
                            DataTable dataTableActivity = workFlowActivityManager.GetDataTable(parameters, BaseWorkFlowActivityEntity.FieldSortCode);
                            if (dataTableActivity.Rows.Count > 0)
                            {
                                dataTable = dataTableActivity;
                            }
                            string activityId = string.Empty;
                            if (workFlowCurrentEntity.ActivityId != null)
                            {
                                activityId = workFlowCurrentEntity.ActivityId.ToString();
                            }

                            if (!string.IsNullOrEmpty(activityId))
                            {
                                rejectToActivityId = BaseSortLogic.GetPreviousId(dataTable, activityId.ToString());
                            }
                            else
                            {
                                if (dataTable.Rows.Count > 0)
                                {
                                    rejectToActivityId = dataTable.Rows[0][BaseWorkFlowActivityEntity.FieldId].ToString();
                                }
                            }
                            if (string.IsNullOrEmpty(rejectToActivityId))
                            {
                                // 这里已经是最后一步,发出者这里了
                                // 已经到自己手里的,没必要再继续退回了
                                if (this.UserInfo.Id.Equals(workFlowCurrentEntity.CreateUserId))
                                {
                                    return returnValue;
                                }
                            }
                        }
                    }

                    // 这里不应该是发给所有的人,审核过的人,才可以看到才对。
                    string[] userIds = workFlowHistoryManager.GetProperties(new KeyValuePair<string, object>(BaseWorkFlowCurrentEntity.FieldWorkFlowId, workFlowCurrentEntity.Id), BaseWorkFlowCurrentEntity.FieldAuditUserId);
                    userIds = StringUtil.Concat(userIds, workFlowCurrentEntity.CreateUserId);

                    // 进行更新操作
                    workFlowCurrentEntity = this.StepAuditReject(currentId, auditIdea, workFlowCurrentEntity.CreateUserId, rejectToActivityId);
                    if (workFlowCurrentEntity.Id != null)
                    {
                        // 5.发送提示信息
                        if (workFlowManager != null)
                        {
                            workFlowManager.OnAuditReject(workFlowCurrentEntity);
                            /*
                            // 这个是表明已经彻底退回了,不是退回给指定的一个人了
                            if (activityId == null)
                            {
                                // 已经审核过的人,都需要得到退回的信息
                                BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(this.UserInfo);
                                DataTable dt = workFlowActivityManager.GetBackToDT(workFlowCurrentEntity);
                                userIds = BaseBusinessLogic.FieldToArray(dt, BaseWorkFlowActivityEntity.FieldAuditUserId);
                            }
                            */
                            // 都给谁发送退回的消息
                            workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditReject, userIds, workFlowCurrentEntity.ToDepartmentId, workFlowCurrentEntity.ToRoleId);

                        }
                        returnValue = 1;
                    }
                    else
                    {
                        // 数据可能被删除
                        this.ReturnStatusCode = StatusCode.ErrorDeleted.ToString();
                    }
                    // 应该给创建者一个提醒消息
                    this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
                }
                catch (System.Exception ex)
                {
                    // 在本地记录异常
                    FileUtil.WriteException(UserInfo, ex);
                }
                finally
                {
                }
                // transactionScope.Complete();
                // }
            }
            return returnValue;
        }
        /// <summary>
        /// 审核退回
        /// </summary>
        /// <param name="currentId">当前主键</param>
        /// <param name="auditIdea">批示</param>
        /// <param name="historyId">退回到第几步</param>
        /// <returns>影响行数</returns>
        public int AuditReject(IWorkFlowManager workFlowManager, string currentId, string auditIdea, string historyId = null)
        {
            int result = 0;

            lock (WorkFlowCurrentLock)
            {
                // using (TransactionScope transactionScope = new TransactionScope())
                //{
                try
                {
                    BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(currentId);
                    // 判断是是否是自由流(自由流这个为空)
                    if (workFlowCurrentEntity.ProcessId != null && workFlowCurrentEntity.ProcessId != 0)
                    {
                        // 若都已经被退回到彻底了,不能再被退回了,意思是已经退回到创建人了
                        if (workFlowCurrentEntity.ActivityId == null)
                        {
                            return(result);
                        }
                    }

                    // 只有待审核状态的,才可以退回,还需要能持续退回
                    if ( //workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.AuditComplete.ToString()) ||
                        workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.AuditQuash.ToString()))
                    {
                        return(result);
                    }

                    /* 彻底退回的处理
                     * if (activityId == null)
                     * {
                     *  // 发送给当初发起这个工作流的创建者
                     *  sendToUserId = workFlowCurrentEntity.CreateUserId;
                     * }
                     * else
                     * {
                     *  BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(this.DbHelper, this.UserInfo);
                     *  BaseWorkFlowActivityEntity workFlowActivityEntity = workFlowActivityManager.GetObject(activityId.ToString());
                     *  sendToUserId = workFlowActivityEntity.AuditUserId.ToString();
                     * }
                     */

                    if (!string.IsNullOrEmpty(workFlowCurrentEntity.ToUserId))
                    {
                        // 若不是自己应该审核的,不应该能退回,在审核历史里需要控制一下
                        if (!this.UserInfo.IsAdministrator &&
                            (!(workFlowCurrentEntity.AuditUserId.ToString().Equals(this.UserInfo.Id) || workFlowCurrentEntity.ToUserId.ToString().Equals(this.UserInfo.Id))))
                        {
                            return(result);
                        }

                        // 一个审核者不能持续退回,但是发给自己的,还可以持续退回
                        if (workFlowCurrentEntity.AuditUserId.ToString().Equals(this.UserInfo.Id) &&
                            workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.AuditReject.ToString()) &&
                            (!workFlowCurrentEntity.ToUserId.ToString().Equals(this.UserInfo.Id)))
                        {
                            return(result);
                        }
                    }

                    // 默认是自由工作流
                    string workFlowId = "0";
                    List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                    DataTable dt = null;
                    BaseWorkFlowHistoryManager workFlowHistoryManager = new BaseWorkFlowHistoryManager(this.DbHelper, this.UserInfo);
                    string rejectToActivityId = string.Empty;
                    // 工作流主键
                    if (workFlowCurrentEntity.ProcessId != null && workFlowCurrentEntity.ProcessId != 0)
                    {
                        workFlowId = workFlowCurrentEntity.ProcessId.ToString();
                        BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo);
                        parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldCategoryCode, workFlowCurrentEntity.CategoryCode));
                        parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldObjectId, workFlowCurrentEntity.ObjectId));
                        parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldProcessId, workFlowId));
                        parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldEnabled, 1));
                        parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldDeletionStateCode, 0));
                        dt = workFlowStepManager.GetDataTable(parameters, BaseWorkFlowStepEntity.FieldSortCode);
                        if (dt.Rows.Count > 0)
                        {
                            dt.Columns.Remove(BaseWorkFlowStepEntity.FieldId);
                            dt.Columns[BaseWorkFlowStepEntity.FieldActivityId].ColumnName = BaseWorkFlowStepEntity.FieldId;
                        }
                        else
                        {
                            // 判断是是否是自由流(自由流这个为空)
                            if (workFlowCurrentEntity.ProcessId != null && workFlowCurrentEntity.ProcessId != 0)
                            {
                                return(result);
                            }
                        }

                        if (!string.IsNullOrEmpty(historyId))
                        {
                            BaseWorkFlowHistoryEntity workFlowHistoryEntity = workFlowHistoryManager.GetObject(historyId);
                            rejectToActivityId = workFlowHistoryEntity.ActivityId.ToString();
                        }
                        else
                        {
                            // 2. 从工作流审核模板里选取审核步骤 下一步是多少?按工作流进行查找审核步骤
                            // 3. 下一步是多少?按工作流进行查找审核步骤
                            BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(this.DbHelper, this.UserInfo);
                            parameters = new List <KeyValuePair <string, object> >();
                            parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowActivityEntity.FieldProcessId, workFlowId));
                            parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowActivityEntity.FieldEnabled, 1));
                            parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowActivityEntity.FieldDeletionStateCode, 0));
                            DataTable dataTableActivity = workFlowActivityManager.GetDataTable(parameters, BaseWorkFlowActivityEntity.FieldSortCode);
                            if (dataTableActivity.Rows.Count > 0)
                            {
                                dt = dataTableActivity;
                            }
                            string activityId = string.Empty;
                            if (workFlowCurrentEntity.ActivityId != null)
                            {
                                activityId = workFlowCurrentEntity.ActivityId.ToString();
                            }

                            if (!string.IsNullOrEmpty(activityId))
                            {
                                rejectToActivityId = BaseSortLogic.GetPreviousId(dt, activityId.ToString());
                            }
                            else
                            {
                                if (dt.Rows.Count > 0)
                                {
                                    rejectToActivityId = dt.Rows[0][BaseWorkFlowActivityEntity.FieldId].ToString();
                                }
                            }
                            if (string.IsNullOrEmpty(rejectToActivityId))
                            {
                                // 这里已经是最后一步,发出者这里了
                                // 已经到自己手里的,没必要再继续退回了
                                if (this.UserInfo.Id.Equals(workFlowCurrentEntity.CreateUserId))
                                {
                                    return(result);
                                }
                            }
                        }
                    }

                    // 这里不应该是发给所有的人,审核过的人,才可以看到才对。
                    string[] userIds = workFlowHistoryManager.GetProperties(new KeyValuePair <string, object>(BaseWorkFlowCurrentEntity.FieldProcessId, workFlowCurrentEntity.ProcessId)
                                                                            , BaseWorkFlowCurrentEntity.FieldAuditUserId);
                    userIds = StringUtil.Concat(userIds, workFlowCurrentEntity.CreateUserId);

                    // 进行更新操作
                    workFlowCurrentEntity = this.StepAuditReject(currentId, auditIdea, workFlowCurrentEntity.CreateUserId, rejectToActivityId);
                    if (workFlowCurrentEntity.Id != null)
                    {
                        // 5.发送提示信息
                        if (workFlowManager != null)
                        {
                            workFlowManager.OnAuditReject(workFlowCurrentEntity);

                            /*
                             * // 这个是表明已经彻底退回了,不是退回给指定的一个人了
                             * if (activityId == null)
                             * {
                             *  // 已经审核过的人,都需要得到退回的信息
                             *  BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(this.UserInfo);
                             *  var result = workFlowActivityManager.GetBackToDT(workFlowCurrentEntity);
                             *  userIds = BaseBusinessLogic.FieldToArray(result, BaseWorkFlowActivityEntity.FieldAuditUserId).Distinct<string>().Where(t => !string.IsNullOrEmpty(t)).ToArray();
                             * }
                             */
                            // 都给谁发送退回的消息
                            workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditReject, userIds, workFlowCurrentEntity.ToDepartmentId, workFlowCurrentEntity.ToRoleId);
                        }
                        result = 1;
                    }
                    else
                    {
                        // 数据可能被删除
                        this.StatusCode = Status.ErrorDeleted.ToString();
                    }
                    // 应该给创建者一个提醒消息
                    this.StatusMessage = this.GetStateMessage(this.StatusCode);
                }
                catch (System.Exception ex)
                {
                    // 在本地记录异常
                    FileUtil.WriteException(UserInfo, ex);
                }
                finally
                {
                }
                // transactionScope.Complete();
                // }
            }
            return(result);
        }
        //-----------------------------------------------------
        //                  启动工作流 自由流
        //-----------------------------------------------------

        /// <summary>
        /// 启动工作流(自由流转)
        /// </summary>
        /// <param name="workFlowManager"></param>
        /// <param name="objectId"></param>
        /// <param name="objectFullName"></param>
        /// <param name="categoryCode"></param>
        /// <param name="categoryFullName"></param>
        /// <param name="workFlowCode"></param>
        /// <param name="toUserId"></param>
        /// <param name="toDepartmentId"></param>
        /// <param name="toRoleId"></param>
        /// <param name="auditIdea"></param>
        /// <returns></returns>
        public string FreeStart(IWorkFlowManager workFlowManager, string objectId, string objectFullName, string categoryCode, string categoryFullName, string workFlowCode, string toUserId, string toDepartmentId = null, string toRoleId = null, string auditIdea = null)
        {
            // 获取当前工作流步骤
            string currentId = this.GetCurrentId(categoryCode, objectId);
            // 定义步骤实体
            BaseWorkFlowStepEntity workFlowStepEntity = new BaseWorkFlowStepEntity();

            // FreeWorkFlow 自由工作流
            workFlowStepEntity.WorkFlowId = 0;
            // 获取排序码
            workFlowStepEntity.SortCode = int.Parse(new BaseSequenceManager().GetSequence(workFlowCode, 10000000));
            // 是否提交给用户审批
            if (!string.IsNullOrEmpty(toUserId))
            {
                workFlowStepEntity.AuditUserId       = toUserId;
                workFlowStepEntity.AuditUserRealName = new BaseUserManager().GetEntity(toUserId).RealName;
            }
            // 是否提交给部门审批
            if (!string.IsNullOrEmpty(toDepartmentId))
            {
                workFlowStepEntity.AuditDepartmentId   = toDepartmentId;
                workFlowStepEntity.AuditDepartmentName = new BaseOrganizeManager().GetEntity(toDepartmentId).FullName;
            }
            // 是否提交给角色审批
            if (!string.IsNullOrEmpty(toRoleId))
            {
                workFlowStepEntity.AuditRoleId       = toRoleId;
                workFlowStepEntity.AuditRoleRealName = new BaseRoleManager().GetEntity(toRoleId).RealName;
            }
            if (workFlowManager != null)
            {
                workFlowManager.BeforeAutoStatr(objectId);
            }
            // 如果已经存在
            if (currentId.Length > 0)
            {
                // 获取当前处于什么状态
                string auditstatus = this.GetProperty(currentId, BaseWorkFlowCurrentEntity.FieldAuditStatus);
                // 如果还是开始审批状态的话,允许他再次提交把原来的覆盖掉
                if (auditstatus == AuditStatus.StartAudit.ToString() ||
                    auditstatus == AuditStatus.AuditReject.ToString())
                {
                    // 更新
                    this.UpdataAuditStatr(currentId, categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity);
                }
                // 不是的话则返回
                else
                {
                    // 该单据已进入审核状态不能在次提交
                    this.ReturnStatusCode = StatusCode.ErrorChanged.ToString();
                    // 返回为空可以判断
                    currentId = null;
                    return(currentId);
                }
            }
            else
            {
                // 新增
                currentId = this.StepAuditStatr(categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity);
            }
            BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId);

            // 发送提醒信息,若发给指定的某个人了,就不发给部门的提示信息了
            if (workFlowManager != null)
            {
                if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId))
                {
                    workFlowStepEntity.AuditDepartmentId = null;
                    workFlowStepEntity.AuditRoleId       = null;
                }
                workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.StartAudit, new string[] { workFlowCurrentEntity.CreateUserId, workFlowStepEntity.AuditUserId }, workFlowStepEntity.AuditDepartmentId, workFlowStepEntity.AuditRoleId);
            }
            // 成功工作流后的处理
            if (workFlowManager != null && !string.IsNullOrEmpty(objectId))
            {
                workFlowManager.AfterAutoStatr(objectId);
            }
            // 运行成功
            this.ReturnStatusCode    = StatusCode.OK.ToString();
            this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
            return(currentId);
        }
        //-----------------------------------------------------
        //                  启动工作流 步骤流
        //-----------------------------------------------------
        /// <summary>
        /// 启动工作流(步骤流转)
        /// </summary>
        /// <param name="workFlowManager">审批流程管理器</param>
        /// <param name="objectId">单据主键</param>
        /// <param name="objectFullName">单据名称</param>
        /// <param name="categoryCode">单据分类</param>
        /// <param name="categoryFullName">单据分类名称</param>
        /// <param name="workFlowCode">工作流程</param>
        /// <param name="auditIdea">审批意见</param>
        /// <param name="dtWorkFlowActivity">需要走的流程</param>
        /// <returns>主键</returns>
        public string AutoStatr(IWorkFlowManager workFlowManager, string objectId, string objectFullName, string categoryCode, string categoryFullName = null, string workFlowCode = null, string auditIdea = null, DataTable dtWorkFlowActivity = null)
        {
            string currentId = string.Empty;
            if (dtWorkFlowActivity == null || dtWorkFlowActivity.Rows.Count == 0)
            {
                return currentId;
            }
            lock (WorkFlowCurrentLock)
            {
                BaseWorkFlowStepEntity workFlowStepEntity = null;
                // 这里需要读取一下
                if (dtWorkFlowActivity == null)
                {

                }
                workFlowStepEntity = new BaseWorkFlowStepEntity(dtWorkFlowActivity.Rows[0]);
                if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId))
                {
                    // 若是任意人可以审核的,需要进行一次人工选任的工作
                    if (workFlowStepEntity.AuditUserId.Equals("Anyone"))
                    {
                        return null;
                    }
                }
                // 1. 先把已有的流程设置功能都删除掉
                BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo);
                workFlowStepManager.Delete(
                    new KeyValuePair<string, object>(BaseWorkFlowStepEntity.FieldCategoryCode, categoryCode)
                    , new KeyValuePair<string, object>(BaseWorkFlowStepEntity.FieldObjectId, objectId));
                // 2. 把当前的流程设置保存好
                foreach (DataRow dataRow in dtWorkFlowActivity.Rows)
                {
                    workFlowStepEntity = new BaseWorkFlowStepEntity(dataRow);
                    workFlowStepEntity.ActivityId = workFlowStepEntity.Id;
                    workFlowStepEntity.CategoryCode = categoryCode;
                    workFlowStepEntity.ObjectId = objectId;
                    workFlowStepEntity.Id = null;
                    workFlowStepManager.Add(workFlowStepEntity);
                }
                workFlowStepEntity = new BaseWorkFlowStepEntity(dtWorkFlowActivity.Rows[0]);

                // 3. 启动审核流程
                currentId = this.GetCurrentId(categoryCode, objectId);
                BaseWorkFlowCurrentEntity workFlowCurrentEntity = null;
                if (currentId.Length > 0)
                {
                    // 获取当前处于什么状态
                    string auditstatus = this.GetProperty(currentId, BaseWorkFlowCurrentEntity.FieldAuditStatus);
                    // 如果还是开始审批状态的话,允许他再次提交把原来的覆盖掉
                    if (auditstatus == AuditStatus.StartAudit.ToString())
                    {
                        this.UpdataAuditStatr(currentId, categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity);
                    }
                    // 不是的话则返回
                    else
                    {
                        // 该单据已进入审核状态不能在次提交
                        this.ReturnStatusCode = StatusCode.ErrorChanged.ToString();
                        // 返回为空可以判断
                        currentId = null;
                    }
                }
                else
                {
                    workFlowManager.BeforeAutoStatr(objectId);
                    currentId = this.StepAuditStatr(categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity);
                    workFlowCurrentEntity = this.GetEntity(currentId);
                    // 发送提醒信息,若发给指定的某个人了,就不发给部门的提示信息了
                    if (workFlowManager != null)
                    {
                        if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId))
                        {
                            workFlowStepEntity.AuditDepartmentId = null;
                            workFlowStepEntity.AuditRoleId = null;
                        }
                        workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.StartAudit, new string[] { workFlowCurrentEntity.CreateUserId, workFlowStepEntity.AuditUserId }, workFlowStepEntity.AuditDepartmentId, workFlowStepEntity.AuditRoleId);
                    }
                    // 成功工作流后的处理
                    if (!string.IsNullOrEmpty(objectId))
                    {
                        workFlowManager.AfterAutoStatr(objectId);
                    }
                    // 运行成功
                    this.ReturnStatusCode = StatusCode.OK.ToString();
                    this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode);
                }
            }
            return currentId;
        }
Example #16
0
        /// <summary>
        /// 提交自由审批
        /// </summary>
        /// <param name="workFlowManager">流程控制管理器</param>
        /// <param name="workFlowAuditInfo">流程信息</param>
        /// <returns>主键</returns>
        public string FreeAuditStatr(IWorkFlowManager workFlowManager, BaseWorkFlowAuditInfo workFlowAuditInfo)
        {
            // 当工作流开始启动,进入流程审批
            try
            {
                // 开始事务
                this.DbHelper.BeginTransaction();

                if (workFlowManager != null)
                {
                    workFlowManager.BeforeAutoStatr(workFlowAuditInfo);
                }

                workFlowAuditInfo.AuditStatus     = AuditStatus.StartAudit.ToString();
                workFlowAuditInfo.AuditStatusName = AuditStatus.StartAudit.ToDescription();
                workFlowAuditInfo.Description     = "申请登记";
                workFlowAuditInfo.Id = this.StepAuditStatr(workFlowAuditInfo);

                BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(workFlowAuditInfo.Id);

                // 获取当前处于什么状态
                // 如果还是开始审批状态的话,允许他再次提交把原来的覆盖掉
                // if (workFlowCurrentEntity.AuditStatus == AuditStatus.AuditReject.ToString())
                // {
                // 更新
                // this.UpdataAuditStatr(workFlowCurrentEntity.Id, categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity);

                // 发送提醒信息,若发给指定的某个人了,就不发给部门的提示信息了
                if (workFlowManager != null)
                {
                    if (!string.IsNullOrEmpty(workFlowAuditInfo.ToUserId))
                    {
                        workFlowAuditInfo.ToDepartmentId = null;
                        workFlowAuditInfo.ToRoleId       = null;
                    }
                    workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.StartAudit, new string[] { workFlowCurrentEntity.CreateUserId, workFlowAuditInfo.ToUserId }, workFlowAuditInfo.ToDepartmentId, workFlowAuditInfo.ToRoleId);
                }
                // 成功工作流后的处理
                if (workFlowManager != null && !string.IsNullOrEmpty(workFlowAuditInfo.ObjectId))
                {
                    workFlowManager.AfterAutoStatr(workFlowAuditInfo);
                }

                this.DbHelper.CommitTransaction();
                // 运行成功
                this.StatusCode    = Status.OK.ToString();
                this.StatusMessage = this.GetStateMessage(this.StatusCode);
            }
            catch (Exception ex)
            {
                this.DbHelper.RollbackTransaction();
                BaseExceptionManager.LogException(dbHelper, this.UserInfo, ex);
                this.StatusCode = Status.Error.ToString();
                // throw;
            }
            finally
            {
                this.DbHelper.Close();
            }

            return(workFlowAuditInfo.Id);
        }
Example #17
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);
            }
        }
Example #18
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);
            }
        }