public bool Update(Schema.Domain.Entity entityMetadata, Entity data) { //exists summary field? var summaryFields = _attributeFinder.Query(n => n.Where(f => f.SummaryEntityId == entityMetadata.EntityId)); if (summaryFields.NotEmpty()) { foreach (var item in summaryFields) { var ae = new AttributeAggregateExpression(); ae = ae.DeserializeFromJson(item.SummaryExpression); if (!data.ContainsKey(ae.Field)) { continue; } if (ae.EntityName.IsCaseInsensitiveEqual(data.Name)) { var rs = _relationShipFinder.FindByName(ae.RelationshipName); _fieldValueUpdater.UpdateSummaryValue(entityMetadata, data, item, rs, ae); //字段公式计算 var formulaAttributes = _attributeFinder.FindByEntityName(rs.ReferencedEntityName).Where(n => n.ValueType == 2).ToList(); if (formulaAttributes.NotEmpty()) { _fieldValueUpdater.UpdateFormulaValue(rs.ReferencedEntityName, formulaAttributes, data.GetGuidValue(rs.ReferencedAttributeName)); } } } } return(true); }
public IActionResult Get(string name) { if (name.IsEmpty()) { return(NotFound()); } var result = _relationShipFinder.FindByName(name); return(JOk(result.SerializeToJson())); }
public Guid Create(AggregateRoot aggregateRoot, Guid?systemFormId = null, bool ignorePermissions = false) { AggregateRootMetaData aggRootMetaData = GetAggregateRootMetaData(aggregateRoot, systemFormId); var thisId = Guid.Empty; try { _organizationDataProvider.BeginTransaction(); InternalOnCreate(aggregateRoot, OperationStage.PreOperation, aggRootMetaData); //关联Id thisId = Guid.NewGuid(); foreach (var c in aggregateRoot.ChildEntities) { string name = c.Name, relationshipname = c.Relationshipname, refname = string.Empty; if (relationshipname.IsNotEmpty()) { var relationShipMetas = _relationShipFinder.FindByName(c.Relationshipname); if (null != relationShipMetas && relationShipMetas.ReferencedEntityId == c.Entityid) { refname = relationShipMetas.ReferencingAttributeName; } if (refname.IsNotEmpty()) { c.Entity.SetAttributeValue(refname, new EntityReference(aggregateRoot.MainEntity.Name, thisId)); } } } var childEntities = aggregateRoot.ChildEntities.Select(x => x.Entity).ToList(); var entityNames = childEntities.Select(n => n.Name).Distinct().ToList(); foreach (var item in entityNames) { var items = childEntities.Where(n => n.Name.IsCaseInsensitiveEqual(item)).ToList(); var creatingRecords = items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && n.GetIdValue().Equals(Guid.Empty)).ToList(); if (creatingRecords.NotEmpty()) { _dataCreater.CreateMany(creatingRecords); } } aggregateRoot.MainEntity.SetIdValue(thisId); _dataCreater.Create(aggregateRoot.MainEntity); InternalOnCreate(aggregateRoot, OperationStage.PostOperation, aggRootMetaData); _organizationDataProvider.CommitTransaction(); } catch (Exception e) { _organizationDataProvider.RollBackTransaction(); OnException(e); } return(thisId); }
public IActionResult EditEntityMap(Guid entitymapid) { var headEntityMap = _entityMapFinder.FindById(entitymapid); EditEntityMapModel model = new EditEntityMapModel { EntityMapId = entitymapid, EntityId = headEntityMap.TargetEntityId, TargetEntityMetaData = _entityFinder.FindById(headEntityMap.TargetEntityId), SourceEntityMetaData = _entityFinder.FindById(headEntityMap.SourceEntityId), Attributes = _attributeFinder.Query(n => n .Where(f => f.EntityId == headEntityMap.TargetEntityId && f.Name.NotIn(AttributeDefaults.SystemAttributes)).Sort(s => s.SortAscending(f => f.Name))), SolutionId = SolutionId.Value, //单据头 HeadEntityMap = headEntityMap, RelationShipName = headEntityMap.RelationShipName, HeadAttributeMap = _attributeMapFinder.Query(n => n.Where(f => f.EntityMapId == headEntityMap.EntityMapId)), SourceEntityId = headEntityMap.SourceEntityId, MapType = headEntityMap.MapType }; model.HeadRelationShip = _relationShipFinder.FindByName(model.RelationShipName); //单据体 var childEntityMap = _entityMapFinder.FindByParentId(headEntityMap.EntityMapId); if (childEntityMap != null) { model.ChildEntityMap = childEntityMap; model.ChildRelationShipName = childEntityMap.RelationShipName; model.ChildTargetEntityMetaData = _entityFinder.FindById(childEntityMap.TargetEntityId); model.ChildSourceEntityMetaData = _entityFinder.FindById(childEntityMap.SourceEntityId); model.ChildAttributeMap = _attributeMapFinder.Query(n => n.Where(f => f.EntityMapId == childEntityMap.EntityMapId)); model.ChildTargetEntityId = childEntityMap.TargetEntityId; model.ChildSourceEntityId = childEntityMap.SourceEntityId; } return(View(model)); }
/// <summary> /// 过滤条件对话框 /// </summary> /// <returns></returns> public IActionResult FilterDialog([FromBody] FilterModel model, DialogModel dm) { ViewData["DialogModel"] = dm; if (model.Field.IsNotEmpty()) { //如果是关联表字段 if (model.Field.IndexOf('.') > 0) { var relationshipName = model.Field.Split('.')[0]; var field = model.Field.Split('.')[1]; //根据关系查询目标实体ID var relationship = _relationShipFinder.FindByName(relationshipName); model.AttributeMeta = _attributeFinder.Find(relationship.ReferencedEntityId, field); model.RelationShipMeta = relationship; } else { model.AttributeMeta = _attributeFinder.Find(model.EntityId, model.Field); } if (model.AttributeMeta == null) { return(NotFound()); } if (model.AttributeMeta.AttributeTypeName.IsCaseInsensitiveEqual(AttributeTypeIds.PICKLIST)) { model.AttributeMeta.OptionSet = _optionSetFinder.FindById(model.AttributeMeta.OptionSetId.Value); } if (model.AttributeMeta.AttributeTypeName.IsCaseInsensitiveEqual(AttributeTypeIds.BIT) || model.AttributeMeta.AttributeTypeName.IsCaseInsensitiveEqual(AttributeTypeIds.STATE)) { model.AttributeMeta.PickLists = _stringMapFinder.Query(n => n.Where(w => w.AttributeId == model.AttributeMeta.AttributeId)); } } return(View(model)); }
public IActionResult RenderGridView([FromBody] EntityGridModel model) { QueryView.Domain.QueryView queryView = null; if (model.QueryViewId.HasValue && !model.QueryViewId.Equals(Guid.Empty)) { queryView = _queryViewFinder.FindById(model.QueryViewId.Value); } else if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty)) { queryView = _queryViewFinder.FindEntityDefaultView(model.EntityId.Value); } else if (model.EntityName.IsNotEmpty()) { queryView = _queryViewFinder.FindEntityDefaultView(model.EntityName); } else { return(NotFound()); } if (queryView == null) { return(NotFound()); } if (!queryView.IsDefault && queryView.AuthorizationEnabled) { if (!_roleObjectAccessService.Exists(queryView.QueryViewId, QueryViewDefaults.ModuleName, CurrentUser.Roles.Select(n => n.RoleId).ToArray())) { return(Unauthorized()); } } model.QueryView = queryView; model.EntityId = queryView.EntityId; FetchDescriptor fetch = new FetchDescriptor { Page = model.Page, PageSize = model.PageSize, FetchConfig = queryView.FetchConfig, GetAll = !model.PagingEnabled }; if (model.IsSortBySeted) { QueryColumnSortInfo sort = new QueryColumnSortInfo(model.SortBy, model.SortDirection == 0); fetch.Sort = sort; } //查询关键字 if (model.Q.IsNotEmpty()) { fetch.Keyword = model.Q; fetch.Field = model.QField; } var canFetch = true; //filter by relationship if (model.RelationShipName.IsNotEmpty()) { var relationship = _relationShipFinder.FindByName(model.RelationShipName); if (relationship != null && model.ReferencedRecordId.HasValue && !model.ReferencedRecordId.Value.Equals(Guid.Empty)) { if (model.Filter == null) { model.Filter = new FilterExpression(); } var condition = new ConditionExpression(relationship.ReferencingAttributeName, ConditionOperator.Equal, model.ReferencedRecordId); model.Filter.AddCondition(condition); } model.RelationShipMeta = relationship; } if (model.RelationShipName.IsNotEmpty() && (!model.ReferencedRecordId.HasValue || model.ReferencedRecordId.Value.Equals(Guid.Empty))) { //如果被引用ID为空,则不查询数据 canFetch = false; } fetch.Filter = model.Filter; if (canFetch) { fetch.User = CurrentUser; var datas = _fetchService.Execute(fetch); if (model.OnlyData) { //var serializer = new DataContractJsonSerializer(typeof(User), new DataContractJsonSerializerSettings() //{ // UseSimpleDictionaryFormat = true//去掉Key和Value //}); //return new JsonResult() { Data = datas.Items.SerializeToJson(), JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return(Content(datas.SerializeToJson())); } model.Grid = _gridService.Build(queryView, _fetchService.QueryResolver.EntityList, _fetchService.QueryResolver.AttributeList); model.EntityList = _fetchService.QueryResolver.EntityList; model.AttributeList = _fetchService.QueryResolver.AttributeList; model.RelationShipList = _fetchService.QueryResolver.RelationShipList; model.Items = datas.Items; model.TotalItems = datas.TotalItems; } else { _fetchService.GetMetaDatas(fetch); model.Grid = _gridService.Build(queryView, _fetchService.QueryResolver.EntityList, _fetchService.QueryResolver.AttributeList); model.EntityList = _fetchService.QueryResolver.EntityList; model.AttributeList = _fetchService.QueryResolver.AttributeList; model.RelationShipList = _fetchService.QueryResolver.RelationShipList; model.Items = new List <dynamic>(); model.TotalItems = 0; } var buttons = _ribbonbuttonFinder.Find(model.EntityId.Value, RibbonButtonArea.SubGrid); if (buttons.NotEmpty()) { buttons = buttons.OrderBy(x => x.DisplayOrder).ToList(); model.RibbonButtons = buttons; } if (model.IsSortBySeted == false) { if (_fetchService.QueryExpression.Orders.NotEmpty()) { model.SortBy = _fetchService.QueryExpression.Orders[0].AttributeName; model.SortDirection = (int)_fetchService.QueryExpression.Orders[0].OrderType; } } return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model)); }
public async Task <IActionResult> Post([FromForm] SaveDataModel model) { if (model.EntityId.Equals(Guid.Empty)) { return(NotFound()); } var entityMetaData = _entityFinder.FindById(model.EntityId); if (entityMetaData == null) { return(NotFound()); } AggregateRoot aggregateRoot = new AggregateRoot(); var attributeMetaDatas = _attributeFinder.FindByEntityId(model.EntityId); bool isNew = !(model.RecordId.HasValue && !model.RecordId.Value.Equals(Guid.Empty)); var thisId = Guid.Empty; try { Core.Data.Entity entity = new Core.Data.Entity(entityMetaData.Name); dynamic headData = JObject.Parse(model.Data); foreach (JProperty p in headData) { var attr = attributeMetaDatas.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name)); if (attr != null && p.Value != null) { entity.SetAttributeValue(p.Name.ToString().ToLower(), entity.WrapAttributeValue(_entityFinder, attr, p.Value.ToString())); } } if (isNew) { thisId = Guid.NewGuid(); if (model.RelationShipName.IsNotEmpty() && model.ReferencedRecordId.HasValue)//如果存在关联关系 { var relationShipMetas = _relationShipFinder.FindByName(model.RelationShipName); if (null != relationShipMetas && relationShipMetas.ReferencingEntityId == model.EntityId && entity.GetStringValue(relationShipMetas.ReferencingAttributeName).IsEmpty()) { //设置当前记录关联字段的值 entity.SetAttributeValue(relationShipMetas.ReferencingAttributeName, new EntityReference(relationShipMetas.ReferencedEntityName, model.ReferencedRecordId.Value)); } } if (!model.StageId.Equals(Guid.Empty))//业务流程的阶段 { entity.SetAttributeValue("StageId", model.StageId); } //thisId = _dataCreater.Create(entity); if (!model.StageId.Equals(Guid.Empty))//业务流程的阶段 { _businessProcessFlowInstanceUpdater.UpdateForward(model.BusinessFlowId, model.BusinessFlowInstanceId, model.StageId, thisId); } } else { thisId = model.RecordId.Value; entity.SetIdValue(model.RecordId.Value); } aggregateRoot.MainEntity = entity; aggregateRoot.ChildEntities = new List <RefEntity>(); //单据体 if (model.Child.IsNotEmpty()) { var childs = JArray.Parse(model.Child.UrlDecode()); if (childs.Count > 0) { List <Core.Data.Entity> childEntities = new List <Core.Data.Entity>(); List <string> entityNames = new List <string>(); foreach (var c in childs) { dynamic root = JObject.Parse(c.ToString()); string name = root.name, relationshipname = root.relationshipname, refname = string.Empty; OperationTypeEnum?entitystatus = root.entitystatus; if (!entityNames.Exists(n => n.IsCaseInsensitiveEqual(name))) { entityNames.Add(name); } var data = root.data; var childAttributes = _attributeFinder.FindByEntityName(name); if (relationshipname.IsNotEmpty()) { var relationShipMetas = _relationShipFinder.FindByName(relationshipname); if (null != relationShipMetas && relationShipMetas.ReferencedEntityId == model.EntityId) { refname = relationShipMetas.ReferencingAttributeName; } } Core.Data.Entity detail = new Core.Data.Entity(name); RefEntity refEntity = new RefEntity() { Name = name, Relationshipname = relationshipname, Entityid = model.EntityId, Entitystatus = entitystatus }; foreach (JProperty p in data) { var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name)); if (attr != null && p.Value != null) { detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString())); } refEntity.Entity = detail; } //关联主记录ID if (refname.IsNotEmpty()) { detail.SetAttributeValue(refname, new EntityReference(entityMetaData.Name, thisId)); } aggregateRoot.ChildEntities.Add(refEntity); } } } //附件保存 var files = Request.Form.Files; if (files.Count > 0) { var result = await _attachmentCreater.CreateManyAsync(model.EntityId, thisId, files.ToList()).ConfigureAwait(false); for (int i = 0; i < files.Count; i++) { var attr = attributeMetaDatas.Find(n => n.Name.IsCaseInsensitiveEqual(files[i].Name)); if (attr != null) { var etAttachement = result.Where(x => x["Name"].ToString().IsCaseInsensitiveEqual(files[i].FileName)).First(); if (etAttachement != null) { entity.SetAttributeValue(files[i].Name, entity.WrapAttributeValue(_entityFinder, attr, etAttachement["CDNPath"].ToString())); } } } } if (isNew) { thisId = _aggCreater.Create(aggregateRoot, thisId, model.FormId); } else { _aggUpdater.Update(aggregateRoot, model.FormId); } } catch (Exception ex) { return(JError(ex.InnerException != null ? ex.InnerException.Message : ex.Message)); } if (isNew) { return(CreateSuccess(new { id = thisId })); } return(UpdateSuccess(new { id = thisId })); }
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 Post(SaveDataModel model) { if (model.EntityId.Equals(Guid.Empty)) { return(NotFound()); } var entityMetaData = _entityFinder.FindById(model.EntityId); if (entityMetaData == null) { return(NotFound()); } var attributeMetaDatas = _attributeFinder.FindByEntityId(model.EntityId); bool isNew = !(model.RecordId.HasValue && !model.RecordId.Value.Equals(Guid.Empty)); var thisId = Guid.Empty; try { Core.Data.Entity entity = new Core.Data.Entity(entityMetaData.Name); dynamic headData = JObject.Parse(model.Data); foreach (JProperty p in headData) { var attr = attributeMetaDatas.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name)); if (attr != null && p.Value != null) { entity.SetAttributeValue(p.Name.ToString().ToLower(), entity.WrapAttributeValue(_entityFinder, attr, p.Value.ToString())); } } if (isNew) { if (model.RelationShipName.IsNotEmpty() && model.ReferencedRecordId.HasValue)//如果存在关联关系 { var relationShipMetas = _relationShipFinder.FindByName(model.RelationShipName); if (null != relationShipMetas && relationShipMetas.ReferencingEntityId == model.EntityId && entity.GetStringValue(relationShipMetas.ReferencingAttributeName).IsEmpty()) { //设置当前记录关联字段的值 entity.SetAttributeValue(relationShipMetas.ReferencingAttributeName, new EntityReference(relationShipMetas.ReferencedEntityName, model.ReferencedRecordId.Value)); } } if (!model.StageId.Equals(Guid.Empty))//业务流程的阶段 { entity.SetAttributeValue("StageId", model.StageId); } thisId = _dataCreater.Create(entity); if (!model.StageId.Equals(Guid.Empty))//业务流程的阶段 { _businessProcessFlowInstanceUpdater.UpdateForward(model.BusinessFlowId, model.BusinessFlowInstanceId, model.StageId, thisId); } } else { thisId = model.RecordId.Value; entity.SetIdValue(model.RecordId.Value); _dataUpdater.Update(entity); } //单据体 if (model.Child.IsNotEmpty()) { var childs = JArray.Parse(model.Child.UrlDecode()); if (childs.Count > 0) { List <Core.Data.Entity> childEntities = new List <Core.Data.Entity>(); List <string> entityNames = new List <string>(); foreach (var c in childs) { dynamic root = JObject.Parse(c.ToString()); string name = root.name, relationshipname = root.relationshipname, refname = string.Empty; if (!entityNames.Exists(n => n.IsCaseInsensitiveEqual(name))) { entityNames.Add(name); } var data = root.data; var childAttributes = _attributeFinder.FindByEntityName(name); if (relationshipname.IsNotEmpty()) { var relationShipMetas = _relationShipFinder.FindByName(relationshipname); if (null != relationShipMetas && relationShipMetas.ReferencedEntityId == model.EntityId) { refname = relationShipMetas.ReferencingAttributeName; } } Core.Data.Entity detail = new Core.Data.Entity(name); foreach (JProperty p in data) { var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name)); if (attr != null && p.Value != null) { detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString())); } } //关联主记录ID if (refname.IsNotEmpty()) { detail.SetAttributeValue(refname, new EntityReference(entityMetaData.Name, thisId)); } childEntities.Add(detail); } //批量创建记录 if (childEntities.NotEmpty()) { foreach (var item in entityNames) { var items = childEntities.Where(n => n.Name.IsCaseInsensitiveEqual(item)).ToList(); var creatingRecords = items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && n.GetIdValue().Equals(Guid.Empty)).ToList(); if (creatingRecords.NotEmpty()) { _dataCreater.CreateMany(creatingRecords); } if (!isNew) { foreach (var updItem in items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && !n.GetIdValue().Equals(Guid.Empty))) { _dataUpdater.Update(updItem); } } } } } } } catch (Exception ex) { return(JError(ex.InnerException != null ? ex.InnerException.Message : ex.Message)); } if (isNew) { return(CreateSuccess(new { id = thisId })); } return(UpdateSuccess(new { id = thisId })); }
public IActionResult Post([FromBody] EntityGridModel model) { QueryView.Domain.QueryView queryView = null; if (model.QueryViewId.HasValue && !model.QueryViewId.Equals(Guid.Empty)) { queryView = _queryViewFinder.FindById(model.QueryViewId.Value); } else if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty)) { queryView = _queryViewFinder.FindEntityDefaultView(model.EntityId.Value); } else if (model.EntityName.IsNotEmpty()) { queryView = _queryViewFinder.FindEntityDefaultView(model.EntityName); } else { return(NotFound()); } if (queryView == null) { return(NotFound()); } if (!queryView.IsDefault && queryView.AuthorizationEnabled) { if (!_roleObjectAccessService.Exists(queryView.QueryViewId, QueryViewDefaults.ModuleName, CurrentUser.Roles.Select(n => n.RoleId).ToArray())) { return(Unauthorized()); } } model.QueryView = queryView; model.EntityId = queryView.EntityId; FetchDescriptor fetch = new FetchDescriptor { Page = model.Page, PageSize = model.PageSize, FetchConfig = queryView.FetchConfig, GetAll = !model.PagingEnabled }; if (model.IsSortBySeted) { QueryColumnSortInfo sort = new QueryColumnSortInfo(model.SortBy, model.SortDirection == 0); fetch.Sort = sort; } //查询关键字 if (model.Q.IsNotEmpty()) { fetch.Keyword = model.Q; fetch.Field = model.QField; } var canFetch = true; //filter by relationship if (model.RelationShipName.IsNotEmpty()) { var relationship = _relationShipFinder.FindByName(model.RelationShipName); if (relationship != null && model.ReferencedRecordId.HasValue && !model.ReferencedRecordId.Value.Equals(Guid.Empty)) { if (model.Filter == null) { model.Filter = new FilterExpression(); } var condition = new ConditionExpression(relationship.ReferencingAttributeName, ConditionOperator.Equal, model.ReferencedRecordId); model.Filter.AddCondition(condition); } model.RelationShipMeta = relationship; } if (model.RelationShipName.IsNotEmpty() && (!model.ReferencedRecordId.HasValue || model.ReferencedRecordId.Value.Equals(Guid.Empty))) { //如果被引用ID为空,则不查询数据 canFetch = false; } fetch.Filter = model.Filter; if (canFetch) { fetch.User = CurrentUser; var fetchDatas = _fetchService.Execute(fetch); object aggregateDatas = null; if (queryView.AggregateConfig.IsNotEmpty()) { var aggFields = new List <AggregateExpressionField>().DeserializeFromJson(queryView.AggregateConfig); if (aggFields.NotEmpty()) { var queryExp = new QueryExpression().DeserializeFromJson(queryView.FetchConfig); if (model.Filter != null && (model.Filter.Conditions.NotEmpty() || (model.Filter.Filters.NotEmpty() && model.Filter.Filters.First().Conditions.NotEmpty()))) { queryExp.Criteria.AddFilter(model.Filter); } var aggExp = new AggregateExpression { ColumnSet = queryExp.ColumnSet, Criteria = queryExp.Criteria, EntityName = queryExp.EntityName, LinkEntities = queryExp.LinkEntities, AggregateFields = aggFields }; var aggDatas = _aggregateService.Execute(aggExp); var attributes = _attributeFinder.FindByName(queryView.EntityId, aggFields.Select(x => x.AttributeName).ToArray()); foreach (dynamic item in aggDatas) { var line = item as IDictionary <string, object>; var attribute = attributes.Find(x => x.Name.IsCaseInsensitiveEqual(line.Keys.First())); item.metadata = new { attribute.Name, attribute.LocalizedName, attribute.AttributeTypeName, attribute.EntityId, attribute.EntityName, attribute.EntityLocalizedName }; item.aggregatetype = aggFields.Find(x => x.AttributeName.IsCaseInsensitiveEqual(attribute.Name)).AggregateType; } aggregateDatas = new { View = new { queryView.QueryViewId, queryView.Name }, Data = aggDatas }; } } return(Content(new { FetchData = fetchDatas, AggregateData = aggregateDatas }.SerializeToJson())); } if (!model.IsSortBySeted) { if (_fetchService.QueryExpression.Orders.NotEmpty()) { model.SortBy = _fetchService.QueryExpression.Orders[0].AttributeName; model.SortDirection = (int)_fetchService.QueryExpression.Orders[0].OrderType; } } return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model)); }
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); }
public IActionResult RecordsDialog([FromBody] SelectEntityRecordsDialogModel model, DialogModel dm) { QueryView.Domain.QueryView queryView = null; if (model.QueryId.HasValue && !model.QueryId.Equals(Guid.Empty)) { queryView = _queryViewFinder.FindById(model.QueryId.Value); } else if (model.EntityId.HasValue && !model.EntityId.Equals(Guid.Empty)) { queryView = _queryViewFinder.FindEntityDefaultView(model.EntityId.Value); } else if (model.EntityName.IsNotEmpty()) { queryView = _queryViewFinder.FindEntityDefaultView(model.EntityName); } else { return(NotFound()); } if (queryView == null) { return(NotFound()); } model.QueryId = queryView.QueryViewId; model.QueryView = queryView; model.EntityId = queryView.EntityId; FetchDescriptor fetch = new FetchDescriptor { User = CurrentUser, Page = model.Page, PageSize = model.PageSize, FetchConfig = queryView.FetchConfig }; if (model.IsSortBySeted) { QueryColumnSortInfo sort = new QueryColumnSortInfo(model.SortBy, model.SortDirection == 0); fetch.Sort = sort; } if (model.Q.IsNotEmpty()) { fetch.Keyword = model.Q; fetch.Field = model.QField; } if (model.Filter == null) { model.Filter = new FilterExpression(); } //filter disabled records if (model.OnlyEnabledRecords) { if (model.Filter.Conditions.IsEmpty() || model.Filter.Conditions.Find(n => n.AttributeName.IsCaseInsensitiveEqual("statecode")) == null) { model.Filter.AddCondition("statecode", ConditionOperator.Equal, 1); } } //filter by relationship if (model.RelationShipName.IsNotEmpty()) { var relationship = _relationShipFinder.FindByName(model.RelationShipName); if (relationship != null && model.ReferencedRecordId.HasValue && !model.ReferencedRecordId.Value.Equals(Guid.Empty)) { var condition = new ConditionExpression(relationship.ReferencingAttributeName, ConditionOperator.Equal, model.ReferencedRecordId); model.Filter.AddCondition(condition); } model.RelationShipMeta = relationship; } fetch.Filter = model.Filter; var datas = _fetchDataService.Execute(fetch); model.Grid = _gridService.Build(queryView, _fetchDataService.QueryResolver.EntityList, _fetchDataService.QueryResolver.AttributeList); model.EntityList = _fetchDataService.QueryResolver.EntityList; model.AttributeList = _fetchDataService.QueryResolver.AttributeList; model.RelationShipList = _fetchDataService.QueryResolver.RelationShipList; model.Items = datas.Items; model.TotalItems = datas.TotalItems; if (model.IsSortBySeted == false) { if (_fetchDataService.QueryExpression.Orders.NotEmpty()) { model.SortBy = _fetchDataService.QueryExpression.Orders[0].AttributeName; model.SortDirection = (int)_fetchDataService.QueryExpression.Orders[0].OrderType; } } ViewData["DialogModel"] = dm; return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model)); }
public IActionResult Post([FromBody] EntityGridModel model) { QueryView.Domain.QueryView queryView = null; if (model.QueryViewId.HasValue && !model.QueryViewId.Equals(Guid.Empty)) { queryView = _queryViewFinder.FindById(model.QueryViewId.Value); } else if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty)) { queryView = _queryViewFinder.FindEntityDefaultView(model.EntityId.Value); } else if (model.EntityName.IsNotEmpty()) { queryView = _queryViewFinder.FindEntityDefaultView(model.EntityName); } else { return(NotFound()); } if (queryView == null) { return(NotFound()); } if (!queryView.IsDefault && queryView.AuthorizationEnabled) { if (!_roleObjectAccessService.Exists(queryView.QueryViewId, QueryViewDefaults.ModuleName, CurrentUser.Roles.Select(n => n.RoleId).ToArray())) { return(Unauthorized()); } } model.QueryView = queryView; model.EntityId = queryView.EntityId; FetchDescriptor fetch = new FetchDescriptor { Page = model.Page, PageSize = model.PageSize, FetchConfig = queryView.FetchConfig, GetAll = !model.PagingEnabled }; if (model.IsSortBySeted) { QueryColumnSortInfo sort = new QueryColumnSortInfo(model.SortBy, model.SortDirection == 0); fetch.Sort = sort; } //查询关键字 if (model.Q.IsNotEmpty()) { fetch.Keyword = model.Q; fetch.Field = model.QField; } var canFetch = true; //filter by relationship if (model.RelationShipName.IsNotEmpty()) { var relationship = _relationShipFinder.FindByName(model.RelationShipName); if (relationship != null && model.ReferencedRecordId.HasValue && !model.ReferencedRecordId.Value.Equals(Guid.Empty)) { if (model.Filter == null) { model.Filter = new FilterExpression(); } var condition = new ConditionExpression(relationship.ReferencingAttributeName, ConditionOperator.Equal, model.ReferencedRecordId); model.Filter.AddCondition(condition); } model.RelationShipMeta = relationship; } if (model.RelationShipName.IsNotEmpty() && (!model.ReferencedRecordId.HasValue || model.ReferencedRecordId.Value.Equals(Guid.Empty))) { //如果被引用ID为空,则不查询数据 canFetch = false; } fetch.Filter = model.Filter; if (canFetch) { fetch.User = CurrentUser; var datas = _fetchService.Execute(fetch); return(Content(datas.SerializeToJson())); } if (!model.IsSortBySeted) { if (_fetchService.QueryExpression.Orders.NotEmpty()) { model.SortBy = _fetchService.QueryExpression.Orders[0].AttributeName; model.SortDirection = (int)_fetchService.QueryExpression.Orders[0].OrderType; } } return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model)); }