Пример #1
0
        private void AddQueryColumns()
        {
            entityColumnsMap = new Dictionary <string, object>();
            EntitySchema entitySchema             = UserConnection.EntitySchemaManager.GetInstanceByName(SchemaName);
            string       primaryDisplayColumnName = entitySchema.FindPrimaryDisplayColumnName();
            string       primaryKeyColumnName     = entitySchema.GetPrimaryColumnName();
            string       primaryColumnAlias       = string.Empty;

            foreach (JObject columnItem in _columns)
            {
                string columnPath = DashboardDataUtils.GetColumnPath(columnItem);
                if (entityColumnsMap.ContainsKey(columnPath))
                {
                    continue;
                }
                EntitySchemaQueryColumn     column = AddQueryColumn(columnItem, columnPath);
                Dictionary <string, object> map    = MapColumn(column);
                entityColumnsMap[columnPath] = map;
                if (columnPath == primaryKeyColumnName)
                {
                    primaryColumnAlias = (string)map["valueAlias"];
                }
            }
            if (primaryColumnAlias.IsNullOrEmpty() && primaryKeyColumnName.IsNotNullOrEmpty())
            {
                EntitySchemaQueryColumn primaryKeyColumn = Esq.AddColumn(primaryKeyColumnName);
                entityColumnsMap[primaryKeyColumnName] = MapColumn(primaryKeyColumn);
            }
        }
Пример #2
0
        private EntitySchemaQueryColumn AddQueryColumn(JObject columnItem, string columnPath)
        {
            columnPath = DashboardDataUtils.ClearColumnPathSuffix(columnPath);
            string          filterData            = columnItem.Value <string>("serializedFilter");
            string          aggregationType       = columnItem.Value <string>("aggregationType");
            AggregationType columnAggregationType = AggregationType.None;

            if (!string.IsNullOrEmpty(aggregationType))
            {
                columnAggregationType = (AggregationType)Enum.Parse(typeof(AggregationType),
                                                                    aggregationType);
            }
            EntitySchemaQueryColumn column;

            if (columnAggregationType != AggregationType.None && !string.IsNullOrEmpty(filterData))
            {
                EntitySchemaQuery subQuery;
                column = Esq.AddColumn(columnPath, columnAggregationType.ToStrict(), out subQuery);
                var dashboardData = new BaseDashboardItemSelectBuilder(UserConnection, subQuery);
                dashboardData.AddFilterByJson(filterData);
            }
            else
            {
                column = Esq.AddColumn(columnPath);
                if (!string.IsNullOrEmpty(aggregationType))
                {
                    column.SummaryType = columnAggregationType;
                }
            }
            SetColumnOrder(columnItem, column);
            return(column);
        }
Пример #3
0
        public override Select Build()
        {
            entityColumnsMap = new Dictionary <string, object>();
            JObject xAxisConfig    = SerieConfig.Value <JObject>("xAxis");
            JObject yAxisConfig    = SerieConfig.Value <JObject>("yAxis");
            string  dateTimeFormat = Parameters.Value <string>("dateTimeFormat");

            if (HasDateTimeFormat)
            {
                AddDateTimeColumnsByFormat(dateTimeFormat);
                xAxisConfig["dateTimeFormat"] = dateTimeFormat;
            }
            else
            {
                EntitySchemaQueryColumn column = Esq.AddColumn(ColumnPath);
                entityColumnsMap[column.Name] = MapColumn(column);
                xAxisConfig["dataValueType"]  = GetColumnDataValueType(column);
                if (OrderByGroupField)
                {
                    ApplyColumnOrder(column);
                }
            }
            var useEmptyValue = Parameters.Value <string>("useEmptyValue");

            SerieConfig.Add(new JProperty("useEmptyValue", useEmptyValue));
            EntitySchemaQueryColumn aggregatedColumn = AddAggregatedColumn(yAxisConfig);

            if (!OrderByGroupField)
            {
                ApplyColumnOrder(aggregatedColumn);
            }
            var select = base.Build();

            return(select);
        }
