修改(服务端)接口服务生成统计的错误,更灵活,增加默认缓存和事件
This commit is contained in:
parent
2df313c500
commit
abdab25e6e
@ -36,30 +36,45 @@ namespace @Model.NameSpace;
|
||||
[ApiDescriptionSettings(@(@Model.ProjectLastName)Const.GroupName, Name = "@(@Model.LowerClassName)", Order = 100)]
|
||||
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;
|
||||
@foreach (var column in Model.TableField){
|
||||
if(@column.EffectType == "ForeignKey"||@column.EffectType == "ApiTreeSelector"){
|
||||
if(@column.FkEntityName != @Model.ClassName){
|
||||
@:private readonly SqlSugarRepository<@(@column.FkEntityName)> _@(@column.LowerFkEntityName)Rep;
|
||||
}
|
||||
}
|
||||
}
|
||||
private TypeAdapterConfig _typeAdapterConfig = TypeAdapterConfig.GlobalSettings;
|
||||
|
||||
public @(@Model.ClassName)Service(SqlSugarRepository<@(@Model.ClassName)> @(@Model.LowerClassName)Rep
|
||||
,SysCacheService sysCacheService
|
||||
, UserManager userManager
|
||||
,IEventPublisher eventPublisher
|
||||
@foreach (var column in Model.TableField){
|
||||
if(@column.EffectType == "ForeignKey"||@column.EffectType == "ApiTreeSelector"){
|
||||
if(@column.FkEntityName != @Model.ClassName){
|
||||
@:,SqlSugarRepository<@(@column.FkEntityName)> @(@column.LowerFkEntityName)Rep
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
)
|
||||
{
|
||||
_@(@Model.LowerClassName)Rep = @(@Model.LowerClassName)Rep;
|
||||
@foreach (var column in Model.TableField){
|
||||
if(@column.EffectType == "ForeignKey"||@column.EffectType == "ApiTreeSelector"){
|
||||
if(@column.FkEntityName != @Model.ClassName){
|
||||
@:_@(@column.LowerFkEntityName)Rep = @(@column.LowerFkEntityName)Rep;
|
||||
}
|
||||
}
|
||||
}
|
||||
_typeAdapterConfig.ForType<T, @(@Model.ClassName)>().IgnoreNullValues(true);
|
||||
_sysCacheService = sysCacheService;
|
||||
_eventPublisher = eventPublisher;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -168,28 +183,28 @@ if (@column.ColumnKey == "True"){
|
||||
return await @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input).OrderBuilder(input).ToListAsync();
|
||||
}
|
||||
|
||||
@if(@Model.TableField.Any(x=>x.Statistical == "Y")){
|
||||
@:/// <summary>
|
||||
@:/// 获取@(@Model.BusName)
|
||||
@:/// </summary>
|
||||
@:/// <param name="input"></param>
|
||||
@:/// <returns></returns>
|
||||
@:[ApiDescriptionSettings(Name = "GetTotalSum", Description = "获取@(@Model.BusName)统计", Order = 960), HttpPost]
|
||||
@:[DisplayName("获取@(@Model.BusName)统计")]
|
||||
@:public async Task<List<@(@Model.ClassName)Output>> GetTotalSum(Page@(@Model.ClassName)Input input)
|
||||
@:{
|
||||
@:// 单次查询同时获取统计值
|
||||
@:var querystats = @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input)
|
||||
/// <summary>
|
||||
/// 获取@(@Model.BusName)
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[ApiDescriptionSettings(Name = "GetTotalSum", Description = "获取@(@Model.BusName)统计", Order = 960), HttpPost]
|
||||
[DisplayName("获取@(@Model.BusName)统计")]
|
||||
public async Task<List<@(@Model.ClassName)Output>> GetTotalSum(Page@(@Model.ClassName)Input 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){
|
||||
if (@column.IsGroupBy == "Y"){
|
||||
@: .GroupByIF(input.GroupBy.Contains("@column.PropertyName"), u => u.@column.PropertyName)
|
||||
}
|
||||
}
|
||||
@: //.Having(it => SqlFunc.AggregateCount(it.Id) > 0)//聚合函数过滤
|
||||
@: .Select(it => new @(@Model.ClassName)Output
|
||||
@: {
|
||||
@: count = SqlFunc.AggregateCount(it.Id),
|
||||
|
||||
}
|
||||
.Select(it => new @(@Model.ClassName)Output
|
||||
{
|
||||
count = SqlFunc.AggregateCount(it.Id),
|
||||
@foreach (var column in Model.TableField){
|
||||
if (@column.IsGroupBy == "Y"){
|
||||
@: @(@column.PropertyName) = it.@(@column.PropertyName),
|
||||
@ -198,9 +213,8 @@ if (@column.ColumnKey == "True"){
|
||||
@: @(@column.PropertyName) = SqlFunc.AggregateSum(it.@(@column.PropertyName)) ?? 0,
|
||||
}
|
||||
}
|
||||
@: });
|
||||
@:return await querystats.ToListAsync();
|
||||
@:}
|
||||
});
|
||||
return await querystats.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -220,7 +234,7 @@ if (@column.ColumnKey == "True"){
|
||||
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
|
||||
//{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user