コード例 #1
0
        public IActionResult Index(RelationShipsModel model)
        {
            if (!model.LoadData)
            {
                return(DynamicResult(model));
            }
            FilterContainer <Schema.Domain.RelationShip> filter = FilterContainerBuilder.Build <Schema.Domain.RelationShip>();

            if (model.Type == RelationShipType.OneToMany)
            {
                filter.And(n => n.ReferencedEntityId == model.EntityId);
            }
            else if (model.Type == RelationShipType.ManyToOne)
            {
                filter.And(n => n.ReferencingEntityId == model.EntityId);
            }
            else if (model.Type == RelationShipType.ManyToMany)
            {
                filter.And(n => n.ReferencingEntityId == model.EntityId);
            }

            if (model.GetAll)
            {
                model.Page     = 1;
                model.PageSize = WebContext.PlatformSettings.MaxFetchRecords;
            }
            else if (!model.PageSizeBySeted && CurrentUser.UserSettings.PagingLimit > 0)
            {
                model.PageSize = CurrentUser.UserSettings.PagingLimit;
            }
            model.PageSize = model.PageSize > WebContext.PlatformSettings.MaxFetchRecords ? WebContext.PlatformSettings.MaxFetchRecords : model.PageSize;
            PagedList <Schema.Domain.RelationShip> result = _relationShipFinder.QueryPaged(x => x
                                                                                           .Page(model.Page, model.PageSize)
                                                                                           .Where(filter)
                                                                                           .Sort(n => n.OnFile(model.SortBy).ByDirection(model.SortDirection)));

            _relationShipFinder.WrapLocalizedLabel(result.Items);
            model.Items      = result.Items;
            model.TotalItems = result.TotalItems;
            model.SolutionId = SolutionId.Value;
            model.Entity     = _entityFinder.FindById(model.EntityId);
            return(DynamicResult(model));
        }
