Пример #1
0
 /// <summary>
 /// 根据指定流程 选择的流转步骤创建任务
 /// </summary>
 /// <param name="task">当前任务Dto</param>
 /// <param name="stepId">当前步骤Id</param>
 protected void CreatedNextTask(FlowExecuteDto task, short stepId)
 {
     foreach (var step in task.Steps)
     {
         //流转的下个步骤
         var nextStep = FlowStepRepository.Entities.Single(p => p.StepId == step.Key && p.FlowDesignId == task.FlowId);
         foreach (var user in step.Value)
         {
             var uid   = user.Key;
             var uname = user.Value;
             GetReceiver(task.FlowId, ref uid, ref uname);
             WorkFlowTask taskModel = new WorkFlowTask()
             {
                 Id           = CombHelper.NewComb(),
                 PrevId       = task.TaskId,
                 FlowItemId   = task.ItemId,
                 PrevStepId   = stepId,
                 StepId       = nextStep.StepId,
                 StepName     = nextStep.StepName,
                 SenderId     = task.SenderId,
                 SenderName   = task.SenderName,
                 ReceiverId   = uid,
                 ReceiverName = uname,
                 IsComment    = nextStep.CountersignType == 0 ? false : true,
                 IsSeal       = nextStep.CountersignType == 2 ? true : false,
                 IsArchive    = nextStep.IsArchives,
                 StepDay      = nextStep.SpecifiedDay,
                 Status       = 1
             };
             FlowTaskRepository.Insert(taskModel);
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 办结任务
        /// </summary>
        /// <param name="task">当前任务Dto</param>
        /// <returns>业务操作结果</returns>
        protected OperationResult ExecuteCompleted(FlowExecuteDto task)
        {
            OperationResult re          = new OperationResult(OperationResultType.NoChanged, "办结未做处理!");
            var             currentTask = FlowTaskRepository.Entities.SingleOrDefault(c => c.Id == task.TaskId);

            if (currentTask != null)
            {
                var currentItem = FlowItemRepository.Entities.Single(c => c.Id == currentTask.FlowItemId);
                currentItem.Status        = 1;
                currentItem.CompletedTime = DateTime.Now;

                currentTask.Comment       = task.Comment;
                currentTask.TaskNote      = task.Note;
                currentTask.Status        = 10;
                currentTask.CompletedTime = DateTime.Now;

                FlowTaskRepository.UnitOfWork.TransactionEnabled = true;  //事务处理

                if (currentTask.IsArchive)
                {
                    FlowArchiveRepository.Insert(new WorkFlowArchive()
                    {
                        Id              = CombHelper.NewComb(),
                        FlowItemId      = currentTask.FlowItemId,
                        CreatorUserName = task.SenderName
                    });
                }
                FlowTaskRepository.Update(currentTask);
                FlowItemRepository.Update(currentItem);
                FlowTaskRepository.UnitOfWork.SaveChanges();

                re = new OperationResult(OperationResultType.Success, "成功办结!");
            }
            return(re);
        }
Пример #3
0
        /// <summary>
        /// 撤销提交
        /// </summary>
        /// <param name="task">当前任务Dto</param>
        /// <returns>业务操作结果</returns>
        protected OperationResult ExecuteCallBack(FlowExecuteDto task)
        {
            OperationResult result = IsCallBack(task.TaskId);

            if (result.ResultType != OperationResultType.Success)
            {
                return(new OperationResult(OperationResultType.ValidError, "任务在下级已经有处理,不能再撤销!"));
            }
            FlowTaskRepository.UnitOfWork.TransactionEnabled = true;  //事务处理
            var nextTask = (List <Guid>)result.Data;

            foreach (var item in nextTask)
            {
                FlowTaskRepository.Delete(item);
            }
            //标记本任务为待处理
            var currentTask = FlowTaskRepository.Entities.Where(c => c.Id == task.TaskId).Single();

            CompletedTask(currentTask, 1, "", "");
            var currentSiblingTask = GetSiblingTask(currentTask.FlowItemId, currentTask.StepId).Where(c => c.Status == 30).ToList();

            foreach (var item in currentSiblingTask)
            {
                CompletedTask(item, 1, "", "他人已撤销的任务");
            }
            FlowTaskRepository.UnitOfWork.SaveChanges();
            result = new OperationResult(OperationResultType.Success, "撤销成功!");

            return(result);
        }
Пример #4
0
 /// <summary>
 /// 设置当前任务状态
 /// </summary>
 /// <param name="currentTask">任务实体</param>
 /// <param name="status">标记状态</param>
 /// <param name="Comment">提交意见</param>
 /// <param name="Note">任务说明</param>
 protected void CompletedTask(WorkFlowTask currentTask, short status, string Comment = "", string Note = "")
 {
     if (currentTask != null)
     {
         currentTask.CompletedTime = DateTime.Now;
         currentTask.Comment       = Comment;
         if (Note != "")
         {
             currentTask.TaskNote = Note;
         }
         currentTask.Status = status;
         FlowTaskRepository.Update(currentTask);
     }
 }
Пример #5
0
        /// <summary>
        /// 执行 根据指定任务 标识已阅读
        /// </summary>
        /// <param name="taskId">流程任务Id</param>
        /// <returns>业务操作结果</returns>
        public OperationResult OpenTask(Guid TaskId)
        {
            OperationResult re          = new OperationResult(OperationResultType.NoChanged);
            var             currentTask = FlowTaskRepository.Entities.SingleOrDefault(c => c.Id == TaskId);

            if (currentTask != null && currentTask.Status == 1)
            {
                currentTask.Status     = 2;
                currentTask.OpenedTime = DateTime.Now;
                FlowTaskRepository.Update(currentTask);
                re = new OperationResult(OperationResultType.Success, "任务已阅读");
            }
            return(re);
        }
Пример #6
0
        /// <summary>
        /// 处理同级他人未完成的任务状态
        /// </summary>
        /// <param name="currentTask">任务实体</param>
        /// <param name="status">标记状态</param>
        /// <param name="Comment">提交意见</param>
        /// <param name="Note">任务说明</param>
        protected void CompletedOtherSiblingTask(WorkFlowTask currentTask, short status, string Comment = "", string Note = "")
        {
            List <WorkFlowTask> OtherSiblingTaskList = FlowTaskRepository.Entities.Where(c => c.FlowItemId == currentTask.FlowItemId && c.StepId == currentTask.StepId && c.Id != currentTask.Id && (c.Status == 1 || c.Status == 2)).ToList();    //找同级步骤他人未完成的任务

            if (OtherSiblingTaskList.Count > 0)
            {
                foreach (var task in OtherSiblingTaskList)
                {
                    task.CompletedTime = DateTime.Now;
                    task.Comment       = Comment;
                    task.TaskNote      = Note;
                    task.Status        = status;
                    FlowTaskRepository.Update(task);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// 退回任务
        /// </summary>
        /// <param name="task">当前任务Dto</param>
        /// <returns>业务操作结果</returns>
        protected OperationResult ExecuteBack(FlowExecuteDto task)
        {
            OperationResult re          = new OperationResult(OperationResultType.NoChanged, "退回未处理!");
            var             currentTask = FlowTaskRepository.Entities.Single(c => c.Id == task.TaskId);

            if (currentTask != null)
            {
                if (currentTask.Status != 1 && currentTask.Status != 2)
                {
                    return(new OperationResult(OperationResultType.ValidError, "任务已经处理,不能进行退回!"));
                }

                var currentStep = FlowStepRepository.Entities.Where(c => c.FlowDesignId == task.FlowId && c.StepId == currentTask.StepId).Select(m => new { m.StepType, m.BackType, m.SpecifiedBackStep }).SingleOrDefault();

                if (currentStep.StepType == 0)
                {
                    return(new OperationResult(OperationResultType.ValidError, "流程的第一个步骤不能退回!"));
                }
                if (currentStep.BackType == 0)
                {
                    return(new OperationResult(OperationResultType.ValidError, "当前步骤为不可退回步骤!"));
                }

                #region 退回处理
                List <WorkFlowTask> backTasks = new List <WorkFlowTask>();

                if (currentStep.BackType == 1)                                         //退回到上一步
                {
                    backTasks.AddRange(FlowTaskRepository.Entities.Where(c => c.Id == currentTask.PrevId).ToList());
                }
                else if (currentStep.BackType == 2)                                        //退回到第一步
                {
                    var firstTack = FlowTaskRepository.Entities.Where(c => c.PrevStepId == -1 && c.FlowItemId == currentTask.FlowItemId).OrderByDescending(c => c.CreatedTime).ToList()[0];
                    firstTack.PrevId = task.TaskId;  //上一个任务Id
                    backTasks.Add(firstTack);
                }
                else                                                                     //退回到指定步
                {
                    var backStep = FlowStepRepository.Entities.Where(c => c.FlowDesignId == task.FlowId && c.StepName == currentStep.SpecifiedBackStep).Select(c => new { c.StepId }).Single();
                    if (backStep == null)
                    {
                        return(new OperationResult(OperationResultType.ValidError, "当前流程步骤配置有误,不能退回!"));
                    }
                    var    backtask = GetSiblingTask(currentTask.FlowItemId, backStep.StepId).OrderByDescending(c => c.SenderId).ThenByDescending(c => c.CreatedTime).ToList();
                    string senderId = "";
                    foreach (var item in backtask)             //移除同一步骤中相同的发送人的以前的任务
                    {
                        if (senderId == item.SenderId)
                        {
                            backtask.Remove(item);
                        }
                        senderId = item.SenderId;
                    }
                    backTasks.AddRange(backtask);
                }

                FlowTaskRepository.UnitOfWork.TransactionEnabled = true;  //事务处理
                foreach (var item in backTasks)
                {
                    WorkFlowTask newTask = new WorkFlowTask();
                    newTask.Id            = CombHelper.NewComb();
                    newTask.PrevId        = item.PrevId;
                    newTask.FlowItemId    = item.FlowItemId;
                    newTask.PrevStepId    = item.PrevStepId;
                    newTask.StepId        = item.StepId;
                    newTask.StepName      = item.StepName;
                    newTask.SenderId      = task.SenderId;
                    newTask.SenderName    = task.SenderName;
                    newTask.ReceiverId    = item.ReceiverId;
                    newTask.ReceiverName  = item.ReceiverName;
                    newTask.OpenedTime    = null;
                    newTask.CompletedTime = null;
                    newTask.IsComment     = item.IsComment;
                    newTask.IsSeal        = item.IsSeal;
                    newTask.IsArchive     = item.IsArchive;
                    newTask.TaskNote      = "退回的任务";
                    newTask.StepDay       = item.StepDay;
                    newTask.DelayDay      = 0;
                    newTask.Status        = 1;

                    FlowTaskRepository.Insert(newTask);
                }

                CompletedTask(currentTask, 20, task.Comment);
                CompletedOtherSiblingTask(currentTask, 40, "", "他人已退回");

                FlowTaskRepository.UnitOfWork.SaveChanges();
                re = new OperationResult(OperationResultType.Success, "退回成功!");

                #endregion
            }
            else
            {
                re = new OperationResult(OperationResultType.ValidError, "您要退回的任务不存在!");
            }
            return(re);
        }