Merge pull request 'aq982' (#273) from aq982 into v2
Reviewed-on: https://code.adminnet.top/Admin.NET/Admin.NET.Pro/pulls/273
This commit is contained in:
commit
5860e4e1e1
@ -91,7 +91,7 @@ public class AggregationBuilder
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 验证字段有效性
|
/// 验证字段有效性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static List<string> ValidateFields(string[] fields, Type targetType)
|
public static List<string> ValidateFields<T>(string[] fields, Type targetType)
|
||||||
{
|
{
|
||||||
if (fields == null || fields.Length == 0) return new List<string>();
|
if (fields == null || fields.Length == 0) return new List<string>();
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ public class AggregationBuilder
|
|||||||
.Where(f => !string.IsNullOrWhiteSpace(f))
|
.Where(f => !string.IsNullOrWhiteSpace(f))
|
||||||
.Select(f => f.Trim())
|
.Select(f => f.Trim())
|
||||||
.Where(f => targetType.GetProperty(
|
.Where(f => targetType.GetProperty(
|
||||||
targetType == typeof(UsagetokenOutput) ?
|
targetType == typeof(T) ?
|
||||||
$"{f}Sum" : f) != null)
|
$"{f}Sum" : f) != null)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,18 +36,28 @@ namespace @Model.NameSpace;
|
|||||||
[ApiDescriptionSettings(@(@Model.ProjectLastName)Const.GroupName, Name = "@(@Model.LowerClassName)", Order = 100)]
|
[ApiDescriptionSettings(@(@Model.ProjectLastName)Const.GroupName, Name = "@(@Model.LowerClassName)", Order = 100)]
|
||||||
public partial class @(@Model.ClassName)Service : IDynamicApiController, ITransient
|
public partial class @(@Model.ClassName)Service : IDynamicApiController, ITransient
|
||||||
{
|
{
|
||||||
|
private readonly SysCacheService _sysCacheService;//默认CacheService
|
||||||
|
private readonly UserManager _userManager;//默认用户管理
|
||||||
|
private readonly IEventPublisher _eventPublisher;//默认事件总线
|
||||||
private readonly SqlSugarRepository<@(@Model.ClassName)> _@(@Model.LowerClassName)Rep;
|
private readonly SqlSugarRepository<@(@Model.ClassName)> _@(@Model.LowerClassName)Rep;
|
||||||
@foreach (var column in Model.TableField){
|
@foreach (var column in Model.TableField){
|
||||||
if(@column.EffectType == "ForeignKey"||@column.EffectType == "ApiTreeSelector"){
|
if(@column.EffectType == "ForeignKey"||@column.EffectType == "ApiTreeSelector"){
|
||||||
|
if(@column.FkEntityName != @Model.ClassName){
|
||||||
@:private readonly SqlSugarRepository<@(@column.FkEntityName)> _@(@column.LowerFkEntityName)Rep;
|
@:private readonly SqlSugarRepository<@(@column.FkEntityName)> _@(@column.LowerFkEntityName)Rep;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private TypeAdapterConfig _typeAdapterConfig = TypeAdapterConfig.GlobalSettings;
|
private TypeAdapterConfig _typeAdapterConfig = TypeAdapterConfig.GlobalSettings;
|
||||||
|
|
||||||
public @(@Model.ClassName)Service(SqlSugarRepository<@(@Model.ClassName)> @(@Model.LowerClassName)Rep
|
public @(@Model.ClassName)Service(SqlSugarRepository<@(@Model.ClassName)> @(@Model.LowerClassName)Rep
|
||||||
|
,SysCacheService sysCacheService
|
||||||
|
, UserManager userManager
|
||||||
|
,IEventPublisher eventPublisher
|
||||||
@foreach (var column in Model.TableField){
|
@foreach (var column in Model.TableField){
|
||||||
if(@column.EffectType == "ForeignKey"||@column.EffectType == "ApiTreeSelector"){
|
if(@column.EffectType == "ForeignKey"||@column.EffectType == "ApiTreeSelector"){
|
||||||
|
if(@column.FkEntityName != @Model.ClassName){
|
||||||
@:,SqlSugarRepository<@(@column.FkEntityName)> @(@column.LowerFkEntityName)Rep
|
@:,SqlSugarRepository<@(@column.FkEntityName)> @(@column.LowerFkEntityName)Rep
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,10 +66,15 @@ public partial class @(@Model.ClassName)Service : IDynamicApiController, ITransi
|
|||||||
_@(@Model.LowerClassName)Rep = @(@Model.LowerClassName)Rep;
|
_@(@Model.LowerClassName)Rep = @(@Model.LowerClassName)Rep;
|
||||||
@foreach (var column in Model.TableField){
|
@foreach (var column in Model.TableField){
|
||||||
if(@column.EffectType == "ForeignKey"||@column.EffectType == "ApiTreeSelector"){
|
if(@column.EffectType == "ForeignKey"||@column.EffectType == "ApiTreeSelector"){
|
||||||
|
if(@column.FkEntityName != @Model.ClassName){
|
||||||
@:_@(@column.LowerFkEntityName)Rep = @(@column.LowerFkEntityName)Rep;
|
@:_@(@column.LowerFkEntityName)Rep = @(@column.LowerFkEntityName)Rep;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_typeAdapterConfig.ForType<T, @(@Model.ClassName)>().IgnoreNullValues(true);
|
_typeAdapterConfig.ForType<T, @(@Model.ClassName)>().IgnoreNullValues(true);
|
||||||
|
_sysCacheService = sysCacheService;
|
||||||
|
_eventPublisher = eventPublisher;
|
||||||
|
_userManager = userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -168,28 +183,28 @@ if (@column.ColumnKey == "True"){
|
|||||||
return await @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input).OrderBuilder(input).ToListAsync();
|
return await @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input).OrderBuilder(input).ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@if(@Model.TableField.Any(x=>x.Statistical == "Y")){
|
/// <summary>
|
||||||
@:/// <summary>
|
/// 获取@(@Model.BusName)
|
||||||
@:/// 获取@(@Model.BusName)
|
/// </summary>
|
||||||
@:/// </summary>
|
/// <param name="input"></param>
|
||||||
@:/// <param name="input"></param>
|
/// <returns></returns>
|
||||||
@:/// <returns></returns>
|
[ApiDescriptionSettings(Name = "GetTotalSum", Description = "获取@(@Model.BusName)统计", Order = 960), HttpPost]
|
||||||
@:[ApiDescriptionSettings(Name = "GetTotalSum", Description = "获取@(@Model.BusName)统计", Order = 960), HttpPost]
|
[DisplayName("获取@(@Model.BusName)统计")]
|
||||||
@:[DisplayName("获取@(@Model.BusName)统计")]
|
public async Task<List<@(@Model.ClassName)Output>> GetTotalSum(Page@(@Model.ClassName)Input input)
|
||||||
@:public async Task<List<@(@Model.ClassName)Output>> GetTotalSum(Page@(@Model.ClassName)Input input)
|
{
|
||||||
@:{
|
// 单次查询同时获取统计值
|
||||||
@:// 单次查询同时获取统计值
|
var querystats = @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input)
|
||||||
@:var querystats = @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input)
|
@if(@Model.TableField.Any(x=>x.IsGroupBy == "Y")){
|
||||||
@foreach (var column in Model.TableField){
|
@foreach (var column in Model.TableField){
|
||||||
if (@column.IsGroupBy == "Y"){
|
if (@column.IsGroupBy == "Y"){
|
||||||
@: .GroupByIF(input.GroupBy.Contains("@column.PropertyName"), u => u.@column.PropertyName)
|
@: .GroupByIF(input.GroupBy.Contains("@column.PropertyName"), u => u.@column.PropertyName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@: //.Having(it => SqlFunc.AggregateCount(it.Id) > 0)//聚合函数过滤
|
@: //.Having(it => SqlFunc.AggregateCount(it.Id) > 0)//聚合函数过滤
|
||||||
@: .Select(it => new @(@Model.ClassName)Output
|
}
|
||||||
@: {
|
.Select(it => new @(@Model.ClassName)Output
|
||||||
@: count = SqlFunc.AggregateCount(it.Id),
|
{
|
||||||
|
count = SqlFunc.AggregateCount(it.Id),
|
||||||
@foreach (var column in Model.TableField){
|
@foreach (var column in Model.TableField){
|
||||||
if (@column.IsGroupBy == "Y"){
|
if (@column.IsGroupBy == "Y"){
|
||||||
@: @(@column.PropertyName) = it.@(@column.PropertyName),
|
@: @(@column.PropertyName) = it.@(@column.PropertyName),
|
||||||
@ -198,10 +213,9 @@ if (@column.ColumnKey == "True"){
|
|||||||
@: @(@column.PropertyName) = SqlFunc.AggregateSum(it.@(@column.PropertyName)) ?? 0,
|
@: @(@column.PropertyName) = SqlFunc.AggregateSum(it.@(@column.PropertyName)) ?? 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@: });
|
});
|
||||||
@:return await querystats.ToListAsync();
|
return await querystats.ToListAsync();
|
||||||
@:}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据输入参数获取@(@Model.BusName)统计
|
/// 根据输入参数获取@(@Model.BusName)统计
|
||||||
@ -220,7 +234,7 @@ if (@column.ColumnKey == "True"){
|
|||||||
public async Task<List<@(@Model.ClassName)Output>> GetAggregTotalSum(Page@(@Model.ClassName)Input input)
|
public async Task<List<@(@Model.ClassName)Output>> GetAggregTotalSum(Page@(@Model.ClassName)Input input)
|
||||||
{
|
{
|
||||||
|
|
||||||
@:var query = @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input)
|
var query = @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input)
|
||||||
// 输入参数示例
|
// 输入参数示例
|
||||||
//input = new Page@(@Model.ClassName)Input
|
//input = new Page@(@Model.ClassName)Input
|
||||||
//{
|
//{
|
||||||
@ -253,7 +267,7 @@ if (@column.ColumnKey == "True"){
|
|||||||
// HAVING(SUM(cost) > 10000) AND(AVG(CAST(response_time AS FLOAT)) < 500)
|
// HAVING(SUM(cost) > 10000) AND(AVG(CAST(response_time AS FLOAT)) < 500)
|
||||||
|
|
||||||
// 处理分组字段
|
// 处理分组字段
|
||||||
var groupFields = AggregationBuilder.ValidateFields(input.GroupBy, typeof(@(@Model.ClassName)Output));
|
var groupFields = AggregationBuilder.ValidateFields<@(@Model.ClassName)Output>(input.GroupBy, typeof(@(@Model.ClassName)Output));
|
||||||
if (groupFields.Count > 0)
|
if (groupFields.Count > 0)
|
||||||
{
|
{
|
||||||
query = query.GroupBy(string.Join(",", groupFields));
|
query = query.GroupBy(string.Join(",", groupFields));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user