コード例 #2
0
        public IActionResult BusinessProcess([FromBody] BusinessProcessArgsModel args)
        {
            if (args.EntityId.Equals(Guid.Empty) || args.RecordId.Equals(Guid.Empty))
            {
                return(JError(T["parameter_error"]));
            }
            var entityMeta = _entityFinder.FindById(args.EntityId);

            if (entityMeta == null)
            {
                return(NotFound());
            }
            if (!entityMeta.BusinessFlowEnabled)
            {
                return(JError(T["businessflow_disabled"]));
            }
            var data = this._dataFinder.RetrieveById(entityMeta.Name, args.RecordId);

            if (data.IsEmpty())
            {
                return(NotFound());
            }
            WorkFlow flowInfo = null;
            BusinessProcessFlowInstance flowInstance = null;
            List <ProcessStage>         stages       = null;
            Guid entityStageId = data.GetGuidValue("stageid");
            int  entityIndex   = 0;

            if (args.BusinessflowId.HasValue && !args.BusinessflowId.Equals(Guid.Empty))
            {
                flowInfo = _workFlowFinder.Find(n => n.WorkFlowId == args.BusinessflowId.Value);
            }
            else if (args.BusinessflowInstanceId.HasValue && !args.BusinessflowInstanceId.Value.Equals(Guid.Empty))
            {
                flowInstance = _businessProcessFlowInstanceService.FindById(args.BusinessflowInstanceId.Value);
                if (flowInstance != null)
                {
                    flowInfo = _workFlowFinder.Find(n => n.WorkFlowId == flowInstance.WorkFlowId);
                }
            }
            if (flowInfo == null)
            {
                var flowList = _workFlowFinder.QueryAuthorized(args.EntityId, FlowType.Business);
                flowInfo = flowList.NotEmpty() ? flowList.First() : null;
                if (flowInfo == null && !entityStageId.Equals(Guid.Empty))
                {
                    //查找当前实体所在阶段
                    var processstage = _processStageService.Find(n => n.ProcessStageId == entityStageId);
                    if (processstage == null)
                    {
                        return(NotFound());
                    }
                    flowInfo = _workFlowFinder.Find(n => n.WorkFlowId == processstage.WorkFlowId && n.StateCode == RecordState.Enabled);
                }
            }
            if (flowInfo == null)
            {
                return(Content(""));
            }
            stages = _processStageService.Query(n => n
                                                .Where(f => f.WorkFlowId == flowInfo.WorkFlowId)
                                                .Sort(s => s.SortAscending(f => f.StageOrder))
                                                );
            var entityIds = stages.Select(n => n.EntityId).Distinct().ToList();

            entityIndex = entityIds.FindIndex(n => n.Equals(args.EntityId)) + 1;
            //查询业务流程实例
            if (flowInstance == null)
            {
                if (entityIndex == 1)
                {
                    flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity1Id == args.RecordId);
                }

                if (entityIndex == 2)
                {
                    flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity2Id == args.RecordId);
                }

                if (entityIndex == 3)
                {
                    flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity3Id == args.RecordId);
                }

                if (entityIndex == 4)
                {
                    flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity4Id == args.RecordId);
                }

                if (entityIndex == 5)
                {
                    flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity5Id == args.RecordId);
                }
            }

            if (flowInstance != null)
            {
                entityStageId = flowInstance.ProcessStageId.Value;
            }
            BusinessProcessModel model = new BusinessProcessModel
            {
                EntityId             = args.EntityId,
                RecordId             = args.RecordId,
                Data                 = data,
                BusinessFlow         = flowInfo,
                BusinessFlowInstance = flowInstance,
                Stages               = stages
            };

            model.CurrentStageId = entityStageId.Equals(Guid.Empty) ? model.Stages.First().ProcessStageId : entityStageId;
            Dictionary <string, object>    steps      = new Dictionary <string, object>();
            List <Schema.Domain.Attribute> attributes = new List <Schema.Domain.Attribute>();

            foreach (var stage in model.Stages)
            {
                var st = new List <ProcessStep>();
                st = st.DeserializeFromJson(stage.Steps);
                steps.Add(stage.ProcessStageId.ToString(), st);
                var attrs = st.Select(f => f.AttributeName).ToList();
                attributes.AddRange(_attributeFinder.Query(n => n.Where(f => f.Name.In(attrs) && f.EntityId == stage.EntityId)));
            }
            model.Steps      = steps;
            model.Attributes = attributes;
            var related = model.Stages.Where(n => n.RelationshipName.IsNotEmpty()).ToList();

            if (related.NotEmpty())
            {
                var rnames = related.Select(f => f.RelationshipName).ToList();
                model.RelationShips = _relationShipFinder.Query(n => n.Where(f => f.Name.In(rnames)));
                _relationShipFinder.WrapLocalizedLabel(model.RelationShips);
            }
            if (model.BusinessFlowInstance != null)
            {
                var rsRecords = new Dictionary <string, object>();
                int i         = 1;
                foreach (var eid in entityIds)
                {
                    var eidMeta = _entityFinder.FindById(eid);
                    var filter  = new Dictionary <string, object>();
                    if (i == 1 && flowInstance.Entity1Id.HasValue && !flowInstance.Entity1Id.Value.Equals(Guid.Empty))
                    {
                        filter.Add(eidMeta.Name + "id", flowInstance.Entity1Id);
                    }

                    if (i == 2 && flowInstance.Entity2Id.HasValue && !flowInstance.Entity2Id.Value.Equals(Guid.Empty))
                    {
                        filter.Add(eidMeta.Name + "id", flowInstance.Entity2Id);
                    }

                    if (i == 3 && flowInstance.Entity3Id.HasValue && !flowInstance.Entity3Id.Value.Equals(Guid.Empty))
                    {
                        filter.Add(eidMeta.Name + "id", flowInstance.Entity3Id);
                    }

                    if (i == 4 && flowInstance.Entity4Id.HasValue && !flowInstance.Entity4Id.Value.Equals(Guid.Empty))
                    {
                        filter.Add(eidMeta.Name + "id", flowInstance.Entity4Id);
                    }

                    if (i == 5 && flowInstance.Entity5Id.HasValue && !flowInstance.Entity5Id.Value.Equals(Guid.Empty))
                    {
                        filter.Add(eidMeta.Name + "id", flowInstance.Entity5Id);
                    }

                    if (filter.Count > 0)
                    {
                        rsRecords.Add(eid.ToString(), _dataFinder.RetrieveByAttribute(eidMeta.Name, filter));
                    }
                    else
                    {
                        rsRecords.Add(eid.ToString(), null);
                    }

                    i++;
                }
                model.RelatedRecords = rsRecords;
            }
            return(View($"~/Views/Flow/{WebContext.ActionName}.cshtml", model));
        }
