public IActionResult Get(Guid id) { var entity = _dataFinder.RetrieveById("notice", id); if (entity.NotEmpty()) { //如果所有者等于当前用户,则设为已读 if (entity.GetGuidValue("ownerid").Equals(CurrentUser.SystemUserId)) { var updEntity = new Entity("notice"); updEntity.SetIdValue(id); updEntity.SetAttributeValue("isread", true); _dataUpdater.Update(updEntity); } //if (entity.GetStringValue("linkto").IsNotEmpty()) //{ // return Redirect("/" + XmsWebContext.OrganizationUniqueName + entity.GetStringValue("linkto")); //} //else //{ // return Redirect("/" + XmsWebContext.OrganizationUniqueName + "/entity/create?entityname=notice&recordid=" + id); //} return(JOk(entity)); } return(NotFound()); }
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 Merge(Guid entityid, Guid recordid1, Guid recordid2) { MergeModel model = new MergeModel(); if (entityid.Equals(Guid.Empty) || recordid1.Equals(Guid.Empty) || recordid2.Equals(Guid.Empty)) { return(JError(T["parameter_error"])); } model.EntityMetas = _entityFinder.FindById(entityid); model.Attributes = _attributeFinder.FindByEntityId(entityid); model.Record1 = _dataFinder.RetrieveById(model.EntityMetas.Name, recordid1); model.Record2 = _dataFinder.RetrieveById(model.EntityMetas.Name, recordid2); model.EntityId = entityid; model.RecordId1 = recordid1; model.RecordId2 = recordid2; return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model)); }
public async Task <IActionResult> Post(StartWorkFlowModel model) { if (ModelState.IsValid) { //实体元数据 var entityMetas = _entityFinder.FindById(model.EntityId); //查找记录 var entity = _dataFinder.RetrieveById(entityMetas.Name, model.RecordId); if (entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Processing) { return(JError(T["workflow_processing_notallowtwice"])); } if (entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Passed) { return(JError(T["workflow_stop_notallowtwice"])); } if (entity.GetIntValue("ProcessState", -1) != -1 && (entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Waiting || entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Disabled)) { return(JError(T["workflow_state_notallowtwice"])); } //找到审批流程 var workFlow = _workFlowFinder.FindById(model.WorkflowId); if (workFlow == null) { return(JError(T["workflow_notfound"])); } var result = await _workFlowStarter.StartAsync(new WorkFlowStartUpContext() { User = CurrentUser , ApplicantId = CurrentUser.SystemUserId , Description = model.Description , ObjectId = model.RecordId , EntityMetaData = entityMetas , WorkFlowMetaData = workFlow , ObjectData = entity , Attachments = model.Attachments != null ? model.Attachments.Count : 0 , AttachmentFiles = model.Attachments }).ConfigureAwait(false); if (!result.IsSuccess) { return(JError(result.Message)); } return(JOk(T["workflow_start_success"])); } return(JModelError(T["workflow_start_failure"])); }
public IActionResult UserSettings() { UserSettingsModel model = new UserSettingsModel(); model.EntityMeta = _entityFinder.FindByName("SystemUserSettings"); model.AttributesMeta = _attributeFinder.FindByEntityId(model.EntityMeta.EntityId); model.Languages = _languageService.Query(n => n.Sort(s => s.SortAscending(f => f.Name))); model.EntityDatas = _dataFinder.RetrieveById("SystemUserSettings", CurrentUser.SystemUserId); model.SystemUserSettingsId = model.EntityDatas.GetIdValue(); model.LanguageUniqueId = model.EntityDatas.GetIntValue("languageuniqueid"); model.PagingLimit = model.EntityDatas.GetIntValue("paginglimit"); model.CurrencyId = model.EntityDatas.GetGuidValue("TransactionCurrencyId"); model.EnabledNotification = model.EntityDatas.GetBoolValue("EnabledNotification"); return(View($"~/Views/User/{WebContext.ActionName}.cshtml", model)); }
public IActionResult Get(Guid id) { if (id.Equals(Guid.Empty)) { return(NotFound()); } EditOrganizationModel model = new EditOrganizationModel(); model.OrganizationId = id; model.EntityMeta = _entityFinder.FindByName("organization"); model.Attributes = _attributeFinder.FindByEntityId(model.EntityMeta.EntityId); model.LanguageList = _languageService.Query(n => n.Where(f => f.StateCode == RecordState.Enabled).Sort(s => s.SortAscending(f => f.UniqueId))); model.Datas = _dataFinder.RetrieveById("organization", id); model.Datas["manageridname"] = string.Empty; if (!model.Datas.GetGuidValue("managerid").Equals(Guid.Empty)) { var manager = _dataFinder.RetrieveById("systemuser", model.Datas.GetGuidValue("managerid")); if (manager != null && manager.Count > 0) { model.Datas["manageridname"] = manager.GetStringValue("name"); } } return(JOk(model)); }
public IActionResult RetrieveById([FromRoute] RetrieveByIdModel args) { if (args.EntityName.IsEmpty()) { return(JError("entityname is not specified")); } var entity = _entityFinder.FindByName(args.EntityName); if (entity == null) { return(JError("entityname is not found")); } var result = _dataFinder.RetrieveById(args.EntityName, args.Id); return(JOk(result)); }
public IActionResult StartWorkFlow(Guid entityId, Guid recordId) { StartWorkFlowModel model = new StartWorkFlowModel { EntityId = entityId, RecordId = recordId }; //实体元数据 var entityMetas = _entityFinder.FindById(model.EntityId); //查找记录 var entity = _dataFinder.RetrieveById(entityMetas.Name, model.RecordId); if (entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Processing) { return(JError(T["workflow_processing_notallowtwice"])); } if (entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Passed) { return(JError(T["workflow_stop_notallowtwice"])); } if (entity.GetIntValue("ProcessState", -1) != -1 && (entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Waiting || entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Disabled)) { return(JError(T["workflow_state_notallowtwice"])); } //找到审批流程 var wfs = _workFlowFinder.QueryAuthorized(model.EntityId, FlowType.Approval); if (wfs.IsEmpty()) { return(NotFound()); } model.WorkFlows = wfs; return(View($"~/Views/Flow/{WebContext.ActionName}.cshtml", 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 })); }
public AggregateRoot Retrieve(QueryBase request, bool ignorePermissions = false) { //查询单个实体,查询列表 //var entity = args.EntityId.Equals(Guid.Empty) ? _entityFinder.FindByName(args.EntityName) : _entityFinder.FindById(args.EntityId); //var record = _dataFinder.RetrieveById(entity.Name, args.RecordId.Value); string entityname = ""; Guid? recordId = null; Guid? formId = null; _aggregateRoot.MainEntity = _dataFinder.RetrieveById(entityname, recordId.Value); //表单列表 SystemForm formEntity = null; formEntity = _systemFormFinder.FindById(formId.Value); FormBuilder formBuilder = new FormBuilder(formEntity.FormConfig); List <PanelDescriptor> panelDescriptors = formBuilder.Form.Panels; foreach (var panel in panelDescriptors) { foreach (var section in panel.Sections) { foreach (var row in section.Rows) { foreach (var cell in row.Cells) { if (cell.Control.ControlType == FormControlType.SubGrid) { var param = (SubGridParameters)cell.Control.Parameters; //param.ViewId; //param.RelationshipName var queryView = _queryViewFinder.FindById(Guid.Parse(param.ViewId)); if (queryView != null) { //if (!queryView.IsDefault && queryView.IsAuthorization) { } FetchDescriptor fetch = new FetchDescriptor { //Page = model.Page, //PageSize = model.PageSize, //FetchConfig = queryView.FetchConfig, //GetAll = !model.PagingEnabled }; //排序,过滤 var relationship = _relationShipFinder.FindByName(param.RelationshipName); var filter = new FilterExpression(); var condition = new ConditionExpression(relationship.ReferencingAttributeName, ConditionOperator.Equal, recordId.Value); filter.AddCondition(condition); fetch.Filter = filter; fetch.User = User; var datas = _fetchService.Execute(fetch); //_aggregateRoot.grids.Add("", datas.Items); } } } } } } return(_aggregateRoot); }
public IActionResult UpdateProcessStage(UpdateProcessStageModel model) { if (model.EntityId.Equals(Guid.Empty) || model.RecordId.Equals(Guid.Empty) || model.WorkflowId.Equals(Guid.Empty) || model.StageId.Equals(Guid.Empty)) { return(JError(T["parameter_error"])); } var entityMeta = _entityFinder.FindById(model.EntityId); if (entityMeta == null) { return(NotFound()); } var flowInfo = _workFlowFinder.FindById(model.WorkflowId); if (flowInfo == null) { return(NotFound()); } var data = _dataFinder.RetrieveById(entityMeta.Name, model.RecordId); if (data.IsEmpty()) { return(NotFound()); } var stages = _processStageService.Query(n => n .Where(f => f.WorkFlowId == flowInfo.WorkFlowId) .Sort(s => s.SortAscending(f => f.StageOrder))); var currentStage = stages.Find(n => n.ProcessStageId == model.StageId); var entityIds = stages.Select(n => n.EntityId).Distinct().ToList(); int entityIndex = entityIds.FindIndex(n => n.Equals(currentStage.EntityId)) + 1; BusinessProcessFlowInstance bpfInstance = null; if (model.InstanceId.HasValue && !model.InstanceId.Value.Equals(Guid.Empty)) { bpfInstance = _businessProcessFlowInstanceService.Find(n => n.BusinessProcessFlowInstanceId == model.InstanceId && n.WorkFlowId == model.WorkflowId); if (bpfInstance == null) { return(NotFound()); } } if (bpfInstance == null) { bpfInstance = new BusinessProcessFlowInstance(); bpfInstance.BusinessProcessFlowInstanceId = Guid.NewGuid(); bpfInstance.WorkFlowId = model.WorkflowId; bpfInstance.ProcessStageId = currentStage.ProcessStageId; bpfInstance.Entity1Id = model.FromRecordId; bpfInstance.Entity2Id = model.RecordId; bpfInstance.ProcessEntityId = model.EntityId; _businessProcessFlowInstanceService.Create(bpfInstance); } else { var originalStage = stages.Find(n => n.ProcessStageId == bpfInstance.ProcessStageId); var isForward = currentStage.StageOrder > originalStage.StageOrder; if (isForward) { _businessProcessFlowInstanceUpdater.UpdateForward(model.WorkflowId, bpfInstance.BusinessProcessFlowInstanceId, model.StageId, model.RecordId); } //如果后退并且阶段不在同一实体,更新实例对应的记录id else if (!isForward) { if (!model.InstanceId.HasValue || model.InstanceId.Equals(Guid.Empty)) { return(JError(T["parameter_error"])); } _businessProcessFlowInstanceUpdater.UpdateBack(model.WorkflowId, model.InstanceId.Value, model.StageId, model.RecordId); } } //更新当前记录的业务阶段 var updData = new Entity(data.Name); updData.SetIdValue(data.GetIdValue()); updData.SetAttributeValue("stageid", model.StageId); _dataUpdater.Update(updData); return(SaveSuccess()); }
private Guid CreateFromMap_Copy(EntityMap entityMap, Guid sourceRecordId) { var headTargetEntityMeta = _entityFinder.FindById(entityMap.TargetEntityId); var headTargetAttributes = _attributeFinder.FindByEntityId(entityMap.TargetEntityId); //引用源实体的字段 var headRelationShipMeta = _relationShipFinder.FindByName(entityMap.RelationShipName); var refAttr = headTargetAttributes.Find(n => n.AttributeId == headRelationShipMeta.ReferencingAttributeId); if (entityMap.MapType == MapType.CopyOne) { //查询是否已生成记录 QueryExpression query_target = new QueryExpression(headTargetEntityMeta.Name, _languageId); query_target.ColumnSet.AddColumn(headTargetAttributes.Find(n => n.TypeIsPrimaryKey()).Name); query_target.Criteria.AddCondition(refAttr.Name, ConditionOperator.Equal, sourceRecordId); var existsRecord = _dataFinder.Retrieve(query_target); if (existsRecord.NotEmpty()) { OnException(_loc["entitymap_copyone_error"]); return(Guid.Empty); } } Guid newId = Guid.Empty; //源记录 var sourceRecord = _dataFinder.RetrieveById(entityMap.SourceEnttiyName, sourceRecordId); if (sourceRecord.IsEmpty()) { OnException(_loc["notfound_record"]); return(Guid.Empty); } //单据头 var attributeMaps = _attributeMapFinder.Query(n => n.Where(f => f.EntityMapId == entityMap.EntityMapId)); if (attributeMaps.IsEmpty()) { OnException(_loc["entitymap_emptyheadattributemap"]); return(Guid.Empty); } //单据体 var childEntityMap = _entityMapFinder.FindByParentId(entityMap.EntityMapId); //单据头字段元数据 var headSourceAttributes = _attributeFinder.FindByEntityId(entityMap.SourceEntityId); //新增单据头信息 Entity headEntity = new Entity(entityMap.TargetEnttiyName); foreach (var attrMap in attributeMaps) { if (!headSourceAttributes.Exists(n => n.AttributeId == attrMap.SourceAttributeId) || !headTargetAttributes.Exists(n => n.AttributeId == attrMap.TargetAttributeId)) { continue; } var attr = headTargetAttributes.Find(n => n.AttributeId == attrMap.TargetAttributeId); if (attr == null) { continue; } var value = sourceRecord[attrMap.SourceAttributeName]; if (value == null && attrMap.DefaultValue.IsNotEmpty()) { value = attrMap.DefaultValue; } headEntity.SetAttributeValue(attr.Name, sourceRecord.WrapAttributeValue(_entityFinder, attr, value)); } //关联来源单据ID headEntity.SetAttributeValue(refAttr.Name, sourceRecord.WrapAttributeValue(_entityFinder, refAttr, sourceRecord.GetIdValue())); try { _organizationDataProvider.BeginTransaction(); InternalOnMap(sourceRecord, headEntity, OperationStage.PreOperation, headTargetEntityMeta, headTargetAttributes); newId = _dataCreater.Create(headEntity); //新增单据体信息 if (childEntityMap != null) { var childAttributeMaps = _attributeMapFinder.Query(n => n.Where(f => f.EntityMapId == childEntityMap.EntityMapId)); if (childAttributeMaps.NotEmpty()) { var childTargetEntityMeta = _entityFinder.FindById(childEntityMap.TargetEntityId); var childTargetAttributesMeta = _attributeFinder.FindByEntityId(childEntityMap.TargetEntityId); var childSourceAttributesMeta = _attributeFinder.FindByEntityId(childEntityMap.SourceEntityId); var childRelationShips = childEntityMap.RelationShipName.SplitSafe(","); //源单据体与源单据头的关系 var childSourceRelationShipMeta = _relationShipFinder.FindByName(childRelationShips[0]); //目标单据体与目标单据头的关系 var childTargetRelationShipMeta = _relationShipFinder.FindByName(childRelationShips[1]); //源单据体数据 QueryExpression query_source = new QueryExpression(childEntityMap.SourceEnttiyName, _languageId); query_source.ColumnSet.AllColumns = true; var refKey = headSourceAttributes.Find(n => n.AttributeId == childSourceRelationShipMeta.ReferencedAttributeId).Name; query_source.Criteria.AddCondition(refKey, ConditionOperator.Equal, sourceRecordId); var childSourceRecords = _dataFinder.RetrieveAll(query_source); if (childSourceRecords.NotEmpty()) { //引用单据头的字段 var headRefAttr = childTargetAttributesMeta.Find(n => n.AttributeId == childTargetRelationShipMeta.ReferencingAttributeId); //引用源单据体的字段 var refSourceAttr = childTargetAttributesMeta.Find(n => n.ReferencedEntityId.HasValue && n.ReferencedEntityId.Value == childEntityMap.SourceEntityId); foreach (var item in childSourceRecords) { //目标单据体 Entity childTargetRecord = new Entity(childEntityMap.TargetEnttiyName); foreach (var attrMap in childAttributeMaps) { if (!childSourceAttributesMeta.Exists(n => n.AttributeId == attrMap.SourceAttributeId) || !childTargetAttributesMeta.Exists(n => n.AttributeId == attrMap.TargetAttributeId)) { continue; } var attr = childTargetAttributesMeta.Find(n => n.AttributeId == attrMap.TargetAttributeId); if (attr == null) { continue; } var value = item[attrMap.SourceAttributeName]; if (value == null && attrMap.DefaultValue.IsNotEmpty()) { value = attrMap.DefaultValue; } childTargetRecord.SetAttributeValue(attrMap.TargetAttributeName, sourceRecord.WrapAttributeValue(_entityFinder, attr, value)); } //关联来源单据体记录ID if (refSourceAttr != null) { childTargetRecord.SetAttributeValue(refSourceAttr.Name, sourceRecord.WrapAttributeValue(_entityFinder, refSourceAttr, item.GetIdValue())); } //单据头ID childTargetRecord.SetAttributeValue(headRefAttr.Name, sourceRecord.WrapAttributeValue(_entityFinder, headRefAttr, newId)); _dataCreater.Create(childTargetRecord); } } } } _organizationDataProvider.CommitTransaction(); InternalOnMap(sourceRecord, headEntity, OperationStage.PostOperation, headTargetEntityMeta, headTargetAttributes); } catch (Exception e) { _organizationDataProvider.RollBackTransaction(); newId = Guid.Empty; OnException(e); } return(newId); }
/// <summary> /// 获取当前处理者列表 /// </summary> /// <param name="instance"></param> /// <param name="handlerIdType"></param> /// <param name="handlers"></param> /// <param name="stepOrder"></param> /// <returns></returns> public List <Guid> GetCurrentHandlerId(WorkFlowInstance instance, WorkFlowProcess prevStep, int handlerIdType, string handlers) { var result = new List <Guid>(); try { var applicantUser = _dataFinder.RetrieveById("systemuser", instance.ApplicantId, ignorePermissions: true); switch (handlerIdType) { case 1: //所有成员 break; case 2: //指定成员 if (handlers.IsNotEmpty()) { List <WorkFlowStepHandler> handlerObjs = new List <WorkFlowStepHandler>().DeserializeFromJson(handlers); foreach (var item in handlerObjs) { if (item.Type == WorkFlowStepHandlerType.SystemUser) { result.Add(item.Id); } else if (item.Type == WorkFlowStepHandlerType.Team) { var queryTeam = new QueryExpression("TeamMembership", _currentUser.UserSettings.LanguageId); queryTeam.ColumnSet.AddColumn("SystemUserId"); queryTeam.Criteria.AddCondition("TeamId", ConditionOperator.Equal, item.Id); var teamMembers = _dataFinder.RetrieveAll(queryTeam, true); if (teamMembers.NotEmpty()) { result.AddRange(teamMembers.Select(n => n.GetGuidValue("SystemUserId"))); } } else if (item.Type == WorkFlowStepHandlerType.Roles) { QueryExpression query = new QueryExpression("SystemUserRoles"); query.AddColumns("SystemUserId"); query.Criteria.AddCondition("RoleId", ConditionOperator.Equal, item.Id); var userRolesData = _dataFinder.RetrieveAll(query, true); if (userRolesData.NotEmpty()) { result.AddRange(userRolesData.Select(n => n.GetGuidValue("SystemUserId"))); } } else if (item.Type == WorkFlowStepHandlerType.Post) { var queryTeam = new QueryExpression("SystemUser", _currentUser.UserSettings.LanguageId); queryTeam.ColumnSet.AddColumn("SystemUserId"); queryTeam.Criteria.AddCondition("PostId", ConditionOperator.Equal, item.Id); queryTeam.Criteria.AddCondition("statecode", ConditionOperator.Equal, 1); var teamMembers = _dataFinder.RetrieveAll(queryTeam, true); if (teamMembers.NotEmpty()) { result.AddRange(teamMembers.Select(n => n.GetGuidValue("SystemUserId"))); } } } } break; case 3: //发起人领导 var parentUserId = applicantUser.GetGuidValue("parentsystemuserid"); if (!parentUserId.Equals(Guid.Empty)) { result.Add(parentUserId); } break; case 4: //发起人部门负责人 var bmanager = _dataFinder.RetrieveById("businessunit", applicantUser.GetGuidValue("businessunitid")); var bmanagerId = bmanager.GetGuidValue("managerid"); if (!bmanagerId.Equals(Guid.Empty)) { result.Add(bmanagerId); } break; case 5: //发起人公司负责人 var orgmanager = _dataFinder.RetrieveById("organization", applicantUser.GetGuidValue("organizationid"), ignorePermissions: true); var orgmanagerId = orgmanager.GetGuidValue("managerid"); if (!orgmanagerId.Equals(Guid.Empty)) { result.Add(orgmanagerId); } break; case 6: //上一环节审核人领导 //var prevStepOrder = stepOrder - 1; //var prevStep = new WorkFlowStepService(this.User).Find(n => n.WorkFlowId == instance.WorkFlowId && n.StepOrder == prevStepOrder); if (prevStep != null) { var prevHandlers = GetCurrentHandlerId(instance, null, prevStep.HandlerIdType, prevStep.Handlers); foreach (var item in prevHandlers) { var prevHandledUsers = _dataFinder.RetrieveById("systemuser", item, ignorePermissions: true); var parentUserId2 = prevHandledUsers.GetGuidValue("parentsystemuserid"); if (!parentUserId2.Equals(Guid.Empty)) { result.Add(parentUserId2); } } } break; case 7: //发起人 result.Add(instance.ApplicantId); break; } } catch (Exception ex) { throw new XmsException(ex); } return(result.Distinct().ToList()); }
public virtual Entity FindById(Guid id) { return(_dataFinder.RetrieveById(EntityName, id)); }
public void HandleEvent(WorkFlowExecutedEvent eventMessage) { Entity user; var msg = string.Empty; if (eventMessage.Result.NextHandlerId.NotEmpty()) { foreach (var hid in eventMessage.Result.NextHandlerId) { //通知下一个处理人 user = _dataFinder.RetrieveById("systemuser", hid, ignorePermissions: true); //生成审批消息,文本或网页链接 msg = string.Format(_loc["workflow_newtasknotify"], eventMessage.Context.EntityMetaData.LocalizedName); //发送消息 foreach (var notifier in _notifies) { notifier.Send(new InternalNotifyBody() { TypeCode = 2 , Subject = msg , Content = "" , ToUserId = hid , LinkTo = "/entity/create?entityid=" + eventMessage.Context.EntityMetaData.EntityId + "&recordid=" + eventMessage.Context.InstanceInfo.ObjectId }); } } } else { //通知申请人 user = _dataFinder.RetrieveById("systemuser", eventMessage.Context.InstanceInfo.ApplicantId, ignorePermissions: true); if (eventMessage.Context.ProcessState == WorkFlowProcessState.Passed) { msg = string.Format(_loc["workflow_passednotify"], eventMessage.Context.EntityMetaData.LocalizedName); } else if (eventMessage.Context.ProcessState == WorkFlowProcessState.UnPassed) { msg = string.Format(_loc["workflow_unpassednotify"], eventMessage.Context.EntityMetaData.LocalizedName); } //发送消息 foreach (var notifier in _notifies) { notifier.Send(new InternalNotifyBody() { TypeCode = 1 , Subject = string.Format("您提交的【{0}】审批{1}", eventMessage.Context.EntityMetaData.LocalizedName, (eventMessage.Context.ProcessState == WorkFlowProcessState.Passed ? "通过" : "不通过")) , Content = msg , ToUserId = user.GetIdValue() , LinkTo = "/entity/create?entityid=" + eventMessage.Context.EntityMetaData.EntityId + "&recordid=" + eventMessage.Context.InstanceInfo.ObjectId }); } } }