From 5e23c38df4ce814015a805f32e55617b0e92e882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E8=AF=9A?= Date: Fri, 26 Dec 2025 17:56:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=A0=B7=E5=BC=8F=E5=BE=AE?= =?UTF-8?q?=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Repository/TransactionRecordRepository.cs | 45 ++- Web/src/views/StatisticsView.vue | 283 +++++++++++++++++- .../TransactionRecordController.cs | 17 +- 3 files changed, 331 insertions(+), 14 deletions(-) diff --git a/Repository/TransactionRecordRepository.cs b/Repository/TransactionRecordRepository.cs index 07479ff..6a4ba64 100644 --- a/Repository/TransactionRecordRepository.cs +++ b/Repository/TransactionRecordRepository.cs @@ -13,8 +13,20 @@ public interface ITransactionRecordRepository : IBaseRepository上一页最后一条记录的ID /// 每页数量 /// 搜索关键词(搜索交易摘要和分类) + /// 筛选分类 + /// 筛选交易类型 + /// 筛选年份 + /// 筛选月份 /// 交易记录列表、最后发生时间和最后ID - Task<(List list, DateTime? lastOccurredAt, long lastId)> GetPagedListAsync(DateTime? lastOccurredAt, long? lastId, int pageSize = 20, string? searchKeyword = null); + Task<(List list, DateTime? lastOccurredAt, long lastId)> GetPagedListAsync( + DateTime? lastOccurredAt, + long? lastId, + int pageSize = 20, + string? searchKeyword = null, + string? classify = null, + TransactionType? type = null, + int? year = null, + int? month = null); /// /// 获取总数 @@ -150,7 +162,15 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository list, DateTime? lastOccurredAt, long lastId)> GetPagedListAsync(DateTime? lastOccurredAt, long? lastId, int pageSize = 20, string? searchKeyword = null) + public async Task<(List list, DateTime? lastOccurredAt, long lastId)> GetPagedListAsync( + DateTime? lastOccurredAt, + long? lastId, + int pageSize = 20, + string? searchKeyword = null, + string? classify = null, + TransactionType? type = null, + int? year = null, + int? month = null) { var query = FreeSql.Select(); @@ -163,6 +183,26 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository t.Classify == classify); + } + + // 按交易类型筛选 + if (type.HasValue) + { + query = query.Where(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); + } + // 如果提供了游标,则获取小于游标位置的记录 if (lastOccurredAt.HasValue && lastId.HasValue) { @@ -200,7 +240,6 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository() .Where(t => t.OccurredAt >= startDate && t.OccurredAt < endDate) - .Where(t => t.Type == TransactionType.Expense || t.Type == TransactionType.Income) // 统计消费和收入 .ToListAsync(); var statistics = records diff --git a/Web/src/views/StatisticsView.vue b/Web/src/views/StatisticsView.vue index 7bc4864..673e1bf 100644 --- a/Web/src/views/StatisticsView.vue +++ b/Web/src/views/StatisticsView.vue @@ -98,16 +98,21 @@
- {{ category.classify || '未分类' }} +
+ {{ category.classify || '未分类' }} + {{ category.count }}笔 +
¥{{ formatMoney(category.amount) }}
{{ category.percent }}%
+
@@ -129,16 +134,21 @@
- {{ category.classify || '未分类' }} +
+ {{ category.classify || '未分类' }} + {{ category.count }}笔 +
¥{{ formatMoney(category.amount) }}
{{ category.percent }}%
+
@@ -234,14 +244,51 @@ @cancel="showMonthPicker = false" /> + + + +
+ + +
+ +
+
+
+ + + \ No newline at end of file diff --git a/WebApi/Controllers/TransactionRecordController.cs b/WebApi/Controllers/TransactionRecordController.cs index e66c54b..d3c8a91 100644 --- a/WebApi/Controllers/TransactionRecordController.cs +++ b/WebApi/Controllers/TransactionRecordController.cs @@ -18,12 +18,25 @@ public class TransactionRecordController( public async Task> GetListAsync( [FromQuery] DateTime? lastOccurredAt = null, [FromQuery] long? lastId = null, - [FromQuery] string? searchKeyword = null + [FromQuery] string? searchKeyword = null, + [FromQuery] string? classify = null, + [FromQuery] int? type = null, + [FromQuery] int? year = null, + [FromQuery] int? month = null ) { try { - var (list, lastTime, lastIdResult) = await transactionRepository.GetPagedListAsync(lastOccurredAt, lastId, 20, searchKeyword); + TransactionType? transactionType = type.HasValue ? (TransactionType)type.Value : null; + var (list, lastTime, lastIdResult) = await transactionRepository.GetPagedListAsync( + lastOccurredAt, + lastId, + 20, + searchKeyword, + classify, + transactionType, + year, + month); var total = await transactionRepository.GetTotalCountAsync(); return new PagedResponse