コード例 #3
0
        public MemoryStream ToExcelStream(QueryView.Domain.QueryView queryView, FilterExpression filter, OrderExpression order, string fileName, bool includePrimaryKey = false, bool includeIndex = false, string title = "")
        {
            _fetchDataService.GetMetaDatas(queryView.FetchConfig);
            if (filter != null)
            {
                _fetchDataService.QueryExpression.Criteria.AddFilter(filter);
            }
            if (order != null)
            {
                _fetchDataService.QueryExpression.Orders.Clear();
                _fetchDataService.QueryExpression.Orders.Add(order);
            }
            _fetchDataService.QueryExpression.PageInfo = new PagingInfo()
            {
                PageNumber = 1, PageSize = 99999
            };
            var data = _fetchDataService.Execute(_fetchDataService.QueryExpression);

            if (data.TotalItems == 0)
            {
                return(null);
            }
            Dictionary <string, string> columnNames = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            List <string> hideColumns = new List <string>();
            var           grid        = _gridService.Build(queryView, _fetchDataService.QueryResolver.EntityList, _fetchDataService.QueryResolver.AttributeList);

            if (includeIndex)
            {
                columnNames.Add("rownum", "序号");
                if (data.Items.NotEmpty())
                {
                    for (int i = 0; i < data.Items.Count; i++)
                    {
                        data.Items[i].RowNum = i + 1;
                    }
                }
            }
            if (includePrimaryKey)
            {
                var pk = _fetchDataService.QueryResolver.AttributeList.Find(n => n.EntityName.IsCaseInsensitiveEqual(_fetchDataService.QueryResolver.MainEntity.Name) && n.TypeIsPrimaryKey());//new Schema.AttributeService(user).Find(n => n.AttributeTypeName == AttributeTypeIds.PRIMARYKEY && n.EntityName == fetchService.QueryResolver.MainEntity.Name);
                columnNames.Add(pk.Name, pk.Name);
                hideColumns.Add(pk.Name);
            }
            foreach (var cell in grid.Rows[0].Cells)
            {
                var columnName = cell.Name.IndexOf(".") > 0 ? cell.Name.Split('.')[1] : cell.Name;
                var item       = _fetchDataService.QueryResolver.AttributeList.Find(n => n.Name.IsCaseInsensitiveEqual(columnName) && n.EntityName.IsCaseInsensitiveEqual(cell.EntityName));
                var label      = cell.Label;//item.LocalizedName;
                if (cell.Label.IsEmpty())
                {
                    if (!item.EntityId.Equals(_fetchDataService.QueryResolver.MainEntity.EntityId))
                    {
                        var le = _fetchDataService.QueryExpression.FindLinkEntityByName(item.EntityName);
                        if (le != null)
                        {
                            var relationship = _fetchDataService.QueryResolver.RelationShipList.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Name.Split('.')[0]));
                            _relationShipFinder.WrapLocalizedLabel(relationship);
                            label     += "(" + relationship.ReferencingAttributeLocalizedName + ")";
                            columnName = le.EntityAlias + "." + columnName;
                        }
                    }
                    else
                    {
                        label = item.LocalizedName;
                    }
                }
                if (item.TypeIsPrimaryKey())
                {
                    var pkField = _fetchDataService.QueryResolver.AttributeList.Find(n => n.EntityName.IsCaseInsensitiveEqual(_fetchDataService.QueryResolver.MainEntity.Name) && n.IsPrimaryField);
                    columnNames.Add(pkField.Name, label);
                }
                else if (item.TypeIsBit() || item.TypeIsState() || item.TypeIsStatus() || item.TypeIsPickList() || item.TypeIsLookUp() || item.TypeIsOwner() || item.TypeIsCustomer())
                {
                    columnNames.Add(cell.Name + "Name", label);
                }
                else
                {
                    columnNames.Add(cell.Name, label);
                }
            }
            //字段权限
            if (_fetchDataService.QueryResolver.AttributeList.Count(x => x.AuthorizationEnabled) > 0)
            {
                var noneRead = _systemUserPermissionService.GetNoneReadFields(_appContext.GetFeature <ICurrentUser>().SystemUserId, _fetchDataService.QueryResolver.AttributeList.Where(x => x.AuthorizationEnabled).Select(x => x.AttributeId).ToList());
                if (noneRead.NotEmpty())
                {
                    var noneReadAttrs = _attributeFinder.Query(x => x.Where(f => f.AttributeId.In(noneRead)));
                    foreach (var d in data.Items)
                    {
                        var _this = d as IDictionary <string, object>;
                        foreach (var nr in noneReadAttrs)
                        {
                            _this[nr.Name.ToLower()] = null;
                            if (nr.TypeIsBit() || nr.TypeIsState() || nr.TypeIsPickList() || nr.TypeIsStatus() ||
                                nr.TypeIsLookUp() || nr.TypeIsOwner() || nr.TypeIsCustomer())
                            {
                                _this[nr.Name.ToLower() + "name"] = null;
                            }
                        }
                    }
                }
            }
            var list = data.Items;

            //aggregation
            if (list.NotEmpty() && queryView.AggregateConfig.IsNotEmpty())
            {
                var aggFields = new List <AggregateExpressionField>().DeserializeFromJson(queryView.AggregateConfig);
                if (aggFields.NotEmpty())
                {
                    var aggExp = new AggregateExpression
                    {
                        ColumnSet       = _fetchDataService.QueryExpression.ColumnSet,
                        Criteria        = _fetchDataService.QueryExpression.Criteria,
                        EntityName      = _fetchDataService.QueryExpression.EntityName,
                        LinkEntities    = _fetchDataService.QueryExpression.LinkEntities,
                        AggregateFields = aggFields
                    };
                    var aggDatas = _aggregateService.Execute(aggExp);
                    var aggData  = aggDatas.NotEmpty() ? aggDatas.First() : null;
                    if (aggData != null)
                    {
                        var tmpRow     = list.First() as IDictionary <string, object>;
                        var aggRow     = new Dictionary <string, object>();
                        var aggDataRow = aggData as IDictionary <string, object>;
                        foreach (var r in tmpRow)
                        {
                            var aggf = aggFields.Find(n => n.AttributeName.IsCaseInsensitiveEqual(r.Key));
                            if (aggf != null)
                            {
                                aggRow[r.Key] = aggDataRow[aggf.AttributeName.ToLower()];
                            }
                            else
                            {
                                aggRow[r.Key] = null;
                            }
                        }
                        list.Add(aggRow);
                    }
                }
            }
            return(ToExcelStream(list, fileName, columnNames, hideColumns, title, _fetchDataService.QueryResolver.AttributeList));
        }
