排序处理
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
541e000183
commit
40c3ea65ff
|
|
@ -16,6 +16,7 @@ using MailKit.Security;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using MimeKit;
|
using MimeKit;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Mail;
|
using System.Net.Mail;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
namespace IRaCIS.Core.Application.Service;
|
namespace IRaCIS.Core.Application.Service;
|
||||||
|
|
@ -73,15 +74,16 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
|
|
||||||
//var uids = sentFolder.Sort(searchQuery, orderBy).Skip((inQuery.PageIndex - 1) * inQuery.PageSize).Take(inQuery.PageSize).ToList();
|
//var uids = sentFolder.Sort(searchQuery, orderBy).Skip((inQuery.PageIndex - 1) * inQuery.PageSize).Take(inQuery.PageSize).ToList();
|
||||||
|
|
||||||
var uids = sentFolder.Search(searchQuery).Skip((inQuery.PageIndex - 1) * inQuery.PageSize).Take(inQuery.PageSize).ToList();
|
|
||||||
|
|
||||||
|
pageOutput.TotalCount = sentFolder.Search(searchQuery).Count();
|
||||||
|
|
||||||
|
// 在内存中分页倒序
|
||||||
|
|
||||||
|
var uids = sentFolder.Search(searchQuery).Skip(CalcReverseSkip(inQuery.PageIndex, inQuery.PageSize, (int)pageOutput.TotalCount)).Take(inQuery.PageSize).ToList();
|
||||||
|
uids.Reverse();
|
||||||
// 获取邮件并排序(按时间倒序)
|
// 获取邮件并排序(按时间倒序)
|
||||||
var emailList = GetEmailsWithSorting(sentFolder, uids);
|
var emailList = GetEmailsWithSorting(sentFolder, uids);
|
||||||
|
|
||||||
// 应用内存中的过滤条件(对于无法通过IMAP搜索的条件)
|
|
||||||
//var filteredEmails = ApplyMemoryFilters(emailList, inQuery);
|
|
||||||
|
|
||||||
pageOutput.TotalCount = sentFolder.Search(searchQuery).Count();
|
|
||||||
pageOutput.PageIndex = inQuery.PageIndex;
|
pageOutput.PageIndex = inQuery.PageIndex;
|
||||||
pageOutput.PageSize = inQuery.PageSize;
|
pageOutput.PageSize = inQuery.PageSize;
|
||||||
|
|
||||||
|
|
@ -115,10 +117,15 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
return pageOutput;
|
return pageOutput;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取skip的值
|
||||||
|
public int CalcReverseSkip(int pageIndex, int pageSize, int totalCount)
|
||||||
|
{
|
||||||
|
|
||||||
|
int lastPageFullSkip = totalCount / pageSize * pageSize; // 最后一页“整页”起点
|
||||||
|
int skip = lastPageFullSkip - pageIndex * pageSize; // 倒着减
|
||||||
|
return Math.Max(skip, 0); // 防止负值
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue