|
|
@ -7,11 +7,13 @@ using System.Linq.Expressions; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Faster.Zheng.Winin.AppBase.Filters; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.Application.Services; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory; |
|
|
|
|
|
|
|
namespace Faster.Zheng.Winin.AppBase; |
|
|
|
|
|
|
@ -22,7 +24,7 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
|
where TEntity : class, IEntity<TKey> |
|
|
|
where TEntityDto : IEntityDto<TKey> |
|
|
|
{ |
|
|
|
private IRepository<TEntity, TKey> _repository; |
|
|
|
private readonly IRepository<TEntity, TKey> _repository; |
|
|
|
|
|
|
|
public ZbxBase(IRepository<TEntity, TKey> repository) : base(repository) |
|
|
|
{ |
|
|
@ -32,28 +34,52 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
|
#region 公开接口
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 分页查询
|
|
|
|
/// 【分页查询】【有筛选条件】
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sfsRequestInputBase"></param>
|
|
|
|
/// <param name="includeDetails"></param>
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
//[HttpPost]
|
|
|
|
public async Task<List<TEntity>> GetPageListByFilterAsync(SfsRequestInputBase sfsRequestInputBase, |
|
|
|
[HttpPost("api/[controller]/base/get-list-page-by-filter")]
|
|
|
|
public async Task<PagedResultDto<TEntityDto>> GetPageListByFilterAsync(SfsRequestInputBase sfsRequestInputBase, |
|
|
|
bool includeDetails = false, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var expression = sfsRequestInputBase.Condition.Filters?.Count > 0 |
|
|
|
? sfsRequestInputBase.Condition.Filters.ToLambda<TEntity>() |
|
|
|
: p => true; |
|
|
|
|
|
|
|
var result = await GetQueryListAsync(expression, sfsRequestInputBase.SkipCount, |
|
|
|
var resultEntities = await GetQueryListAsync(expression, sfsRequestInputBase.SkipCount, |
|
|
|
sfsRequestInputBase.MaxResultCount, |
|
|
|
sfsRequestInputBase.Sorting, includeDetails, cancellationToken); |
|
|
|
|
|
|
|
return result; |
|
|
|
var resultDtos = ObjectMapper.Map<List<TEntity>, List<TEntityDto>>(resultEntities); |
|
|
|
//获取总数
|
|
|
|
var totalCount =await GetCountAsync(expression, cancellationToken); |
|
|
|
|
|
|
|
return new PagedResultDto<TEntityDto>(totalCount, resultDtos); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 【记录数量查询】【有筛选条件】
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="expression"></param>
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("api/[controller]/base/get-count-by-filter")]
|
|
|
|
private async Task<long> GetCountAsync(Expression<Func<TEntity, bool>> expression, |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var count= await _repository.LongCountAsync(expression, cancellationToken: cancellationToken); |
|
|
|
|
|
|
|
return count; |
|
|
|
} |
|
|
|
|
|
|
|
//[HttpPost]
|
|
|
|
/// <summary>
|
|
|
|
/// 【基础】-【新增】
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("api/[controller]/base/create")]
|
|
|
|
public override async Task<TEntityDto> CreateAsync(TCreateInput input) |
|
|
|
{ |
|
|
|
await CheckCreatePolicyAsync(); |
|
|
@ -131,13 +157,24 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
|
return await MapToGetOutputDtoAsync(entity); |
|
|
|
} |
|
|
|
|
|
|
|
//[HttpDelete]
|
|
|
|
/// <summary>
|
|
|
|
/// 【基础】-【删除】
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpDelete("api/[controller]/base/delete-by-id")]
|
|
|
|
public override async Task DeleteAsync(TKey id) |
|
|
|
{ |
|
|
|
await _repository.DeleteAsync(id); |
|
|
|
await base.DeleteAsync(id); |
|
|
|
} |
|
|
|
|
|
|
|
//[HttpPut]
|
|
|
|
/// <summary>
|
|
|
|
/// 【基础】-【修改】
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPut("api/[controller]/base/update-by-id")]
|
|
|
|
public override Task<TEntityDto> UpdateAsync(TKey id, TUpdateInput input) |
|
|
|
{ |
|
|
|
return base.UpdateAsync(id, input); |
|
|
@ -161,7 +198,7 @@ public class ZbxBase<TEntity, TEntityDto, TKey, TPagedAndSortedResultRequestDto, |
|
|
|
int skipCount, int maxResultCount, string sorting, |
|
|
|
bool includeDetails = false, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var query = await Repository.GetQueryableAsync(); |
|
|
|
var query = await Repository.WithDetailsAsync(); |
|
|
|
|
|
|
|
var entities = query.Where(expression); |
|
|
|
entities = GetSortingQueryable(entities, sorting); |
|
|
|