Пример #4
0
        private EntitySchemaQueryColumn AddAggregatedColumn(JObject yAxisConfig)
        {
            AggregationType columnAggregationType = AggregationType.Count;
            string          aggregationType       = SerieParameters.Value <string>("func");

            if (!string.IsNullOrEmpty(aggregationType))
            {
                columnAggregationType = (AggregationType)Enum.Parse(typeof(AggregationType),
                                                                    aggregationType);
            }
            EntitySchemaQueryExpression columnExpression = EntitySchemaQuery.CreateSchemaColumnExpression(
                Esq.RootSchema, GroupColumnPath);

            columnExpression.UId = Guid.NewGuid();
            var queryFunction = new EntitySchemaAggregationQueryFunction(columnAggregationType.ToStrict(),
                                                                         columnExpression, Esq);

            if (columnAggregationType == AggregationType.Count)
            {
                queryFunction.AggregationEvalType = AggregationEvalType.Distinct;
            }
            EntitySchemaQueryColumn column = Esq.AddColumn(queryFunction);
            var columnMap = new Dictionary <string, object>();

            columnMap["valueAlias"]           = column.ValueExpression.Function.QueryAlias;
            columnMap["dataValueType"]        = columnExpression.SchemaColumn.DataValueType;
            entityColumnsMap[GroupColumnPath] = columnMap;
            yAxisConfig["dataValueType"]      = GetColumnDataValueType(columnExpression);
            return(column);
        }
Пример #5
0
        private void AddDateTimeColumnsByFormat(string dateTimeFormat)
        {
            SortedDictionary <int, string> dateTimeFormats = GetSortedDateTimeFormats(dateTimeFormat);
            int index = 0;

            foreach (int key in dateTimeFormats.Keys)
            {
                var    format = dateTimeFormats[key];
                string alias  = "DatePart" + index;
                EntitySchemaDatePartQueryFunctionInterval interval = DashboardDataUtils.GetDatePartInterval(format);
                EntitySchemaQueryExpression columnExpression       =
                    EntitySchemaQuery.CreateSchemaColumnExpression(Esq.RootSchema, ColumnPath);
                columnExpression.UId = Guid.NewGuid();
                var queryFunction = new EntitySchemaDatePartQueryFunction(Esq, interval, columnExpression);
                queryFunction.SpecifyQueryAlias(alias);
                columnExpression.ParentQuery = queryFunction.ParentQuery;
                var esqExpression = new EntitySchemaQueryExpression(queryFunction)
                {
                    UId = Guid.NewGuid()
                };
                EntitySchemaQueryColumn column = Esq.AddColumn(esqExpression.Function);
                var map = new Dictionary <string, object>();
                map["format"]           = format;
                map["valueAlias"]       = alias;
                entityColumnsMap[alias] = map;
                if (OrderByGroupField)
                {
                    ApplyColumnOrder(column);
                }
                index++;
            }
        }
Пример #6
0
        public override Select Build()
        {
            string columnPath = Parameters.Value <string>("columnName");

            if (string.IsNullOrEmpty(columnPath))
            {
                columnPath = Esq.RootSchema.PrimaryColumn.ColumnValueName;
            }
            EntitySchemaQueryExpression columnExpression = EntitySchemaQuery.CreateSchemaColumnExpression(
                Esq.RootSchema, columnPath);

            columnExpression.UId = Guid.NewGuid();
            AggregationType columnAggregationType = AggregationType.Count;
            string          aggregationType       = Parameters.Value <string>("aggregationType");

            if (!string.IsNullOrEmpty(aggregationType))
            {
                columnAggregationType = (AggregationType)Enum.Parse(typeof(AggregationType),
                                                                    aggregationType);
            }
            var queryFunction = new EntitySchemaAggregationQueryFunction(columnAggregationType.ToStrict(),
                                                                         columnExpression, Esq);

            ColumnDataValueType = GetColumnDataValueType(columnExpression);
            Esq.AddColumn(queryFunction);
            EntityColumnMap = new Dictionary <string, object>();
            EntityColumnMap["valueAlias"]    = queryFunction.QueryAlias;
            EntityColumnMap["dataValueType"] = columnExpression.SchemaColumn.DataValueType;
            string filterData = Parameters.Value <string>("filterData");

            AddFilterByJson(filterData);
            return(base.Build());
        }