修改服务端模板不选统计字段不增加自定义统计
This commit is contained in:
parent
a9ee6c893e
commit
99fdb86dcb
@ -215,7 +215,7 @@ if (@column.ColumnKey == "True"){
|
||||
});
|
||||
return await querystats.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据输入参数获取@(@Model.BusName)统计
|
||||
/// 支持双模式聚合配置:
|
||||
@ -264,29 +264,31 @@ if (@column.ColumnKey == "True"){
|
||||
// FROM...
|
||||
// GROUP BY department, project
|
||||
// HAVING(SUM(cost) > 10000) AND(AVG(CAST(response_time AS FLOAT)) < 500)
|
||||
@if(@Model.TableField.Any(x=>x.Statistical == "Y")){
|
||||
|
||||
// 处理分组字段
|
||||
var groupFields = AggregationBuilder.ValidateFields<@(@Model.ClassName)Output>(input.GroupBy, typeof(@(@Model.ClassName)Output));
|
||||
if (groupFields.Count > 0)
|
||||
{
|
||||
query = query.GroupBy(string.Join(",", groupFields));
|
||||
}
|
||||
// 构建聚合配置
|
||||
var aggregator = new AggregationBuilder(
|
||||
configs: input.Aggregations,
|
||||
entityType: typeof(@(@Model.ClassName)),
|
||||
outputType: typeof(@(@Model.ClassName)Output)
|
||||
);
|
||||
@:// 处理分组字段
|
||||
@:var groupFields = AggregationBuilder.ValidateFields<@(@Model.ClassName)Output>(input.GroupBy, typeof(@(@Model.ClassName)Output));
|
||||
@:if (groupFields.Count > 0)
|
||||
@:{
|
||||
@: query = query.GroupBy(string.Join(",", groupFields));
|
||||
@:}
|
||||
@:// 构建聚合配置
|
||||
@:var aggregator = new AggregationBuilder(
|
||||
@: configs: input.Aggregations,
|
||||
@: entityType: typeof(@(@Model.ClassName)),
|
||||
@: outputType: typeof(@(@Model.ClassName)Output)
|
||||
@:);
|
||||
|
||||
// 组合SELECT语句
|
||||
var selectParts = groupFields.Select(f => $"{f} AS {f}")
|
||||
.Concat(aggregator.SelectParts)
|
||||
.ToList();
|
||||
@:// 组合SELECT语句
|
||||
@:var selectParts = groupFields.Select(f => $"{f} AS {f}")
|
||||
@: .Concat(aggregator.SelectParts)
|
||||
@: .ToList();
|
||||
|
||||
// 应用HAVING条件
|
||||
if (aggregator.HavingConditions.Count > 0)
|
||||
{
|
||||
query = query.Having(string.Join(" AND ", aggregator.HavingConditions));
|
||||
@:// 应用HAVING条件
|
||||
@:if (aggregator.HavingConditions.Count > 0)
|
||||
@:{
|
||||
@: query = query.Having(string.Join(" AND ", aggregator.HavingConditions));
|
||||
@:}
|
||||
}
|
||||
// 执行查询
|
||||
return await query.Select<@(@Model.ClassName)Output>(string.Join(", ", selectParts))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user