From a9ee6c893ed8b2587ab9495a398e4cd76db7fea2 Mon Sep 17 00:00:00 2001 From: aq982 Date: Tue, 4 Mar 2025 23:28:08 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9PartialEntity=5FEntity?= =?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=BE=93=E5=85=A5=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/template/PartialEntity_Entity.cs.vm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/PartialEntity_Entity.cs.vm b/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/PartialEntity_Entity.cs.vm index 513b0a7e..35552644 100644 --- a/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/PartialEntity_Entity.cs.vm +++ b/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/PartialEntity_Entity.cs.vm @@ -41,8 +41,10 @@ public partial class @(@Model.ClassName)Output /// public partial class Page@(@Model.ClassName)Input { - public string[] GroupBy { get; set; } - public string[] Sum { get; set; } - public IEnumerable Aggregations { get; set; } + @if(@Model.TableField.Any(x=>x.Statistical == "Y")){ + @:public string[] GroupBy { get; set; } + @:public string[] Sum { get; set; } + @:public IEnumerable Aggregations { get; set; } + } } From 99fdb86dcb40c315004d222f5c29fc63271fd9da Mon Sep 17 00:00:00 2001 From: aq982 Date: Tue, 4 Mar 2025 23:34:30 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=AB=AF=E6=A8=A1=E6=9D=BF=E4=B8=8D=E9=80=89=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=B8=8D=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=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)) From 4c6b34d1f7f43933166f588d7010ab5ea4fb321c Mon Sep 17 00:00:00 2001 From: aq982 Date: Tue, 4 Mar 2025 23:37:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=AB=AF=E6=A8=A1=E6=9D=BF=E4=B8=8D=E9=80=89=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=B8=8D=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 2621b7c8..62c05cf7 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 @@ -289,10 +289,14 @@ if (@column.ColumnKey == "True"){ @:{ @: query = query.Having(string.Join(" AND ", aggregator.HavingConditions)); @:} + + @:// 执行查询 + @:return await query.Select<@(@Model.ClassName)Output>(string.Join(", ", selectParts)).ToListAsync(); + } + else + { + @:return await query.ToListAsync(); } - // 执行查询 - return await query.Select<@(@Model.ClassName)Output>(string.Join(", ", selectParts)) - .ToListAsync(); } @foreach (var column in Model.TableField){