public IActionResult WorkFlowProcessing(WorkFlowProcessingModel model) { if (model.EntityId.Equals(Guid.Empty) || model.RecordId.Equals(Guid.Empty)) { return(NotFound()); } var entityMetas = _entityFinder.FindById(model.EntityId); var entity = _dataFinder.RetrieveById(entityMetas.Name, model.RecordId); var instances = _workFlowInstanceService.Query(n => n.Take(1).Where(f => f.EntityId == model.EntityId && f.ObjectId == model.RecordId).Sort(s => s.SortDescending(f => f.CreatedOn))); WorkFlowInstance instance = null; if (instances.NotEmpty()) { instance = instances.First(); } if (instance == null) { return(NotFound()); } var processInfo = _workFlowProcessFinder.GetCurrentStep(instance.WorkFlowInstanceId, CurrentUser.SystemUserId); if (processInfo == null) { if (_workFlowProcessFinder.GetLastHandledStep(instance.WorkFlowInstanceId, CurrentUser.SystemUserId) != null) { return(JError("您已处理")); } return(JError(T["workflow_nopermission"])); } model.InstanceInfo = instance; model.ProcessInfo = processInfo; model.ProcessList = _workFlowProcessFinder.Query(n => n.Where(f => f.WorkFlowInstanceId == instance.WorkFlowInstanceId).Sort(s => s.SortAscending(f => f.StepOrder))); return(View($"~/Views/Flow/{WebContext.ActionName}.cshtml", model)); }
public IActionResult Instances(Guid entityid, Guid recordid) { var instances = _workFlowInstanceService.Query(n => n .Where(f => f.EntityId == entityid && f.ObjectId == recordid) .Sort(s => s.SortDescending(f => f.CreatedOn)) ); if (instances.IsEmpty()) { return(NotFound()); } var entityMeta = _entityFinder.FindById(entityid); if (entityMeta == null) { return(NotFound()); } foreach (var instance in instances) { var steps = _workFlowProcessFinder.Query(n => n .Where(f => f.WorkFlowInstanceId == instance.WorkFlowInstanceId && f.StateCode != WorkFlowProcessState.Disabled) .Sort(s => s.SortAscending(f => f.StepOrder)).Sort(s => s.SortAscending(f => f.StateCode))); instance.Steps = steps; } return(JOk(instances)); }
public IActionResult WorkFlowInstanceDetail(Guid entityid, Guid recordid) { var instances = _workFlowInstanceService.Query(n => n .Where(f => f.EntityId == entityid && f.ObjectId == recordid) .Sort(s => s.SortDescending(f => f.CreatedOn)) ); if (instances.IsEmpty()) { return(NotFound()); } var entityMeta = _entityFinder.FindById(entityid); if (entityMeta == null) { return(NotFound()); } foreach (var instance in instances) { var steps = _workFlowProcessFinder.Query(n => n .Where(f => f.WorkFlowInstanceId == instance.WorkFlowInstanceId && f.StateCode != WorkFlowProcessState.Disabled) .Sort(s => s.SortAscending(f => f.StepOrder)).Sort(s => s.SortAscending(f => f.StateCode))); instance.Steps = steps; } WorkFlowInstanceDetailModel model = new WorkFlowInstanceDetailModel(); model.Items = instances; var workFlowId = instances.First().WorkFlowId; model.FlowInfo = _workFlowFinder.FindById(workFlowId); var allSteps = _workFlowStepService.Query(n => n.Where(f => f.WorkFlowId == workFlowId).Sort(s => s.SortAscending(f => f.StepOrder))); model.Steps = allSteps; return(View(model)); }
public IActionResult GetCompleteInfo(EntityFormModel args) { string nonePermissionFields = null, form = null, records = null; if (args.EntityId.Equals(Guid.Empty) && args.EntityName.IsEmpty()) { return(NotFound()); } var entity = args.EntityId.Equals(Guid.Empty) ? _entityFinder.FindByName(args.EntityName) : _entityFinder.FindById(args.EntityId); if (entity == null) { return(NotFound()); } args.EntityId = entity.EntityId; args.EntityName = entity.Name; EditRecordModel m = new EditRecordModel { EntityMetaData = entity, EntityId = args.EntityId, RelationShipName = args.RelationShipName, ReferencedRecordId = args.ReferencedRecordId }; if (args.RecordId.HasValue && !args.RecordId.Value.Equals(Guid.Empty)) { var record = _dataFinder.RetrieveById(entity.Name, args.RecordId.Value); if (record == null || record.Count == 0) { return(NotFound()); } var fileAttributes = _attributeFinder.FindByEntityId(entity.EntityId).Where(n => n.DataFormat.IsCaseInsensitiveEqual("fileupload")); foreach (var item in fileAttributes) { if (record.GetStringValue(item.Name).IsNotEmpty()) { record[item.Name] = string.Empty; } else { record.Remove(item.Name); } } m.Entity = record; m.RecordId = args.RecordId; m.FormState = FormState.Update; if (m.Entity.GetIntValue("statecode", -1) == 0) { m.FormState = FormState.Disabled; //model.ReadOnly = true; } } else if (args.CopyId.HasValue && !args.CopyId.Value.Equals(Guid.Empty)) { var record = _dataFinder.RetrieveById(entity.Name, args.CopyId.Value); if (record == null || record.Count == 0) { return(NotFound()); } var fileAttributes = _attributeFinder.FindByEntityId(entity.EntityId).Where(n => n.DataFormat.IsCaseInsensitiveEqual("fileupload")); foreach (var item in fileAttributes) { record.Remove(item.Name); } record.RemoveKeys(AttributeDefaults.SystemAttributes); m.Entity = record; //m.RecordId = model.RecordId; m.FormState = FormState.Create; } else { //ViewData["record"] = "{}"; m.FormState = FormState.Create; } m.ReadOnly = args.ReadOnly; var isCreate = !args.RecordId.HasValue || args.RecordId.Value.Equals(Guid.Empty); SystemForm formEntity = null; //workflow if (!isCreate && m.EntityMetaData.WorkFlowEnabled && m.Entity.GetGuidValue("workflowid").Equals(Guid.Empty)) { var processState = m.Entity.GetIntValue("processstate", -1); if (processState == (int)WorkFlowProcessState.Processing)// || processState == (int)WorkFlowProcessState.Passed) { m.ReadOnly = true; m.FormState = FormState.ReadOnly; var instances = _workFlowInstanceService.Query(n => n.Take(1).Where(f => f.EntityId == m.EntityId.Value && f.ObjectId == m.RecordId.Value).Sort(s => s.SortDescending(f => f.CreatedOn))); WorkFlowInstance instance = null; if (instances.NotEmpty()) { instance = instances.First(); } if (instance != null) { var processInfo = _workFlowProcessFinder.GetCurrentStep(instance.WorkFlowInstanceId, CurrentUser.SystemUserId); if (processInfo != null) { if (!processInfo.FormId.Equals(Guid.Empty)) { formEntity = _systemFormFinder.FindById(processInfo.FormId); } } } } m.WorkFlowProcessState = processState; } if (formEntity == null) { if (args.FormId.HasValue && !args.FormId.Value.Equals(Guid.Empty)) { formEntity = _systemFormFinder.FindById(args.FormId.Value); if (formEntity.StateCode != RecordState.Enabled) { formEntity = null; } } else { //获取实体默认表单 formEntity = _systemFormFinder.FindEntityDefaultForm(args.EntityId); } } if (formEntity == null) { return(JError(T["notfound_defaultform"])); } m.FormInfo = formEntity; m.FormId = formEntity.SystemFormId; FormBuilder formBuilder = new FormBuilder(formEntity.FormConfig); _formService.Init(formEntity); //表单可用状态 if (!isCreate && m.FormState != FormState.Disabled && formBuilder.Form.FormRules.NotEmpty()) { if (_systemFormStatusSetter.IsDisabled(formBuilder.Form.FormRules, m.Entity)) { m.FormState = FormState.Disabled; } } //获取所有字段信息 m.AttributeList = _formService.AttributeMetaDatas; //获取字段权限 if (!CurrentUser.IsSuperAdmin && m.AttributeList.Count(n => n.AuthorizationEnabled) > 0) { var securityFields = m.AttributeList.Where(n => n.AuthorizationEnabled).Select(f => f.AttributeId)?.ToList(); if (securityFields.NotEmpty()) { //无权限的字段 var noneRead = _systemUserPermissionService.GetNoneReadFields(CurrentUser.SystemUserId, securityFields); var noneEdit = _systemUserPermissionService.GetNoneEditFields(CurrentUser.SystemUserId, securityFields); //移除无读取权限的字段内容 if (m.Entity.NotEmpty()) { foreach (var item in noneRead) { m.Entity.Remove(m.AttributeList.Find(n => n.AttributeId == item).Name); } } var obj = new { noneread = noneRead, noneedit = noneEdit }; nonePermissionFields = obj.SerializeToJson(); } } else { nonePermissionFields = "[]"; } var _form = formBuilder.Form; m.Form = _form; form = _formService.Form.SerializeToJson(false); //buttons var buttons = _ribbonbuttonFinder.Find(m.EntityId.Value, RibbonButtonArea.Form); if (formEntity.IsCustomButton && formEntity.CustomButtons.IsNotEmpty()) { List <Guid> buttonid = new List <Guid>(); buttonid = buttonid.DeserializeFromJson(formEntity.CustomButtons); buttons.RemoveAll(x => !buttonid.Contains(x.RibbonButtonId)); } if (buttons.NotEmpty()) { buttons = buttons.OrderBy(x => x.DisplayOrder).ToList(); m.RibbonButtons = buttons; _ribbonButtonStatusSetter.Set(m.RibbonButtons, m.FormState, m.Entity); } if (isCreate) { var rep = _roleObjectAccessEntityPermissionService.FindUserPermission(m.EntityMetaData.Name, CurrentUser.LoginName, AccessRightValue.Create); m.HasBasePermission = rep != null && rep.AccessRightsMask != EntityPermissionDepth.None; } else { var rep = _roleObjectAccessEntityPermissionService.FindUserPermission(m.EntityMetaData.Name, CurrentUser.LoginName, AccessRightValue.Update); m.HasBasePermission = rep != null && rep.AccessRightsMask != EntityPermissionDepth.None; } m.SnRule = _serialNumberRuleFinder.FindByEntityId(args.EntityId); if (m.SnRule != null && m.Entity.NotEmpty() && args.CopyId.HasValue) { m.Entity.SetAttributeValue(m.SnRule.AttributeName, null); } records = m.Entity.SerializeToJson(); m.StageId = args.StageId; m.BusinessFlowId = args.BusinessFlowId; m.BusinessFlowInstanceId = args.BusinessFlowInstanceId; return(JOk(new { EditRecord = m, NonePermissionFields = nonePermissionFields, Form = form, Record = records })); }