コード例 #4
0
ファイル: DataDeleter.cs プロジェクト: zzdxpq007/xms
        private bool DeleteCore(Schema.Domain.Entity entityMetadata, List <Schema.Domain.Attribute> attributeMetadatas, Entity record, bool ignorePermissions = false)
        {
            if (!ignorePermissions)
            {
                VerifyEntityPermission(record, AccessRightValue.Delete, entityMetadata);
            }
            //cascade relationship, 1: N
            var relationships = _relationShipFinder.Query(n => n
                                                          .Where(f => f.ReferencedEntityId == entityMetadata.EntityId)
                                                          );
            //check referenced
            var cascadeDeleteRestrict = relationships.Where(n => n.ReferencedEntityId == entityMetadata.EntityId && n.CascadeDelete == (int)CascadeDeleteType.Restrict && n.RelationshipType == RelationShipType.ManyToOne);

            var primaryAttr = attributeMetadatas.Find(n => n.TypeIsPrimaryKey());
            var primarykey  = primaryAttr.Name;

            record.IdName = primarykey;
            var recordId = record.GetIdValue();

            foreach (var cdr in cascadeDeleteRestrict)
            {
                var referencingRecord = _aggregateService.Count(cdr.ReferencingEntityName, new FilterExpression(LogicalOperator.And).AddCondition(cdr.ReferencingAttributeName, ConditionOperator.Equal, recordId));
                if (referencingRecord > 0)
                {
                    _relationShipFinder.WrapLocalizedLabel(cdr);
                    return(OnException(_loc["referenced"] + ": " + cdr.ReferencingEntityLocalizedName));
                }
            }
            var result = false;

            try
            {
                _organizationDataProvider.BeginTransaction();
                InternalOnDelete(record, OperationStage.PreOperation, entityMetadata, attributeMetadatas);
                //delete related records
                var cascadeDelete = relationships.Where(n => n.ReferencedEntityId == entityMetadata.EntityId && n.CascadeDelete == (int)CascadeDeleteType.All && n.RelationshipType == RelationShipType.ManyToOne).ToList();
                if (cascadeDelete.NotEmpty())
                {
                    DeleteRelatedRecords(entityMetadata, attributeMetadatas, cascadeDelete, recordId);
                }
                //delete main record
                result = _organizationDataProvider.Delete(record.Name, recordId, primarykey);
                if (result)
                {
                    //update maps
                    _mapUpdater.Update(entityMetadata, record, true);
                    _formulaUpdater.Update(entityMetadata, record);
                    _organizationDataProvider.CommitTransaction();
                    InternalOnDelete(record, OperationStage.PostOperation, entityMetadata, attributeMetadatas);
                }
                else
                {
                    _organizationDataProvider.RollBackTransaction();
                }
            }
            catch (Exception e)
            {
                _organizationDataProvider.RollBackTransaction();
                OnException(e);
            }

            return(result);
        }