修复列表分页丢Where:改用GetListAsync分页,状态筛选生效。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
3d0db418d2
commit
d73c98b44e
@ -50,12 +50,12 @@ public class PlatformStoreOrderService : ApplicationService
|
||||
var predicate = BuildListPredicate(customerId, input);
|
||||
var pageIndex = OmsDocHelper.NormalizePage(input.Page);
|
||||
var pageSize = OmsDocHelper.NormalizePageSize(input.PageSize);
|
||||
var entities = await StoreOrderRepository.GetPagedListAsync(
|
||||
// 避免 Fake GetPagedListAsync(sorting) 丢失 Where:total 正确但 items 返回全量
|
||||
var (entities, total) = await RepositoryPageHelper.GetPageByUpdateTimeDescAsync(
|
||||
StoreOrderRepository,
|
||||
predicate,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
new Dictionary<string, bool> { [nameof(SalesStoreOrder.UpdateTime)] = false, [nameof(SalesStoreOrder.Id)] = false });
|
||||
var total = await StoreOrderRepository.CountAsync(predicate);
|
||||
pageSize);
|
||||
|
||||
var storeIds = entities.Select(x => x.StoreId).Distinct().ToArray();
|
||||
var stores = storeIds.Length == 0
|
||||
|
||||
@ -42,12 +42,12 @@ public partial class WarehouseService
|
||||
|
||||
var pageIndex = OmsDocHelper.NormalizePage(input.Page);
|
||||
var pageSize = OmsDocHelper.NormalizePageSize(input.PageSize);
|
||||
var entities = await InboundNoticeRepository.GetPagedListAsync(
|
||||
// 避免 Fake GetPagedListAsync(sorting) 丢失 Where:total 正确但 items 返回全量
|
||||
var (entities, total) = await RepositoryPageHelper.GetPageByUpdateTimeDescAsync(
|
||||
InboundNoticeRepository,
|
||||
predicate,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
new Dictionary<string, bool> { [nameof(CInboundNotice.UpdateTime)] = false, [nameof(CInboundNotice.Id)] = false });
|
||||
var total = await InboundNoticeRepository.CountAsync(predicate);
|
||||
pageSize);
|
||||
|
||||
var noticeIds = entities.Select(x => x.Id).ToArray();
|
||||
var boxes = noticeIds.Length == 0
|
||||
|
||||
@ -42,12 +42,12 @@ public partial class WarehouseService
|
||||
|
||||
var pageIndex = OmsDocHelper.NormalizePage(input.Page);
|
||||
var pageSize = OmsDocHelper.NormalizePageSize(input.PageSize);
|
||||
var entities = await ParcelRepository.GetPagedListAsync(
|
||||
// 避免 Fake GetPagedListAsync(sorting) 丢失 Where:total 正确但 items 返回全量
|
||||
var (entities, total) = await RepositoryPageHelper.GetPageByUpdateTimeDescAsync(
|
||||
ParcelRepository,
|
||||
predicate,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
new Dictionary<string, bool> { [nameof(CParcel.UpdateTime)] = false, [nameof(CParcel.Id)] = false });
|
||||
var total = await ParcelRepository.CountAsync(predicate);
|
||||
pageSize);
|
||||
|
||||
var parcelIds = entities.Select(x => x.Id).ToArray();
|
||||
var items = parcelIds.Length == 0
|
||||
|
||||
48
src/Oms.Application/Shared/RepositoryPageHelper.cs
Normal file
48
src/Oms.Application/Shared/RepositoryPageHelper.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System.Linq.Expressions;
|
||||
using Fake.Domain.Repositories;
|
||||
using Oms.Domain.Shared;
|
||||
|
||||
namespace Oms.Application.Shared;
|
||||
|
||||
/// <summary>
|
||||
/// 仓储分页辅助。
|
||||
/// Fake.SqlSugarCore 的 GetPagedListAsync 在传入 sorting 字典时会丢失 Where 条件
|
||||
/// (CountAsync/GetListAsync 正常,导致 total 对、items 却是全量),故改用本方法分页。
|
||||
/// </summary>
|
||||
public static class RepositoryPageHelper
|
||||
{
|
||||
public static async Task<(List<TEntity> Items, long Total)> GetPageAsync<TEntity>(
|
||||
IRepository<TEntity> repository,
|
||||
Expression<Func<TEntity, bool>> predicate,
|
||||
int pageIndex,
|
||||
int pageSize,
|
||||
Func<IEnumerable<TEntity>, IOrderedEnumerable<TEntity>> orderBy)
|
||||
where TEntity : OmsAuditedAggregateRoot
|
||||
{
|
||||
var total = await repository.CountAsync(predicate);
|
||||
if (total <= 0)
|
||||
{
|
||||
return ([], 0);
|
||||
}
|
||||
|
||||
var matched = await repository.GetListAsync(predicate);
|
||||
var items = orderBy(matched)
|
||||
.Skip((pageIndex - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToList();
|
||||
return (items, total);
|
||||
}
|
||||
|
||||
public static Task<(List<TEntity> Items, long Total)> GetPageByUpdateTimeDescAsync<TEntity>(
|
||||
IRepository<TEntity> repository,
|
||||
Expression<Func<TEntity, bool>> predicate,
|
||||
int pageIndex,
|
||||
int pageSize)
|
||||
where TEntity : OmsAuditedAggregateRoot =>
|
||||
GetPageAsync(
|
||||
repository,
|
||||
predicate,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
q => q.OrderByDescending(x => x.UpdateTime).ThenByDescending(x => x.Id));
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user