Exemplo n.º 1
0
        public IActionResult KanbanView([FromBody, FromQuery] KanbanGridModel model)
        {
            if (model.AggregateField.IsEmpty() || model.GroupField.IsEmpty())
            {
                return(JError("请指定统计字段及分组字段"));
            }
            QueryView.Domain.QueryView queryView = null;
            if (model.QueryId.HasValue && !model.QueryId.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindById(model.QueryId.Value);
            }
            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;
            model.QueryId    = queryView.QueryViewId;
            model.EntityName = _entityFinder.FindById(model.EntityId.Value).Name;
            var attributes = new List <Schema.Domain.Attribute>();
            var aggAttr    = _attributeFinder.Find(model.EntityId.Value, model.AggregateField);

            attributes.Add(aggAttr);
            var queryExp = new QueryExpression();

            queryExp = queryExp.DeserializeFromJson(queryView.FetchConfig);
            var orderExp = new OrderExpression("createdon", OrderType.Descending);

            queryExp.Orders.Add(orderExp);
            Dictionary <string, AggregateType> attributeAggs = new Dictionary <string, AggregateType>();

            if (aggAttr.TypeIsInt() || aggAttr.TypeIsFloat() || aggAttr.TypeIsDecimal() || aggAttr.TypeIsMoney())
            {
                attributeAggs.Add(model.AggregateField, AggregateType.Sum);
                model.AggType = AggregateType.Sum;
            }
            else
            {
                attributeAggs.Add(model.AggregateField, AggregateType.Count);
                model.AggType = AggregateType.Count;
            }
            var datas = _aggregateService.Execute(queryExp, attributeAggs, new List <string>()
            {
                model.GroupField
            });

            model.Items = datas;
            queryExp.ColumnSet.Columns.Clear();
            queryExp.ColumnSet.AddColumns("createdon", model.AggregateField, model.GroupField, "ownerid");
            model.GroupingDatas = _aggregateService.GroupingTop(model.GroupingTop, model.GroupField, queryExp, orderExp);
            var groupAttr = _attributeFinder.Find(model.EntityId.Value, model.GroupField);

            groupAttr.OptionSet = _optionSetFinder.FindById(groupAttr.OptionSetId.Value);
            attributes.Add(groupAttr);
            model.AttributeList = attributes;
            return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model));
        }