From 99fdb86dcb40c315004d222f5c29fc63271fd9da Mon Sep 17 00:00:00 2001 From: aq982 Date: Tue, 4 Mar 2025 23:34:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E4=B8=8D=E9=80=89=E7=BB=9F=E8=AE=A1=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E4=B8=8D=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/template/service_Service.cs.vm | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/service_Service.cs.vm b/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/service_Service.cs.vm index 084ab550..2621b7c8 100644 --- a/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/service_Service.cs.vm +++ b/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/service_Service.cs.vm @@ -215,7 +215,7 @@ if (@column.ColumnKey == "True"){ }); return await querystats.ToListAsync(); } - + /// /// 根据输入参数获取@(@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))