Exemple #1
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="baseWorkFlowHistoryEntity">实体</param>
 public int Update(BaseWorkFlowHistoryEntity baseWorkFlowHistoryEntity)
 {
     return(this.UpdateEntity(baseWorkFlowHistoryEntity));
 }
Exemple #2
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="baseWorkFlowHistoryEntity">实体</param>
 /// <param name="identity">自增量方式</param>
 /// <param name="returnId">返回主键</param>
 /// <returns>主键</returns>
 public string Add(BaseWorkFlowHistoryEntity baseWorkFlowHistoryEntity, bool identity, bool returnId)
 {
     this.Identity = identity;
     this.ReturnId = returnId;
     return(this.AddEntity(baseWorkFlowHistoryEntity));
 }
Exemple #3
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="baseWorkFlowHistoryEntity">实体</param>
 /// <returns>主键</returns>
 public string Add(BaseWorkFlowHistoryEntity baseWorkFlowHistoryEntity)
 {
     return(this.AddObject(baseWorkFlowHistoryEntity));
 }
Exemple #4
0
 // 这个是声明扩展方法
 partial void SetObjectExpand(SQLBuilder sqlBuilder, BaseWorkFlowHistoryEntity entity);
Exemple #5
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="baseWorkFlowHistoryEntity">实体</param>
        public string AddObject(BaseWorkFlowHistoryEntity baseWorkFlowHistoryEntity)
        {
            string sequence = string.Empty;

            if (baseWorkFlowHistoryEntity.SortCode == null || baseWorkFlowHistoryEntity.SortCode == 0)
            {
                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                sequence = sequenceManager.Increment(this.CurrentTableName);
                baseWorkFlowHistoryEntity.SortCode = int.Parse(sequence);
            }
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, BaseWorkFlowHistoryEntity.FieldId);
            if (!this.Identity)
            {
                sqlBuilder.SetValue(BaseWorkFlowHistoryEntity.FieldId, baseWorkFlowHistoryEntity.Id);
            }
            else
            {
                if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(BaseWorkFlowHistoryEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                    }
                    if (DbHelper.CurrentDbType == CurrentDbType.DB2)
                    {
                        sqlBuilder.SetFormula(BaseWorkFlowHistoryEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
                    }
                }
                else
                {
                    if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2))
                    {
                        if (baseWorkFlowHistoryEntity.Id == null)
                        {
                            if (string.IsNullOrEmpty(sequence))
                            {
                                BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                                sequence = sequenceManager.Increment(this.CurrentTableName);
                            }
                            baseWorkFlowHistoryEntity.Id = int.Parse(sequence);
                        }
                        sqlBuilder.SetValue(BaseWorkFlowHistoryEntity.FieldId, baseWorkFlowHistoryEntity.Id);
                    }
                }
            }
            this.SetObject(sqlBuilder, baseWorkFlowHistoryEntity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseWorkFlowHistoryEntity.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseWorkFlowHistoryEntity.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseWorkFlowHistoryEntity.FieldCreateOn);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseWorkFlowHistoryEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseWorkFlowHistoryEntity.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseWorkFlowHistoryEntity.FieldModifiedOn);
            if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.SqlServer || DbHelper.CurrentDbType == CurrentDbType.Access))
            {
                sequence = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            return(sequence);
        }
        /// <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);
        }