Exemple #1
0
        /// <summary>
        /// 撤消工作流
        /// </summary>
        /// <param name="entityid"></param>
        /// <param name="objectid"></param>
        /// <returns></returns>
        public WorkFlowCancellationResult Cancel(WorkFlowCancellationContext context)
        {
            WorkFlowCancellationResult result = new WorkFlowCancellationResult();

            result.IsSuccess = true;
            var Instance = _WorkFlowInstanceService.Find(n => n.EntityId == context.EntityMetaData.EntityId && n.ObjectId == context.ObjectId && n.StateCode == WorkFlowProcessState.Processing);

            if (Instance == null)
            {
                result.IsSuccess = false;
                result.Message   = _loc["workflow_noinstance"];
            }
            else if (Instance.ApplicantId != _user.SystemUserId)
            {
                result.IsSuccess = false;
                result.Message   = _loc["workflow_nopermissioncancel"];
            }
            else if (Instance.StateCode != WorkFlowProcessState.Processing)
            {
                result.IsSuccess = false;
                result.Message   = _loc["workflow_nopermissioncancel"];
            }
            var currentStep = _workFlowProcessFinder.Find(n => n.WorkFlowInstanceId == Instance.WorkFlowInstanceId && n.StateCode == WorkFlowProcessState.Processing);

            if (result.IsSuccess)
            {
                if (currentStep != null && !currentStep.AllowCancel)
                {
                    result.IsSuccess = false;
                    result.Message   = _loc["workflow_notallowcancel"];
                }
            }
            result = OnCancelling(context, result);
            _eventPublisher.Publish(new WorkFlowCancellingEvent {
                ObjectId = context.ObjectId, EntityMetaData = context.EntityMetaData, Instance = Instance, CurrentStep = currentStep, Result = result
            });
            if (result.IsSuccess)
            {
                try
                {
                    _WorkFlowInstanceService.BeginTransaction();
                    _WorkFlowInstanceService.Update(n => n
                                                    .Set(f => f.StateCode, WorkFlowProcessState.Canceled)
                                                    .Set(f => f.CompletedOn, DateTime.Now)
                                                    .Where(f => f.WorkFlowInstanceId == Instance.WorkFlowInstanceId)
                                                    );
                    _workFlowProcessUpdater.Update(n => n.Set(f => f.StateCode, WorkFlowProcessState.Disabled).Where(f => f.WorkFlowInstanceId == Instance.WorkFlowInstanceId));
                    //_workFlowProcessUpdater.UpdateObjectProcessState(context.EntityMetaData, context.ObjectId, WorkFlowProcessState.Canceled);
                    _WorkFlowInstanceService.CompleteTransaction();
                    result.IsSuccess = true;
                }
                catch (Exception e)
                {
                    _WorkFlowInstanceService.RollBackTransaction();
                    result.IsSuccess = false;
                    result.Message   = e.Message;
                    _logService.Error(e);
                }
            }
            result = OnCancelled(context, result);
            _eventPublisher.Publish(new WorkFlowCancelledEvent {
                ObjectId = context.ObjectId, EntityMetaData = context.EntityMetaData, Instance = Instance, CurrentStep = currentStep, Result = result
            });
            return(result);
        }
Exemple #2
0
 public virtual WorkFlowCancellationResult OnCancelled(WorkFlowCancellationContext context, WorkFlowCancellationResult result)
 {
     return(result);
 }