From 1a805e51f7242b1be28bbd883cd3279fd5eed16c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E8=AF=9A?= Date: Sat, 27 Dec 2025 22:05:50 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Repository/TransactionRecordRepository.cs | 108 ++++++++++++------ Web/src/components/TransactionDetail.vue | 18 ++- Web/src/views/EmailRecord.vue | 27 ++--- Web/src/views/StatisticsView.vue | 79 +++++++++---- Web/src/views/TransactionsRecord.vue | 24 ++-- .../TransactionRecordController.cs | 28 +++-- 6 files changed, 183 insertions(+), 101 deletions(-) diff --git a/Repository/TransactionRecordRepository.cs b/Repository/TransactionRecordRepository.cs index a6a12c8..85defe7 100644 --- a/Repository/TransactionRecordRepository.cs +++ b/Repository/TransactionRecordRepository.cs @@ -7,31 +7,36 @@ public interface ITransactionRecordRepository : IBaseRepository ExistsByImportNoAsync(string importNo, string importFrom); /// - /// 分页获取交易记录列表(游标分页) + /// 分页获取交易记录列表 /// - /// 上一页最后一条记录的发生时间 - /// 上一页最后一条记录的ID + /// 页码,从1开始 /// 每页数量 /// 搜索关键词(搜索交易摘要和分类) /// 筛选分类 /// 筛选交易类型 /// 筛选年份 /// 筛选月份 - /// 交易记录列表、最后发生时间和最后ID - Task<(List list, DateTime? lastOccurredAt, long lastId)> GetPagedListAsync( - DateTime? lastOccurredAt, - long? lastId, + /// 是否按金额降序排列,默认为false按时间降序 + /// 交易记录列表 + Task> GetPagedListAsync( + int pageIndex = 1, int pageSize = 20, string? searchKeyword = null, string? classify = null, TransactionType? type = null, int? year = null, - int? month = null); + int? month = null, + bool sortByAmount = false); /// /// 获取总数 /// - Task GetTotalCountAsync(); + Task GetTotalCountAsync( + string? searchKeyword = null, + string? classify = null, + TransactionType? type = null, + int? year = null, + int? month = null); /// /// 获取所有不同的交易分类 @@ -162,10 +167,68 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository list, DateTime? lastOccurredAt, long lastId)> GetPagedListAsync( - DateTime? lastOccurredAt, - long? lastId, + public async Task> GetPagedListAsync( + int pageIndex = 1, int pageSize = 20, + string? searchKeyword = null, + string? classify = null, + TransactionType? type = null, + int? year = null, + int? month = null, + bool sortByAmount = false) + { + var query = FreeSql.Select(); + + // 如果提供了搜索关键词,则添加搜索条件 + query = query.WhereIf(!string.IsNullOrWhiteSpace(searchKeyword), + t => t.Reason.Contains(searchKeyword!) || + t.Classify.Contains(searchKeyword!) || + t.Card.Contains(searchKeyword!) || + t.ImportFrom.Contains(searchKeyword!)); + + // 按分类筛选 + if (!string.IsNullOrWhiteSpace(classify)) + { + if (classify == "未分类") + { + classify = string.Empty; + } + query = query.Where(t => t.Classify == classify); + } + + // 按交易类型筛选 + query = query.WhereIf(type.HasValue, t => t.Type == type!.Value); + + // 按年月筛选 + if (year.HasValue && month.HasValue) + { + var startDate = new DateTime(year.Value, month.Value, 1); + var endDate = startDate.AddMonths(1); + query = query.Where(t => t.OccurredAt >= startDate && t.OccurredAt < endDate); + } + + // 根据sortByAmount参数决定排序方式 + if (sortByAmount) + { + // 按金额降序排列 + return await query + .OrderByDescending(t => t.Amount) + .OrderByDescending(t => t.Id) + .Page(pageIndex, pageSize) + .ToListAsync(); + } + else + { + // 按时间降序排列 + return await query + .OrderByDescending(t => t.OccurredAt) + .OrderByDescending(t => t.Id) + .Page(pageIndex, pageSize) + .ToListAsync(); + } + } + + public async Task GetTotalCountAsync( string? searchKeyword = null, string? classify = null, TransactionType? type = null, @@ -202,26 +265,7 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository t.OccurredAt >= startDate && t.OccurredAt < endDate); } - // 如果提供了游标,则获取小于游标位置的记录 - if (lastOccurredAt.HasValue && lastId.HasValue) - { - query = query.Where(t => t.OccurredAt < lastOccurredAt.Value || - (t.OccurredAt == lastOccurredAt.Value && t.Id < lastId.Value)); - } - - var list = await query - .OrderByDescending(t => t.OccurredAt) - .OrderByDescending(t => t.Id) - .Page(1, pageSize) - .ToListAsync(); - - var lastRecord = list.Count > 0 ? list.Last() : null; - return (list, lastRecord?.OccurredAt, lastRecord?.Id ?? 0); - } - - public async Task GetTotalCountAsync() - { - return await FreeSql.Select().CountAsync(); + return await query.CountAsync(); } public async Task> GetDistinctClassifyAsync() diff --git a/Web/src/components/TransactionDetail.vue b/Web/src/components/TransactionDetail.vue index 4475a0b..a3c2aba 100644 --- a/Web/src/components/TransactionDetail.vue +++ b/Web/src/components/TransactionDetail.vue @@ -12,6 +12,7 @@

交易详情

+
@@ -102,6 +103,7 @@
+ @@ -334,13 +336,27 @@ const formatDate = (dateString) => {