@ -6,6 +6,7 @@ using System.Linq.Dynamic.Core;
using System.Linq.Expressions ;
using System.Linq.Expressions ;
using System.Threading ;
using System.Threading ;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
using AutoMapper ;
using Faster.Zheng.Winin.AppBase.Filters ;
using Faster.Zheng.Winin.AppBase.Filters ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.EntityFrameworkCore ;
using Microsoft.EntityFrameworkCore ;
@ -13,7 +14,9 @@ using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services ;
using Volo.Abp.Application.Services ;
using Volo.Abp.Domain.Entities ;
using Volo.Abp.Domain.Entities ;
using Volo.Abp.Domain.Repositories ;
using Volo.Abp.Domain.Repositories ;
using Volo.Abp.EntityFrameworkCore ;
using static Microsoft . EntityFrameworkCore . DbLoggerCategory ;
using static Microsoft . EntityFrameworkCore . DbLoggerCategory ;
using static OpenIddict . Abstractions . OpenIddictConstants ;
namespace Faster.Zheng.Winin.AppBase ;
namespace Faster.Zheng.Winin.AppBase ;
@ -25,6 +28,8 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
where TEntityDto : IEntityDto < TKey >
where TEntityDto : IEntityDto < TKey >
{
{
private readonly IRepository < TEntity , TKey > _ repository ;
private readonly IRepository < TEntity , TKey > _ repository ;
private readonly IMapper _ mapper ;
private Func < TCreateInput , Entity > _ mapFunc ;
public ZbxBase ( IRepository < TEntity , TKey > repository ) : base ( repository )
public ZbxBase ( IRepository < TEntity , TKey > repository ) : base ( repository )
{
{
@ -44,6 +49,8 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
public async Task < PagedResultDto < TEntityDto > > GetPageListByFilterAsync ( SfsRequestInputBase sfsRequestInputBase ,
public async Task < PagedResultDto < TEntityDto > > GetPageListByFilterAsync ( SfsRequestInputBase sfsRequestInputBase ,
bool includeDetails = false , CancellationToken cancellationToken = default )
bool includeDetails = false , CancellationToken cancellationToken = default )
{
{
//await TestSqlAsync();
var expression = sfsRequestInputBase . Condition . Filters ? . Count > 0
var expression = sfsRequestInputBase . Condition . Filters ? . Count > 0
? sfsRequestInputBase . Condition . Filters . ToLambda < TEntity > ( )
? sfsRequestInputBase . Condition . Filters . ToLambda < TEntity > ( )
: p = > true ;
: p = > true ;
@ -53,8 +60,9 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
sfsRequestInputBase . Sorting , includeDetails , cancellationToken ) ;
sfsRequestInputBase . Sorting , includeDetails , cancellationToken ) ;
var resultDtos = ObjectMapper . Map < List < TEntity > , List < TEntityDto > > ( resultEntities ) ;
var resultDtos = ObjectMapper . Map < List < TEntity > , List < TEntityDto > > ( resultEntities ) ;
//获取总数
//获取总数
var totalCount = await GetCountAsync ( expression , cancellationToken ) ;
var totalCount = await GetCountAsync ( expression , cancellationToken ) ;
return new PagedResultDto < TEntityDto > ( totalCount , resultDtos ) ;
return new PagedResultDto < TEntityDto > ( totalCount , resultDtos ) ;
}
}
@ -69,8 +77,8 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
private async Task < long > GetCountAsync ( Expression < Func < TEntity , bool > > expression ,
private async Task < long > GetCountAsync ( Expression < Func < TEntity , bool > > expression ,
CancellationToken cancellationToken = default )
CancellationToken cancellationToken = default )
{
{
var count = await _ repository . LongCountAsync ( expression , cancellationToken : cancellationToken ) ;
var count = await _ repository . LongCountAsync ( expression , cancellationToken : cancellationToken ) ;
return count ;
return count ;
}
}
@ -83,6 +91,20 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
public override async Task < TEntityDto > CreateAsync ( TCreateInput input )
public override async Task < TEntityDto > CreateAsync ( TCreateInput input )
{
{
await CheckCreatePolicyAsync ( ) ;
await CheckCreatePolicyAsync ( ) ;
var mapperConfig = new MapperConfiguration ( cfg = >
{
cfg . CreateMap < TCreateInput , TEntity > ( ) ;
} ) ;
var _ mapper = mapperConfig . CreateMapper ( ) ;
var source = Expression . Parameter ( typeof ( TCreateInput ) , "source" ) ;
_ mapFunc = Expression . Lambda < Func < TCreateInput , TEntity > > (
Expression . Invoke ( Expression . Constant ( _ mapper . Map < TCreateInput , TEntity > ) ) , source )
. Compile ( ) ;
var tt = _ mapper . Map < TCreateInput , TEntity > ( input ) ;
var entity = await MapToEntityAsync ( input ) ;
var entity = await MapToEntityAsync ( input ) ;
//判断id是否是00000-0000 如果是则赋值
//判断id是否是00000-0000 如果是则赋值
@ -246,5 +268,19 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto,
return entities ;
return entities ;
}
}
//private async Task TestSqlAsync()
//{
// var dbContext=await _dbContextProvider.GetDbContextAsync().ConfigureAwait(false);
// var query = dbContext.TestSchools
// .Join(dbContext.TestStudentDetails, TPK => TPK.Id, TFK => TFK.MasterId, (TPK, TFK) => new { TPK, TFK })
// .Where(result => result.TFK.StudentName == "阎致远");
// foreach (var result in query)
// {
// Console.WriteLine($"Customer: {result.TFK.StudentName}, Order ID: {result.TPK.SchoolName}");
// }
//}
#endregion
#endregion
}
}