/// <summary> /// 验证 /// </summary> /// <returns></returns> protected virtual bool Validate(WorkflowArgsEntity args) { if (args.Task == null) { args.AddError("TaskNoExist"); return(false); } if (args.Flow == null) { args.AddError("FlowNoExist"); return(false); } if (args.Node == null) { args.AddError("NodeNoExist"); return(false); } if (args.Task.Status != TaskStatusType.Waiting) { args.AddError("TaskHandled"); return(false); } if (args.Task.Account == null || args.Task.Account.Id != args.AccountId) { args.AddError("NoAuthority"); return(false); } return(ValidateCreateTask(args)); }
/// <summary> /// 验证修改 /// </summary> /// <param name="args"></param> /// <returns></returns> public virtual IList <IUnitofwork> Handle(WorkflowArgsEntity args) { if (args == null) { return(null); } if (args.AccountId == 0 || args.TaskId == 0 || args.LevelId == 0) { args.AddError("ParamterError"); return(null); } FillArgs(args); if (!Validate(args)) { return(null); } args.Entity = args.Entity.Id == 0 ? args.Entity : GetEntityByConditions(args); var nodeIds = args.Flow.Nodes == null ? null : args.Flow.Nodes.Where(it => it.Name == args.Node.Name).Select(it => it.Id).ToArray(); if (nodeIds == null || nodeIds.Length == 0) { return(null); } var currentTasks = GetCurrentTasks(args.Entity.Id, nodeIds); args.CreateTasks(currentTasks); if (args.NextTasks == null) { return(null); } SetEntityStatus(args); return(Repository.Save(args.NextTasks)); }
/// <summary> /// 得到流程 /// </summary> /// <param name="args"></param> /// <returns></returns> protected virtual bool ValidateCreateTask(WorkflowArgsEntity args) { if (args.Task != null) { return(true); } if (args.Task == null && args.Entity.SaveType == SaveType.Add) { return(true); } var query = new QueryInfo { IsReturnCount = false }; query.SetPageSize(1) .Query <TaskEntity>() .Where(it => it.DataId == args.Entity.Id && it.Flow.Id == args.Flow.Id) .Select(it => it.Id); var infos = Repository.GetEntities <TaskEntity>(query); if (infos != null && infos.Count > 0) { args.AddError("TaskAlreadCreated"); return(false); } return(true); }