public BaseWorkFlowActivityEntity GetNextWorkFlowActivity(BaseWorkFlowCurrentEntity workFlowCurrentEntity)
        {
            BaseWorkFlowActivityEntity workFlowActivityEntity = null;
            DataTable dataTable = null;

            // 工作流主键
            string workFlowId = workFlowCurrentEntity.WorkFlowId.ToString();

            // 1. 从工作流审核步骤里选取审核步骤
            BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo);

            List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
            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
            {
                // 2. 从工作流审核模板里选取审核步骤 下一步是多少?按工作流进行查找审核步骤
                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 = workFlowActivityManager.GetDataTable(parameters, BaseWorkFlowActivityEntity.FieldSortCode);
            }

            // 审核步骤主键
            string activityId = string.Empty;
            if (workFlowCurrentEntity.ActivityId != null)
            {
                activityId = workFlowCurrentEntity.ActivityId.ToString();
            }
            if (dataTable.Rows.Count == 0)
            {
                return workFlowActivityEntity;
            }
            string nextActivityId = string.Empty;
            if (!string.IsNullOrEmpty(activityId))
            {
                nextActivityId = BaseSortLogic.GetNextId(dataTable, activityId.ToString());
            }
            else
            {
                nextActivityId = dataTable.Rows[0][BaseWorkFlowActivityEntity.FieldId].ToString();
            }
            if (!string.IsNullOrEmpty(nextActivityId))
            {
                // workFlowActivityEntity = workFlowActivityManager.GetEntity(nextActivityId);
                DataRow dataRow = BaseBusinessLogic.GetDataRow(dataTable, nextActivityId);
                workFlowActivityEntity = new BaseWorkFlowActivityEntity(dataRow);
            }
            return workFlowActivityEntity;
        }
Example #2
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);
        }
Example #3
0
        public BaseWorkFlowActivityEntity GetNextWorkFlowActivity(BaseWorkFlowCurrentEntity workFlowCurrentEntity)
        {
            BaseWorkFlowActivityEntity workFlowActivityEntity = null;
            DataTable dataTable = null;

            // 工作流主键
            string workFlowId = workFlowCurrentEntity.WorkFlowId.ToString();

            // 1. 从工作流审核步骤里选取审核步骤
            BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo);

            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            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
            {
                // 2. 从工作流审核模板里选取审核步骤 下一步是多少?按工作流进行查找审核步骤
                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 = workFlowActivityManager.GetDataTable(parameters, BaseWorkFlowActivityEntity.FieldSortCode);
            }

            // 审核步骤主键
            string activityId = string.Empty;

            if (workFlowCurrentEntity.ActivityId != null)
            {
                activityId = workFlowCurrentEntity.ActivityId.ToString();
            }
            if (dataTable.Rows.Count == 0)
            {
                return(workFlowActivityEntity);
            }
            string nextActivityId = string.Empty;

            if (!string.IsNullOrEmpty(activityId))
            {
                nextActivityId = BaseSortLogic.GetNextId(dataTable, activityId.ToString());
            }
            else
            {
                nextActivityId = dataTable.Rows[0][BaseWorkFlowActivityEntity.FieldId].ToString();
            }
            if (!string.IsNullOrEmpty(nextActivityId))
            {
                // workFlowActivityEntity = workFlowActivityManager.GetEntity(nextActivityId);
                DataRow dataRow = BaseBusinessLogic.GetDataRow(dataTable, nextActivityId);
                workFlowActivityEntity = new BaseWorkFlowActivityEntity(dataRow);
            }
            return(workFlowActivityEntity);
        }
        /// <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="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 #6
0
        /// <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);
        }